How to Make a Game Like Space Invaders

  • Slides: 41
Download presentation
How to Make a Game Like Space Invaders

How to Make a Game Like Space Invaders

What IS Space Invaders? • a SHMUP (shoot-em-up) • Player has one ship, enemy

What IS Space Invaders? • a SHMUP (shoot-em-up) • Player has one ship, enemy has many • Player and enemies interact by shooting at each other • Top-down 2 D (usually)

Concepts

Concepts

Video Frames/Ticks • A film is made of 24 still pictures per second •

Video Frames/Ticks • A film is made of 24 still pictures per second • Motion is achieved by small changes to each picture, but 24 fps is still fast

Video Frames/Ticks 2 • Video games are usually 30 or 60 -80 fps •

Video Frames/Ticks 2 • Video games are usually 30 or 60 -80 fps • Video games achieve movement by moving each screen object a little bit every frame

Shmups are very objectoriented • • • Ships are objects Bullets are objects The

Shmups are very objectoriented • • • Ships are objects Bullets are objects The player is an object Explosions are objects Levels can be objects (certainly made of objects)

Question • How many bullets can be on the screen at once? • Space

Question • How many bullets can be on the screen at once? • Space Invaders = 1 for player, 2 for enemies • Modern = completely arbitrary

Lists • A great way to store and organize objects • Most beginners get

Lists • A great way to store and organize objects • Most beginners get hung up here • Conceptually harder than arrays • C and C++ use linked lists (with pointers) • Blitz. Basic has list: TList

What is a ship? • • Is-dead flag Health value X and Y positions

What is a ship? • • Is-dead flag Health value X and Y positions Path logic and data Reference to the art Animation state Bullet/missile launch state Bullets and Explosions are very similar to ships!

What is a player ship? • Not as much, surprisingly • Path logic is

What is a player ship? • Not as much, surprisingly • Path logic is in your fingers, not in code • So keyboard state checks (for avatar control) go here

What is a bullet/missile? • Like a ship, but (usually) simpler movement • Erased

What is a bullet/missile? • Like a ship, but (usually) simpler movement • Erased when it goes off screen, not when it reaches the end of its path • State: Player shot or Enemy shot • Each Player-bullet collides against every enemy • Each Enemy-bullet collides against player

So, to make space invaders… • Make a player • Make a bunch of

So, to make space invaders… • Make a player • Make a bunch of enemies • Move them every frame, have them create bullets • Move the bullets every frame • Check for enemy-bullet collision every frame • Keep going, even if all the enemies or the player is dead

Programming

Programming

Main loop in Pseudocode Main() { Setup. Everything(); Create. Player(); Create. All. Enemies(); done

Main loop in Pseudocode Main() { Setup. Everything(); Create. Player(); Create. All. Enemies(); done = false; while (done == false) { Tick. Player(); Tick. Enemy. List(); Tick. Bullet. List(); Draw. Player(); Draw. Enemy. List(); Draw. Bullet. List(); if (Escape. Key. Pressed() == TRUE) done = TRUE; Wait. For. Next. Frame(); } Shut. Down. Everything(); }

Timer callback version Timer. Function() { Tick. Player(); Tick. Enemy. List(); Tick. Bullet. List();

Timer callback version Timer. Function() { Tick. Player(); Tick. Enemy. List(); Tick. Bullet. List(); // some systems, like Flash and Torque, do the drawing for you Draw. Player(); Draw. Enemy. List(); Draw. Bullet. List(); if (Escape. Key. Pressed() == TRUE) done = TRUE; }

Tick. Bullet. List() { For. Each( bullet) { x = x + dx; y

Tick. Bullet. List() { For. Each( bullet) { x = x + dx; y = y + dy; if (Bullet. Off. Screen()) { is. Dead = TRUE; } For. Each(enemy) { if (Collides(enemy, bullet)) { is. Dead = TRUE; Damage. Enemy(enemy); } } } Remove. Dead. Bullets. From. List(); }

Basic Math

Basic Math

Vectors and Offsets • Where is your Ship? X and Y

Vectors and Offsets • Where is your Ship? X and Y

Vectors and Offsets 2 • Where is your bullet? Also X and Y •

Vectors and Offsets 2 • Where is your bullet? Also X and Y • Where is your bullet in relation to your ship? bullet. X – ship. X and bullet. Y – ship. Y

Vectors and Offsets 3 • How far apart are they? Pythagorean theorem (sqr(a) +

Vectors and Offsets 3 • How far apart are they? Pythagorean theorem (sqr(a) + sqr(b) = sqr(c)) • This requires a slow square root function

Vectors and Offsets 2 • What direction from the ship to the bullet? Arctangent

Vectors and Offsets 2 • What direction from the ship to the bullet? Arctangent • Atan 2(bullet. X – ship. X, bullet. Y – ship. Y)

Arctangent • Usually gives a direction in radians, from 0(2*PI) • PI is 3.

Arctangent • Usually gives a direction in radians, from 0(2*PI) • PI is 3. 1415927 (= 180 degrees) • Radian to degrees = dir / (PI*2) * 360

Vectors and Offsets 3 • So you can describe the relationship between two objects

Vectors and Offsets 3 • So you can describe the relationship between two objects on the screen in two different ways

Offsets • Offset = x and y coordinates (or differences)

Offsets • Offset = x and y coordinates (or differences)

Vectors • Vector = direction and distance

Vectors • Vector = direction and distance

Translate Offsets to Vectors • Get distance with Pythagoras • Get direction with Atan

Translate Offsets to Vectors • Get distance with Pythagoras • Get direction with Atan 2 (Arctangent)

Translate Vectors to Offsets • X = sin(direction) * distance • Y = cos(direction)

Translate Vectors to Offsets • X = sin(direction) * distance • Y = cos(direction) * distance

Vectors & Offsets = important • Shooting bullet directly at the player • Homing

Vectors & Offsets = important • Shooting bullet directly at the player • Homing missiles • Collision detection (is bullet close enough? ) • Enemy follows path

What is Turn. Towards. Point() • If you want the homing missile to turn

What is Turn. Towards. Point() • If you want the homing missile to turn slowly towards the enemy (instead of instantly) what do you do? • The answer is the Turn. Toward. Point() algorithm.

Designing Your Game

Designing Your Game

Bosses • Traditional part of shmups • Each one is a love letter to

Bosses • Traditional part of shmups • Each one is a love letter to the player • Multiple weapons • Multiple parts • Multiple Modes • It’s a boss, not just an extended enemy

Powerups • Functionally just like Bullets • Give expanded powers to the player •

Powerups • Functionally just like Bullets • Give expanded powers to the player • Key to one of the basic metagames

The Game Modes • Play mode • Start mode • Results mode (you are

The Game Modes • Play mode • Start mode • Results mode (you are dead, how’d you do) • Pause mode • Credits mode • Options mode

Game Modes 2 • Recognize that game modes are just states • Completely different

Game Modes 2 • Recognize that game modes are just states • Completely different states than game states

Scrolling Background • Space Invaders background was black • Galaga and others had winking,

Scrolling Background • Space Invaders background was black • Galaga and others had winking, scrolling stars • Zaxxon and others started making the background complex and interactive • Treasure games are famous for complex, puzzle-like environments

What are Shmup levels? • Hand-crafted definitions of when each enemy shows up •

What are Shmup levels? • Hand-crafted definitions of when each enemy shows up • The things that happen before a boss shows up • Divisions of art • Scoring opportunities

How are levels made? • Make the editors yourself, for yourself • Ship path

How are levels made? • Make the editors yourself, for yourself • Ship path editor (mirror-able) • Level editor • Place art tiles • Place ship spawn points • Place camera path • Boss editor

In Conclusion • Don’t be afraid, shmups are simple • Shmups are easier for

In Conclusion • Don’t be afraid, shmups are simple • Shmups are easier for small teams • Google and Youtube will teach you so much • Shmup dev concepts apply to other genres

Q&A • • • Shmup History Program Structure Math Game Modes Game Levels Bosses

Q&A • • • Shmup History Program Structure Math Game Modes Game Levels Bosses Powerup Systems Editors Selling your Shmup