so far our game displays as such :
Now let's add the obstacles , so we need to keep in mind the following :
first of all , we need to import new modules, "time and random".
the "time" modules provides us timing functions so that the logic runs at a set "speed" and "random" module allows us to make random decisions.
next , we will add some more constants and variables.
now we begin by adding the speed check for our game logic,inside the game loop,
we get the current time and see
if 1/speed time has passed,if yes then update
variable for lasttime and then run the code for logic.
The above section of the code , checks if the player and the obstacle are at the same column, and if true , updates the values for score,level and speed being on the same line means from next cycle the obstacle cant cause any problems for the player , hence we also remove it from the count of current obstacles.
we now move every character (except for player) one position to the left,but you will realize that once we do that, the leftmost characters are lost and the rightmost positions have no new values(the old ones are garbage for us). so now we need to add ￼ new characters to the rightmost position , which will either be blank space(" ") or our "OBSTACLE_CHAR" in a random fashion, provided it doesn't block the path completely.The code for doing this is here.