How do you make an enemy hide or disappear when hit?
I am still pretty new and I do not how to do this yet if someone can help me. that would be nice. :)
I am still pretty new and I do not how to do this yet if someone can help me. that would be nice. :)
stop drawing the enemy when it's hit.
what do you mean? like in code can you show me.
Okay, so lets say you have the following object somewhere:
enemy = object
hp = 15
defeated = false
x = 0
y = 0
end
Then you can do this in the drawing function:
if not enemy.defeated then
screen.drawSprite("enemy",enemy.x,enemy.y)
end
While classes are better in this case, this should showcase it well.
Yeah @confusedcatgirl explains it well.
If you wanted an enemy to stop appearing just stop drawing it all together.
Code example:
enemy = class
constructor = function(x,y)
this.x = x
this.y = y
hp = 100
dead = false
end
update = function()
*what you want about the enemy to update*
if hp <= 0 then
dead = true
end
end
draw = function()
if not dead then
screen.drawSprite( *enemy stuff here...* )
end
end
end
thanks guys. thank you so much. :)