Python Forum
Armour is not working? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: Armour is not working? (/thread-23086.html)

Pages: 1 2


Armour is not working? - Piethon - Dec-10-2019

Hello everybody,

since a couple of weeks, I am trying to add armour into my game. But it not seems to be working.
The damage that the mob does, should get subtracted my the armour protection number. But this is not happening.
Here's the necessary code:

The whole thing is in the update section:

# zombies hit player
        hits = pg.sprite.spritecollide(self.player, self.zombies, False, collide_hit_rect)
        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:
                self.leather_chest_plate_protection -= ZOMBIE_DAMAGE
                if self.leather_chest_plate_protection < 1:
                    self.player.health -= ZOMBIE_DAMAGE
            else:
                self.player.health -= ZOMBIE_DAMAGE
Do you have any idea, why it is not working as it should?
Thanks for your help.

Piethon


RE: Armour is not working? - nilamo - Dec-10-2019

1) It's possible there's a typo somewhere, or that self.player.leather_chest_plate_on isn't set to True.
2) It looks like the armor takes the full damage, and then if the armor hasn't been destroyed (it's >1), the full damage is applied to the player. I imagine if the zombie damage was higher than the leather armor, then the full damage would always hit the player (since self.leather_chest_plate_protection would immediately be <1).
3) The leather armor protection doesn't look like it regenerates, so maybe only the first one or two hits are prevented, and any further hits deal full damage?

And I think if that doesn't help, we'll need to see more code (all of it? do you have it on github?) to try to see where the issue is.


RE: Armour is not working? - michael1789 - Dec-10-2019

Here:
           
            if self.player.leather_chest_plate_on == True:
                self.leather_chest_plate_protection -= ZOMBIE_DAMAGE
I would expect to see this:
            if self.player.leather_chest_plate_on == True:
                self.player.health -= ZOMBIE_DAMAGE - self.leather_chest_plate_protection
Your code doesn't show any place where the player gets hit and armor reduces damage each hit. It's the value of self.leather_chest_plate_protection that gets reduced to 0 then the player takes all subsequent damage.


RE: Armour is not working? - Piethon - Dec-11-2019

(Dec-10-2019, 07:09 PM)michael1789 Wrote: Here:
           
            if self.player.leather_chest_plate_on == True:
                self.leather_chest_plate_protection -= ZOMBIE_DAMAGE
I would expect to see this:
            if self.player.leather_chest_plate_on == True:
                self.player.health -= ZOMBIE_DAMAGE - self.leather_chest_plate_protection
Your code doesn't show any place where the player gets hit and armor reduces damage each hit. It's the value of self.leather_chest_plate_protection that gets reduced to 0 then the player takes all subsequent damage.

Hmm...seem's logic but it doesn't work. Undecided


RE: Armour is not working? - michael1789 - Dec-11-2019

If it doesn't work, maybe this will tell us why.
            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)



RE: Armour is not working? - Piethon - Dec-12-2019

(Dec-11-2019, 11:40 PM)michael1789 Wrote: If it doesn't work, maybe this will tell us why.
            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)

Nothing got printed.


RE: Armour is not working? - nilamo - Dec-12-2019

Then the leather chest plate is never on.


RE: Armour is not working? - Piethon - Dec-13-2019

(Dec-12-2019, 05:38 PM)nilamo Wrote: Then the leather chest plate is never on.

In the event section I have this:

#event stuff
#...
if event.key == pg.K_SPACE:
    if self.player.leather_chest_plate == True:
                        self.show_armour_on_screen = True
                        self.player.leather_chest_plate_on = True
                        if self.player.leather_chest_plate_on == True:
                            self.player.leather_chest_plate_on = False
self.player.leather_chest_plate is always true. My armour is getting displayed on the screen, when I press space.
EDIT: It is not that much extended, that happened when posting.


RE: Armour is not working? - michael1789 - Dec-13-2019

#event stuff
#...
if event.key == pg.K_SPACE:
    if self.player.leather_chest_plate == True:
                        self.show_armour_on_screen = True
                        self.player.leather_chest_plate_on = True
                        if self.player.leather_chest_plate_on == True: <------ if true
                            self.player.leather_chest_plate_on = False <------ make  it false
there it is.


RE: Armour is not working? - Piethon - Dec-13-2019

(Dec-13-2019, 03:58 PM)michael1789 Wrote:
#event stuff
#...
if event.key == pg.K_SPACE:
    if self.player.leather_chest_plate == True:
                        self.show_armour_on_screen = True
                        self.player.leather_chest_plate_on = True
                        if self.player.leather_chest_plate_on == True: <------ if true
                            self.player.leather_chest_plate_on = False <------ make  it false
there it is.

Eh...I don't really understand what you mean. It is True and False. Shall I set the True one to False and the False one to True?