forked from Idea-Fighters/Food-Drop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_ContinuousMovement
More file actions
56 lines (39 loc) ยท 1.56 KB
/
Copy pathcode_ContinuousMovement
File metadata and controls
56 lines (39 loc) ยท 1.56 KB
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
# ์์ ์ฝ๋(code)๋ฅผ ๋ณํํ์ฌ ์์ฑ๋ ์ฝ๋์
๋๋ค.
# ๋ฐฉํฅํค๋ฅผ ๋ฐ๋ณต์ ์ผ๋ก ๋๋ฅด์ง ์๊ณ ํค๋ฅผ ๋์ ๋๊น์ง ํด๋น ๋ฐฉํฅ์ผ๋ก ์์ง์ด๋ ์ฝ๋์
๋๋ค.
!pip install pygame
pip install --upgrade pip
import pygame
pygame.init()
WHITE = (255,255,255)
size = (400,300)
screen = pygame.display.set_mode(size)
done = False
clock = pygame.time.Clock()
airplane = pygame.image.load('images/plane.png')
airplane = pygame.transform.scale(airplane, (60, 45))
def runGame():
global done, airplane
x = 20
y = size[1] - 45
speed = 5
while not done:
clock.tick(30) # ์ซ์๊ฐ ์ปค์ง์๋ก ํ๋ฉด์ด ์์ฃผ ์
๋ฐ์ดํธ๋๊ธฐ ๋๋ฌธ์ ์ข ๋ ์๋๊ฐ์๊ณ ๋งค๋๋ฌ์์ง
screen.fill(WHITE)
for event in pygame.event.get():
if event.type == pygame.QUIT:
done=True
# ์์ ๋ ๋ถ๋ถ
keys = pygame.key.get_pressed() # ํค๋ณด๋์ ๋ชจ๋ ํค์ ์ํ ๊ฐ์ ธ์ค๊ธฐ
# ์ผ์ชฝ ๋๋ ์ค๋ฅธ์ชฝ ํค๊ฐ ๋๋ ค ์๋์ง ํ์ธ
if keys[pygame.K_LEFT]: # ์ผ์ชฝ ํค๊ฐ ๋๋ ค ์์ผ๋ฉด
x -= speed # ์ผ์ชฝ์ผ๋ก ์ด๋
if keys[pygame.K_RIGHT]: # ์ค๋ฅธ์ชฝ ํค๊ฐ ๋๋ ค ์์ผ๋ฉด
x += speed # ์ค๋ฅธ์ชฝ์ผ๋ก ์ด๋
if x < 0:
x = 0
elif x > size[0] - 60:
x = size[0] - 60
screen.blit(airplane, (x, y))
pygame.display.update()
runGame()
pygame.quit()