티스토리 뷰

 

1. Move the turtle with keypress

2. Create and move the cars

3. Detect collision with car

4. Detect when turtle reachs the other side

5. Create a scoreboard

 

*main.py

import time
from turtle import Screen
from player import Player
from car_manager import CarManager
from scoreboard import Scoreboard
screen = Screen()
screen.setup(width=600, height=600)
screen.tracer(0)
screen.listen()
player = Player()
screen.onkeypress(player.gogogo, "Up")
game_is_on = True
while game_is_on:
    time.sleep(0.1)
    screen.update()
screen.exitonclick()

 

*player.py

from turtle import Turtle
STARTING_POSITION = (0, -280)
MOVE_DISTANCE = 10
FINISH_LINE_Y = 280
class Player(Turtle):
    def __init__(self):
        super().__init__()
        self.color("black")
        self.shape("turtle")
        self.pu()
        self.setpos(STARTING_POSITION)
        self.setheading(90)
    def gogogo(self):
        self.fd(MOVE_DISTANCE)

 

[결과]

'Test > Python(20220101~)' 카테고리의 다른 글

Days23. Turtle crossing 게임 3  (0) 2022.03.05
Days23. Turtle crossing 게임 2  (0) 2022.03.05
Days22. Pong 게임  (0) 2022.03.02
Days21. 뱀게임 최종  (0) 2022.03.02
Days21. 뱀게임7 - Slicing  (0) 2022.03.02
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
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
글 보관함