IPT - A Virtual Approach IPT A Virtual Approach by Peter Whitehouse
Quick Links:
 
 
Information and Intelligent Systems Social and Ethical Implications Human Computer Interaction Software and Systems Engineering eXercise Files Course Outline and Assessment A-Z of Geeky Acronyms Terrace Work Program 2004 Sillybus FAQ = Frequently Asked Questions Help
 
 

Game 2

A Space Shoot'em'up
using Game Maker

Some verbal Instructions (stuff bolded is what you have to type).....

 setup

new folder - call it shump

new game in gamemaker- call it shootemup

now adding bits the game will use:

add sprite -> name = playerSprite, graphic = K:\gamemaking\res01\sprites\space\ship3.bmp
(make sure it is transparent)

add sprite -> name = bulletsprite, graphic = K:\gamekaking\res02\sprites\pack2\fireicon.gif
(make sure it is transparent)

add background -> name = level1background, graphic = k:\gamemaking\res01\backgrounds\space2.jpg

add sound -> name = shotsound, sound = k:\gamemaking\res01\sounds\effects01\laser.wav

Add resources to game

add object (a 'smart' thing) ->name = playerobject, make its sprite = playersprite

add object -> name = bulletobject, make its sprite = bulletsprite

Create a ROOM - change it's name to "level1", change it's caption to "Space The Final Frontier" (this is where the action will take place) then goto backgrounds of the room, tick visible when room starts, select level1background

Add a playerobject to the room (near centre bottom)

now to make the ship fly around

open playerobject
add event -> keyboard -> <left> .... action is code -> execute a piece of code
x := x - 5;

save, test

add event -> keyboard -> <right> .... action is code -> execute a piece of code
y := y + 5;

save, test

now add suitable events for up and down

save, test

now to bullets

add event for playerobject
keyboard -> <space> .... find create instance of object (in main2), select bulletobject, tick relative

we have to make the spawned bullet move
open the bullet object - add event - create
run a bit of code:
hspeed := 0;
vspeed := -8;
(we want it to travel a little faster than the ship)

unless we expire it, each bullet spawned keeps travelling (and consumes memory)
add event on bulletobject = other -> outsideroom
find destroyinstance (dynamite)

save, test

refine bullet action

when you try this,the bullet emanates from the left enginey thing. to move the spawn point of the bullet, go back to the playerobject create instance event and change
x: playerobject.x+35
y: playerobject.y

this should make the bullet spawn from the nose of the spaceship (unless you have chosen a different sprite).

save, test

test for understanding

we want different weapons to sprout from the tip of the left wing
can you do it?
load a sprite
make an object
create an instance of it at the press of the "Z" key and make it move up+left
extinguish it when it is outsideroom.

More realistic firing

More realistic fire can use an alarm event. You can set alarm events to go off after a pre-set number of frames (a timer-like event).

Go backto the playerobject and add a create event and in it, run a bit of code:
gunready := true;

this creates and initialises a variable saying it is ready to fire. Each time we fire, we will, for a short time, disenable the gun (10 frames, say). If the game is playing at 30fps then the gun can be fired 3 times a second.

delete the action for the SPACE BAR and replace it with a bit of code instead:

if gunready
   then begin
                 instance_create(playerobject.x+32,playerobject.y, bulletobject);
                 gunready := false;
                 alarm[0] := 10;
            end

add an event for playerobject: alarm[0]
run a bit of code and type in:
gunready := true;

save, test

Adding a single Enemy

Add a SPRITE - call it ENEMYSPRITE, get it from K:\gamemaking\res01\sprites\space\ufo2.gif (it is a cute animated gif).

Add an OBJECT - call it enemy1object, associate the sprite with it.

Goto the ROOM, add an enemy object to near the top edge of the room screen.

Goto the enemyobject, add an oncreate event that runs a bit of code:
hspeed := random(5);
vspeed := random(5);

Add a collision event with bulletobject to enemyobject and run a bit of code:
x:= random(640);
y := 0;
hspeed := random(5);
vspeed := random(5);

this will make the enemy ship reappear at the top of the screen after it has been hit, travelling on a new path

Add an other -> outside room event to the enemyobject and run a bit of code:
x:= random(640);
y := 0;

this will make the enemy spaceship re-appear when it flies offscreen but will ensure it stays on the course it was on

save, test

Finally, add a collision event to the bulletobject so that when it hits the enemyobject it destroys the instance also, otherwise the bullet appears to pass right through the enemy.

 

Can you add a sound to the "hit" to reward the player for aiming well?

How about keeping track of the score?

How about adding "lives" for the playerobject?

   Read more.... or play so far
goto TOP
BACK FORWARD
goto HOME

 

 

wonko@wonko.info
©Copyright t 1992..2018+. Edition 26.150117
wonkosite
Creative Commons License
This work is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 2.1 Australia License
.