Hey guys. I am in a struggle again. I have a shooter that shoots bullets. But the bullets are not added the place i want them to. it's a bit difficult to explain, so i made some pictures to explain it
Here is how my shooter shoots right now: http://imgur.com/GAk34cR,5Amf7Xb#0
Here is how i WANT my shooter to shoot(the red line): http://imgur.com/GAk34cR,5Amf7Xb#1it
And here is my current code for my shooter:
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Skydemand here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Skydemand extends SmoothMover
{
int change = 0;
int speed = 2;
SkydemandPoint skydemandPoint = new SkydemandPoint();
GreenfootSound swap = new GreenfootSound("swap.wav");
GreenfootSound clockwiseMove = new GreenfootSound("ClockwiseMove.wav");
GreenfootSound counterClockwiseMove = new GreenfootSound("CounterClockwiseMove.wav");
GreenfootSound shooting =new GreenfootSound("Shooting.wav");
/**
* Act - do whatever the Skydemand wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
moving();
checkKeys();
}
private void checkKeys()
{
String key = Greenfoot.getKey();
if("space".equals(key))
{
fire();
}
if ("w". equals(key))
{
change=change+180;
swap.play();
}
if ("s". equals(key))
{
change=change-180;
swap.play();
}
}
/**
* moving the object
*/
private void moving()
{
if (Greenfoot.isKeyDown("d"))
{
change=change+speed;
clockwiseMove.play();
clockwiseMove.setVolume(75);
}
if (Greenfoot.isKeyDown("a"))
{
change=change-speed;
counterClockwiseMove.play();
counterClockwiseMove.setVolume(70);
}
setRotation(change);
setLocation(getWorld().getWidth()/2, getWorld().getHeight()/2);
move(65);
}
/**
* Fire the cannon
*/
private void fire()
{
ZombieWorld zombieWorld = (ZombieWorld)getWorld();
Bullet bullet = new Bullet(zombieWorld.skydemandPoint);
getWorld().addObject(bullet,getX(),getY());
bullet.setRotation(getRotation());
bullet.move(40.0);
shooting.play();
}
}
