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

2021/1/24

How to let a actor spawn a other actor at the same place?

GreenfootUser1234 GreenfootUser1234

2021/1/24

#
I am trying to make Bomberman but I don't know how to let the Bomberman spawn a bomb. I am new with java so could someone help me, please?
GreenfootUser1234 GreenfootUser1234

2021/1/24

#
This is the code I currently have of the Bomberman
public void act() 
    {
        move(0);
        if(Greenfoot.isKeyDown("right")) setLocation(getX()+3, getY());
        if(Greenfoot.isKeyDown("left")) setLocation(getX()-3, getY());
        if(Greenfoot.isKeyDown("down")) setLocation(getX(), getY()+3);
        if(Greenfoot.isKeyDown("up")) setLocation(getX(), getY()-3);
 }    
FirewolfTheBrave FirewolfTheBrave

2021/1/24

#
This line will spawn a bomb at the Bomberman's location:
this.getWorld().addObject(new Bomb(<any attributes that the bomb has>), this.getX(), this.getY());
GreenfootUser1234 GreenfootUser1234

2021/1/24

#
Thank you it works
RcCookie RcCookie

2021/1/24

#
Btw you can remove line 3 as it does nothing
You need to login to post a reply.