comparison demos/shooter/run.py @ 446:2046a1f2f5f2

Adding the shooter demo. This is still a work in progress.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 31 Mar 2010 15:40:00 +0000
parents
children e686b82d93d0
comparison
equal deleted inserted replaced
445:f855809822cf 446:2046a1f2f5f2
1 #!/usr/bin/env python
2
3 # -*- coding: utf-8 -*-
4
5 # ####################################################################
6 # Copyright (C) 2005-2009 by the FIFE team
7 # http://www.fifengine.de
8 # This file is part of FIFE.
9 #
10 # FIFE is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Lesser General Public
12 # License as published by the Free Software Foundation; either
13 # version 2.1 of the License, or (at your option) any later version.
14 #
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Lesser General Public License for more details.
19 #
20 # You should have received a copy of the GNU Lesser General Public
21 # License along with this library; if not, write to the
22 # Free Software Foundation, Inc.,
23 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 # ####################################################################
25 # This is the rio de hola client for FIFE.
26
27 import sys, os, re, math, random, shutil
28
29 fife_path = os.path.join('..','..','engine','python')
30 if os.path.isdir(fife_path) and fife_path not in sys.path:
31 sys.path.insert(0,fife_path)
32
33 from fife import fife
34 print "Using the FIFE python module found here: ", os.path.dirname(fife.__file__)
35
36 from fife.extensions import *
37 from scripts import world
38 from scripts.common import eventlistenerbase
39 from fife.extensions.basicapplication import ApplicationBase
40 from fife.extensions import pychan
41 from fife.extensions.pychan import widgets
42
43 class ApplicationListener(eventlistenerbase.EventListenerBase):
44 def __init__(self, engine, world):
45 super(ApplicationListener, self).__init__(engine,regKeys=True,regCmd=True, regMouse=False, regConsole=True, regWidget=True)
46 self.engine = engine
47 self.world = world
48 engine.getEventManager().setNonConsumableKeys([
49 fife.Key.ESCAPE,])
50
51 self.quit = False
52
53 def keyPressed(self, evt):
54 keyval = evt.getKey().getValue()
55 keystr = evt.getKey().getAsString().lower()
56 consumed = False
57 if keyval == fife.Key.ESCAPE:
58 self.quit = True
59 evt.consume()
60
61 def onCommand(self, command):
62 self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME)
63 if self.quit:
64 command.consume()
65
66 class Tutorial(ApplicationBase):
67 def __init__(self):
68 super(Tutorial,self).__init__()
69 pychan.init(self.engine, debug=False)
70 self.world = world.World(self.engine)
71 self.listener = ApplicationListener(self.engine, self.world)
72 self.world.load("maps/shooter_map1.xml")
73
74 def loadSettings(self):
75 """
76 Load the settings from a python file and load them into the engine.
77 Called in the ApplicationBase constructor.
78 """
79
80 engineSetting = self.engine.getSettings()
81 engineSetting.setDefaultFontGlyphs(" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\"")
82 engineSetting.setDefaultFontPath("fonts/FreeSans.ttf")
83 engineSetting.setDefaultFontSize(12)
84 engineSetting.setBitsPerPixel(16)
85 engineSetting.setScreenWidth(1024)
86 engineSetting.setScreenHeight(768)
87 engineSetting.setRenderBackend("OpenGL")
88 engineSetting.setFullScreen(0)
89
90 try:
91 engineSetting.setWindowTitle("FIFE - Shooter")
92 except:
93 pass
94 try:
95 engineSetting.setImageChunkingSize(256)
96 except:
97 pass
98
99 def initLogging(self):
100 """
101 Initialize the LogManager.
102 """
103 #LogModules = list()
104 #LogModules.append("controller")
105 LogModules = ["controller",]
106 self.log = fifelog.LogManager(self.engine, 1, 0)
107 if LogModules:
108 self.log.setVisibleModules(*LogModules)
109
110 def createListener(self):
111 pass # already created in constructor
112
113 def _pump(self):
114 if self.listener.quit:
115 self.breakRequested = True
116 else:
117 self.world.pump()
118
119 def main():
120 app = Tutorial()
121 app.run()
122
123
124 if __name__ == '__main__':
125 main()