Tuesday, June 1, 2021

【GAMEMAKER】Shows how to display the players score above their head, as they move around

 Information about object: objPlayer

Sprite: sprStand
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask: sprStand
No Physics Object
Create Event:
set variable ShotTimer to 0
set variable BulletType to 6
set variable sprite to sprStand
Step Event:
execute code:

hspeed=0;
vspeed=0;

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 hspeed<0 && vspeed=0 {
  sprite=sprWest;
  BulletType=4;
}
if hspeed<0 && vspeed<0 {
  sprite=sprNorthWest;
  BulletType=3;
}

if hspeed<0 && vspeed>0 {
  sprite=sprSouthWest;
  BulletType=5;
}

if hspeed>0 && vspeed=0 {
  sprite=sprEast;
  BulletType=0;
}
if hspeed>0 && vspeed<0 {
  sprite=sprNorthEast;
  BulletType=1;
}
if hspeed>0 && vspeed>0 {
  sprite=sprSouthEast;
  BulletType=7;
}

if hspeed=0 && vspeed<0 {
  sprite=sprNorth;
  BulletType=2;
}
if hspeed=0 && vspeed>0 {
  sprite=sprSouth;
  BulletType=6;
}

sprite_index = (sprite);

if hspeed!=0 or vspeed!=0 {
  image_single=-1;
} else {
  image_single=1;
}
set variable ShotTimer relative to -1
Collision Event with object objEnergy:
for other object: destroy the instance
set the score relative to 10
Keyboard Event for <Alt> Key:
if expression ShotTimer<0 is true
      create instance of object objOtherBullet at relative position (0,0)
      set variable ShotTimer to 25
Keyboard Event for <Space> Key:
if expression ShotTimer<0 is true
      create instance of object objBullet at relative position (0,0)
      set variable ShotTimer to 25
Draw Event:
execute code:

draw_sprite(sprite,-1,x,y)
draw_text(x-5,y-10,"Score: "+string(score));

Information about object: objBullet
Sprite: sprBullet
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:

if objPlayer.BulletType=4 sprite_index = (sprBulletW);
if objPlayer.BulletType=3 sprite_index = (sprBulletNW);
if objPlayer.BulletType=5 sprite_index = (sprBulletSW);

if objPlayer.BulletType=0 sprite_index = (sprBulletE);
if objPlayer.BulletType=1 sprite_index = (sprBulletNE);
if objPlayer.BulletType=7 sprite_index = (sprBulletSE);

if objPlayer.BulletType=2 sprite_index = (sprBulletN);
if objPlayer.BulletType=6 sprite_index = (sprBulletS);
set speed to 8 and direction to objPlayer.BulletType*45
Other Event: Outside Room:
destroy the instance

Information about object: objOtherBullet
Sprite: sprBullet
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
set speed to 8 and direction to objPlayer.BulletType*45

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

No comments:

Post a Comment

FIFI FW Discount Tickets for WordPress Subscribers

  Hello Fashion Blog Subscribers:   Did you know that because you are a subscriber to t...