Hi,
My actor Bowser is unable to shoot a fireball in the direction it is facing. Does anyone know how to do this? Please note that the image 'fireball1.png' is facing right and I have another image called 'fireball2.png' facing left.
Here is my Bowser code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Fireball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Fireball extends Actor
{
private static final int SPEED=10;
/**
* Act - do whatever the Fireball wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{move(SPEED);
if(getX()>getWorld().getWidth()-3) {
getWorld().removeObject(this);
}
else {
Actor kingboo = getOneIntersectingObject(Kingboo.class);
if(kingboo !=null) {
getWorld().addObject(new Explosion(),getX(),getY());
getWorld().removeObject(kingboo);
getWorld().removeObject(this);
}
}
}
public Fireball()
{
setImage("fireball1.png");
}
}
Here is my Fireball code:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Fireball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Fireball extends Actor
{
private static final int SPEED=10;
/**
* Act - do whatever the Fireball wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{move(SPEED);
if(getX()>getWorld().getWidth()-3) {
getWorld().removeObject(this);
}
else {
Actor kingboo = getOneIntersectingObject(Kingboo.class);
if(kingboo !=null) {
getWorld().addObject(new Explosion(),getX(),getY());
getWorld().removeObject(kingboo);
getWorld().removeObject(this);
}
}
}
public Fireball()
{
setImage("fireball1.png");
}
}

