-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtutorial1.py
More file actions
91 lines (77 loc) · 3.59 KB
/
tutorial1.py
File metadata and controls
91 lines (77 loc) · 3.59 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ####################################################################
# Copyright (C) 2005-2013 by the FIFE team
# http://www.fifengine.net
# This file is part of FIFE.
#
# FIFE is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
# ####################################################################
import sys, os
from fife import fife
# Import the ApplicationBase. This is where a lot of magic happens but
# you don't need to know the inner workings just yet. Once you are more
# familiar with FIFE you'll understand ApplicationBase much more.
from fife.extensions.basicapplication import ApplicationBase
class Tutorial1Application(ApplicationBase):
"""
The main application. It inherits fife.extensions.ApplicationBase
and implements the _pump() function which gets called every frame.
"""
def __init__(self, settings):
# Call our base class's __init__ function and pass it settings.
# This is where the FIFE engine instance gets created and configured
# (amoungst other things). This includes reading the settings file,
# applying the settings to the engine, initializing PyChan (our GUI
# manager), creating the default application listener (more info on
# this in our later tutorials), and setting up logging. All of
# these things you can do on your own but we provide ApplicationBase
# to make your life easier.
super(Tutorial1Application,self).__init__(settings)
# Save a copy of our settings. This could be useful in the future
# as the Setting module allows you to store your own settins as
# well as FIFE settings.
self._settings = settings
# Initialize an instance of fife.MapLoader which is a built in map
# loader that we provide. We must pass it some internal FIFE objects
# that the loader requires to properly load a map.
self._loader = fife.MapLoader(self.engine.getModel(),
self.engine.getVFS(),
self.engine.getImageManager(),
self.engine.getRenderBackend())
# True if we have a map loaded. False otherwise.
self._mapLoaded = False
def loadMap(self, filename):
"""
Simple function to load and display a map file. We could of course
have passed in the map filename but I'll leave that up to you.
"""
# This is the map filename. Notice that it is relative to the tutorial
# directory.
self._mapfilename = filename
# Check to make sure the map file is loadable (i.e. it's in the correct
# format) and attempt to load the map.
if self._loader.isLoadable(self._mapfilename):
self._map = self._loader.load(self._mapfilename)
self._mapLoaded = True
def _pump(self):
"""
This function gets called every frame. This is where you want to
call your main game logic code.
"""
# On our first frame the map will be loaded
if not self._mapLoaded:
self.loadMap("../assets/maps/tutorial1map.xml")