This site requires JavaScript, please enable it in your browser!
Greenfoot back
Supersoprych
Supersoprych wrote ...

2019/4/20

Explotions

Supersoprych Supersoprych

2019/4/20

#
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.
N0way N0way

2019/4/20

#
post your code pls :D
Supersoprych Supersoprych

2019/4/20

#
heres what it looks like
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++; 
Supersoprych Supersoprych

2019/4/20

#
I figured It out I just Made a separate explosion actor here
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++;
    }
        
        }
  
 
Then in player you add this method
 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);                                  
            }  
    }
Supersoprych Supersoprych

2019/4/20

#
heres the Image if you want it [Disallowed URL]
You need to login to post a reply.