Help needed with Array on a simple game.
in
Programming Questions
•
9 months ago
Hi, I am making a small game which allows users to 'record' their moves.
The next step in my project is when the user presses the space bar, it will take them back to their last move. The user will only be able to go back 4 steps. Here is what I have so far:
int xPos = 85;
int yPos = 85;
int [] myArray = new int [3];
float speed = 1;
void setup ()
{
size(200, 200);
noStroke();
for (int i = 0; i < myArray.length; i++) {
myArray [i] = 0;
}
}
void draw ()
{
background (0);
if (xPos > width) {
xPos = 0;
fill (215, 0, 35);
}
if (yPos > height) {
yPos = 0;
fill (200, 56, 35);
}
if (xPos < 0) {
xPos = width;
fill (190, 86, 23);
}
if (yPos < 0) {
yPos = height;
fill (150, 0, 65);
}
rect (xPos, yPos, 30, 20);
}
void keyPressed () {
if (key == CODED) {
if (keyCode == LEFT) {
xPos = xPos - 10;
} else if (keyCode == RIGHT) {
xPos = xPos + 10;
}
else if (keyCode == UP)
{
yPos = yPos -10;
}
else if (keyCode == DOWN)
{
yPos = yPos + 10;
//hit space bar to show the last move. With a maximum of 4 steps.
//Arrays - storing information (4 store array)
}
}
}
Any help would be appreciated!
1