Help with missile command game.
in
Programming Questions
•
1 year ago
I'm trying to write code for the missiles for the game, and I'm having trouble with the coding of it.
int endX;
int endY;
int endvar;
int startX;
void setup() {
size(500, 500);
startX = (int)random(500);
endY=0;
endvar = (int)random(-10 , 10);
endX = startX;
}
void draw(){
background (255);
smooth();
stroke(255,0,0);
line(startX, 0, endX, endY);
endY++;
endX = endX + endvar;
}
This is what I've got so far.
I want to make it so that the missiles have a few pre determined vectors already. So they have lets say there are 6 cities which they can randomly go to. The thing which changes is the start point which has to be on the top of the screen.
I'm stuck on creating this random angle to the cities. I thought that prehaps I could create some variables which have the co-ordinates for the cities pre determined and then I could input these into the line code. But I'm not entirely sure, I simply need some help on how I would go about coding this.
int endX;
int endY;
int endvar;
int startX;
void setup() {
size(500, 500);
startX = (int)random(500);
endY=0;
endvar = (int)random(-10 , 10);
endX = startX;
}
void draw(){
background (255);
smooth();
stroke(255,0,0);
line(startX, 0, endX, endY);
endY++;
endX = endX + endvar;
}
This is what I've got so far.
I want to make it so that the missiles have a few pre determined vectors already. So they have lets say there are 6 cities which they can randomly go to. The thing which changes is the start point which has to be on the top of the screen.
I'm stuck on creating this random angle to the cities. I thought that prehaps I could create some variables which have the co-ordinates for the cities pre determined and then I could input these into the line code. But I'm not entirely sure, I simply need some help on how I would go about coding this.
1