Forum Archive

[RPG Update] - For those following along

stephen

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 touch events from GameLoop to EventManager

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 GameObjects with gameLoop
  • Provides aditional control over timed execution
  • class Sprite(SpriteNode) rpg Template attributes. must subclass this instead of SpriteNode
  • class UIButton(Sprite) Similar to ui modules 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 πŸ€“

Video


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())

stephen

UPDATED

original codeblock for example was incorect.. coppied wrong file lol..

now you can run code as is to demo the EventManager πŸ˜‰πŸ€“πŸ˜Ž

cvp

@stephen I didn't dare say something πŸ˜‡

stephen

@cvp haha thanks

Drizzel

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

Don’t sell yourself shortπŸ˜‚ it’s always interesting to know what others are working on

stephen

@Drizzel haha thanks lol its been a pain to write at times but it will be worth it for anyone interested in making rpg's on pythonista lol

DoinStuffMobile

@stephen Hey I just registered for this forum and this is the first thread I went to. Just wanted to let you know that I'm very very interested in your project! Is there a place that you post more about it? Do you have a specific thread on here about it? Use Discord? Youtube?

I couldn't find a private message option in your profile, but I wanted to reach out when I saw you're cool project. Thanks for posting!

stephen

@DoinStuffMobile

Hello!

This project is Still Active 😁 i did take a quick break to write Space Escape to help people new to Creating game with scene and Pythonista. its not a tutorial but more a Playable mini-game. but the code is written as a group of examples of ways to implement diferent aspects of a game. all the image are built-in so only thing needed is the script. i recently added a version that works on iphone but still has a few sizing isues but code is the same. if your new to Video Game Programing there is a Tutorial in the Examples Folder and i suggest doing that first because there is some basics that you might need to understand in order to fully follow my example. you can find that post here. if you are experienced in this area and would like to participate in my RPG Template project you can let me know on this thread or e-mail me at stephenmfrey@icloud.com. And if you just would like to sit back and watch from an update by update manner thats ok too πŸ™ƒ

if you ever have any questions please dont hesitate to ask