티스토리 뷰
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)
player = Player()
car_manager = CarManager()
screen.listen()
screen.onkeypress(player.gogogo, "Up")
game_is_on = True
while game_is_on:
time.sleep(0.1)
screen.update()
car_manager.create_car()
car_manager.move_cars()
screen.exitonclick()
*car_manager.py
from turtle import Turtle
import random
COLORS = ["red", "orange", "yellow", "green", "blue", "purple"]
STARTING_MOVE_DISTANCE = 5
MOVE_INCREMENT = 10
class CarManager(Turtle):
def __init__(self):
self.all_cars=[]
def create_car(self):
if random.randint(1, 6) == 1:
new_car = Turtle("square")
new_car.shapesize(stretch_wid=1, stretch_len=2)
new_car.color(random.choice(COLORS))
new_car.pu()
random_y = random.randint(-250, 280)
new_car.setpos(x=300, y=random_y)
self.all_cars.append(new_car)
def move_cars(self):
for car in self.all_cars:
car.backward(STARTING_MOVE_DISTANCE)
*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~)' 카테고리의 다른 글
Dats23. Turtle crossing 게임 4 (0) | 2022.03.05 |
---|---|
Days23. Turtle crossing 게임 3 (0) | 2022.03.05 |
Days23. Turtle crossing 게임 (0) | 2022.03.05 |
Days22. Pong 게임 (0) | 2022.03.02 |
Days21. 뱀게임 최종 (0) | 2022.03.02 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- insert
- 스토리지
- Join
- oracle
- cloud-init
- set()
- dezoomify
- dp-1
- storage
- LIST
- vmware.powercli
- 배열
- exadata
- EXA
- powercli
- 정렬
- 중복제거
- powershell
- vmware
- 변수화
- 대소문자
- 부동없이
- sysprep
- artandculture
- dp-2
- 차집합
- 읽어오기
- fromkeys
- virt-sysprep
- 3par
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함