1

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()
  • 1
    Welcome to Stack Overflow. Your code example isn't [complete/runnable and verifiable](https://stackoverflow.com/help/mcve), so please read the linked page and edit your question. -- It looks like it would be a good idea to implement a [finite state machine](http://gameprogrammingpatterns.com/state.html) instead of the `attack`, `standing`, `left` and `right` attributes. – skrx Nov 17 '18 at 12:29
  • I was checking out what you sent me I can barely understand it because the examples are C. Im not sure but I think the idea is my attack class is not a class yet, nor is it being displayed? Im gonna post the code from paste bin if you or anybody is interested thanks for anything you come up with. https://pastebin.com/BKZJdL3i – Grayve Oniboru Nov 18 '18 at 08:09
  • Mkay so I got things going a bit better although I am still trying to figure out it out. When I press space my char reset animation to "Standing" instead of attack animation. Im still currently working on it although I am almost unsure why it ill not display even though I THINK i am calling it correctly because of how I blited my walks to the screen or am I trying to do something different from a boolean? – Grayve Oniboru Nov 18 '18 at 09:45

0 Answers0