how to shoot fireball from direction my actor facing
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Wraith extends Actor
{
int animateImage = 0; //for walking animation image (frame)
int animateSpeed = 3; //lower the animate speed for faster walking animation
int count;
SimpleTimer spaceTimer = new SimpleTimer(); //timer for when the next space can be tekan lagi
public Wraith()
{
setImage("Wraith_01_Moving Forward_000.png");
getImage().scale(260,210);
}
public void act()
{
count++;
checkKeys();
//for movement restrict of wraith in the world
if(getX()>1200) setLocation(1200,getY());
if(getY()>550) setLocation(getX(), 550);
if(getY()<250) setLocation(getX(),250);
}
private void checkKeys()
{
if(Greenfoot.isKeyDown("w")) //for moveup
{
setLocation(getX(), getY()-5);
}
if(Greenfoot.isKeyDown("s")) //for movedown
{
setLocation(getX(), getY()+5);
}
if(Greenfoot.isKeyDown("d")) //for move right
{
setLocation (getX() +5, getY());
walkinganimateRight();
}
if(Greenfoot.isKeyDown("a")) //for move left
{
setLocation (getX() -5, getY());
walkinganimateLeft();
}
if(Greenfoot.isKeyDown("space") && spaceTimer.millisElapsed() > 1000)
{
shoot();
spaceTimer.mark(); //reset balik timer kepada 0
}
/*if(Greenfoot.isKeyDown(null)) //kalau tak tekan apa
{
}*/
}
public void walkinganimateRight()
{
if(count % animateSpeed == 0)
{
if(animateImage >11)
{
animateImage = 0;
}
setImage("Wraith_01_Moving Forward_00" + animateImage + ".png");
animateImage++;
getImage().scale(260,210);
}
}
public void walkinganimateLeft()
{
if(count % animateSpeed ==0)
{
if(animateImage >11)
{
animateImage = 0;
}
setImage("Wraith_01_Moving Forward_00" + animateImage + ".png");
animateImage++;
getImage().scale(260,210);
getImage().mirrorHorizontally();
}
}
public void shoot()
{
Fireball fireball = new Fireball();
getWorld().addObject(fireball, getX()+100, getY()); //masukkan fireball ke dalam world dan berjarak 100 pixels dari wraith
fireball.setRotation(getRotation());
}
}
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Fireball extends Actor
{
public Fireball()
{
setImage("blueFireball.png");
getImage().scale(80,80);
}
public void act()
{
move(10);
}
}

