Project Concept and Design
For my midterm project, I have planned to create a game where the player controls a fish swimming through a river. The main goal of the game is to survive for as long as possible. While swimming through the river, the fish will encounter different food objects and garbage objects. The player needs to eat the food to keep the fish healthy while avoiding the garbage.
The game is also intended to communicate a message about pollution in freshwater environments. Pollution in rivers can seriously affect the aquatic animals living there. By making this the main idea of the game, I want the player to experience this problem through the gameplay rather than simply being told about it.
The player will control the fish using the up and down arrow keys. The fish will have three lives, and eating garbage will cause the player to lose a life. Once all three lives are lost, the game will end. I also plan to add a health system where the fish’s health continuously decreases if it does not eat food. A health bar will show the player how much health the fish has remaining. I am also thinking to using left and right arrow keys to make the fish go front and back if the game feels really static.
Progress So Far
So far, I have created the basic game window and the river environment using p5.js. I have also added a fish as an ellipse that the player can control using the keyboard. I added moving water lines and bubbles to make the river feel more active rather than having a completely static background.
I have also started working on the objects that will appear in the river. At the moment, I am using simple circles as placeholders instead of actual images. There are three types of food: shrimp, small fish, and algae. There are also three types of garbage: plastic, bottles, and cans. Each object has a different size and color so that I can easily tell them apart while testing the game.
Another important part I have worked on is spawning and collision detection. The objects are currently spawned from the right side of the screen and move towards the left, similar to how objects would flow through the river. When an object reaches the fish, the program checks whether the two objects have collided. I have used the distance between the fish and the object to determine whether they are close enough to count as a collision.
let fish;
let objects = [];
let lastSpawnTime = 0;
let spawnInterval = 1500;
let foodTypes = [
{type: "shrimp", color: [255, 160, 50], size: 15},
{type: "small fish", color: [255, 220, 80], size: 22},
{type: "algae", color: [80, 210, 100], size: 30}
];
let garbageTypes = [
{type: "plastic", color: [255, 255, 255], size: 18},
{type: "bottle", color: [0, 0, 0], size: 25},
{type: "can", color: [255, 50, 50], size: 32}
];
function setup() {
createCanvas(700, 500);
// Create the fish
fish = {x: 200, y: height / 2, size: 40, speed: 4};
}
function draw() {
if (millis() - lastSpawnTime > spawnInterval) {
spawnObject();
lastSpawnTime = millis();
}
drawObjects();
// Draw the fish
drawFish();
}
// Function for drawing the fish
function drawFish() {
fill(255, 180, 50);
ellipse(fish.x,fish.y,fish.size * 1.5,fish.size);
}
function spawnObject() {
let objectType;
if (random(1) < 0.5) {
objectType = random(foodTypes);
} else {
objectType = random(garbageTypes);
}
let object = {x: width + 20, y: random(80,380), size:objectType.size, color: objectType.color, type: objectType.type, speed:random(2, 4)};
objects.push(object);
}
// Function for drawing objects
function drawObjects() {
for (let i = objects.length - 1; i >= 0; i--) {
let object = objects[i];
// Move object from right to left
object.x -= object.speed;
// Set the object's color
fill(
object.color[0],
object.color[1],
object.color[2]
);
// Draw the object
circle(object.x,object.y,object.size);
// Remove object when it leaves the screen
if (object.x < -object.size) {
objects.splice(i, 1);
}
if (checkCollision(fish, object)) {
objects.splice(i, 1);
}
}
}
// Function for checking collision
function checkCollision(fish, object) {
let distanceBetween = dist(fish.x,fish.y,object.x,object.y);
return distanceBetween < fish.size / 2 + object.size / 2;
}
The Most Uncertain Part
One of the parts of the project that I was most uncertain about was collision detection. I knew that the game would depend heavily on detecting when the fish eats food or garbage, but I was not sure how I would implement this in p5.js. I decided to work on this part early because it is an important part of the game’s main interaction.
I implemented a collision detection function that uses the distance between the fish and each object. If the distance is smaller than the combined sizes of the fish and object, the program considers them to have collided. Testing this early has reduced some of the risk because I now have a working foundation for the main gameplay mechanic.
Another part I am uncertain about is how I will make the game become harder as the player progresses. I want the game to start relatively easy and gradually become more difficult so that the player has to react faster and pay more attention as they continue playing. One idea I plan to try is changing the probability of spawning food and garbage as time passes. At the beginning, there could be a more balanced chance of getting food or garbage. As more time passes, I plan to increase the probability of garbage spawning while decreasing the probability of food spawning. This would make it harder for the player to maintain the fish’s health and avoid losing lives.
Next Steps
My next focus will be designing the home screen and the game-over screen so that the game feels more complete. I also plan to replace the simple colored circles with images for the fish, food, and garbage objects. I would like to add sounds as well, such as sounds for eating food, hitting garbage, and losing a life.
After that, I will continue developing the health and life systems. The final game will have three lives, a health bar, a scoring system, and increasing difficulty as the game continues. I also want to make the objects more visually interesting while keeping the controls simple enough for the player to understand easily.
Overall, I have now moved from planning the idea and have started building the core mechanics of the game. Having the fish movement, object spawning, and collision detection working gives me a basic foundation that I can build the rest of the game around.