I am working on this game that I want to have a scrolling background and some dudes to punch. When ever I go to press onto the space Key instead of throwing the punch sprite, it loads up the left idle Sprite. Ive been trying to alter my true and false statements with nothing happening and ive added in a class or two with no success as well.
Ive been on this for the better half of the day any help is appreciated.
import pygame
pygame.init()
class player(object):
def __init__(self,x,y,width,height):
self.x = x
self.y = y
self.width = width
self.height = height
self.vel = 5
self.isJump = False
self.left = False
self.right = False
self.walkCount = 0
self.jumpCount = 10
self.standing = True
def draw(self, win):
if self.walkCount + 1 >= 27:
self.walkCount = 0
if not(self.standing):
if self.left:
win.blit(walkLeft[self.walkCount//9], (self.x,self.y))
self.walkCount += 1
elif self.right:
win.blit(walkRight[self.walkCount//9], (self.x,self.y))
self.walkCount +=1
else:
if self.right:
win.blit(walkRight[0], (self.x, self.y))
else:
win.blit(walkLeft[0], (self.x, self.y))
class Attacks(object):
attack = pygame.image.load("atk3.png")
def __init__(self, x, y, width, height, attack):
self.x = x
self.y = y
self.width = width
self.height = height
self.attack = True
def draw(self, win):
self.attack()
if self.attack:
win.blit(attack, (self.x, self.y))
else:
self.attack = True
if not(self.attack):
self.attack = False
def redrawGameWindow():
win.blit(bg, (0, 0))
bob.draw(win)
jerk.draw(win)
for Attack in attack:
attack.draw(win)
pygame.display.update()
#While true
bob = player(100, 200, 128, 128)
jerk = enemy(500, 200, 164, 100, 600)
attack = []
run = True
while run:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
keys = pygame.key.get_pressed()
if keys[pygame.K_SPACE]:
bob.attack = True
bob.standing = False
bob.left = False
bob.right = False
redrawGameWindow()
pygame.quit()