This repository has been archived by the owner on Dec 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteste.py
74 lines (51 loc) · 1.78 KB
/
teste.py
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
# Todas bibliotecas do programa
import pygame
import random
pygame.init()
# Tela principal
window_width = 1000
window_height = 600
window = pygame.display.set_mode((window_width, window_height))
pygame.display.set_caption('Space Run')
font = pygame.font.SysFont(None, 48)
plane_width = 50
plane_heigth = 80
nave_width = 20
nave_heigth = 40
elements = {}
elements['background1'] = pygame.image.load(r'imagem1.png').convert()
elements['background1'] = pygame.transform.scale(elements['background1'], (window_width, window_height))
elements['plane'] = pygame.image.load(r'caça.png').convert_alpha()
elements['plane'] = pygame.transform.scale(elements['plane'], (nave_width, nave_heigth))
class Plane(pygame.sprite.Sprite):
def __init__(self, img):
pygame.sprite.Sprite.__init__(self)
self.image = img
self.rect = self.image.get_rect()
self.rect.x = random.randint(-100, 0-plane_width)
self.rect.y = random.randint(0, window_height-plane_heigth)
self.speedx = random.randint(2, 8)
self.speedy = 0
def update(self):
self.rect.x += self.speedx
self.rect.y += self.speedy
if self.rect.right > window_width:
self.rect.x = random.randint(-100, 0-plane_width)
self.rect.y = random.randint(0, window_height-plane_heigth)
self.speedx = random.randint(2, 8)
self.speedy = 0
game = True
clock = pygame.time.Clock()
FPS = 30
plane1 = Plane(elements['plane'])
while game:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
game = False
plane1.update()
window.fill((0, 0, 0))
window.blit(elements['background1'], (0, 0))
window.blit(plane1.image, plane1.rect)
pygame.display.update()
pygame.quit()