-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (51 loc) · 1.69 KB
/
main.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
import pygame
import sys
from game_objects import Player
from levels import Level
class Game:
def __init__(self):
pygame.init()
self.running = True
self.caption = "Game Name"
self.fps = 60
def run(self):
# window settings
window = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
pygame.display.set_caption(self.caption)
# clock
clock = pygame.time.Clock()
# create players
players = pygame.sprite.Group()
gort = Player(
(100, 100),
pygame.transform.scale(pygame.image.load("assets/images/Gort1.png").convert_alpha(), (100, 100))
)
players.add(gort)
# create platforms
platforms = Level.load(0)
# main game loop
while self.running:
# limit the frame rate
clock.tick(self.fps)
# draw
self.draw(window, players, platforms)
# event loop
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
# pressing escape terminates the program
if event.key == pygame.K_ESCAPE:
self.running = False
pygame.quit()
sys.exit()
def draw(self, surface, players, platforms):
# draw background
background = pygame.image.load("assets/images/temp_background.jpg")
surface.blit(background, (0, 0))
# draw players and platforms
players.draw(surface)
platforms.draw(surface)
# update screen
pygame.display.update()
if __name__ == "__main__":
game = Game()
game.run()