Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Armour is not working?
#11
Something can't be both True AND False. Must be one OR the other, like a switch. On OR off, up OR down, never both. True OR False.
Reply
#12
Maybe a different approach will help.
Like making simple framework interface.
Example. An idea how to start.
class EquipArmor:
    def __init__(self):
        self.head = None
        self.chest = None
        self.legs = None
        self.feet = None

    # Check if armor can be equip.
    def equip_chest(self, armor):
        if armor is None:
            self.chest = None
            return True

        if isinstance(armor, ChestArmor):
            self.chest = armor
            return True

        return False

    # Get total protection from all armor.
    def get_protection(self):
        protection = 0
        for armor in vars(self).values():
            if armor:
                protection += armor.protection

        return protection

class Armor:
    library = {}

    def __init__(self, name, protection):
        # Make sure that all armor will have a name and protection variables.
        self.name = name
        self.protection = protection
        Armor.library[self.name] = self

# Identify armor type
class ChestArmor(Armor):
    def __init__(self, name, protection):
        Armor.__init__(self, name, protection)

ChestArmor("Leather Chest Plate", 5)
ChestArmor("Leather", 2)

player = EquipArmor()
print(player.get_protection())

player.equip_chest(Armor.library["Leather Chest Plate"])
print(player.get_protection())

player.equip_chest(Armor.library["Leather"])
print(player.get_protection())
99 percent of computer problems exists between chair and keyboard.
Reply
#13
(Dec-13-2019, 05:29 PM)michael1789 Wrote: Something can't be both True AND False. Must be one OR the other, like a switch. On OR off, up OR down, never both. True OR False.

Yes I know. I meant that one of them is True and the other one is False.

And by the way: Now the things are getting printed:

True
100
10000002103122 2 10000002103024
True
10000002103122
20000004206144 2 10000002103024
True
20000004206144
30000006309166 2 10000002103024

But if something hits me, the protection of the armour gets added to the players health. How can I fix that?
Thanks for your help!
Reply
#14
Sound like protection value was higher then damage. You simple have to make sure damage is less or greater than zero. Depends how you apply damage to health.
hit = protection - damage
if hit < 0:
    health += hit
else
hit = damage - protection
if hit > 0:
    health -= hit
You might find this helpful.
class Pool:
    def __init__(self, value):
        self.value = value
        self.max_value = value

    def damage(self, value):
        if value > 0:
            self.value -= value

    def fill(self):
        self.value = self.max_value

    def heal(self, value):
        self.value += value
        if self.value > self.max_value:
            self.value = self.max_value
99 percent of computer problems exists between chair and keyboard.
Reply
#15
(Dec-14-2019, 02:22 PM)Windspar Wrote: Sound like protection value was higher then damage. You simple have to make sure damage is less or greater than zero. Depends how you apply damage to health.
hit = protection - damage
if hit < 0:
    health += hit
else
hit = damage - protection
if hit > 0:
    health -= hit

Looks good, but both ways don't work. My protection is at 10. The health of the player is 100 and the damage of the zombie is 2. My code looks like this now:

for hit in hits:
            hit.vel = vec(0, 0)
            if self.player.health <= 0:
                self.playing = False
        if hits:
            self.player.hit()
            self.player.pos += vec(ZOMBIE_KNOCKBACK, 0).rotate(-hits[0].rot)
            if self.player.leather_chest_plate_on == True:
                hit = ZOMBIE_DAMAGE - self.leather_chest_plate_protection  
                self.player.health -= ZOMBIE_DAMAGE - self.leather_chest_plate_protection
                if hit > 1:
                    self.player.health -= hit
            else:
                self.player.health -= ZOMBIE_DAMAGE
            if self.player.leather_chest_plate_on == True:
                print(self.player.leather_chest_plate_on)
                print(self.player.health)
                self.player.health -= ZOMBIE_DAMAGE - self.leather_chest_plate_protection
                print(self.player.health, ZOMBIE_DAMAGE, self.leather_chest_plate_protection)
Thanks for your help. Piethon Smile
Reply
#16
        
                self.player.health -= ZOMBIE_DAMAGE - self.leather_chest_plate_protection
              
                self.player.health -= hit
           
                self.player.health -= ZOMBIE_DAMAGE - self.leather_chest_plate_protection
              
If your player is wareing armor it take damage 3 times.
Reply
#17
(Dec-14-2019, 04:38 PM)michael1789 Wrote:
        
                self.player.health -= ZOMBIE_DAMAGE - self.leather_chest_plate_protection
              
                self.player.health -= hit
           
                self.player.health -= ZOMBIE_DAMAGE - self.leather_chest_plate_protection
              
If your player is wareing armor it take damage 3 times.

Which one shall I delete? The first, second or third? I am not sure. Huh
Thanks
Reply
#18
This is basic math. Please do the math. Insert test values an you can see what going on. Then rewrite formula until you get what you are looking for.
def test(health, zombie_damage, protection):
    health -= zombie_damage - protection
    print(health)
Games will require more complex math.
You will use algebra, calculus, geometry, and algorithms.
99 percent of computer problems exists between chair and keyboard.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020