Pls help in this code = #include <Wire.h> #include <LiquidCrystal_I2C.h> // Define LCD parameters LiquidCrystal_I2C lcd(0x27, 16, 2); /

Pls help in this code =
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Define LCD parameters
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set I2C address, columns, rows

// Game variables
const int buttonPin = 2; // Button connected to digital pin 2
int buttonState = 0;
int lastButtonState = 0;
int dinoY = 0; // Dinosaur's Y-position (0 is ground, higher values are higher jumps)
int jumpHeight = 2; // Maximum jump height
int jumpVelocity = jumpHeight; // Initial jump velocity
int gravity = 1; // Gravity constant

int obstacleX = 16;
int obstacleSpeed = 1;
int score = 0;
bool gameOver = false;

void setup() {
pinMode(buttonPin, INPUT_PULLUP); // Use internal pull-up resistor

// Initialize LCD
lcd.init();
lcd.backlight();
}

void loop() {
// Read button state
buttonState = digitalRead(buttonPin);

// Detect button press
if (buttonState == LOW && lastButtonState == HIGH) {
// Jump
jumpVelocity = jumpHeight;
}

// Update dinosaur position (gravity)
if (dinoY < jumpHeight) {
dinoY += jumpVelocity;
jumpVelocity -= gravity;
} else {
dinoY -= gravity;
}
dinoY = constrain(dinoY, 0, jumpHeight); // Keep dinoY within bounds

// Move obstacle
obstacleX -= obstacleSpeed;

// Check for collision
if (obstacleX <= 0 && dinoY == 0) {
gameOver = true;
}

// Check for game over
if (gameOver) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Game Over!");
lcd.setCursor(0, 1);
lcd.print("Score: ");
lcd.print(score);

delay(2000); // Delay before restarting
resetGame(); 

}

// Update score
if (obstacleX <= 0) {
obstacleX = 16;
score++;
obstacleSpeed = constrain(obstacleSpeed + 1, 1, 5); // Increase speed gradually
}

// Draw game on LCD
lcd.clear();
lcd.setCursor(0, dinoY); // Use dinoY to control vertical position
lcd.print("D");
lcd.setCursor(obstacleX, 0);
lcd.print("O");
lcd.setCursor(0, 1);
lcd.print("Score: ");
lcd.print(score);

lastButtonState = buttonState;
delay(100);
}

void resetGame() {
dinoY = 0;
obstacleX = 16;
obstacleSpeed = 1;
score = 0;
gameOver = false;
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your sketch, using code tags when you do

Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows

Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

1 Like

What do you need help with ?

I just bought an arduino r3 and i added this code and it says unexpected quantity before an constant pls help

@UKHeliBob has been trying to help you. They've outlined exactly what you need to do in order to get it. Simply repeating "pls help" without following the steps outlined in How to get the best out of the forum is just wasting time.

Thankss

Sorry i thought someone might help if i added "pls help" and i didnt saw starting post i am new to this web but everyone is helping this is a good community

I very much doubt that is the exact error message

Please copy the full error message using the button provided in the IDE and post it here, using code tags when you do

1 Like

There is no error in the program code. It is not doing anything useful or playful (or remotely "dino"), but it compiles.

While you are fixing this one, here's a "Running Man" from a few years back.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.