-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGame.py
180 lines (124 loc) · 5.28 KB
/
Game.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# -*- coding: utf-8 -*-
import GfxCtx
import GfxRender as Gfx
import LabyObjects as LabyObj
import LabyText as Laby
import Entity
import MonsterEngine
__author__ = 'Yoann'
"""
Programme principal
"""
class GameSession():
"""
Cette class matérialise une session de jeu, elle asssure la transition entre les niveaux (cartes)
"""
def __init__(self):
self.playListFile = None
self._labyObject = None
self._gfxRender = None
self._entityMgr = None
# Création de la liste des Map
self.mapList = []
# Création du context Graphique
self._ctxGfx = GfxCtx.CtxGfx("Labyrinthe d'Info@Leze V0.80a")
self._ctxGfx.onNext = self._onNextMap
self._ctxGfx.onReload = self._onReload
# Affichage de l'interface
self._ctxGfx.construitInterface()
# Création de l'objet labyrinthe
self._labyObject = Laby.LabyText()
# initialise la liste des monstres
self._entityMgr = Entity.EntityList(self._labyObject)
# Initialise le call back lorsque que tous les monstre sont mort
self._entityMgr.OnFinish = self._labyObject.onAllMonsterDead
# initialisation du graphisme
self._gfxRender = Gfx.GfxRender(self._labyObject,self._entityMgr,self._ctxGfx)
self._gfxRender.OnMapEnd = self._onMapEnd
def loadMapList(self):
self.mapList = [
"./maps/MonsterOnly.json",
"./maps/TestLumiere.json",
"./maps/Spirale.json",
"./maps/Special.json",
"./maps/litle.json",
"./maps/Intro_001.json",
"./maps/Learning.json",
"./maps/Default.json",
"./maps/FindTheWay.json",
"./maps/Phasor.json"]
self.mapList.reverse()
def loadLaby(self,LabyName):
# charge le labyrinthe
self._labyObject.loadJSON(LabyName)
def loadMonster(self):
# Ajout d'un monstre
M = self._gfxRender.AddMonster('Simple', speed=0.5, pv=500)
M.engine = MonsterEngine.MME_Basic
M.moveToInitialPos()
# Ajout d'un monstre
M = self._gfxRender.AddMonster('More', speed=0.3, spriteFile="sprite/Hero/monster05.png", pv=500)
M.engine = MonsterEngine.MME_Standard
M.moveToInitialPos()
# Ajout d'un monstre
M = self._gfxRender.AddMonster('Flamiche', speed=0.2, spriteFile="sprite/Hero/flammiche.png", pv=1000)
M.engine = MonsterEngine.MME_Foward
M.moveToInitialPos()
M = None
def loadPlayer(self):
# Ajout du premier joueur
J1 = self._gfxRender.AddUser('John', pv=500)
# Affectation des touches
J1.bindKey({"N": "<Up>", "S": "<Down>", "O": "<Left>", "E": "<Right>"})
# Positionnement du joueur
J1.moveToInitialPos()
# Ajout du second joueur
J2 = self._gfxRender.AddUser('Melba', spriteFile='sprite/Hero/hero3.png', pv=500)
# Affectation des touches
J2.bindKey({"N": "z", "S": "s", "O": "q", "E": "d"})
J2.moveToInitialPos()
def loadFirstMap(self):
firstMap = self.mapList.pop()
self.loadLaby(firstMap)
self._ctxGfx.resizeLabyCanvas(self._labyObject.LX, self._labyObject.LY)
self._gfxRender.reInit()
def mainLoop(self):
# Lancement de la boucle principal (boucle graphique)
self._gfxRender.mainLoop()
def _onMapEnd(self):
# Call back utilisé pour détecté la fin d'une partie
print("GameSession::_onMapEnd: On Map End !!!!!!!!!!!")
time = self._ctxGfx.doEndMapTitle()
print("Time::", time)
self._onNextMap()
def _onNextMap(self):
#print("GameSession::_onNextMap")
try:
nextMap = self.mapList.pop()
print("GameSession::_onNextMap::=",nextMap)
except:
#if nextMap is None:
print("GameSession::_onNextMap::loadMap")
self.loadMapList()
nextMap = self.mapList.pop()
self.loadLaby(nextMap)
self._ctxGfx.resizeLabyCanvas(self._labyObject.LX, self._labyObject.LY)
self._entityMgr.reinitPlayer()
self._entityMgr.reinitMonster()
self._gfxRender.reInit()
def _onReload(self):
mapName = self._labyObject.FileName
print("GameSession::_onReload")
self.loadLaby(mapName)
self._ctxGfx.resizeLabyCanvas(self._labyObject.LX, self._labyObject.LY)
self._entityMgr.reinitPlayer()
self._entityMgr.reinitMonster()
self._gfxRender.reInit()
# Vérification que nous sommes dans le programme principal
if __name__ == "__main__":
SG = GameSession()
SG.loadMapList()
SG.loadFirstMap()
SG.loadPlayer()
SG.loadMonster()
SG.mainLoop()