So I have a scenario ive been working on in which there is a plane which you control and then a few other enemy planes which move randomly, I intend to eventually make bullets be able to fire from the plane and damage the enemies. So far I am stuck at getting the bullet to face the same direction as the plane.
This is the code I have so far
I have 2 others which are the enemy plane script and a bomb script to drop bombs for a later feature. Please if someone could tell me how I can make the bullet be at the same rotation of the plane at the time of firing. any help will be appreciated, let me know if you don't understand whats going on.
//Plane script
import greenfoot.*;
public class Plane extends Actor
{
int speed = 0;
int bombPlaced = 0;
public Plane(){
GreenfootImage image = getImage();
image.scale(75, 75);
setImage(image);
}
public void act()
{
rotation = getRotation();
bombPlaced = bombPlaced + 1;
if (Greenfoot.isKeyDown("left")){
turn(-5);
}
if (Greenfoot.isKeyDown("right")){
turn(5);
}
if (Greenfoot.isKeyDown("up") && speed < 65){
speed = speed + 1;
}
if (Greenfoot.isKeyDown("down") && speed >= 0){
speed = speed - 1;
}
move(speed / 10);
if ((speed > 0) && !(Greenfoot.isKeyDown("up"))){
speed = speed - 1;
}
if (Greenfoot.isKeyDown("space") && bombPlaced > 40){
getWorld().addObject(new Bomb(), getX(), getY());
bombPlaced = 0;
}
if (Greenfoot.isKeyDown("shift")){
getWorld().addObject( new Bullet(), getX(), getY());
}
}
}
//Bullet script
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
public class Bullet extends Actor
{
int x = 0;
public void act()
{
if (x == 0){
turnPlaneDirection();// method which should eventually return the rotation of Plane
}
move(10);
}
}
//World script (called sea)
import greenfoot.*;
import java.util.*;
public class Sea extends World
{
public Sea()
{
super(1000, 520, 1);
addObject( new EnemyPlane(), 100, 100);
addObject( new EnemyPlane(), 200, 500);
addObject( new EnemyPlane(), 50, 425);
addObject(Plane, 180, 180);
}
}
