QNA > H > How To Create A Google Dino Run Game In Python

How to create a Google Dino Run game in Python

“Using turtle”

I am trying to create one, but I have got only half success.

I am not able to make it jump properly.

main-qimg-733dba2659d3343603c9b2068faf72a3

You can notice that whenever the dinosaur jumps, the plant stops moving.

main-qimg-bbb888888e986b5d2b3f8881b099ca57

(Believe me, it’s turtle not the actual game. Though I have used their images in .gif format. XD)

Though, I will work on the project in future (maybe after a month) but as my exams are coming so I will not make any upgrade in the codes.

Still if you want to learn, here’s the source code:

  1. import turtle 
  2. import time 
  3. import keyboard 
  4.  
  5. count = 0 
  6. dx = 0.3 
  7.  
  8. img = r"C:\Users...dinoo.gif" 
  9. img1 = r"C:\Users...dino1.gif" 
  10. img2 = r"C:\Users...dino2.gif" 
  11. obj1 = r"C:\Users...obs1.gif" 
  12. bgpic = r"C:\Users...bgpic.png" 
  13.  
  14. imglst = [img1,img2] 
  15.  
  16. win = turtle.Screen() 
  17. win.bgpic(bgpic) 
  18. win.addshape(img) 
  19. win.addshape(img1) 
  20. win.addshape(img2) 
  21. win.addshape(obj1) 
  22. win.tracer(0) 
  23.  
  24. obs1 = turtle.Turtle() 
  25. obs1.shape(obj1) 
  26. obs1.ht() 
  27. obs1.pu() 
  28. obs1.goto(420,142) 
  29.  
  30. dino = turtle 
  31. dino.lt(90) 
  32. dino.shape(img) 
  33. dino.pu() 
  34. dino.goto(-255,142) 
  35. win.update() 
  36.  
  37. def jump(): 
  38. for i in range(128): 
  39. dino.sety(142+i) 
  40. win.update() 
  41. time.sleep(0.1) 
  42. dino.sety(170) 
  43. win.update() 
  44. dino.sety(142) 
  45.  
  46. def obs1move(): 
  47. obs1x = obs1.xcor() 
  48. obs1.setx(obs1x-dx) 
  49. if obs1x < 300: 
  50. obs1.st() 
  51. if obs1x < -300: 
  52. obs1.ht() 
  53. obs1.setx(420) 
  54.  
  55. while True: 
  56. win.update() 
  57. count = count+1 
  58. if count > 1: 
  59. count = 0 
  60. img = imglst[count] 
  61. dino.shape(img) 
  62. if keyboard.is_pressed("up") or keyboard.is_pressed("space"): 
  63. jump() 
  64. obs1move() 

You need to download these images (keep the format same, i.e, if it’s .png then save it as .png):

  1. bgpic.png
  2. obs1.gif
  3. dino2.gif
  4. dino1.gif
  5. dinoo.gif

I will try to complete the game soon, after my exams.

Thanks for reading.

Have a great day ahead.

RajMa

Di Agna Kendry

Quale telefono è meglio, Mi4i o Meizu M2 nota? :: Qual era la carriera di Vickie Guerrero prima di entrare nella WWE?
Link utili