-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
66 lines (51 loc) · 2.04 KB
/
game.py
File metadata and controls
66 lines (51 loc) · 2.04 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
57
58
59
60
61
62
63
64
65
66
import sys
import pygame
class Game:
def __init__(self):
pygame.init()
pygame.display.set_caption('Ninja Game')
self.screen = pygame.display.set_mode((640, 480))
self.clock = pygame.time.Clock()
self.img = pygame.image.load('data/images/clouds/cloud_1.png')
self.img.set_colorkey((0, 0, 0))
self.img_pos = [160, 260]
self.movement = [False, False]
self.collision_area = pygame.Rect(50, 50, 300, 50)
def run(self):
while True:
self.screen.fill((14, 219, 248)) # RGB(14,219,248)= azul claro
img_r = pygame.Rect(
self.img_pos[0],
self.img_pos[1],
self.img.get_width(),
self.img.get_height()
)
if img_r.colliderect(self.collision_area):
pygame.draw.rect(
self.screen,
pygame.Color('blue'),
self.collision_area)
else:
pygame.draw.rect(
self.screen,
pygame.Color('blue4'), self.collision_area)
self.img_pos[1] += (self.movement[1] - self.movement[0]) * 4
self.screen.blit(self.img, self.img_pos)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
self.movement[0] = True
if event.key == pygame.K_DOWN:
self.movement[1] = True
if event.type == pygame.KEYUP:
if event.key == pygame.K_UP:
self.movement[0] = False
if event.key == pygame.K_DOWN:
self.movement[1] = False
pygame.display.update()
self.clock.tick(60) # 60 fotogramas por segundos
# --- CODE MAIN ----
Game().run()