Mercurial > touhou
annotate eclviewer.py @ 97:ac2e5e1c2c3c
Refactor \o/
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 04 Sep 2011 23:50:00 +0200 |
parents | ca571697ec83 |
children | 5c40cc1b8019 |
rev | line source |
---|---|
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
2 # -*- encoding: utf-8 -*- |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
3 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
4 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
5 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
6 ## This program is free software; you can redistribute it and/or modify |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
7 ## it under the terms of the GNU General Public License as published |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
8 ## by the Free Software Foundation; version 3 only. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
9 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
10 ## This program is distributed in the hope that it will be useful, |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
13 ## GNU General Public License for more details. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
14 ## |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
15 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
16 import sys |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
17 import os |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
18 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
19 import struct |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
20 from math import degrees, radians |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
21 from itertools import chain |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
22 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
23 import pygame |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
24 |
97 | 25 from pytouhou.resource.loader import Loader |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
26 from pytouhou.game.background import Background |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
27 from pytouhou.opengl.texture import TextureManager |
97 | 28 from pytouhou.game.game import Game |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
49
diff
changeset
|
29 from pytouhou.game.player import Player |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
30 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
31 import OpenGL |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
32 OpenGL.FORWARD_COMPATIBLE_ONLY = True |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
33 from OpenGL.GL import * |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
34 from OpenGL.GLU import * |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
35 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
36 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
37 def main(path, stage_num): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
38 # Initialize pygame |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
39 pygame.init() |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
40 window = pygame.display.set_mode((384, 448), pygame.OPENGL | pygame.DOUBLEBUF) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
41 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
42 # Initialize OpenGL |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
43 glMatrixMode(GL_PROJECTION) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
44 glLoadIdentity() |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
45 gluPerspective(30, float(window.get_width())/window.get_height(), 101010101./2010101., 101010101./10101.) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
46 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
47 glEnable(GL_BLEND) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
48 glEnable(GL_TEXTURE_2D) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
49 glEnable(GL_FOG) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
50 glHint(GL_FOG_HINT, GL_NICEST) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
51 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
52 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) |
37
a10e3f44a883
Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
53 glEnableClientState(GL_COLOR_ARRAY) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
54 glEnableClientState(GL_VERTEX_ARRAY) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
55 glEnableClientState(GL_TEXTURE_COORD_ARRAY) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
56 |
97 | 57 resource_loader = Loader() |
58 texture_manager = TextureManager(resource_loader) | |
59 resource_loader.scan_archives(os.path.join(path, name) | |
60 for name in ('CM.DAT', 'ST.DAT')) | |
61 game = Game(resource_loader, [Player()], stage_num, 3, 16) | |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
62 |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
63 # Load common data |
97 | 64 etama_anm_wrappers = (resource_loader.get_anm_wrapper(('etama3.anm',)), |
65 resource_loader.get_anm_wrapper(('etama4.anm',))) | |
66 effects_anm_wrapper = resource_loader.get_anm_wrapper(('eff00.anm',)) | |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
67 |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
68 # Load stage data |
97 | 69 stage = resource_loader.get_stage('stage%d.std' % stage_num) |
70 enemies_anm_wrapper = resource_loader.get_anm_wrapper2(('stg%denm.anm' % stage_num, | |
71 'stg%denm2.anm' % stage_num)) | |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
72 |
97 | 73 background_anm_wrapper = resource_loader.get_anm_wrapper(('stg%dbg.anm' % stage_num,)) |
74 background = Background(stage, background_anm_wrapper) | |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
75 |
97 | 76 # Preload textures |
77 for anm_wrapper in chain(etama_anm_wrappers, | |
78 (background_anm_wrapper, enemies_anm_wrapper, | |
79 effects_anm_wrapper)): | |
80 texture_manager.preload(anm_wrapper) | |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
81 |
97 | 82 # Let's go! |
83 print(stage.name) | |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
84 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
85 # Main loop |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
86 clock = pygame.time.Clock() |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
87 while True: |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
88 # Check events |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
89 for event in pygame.event.get(): |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
90 if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key in (pygame.K_ESCAPE, pygame.K_q)): |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
91 sys.exit(0) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
92 elif event.type == pygame.KEYDOWN: |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
93 if event.key == pygame.K_RETURN and event.mod & pygame.KMOD_ALT: |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
94 pygame.display.toggle_fullscreen() |
97 | 95 keystate = 0 #TODO |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
96 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
97 # Update game |
97 | 98 background.update(game.game_state.frame) #TODO |
99 game.run_iter(keystate) | |
59
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
100 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
101 # Draw everything |
37
a10e3f44a883
Add alpha (anm0 instruction 3) support
Thibaut Girka <thib@sitedethib.com>
parents:
25
diff
changeset
|
102 # glClearColor(0.0, 0.0, 1.0, 0) |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
103 glClear(GL_DEPTH_BUFFER_BIT) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
104 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
105 fog_b, fog_g, fog_r, _, fog_start, fog_end = background.fog_interpolator.values |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
106 x, y, z = background.position_interpolator.values |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
107 dx, dy, dz = background.position2_interpolator.values |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
108 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
109 glFogi(GL_FOG_MODE, GL_LINEAR) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
110 glFogf(GL_FOG_START, fog_start) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
111 glFogf(GL_FOG_END, fog_end) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
112 glFogfv(GL_FOG_COLOR, (fog_r / 255., fog_g / 255., fog_b / 255., 1.)) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
113 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
114 #TODO |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
115 glMatrixMode(GL_MODELVIEW) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
116 glLoadIdentity() |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
117 # Some explanations on the magic constants: |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
118 # 192. = 384. / 2. = width / 2. |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
119 # 224. = 448. / 2. = height / 2. |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
120 # 835.979370 = 224./math.tan(math.radians(15)) = (height/2.)/math.tan(math.radians(fov/2)) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
121 # This is so that objects on the (O, x, y) plane use pixel coordinates |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
122 gluLookAt(192., 224., - 835.979370 * dz, |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
123 192. + dx, 224. - dy, 0., 0., -1., 0.) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
124 glTranslatef(-x, -y, -z) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
125 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
126 glEnable(GL_DEPTH_TEST) |
94
ca571697ec83
Various minor optimisations and refactoring
Thibaut Girka <thib@sitedethib.com>
parents:
92
diff
changeset
|
127 for (texture_key, blendfunc), (nb_vertices, vertices, uvs, colors) in background.objects_by_texture.items(): |
92
85f3b8ba3f24
Minor refactoring and optimizations. Drop stageviewer.
Thibaut Girka <thib@sitedethib.com>
parents:
83
diff
changeset
|
128 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
129 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key]) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
130 glVertexPointer(3, GL_FLOAT, 0, vertices) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
131 glTexCoordPointer(2, GL_FLOAT, 0, uvs) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
132 glColorPointer(4, GL_UNSIGNED_BYTE, 0, colors) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
133 glDrawArrays(GL_QUADS, 0, nb_vertices) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
134 glDisable(GL_DEPTH_TEST) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
135 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
136 #TODO |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
137 glMatrixMode(GL_MODELVIEW) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
138 glLoadIdentity() |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
139 # Some explanations on the magic constants: |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
140 # 192. = 384. / 2. = width / 2. |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
141 # 224. = 448. / 2. = height / 2. |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
142 # 835.979370 = 224./math.tan(math.radians(15)) = (height/2.)/math.tan(math.radians(fov/2)) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
143 # This is so that objects on the (O, x, y) plane use pixel coordinates |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
144 gluLookAt(192., 224., - 835.979370, |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
145 192., 224., 0., 0., -1., 0.) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
146 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
147 glDisable(GL_FOG) |
92
85f3b8ba3f24
Minor refactoring and optimizations. Drop stageviewer.
Thibaut Girka <thib@sitedethib.com>
parents:
83
diff
changeset
|
148 objects_by_texture = {} |
97 | 149 game.get_objects_by_texture(objects_by_texture) |
94
ca571697ec83
Various minor optimisations and refactoring
Thibaut Girka <thib@sitedethib.com>
parents:
92
diff
changeset
|
150 for (texture_key, blendfunc), (vertices, uvs, colors) in objects_by_texture.items(): |
92
85f3b8ba3f24
Minor refactoring and optimizations. Drop stageviewer.
Thibaut Girka <thib@sitedethib.com>
parents:
83
diff
changeset
|
151 nb_vertices = len(vertices) |
85f3b8ba3f24
Minor refactoring and optimizations. Drop stageviewer.
Thibaut Girka <thib@sitedethib.com>
parents:
83
diff
changeset
|
152 glBlendFunc(GL_SRC_ALPHA, (GL_ONE_MINUS_SRC_ALPHA, GL_ONE)[blendfunc]) |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
153 glBindTexture(GL_TEXTURE_2D, texture_manager[texture_key]) |
92
85f3b8ba3f24
Minor refactoring and optimizations. Drop stageviewer.
Thibaut Girka <thib@sitedethib.com>
parents:
83
diff
changeset
|
154 glVertexPointer(3, GL_FLOAT, 0, struct.pack(str(3 * nb_vertices) + 'f', *chain(*vertices))) |
85f3b8ba3f24
Minor refactoring and optimizations. Drop stageviewer.
Thibaut Girka <thib@sitedethib.com>
parents:
83
diff
changeset
|
155 glTexCoordPointer(2, GL_FLOAT, 0, struct.pack(str(2 * nb_vertices) + 'f', *chain(*uvs))) |
85f3b8ba3f24
Minor refactoring and optimizations. Drop stageviewer.
Thibaut Girka <thib@sitedethib.com>
parents:
83
diff
changeset
|
156 glColorPointer(4, GL_UNSIGNED_BYTE, 0, struct.pack(str(4 * nb_vertices) + 'B', *chain(*colors))) |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
157 glDrawArrays(GL_QUADS, 0, nb_vertices) |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
158 glEnable(GL_FOG) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
159 |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
160 pygame.display.flip() |
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
161 clock.tick(120) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
162 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
163 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
164 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
165 try: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
166 file_path, stage_num = sys.argv[1:] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
167 stage_num = int(stage_num) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
168 except ValueError: |
83
fc0294c745b6
Basic bullet handling! Clean up as soon as possible :p
Thibaut Girka <thib@sitedethib.com>
parents:
72
diff
changeset
|
169 print('Usage: %s game_dir_path stage_num' % sys.argv[0]) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
170 else: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
171 main(file_path, stage_num) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
172 |