Dec-13-2019, 05:29 PM
(This post was last modified: Dec-13-2019, 05:30 PM by michael1789.)
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.
Armour is not working?
|
Dec-13-2019, 05:29 PM
(This post was last modified: Dec-13-2019, 05:30 PM by michael1789.)
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.
Dec-13-2019, 11:43 PM
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.
(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!
Dec-14-2019, 02:22 PM
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 += hitelse hit = damage - protection if hit > 0: health -= hitYou 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.
Dec-14-2019, 04:04 PM
(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. 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
Dec-14-2019, 04:38 PM
(This post was last modified: Dec-14-2019, 04:38 PM by michael1789.)
self.player.health -= ZOMBIE_DAMAGE - self.leather_chest_plate_protection self.player.health -= hit self.player.health -= ZOMBIE_DAMAGE - self.leather_chest_plate_protectionIf your player is wareing armor it take damage 3 times.
Dec-15-2019, 10:10 AM
(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_protectionIf your player is wareing armor it take damage 3 times. Which one shall I delete? The first, second or third? I am not sure. Thanks
Dec-15-2019, 10:48 AM
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.
|
|