Mercurial > fife-parpg
changeset 520:b6bd314df28a
Added a quest dialog.
Added QuestGiver class.
Moved level specific settings to another file.
Added BaseItem class.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 27 May 2010 16:29:07 +0000 |
parents | 14f777be6b94 |
children | 494c60cf61cf |
files | demos/rpg/gui/quest.xml demos/rpg/maps/town_objects.xml demos/rpg/scripts/actors/baseactor.py demos/rpg/scripts/actors/player.py demos/rpg/scripts/gamecontroller.py demos/rpg/scripts/guicontroller.py demos/rpg/scripts/objects/baseobject.py demos/rpg/scripts/objects/items.py demos/rpg/scripts/scene.py demos/rpg/settings-dist.xml |
diffstat | 10 files changed, 184 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/rpg/gui/quest.xml Thu May 27 16:29:07 2010 +0000 @@ -0,0 +1,18 @@ +<Container base_color="0,0,0" border_size="0" opaque="0" position="0,0" name="questcontainer" size="1024,768"> + <VBox name="credits" position="312,200" opaque="1" base_color="188,0,0"> + <HBox> + <Spacer /> + <Label name="questlabel" border_size="0" text="Quest" /> + <Spacer /> + </HBox> + <HBox> + <ScrollArea min_size="400,400" max_size="400,400" size="400,400" vertical_scrollbar="1"> + <TextBox name="questtext"/> + </ScrollArea> + </HBox> + <HBox> + <Button name="accept" text="Accept"/> + <Button name="decline" text="Decline"/> + </HBox> + </VBox> +</Container>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/rpg/maps/town_objects.xml Thu May 27 16:29:07 2010 +0000 @@ -0,0 +1,7 @@ +<?xml version='1.0' encoding='UTF-8'?> +<Settings> + <Module name="town"> + <Setting name="npclist" type="list"> Quiller </Setting> + <Setting name="Quiller" type="list"> QUESTGIVER ; warrior ; 1.0 ; 1.0 </Setting> + </Module> +</Settings>
--- a/demos/rpg/scripts/actors/baseactor.py Thu May 27 04:36:09 2010 +0000 +++ b/demos/rpg/scripts/actors/baseactor.py Thu May 27 16:29:07 2010 +0000 @@ -29,12 +29,14 @@ from fife import fife from fife.extensions.loaders import loadMapFile -from scripts.objects.baseobject import ObjectActionListener, BaseGameObject +from scripts.objects.baseobject import ObjectActionListener, BaseGameObject, GameObjectTypes Actions = {'NONE':0, 'PICKUP':1, 'TALK':2, - 'HIT':3} + 'HIT':3, + 'OPEN':4, + 'ENTER':5} class BaseAction(object): def __init__(self): @@ -50,7 +52,8 @@ self._dest = destobj def execute(self): - print "talking" + print "talking to: " + self._dest.instance.getId() + self._source.showQuestDialog() ActorStates = {'STAND':0, 'WALK':1, @@ -76,6 +79,8 @@ self._nextaction = None self.stand() + + self._type = GameObjectTypes["NPC"] def stand(self): self._state = ActorStates["STAND"] @@ -104,3 +109,13 @@ state = property(_getState, _setState) nextaction = property(_getNextAction, _setNextAction) + +class QuestGiver(Actor): + def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False): + super(QuestGiver, self).__init__(gamecontroller, instancename, instanceid, createInstance) + + self._type = GameObjectTypes["QUESTGIVER"] + self._quests = [] + + def addQuest(self, quest): + self._quests.append(quest)
--- a/demos/rpg/scripts/actors/player.py Thu May 27 04:36:09 2010 +0000 +++ b/demos/rpg/scripts/actors/player.py Thu May 27 16:29:07 2010 +0000 @@ -28,7 +28,7 @@ from fife import fife from scripts.actors.baseactor import Actor, ActorStates -from scripts.objects.baseobject import ObjectActionListener, BaseGameObject +from scripts.objects.baseobject import ObjectActionListener, BaseGameObject, GameObjectTypes class PlayerActionListener(ObjectActionListener): def __init__(self, gamecontroller, obj): @@ -46,3 +46,8 @@ self._playermodelname = playermodelname self._playeractionlistener = PlayerActionListener(self._gamecontroller, self) + + self._type = GameObjectTypes["PLAYER"] + + def showQuestDialog(self): + self._gamecontroller.guicontroller.showQuestDialog()
--- a/demos/rpg/scripts/gamecontroller.py Thu May 27 04:36:09 2010 +0000 +++ b/demos/rpg/scripts/gamecontroller.py Thu May 27 16:29:07 2010 +0000 @@ -34,6 +34,7 @@ from scripts.scene import Scene from scripts.guicontroller import GUIController from scripts.actors.baseactor import TalkAction +from scripts.objects.baseobject import GameObjectTypes class KeyState(object): @@ -88,11 +89,15 @@ self._gamecontroller.scene.player.walk( self._gamecontroller.scene.getLocationAt(clickpoint) ) instances = self._gamecontroller.scene.getInstancesAt(clickpoint) if instances: - self._gamecontroller.scene.player.nextaction = TalkAction(self, self) + obj = self._gamecontroller.scene.objectlist[instances[0].getId()] + print obj.type + if obj.type == GameObjectTypes["QUESTGIVER"]: + action = TalkAction(self._gamecontroller.scene.player, obj) + self._gamecontroller.scene.player.nextaction = action if (event.getButton() == fife.MouseEvent.RIGHT): instances = self._gamecontroller.scene.getInstancesAt(clickpoint) - print "selected instances on actor layer: ", [i.getObject().getId() for i in instances] + print "selected instances on actor layer: ", [i.getId() for i in instances] if instances: #do something pass
--- a/demos/rpg/scripts/guicontroller.py Thu May 27 04:36:09 2010 +0000 +++ b/demos/rpg/scripts/guicontroller.py Thu May 27 16:29:07 2010 +0000 @@ -30,11 +30,22 @@ from fife.extensions import pychan from fife.extensions.pychan import widgets -class MainMenu(object): +class Window(object): def __init__(self, gamecontroller): self._guicontroller = gamecontroller.guicontroller self._gamecontroller = gamecontroller self._settings = gamecontroller.settings + + self._widget = None + + def _getWidget(self): + return self._widget + + widget = property(_getWidget) + +class MainMenu(Window): + def __init__(self, gamecontroller): + super(MainMenu, self).__init__(gamecontroller) self._widget = pychan.loadXML('gui/mainmenu.xml') self._newgame = self._widget.findChild(name="new_game") @@ -51,15 +62,10 @@ } self._widget.mapEvents(eventMap) - - def _getWidget(self): - return self._widget - - widget = property(_getWidget) -class Credits(object): +class Credits(Window): def __init__(self, guicontroller): - self._guicontroller = guicontroller + super(Credits, self).__init__(gamecontroller) self._widget = pychan.loadXML('gui/credits.xml') eventMap = { @@ -68,11 +74,24 @@ self._widget.mapEvents(eventMap) - def _getWidget(self): - return self._widget +class QuestDialog(Window): + def __init__(self, guicontroller): + super(QuestDialog, self).__init__(guicontroller) + self._widget = pychan.loadXML('gui/quest.xml') - widget = property(_getWidget) + self._questtext = self._widget.findChild(name="questtext") + + eventMap = { + 'accept': self.questAccepted, + 'decline': self._widget.hide, + } + self._widget.mapEvents(eventMap) + + def questAccepted(self): + print "quest has been accepted" + self._widget.hide() + class GUIController(object): def __init__(self, gamecontroller): self._gamecontroller = gamecontroller @@ -106,3 +125,7 @@ if self._credits: self._credits.widget.hide() self._credits = None + + def showQuestDialog(self): + questdlg = QuestDialog(self._gamecontroller) + questdlg.widget.show()
--- a/demos/rpg/scripts/objects/baseobject.py Thu May 27 04:36:09 2010 +0000 +++ b/demos/rpg/scripts/objects/baseobject.py Thu May 27 16:29:07 2010 +0000 @@ -29,6 +29,15 @@ from fife import fife from fife.extensions.loaders import loadMapFile +GameObjectTypes = { + "DEFAULT": 0, + "ITEM":1, + "QUESTGIVER":2, + "PLAYER":3, + "NPC":4, + "ENEMY":5 + } + class ObjectActionListener(fife.InstanceActionListener): def __init__(self, gamecontroller, obj): fife.InstanceActionListener.__init__(self) @@ -68,6 +77,8 @@ self._instance = self._gamecontroller.scene.actorlayer.getInstance(self._id) self._instance.thisown = 0 + self._type = GameObjectTypes["DEFAULT"] + def destroy(self): """ Deletes the FIFE instance from the actor layer on the map. @@ -105,6 +116,10 @@ def _getInstance(self): return self._instance - + + def _getType(self): + return self._type + location = property(_getLocation, _setLocation) instance = property(_getInstance) + type = property(_getType)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/demos/rpg/scripts/objects/items.py Thu May 27 16:29:07 2010 +0000 @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +# -*- coding: utf-8 -*- + +# #################################################################### +# Copyright (C) 2005-2010 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 +# #################################################################### +# This is the rio de hola client for FIFE. + +import sys, os, re, math, random, shutil + +from fife import fife + +from scripts.objects.baseobject import BaseGameObject, GameObjectTypes + + +class BaseItem(BaseGameObject): + def __init__(self, gamecontroller, itemname, itemtype="unknown"): + super(Item, self).__init__(gamecontroller, itemtype, itemname, True) + + self._type = GameObjectTypes["ITEM"] + + def onPickUp(self): + #remove item from the map + self.destroy() + + def onDrop(self, dropx, dropy): + #recreate object + self._createFIFEInstance(self) + self.setMapPosition(dropx, dropy) + + def _getItemType(self): + return self._name + + def _getItemName(self): + return self._id + + itemtype = property(_getItemType) + itemname = property(_getItemName)
--- a/demos/rpg/scripts/scene.py Thu May 27 04:36:09 2010 +0000 +++ b/demos/rpg/scripts/scene.py Thu May 27 16:29:07 2010 +0000 @@ -28,9 +28,12 @@ from fife import fife from fife.extensions.loaders import loadMapFile +from fife.extensions.fife_settings import Setting from scripts.actors.baseactor import Actor +from scripts.actors.baseactor import QuestGiver from scripts.actors.player import Player +from scripts.objects.baseobject import GameObjectTypes class Scene(object): def __init__(self, gamecontroller): @@ -43,7 +46,7 @@ self._actorlayer = None self._player = None - self._npclist = [] + self._objectlist = {} def createScene(self, mapfilename): if not self._map: @@ -61,11 +64,18 @@ self._player = Player(self._gamecontroller, "warrior") mapname = os.path.splitext(os.path.basename(mapfilename)) - for npc in self._gamecontroller.settings.get(mapname[0], "npclist", []): - (modelname, posx, posy) = self._gamecontroller.settings.get(mapname[0], npc, ["warrior", "0", "0"]) - actor = Actor(self._gamecontroller, modelname, npc, True) + objectfile = "maps/" + mapname[0] + "_objects.xml" + objectsettings = Setting(app_name="",settings_file=objectfile) + + for npc in objectsettings.get(mapname[0], "npclist", []): + (objtype, modelname, posx, posy) = objectsettings.get(mapname[0], npc, ["NPC", "warrior", "0", "0"]) + if objtype == "QUESTGIVER": + actor = QuestGiver(self._gamecontroller, modelname, npc, True) + elif objtype == "NPC": + actor = Actor(self._gamecontroller, modelname, npc, True) + actor.setMapPosition(float(posx), float(posy)) - self._npclist.append(actor) + self._objectlist[actor.instance.getId()] = actor def destroyScene(self): @@ -73,8 +83,8 @@ self._player.destroy() - for npc in self._npclist: - npc.destroy() + for obj in self._objectlist.values(): + obj.destroy() if self._map: self._gamecontroller.engine.getModel().deleteMap(self._map) @@ -83,7 +93,7 @@ self._actorlayer = None self._player = None - self._npclist = [] + self._objectlist.clear() def getInstancesAt(self, clickpoint): """ @@ -114,7 +124,11 @@ def _getPlayer(self): return self._player + def _getObjectList(self): + return self._objectlist + actorlayer = property(_getActorLayer) cameras = property(_getCameras) player = property(_getPlayer) + objectlist = property(_getObjectList)
--- a/demos/rpg/settings-dist.xml Thu May 27 04:36:09 2010 +0000 +++ b/demos/rpg/settings-dist.xml Thu May 27 16:29:07 2010 +0000 @@ -33,9 +33,4 @@ <Setting name="DefaultActorWalkSpeed" type="float"> 2.5 </Setting> </Module> - - <Module name="town"> - <Setting name="npclist" type="list"> Quiller </Setting> - <Setting name="Quiller" type="list"> warrior ; 0 ; 0</Setting> - </Module> </Settings>