Wednesday, May 19, 2021

【GAMEMAKER】Horizontal Shooter

 Information about object: objPlayer

Sprite: sprPlayer
Solid: false
Visible: true
Depth: 0
Persistent: true
Parent:
Children:
Mask:
No Physics Object
Create Event:
set variable ShotTimer to 0
set the number of lives to 3
set variable global.ShieldTimer to 1500
Step Event:
execute code:

hspeed=0;
vspeed=0;
ShotTimer-=1;

if keyboard_check(vk_left) hspeed=-4;
if keyboard_check(vk_right) hspeed=4;
if keyboard_check(vk_up) vspeed=-4;
if keyboard_check(vk_down) vspeed=4;
if keyboard_check(ord("S")) and global.ShieldTimer>0 { 
  if instance_number(objShield)=0 {  
    instance_create(x+sprite_width+48,y,objShield);
  }
} else {
  with (objShield) instance_destroy();
}

if (x<5) x=5;
if (x>550)x=550;
if (y<5) y=5;
if (y>350)y=350;

if keyboard_check(vk_space) {
  if ShotTimer<0 {
    instance_create (x+sprite_width,y+sprite_height/2,objPlayerBullet);
    ShotTimer=10;
  }
}
Collision Event with object objEnemy:
create instance of object objExplode at relative position (0,0)
play sound sndExplode; looping: false
for all objEnemy: destroy the instance
for all objEnemyBullet: destroy the instance
set the number of lives relative to -1
Collision Event with object objEnemyBullet:
create instance of object objExplode at relative position (0,0)
play sound sndExplode; looping: false
for all objEnemy: destroy the instance
for all objEnemyBullet: destroy the instance
set the number of lives relative to -1
Other Event: No More Lives:
if the player does say yes to the question: Game Over## Would you like to play again?
      Restart the current room
else
      end the game

Information about object: objEnemy
Sprite: sprEnemy
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
start moving in directions 000100000 with speed set to 4
Step Event:
execute code:

if floor(random(50))=1 {
  instance_create(x,y+sprite_height/2,objEnemyBullet);
}
Collision Event with object objPlayerBullet:
create instance of object objExplode at relative position (0,0)
destroy the instance
for other object: destroy the instance
play sound sndExplode; looping: false
set the score relative to 10
Other Event: Outside Room:
destroy the instance
Information about object: objEnemyController
Sprite: sprController
Solid: false
Visible: false
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
set Alarm 0 to room_speed
Alarm Event for alarm 0:
create instance of object objEnemy at position (display_get_width(),random(room_height-96))
set Alarm 0 to random(room_speed*2)

Information about object: objPlayerBullet
Sprite: sprPlayerBullet
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
start moving in directions 000001000 with speed set to 8
Other Event: Outside Room:
destroy the instance
Information about object: objEnemyBullet
Sprite: sprEnemyBullet
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
start moving in directions 000100000 with speed set to 8
Other Event: Outside Room:
destroy the instance

Information about object: objExplode
Sprite: sprExplode
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Other Event: Animation End:
destroy the instance
Information about object: objShield
Sprite: sprShield
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Step Event:
execute code:

global.ShieldTimer-=1;

if (global.ShieldTimer<1) instance_destroy();
x=objPlayer.x+65;
y=objPlayer.y;
Collision Event with object objEnemy:
for other object: destroy the instance
Collision Event with object objEnemyBullet:
for other object: destroy the instance

No comments:

Post a Comment