- Obstacles with collision detection
- Make players switch colors when they touch (switch who is "it")
- A restart button
I'm also a little disappointed that I didn't get to add in any data checking during the grace period that would have let me run the game at a higher framerate. I just didn't have time with work and class.
The finished project is pretty simple. I took some screenshots to show the progression of the game:
The start location for the players |
The red player, who is "it" gets closer to the target. |
When the red player touches blue, both players see the game over screen. |
There were a few code snippets that I think exemplify some of the effort I put into the project, even if the end result wasn't very flashy. First, there's the logic I built for the collision detection.
boolean isInsideRect(float x, float y, float rectX, float rectY, float rectW, float rectH)
{
boolean answer = x > rectX && y > rectY && x < rectX+rectW && y < rectY+rectH; return answer; }
This function was used in my IMM120 class (I can't find the original github repo) and I had to tweak it for my implementation:
if ((isInsideRect(player1.x, player1.y, player2.x, player2.y, size, size)) ||
(isInsideRect(player1.x, player1.y+size, player2.x, player2.y, size, size))||
(isInsideRect(player1.x, player1.y, player2.x+size, player2.y, size, size))||
(isInsideRect(player1.x, player1.y, player2.x, player2.y+size, size, size))||
(isInsideRect(player1.x+size, player1.y, player2.x, player2.y, size, size))||
(isInsideRect(player1.x+size, player1.y+size, player2.x, player2.y, size, size))||
(isInsideRect(player1.x+size, player1.y+size, player2.x+size, player2.y+size, size, size))||
(isInsideRect(player1.x+size, player1.y, player2.x, player2.y+size, size, size))||
(isInsideRect(player1.x+size, player1.y, player2.x+size, player2.y, size, size))||
(isInsideRect(player1.x+size, player1.y+size, player2.x+size, player2.y, size, size))||
(isInsideRect(player1.x+size, player1.y+size, player2.x, player2.y+size, size, size))||
(isInsideRect(player1.x+size, player1.y, player2.x, player2.y+size, size, size))||
(isInsideRect(player1.x, player1.y, player2.x+size, player2.y, size, size))||
(isInsideRect(player1.x, player1.y, player2.x, player2.y+size, size, size))||
(isInsideRect(player1.x, player1.y, player2.x+size, player2.y+size, size, size))||
(isInsideRect(player1.x, player1.y+size, player2.x+size, player2.y+size, size, size))
== true) {
gameOver = true;
}
As you can see, it's a bit tedious and sloppy. But it's the way I know how to do collision detection, so I used it. It seems to work.
I also like the way I did movement for the player who is "it". I used processing's second() function to count time, and after 30 seconds have passed the player moves faster. It isn't really anything special, but I liked the functionality of it.
void update(){
if(keyPressed == true && keyCode == UP){
y -= speed;
}
if(keyPressed == true && keyCode == DOWN){
y += speed;
}
if(keyPressed == true && keyCode == RIGHT){
x += speed;
}
if(keyPressed == true && keyCode == LEFT){
x -= speed;
}
if (x > width - 100){
x = width - 100;
}
if (x < 0){
x = 0;
}
if (y > height - 100){
y = height - 100;
}
if (y < 0){
y = 0;
}
if (time > 30){
speed = 15;
}
}
All in all, there were a couple takeaways from this project for me.
1. Collision detection is hard
2. Everything will always take longer and be harder than you think it will.
I wish I had had more time/skill to implement the features I wanted to. I'm a little disappointed with the outcome of this project, but I'm glad it at least works on some level.