I need help with when my player dies. Either the ship explodes and doesn't respawn; or the ship respawns and the ship doesn't explode. I wold like for both the explotion and the ship to respawn.
private int timer=0;
if(isTouching(Enemy.class))
{
Life.addLife(-1);
removeTouching(Enemy.class);
getWorld().addObject(new Explotion(),getX(),getY());
Greenfoot.playSound("DSExplod.wav");
getWorld().removeObject(this);
if (timer==10)
{
timer=0;
Greenfoot.setWorld(new MyWorld());
if (Life.getLife()==0)
{
Greenfoot.setWorld(new StartUp());
Life.resetLife();
}
}
}
timer++; import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* simulates explotion.
*
* @author (Supersoprych)
* @version (1.0)
*/
public class EnemyExplotion extends Enemy
{
/**
* Act - do whatever the Explotion wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private GifImage gif;
private int timer=0;
public EnemyExplotion()
{
gif=new GifImage("explode.gif");
getImage().scale(20,20);
}
public void act()
{
setImage(gif.getCurrentImage());
if(timer>40)
{
getWorld().removeObject(this);
}
timer++;
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* simulates explotion then resets
* if the number of lives is equal to zero it goes to start screen.
*
* @author (Supersoprych)
* @version (2.0)
*/
public class PlayerExplotion extends Player
{
/**
* Act - do whatever the PlayerExplotion wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private GifImage gif;
private int timer=0;
public PlayerExplotion()
{
gif=new GifImage("explode.gif");
}
public void act()
{
setImage(gif.getCurrentImage());
if(timer>40)
{
getWorld().removeObject(this);
}
if (timer>30)
{
timer=0;
Greenfoot.setWorld(new MyWorld());
if (Life.getLife()==0)
{
Greenfoot.setWorld(new StartUp());
Life.resetLife();
}
}
timer++;
}
}
public void hit()
{
if(isTouching(Enemy.class))
{
Life.addLife(-1);
removeTouching(Enemy.class);
getWorld().addObject(new PlayerExplotion(),getX(),getY());
Greenfoot.playSound("DSExplod.wav");
getWorld().removeObject(this);
}
}