-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
145 lines (117 loc) · 4.41 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import pygame
from pygame.locals import *
from sys import exit
from sprites import *
import random as rand
from values import *
from levels import *
from splash_screens import *
import math
from assets import *
#setup frames per second
clock = pygame.time.Clock()
#set initial scene to 0
scene = 0
#start pygame
pygame.init()
#set up screen display and images
screen = pygame.display.set_mode(SCREEN_SIZE,0,32)
#initialize the player
player = Player(player_img_name,10,100,100)
#set paused status to false
paused = False
map_showing = False
#initialize first room
size = 5
#level_1 = Level([(2,0),(4,0,"x"),(0,1),(2,1),(4,1),(0,2),(1,2),(2,2,"*"),(3,2),(4,2),(2,3),(2,4)])
level_1 = Level(size)
#add the player to the allies sprite group
#print(level_1.current_room)
level_1.current_room.ally_sprite_group.add(player)
scene_0_images = [(title_img_name,(0,0))]
scene_0_buttons = [(start_button_img_name,(220,200)),(quit_button_img_name,(220,300))]
title_screen = Splash_Screen((0,0),150,scene_0_background_img_names,scene_0_images,scene_0_buttons)
pause_menu_backgrounds = [pause_menu_img_name]
pause_menu_images = []
pause_menu_buttons = [(continue_button_img_name,(220,193)),(quit_button_img_name,(220,266))]
pause_menu = Splash_Screen((160,120),0,pause_menu_backgrounds,pause_menu_images,pause_menu_buttons)
map_overlay_backgrounds = [map_overlay_img]
map_overlay = Splash_Screen((0,0),0,map_overlay_backgrounds,[(starting_room_img,(305,225))],[])
while True:
#set clock to save the time between frames
dt = clock.tick(FPS)
speed = float(dt)/64
##########SCENE-RENDERING#########
#rendering for title scene
if scene == 0:
title_screen.display(screen,dt)
#rendering for the firsl level scene
elif scene == 1:
level_1.current_room.draw_all(screen,dt)
if paused:
pause_menu.display(screen,dt)
elif not paused:
#print(level_1.current_room)
for l in level_1.current_room.lasers:
l.behave(speed,dt)
for e in level_1.current_room.enemies:
l.on_collision(e)
for e in level_1.current_room.enemies:
e.behave(speed)
for p in level_1.current_room.portals:
p.on_collision(player,screen)
player.behave(speed)
if map_showing:
map_overlay.display(screen,dt)
##########EVENT-LISTENING##########
for event in pygame.event.get():
#print the events
#print(event)
if event.type == QUIT:
exit()
if event.type == MOUSEBUTTONUP:
if event.button == 1:
if scene == 0:
if title_screen.button_disp[0].collidepoint(pygame.mouse.get_pos()):
scene = 1
level_1.current_room.generate(screen)
if title_screen.button_disp[1].collidepoint(pygame.mouse.get_pos()):
exit()
if scene == 1:
if paused:
if pause_menu.button_disp[0].collidepoint(pygame.mouse.get_pos()):
paused = False
if pause_menu.button_disp[1].collidepoint(pygame.mouse.get_pos()):
exit()
if event.type == KEYDOWN:
if not paused:
if event.key == K_w:
player.accelerate(0)
elif event.key == K_s:
player.accelerate(1)
elif event.key == K_a:
player.accelerate(2)
elif event.key == K_d:
player.accelerate(3)
elif event.key == K_SPACE:
level_1.current_room.generate_player_laser(player)
if event.type == KEYUP:
if event.key == K_w:
player.deccelerate(0)
elif event.key == K_s:
player.deccelerate(1)
elif event.key == K_a:
player.deccelerate(2)
elif event.key == K_d:
player.deccelerate(3)
if event.key == K_ESCAPE:
if not paused:
paused = True
elif paused:
paused = False
if event.key == K_m:
if not map_showing:
map_showing = True
elif map_showing:
map_showing = False
pygame.display.update()