I am making a game for my school project where you just go up and down shooting at enemies. I have made the enemy however he is not appearing on the screen. There are no errors and everything else works perfectly fine, the enemy is also meant to go up and down the y-axis, so only up and down. Here is my code:
import pygame, sys
# classes
# Player class
class Player(pygame.sprite.Sprite):
def __init__(self, image):
super().__init__()
self.image = image
self.rect = self.image.get_rect(center = (screen_width//2, screen_height//2))
def update(self):
self.rect.center = pygame.mouse.get_pos()
def create_bullet(self):
return Bullet(*pygame.mouse.get_pos())
# bullet class
class Bullet (pygame.sprite.Sprite):
def __init__(self,pos_x,pos_y):
super().__init__()
self.image = pygame.Surface((50,10))
self.image.fill((255,255,0))
self.rect = self.image.get_rect(center = (pos_x,pos_y))
def update(self):
self.rect.x += 5
# enemy class
class enemy(pygame.sprite.Sprite):
walkup = pygame.image.load("enemy.png")
walkdown = pygame.image.load("enemy.png")
def __init__(self, x, y, width, height, end):
self.x = x
self.y = y
self.width = width
self.height = height
self.end = end
self.path = [self.y, self.end]
self.walkcount = 0
self.vel = 3
def draw(self,win):
self.move()
if self.walkcount + 1 <= 33:
self.walkcount = 0
if self.vel > 0:
win.blit(self.walkup[self.walkcount //3], (self.x, self.y))
self.walkcount += 1
else:
win.blit(self.walkdown [self.walkcount //3], (self.x, self.y) )
self.walkcount += 1
def move(self):
if self.vel >0:
if self.x + self.vel < self.path[1]:
self.x += self.vel
else:
self.vel - self.vel * -1
self.walkcount - 0
else:
if self.y - self.vel > self.path[0]:
self.x += self.vel
else:
self.vel = self.vel * -1
self.walkcount = 0
# making the enemy appear
def redrawGameWindow():
thief.draw(screen)
thief = enemy(100, 410, 64, 64, 450)
# general setup
pygame.init()
clock = pygame.time.Clock()
# game screen
screen_width = 1920
screen_height = 1080
screen = pygame .display.set_mode((screen_width, screen_height))
background = pygame.image.load("BackGround.png")
# player
player_image = pygame.image.load("Charachter2.png")
player = Player(player_image)
player_group = pygame.sprite.Group()
player_group.add(player)
# Bullet
bullet_group = pygame.sprite.Group()
# caption
pygame.display.set_caption("Wild-West Shooter")
# makes game quit
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame:quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
bullet_group.add(player.create_bullet())
player_group.update()
bullet_group.update()
screen.blit(background,(0,0))
player_group.draw(screen)
bullet_group.draw(screen)
pygame.display.flip()
clock.tick(120)