Problem for making a little game (LED display movement)

Hello,

I’ve just got these wonderful toys last week for a project : breadbord, arduino, led display…
The initial project was to realise something with the temperapture captor and a wi-fi controller (ESP8266)… but thats not the topic.

Well, I wanted to make a little game. Because I like games, and the tools I have was totaly not for games, and I like to deflect the way a systems works to make another thing.

So, for now, Its just to make the LCD displays the game. No input for now.

The game is simple : You are a little ship and you need to avoid asteroids.

The problem is, I have some difficulty to make the asteroids move. After some research, I’ve finnaly find a function to make the LCD screen move by itself, but thats not really what I want to do, because the ship moves at the same time as the asteroids. (The player must stand at the same position)

Here’s my code :

//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display
int gamestart = 0;
int posJoueur = 0;
int posCursor = 3;

int randInRange(int min, int max)
{
  return min + (int) (rand() / (double) (RAND_MAX + 1) * (max - min + 1));
}

void ennemy()
{
  delay(200);
  lcd.setCursor(16,randInRange(0,1));
  lcd.print("O"); //This is an asteroid
}

void setup()
{
  lcd.init();                      
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(5,0);
  lcd.print("XENON");
  lcd.setCursor(1,1);
  lcd.print("2018 StmH Ent.");
  delay(5000);
  gamestart = 1;
  lcd.clear();
  lcd.setCursor(3,0);
  lcd.print(">");
}

void loop()
{
  while(gamestart = 1)
  {
    lcd.setCursor(3,posJoueur);
    lcd.print(">"); //This is the player
    ennemy();
    lcd.scrollDisplayLeft(); //Making the LCD screen move
    lcd.setCursor(3,posJoueur);
  }
}

Annnnd then. I’m complety lost for now, as a newbie, Its pretty hard to think of a custom function, I cant find a clue of what I can do to make the custom function (if i need one) to work.

Any ideas to resolve my problem ? Did I need a custom function ? It is very hard, too hard for my level ?

Dont hesitate to ask me more info. I’ve maybe forget to indicate some things to this post.

Thanks for reading me, and helping me.

PS : Sorry If you think my english is pretty bad, thats not my native langage and I need to work it.

OK. It is not a game I'd spend too long playing myself, but I see the learning value in writing it.
As I understand it, you have 2 line 16 character display.
You have a number of 'asteroids' represented by the letter 'O' randomly placed and maybe even moving on the display.
You have a 'ship' represented by a '>' starting at the left of the display.
You want to navigate the 'ship' to the right, moving it between line 0 and line 1 , to avoid any 'asteroids'.

For the ship, its quite easy. You just need navigation buttons up/down/right/ (maybe left)
For the asteroids, it is a bit more complex. You have to specify the number, their random placement, their movement etc. Too many or too fast and the game is impossible.
Detecting a collision is also quite easy if you get the data structure (say an array) right so you can see if a ship is occupying the same cell as an asteroid.

  while (gamestart = 1)

Whatever else you are doing I am certain that this line is wrong
use = for assignment
use == for comparison

6v6gt:
OK. It is not a game I'd spend too long playing myself, but I see the learning value in writing it.
As I understand it, you have 2 line 16 character display.
You have a number of 'asteroids' represented by the letter 'O' randomly placed and maybe even moving on the display.
You have a 'ship' represented by a '>' starting at the left of the display.
You want to navigate the 'ship' to the right, moving it between line 0 and line 1 , to avoid any 'asteroids'.

Yes exactly !

6v6gt:
For the ship, its quite easy. You just need navigation buttons up/down/right/ (maybe left)
For the asteroids, it is a bit more complex. You have to specify the number, their random placement, their movement etc. Too many or too fast and the game is impossible.
Detecting a collision is also quite easy if you get the data structure (say an array) right so you can see if a ship is occupying the same cell as an asteroid.

Well, I'm not interest in these things right now. First, I need to get down the problem I've said in the first post of this topic.

UKHeliBob:

  while (gamestart = 1)

Whatever else you are doing I am certain that this line is wrong
use = for assignment
use == for comparison

Now you're saying it, yes, thats right. But the program dosent seems to have a problem with it at all. I've corrected the line, thank you

the program dosent seems to have a problem with it at all.

Then something is wrong with your program logic

UKHeliBob:
Then something is wrong with your program logic

What it is ?

Naeso:
What it is ?

To start with, as you never change the value of gamestart the while loop would never even if you tested its value properly with ==. Secondly, setting gamestart to 1 in the while loop as you do returns true true so the while loop never ends anyway.

What is it that you want that while loop to do ?