My game loop is structured like this:
update
draw
checkforcollision
sleep
I want to draw the death animation in my draw method but the problem is
by the time I check for collision, the draw method already been executed which
means it won't execute this draw code in my Ghost class.
// if ghost is in a dead state
if(getDeadState())
{
g.drawImage(ghostMovementAnimation.get(3), (int)position.getX(), (int)position.getY(), null);
}
The code posted below is in my Laser class.
Quick explanation of my collision code:
if collision is valid, remove the laser
set monster dead state to be true
remove the monster
/* check the intersection of the laser's rectangle and all the monster's
* rectangle. If both rectangles intersects, it is a collision
*/
if(rectangle.intersects(((Collidable) component).getRectangle()))
{
// remove laser upon monster contact
Game.getInstance().remove(this);
// set monster to be dead
monsterIsDead = true;
// set monster to be dead
((Monster) component).setDeadState(monsterIsDead);
// remove the monster upon contact of the laser
Game.getInstance().remove(component);