So I want to do a Zombie Shooter, and I already have a character who can be moved by WASD
and who's looking to the cursor,...by clicking left mouse he "fires".
final static int NORTH = 1;
final static int EAST = 2;
final static int SOUTH = 4;
final static int WEST = 8;
int result;
float x,y;
float angle;
boolean pressed = false;
boolean locked = false;
void setup() {
size(900,900);
frameRate(60);
result = 0;
x = width/2;
y = height/2;
smooth ();
rectMode(CENTER);
}
void draw() {
background(255,0,0);
noStroke();
switch(result) {
case NORTH: y=y-2; break;
case EAST: x=x+2; break;
case SOUTH: y=y+2; break;
case WEST: x=x-2; break;
case NORTH|EAST: y=y-2; x=x+2; break;
case NORTH|WEST: y=y-2; x=x-2; break;
case SOUTH|EAST: y=y+2; x=x+2; break;
case SOUTH|WEST: y=y+2; x=x-2; break;
}
fill(255);
pushMatrix();
translate(x,y);
rotate(angle);
rect(0,0,50,50);
popMatrix();
}
void mouseReleased(){
stroke(#007700);
strokeWeight(5);
strokeCap(ROUND);
fill(#009900);
line(x,y,mouseX,mouseY);
}
void mouseMoved(){
angle = atan2(mouseY - y, mouseX - x);
}
void keyPressed(){
switch(key) {
case('w'):case('W'):result |=NORTH;break;
case('d'):case('D'):result |=EAST;break;
case('s'):case('S'):result |=SOUTH;break;
case('a'):case('A'):result |=WEST;break;
}
}
void keyReleased(){
switch(key) {
case('w'):case('W'):result ^=NORTH;break;
case('d'):case('D'):result ^=EAST;break;
case('s'):case('S'):result ^=SOUTH;break;
case('a'):case('A'):result ^=WEST;break;
}
}
So now I want to spawn Zombies, who walk to my character
I did this with a bunch of if loops.
Now they follow the character, but I don't know, how I could let them spawn from the border.
Also they should spawn to a random time, and I don't know how to integrate time in my game.
So first the zombie(the ellipse) should follow the character and not the mouse anymore.
And if you could help me with this spawning thing, I'd be thankful.
I have a problem and after lots of hours testing and trying I have no idea what else I can do.
So I'm begging you to help me. I also have to say, I'm very newbie with processing,
we did
a bit in school :S
So I want to do a 2D Shooter (in bird's eye view), and the character should be movable with "wasd".
This one is not the problem, but i also want the character rotating/look in direction of the cursor.
Both things I can do easily, but I don't get how I achieve to combine those two things.