Python Öğreniyorum 9 – Python ile oyun hazırlama
Python Öğreniyorum 9 – Python ile oyun hazırlama. Merhabalar, bu videmuzda Pytho dilinde Turtle modülünü kullanarak bir oyun hazırlayacağız.
00:00 Oyun inceleme
01:10 Oyun penceresi ve oyunucuyu hazırlama
04:20 Klavye kontrolü
08:50 Oyuncu sınır kontrolü
10:50 Hedef ekleme
15:20 Birçok hedef ekleme
19:35 Hedef sınır kontrolü
21:35 Çarpışma kontrolü
22:20 Puan ve Hız yazıları ekleme
28:00 Arka alan resmi ve ses ekleme
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
import turtle import random from playsound import playsound win = turtle.Screen() win.screensize(600, 600) win.title('Kalumbağaları Yakala') win.bgcolor('blue') win.bgpic('underwater.gif') win.tracer(2) player = turtle.Turtle() player.color('white') player.shape('triangle') player.shapesize(3) player.penup() score = 0 pen = turtle.Turtle() pen.speed(0) pen.shape("square") pen.color("white") pen.penup() pen.hideturtle() pen.goto(-200, 220) pen.write("Puan: {}".format(score), align="center", font=("Courier", 24, "normal")) speed = 1 pen2 = turtle.Turtle() pen2.speed(0) pen2.shape("square") pen2.color("white") pen2.penup() pen2.hideturtle() pen2.goto(200, 220) pen2.write("Hız: {}".format(speed), align="center", font=("Courier", 24, "normal")) maxGoals = 5 goals = [] for i in range(maxGoals): goals.append(turtle.Turtle()) goals[i].penup() goals[i].color('yellow') goals[i].shape('turtle') goals[i].speed(0) goals[i].setposition(random.randint(-300, 300), random.randint(-300, 300)) def turnLeft(): player.left(30) def turnRight(): player.right(30) def increaseSpeed(): global speed speed = speed + 1 pen2.clear() pen2.write("Hız: {}".format(speed), align="center", font=("Courier", 24, "normal")) def decreaseSpeed(): global speed speed = speed - 1 pen2.clear() pen2.write("Hız: {}".format(speed), align="center", font=("Courier", 24, "normal")) win.listen() win.onkey(turnLeft, 'Left') win.onkey(turnRight, 'Right') win.onkey(increaseSpeed, 'Up') win.onkey(decreaseSpeed, 'Down') while True: player.forward(speed) if player.xcor() > 300 or player.xcor() < -300: player.right(180) if player.ycor() > 300 or player.ycor() < -300: player.right(180) for i in range(maxGoals): goals[i].forward(1) if goals[i].xcor() > 500 or goals[i].xcor() < -500: goals[i].right(random.randrange(150, 250)) if goals[i].ycor() > 500 or goals[i].ycor() < -500: goals[i].right(random.randrange(150, 250)) if player.distance(goals[i]) < 40: goals[i].setposition(random.randint(-290, 290), random.randint(-290, 290)) goals[i].right(random.randint(0, 360)) playsound('swallow.wav', False) score = score + 1 pen.clear() pen.write("Puan: {}".format(score), align="center", font=("Courier", 24, "normal")) |