Python Öğreniyorum 21 – Pythonda dinozor oyunu yapma
Python Öğreniyorum 21 – Pythonda dinozor oyunu yapma. Merhabalar, bu videomuzda Python da meşhur Chrome dinozor oyununu (Chrome dinosaur game) yapacağız. Bunun için turtle modülü kullanılacaktır
Videoda kullanılan resimleri indir
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
import turtle import random import time pencere = turtle.Screen() pencere.title("Dinosaur Game") pencere.bgcolor("black") pencere.setup(height=500, width=800) pencere.bgpic("back.gif") pencere.tracer(0) pencere.register_shape("dino.gif") pencere.register_shape("cactus.gif") dino = turtle.Turtle() dino.speed(0) dino.shape("dino.gif") dino.color("green") dino.penup() dino.dy = 0 dino.dx = 0 dino.state = "ready" dino.height = 100 dino.width = 120 dino.goto(-200, -50) gravity = -0.5 kaktus = turtle.Turtle() kaktus.speed(0) kaktus.shape("cactus.gif") kaktus.color("red") kaktus.penup() kaktus.dx = -5 kaktus.height = 60 kaktus.width = 28 kaktus.goto(200, -70) def jump(): if dino.state == "ready": dino.dy = 12 dino.state = "jumping" pencere.listen() pencere.onkeypress(jump, "space") while True: time.sleep(0.01) if dino.ycor() < -50: dino.sety(-50) dino.dy = 0 dino.state = "ready" if dino.ycor() != -50 and dino.state == "jumping": dino.dy += gravity y = dino.ycor() y += dino.dy dino.sety(y) x = kaktus.xcor() x += kaktus.dx kaktus.setx(x) if kaktus.xcor() < -400: x = random.randint(400, 600) kaktus.setx(x) kaktus.dx *= 1.05 if kaktus.distance(dino) < 30: print('GAME OVER') pencere.update() |
olmuyo aciliyo ekran sora kapaniyo
ne hata veriyor?
Özel durum oluştu: TclError
couldn’t open “back.gif”: no such file or directory
File “/Users/atahanuzerrr/Desktop/PROJELER/dinazoroyunu.py”, line 10, in
pencere.bgpic(“back.gif”)
hatası aliyorum
resimleri eklemen lazım
kakts için cactus.gif, dinazor için : dino.gf,
manzara için : back.gif
internetten rastgele mantıklı resim seç ev ekle klasöre
burada kitabxana hissəsi necə olur?