Wednesday, May 26, 2021

【GAMEMAKER】Mouse Shoot shows how to use the mouse as a crosshair to aim your shots

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

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

if hspeed>0 && vspeed=0 {
  BulletType=0;
}
if hspeed>0 && vspeed<0 {
  BulletType=1;
}
if hspeed>0 && vspeed>0 {
  BulletType=7;
}

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

if mouse_x>x and mouse_y<y+10 and mouse_y>y-10 then sprite=sprEast;
if mouse_x<x and mouse_y<y+10 and mouse_y>y-10then sprite=sprWest;
if mouse_y>y and mouse_x<x+10 and mouse_x>x-10then sprite=sprSouth;
if mouse_y<y and mouse_x<x+10 and mouse_x>x-10then sprite=sprNorth;

if mouse_x>x+10 and mouse_y>y+10 then sprite=sprSouthEast;
if mouse_x>x+10 and mouse_y<y-10 then sprite=sprNorthEast;
if mouse_x<x-10 and mouse_y>y+10 then sprite=sprSouthWest;
if mouse_x<x-10 and mouse_y<y-10 then sprite=sprNorthWest;

sprite_index = (sprite);

if hspeed!=0 or vspeed!=0 {
  image_single=-1;
} else {
  image_single=1;
}

if mouse_button=mb_left {
  if ShotTimer<0 {
    instance_create(x,y,objBullet);
    ShotTimer=25;
  }
}
set variable ShotTimer relative to -1

Information about object: objBullet
Sprite: sprBullet
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Create Event:
start moving in the direction of position (mouse_x,mouse_y) with speed 8
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:
start moving in the direction of position (mouse_x,mouse_y) with speed 8

Information about object: objCrossHair
Sprite: sprCrossHair
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Children:
Mask:
No Physics Object
Step Event:
set variable x to mouse_x-sprite_width/2
set variable y to mouse_y-sprite_height/2

No comments:

Post a Comment

End of Summer Sale ☀️😎

20% OFF Inside!🤯 ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏  ͏...