I have made a top down shooter game in space.
I have made all of the movement.
I have come across my first problem spawning the bullets in the right place
I have made it so that the bullets spawn from the centre of the space ship but I want to know is there a way to make them a certain distance away from the space ship.
Here is the code on the main frame
var speed = 0;
var shiprotation = 0;
var rotationspeed = 0.1;
var accel = 0.1;
var maxrotationspeed = 5;
var maxspeed = 10;
var friction = 0.9;
function moveship() {
if (Key.isDown(Key.LEFT)) {
shiprotation -= rotationspeed;
}
if (Key.isDown(Key.RIGHT)) {
shiprotation += rotationspeed;
}
if (shiprotation>maxrotationspeed) {
shiprotation = maxrotationspeed;
}
if (shiprotation<-maxrotationspeed) {
shiprotation = -maxrotationspeed;
}
if (Key.isDown(Key.UP)) {
speed += accel;
}
if (Key.isDown(Key.DOWN)) {
speed -= speed/30;
}
if (speed>maxspeed) {
speed = maxspeed;
}
ship._rotation += shiprotation;
xspeed *= friction;
yspeed *= friction;
shiprotation *= friction;
xspeed = speed*Math.sin((ship._rotation+90)*(Math.PI/180));
yspeed = speed*Math.cos((ship._rotation+90)*(Math.PI/180));
map._x -= xspeed;
map._y += yspeed;
}
var shipstate = "idle";
function changestate() {
if (Key.isDown(Key.CONTROL) && shipstate != "guns") {
ship.gotoAndStop(2);
}
if (Key.isDown(Key.CONTROL) && shipstate == "weapons") {
ship.gotoAndStop(3);
}
if (shipstate == "weapons") {
accel = 0.1;
rotationspeed = 0.5;
} else {
accel = 0.5;
rotationspeed = 0.1;
}
}
var shootready = true;
var count = 0;
var bullets = [];
var shoottimer = 0;
var shootdelay = 0.5*30;
function shooting() {
if (Key.isDown(Key.SPACE) && shootready == true) {
bullet = attachMovie("bullet", "bullet"+count, count);
bullet._x = ship._x;
bullet._y = ship._y;
count++;
shootready = false;
bullets.push(bullet);
}
shoottimer++;
if (shoottimer>shootdelay) {
shootready = true;
shoottimer = 0;
}
}
_root.onEnterFrame = function() {
moveship();
changestate();
shooting();
};
any help will be great.
thanks