-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoom.py
More file actions
210 lines (191 loc) · 5.92 KB
/
Copy pathdoom.py
File metadata and controls
210 lines (191 loc) · 5.92 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import pyglet
from pyglet import shapes, window, clock, gl
from math import sqrt, cos, sin, tan, pi
import structure as C
import plans as P
import joueur as J
import monde as M
import scene3d as S
import sprites as I
import env
E = env.Env()
pyglet.resource.path = ['textures', 'sprites']
pyglet.resource.reindex()
# mode:
r=input("Mode plein écran (o/[n]) : ")
PLEIN_ECRAN = (r.upper()=="O")
r=input("Mode de dessin (0=fil_de_fer / [1]=rempli / 2=rempli+bordures (lent) : ")
if r=="": r = 1
else: r = int(r)
E.MODE_DESSIN = r
p=input("Quel plan (1 à [3]) : ")
if p=="": p = 3
else: p = int(p)
# joueur 2D
lot0 = pyglet.graphics.Batch()
# murs 2D
lot1 = pyglet.graphics.Batch()
# murs 3D
lot3 = pyglet.graphics.Batch()
CARTE_RATIO = 0.5
CARTE_XDECAL, CARTE_YDECAL = 20, 20
X0, Y0, S0 = 0, 0, 0
#X0, Y0, S0 = 0, 0, 1
# création des fenêtres
fenêtre0 = pyglet.window.Window(E.X_RES,E.Y_RES,"Visuel 2D absolu",vsync=False)
fenêtre0.set_location(fenêtre0.get_location()[0]+100,20)
if PLEIN_ECRAN:
écran = pyglet.canvas.get_display().get_screens()[0]
print(écran)
E.redef_Résolution(écran.width, écran.height)
fenêtre0.set_visible(False)
fenêtre1 = pyglet.window.Window(fullscreen=True, vsync=True)
else:
fenêtre1 = pyglet.window.Window(E.X_RES,E.Y_RES,"Visuel 2.5D csubjectif")
fenêtre1.set_location(fenêtre1.get_location()[0]+400,E.Y_RES//2)
fps = window.FPSDisplay(fenêtre1)
label = pyglet.text.Label("", font_name='Times New Roman', font_size=E.TAILLE_POLICE, x=0, y=0)
label2 = pyglet.text.Label("", font_name='Times New Roman', font_size=E.TAILLE_POLICE, x=0, y=E.Y_RES-20)
# création de la structure
s = C.Structure(env=E)
# création des plans
plan = P.Plans(s, env=E)
if p==1: param = plan.plan1()
elif p==2: param = plan.plan2()
elif p==3: param = plan.plan3()
X0,Y0,S0 = param[0]
CARTE_XDECAL,CARTE_YDECAL,CARTE_RATIO = param[1]
murs0 = param[2]
n,m = plan.ret_Taille()
print("Nb de secteurs:",n," Nb de murs:",m)
# création du joueur
j = J.Joueur(X0*plan.r,Y0*plan.r,E.A_DROIT,E.H_JOUEUR,S0,lot0,CARTE_RATIO)
# création du monde
monde = M.Monde(plan.S, murs0, j, lot1, env=E)
print("BSP:",monde.bsp.ret_Taille(),"noeuds - hauteur=",monde.bsp.ret_Hauteur(0))
# introduction des sprites
monde.S.I.modif_BSP(monde.bsp)
# rendu 2D de la carte
decal = (CARTE_XDECAL*plan.r,CARTE_YDECAL*plan.r)
monde.tracer_2D(CARTE_RATIO, decal)
# rendu 3D de la scène
scène = S.Scène3D(monde, env=E)
def redef_Env():
C.redef_Env(E)
P.redef_Env(E)
M.redef_Env(E)
S.redef_Env(E)
I.redef_Env(E)
@fenêtre0.event
def on_key_press(symbol, modifiers):
if symbol == window.key.Q: pyglet.app.exit()
j.keys[symbol] = True
@fenêtre0.event
def on_key_release(symbol, modifiers):
try:
del j.keys[symbol]
except:
pass
@fenêtre1.event
def on_key_press(symbol, modifiers):
global label
if symbol == window.key.Q: pyglet.app.exit()
j.keys[symbol] = True
if symbol == window.key.SPACE: # interrupteur lumière
monde.allumer(j.s)
if j.s in plan.cieux:
E.SOLEIL = not E.SOLEIL
redef_Env()
monde.init_Eclairage()
j.deplacement=True
afficher()
if symbol == window.key.ENTER:
scène.zBuf.afficher()
@fenêtre1.event
def on_key_release(symbol, modifiers):
try:
del j.keys[symbol]
except:
pass
@fenêtre0.event
def on_draw():
fenêtre0.clear()
j.afficher()
monde.aff_2D()
@fenêtre1.event
def on_draw():
pyglet.gl.glEnable(gl.GL_DEPTH_TEST)
if not j.deplacement:
fenêtre1.clear()
scène.aff_3D()
pyglet.gl.glDisable(gl.GL_DEPTH_TEST)
pyglet.gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
fps.draw()
label.draw()
label2.draw()
def afficher():
fenêtre0.switch_to()
decal = (CARTE_XDECAL*plan.r,CARTE_YDECAL*plan.r)
j.tracer(decal)
fenêtre1.switch_to()
while j.deplacement:
try:
scène.calc_Scène3D()
break
except S.recalc_3D:
if E.DEBUG>E.DEBUG_0: print("# exception (recalc_3D) #",end=" ")
n,m = scène.tracer_3D()
j.deplacement = False
label.text = "s="+str(j.s)+" calc="+scène.stats()+" quads="+str(n)+"(no="+str(m)+")(z="+str(round(scène.T.z,3))+") vz="+str(round(j.vz))
s = monde.secteurs[j.s]
if s.allumé == 0: label2.text = "SECTEUR éteint"
else: label2.text = "SECTEUR allumé"
def aug_Lumin(dlumin):
E.LUMIN0 += dlumin
redef_Env()
j.deplacement = True
def boucle(dt):
global scale, posx, rot
if j.deplacement: return # calc et tracer 3D en cours
if E.TOUCHE_ACCEL in j.keys:
coeff = E.COEFF_ACCEL
elif E.TOUCHE_RAL in j.keys:
coeff = E.COEFF_RAL
else:
coeff = 1
j.aller() # on sauvegarde les positions
if window.key.W in j.keys:
j.décaler(-E.PAS*coeff)
elif window.key.C in j.keys:
j.décaler(E.PAS*coeff)
if window.key.RIGHT in j.keys:
if E.TOUCHE_STRAFE in j.keys:
j.décaler(E.PAS*coeff)
else:
j.tourner(-E.A_ELEM*coeff/E.COEFF_PIVOT)
if window.key.LEFT in j.keys:
if E.TOUCHE_STRAFE in j.keys:
j.décaler(-E.PAS*coeff)
else:
j.tourner(E.A_ELEM*coeff/E.COEFF_PIVOT)
if window.key.UP in j.keys:
j.avancer(E.PAS*coeff)
if window.key.DOWN in j.keys:
j.avancer(-E.PAS*coeff)
if window.key.NUM_ADD in j.keys or window.key.PLUS in j.keys:
if window.key.LCTRL in j.keys:
aug_Lumin(1)
else: j.monter(1)
if window.key.NUM_SUBTRACT in j.keys or window.key.MINUS in j.keys:
if window.key.LCTRL in j.keys:
aug_Lumin(-1)
else: j.monter(-1)
if j.en_chute(): j.chuter()
if j.deplacement:
afficher()
j.deplacement=True
afficher()
if E.DEBUG>=E.DEBUG_1: print("distance collision:",E.D_COLLISION)
if E.FPS==0: pyglet.clock.schedule(boucle)
else: pyglet.clock.schedule_interval(boucle, E.FPS)
pyglet.app.run()