Showing posts with label 【GAMEMAKER】Hearts. Show all posts
Showing posts with label 【GAMEMAKER】Hearts. Show all posts

Monday, May 17, 2021

【GAMEMAKER】Hearts

 Information about object: objHeart

Sprite: sprHeart
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Information about object: objPlayer
Sprite: sprPlayer
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
COMMENT: Set the initial number of hearts the player has
set variable Hearts to 3
COMMENT: Set the initial number of lives a player has
set the number of lives to 15
Step Event:
COMMENT: Just generic move code
execute code:

if keyboard_check(vk_left) then x-=4;
if keyboard_check(vk_right) then x+=4;
if keyboard_check(vk_up) then y-=4;
if keyboard_check(vk_down) then y+=4;
Collision Event with object objHeart:
COMMENT: Check to make sure they dont already have 3 hearts
if expression Hearts<3 is true
      COMMENT: Add one heart, since they have less than 3
      set variable Hearts relative to 1
COMMENT: Remove the heart, since the just used it. 
COMMENT: If you want the heart to NOT dissapear if they can not use it
COMMENT: Move this destroy event ABOVE the end block icon above
for other object: destroy the instance
Collision Event with object objEnemy:
COMMENT: Take 1 heart away from the player
set variable Hearts relative to -1
COMMENT: Chek to see if hearts=0 (We just took their last heart)
if expression Hearts=0 is true
      COMMENT: Their last heart was taken, so....
      COMMENT: Remove 1 life
      COMMENT: No More Lives event will occur if no lives are left
      COMMENT: Right click OUTSIDE to find the No More Lives event
      set the number of lives relative to -1
      COMMENT: Set their hearts back to 3 for this next life
      set variable Hearts to 3
COMMENT: Get rid of the object that just took our life
for other object: destroy the instance
Other Event: No More Lives:
COMMENT: Tell them they are out of lives
display message: No More Lives
COMMENT: Restart the game
restart the game

Information about object: objEnemy
Sprite: sprEnemy
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object

Information about object: objController
Sprite: sprController
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Draw Event:
COMMENT: Variable used to position the hearts we are drawing for the player
set variable HeartNum to 1
COMMENT: Repeat the following for each heart the player has
repeat next action (block) objPlayer.Hearts times
      COMMENT: Increase the temporary heart counter by 1
      set variable HeartNum relative to 1
      COMMENT: Draw a heart at upper right corner, offset by the heartnum*32 pixels
      at position (400+(HeartNum*32),0) draw image -1 of sprite sprHeart