Hi, I am working on making the dinosour game from offline chrome on a touchscreen with arduino. in the finishing touches of the game I discovered a bug where when the "speed" is lower than -15 the hitboxes does not work anymore. However, when the "speed" is -14 and higher everything works just fine. In other words, when the dino reaches 1000 score points, it will run for ever and jumping over the cactuses doesnt give any points, nor does the cactuses "kill it". Please help.
just to make troubleshooting easier:
cacX = var for drawing and moving cactus
cacSpeed = "speed" on the cactuses
cactus = function to draw cactus
jumpy+65 = T-rex lowest point (feet)
175 = Y position for cactus
rexX = T-rex's x position
scoreboard = var for refreshing the score
actualScore = score
void drawCactus() {
cactus(cacX, WHITE); //use function
cacX = cacX + cacSpeed; //make the cactuses move
cactus(cacX, BLACK); //use function
if (cacX <= 0) { // if the cactuses is at 0 move them back to 400
cactus(cacX, WHITE);
cacX = 400;
}
if (jumpY+65 >= 175 && cacX-8 >= rexX-20 && cacX+12 <= rexX+5) { //hitbox for resetting
actualScore = 0;
scoreboard = 0;
}
if (jumping == 1 && jumpY+65 <= 175 && cacX-8 >= rexX-20 && cacX+12 <= rexX+5) { //hitbox for points
actualScore = actualScore + 10;
scoreboard = 0;
}
}
void score() {
if (scoreboard == 0) {
tft.setFont();
tft.setRotation(1);
tft.setCursor(10, 10);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print("SCORE ");
tft.fillRect(70, 5, 50, 30, WHITE);
tft.setTextColor(BLACK);
tft.print(actualScore);
scoreboard = 1;
}
if (actualScore == 0) { // if score is 0 speed = -5
cacSpeed = -5;
}
if (actualScore == 100) { /if score is 100 speed = -6
cacSpeed = -6;
}
if (actualScore == 200) { //etc.
cacSpeed = -7;
}
if (actualScore == 300) {
cacSpeed = -8;
}
if (actualScore == 400) {
cacSpeed = -10;
}
if (actualScore == 500) {
cacSpeed = -11;
}
if (actualScore == 600) {
cacSpeed = -12;
}
if (actualScore == 700) {
cacSpeed = -13;
}
if (actualScore == 800) {
cacSpeed = -14;
}
if (actualScore == 1000) {
cacSpeed = -15;
}
}
T-rex.ino (7.95 KB)