-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
77 lines (65 loc) · 2.39 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
69
70
71
72
73
74
75
76
77
import sys
import pygame
from super_ellipse.settings import *
from super_ellipse.surfaces import GameSurface, MenuSurface
pygame.mixer.init(44100, -16, 2, 512)
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT), flags=pygame.RESIZABLE)
print('ok')
pygame.display.set_caption('Super Ellipse')
pygame.display.set_icon(pygame.image.load('assets/images/logo.png'))
clock = pygame.time.Clock()
# Timing
pygame.time.set_timer(TIMER_UPDATE, TIMER_UPDATE_INTERVAL)
pygame.time.set_timer(OBSTACLE_SPAWN, OBSTACLE_SPAWN_RATE)
pygame.time.set_timer(GAME_UPDATE, GAME_UPDATE_RATE)
# Surfaces
menu = MenuSurface(screen)
game = GameSurface(screen)
game.set_song(SONG)
game.set_gameover_callback(menu.return_to_menu)
while True:
clock.tick(FRAMES_PER_SECOND)
for event in pygame.event.get():
if event.type == pygame.QUIT:
quit()
elif event.type == pygame.VIDEORESIZE:
pygame.display.set_mode(event.size)
elif menu.enabled:
# MENU CONTROLS
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
menu.up()
elif event.key == pygame.K_DOWN:
menu.down()
elif event.key == pygame.K_RETURN:
menu.choose_option()
else:
# GAME CONTROLS
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
game.move_left(ARROW_SPEED)
elif event.key == pygame.K_RIGHT:
game.move_right(ARROW_SPEED)
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
game.move_left(0)
elif event.key == pygame.K_RIGHT:
game.move_right(0)
elif event.type == TIMER_UPDATE:
game.timer_update(TIMER_UPDATE_INTERVAL)
elif event.type == OBSTACLE_SPAWN:
game.create_wall()
elif event.type == GAME_UPDATE:
game.obstacles.update()
game.entities.update()
if menu.enabled:
menu.update()
screen.blit(menu, (0, 0))
else:
game.update()
screen.blit(game, (0, 0))
if not pygame.mixer.music.get_busy() and not menu.enabled:
pygame.mixer.music.load(game.song_file)
pygame.mixer.music.play(-1)
pygame.display.flip()