Im not even positive anyone is even wanting to follow the progress of this lol but just in case one person is here is change log 1 lol
Change Log
Event Manager
- Added
class Listener - Connected
touchevents fromGameLooptoEventManager
Items
Added
- TrainingShortSword for testing Inventory
Removed
- None
Inventory System
- Added Open/Close Functionality for menu
- Added item durability handling, Bar animations
- Added item Stacking
- added item Weight handeling for inventory limitations and posible movement modifications.
Misc
class Tick- updates
GameObjectswithgameLoop - Provides aditional control over timed execution
class Sprite(SpriteNode)rpg Template attributes. must subclass this instead ofSpriteNodeclass UIButton(Sprite)Similar touimodules with more Customizable features.
Following is a snippet of the Event classes and video of the inventory animation for anyone who needs and if anyone knows of a better way of doing this please post in comments π€
from scene import *
sw, sh = get_screen_size()
class Tick:
val = 0.1 # Current Delta at Tick
last_tick = 0.1 # Delta at last Tick
intervals = 1.0 # time in seconds between Ticks
objects_to_update = [] # Objects updated every Tick
# Displays Tick data
label = LabelNode(text = 'Tick: ', color = (0.0, 1.0, 0.0, 1.0),
position = Point(0.0, sh - 20), anchor_point = (0.0, 0.0))
@classmethod
def dt(cls):
return round(cls.val, 4)
@classmethod
def set(cls, val):
cls.last_tick, cls.val = cls.val, val
if cls.val < cls.last_tick:
cls.label.color = (0.0, 0.75, 0.0, 0.0)
cls.label.text = f'Tick: {cls.dt()}'
else:
cls.label.color = (0.75, 0.0, 0.0, 0.0)
cls.label.text = f'Tick: {cls.dt()}'
@classmethod
def Display(cls, other): other.add_child(cls.label)
@classmethod
def size(cls): return len(cls.objects_to_update)
@classmethod
def Add(cls, object): cls.objects_to_update.append(object)
@classmethod
def _update(cls, GameLoop):
cls.set(GameLoop.dt)
if cls.objects_to_update:
for child in cls.objects_to_update:
child.update(cls.dt, GameLoop)
class Listener:
def __init__(self, node, reaction):
self.node, self.reaction = node, reaction
class EventManager:
listeners = list([])
@classmethod
def AddListener(cls, node, func):
cls.listeners.append(Listener(node, func))
@classmethod
def touch_began(cls, touch):
'''
β¦ Iterate through provided Listener Objects.
β¦ check if touch is valid for Lstener
β¦ If So Run Function
'''
if cls.listeners:
for l in cls.listeners:
p = l.node.parent.point_from_scene(touch.location)
if(p in l.node.frame): l.reaction()
@classmethod
def touch_moved(cls, touch): pass
@classmethod
def touch_ended(cls, touch): pass
class Chest(SpriteNode): # Interactive Object
def __init__(self, x, y, w, h, *args, **kwargs):
self.position = Point(x, y)
self.w, self.h = w, h
self.size = Size(w, h)
self.img1 = Texture('plc:Chest_Closed')
self.img2 = Texture('plc:Chest_Open')
self.isOpen = False
super().__init__(texture=self.img1, position=self.position,
size=self.size, z_position=10, *args, **kwargs)
def Toggle(self): #Open and Close Chest
self.isOpen = not self.isOpen
self.texture = self.img2 if self.isOpen else self.img1
self.size=Size(self.w, self.h)
def Ground(t, x, y, w, h, z): # Sprite Builder
return SpriteNode(
texture = Texture(t),
position = Point(x, y),
anchor_point = (0.0, 0.0),
size = Size(w, h),
z_position = z)
class GameLoop (Scene):
def setup(self):
self.background_color = (0.45, 0.79, 1.0, 1.0)
self.tt=0.0 #Tick Timer
Tick.Display(self)
i=0
w, h = self.size
for y in range(20):
for x in range(3):
if y == 0:
if x != 1:
self.add_child(
Ground('plc:Grass_Block',
x*w/3, (h/10)-(y*h/100*20),
256, 128, 1))
continue
chest = Chest(
x*w/2, (h/4.5)+(y*128),
128, 128)
EventManager.AddListener(chest, chest.Toggle)
self.add_child(chest)
self.add_child(
Ground('plc:Wood_Block',
x*w/3, (h/10)-(y*h/100*20),
256, 128, 1))
continue
self.add_child(
Ground('plc:Dirt_Block',
x*w/3, (h/10)-(y*32),
256, 128, y*-1))
def update(self):
self.tt = (self.tt + self.dt) if self.tt < Tick.intervals else 0.0
if self.tt >= Tick.intervals:
Tick._update(self)
self.tt=0.0
def touch_began(self, touch):
EventManager.touch_began(touch)
def touch_moved(self, touch):
EventManager.touch_moved(touch)
def touch_ended(self, touch):
EventManager.touch_ended(touch)
if(__name__=='__main__'):
run(GameLoop())