Last active
August 29, 2015 14:01
-
-
Save edprince/a7aabcf54ac2629cad84 to your computer and use it in GitHub Desktop.
Getting enemy to switch costume and drop off screen when hit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//spr_EnemyDead is a speparate sprite that contains the image of the enemy rotated slightly. | |
//Trying to get enemy once hit, to switch to spr_EnemyDead and then fall off screen, at the moment, as soon | |
//as player bounces off head he switches back to alive sprite. | |
//Enemy Movement | |
hsp = dir * movespeed; | |
vsp += grav; | |
sprite_index = spr_enemy | |
//Horizontal Collision | |
if (place_meeting(x + hsp, y, obj_wall || obj_GravBlock)) | |
{ | |
while(!place_meeting(x + sign(hsp), y, obj_wall)) and sprite_index = spr_enemy | |
{ | |
x += sign(hsp); | |
} | |
hsp = 0 | |
dir *= -1 | |
} | |
//Movement through lava | |
if (place_meeting(x, y, obj_lava)) | |
{ | |
vsp = (vsp / 1.1); | |
} | |
if (place_meeting(x, y, obj_lava)) | |
{ | |
hsp = (hsp / 3); | |
} | |
x += hsp; | |
//Vertical Collision | |
if (place_meeting(x, y + vsp, obj_wall || obj_GravBlock)) and sprite_index = spr_enemy | |
{ | |
while(!place_meeting(x, y + sign(vsp), obj_wall)) | |
{ | |
y += sign(vsp); | |
} | |
vsp = 0 | |
} | |
y += vsp; | |
//Enemy Collision | |
if (place_meeting(x, y, obj_player)) | |
{ | |
if (obj_player.y < y-16) | |
{ | |
with (obj_player) vsp = -jumpspeed; | |
sprite_index = spr_EnemyDead; | |
} | |
else | |
{ | |
game_restart(); | |
} | |
} | |
else | |
{ | |
sprite_index = spr_enemy; | |
} | |
if sprite_index = spr_EnemyDead | |
{ | |
hsp = 0; | |
vsp = 2; | |
} | |
danprince
commented
May 27, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment