forked from fofix/fofix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scene.py
105 lines (88 loc) · 3.47 KB
/
Scene.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
# -*- coding: utf-8 -*-
#####################################################################
# #
# Frets on Fire X (FoFiX) #
# Copyright (C) 2009-2010 FoFiX Team #
# See CREDITS for a full list of contributors #
# #
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License #
# as published by the Free Software Foundation; either version 2 #
# of the License, or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the Free Software #
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, #
# MA 02110-1301, USA. #
#####################################################################
from View import BackgroundLayer
from Input import KeyListener
from Camera import Camera
from OpenGL.GL import *
from OpenGL.GLU import *
#stump: raised by a scene constructor to abort scene processing
class SuppressScene(Exception):
pass
class Scene(BackgroundLayer, KeyListener):
def __init__(self, engine):
self.engine = engine
self.actors = []
self.camera = Camera()
self.world = None
self.space = None
self.time = 0.0
self.actors = []
self.players = self.engine.world.getPlayers()
self.controls = engine.input.controls
#for simplification of theme writing
self.fontDict = self.engine.data.fontDict
self.geometry = self.engine.view.geometry[2:4]
self.fontScreenBottom = self.engine.data.fontScreenBottom
self.aspectRatio = self.engine.view.aspectRatio
self.drawImage = self.engine.drawImage
self.drawStarScore = self.engine.drawStarScore
def addPlayer(self, player):
self.players.append(player)
def removePlayer(self, player):
self.players.remove(player)
def run(self, ticks):
self.time += ticks / 50.0
def shown(self):
self.engine.input.addKeyListener(self)
def hidden(self):
self.engine.input.removeKeyListener(self)
def keyPressed(self, key, unicode):
c = self.controls.keyPressed(key)
if c:
return True
return False
def keyReleased(self, key):
c = self.controls.keyReleased(key)
if c:
return True
return False
def render3D(self):
pass
def render(self, visibility, topMost):
font = self.engine.data.font
# render the scene
try:
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
gluPerspective(60, self.engine.view.aspectRatio, 0.1, 1000)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glPushMatrix()
self.camera.apply()
self.render3D()
finally:
glPopMatrix()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)