This document provides an introduction to game development using the XNA framework. It discusses important considerations for game design, including gameplay mechanics, genre, controls, and whether to use 2D or 3D art. It also covers tools for creating art assets and sound. For programming, it explains working with game engines at different levels using languages like C#, C++, and how XNA works. The document then demonstrates a simple 2D space shooting game called "Squid Invaders" as a tutorial to apply these concepts.
This document provides an introduction to game development using the XNA framework. It discusses important considerations for game design, including gameplay mechanics, genre, controls, and whether to use 2D or 3D art. It also covers tools for creating art assets and sound. For programming, it explains working with game engines at different levels using languages like C#, C++, and how XNA works. The document then demonstrates a simple 2D space shooting game called "Squid Invaders" as a tutorial to apply these concepts.
Original Description:
XNA
Game Development
Space Shooter
Beginner
Tutorial
This document provides an introduction to game development using the XNA framework. It discusses important considerations for game design, including gameplay mechanics, genre, controls, and whether to use 2D or 3D art. It also covers tools for creating art assets and sound. For programming, it explains working with game engines at different levels using languages like C#, C++, and how XNA works. The document then demonstrates a simple 2D space shooting game called "Squid Invaders" as a tutorial to apply these concepts.
This document provides an introduction to game development using the XNA framework. It discusses important considerations for game design, including gameplay mechanics, genre, controls, and whether to use 2D or 3D art. It also covers tools for creating art assets and sound. For programming, it explains working with game engines at different levels using languages like C#, C++, and how XNA works. The document then demonstrates a simple 2D space shooting game called "Squid Invaders" as a tutorial to apply these concepts.
Download as DOCX, PDF, TXT or read online from Scribd
Download as docx, pdf, or txt
You are on page 1of 14
Introduction to Game Development and
XNA Squid Invaders!
XNA Space Game Beginner Tutorial Mikhail Roy Dela Cruz
Preface .......................................................................................................................................................... 3 Introduction .............................................................................................................................................. 3 Expectations .............................................................................................................................................. 3 Introduction to Game Development - "Things You Should Consider" .......................................................... 4 Game Design ............................................................................................................................................. 4 Gameplay .......................................................................................................................................... 4 Art ..................................................................................................................................................... 5 Sound ................................................................................................................................................ 6 Game Programming .................................................................................................................................. 6 At what programming level are you willing to work? ....................................................................... 6 What concepts in programming should one know in order use those tools above? ........................ 8 Squid Invaders! ............................................................................................................................................. 9 Getting Started ...................................................................................................................................... 9 Parts of a class (.cs) ........................................................................................................................... 9 XNA Program Flow .......................................................................................................................... 10 Analyze a game ............................................................................................................................... 12 Game Development ................................................................................................................................ 14 Creating XNA Game Project Creating a Sprite Class Creating a Background Creating a Ship Class Creating a Player Ship Setting up Keyboard Adding Bullet Creating an Enemy Ship Adding AI to Enemy Shop Colliding Bullet Adding lives Adding GUI
Preface Introduction Developing video games is challenging as a programming task. Although a layman can easily relate with the mechanics and objectives of a video game, understanding the technology behind it may require sufficient programming knowledge. Consider a normal Tetris Game -We all about the blocks: The different shapes, how those blocks gradually go down, rotating it so it fits from the pile of other blocks, and how you lose when the pile reaches at top. Its so easy to decipher those mechanics. But when asked how we could we represent them at a computer screen, things get a little bit tight. That is what this document is focused on, representing things on a computer screen. In general, to provide an introduction to assist people who wish to begin making their own games. In the few chapters at the beginning, At the end of this document, the reader will have created a simple, yet functional single player game. We will be usin The game will just be a simple space arcade shooting game consisting of squid aliens, just like the typical Space Invader, with no power-ups and other stuffs. As the title of the document suggests, we will be using Microsoft XNA 3.1 Framework to make such space game.
Expectations If you will read this material, it would definitely help if you have at least a basic familiarity of the following: - General C# Syntax - Object-Oriented(OO) Design - Basic Algebra
Introduction to Game Development - "Things You Should Consider"
Video game development can be sub-divided into two processes: Game Design and Game Programming. When we talk about Game Design, this is the process where the content and mechanics of the game such as gameplay, environment, storyline, and characters are given thought and made. On the other hand, Game Programming is the actual process of implementing the game design into a computer program. Usually, game development starts at the designing process - as it is a good practice to start planning things before going all way to programming. Below I have compiled questions for both Game Design and Game Programming that you should ask yourself. I believe these questions are relatively important in developing a video game. Game Design Gameplay What are the Objectives/ Rules/Mechanics? These are the key components that will define your game. Make sure it is defined clearly when you are making your game.
Example: The objective of the Chess game is to checkmate the King. You can do that by using pieces to capture other pieces (Mechanic). Though there are different rules that define the difference between each pieces.
What kind of Genre? Genre is the different categories of video games based on their gameplay interaction rather than visual or narrative differences;
How about the controls? How would you play the game? Use a Mouse and Keyboard? Or Perhaps a Game Pad? What kind of control mapping would suit the gameplay?
Example: Counter Strike uses WSAD to control the character movement and mouse for the camera and guns.
Art Will it be on 2D or 3D? This is actually can be a difficult question to answer. While most people would prefer to play 3D video games over 2D ones as 3D brings more sense of realism to the gameplay experience, developing a 3D game can be a lot harder.
In 3D, you have to be familiar with lots of thing such as 3D Math (Matrices, Projection, etc), Model Mesh and Textures, lighting, and others which is something I would not recommend for beginner programmers to tackle head-on.
Besides, style is still a big factor when deciding for 2D over 3D. Just like Mario and Pokemon.
How about the style of art? Though ones art is an eyesore to others, it is a rule of the thumb to have a consistent style over a work. This also applies in games.
Try to consider the style of art implemented in the Mario Game. One cant help but notice the consistent cartoonish theme throughout the game.
How do I prepare animated 2D images for game processing? There are lots of ways to handle those, but one thing that is certain: Depending on the rate of speed, animated images have frames that changes over time.
In a sprite based-game, one way to handle animated sprites is to save all of frames into a single plane and program the game in such a way - it would just display a portion.
In the example above, each frame has a size of 196x196 pixels and the whole image can hold 6x5frames. Thus the whole size is about 1176x980;
What tools to use? Are there other resources ? There are lots of graphic editing programs existing out there that can help you make the art assets you need for your game.
In 2D - you may use paid software like Adobe Photoshop CS5, though I would prefer to use free ones such as GIMP and Paint.Net. Well sometimes, even the basic pbrush provided by the OS is enough.
In 3D again, you may use paid softwares like Maya, 3ds MAX. But if you just like to play around, try free ones like Blender.
On the other hand, If you dont like to make your own art assets, you may instead download and use other works made by other people - Though make sure you have their permission.
Usually, these kinds of works are called Royalty-free art assets. Try searching the terms royalty-free 2d sprite on Google. Sound When to start programming sounds in the game? Most of the time, the sounds are inserted after coding the art and gameplay If that is not a sign that sounds can be a lesser priority.
But of course, if the game revolves around sounds, it would be a different matter.
What tools to use? Are there other resources ? If you plan to create your own sounds for the game, again, you can use existing tools such as Audacity, or Guitar Pro
On the other hand, you may instead use others work. Just make sure you have their permission.
Game Programming
At what programming level are you willing to work?
There are actually different ways to program a game and it is a must for you to be aware of it. One way is to develop a game using Game Engines These are software designed to specifically to make games a lot easier, although with limitations on what a developer can create. Typically, developers will code lesser since the Game Maker already provides necessary features such as, 2D/3D graphics
rendering, Animation , Scenes, Events, Sounds, Collision Detection, Physics, and sometimes even an IDE. Usually, game engines have a primary programming language which is required developers to use if they wish to implement the said game engine. Usually, these programming language can be of the following: (C, C++, C#, Java, Lua, Python) There can be kinds of Game Engine out there, which are differentiated on their purpose: RPG Maker XP A game engine that focus primarily on making Role-Playing Games. Developers can code in Ruby programming language Aleph One A game engine for First Person Shooter (FPS), in C++; Unity An open-ended 3D game/interactive software engine for web, Windows, and Mac OS X. Upgrading to paid licenses can additionally enable support for the iPhone, Android, Nintendo Wii, Playstation 3, and the Xbox 360. Unreal Engine Considered one of the most popular game engines in the top market. The free edition, called UDK (a binary release of the engine), allows you to use the engine for commercial purposes under specific terms. CryEngine 3 CryEngine 3 is a new generation engine developed by Crytek to create the FPS game Crysis 2. The engine has been released recently, with a license model that is similar as offered by the UDK engine. On another hand, programmers can use Framework and Libraries instead These Frameworks and Libraries are similar with Game Engines, but are less specific with the features they provide, Thus coding can on it can be longer but has fewer limitations on what a game developer can create. Coding on a framework level may require developers to be familiarized with more programming concepts compared with Game Engines. It does not include physics, collision detection and other things often found in game engines. It is a game development framework, but how the game works is programmed entirely by you.
Examples: Microsoft XNA Framework - is a set of tools with a managed runtime environment provided by Microsoft that facilitates video game development and management
Microsoft DirectX - is a collection of application programming interfaces (APIs) for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay, DirectSound, and so forth.
Simple Directmedia Layer (SDL) - Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.
OpenGL - is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics.
Whatever tool/s you may end-up choosing to develop your game, be reminded that there is a learning curve to be considered - this is true, even with the most basic and simplest game engine out there. What concepts in programming should one know in order use those tools above?
Depending on what programming level you will develop the game and the tools you will use, it can be different.
As pointed out earlier, Game Engine, Frameworks and Libraries use different primary programming language for the implementation and Coding on a framework level may require developers to be familiarized with more programming concepts compared with Game Engines.
On a related note, since this document aims to build a space game in Microsoft XNA Framework, Ill be pointing out things I believe, you should be familiar in order for you create things on the said framework:
Basic C# Syntax - Primitive Data Types (int, float, double, bool, char, string) - Variables - Declaration - Primitive vs Reference variables - Operators - Arithmetic (+, -, *, / ) - Increment/Decrement (++, -- ) - Relational Operataors (<, <=, >, >=, ==, != ) - Logical Operators (&&, ||, !) - Control Structures - Decision Control Structures (if, if-else, if-elseif, switch) - Repetition Control Structures (for, while, dowhile, foreach) - Arrays - Object Oriented Programming - Classes vs Objects - Class and Object/Instance Variables - Class and Object/Instance Method - Properties - Class vs Abstract Class vs Interface - Concepts - Encapsulation - Inheritance - Polymorphism/Casting
Squid Invaders! Getting Started
Parts of a class (.cs)
using System; // Imports using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using Microsoft.Xna.Framework.Net; using Microsoft.Xna.Framework.Storage;
namespace Squid_Invaders // Project Name { public class Ship : Sprite { int lives; // Class Variables
public bool isAlive { // Class Properties get { return lives > 0; } }
public Ship(Texture2D texture) // Constructor Method :base(texture){
}
public void Update(GameTime gameTime) { //Class Methods
}
public override void Draw(SpriteBatch spriteBatch) { //Class Methods }
} }
XNA Program Flow
using Microsoft.Xna.Framework;
namespace Squid_Invaders { public class Game1 : Microsoft.Xna.Framework.Game { Ship player1; // Class Variables
public Game1() // Constructor
{ graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; }
Game Development Creating XNA Game Project Creating a Sprite Class Creating a Background Creating a Ship Class Creating a Player Ship Setting up Keyboard Adding Bullet Creating an Enemy Ship Adding AI to Enemy Shop Colliding Bullet Adding lives Adding GUI