-
Notifications
You must be signed in to change notification settings - Fork 1
/
Flashlight.py
executable file
·156 lines (135 loc) · 6.46 KB
/
Flashlight.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
146
147
148
149
150
151
152
153
154
155
156
from pygame.locals import * #@UnusedWildImport
from fl.globals import * #@UnusedWildImport
from fl.base.Game import Game
from fl.base.Menu import Menu
from fl.base.Stat import Stat
from fl.net.Client import Client
from fl.net.Network import *
from threading import Condition
from fl.menu.OptionMenu import OptionMenu
from fl.net.Server import Server
'''
Created on 2009/12/26
Classe Mae do jogo.
Esta eh a classe que cria os objectos Game, Menu e Client
@author: gnascim@gmail.com
'''
class Main(object):
'''Constructor da classe
Cria um objecto Game, Menu e Network.
'''
def __init__(self):
global STATE_MENU, STATE_GAME, STATE_STATS
STATE_MENU = 0
STATE_GAME = 1
STATE_STATS = 2
pygame.init()
#self.screen = pygame.display.set_mode((1024, 740),pygame.FULLSCREEN)
self.screen = pygame.display.set_mode((1024, 700))
pygame.display.set_caption("Flashlight")
pygame.display.set_icon(load_image("flashlight.jpg", "res/img"))
self.MainState = STATE_MENU
self.ip = "localhost"
self.port = 8740
self.customization = False
#criar o jogo
self.game = Game(self.screen)
self.menu = Menu(self.screen)
self.stat = Stat(self.screen)
self.client = None
self.audio = AudioResource()
self.loop()
os._exit(0)
def loop(self):
self.game.isMulti = False
running = True
while running:
if(self.MainState==STATE_GAME):
GameState = self.game.update()
#Se for multiplayer
if(self.game.isMulti==True):
#Tratar de msgs a enviar
if(self.game.SEND_MESSAGE):
if self.game.msg == "e":
print "MAIN catch 'e'"
self.client.treatOutgoing(self.game.msg)
quit()
else:
self.client.treatOutgoing(self.game.msg)
self.game.SEND_MESSAGE = False
if(GameState==GAME_CONTINUE):
self.game.render()
elif(GameState==GAME_ESCAPE):
self.menu.set_game(True)
self.MainState = STATE_MENU
elif(GameState==GAME_STAT):
self.stat.update_stat(self.game.stat())
GameState = self.stat.update()
self.MainState = STATE_STATS
elif(self.MainState==STATE_MENU):
MenuState = self.menu.update()
if(MenuState == START_SINGLE_GAME_EASY):
if not self.customization:
self.game.creation_player()
#Carregar Audio Resource
self.audio.AddMusic('res/music/MusicAction.mp3', 'GameAction')
self.audio.get_music('GameAction').set_volume(0.5)
self.audio.get_music('GameAction').load_music()
pygame.mixer.music.play(-1)
self.game.load_level("level1");
self.MainState = STATE_GAME
self.game.isMulti = False
self.game.creation_AI(2)
elif(MenuState == START_SINGLE_GAME_MEDIUM):
if not self.customization:
self.game.creation_player()
#Carregar Audio Resource
self.audio.AddMusic('res/music/MusicAction.mp3', 'GameAction')
self.audio.get_music('GameAction').set_volume(0.5)
self.audio.get_music('GameAction').load_music()
pygame.mixer.music.play(-1)
self.game.load_level("level1");
self.MainState = STATE_GAME
self.game.isMulti = False
self.game.creation_AI(3)
elif(MenuState == START_SINGLE_GAME_HARD):
if not self.customization:
self.game.creation_player()
#Carregar Audio Resource
self.audio.AddMusic('res/music/MusicAction.mp3', 'GameAction')
self.audio.get_music('GameAction').set_volume(0.5)
self.audio.get_music('GameAction').load_music()
pygame.mixer.music.play(-1)
self.game.load_level("level1");
self.MainState = STATE_GAME
self.game.isMulti = False
self.game.creation_AI(4)
if(MenuState == START_SERVER):
self.server = Server()
self.server.start()
if(MenuState == JOIN_SERVER):
if not self.customization:
self.game.creation_player()
#Carregar o nivel 1
#Carregar Audio Resource
self.audio.AddMusic('res/music/MusicAction.mp3', 'GameAction')
self.audio.get_music('GameAction').set_volume(0.5)
self.audio.get_music('GameAction').load_music()
pygame.mixer.music.play(-1)
self.game.load_level("level1");
self.MainState = STATE_GAME
self.game.isMulti = True
self.client = Client("cliente",self.game,self.ip, self.port)
self.game.set_client(self.client)
if(MenuState == CHANGE_OPTIONS):
options = OptionMenu()
(option1, option2, option3, option4) = options.results
self.game.creation_player(option3, option2)
self.ip = option1
if option4.text != '':
self.port = int(option4.text)
self.customization = True
elif(self.MainState==STATE_STATS):
if self.stat.update() == GAME_CONTINUE:
self.MainState = STATE_GAME
Main()