You are browsing as a guest. Sign up (or log in) to start making projects!

1h 34m 24s logged

Dev Log #5
.
I have redeemed myself 10 fold. I have finally added recoil to my game!!!!
.
This moment shows real progress. I have been trying to implement recoil for a while now, and I have finally done it.
.
I did this by using the velocity I calculated to determine what direction and what speed bullets are shot at from the gun:

    def __init__(self, barrel_pos, m_pos):
        super().__init__()

        self.image = pygame.image.load("Images/BULLET.png").convert_alpha()
        self.rect = self.image.get_rect(center=barrel_pos)

        direction = pygame.Vector2(
            m_pos[0] - barrel_pos[0],
            m_pos[1] - barrel_pos[1]
        )

        if direction.length() > 0:
            direction = direction.normalize()

        self.velocity = direction * 10

Passing the velocity into my player group and subtracting it from the player’s centre, effectively creating movement opposite to the direction of the bullets, aka recoil!!!

def recoil(self, velocity):
    self.recoiled = velocity

    self.rect.x -= (self.recoiled.x * 10)
    self.rect.y -= (self.recoiled.y * 10)

I also made it so that bullets despawn once off-screen, optimising performance.
.
Finally, I re-ordered my code, making debugging and overall readability much easier.
.
While my recoil is not fully complete, this is a large step in the right direction.
.
I hope by the next devlog I have a fully working recoil system and possibly a working level. Who knows!
.
Aim for the stars and you’ll at least reach the moon.

0
16

Comments 0

No comments yet. Be the first!