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)