0

So I've been making a platformer/shooting game, and I need the Player to shoot out a bullet when someone hits SPACE that travels to the right. When I hit space, nothing happens. I'm not entirely sure where I've gone wrong, but I was hoping someone could help me out.

Bullet class:

import pygame


class Bullet(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()

        self.image = pygame.Surface([4, 10])
        self.image.fill(black)

        self.rect = self.image.get_rect()
        self.change_x = 0

    def update(self):
        self.rect.x += self.change_x

    def draw(self, surface):
        surface.blit(self.image, (self.rect.x, self.rect.y))

Code for SPACE hit event:

if event.type == pygame.KEYDOWN:
    if event.key == pygame.K_SPACE:
        bullet = Bullet()

        bullet.rect.x = player.rect.x
        bullet.rect.y = player.rect.y

        bullet.change_x = 12

        bullet_list.add(bullet)

I also have bullet_list.update() and

for bullet in bullet_list:
    bullet.draw(screen)
Martin Gergov
  • 1,455
  • 4
  • 18
  • 27
L. Pye
  • 11
  • 1
  • 3
  • you should try and print something in your if `event.key==` see if you are even getting inside that block – Joran Beasley Sep 11 '15 at 23:36
  • Thanks for that hint! I put `print(bullet_list)` which returned that there was a bullet being created. Then I had a look, and I saw that the code that was meant to remove the bullet when it went off screen was removing the bullet as soon as it was built. So it's fixed now :D – L. Pye Sep 12 '15 at 00:17

0 Answers0