by Ben Tyers
The sprite for this is shown in Figure 7_48:
Figure 7_48: Showing sprite spr_asteroid_large
Create Event
/// @description Set Movement
ang=irandom_range(150,210);
x=room_width+200;
y=irandom_range(100,room_height-100);
motion_set(ang,4);
rot=choose(-1,1);
Sets a random angle between 150 and 210 (30’ each way from 180’), sets the start location 200 pixels off of the right side of the window, and a random y position between 100 and room height less 100. Sets moving at a speed of 4, and rotation clockwise or anti-clockwise.
Step Event
/// @description Rotate
image_angle+=rot;
Rotates each step.
Collision With obj_player Event
/// @description Damage player if no shield
if other.shield>0
{
coin=instance_create_layer(x,y,"Player",obj_coin_bubble);
coin.value=60;
instance_destroy();
}
else
{
audio_play_sound(snd_lose_health,1,false);
health-=3;
other.flash=true;
other.alarm[0]=room_speed/2;
instance_destroy();
}
When it collides with player, checks for shield. If shield is active it makes a coin bubble instance and destroys itself. If the shield is not active the player loses health, shows damage and the asteroid is destroyed.
Collison With obj_player_weapon_parent Event
/// @description Damage Control
ast=instance_create_layer(x,y,"Asteroid",obj_asteroid_medium);
ast.direction=direction-20;
ast.speed=speed+1;
ast.rot=rot*-2;
ast=instance_create_layer(x,y,"Asteroid",obj_asteroid_medium);
ast.direction=direction+20;
ast.speed=speed+1;
ast.rot=rot*-2;
with other instance_destroy();
instance_destroy();
If hit by a player’s primary weapons, two new smaller asteroids are created, the projectile is destroyed and the current asteroid is destroyed.
obj_asteroid_medium
A medium asteroid that the player can shoot at. If shot it creates smaller asteroids. Damages player if player hits it.
Figure 7_49 shows the sprite set up for this object.
Figure 7_49: Showing spr_asteroid_medium
Step Event
/// @description rotate
image_angle+=rot;
Collision With obj_player_weapon_parent Event
/// @description Damage Control
ast=instance_create_layer(x,y,"Asteroid",obj_asteroid_small);
ast.direction=direction-20;
ast.speed=speed+1;
ast.rot=rot*-2;
ast=instance_create_layer(x,y,"Asteroid",obj_asteroid_small);
ast.direction=direction+20;
ast.speed=speed+1;
ast.rot=rot*-2;
with other instance_destroy();
instance_destroy();
Creates 2 new small asteroids, and destroys projectile and self.
Collision With obj_player Event
/// @description Damage Player If no Shield
if other.shield>0
{
coin=instance_create_layer(x,y,"Player",obj_coin_bubble);
coin.value=30;
instance_destroy();
}
else
{
audio_play_sound(snd_lose_health,1,false);
health-=3;
other.flash=true;
other.alarm[0]=room_speed/2;
instance_destroy();
}
Checks for player’s shield and act accordingly.
obj_asteroid_small
A small asteroid that the player can shoot at. If shot it creates a coin bonus instance for the player to collect. Damages player if player hits it
Figure 7_50 shows the sprite for this object:
Figure 7_50: Showing sprite set up for spr_asteroid_small
Create Event
/// @description Set Up
image_speed=0;
image_index=irandom(5);
Prevents animation and chooses a random sub image.
Step Event
/// @description Rotate
image_angle+=rot;
Rotates in the given direction (when created by obj_asteroid_medium)
Collision With obj_player Event
/// @description Damage Player if no shield
if other.shield>0
{
coin=instance_create_layer(x,y,"Player",obj_coin_bubble);
coin.value=15;
instance_destroy();
}
else
{
health-=1;
other.flash=true;
other.alarm[0]=room_speed/2;
audio_play_sound(snd_lose_health,1,false);
instance_destroy();
}
Creates a coin or damages player, depending if the player’s shield is active or not.
Collision With obj_player_weapon_parent Event
/// @description Make Coin
coin=instance_create_layer(x,y,"Player",obj_coin_bubble);
coin.value=20;
with other instance_destroy();
instance_destroy();
Creates a coin instance if hit by player’s primary weapons.
obj_spawn_poles
Creates foreground instances to create a better parallax effect.
Create Event
/// @description Set an Alarm
alarm[0]=(room_speed*10)+irandom(room_speed*10);
Alarm 0 Event
/// @description Spawn obj_pole
alarm[0]=(room_speed*10)+irandom(room_speed*10);
instance_create_layer(room_width+300,room_height/2,"Foreground",obj_pole);
obj_pole
A foreground object that moves across the window, and moves up and down in relation the player’s movement.
Figure 7_51 shows the sprite set up for this object:
Figure 7_51: Showing sprite set up for spr_post
Create Event
/// @description Set Up
hspeed=-6;
image_speed=0;
image_index=irandom(8);
Moves left at a speed of 6. Prevents animation and chooses a random sub_image.
Step Event
/// @description Check & change position
if x<-1000 instance_destroy();
player=obj_player.y
y=(room_height/2)-player+550;
Moves up and down, taking into account the player’s y position.
obj_info
Tells the player what the bonus they collected does.
Figure 7_52 shows the sprites and set up for this object:
Figure 7_52: Showing spr_info
Create Event
/// @description Set Up
image_speed=0;
alarm[0]=room_speed*5;
x=room_width/2;
y=room_height/2;
Prevent automatic animation, set an alarm for 5 seconds, and position in middle of the window.
Alarm 0 Event
/// @description Destroy
instance_destroy();
Destroys self when alarm triggers.
obj_cursor
Follows the player around the room, used for one of the playar’s weapons. Also draws the locked-on sprite on the nearest enemy (if upgraded and an enemy instance exists).
There is no sprite assigned to this object, though it does use a few. This is shown in Figure 7_53:
Figure 7_53: Showing sprite spr_sight
Figure 7_54 shows sprite spr_lock
Figure 7_54: Showing sprite spr_lock
Create Event
/// @description Set Defualt Cursor
cursor_sprite=spr_sight;
Tells th
e program to set the cursor to sprite spr_sight.
Step Event
/// @description Update Position
x=mouse_x;
y=mouse_y;
Updates the location to the current mouse’s position.
Draw Event
/// @description Lock On
if instance_exists(obj_enemy_parent) and global.level>12
{
nearest=instance_nearest(x,y,obj_enemy_parent);
draw_sprite(spr_lock,0,nearest.x,nearest.y);
}
Will draw the lock on sprite if player’s level is over 12, at the nearest enemy location.
obj_spawner
This will spawn shield and upgrade bonus instances.
There is no sprite for this object.
Create Event
/// @description Set Alarms
alarm[0]=room_speed;//shield
alarm[1]=room_speed;//power power up
Sets some initial alarms.
Alarm 0 Event
/// @description Create a Shield Bonus
instance_create_layer(room_width+200, random_range(100,room_height-100),"Player",obj_shield_collect);
alarm[0]=room_speed*40;
Creates a shield for the player to try and collect, restarts the alarm.
Alarm 1 Event
/// @description Create Power Up
instance_create_layer(room_width+200, random_range(100,room_height-100),"Player",obj_power_up);
alarm[1]=room_speed*35;
Creates a power up for the player to try and collect, restarts the alarm.
obj_asteroid_spawn
Periodically spawns asteroids.
There is no sprite for this object.
Create Event
/// @description Set an Alarm
alarm[0]=room_speed*6;
Sets the initial alarm.
Alarm 0 Event
/// @description Make asteroid and restart alarm
alarm[0]=room_speed*6;
instance_create_layer(x,y,"Asteroid",obj_asteroid_large);
Restarts the alarm, creates an asteroid object.
obj_hud_control
Draws a background images, and info needed for the player (is drawn semi-transparent).
There is no sprite assigned for this object, though it does use one, which is shown below in Figure 7_55:
Figure 7_55: Showing sprite spr_hud
Create Event
/// @description Stop & Play Music
audio_stop_sound(snd_music_menu);
audio_play_sound(snd_music_game,1,true);
Stops any music and player the music for the game room.
Step Event
/// @description Format Score & Save on Gameover If New Highscore
score_text=string(score);
while string_length(score_text)<6 score_text="0"+score_text;
hiscore_text=string(global.highscore);
while string_length(hiscore_text)<6 hiscore_text="0"+hiscore_text;
///check health;
if health<0
{
if score>global.highscore//do this if bigger than current score
{
ini_open("scores.ini");//open ini
ini_write_real("scores","high",score);//write a value
ini_close();//close value
global.highscore=score;//update highscore
global.saved=true;
}
room_goto(room_gameover);
}
This formats the text for the score and highscore. It checks the players health (a global value) and if the player is dead it updates the saved highscore. It then goes to the gameover room.
Draw Event
/// @description Draw HUD
draw_set_font(font_menu);
draw_set_colour(c_black);
draw_set_halign(fa_center);
draw_set_valign(fa_middle);
draw_set_alpha(0.5);
draw_sprite(spr_hud,0,0,0);
draw_text(200,40,"Score "+string(score));
draw_text(200,80,"Highscore "+string(global.highscore));
draw_text(600,40,"Level "+string(global.level));
draw_text(600,80,"Power "+string(global.pow));
if obj_player.shield>0
{
draw_text(1000,40,"Shield Active");
}
else
{
draw_text(1000,40,"No Shield");
}
draw_text(1000,80,"Health "+string(health));
draw_set_alpha(1);
Sets style for text drawing and sets the alpha to 50%. Draws HUD image all HUD text and then sets alpha back to normal value.
This Section Is For The Game Over Room
obj_game_over
Will display player’s score and highscore, then goto the starting room.
There is no sprite for this object.
Create Event
/// @description Set alarm and change music
alarm[0]=room_speed*6;
audio_stop_all();
audio_play_sound(snd_music_gameover,1,true);
Sets an alarm to 6 seconds, stops music and plays music for gameover room on loop.
Alarm 0 Event
/// @description Goto Game Start room
room_goto(room_splash);
Goes back to menu room when alarm is triggered.
Draw Event
/// @description Draw Score Info
draw_set_colour(c_white);
draw_text(room_width/2,400,"Score "+string(score));
draw_text(room_width/2,500,"Highscore "+string(global.highscore));
Sets drawing style and draws player’s score and highscore.
Rooms
This game has a few rooms, the setups are shown below
room_splash
This room has a size of 1300 wide and a height of 768.
It has a single instance of obj_splash.
room_menu
This room has a size of 1300x768.
It has a number of layers as shown in Figure 7_56:
Figure 7_56: Showing the layers for room_menu
The Player layer has one instance of obj_player_menu placed on it.
The Menu layer has one of obj_menu and one of obj_buttom.
Figure 7_57 shows these instances placed in the room:
Figure 7_57: Showing instances placed in the room
This room also has 3 backgrounds, used for a parallax effect.
Figure 7_58 shows the setting for bg_1:
Figure 7_58: Showing background setting for bg_1
Background bg_2 is set with a y offset of -100 and horitonal speed of -2.
Background bg_3 is set with a y offset of 200 and horitonal speed of -1.
Figure 7_59 shows the room with backgrounds and instances in place:
Figure 7_59: Showing room set up
room_intro
This room has a size of 1300 x 768.
Is has one instance of obj_intro_control and one of obj_emitter.
room_how_play
This room has a size of 1300 x 768.
Is has one instance of obj_how_to_play and one of obj_emitter.
room_game
This room has a dimension of 1300 by 768. It has many layers, as shown in Figure 7_60:
Figure 7_60: Showing layers for room_game
The Foreground layer has:
obj_spawn_poles
obj_cursor
The Score_Effect layer has no instances present at room start.
The Asteroid layer has:
obj_asteroid_spawn
The Player layer has:
obj_player
obj_hud_control
obj_spawner
The Missile layer has instances when the room starts.
The Enemy_Cannon layer has no instances.
The Enemy_Ball layer has no instances.
The Enemy layer has no instances.
The Enemy_Missile layer has no instances.
The Instances layer has no instances.
&n
bsp; Backgrounds are set up in the same way as the menu room.
The Foreground layer has:
obj_spawn_poles
obj_cursor
The Foreground layer has:
obj_spawn_poles
obj_cursor
room_gameover
This room has a size of 1300 x 768.
Is has one instance of obj_game_over.
Paths
This game uses two paths, as shown in Figure 7_61 and Figure 7_62:
Figure 7_61: Showing path set up for path_circle
Figure 7_62: Showing path set up for path_boss
Audio
This game uses sound audio, all from SoundImage.org. Figure 7_63 shows the sounds used in this game.
Figure 7_63: Showing sounds
There is a playable exe version of this game in the download.
There is also a skeleton project with all the code and instances set up, but with no sprites.
All sprites for the game are from:
GameDeveloperStudio.com
Chapter 8 Final Testing
The final stage is to make some final checks and make sure everything is working and correctly set up. Ideally there should only be minor tweaks required at this point. You should check for the following:
Audio does not have any blank sound at start or end
Texture pages are set large enough for over sized graphics you may have used
Variables change as expected
You are using the correct variable types (i.e. local, global or var)
Collision boxes are set up according to the sprite and how it behaves