I made a simple test game and the same thing is still happening.
just drop it images into the image folder and it should do the same for others.
to see what is wrong you can click on the saber and it will work properly, but as soon as sword is selected the problem happens.
Code: Select all
init python:
class InvItem:
def __init__(self, name, cost, img):
self.name = name
self.cost = cost
self.img = img
class Equipable(InvItem):
def __init__(self, name, cost, img):
InvItem.__init__(self, name, cost, img)
def equip(self, target):
self.is_equipped = True
self.equipped_to = target
def unequip(self, target):
self.is_equipper = False
self.equipped_to = None
class Weapon(Equipable):
def __init__(self, name, cost, img, atk, wpn_type):
Equipable.__init__(self, name, cost, img)
self.atk = atk
self.wpn_type = wpn_type
def equip(self, target):
Equipable.equip(self, target)
target.equip_weapon(self)
def unequip(self, target):
self.equipped_to.unequip_weapon(self, target)
Equipable.unequip(self)
class Player:
def __init__(self, name, hp, mp, max_hp, max_mp, atk):
self.name = name
self.hp = hp
self.mp = mp
self.max_hp = hp
self.max_mp = mp
self.atk = atk
self.weapon = None
def equip_weapon(self, weapon):
if self.weapon != None:
self.unequip_weapon()
self.weapon = weapon
self.atk += weapon.atk
def unequip_weapon(self):
if self.weapon != None:
self.atk -= self.weapon.atk
self.weapon = None
default inventory = []
default heartinventory = []
default player = Player("Player", 25, 25, 25, 25, 5)
# The game starts here.
label start:
default sword = Weapon("Sword", 1, "weapon_sword.png", 1, "sword") #
default saber = Weapon("Saber", 1, "weapon_saber.png", 2, "sword") #
$ inventory.append(saber)
$ heartinventory.append(sword)
$ heartinventory.append(sword)
label mainbody_build:
scene bg getinmybelly
show screen mainbody_build_screen_inventory
show screen mainbody_build_screen_heartinventory
show screen mainbody_build_screen_equipment
call screen mainbody_build_screen
pause
screen mainbody_build_screen:
hbox:
spacing 150
vbox:
xsize 200
spacing 10
label "Character Details" xalign 0.5
label "HP: [player.hp]/[player.max_hp]"
label "atk: [player.atk]"
textbutton "Return":
action Hide("mainbody_build_screen_heartinventory"), Hide("mainbody_build_screen_inventory"), Jump("Heartworld")
screen mainbody_build_screen_equipment:
frame:
xsize 300
ysize 300
xpos .2 ypos .1
imagebutton:
idle [If(player.weapon == None, "equipment_weapon.png", "[player.weapon.img]")]
xalign .3 yalign .3
action If(player.weapon != None, true = AddToSet(heartinventory, player.weapon)), Function(player.unequip_weapon), Jump("mainbody_build")
screen mainbody_build_screen_inventory:
vpgrid:
cols 1
spacing 5
draggable True
mousewheel True
scrollbars "vertical"
xpos .6 ypos .1
xsize 300 ysize 300
for i in inventory:
if isinstance(i, Weapon):
imagebutton:
idle i.img
action If(player.weapon != None, true = AddToSet(heartinventory, player.weapon)), Function(i.equip, player), RemoveFromSet(inventory, i)
screen mainbody_build_screen_heartinventory:
vpgrid:
cols 4
spacing 5
draggable True
mousewheel True
scrollbars "vertical"
xpos .7 ypos .1
xsize 300 ysize 300
for i in heartinventory:
if isinstance(i, Weapon):
imagebutton:
idle i.img
action If(player.weapon != None, true = AddToSet(heartinventory, player.weapon)), Function(i.equip, player), RemoveFromSet(heartinventory, i)
label ending:
"The end."