Trying to move the view.
[krufty_fps.git] / demo / experimental.py
blob82a6dd78ab4f3897bf1c645b6b4c5d4b42290d2b
1 #!/usr/bin/python
2 # this has some dom related functions
4 import pygame
5 from pygame import *
7 import OpenGL
8 import OpenGL.GL
9 from OpenGL.GL import *
10 import OpenGL.GLU
11 from OpenGL.GLU import *
13 def reduceDOM(dom):
15 results = {}
17 cur = []
19 def parseLevel(level):
20 parsed_stuff = [[], {}]
22 if level.hasAttributes():
23 for i in range(len(level.attributes)):
25 attrname = level.attributes.item(i).name.encode()
27 parsed_stuff[1][attrname] = level.attributes.item(1).value.encode()
29 if len(level.childNodes) == 1 and level.childNodes[0].nodeType == 3:
31 parsed_stuff[0] = level.childNodes[0].nodeValue.encode()
33 else:
35 parsed_stuff[0] = []
37 for node in level.childNodes:
38 if node.nodeType == 1:
40 name, contents = parseLevel(node)
41 parsed_stuff[0].append([name, contents])
43 return level.nodeName.encode(), parsed_stuff
45 results = parseLevel(dom.childNodes[0])
47 return results
49 def reduceConfig(config):
51 results = {}
53 for item in config[1][0]:
54 results[item[0]] = item[1][0]
56 return results
58 def reduceObjectDef(file):
60 results = {}
62 for item in file[1][0]:
64 results[item[0]] = item[1][0]
66 return results
68 def reduceMenuDef(file):
70 name = None
71 script = None
72 elements = {}
74 for item in file[1][0]:
76 if item[0] == 'name':
77 name = item[1][0]
79 if item[0] == 'script':
80 script = item[1][0]
82 if item[0] != 'script' and item[0] != 'name':
83 temp = item[1][1]
84 temp['contents'] = item[1][0]
85 temp['type'] = item[0]
86 elements[temp['id']] = temp
88 return name, script, elements
90 def reduceInstance(item):
92 type = item[0]
93 results = item[1][1]
95 results['contents'] = item[1][0]
97 return type, results
99 def convertEvent(e):
100 data = {}
102 if e.type == QUIT:
103 data['none'] = ''
105 if e.type == ACTIVEEVENT:
106 data['gain'] = e.gain
107 data['state'] = e.state
109 if e.type == KEYDOWN:
110 data['unicode'] = e.unicode
111 data['key'] = e.key
112 data['mod'] = e.mod
114 if e.type == KEYUP:
115 data['key'] = e.key
116 data['mod'] = e.mod
118 if e.type == MOUSEMOTION:
119 data['pos'] = e.pos
120 data['rel'] = e.rel
121 data['buttons'] = e.buttons
123 if e.type == MOUSEBUTTONUP:
124 data['pos'] = e.pos
125 data['button'] = e.button
127 if e.type == MOUSEBUTTONDOWN:
128 data['pos'] = e.pos
129 data['button'] = e.button
131 if e.type == JOYAXISMOTION:
132 data['joy'] = e.joy
133 data['axis'] = e.axis
134 data['value'] = e.value
136 if e.type == JOYBALLMOTION:
137 data['joy'] = e.joy
138 data['ball'] = e.ball
139 data['rel'] = e.rel
141 if e.type == JOYHATMOTION:
142 data['joy'] = e.joy
143 data['hat'] = e.hat
144 data['value'] = e.value
146 if e.type == JOYBUTTONUP:
147 data['joy'] = e.joy
148 data['button'] = e.button
150 if e.type == JOYBUTTONDOWN:
151 data['joy'] = e.joy
152 data['button'] = e.button
154 if e.type == VIDEORESIZE:
155 data['size'] = e.size
156 data['w'] = e.w
157 data['h'] = e.h
159 if e.type == VIDEOEXPOSE:
160 data['none'] = ''
162 if e.type == USEREVENT:
163 data['code'] = e.code
165 type = ''
167 if e.type == QUIT: type = "QUIT"
168 if e.type == ACTIVEEVENT: type = "ACTIVEEVENT"
169 if e.type == KEYDOWN: type = "KEYDOWN"
170 if e.type == KEYUP: type = "KEYUP"
171 if e.type == MOUSEMOTION : type = "MOUSEMOTION"
172 if e.type == MOUSEBUTTONUP: type = "MOUSEBUTTONUP"
173 if e.type == MOUSEBUTTONDOWN: type = "MOUSEBUTTONDOWN"
174 if e.type == JOYAXISMOTION: type = "JOYAXISMOTION"
175 if e.type == JOYBALLMOTION: type = "JOYBALLMOTION"
176 if e.type == JOYHATMOTION: type = "JOYHATMOTION"
177 if e.type == JOYBUTTONUP: type = "JOYBUTTONUP"
178 if e.type == JOYBUTTONDOWN: type = "JOYBUTTONDOWN"
179 if e.type == VIDEORESIZE: type = "VIDEORESIZE"
180 if e.type == VIDEOEXPOSE: type = "VIDEOEXPOSE"
181 if e.type == USEREVENT: type = "USEREVENT"
183 return [type, data]
185 def d():
186 glBegin(GL_TRIANGLES)
188 glColor3f(1.0,0.0,0.0)
189 glVertex3f( 0.0, 1.0, 0.0)
190 glColor3f(0.0,1.0,0.0)
191 glVertex3f(-1.0,-1.0, 1.0)
192 glColor3f(0.0,0.0,1.0)
193 glVertex3f( 1.0,-1.0, 1.0)
195 glColor3f(1.0,0.0,0.0)
196 glVertex3f( 0.0, 1.0, 0.0)
197 glColor3f(0.0,0.0,1.0)
198 glVertex3f( 1.0,-1.0, 1.0)
199 glColor3f(0.0,1.0,0.0)
200 glVertex3f( 1.0,-1.0, -1.0)
202 glColor3f(1.0,0.0,0.0)
203 glVertex3f( 0.0, 1.0, 0.0)
204 glColor3f(0.0,1.0,0.0)
205 glVertex3f( 1.0,-1.0, -1.0)
206 glColor3f(0.0,0.0,1.0)
207 glVertex3f(-1.0,-1.0, -1.0)
210 glColor3f(1.0,0.0,0.0)
211 glVertex3f( 0.0, 1.0, 0.0)
212 glColor3f(0.0,0.0,1.0)
213 glVertex3f(-1.0,-1.0,-1.0)
214 glColor3f(0.0,1.0,0.0)
215 glVertex3f(-1.0,-1.0, 1.0)
216 glEnd()