Session A First Game Program

Similar documents
Visual C# 2010 Express

GAME:IT Advanced. C# XNA Bouncing Ball First Game Part 1

Xna0118-The XNA Framework and. the Game Class

Session 5.1. Writing Text

Game1.cs class that derives (extends) Game public class Game1 : Microsoft.Xna.Framework.Game {..}

ITP 342 Mobile App Dev. Interface Builder in Xcode

Using the History Palette Part 2 - Create & Convert Quick Scripts

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

Engr 123 Spring 2018 Notes on Visual Studio

Chapter 1 Getting Started

XNA Game Studio 4.0.

IMGD The Game Development Process: File Formats

Adobe Photoshop CS2 Reference Guide For Windows

3.3 Web Graphics. 1. So why are graphics important?

On the Web sun.com/aboutsun/comm_invest STAROFFICE 8 DRAW

DRAWING VECTOR VS PIXEL SHAPES IN PHOTOSHOP CS6

DAZ Page 1. DAZ3D to Unity (Objects and Clothing)

Making Your First Character

Packaging Your Program into a Distributable JAR File

DIRECTV Message Board

Getting Started. 1 by Conner Irwin

Photos, Photos. What to do with All Those Photos? Presented by Phil Goff Area 16 Computers and Technology August 17, 2017

INFORMATICS LABORATORY WORK #2

Static Methods. Why use methods?

Photoshop World 2018

Tutorial - Hello World

Image Management Guideline Managing Your Site Images

Beginning a New Project

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

Asset List & Content Creation

Lab 2 Building on Linux

AP Computer Science Unit 1. Writing Programs Using BlueJ

Making use of other Applications

Chapter Two Bonus Lesson: JavaDoc

How to make a Work Profile for Windows 10

How To Upload Your Newsletter

Pong in Unity a basic Intro

12/15/2008. All about Game Maker. Integrated Development Environment for 2D games Global idea

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

Prezi PREZI ONLINE ACCOUNT START FROM A TEMPLATE

CS 177 Recitation. Week 1 Intro to Java

Variables and numeric types

Introduction to Unreal Engine Blueprints for Beginners. By Chaven R Yenketswamy

BONUS! SPECIAL REPORT

Honors Computer Science Python Mr. Clausen Program 7A, 7B

UDK Basics Textures and Material Setup

PSD to Mobile UI Tutorial

- 1 - Handout #33 March 14, 2014 JAR Files. CS106A Winter

Introduction To C#.NET

Hands-On Workshop: 3D Automotive Graphics on Connected Radios Using Rayleigh and OpenGL ES 2.0

Welcome. Introduction. Creating the Bitmaps. Editing

Setting Up the Fotosizer Software

Programming Using C# QUEEN S UNIVERSITY BELFAST. Practical Week 7

MacAutomationTips.com Bakari Chavanu. Hazel: Your Automated Digital Assistant Working According to Rules You Set

Unit 17. Level 1/2 Unit 17 Multimedia Products Development

Using Images in FF&EZ within a Citrix Environment

Fundamental C# Programming

Keep Track of Your Passwords Easily

Lutheran High North Technology The Finder

Introduction to Java Unit 1. Using BlueJ to Write Programs

CATALOGING IDimager Systems DOCUMENT VERSION 0.35

CHAPTER 6 ACTIONS, METHODS, REFACTORING

_CH17_525_10/31/06 CAL 101

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

How Your First Program Works

Image Types Vector vs. Raster

Fireworks Basics. The Fireworks Interface

Soundburst has been a music provider for Jazzercise since Our site is tailored just for Jazzercise instructors. We keep two years of full

Tutorial: Creating a Gem with code

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

The purpose of this tutorial is to introduce you to the Construct 2 program. First, you will be told where the software is located on the computer

XP: Backup Your Important Files for Safety

A new clients guide to: Activating a new Studio 3.0 Account Creating a Photo Album Starting a Project Submitting a Project Publishing Tips

AP Computer Science Unit 1. Writing Programs Using BlueJ

PHOTOSHOP New File. To create a new file, select File > New and a dialog box will open.

Basic Keywords Practice Session

Annotation Hammer Venkat Subramaniam (Also published at

Music Technology for Beginners Session 3

Creating Hair Textures with highlights using The GIMP

CS 201 Software Development Methods Spring Tutorial #1. Eclipse

RIS shading Series #2 Meet The Plugins

ICS3C/4C/3U/4U Unit 2 Workbook Selection: If Statement

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Burning CDs in Windows XP

Robotics II. Module 5: Creating Custom Made Blocks (My Blocks)

The Basics of Visual Studio Code

YCL Session 4 Lesson Plan

1. Welcome. (1) Hello. My name is Dr. Christopher Raridan (Dr. R). (3) In this tutorial I will introduce you to the amsart documentclass.

ASCII Art. Introduction: Python

15 Minute Traffic Formula. Contents HOW TO GET MORE TRAFFIC IN 15 MINUTES WITH SEO... 3

IAT 445 Lab 10. Special Topics in Unity. Lanz Singbeil

Creating the Data Layer

Course 3D_XNA: 3D-Computer Graphics with XNA Chapter C3: Drunken Tiger

Lesson 4: Verifying ROMs with the Fluke 9010A Version 1.03

Soda Machine Laboratory

Please go to the Riemer s 2D XNA Tutorial for C# by clicking on You are allowed to progress ahead of me by

PHOTOSHOP 7 BASIC USER MANUAL

Creating a new form with check boxes, drop-down list boxes, and text box fill-ins. Customizing each of the three form fields.

Add in a new balloon sprite, and a suitable stage backdrop.

XNA 4.0 RPG Tutorials. Part 22. Reading Data

Transcription:

1 Session 11.1 A First Game Program

Chapter 11.1: A First Game Program 2 Session Overview Begin the creation of an arcade game Learn software design techniques that apply to any form of game development Find out more about how C# programs are constructed and executed See how to properly organize the content of a game and the program itself Perform some simple refactoring of a C# solution

Chapter 11.1: A First Game Program 3 Game Idea: Bread and Cheese The starting point for our game is the contents of a shopping bag This contains some food that we bought We are going to use these objects as the basis of a game where the bread hits the cheese around the screen

Chapter 11.1: A First Game Program 4 Creating Game Graphics You really need someone who can work with images to create good game graphics This might mean involving an artist in your game development The graphics editor that you use must be able to work with transparency This makes it possible to create natural looking game objects

Chapter 11.1: A First Game Program 5 Graphics Editors I use Photoshop Elements (tm) to make my game graphics A good free solution is Paint.NET: www.getpaint.net This lets you manipulate images in layers and supports transparency

Chapter 11.1: A First Game Program 6 Image File Formats XNA can use image files in many formats The jpg and gif formats can be used, but they do not support transparency I use the PNG format for all my images You should also make sure that your images are not too large You don t need more than a few hundred pixels for these sprite images You can use Paint.NET to resize images

Chapter 11.1: A First Game Program 7 Projects, Resources, and Classes To start making a game you create a new project in Microsoft Visual Studio This serves as the container for all the game resources Before we build our game, it is worth taking a look at how the elements of the project fit together and how best to organize your solution This knowledge will make your programs much easier to look after in the future

Chapter 11.1: A First Game Program 8 The BreadAndCheese Solution We are going to create a solution called BreadAndCheese This contains all the program files and game content Visual Studio organizes the content into a set of folders We can add our own folders

Chapter 11.1: A First Game Program 9 Adding a Folder A folder is a place in the computer filestore where you can put things you want to store in one place All the tracks from a particular album are stored in a single folder with your music You can create your own folders to organize your content

Chapter 11.1: A First Game Program 10 Creating an Images Folder I like to keep image and sound resources separate This makes it easier to reuse the files as I can just take the entire contents of the folder I ve therefore created an Images folder in the Content of the BreadAndCheese game

Chapter 11.1: A First Game Program 11 Adding Content to a Folder You can add content to a folder in exactly the same way as before In BreadAndCheese project, the Images folder now contains the images for the Bread and Cheese sprites We can create folders inside folders if we like

Chapter 11.1: A First Game Program 12 Loading Content from Folders breadtexture = Content.Load<Texture2D>("Images/Bread"); cheesetexture = Content.Load<Texture2D>("Images/Cheese"); When the textures are loaded you need to add the folder name to the asset name so that the Content Manager can find the asset The / character is used to separate folder names in the path to the asset If you get the path wrong the game will compile OK but will fail when it runs

Chapter 11.1: A First Game Program 13 Game Program Files We are very familiar with the Game1.cs file This is the file that contains the Draw and Update methods that make the game work However this is not the only C# program file in the game There is also a Program.cs file This is actually the file that makes the game run Now we are going to take a look at this file

Chapter 11.1: A First Game Program 14 The Program.cs File using System; namespace BreadAndCheese static class Program static void Main(string[] args) using (Game1 game = new Game1()) game.run(); The Program.cs file is what actually runs our game

Chapter 11.1: A First Game Program 15 The Using Statement using System; namespace BreadAndCheese static class Program static void Main(string[] args) using (Game1 game = new Game1()) game.run(); This is a using statement

Chapter 11.1: A First Game Program 16 Identifying a Namespace with Using using System; The using keyword is used to identify a namespace to use This one tells the compiler to use the System namespace A namespace is somewhere for the compiler to look to find descriptions of resources Lots of important C# classes, including DateTime, are described in the System namespace

Chapter 11.1: A First Game Program 17 Creating Our Own Namespace using System; namespace BreadAndCheese static class Program static void Main(string[] args) using (Game1 game = new Game1()) game.run(); This creates a namespace for our game program

Chapter 11.1: A First Game Program 18 Creating a Namespace namespace BreadAndCheese The designers of C# created a namespace called System where they put system utilities This statement creates a namespace with the name BreadAndCheese (to match the game project) It stops the names of our items from clashing with those from other C# programs Other programs can locate items in the BreadAndCheese namespace by using it

Chapter 11.1: A First Game Program 19 Fully-Qualified Names in Namespaces System.DateTime currenttime = System.DateTime.Now; You can use objects from namespaces without having to have a using statement at the top of the file You do this by putting the namespace in front of the name This fully-qualified name can also be used if there is a name clash between two namespaces If you use two namespaces that both hold an item with a particular name

Chapter 11.1: A First Game Program 20 Creating a Program Class using System; namespace BreadAndCheese static class Program static void Main(string[] args) using (Game1 game = new Game1()) game.run(); This creates a static class called Program

Chapter 11.1: A First Game Program 21 The Program Class static class Program // Program class members go here... A class is a collection of variables and methods The Program class is the class that actually starts the program going It is static because it only contains static members Static in C# means always present There is no need to ever make a Program instance

Chapter 11.1: A First Game Program 22 Declaring the Main Method using System; namespace BreadAndCheese static class Program static void Main(string[] args) using (Game1 game = new Game1()) game.run(); This creates a namespace for our game program

Chapter 11.1: A First Game Program 23 The Main Method static void Main(string[] args) // Main method statements go here This declares the Main method for this project It is static (which means always there) It returns nothing (it is void) It is given an array of strings as a parameter Main is the method that is called to start a C# program running

Chapter 11.1: A First Game Program 24 Creating a Game1 Instance and Using It using System; namespace BreadAndCheese static class Program static void Main(string[] args) using (Game1 game = new Game1()) game.run(); This is another use of the keyword using

Chapter 11.1: A First Game Program 25 The Other Face of Using using (Game1 game = new Game1()) // Code that uses the game1 instance // When we get here game1 can be destroyed This form of using is a way to help the garbage collector and tell it when an object can be removed The using construction creates an object and gives the only block of statements in which it is used When that block is finished the object can be removed from memory

Chapter 11.1: A First Game Program 26 Running the Game using System; namespace BreadAndCheese static class Program static void Main(string[] args) using (Game1 game = new Game1()) game.run(); This statement calls the Run method on the game

Chapter 11.1: A First Game Program 27 Calling the Run Method on an XNA Game game.run(); The Run method is the method that starts everything going in an XNA game: It calls Initialize It calls LoadContent It starts a process that calls Update and Draw 60 times a second You can think of it as the Main method for XNA When the Run method finishes the game ends

Chapter 11.1: A First Game Program 28 The Program Class There is actually no need to change the content of the Program class The class is created automatically when Microsoft Visual Studio creates a new project However it is useful to know how it fits together and what really happens when you run a program If you make a command line program (not a game) the Program.cs file is the only one you get, and you can put your code directly into the Main method

Chapter 11.1: A First Game Program 29 Renaming the Game1 Class One thing that we should do however is change the name of our game class from Game1 This is really just a placeholder for a name which has a bit more meaning The game class we are making should really be called BreadAndCheeseGame Visual Studio makes this very easy

Chapter 11.1: A First Game Program 30 Using Rename in Visual Studio You can rename an item by using right-click on it and then typing in the required name Renaming things so that their names are more meaningful is called refactoring and is a great way to make your programs easier to understand

Chapter 11.1: A First Game Program 31 Entering the New Name Make sure that you don t change the file extension from.cs though, as this will stop your program from building This will rename the file as stored on the disk, and update the reference to it in the project file

Chapter 11.1: A First Game Program 32 Renaming the Class If you rename a program file Visual Studio will offer to rename the class in the file as well This is very useful, and so you should say yes so that the class Game1 will be renamed to BreadAndCheeseGame

Chapter 11.1: A First Game Program 33 1. Renaming Game Classes Files This shows how easy it is to rename a game class From now on I will expect classes to always have the correct names

Chapter 11.1: A First Game Program 34 Summary A good solution is a well organized one C# provides a namespace mechanism to allow a programmers to manage the names of their items An XNA game is actually started by code in a Program class which calls a static Main method In C# the word static means always present The using construction makes garbage collection easier Names of items should always reflect what they are