Greetings!
I'm almost finished in creating a geometry wars like game (except that you cant move =P ). For the last few days I've been stuck doing the diagonal movement of the bullets. I wish someone could help me =D
here's the constructor of the bullet class
x & y is the starting position of the bullet, while destinationX & Y is where the bullet should go.
public Bullet(int x, int y, int destinationX, int destinationY, GameEngine Engine) {
super(x,y,Engine);
setImage("graphics/bullet.png");
destX = destinationX;
destY = destinationY;
curX = x;
curY = y;
calculate();
}
private void calculate () {
if ( curX - destX > 0 ) {
destX = curX - destX;
destX = -destX;
}
else {
destX = destX - curX;
}
if ( curY - destY > 0 ) {
destY = curY - destY;
destY = -destY;
}
else {
destY = destY - curY;
}
}
if the object is outside of screen, the object no longer exists
public void update() {
move();
if (x < 0 || x > 1920 || y < 0 || y > 1200)
exist = false;
}
useless move method
public void move() {
x += destX;
y += destY;
}
I'm having a hard time figuring out the movement.
the player is on the center of the screen. And mouse clicks determine where the bullet will be shot at.
my main problem is the move method it has to move the bullet up to the end of the screen and it has to move it in a fixed speed.
for example:
The player is at (70,60) and I clicked my mouse at (11,3), not only do the bullet need to move to (11,3), it has to move in a fixed speed (e.g. 3 pixels per frame) and it has to move toward the end of the screen (e.g. (600,0) ) ( not just to the point where the mouse is clicked (11,3) ).
The vertical & horizontal movement is not difficult but the diagonal movement is driving me crazy :'(
any help is greatly appreciated =D