Hi there, hoping someone is able to help with this issue I have, I am making a very basic game for an assignment and I am struggling to get an object to collide with the player to end the game. I have use the same collision detection in a previous assignment but it does not work for this game. The method im using probably is not the best but is there a better way to come by collision between the objects?
Below is from the main class
//game mode variables
int gameMode;
int BEGIN = 1;
int END = 0;
void draw()
{
if (gameMode == BEGIN)
{
drawBackground();
if (!player_1.hit());
player_1.update();
spaceRock1.update();
}
if (player_1.hit() == true)
{
gameMode = END;
fill(255);
textSize(32);
text("Get REKT", width/2, height/2);
text("Press SPACE to restart", width/2, height/2+50);
}
}
Below is from the “player” class
int shipFront = y + 75;
boolean hit()
{
color colorIdentify;
for (int i=y; i < y+shipFront; i++)
{
colorIdentify = get(shipFront, i);
if (colorIdentify == colour1)
{
return true;
}
}
return false;
}
and finally below is the colour im checking against if it is near the front of the player
color colour1 = color(211, 211, 211);
If all the code is needed for the whole game, i can upload it but the code above is just the collision that doesnt work for me
Thanks in advance