items can now be used to place other entities on the map. (stones can build walls)
This commit is contained in:
parent
b667d6ce70
commit
7c65706fc7
|
@ -37,20 +37,23 @@ The idea is to make 3 different kind of areas:
|
|||
|
||||
- better code documentation
|
||||
- test server robustness
|
||||
- loot
|
||||
- make items usable
|
||||
- farming
|
||||
- more content (rooms, objects etc)
|
||||
- equipment
|
||||
- configurable keybindings
|
||||
- better reaction on player death
|
||||
- room unloading when there are no players
|
||||
- better interaction selection
|
||||
- write converter to convert tiled map files to readable files
|
||||
- configurable graphics
|
||||
- multicharacter sprites in client
|
||||
- in-game chat
|
||||
- multiple socket types (regular unix, abstract unix, inet and websocket), selectable as command line arguments
|
||||
|
||||
## DONE
|
||||
|
||||
- loot
|
||||
- more efficient target detection for monsters
|
||||
- more efficient drawing/communication by only updating changed squares
|
||||
- growing plants
|
||||
|
|
|
@ -49,6 +49,7 @@ class Client:
|
|||
ord("S"): ("attack", "south"),
|
||||
ord("D"): ("attack", "east"),
|
||||
ord("A"): ("attack", "west"),
|
||||
ord("r"): ("use",)
|
||||
}
|
||||
|
||||
if not spectate:
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
import gameobjects
|
||||
|
||||
class Build:
|
||||
""" item type for item that can be placed on the map to become something more static (like buildable walls or crops)"""
|
||||
|
||||
def __init__(self, objType, objArgs=[], objKwargs={}):
|
||||
self.buildType = objType
|
||||
self.buildArgs = objArgs
|
||||
self.buildKwargs = objKwargs
|
||||
|
||||
def attach(self, obj, roomData):
|
||||
|
||||
self.owner = obj
|
||||
self.roomData = roomData
|
||||
|
||||
|
||||
def use(self, user):
|
||||
obj = gameobjects.makeEntity(self.buildType, self.roomData, *self.buildArgs, **self.buildKwargs)
|
||||
obj.place(user.getGround())
|
||||
self.owner.remove()
|
||||
|
|
@ -30,6 +30,9 @@ class InputController:
|
|||
|
||||
def executeAction(self, action):
|
||||
kind = action[0]
|
||||
|
||||
# probably time to make this a dict with the action as keys and the function as value
|
||||
|
||||
if kind == "move" and len(action) > 1:
|
||||
self.move.move(action[1])
|
||||
|
||||
|
@ -38,7 +41,7 @@ class InputController:
|
|||
for obj in self.owner.getNearObjects():
|
||||
if obj.getComponent("item") != None and self.inventory.canAdd(obj):
|
||||
self.inventory.add(obj)
|
||||
obj.remove()
|
||||
obj.unPlace()
|
||||
break
|
||||
|
||||
if kind == "drop":
|
||||
|
@ -58,6 +61,12 @@ class InputController:
|
|||
if obj.getComponent("fighter") != None and self.alignment.isEnemy(obj):
|
||||
self.fighter.attack(obj)
|
||||
break
|
||||
|
||||
|
||||
if kind == "use":
|
||||
for obj in self.inventory.getItems():
|
||||
obj.getComponent("item").use(self.owner)
|
||||
break
|
||||
|
||||
def getInteractions(self):
|
||||
return []
|
||||
|
|
|
@ -11,9 +11,15 @@ class Inventory:
|
|||
|
||||
def add(self, item):
|
||||
self.items.insert(0, item)
|
||||
item.addListener(self.onItemUpdate)
|
||||
|
||||
def drop(self, item):
|
||||
self.items.remove(item) # should I catch here?
|
||||
|
||||
def getItems(self):
|
||||
return list(self.items)
|
||||
|
||||
def onItemUpdate(self, item, action, *data):
|
||||
if action == "remove":
|
||||
print(item, action)
|
||||
self.drop(item)
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
|
||||
class Item:
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
def use(self, user):
|
||||
pass
|
||||
|
|
|
@ -42,14 +42,18 @@ class Entity:
|
|||
ground.addObj(self)
|
||||
self.ground = ground
|
||||
|
||||
def remove(self):
|
||||
def unPlace(self):
|
||||
|
||||
if self.ground:
|
||||
self.ground.removeObj(self)
|
||||
self.ground = None
|
||||
|
||||
|
||||
def remove(self):
|
||||
self.unPlace()
|
||||
for component in self.components.values():
|
||||
if hasattr(component, "remove"):
|
||||
component.remove()
|
||||
self.trigger("remove")
|
||||
|
||||
def addListener(self, callback, key=None):
|
||||
self.observable.addListener(callback, key)
|
||||
|
|
|
@ -15,6 +15,7 @@ from components.spawner import Spawner
|
|||
from components.grow import Growing
|
||||
from components.alignment import Alignment
|
||||
from components.loot import Loot
|
||||
from components.build import Build
|
||||
|
||||
""" This module contains factory functions for many placable entities, and a make function to call a factory by a string name """
|
||||
|
||||
|
@ -34,7 +35,7 @@ def makeTree(roomData):
|
|||
entities["tree"] = makeTree
|
||||
|
||||
def makeStone(roomData):
|
||||
return Entity(roomData, sprite="stone", height=0.2, components={"item": Item()})
|
||||
return Entity(roomData, sprite="stone", height=0.2, components={"item": Build("wall")})
|
||||
entities["stone"] = makeStone
|
||||
|
||||
def makePebble(roomData):
|
||||
|
|
|
@ -19,6 +19,7 @@ class Player:
|
|||
self.entity = None
|
||||
|
||||
self.data = {}
|
||||
# todo: ensure that items have correct roomData when inventory changes room
|
||||
self.inventory = Inventory(10)
|
||||
self.health = None
|
||||
self.maxHealth = 100
|
||||
|
|
Loading…
Reference in New Issue