Download presentation
Presentation is loading. Please wait.
Published byIsabel Schmidt Modified over 11 years ago
1
How to Make a Game Like Space Invaders
2
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 2D (usually)
3
Concepts
4
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
5
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
6
Shmups are very object- oriented Ships are objects Bullets are objects The player is an object Explosions are objects Levels can be objects (certainly made of objects)
7
Question How many bullets can be on the screen at once? Space Invaders = 1 for player, 2 for enemies Modern = completely arbitrary
8
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) BlitzBasic has list:TList
9
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!
10
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
11
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
12
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
13
Programming
14
Main loop in Pseudocode Main() { SetupEverything(); CreatePlayer(); CreateAllEnemies(); done = false; while (done == false) { TickPlayer(); TickEnemyList(); TickBulletList(); DrawPlayer(); DrawEnemyList(); DrawBulletList(); if (EscapeKeyPressed() == TRUE) done = TRUE; WaitForNextFrame(); } ShutDownEverything(); }
15
Timer callback version TimerFunction() { TickPlayer(); TickEnemyList(); TickBulletList(); // some systems, like Flash and Torque, do the drawing for you DrawPlayer(); DrawEnemyList(); DrawBulletList(); if (EscapeKeyPressed() == TRUE) done = TRUE; }
16
TickBulletList() { ForEach( bullet) { x = x + dx; y = y + dy; if (BulletOffScreen()) { isDead = TRUE; } ForEach(enemy) { if (Collides(enemy, bullet)) { isDead = TRUE; DamageEnemy(enemy); } RemoveDeadBulletsFromList(); }
17
Basic Math
18
Vectors and Offsets Where is your Ship? X and Y
19
Vectors and Offsets 2 Where is your bullet? Also X and Y Where is your bullet in relation to your ship? bulletX – shipX and bulletY – shipY
20
Vectors and Offsets 3 How far apart are they? Pythagorean theorem (sqr(a) + sqr(b) = sqr(c)) This requires a slow square root function
21
Vectors and Offsets2 What direction from the ship to the bullet? Arctangent Atan2(bulletX – shipX, bulletY – shipY)
22
Arctangent Usually gives a direction in radians, from 0- (2*PI) PI is 3.1415927 (= 180 degrees) Radian to degrees = dir / (PI*2) * 360
23
Vectors and Offsets3 So you can describe the relationship between two objects on the screen in two different ways
24
Offsets Offset = x and y coordinates (or differences)
25
Vectors Vector = direction and distance
26
Translate Offsets to Vectors Get distance with Pythagoras Get direction with Atan2 (Arctangent)
27
Translate Vectors to Offsets X = sin(direction) * distance Y = cos(direction) * distance
28
Vectors & Offsets = important Shooting bullet directly at the player Homing missiles Collision detection (is bullet close enough?) Enemy follows path
29
What is TurnTowardsPoint() If you want the homing missile to turn slowly towards the enemy (instead of instantly) what do you do? The answer is the TurnTowardPoint() algorithm.
30
Designing Your Game
31
Bosses Traditional part of shmups Each one is a love letter to the player Multiple weapons Multiple parts Multiple Modes Its a boss, not just an extended enemy
32
Powerups Functionally just like Bullets Give expanded powers to the player Key to one of the basic metagames
33
The Game Modes Play mode Start mode Results mode (you are dead, howd you do) Pause mode Credits mode Options mode
34
Game Modes 2 Recognize that game modes are just states Completely different states than game states
35
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
36
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
37
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.