I cant figure out this space key and attack animation











up vote
1
down vote

favorite












I decided to add the attack images into the walking ones to see what happened and I got them to load up.



I have been attempting to break it down and piece it back together to try and find what I have been doing wrong and it may be an issue of my experience.



I have butchered my code trying to figure this out after someone gave me an explanation about my classes. I thought maybe I should try and set it up as global, and then I realize there's something I'm not doing right. I don't want someone to just write the code for me I should mention. But an explanation for why I am screwing up would be nice.



Some tutorials are helping me but not as much as when someone tells me where specifically where I went wrong. I think I made more progress there.



##a simple punch without the whole animation atm
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.attackCount = 0


def draw(self, win):
## is it my redraw method?
if (self.attack):
if self.attackCount + 1 >= 9:
win.blit(attack, self.attackCount//3(self.x, self.y))
self.attackCount += 1


So with the class set up here im sure that something is wrong, ive been diving through forums and I know something is not right. I dont know what though.



def redrawGameWindow():
global walkCount
global attackCount
win.blit(bg, (0, 0))
if walkCount +1 >= 27:
walkCount = 0

bob.draw(win)
jerk.draw(win)
for attack in attacks:
attack.draw(win)



pygame.display.update()


#While true
#This calls the classes created
bob = player(100, 200, 128, 128)
jerk = enemy(500, 200, 164, 100, 600)
attacks =
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()
#attempting to make this into a bool that changes the value
if not(bob.attacking):
if keys[pygame.K_SPACE]:
bob.attacking = True

bob.standing = False
bob.left = False
bob.right = False

if keys[pygame.K_LEFT] and bob.x > bob.vel:
bob.x -= bob.vel
bob.left = True
bob.right = False
bob.standing = False
elif keys[pygame.K_RIGHT] and bob.x < 800 - bob.width - bob.vel:
bob.x += bob.vel
bob.right = True
bob.left = False
bob.standing = False
else:
bob.standing = True
bob.walkCount = 0

if not(bob.isJump):
if keys[pygame.K_UP]:
bob.isJump = True
bob.right = False
bob.left = False
bob.walkCount = 0
else:
if bob.jumpCount >= -10:
neg = 1
if bob.jumpCount < 0:
neg = -1
bob.y -= (bob.jumpCount ** 2) * 0.5 * neg
bob.jumpCount -= 1
else:
bob.isJump = False
bob.jumpCount = 10

redrawGameWindow()

pygame.quit()


Im almost sure my True loop has nothing to do with it now since im able to run walk and jump. And when I press space it loads a frame thats not an attack one so i know for sure something is happening when I hit space










share|improve this question









New contributor




Grayve Oniboru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Ok im not sure what to do with these comments and I hope someone can help me. Im not sure what I dont get. I just know the issue lies within these lines that are giving me the "AttributeError: list object has no attribute draw" and the other issue I get when I change the attack to attacks is: UnboundLocalError: local variable 'attack' reference before assignment.
    – Grayve Oniboru
    2 days ago












  • class attacks(object): attack = pygame.image.load("atk3.png") def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height self.attackCount = 0
    – Grayve Oniboru
    2 days ago










  • def draw(self, win): self.attacks() if (self.attack): if self.attackCount + 1 >= 9: win.blit(attack[0], [self.attackCount//3],(self.x, self.y)) self.attackCount += 1 else: win.blit(char[0], [self.attackCount//3] (self.x ,self.y)) self.attackCount += 1
    – Grayve Oniboru
    2 days ago










  • Please read the minimal, complete and verifiable example page and edit your code to make it runnable.
    – skrx
    20 hours ago















up vote
1
down vote

favorite












I decided to add the attack images into the walking ones to see what happened and I got them to load up.



I have been attempting to break it down and piece it back together to try and find what I have been doing wrong and it may be an issue of my experience.



I have butchered my code trying to figure this out after someone gave me an explanation about my classes. I thought maybe I should try and set it up as global, and then I realize there's something I'm not doing right. I don't want someone to just write the code for me I should mention. But an explanation for why I am screwing up would be nice.



Some tutorials are helping me but not as much as when someone tells me where specifically where I went wrong. I think I made more progress there.



##a simple punch without the whole animation atm
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.attackCount = 0


def draw(self, win):
## is it my redraw method?
if (self.attack):
if self.attackCount + 1 >= 9:
win.blit(attack, self.attackCount//3(self.x, self.y))
self.attackCount += 1


So with the class set up here im sure that something is wrong, ive been diving through forums and I know something is not right. I dont know what though.



def redrawGameWindow():
global walkCount
global attackCount
win.blit(bg, (0, 0))
if walkCount +1 >= 27:
walkCount = 0

bob.draw(win)
jerk.draw(win)
for attack in attacks:
attack.draw(win)



pygame.display.update()


#While true
#This calls the classes created
bob = player(100, 200, 128, 128)
jerk = enemy(500, 200, 164, 100, 600)
attacks =
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()
#attempting to make this into a bool that changes the value
if not(bob.attacking):
if keys[pygame.K_SPACE]:
bob.attacking = True

bob.standing = False
bob.left = False
bob.right = False

if keys[pygame.K_LEFT] and bob.x > bob.vel:
bob.x -= bob.vel
bob.left = True
bob.right = False
bob.standing = False
elif keys[pygame.K_RIGHT] and bob.x < 800 - bob.width - bob.vel:
bob.x += bob.vel
bob.right = True
bob.left = False
bob.standing = False
else:
bob.standing = True
bob.walkCount = 0

if not(bob.isJump):
if keys[pygame.K_UP]:
bob.isJump = True
bob.right = False
bob.left = False
bob.walkCount = 0
else:
if bob.jumpCount >= -10:
neg = 1
if bob.jumpCount < 0:
neg = -1
bob.y -= (bob.jumpCount ** 2) * 0.5 * neg
bob.jumpCount -= 1
else:
bob.isJump = False
bob.jumpCount = 10

redrawGameWindow()

pygame.quit()


Im almost sure my True loop has nothing to do with it now since im able to run walk and jump. And when I press space it loads a frame thats not an attack one so i know for sure something is happening when I hit space










share|improve this question









New contributor




Grayve Oniboru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Ok im not sure what to do with these comments and I hope someone can help me. Im not sure what I dont get. I just know the issue lies within these lines that are giving me the "AttributeError: list object has no attribute draw" and the other issue I get when I change the attack to attacks is: UnboundLocalError: local variable 'attack' reference before assignment.
    – Grayve Oniboru
    2 days ago












  • class attacks(object): attack = pygame.image.load("atk3.png") def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height self.attackCount = 0
    – Grayve Oniboru
    2 days ago










  • def draw(self, win): self.attacks() if (self.attack): if self.attackCount + 1 >= 9: win.blit(attack[0], [self.attackCount//3],(self.x, self.y)) self.attackCount += 1 else: win.blit(char[0], [self.attackCount//3] (self.x ,self.y)) self.attackCount += 1
    – Grayve Oniboru
    2 days ago










  • Please read the minimal, complete and verifiable example page and edit your code to make it runnable.
    – skrx
    20 hours ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I decided to add the attack images into the walking ones to see what happened and I got them to load up.



I have been attempting to break it down and piece it back together to try and find what I have been doing wrong and it may be an issue of my experience.



I have butchered my code trying to figure this out after someone gave me an explanation about my classes. I thought maybe I should try and set it up as global, and then I realize there's something I'm not doing right. I don't want someone to just write the code for me I should mention. But an explanation for why I am screwing up would be nice.



Some tutorials are helping me but not as much as when someone tells me where specifically where I went wrong. I think I made more progress there.



##a simple punch without the whole animation atm
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.attackCount = 0


def draw(self, win):
## is it my redraw method?
if (self.attack):
if self.attackCount + 1 >= 9:
win.blit(attack, self.attackCount//3(self.x, self.y))
self.attackCount += 1


So with the class set up here im sure that something is wrong, ive been diving through forums and I know something is not right. I dont know what though.



def redrawGameWindow():
global walkCount
global attackCount
win.blit(bg, (0, 0))
if walkCount +1 >= 27:
walkCount = 0

bob.draw(win)
jerk.draw(win)
for attack in attacks:
attack.draw(win)



pygame.display.update()


#While true
#This calls the classes created
bob = player(100, 200, 128, 128)
jerk = enemy(500, 200, 164, 100, 600)
attacks =
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()
#attempting to make this into a bool that changes the value
if not(bob.attacking):
if keys[pygame.K_SPACE]:
bob.attacking = True

bob.standing = False
bob.left = False
bob.right = False

if keys[pygame.K_LEFT] and bob.x > bob.vel:
bob.x -= bob.vel
bob.left = True
bob.right = False
bob.standing = False
elif keys[pygame.K_RIGHT] and bob.x < 800 - bob.width - bob.vel:
bob.x += bob.vel
bob.right = True
bob.left = False
bob.standing = False
else:
bob.standing = True
bob.walkCount = 0

if not(bob.isJump):
if keys[pygame.K_UP]:
bob.isJump = True
bob.right = False
bob.left = False
bob.walkCount = 0
else:
if bob.jumpCount >= -10:
neg = 1
if bob.jumpCount < 0:
neg = -1
bob.y -= (bob.jumpCount ** 2) * 0.5 * neg
bob.jumpCount -= 1
else:
bob.isJump = False
bob.jumpCount = 10

redrawGameWindow()

pygame.quit()


Im almost sure my True loop has nothing to do with it now since im able to run walk and jump. And when I press space it loads a frame thats not an attack one so i know for sure something is happening when I hit space










share|improve this question









New contributor




Grayve Oniboru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I decided to add the attack images into the walking ones to see what happened and I got them to load up.



I have been attempting to break it down and piece it back together to try and find what I have been doing wrong and it may be an issue of my experience.



I have butchered my code trying to figure this out after someone gave me an explanation about my classes. I thought maybe I should try and set it up as global, and then I realize there's something I'm not doing right. I don't want someone to just write the code for me I should mention. But an explanation for why I am screwing up would be nice.



Some tutorials are helping me but not as much as when someone tells me where specifically where I went wrong. I think I made more progress there.



##a simple punch without the whole animation atm
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.attackCount = 0


def draw(self, win):
## is it my redraw method?
if (self.attack):
if self.attackCount + 1 >= 9:
win.blit(attack, self.attackCount//3(self.x, self.y))
self.attackCount += 1


So with the class set up here im sure that something is wrong, ive been diving through forums and I know something is not right. I dont know what though.



def redrawGameWindow():
global walkCount
global attackCount
win.blit(bg, (0, 0))
if walkCount +1 >= 27:
walkCount = 0

bob.draw(win)
jerk.draw(win)
for attack in attacks:
attack.draw(win)



pygame.display.update()


#While true
#This calls the classes created
bob = player(100, 200, 128, 128)
jerk = enemy(500, 200, 164, 100, 600)
attacks =
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()
#attempting to make this into a bool that changes the value
if not(bob.attacking):
if keys[pygame.K_SPACE]:
bob.attacking = True

bob.standing = False
bob.left = False
bob.right = False

if keys[pygame.K_LEFT] and bob.x > bob.vel:
bob.x -= bob.vel
bob.left = True
bob.right = False
bob.standing = False
elif keys[pygame.K_RIGHT] and bob.x < 800 - bob.width - bob.vel:
bob.x += bob.vel
bob.right = True
bob.left = False
bob.standing = False
else:
bob.standing = True
bob.walkCount = 0

if not(bob.isJump):
if keys[pygame.K_UP]:
bob.isJump = True
bob.right = False
bob.left = False
bob.walkCount = 0
else:
if bob.jumpCount >= -10:
neg = 1
if bob.jumpCount < 0:
neg = -1
bob.y -= (bob.jumpCount ** 2) * 0.5 * neg
bob.jumpCount -= 1
else:
bob.isJump = False
bob.jumpCount = 10

redrawGameWindow()

pygame.quit()


Im almost sure my True loop has nothing to do with it now since im able to run walk and jump. And when I press space it loads a frame thats not an attack one so i know for sure something is happening when I hit space







python class object pygame blit






share|improve this question









New contributor




Grayve Oniboru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Grayve Oniboru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Billal Begueradj

5,516132637




5,516132637






New contributor




Grayve Oniboru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Grayve Oniboru

111




111




New contributor




Grayve Oniboru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Grayve Oniboru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Grayve Oniboru is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Ok im not sure what to do with these comments and I hope someone can help me. Im not sure what I dont get. I just know the issue lies within these lines that are giving me the "AttributeError: list object has no attribute draw" and the other issue I get when I change the attack to attacks is: UnboundLocalError: local variable 'attack' reference before assignment.
    – Grayve Oniboru
    2 days ago












  • class attacks(object): attack = pygame.image.load("atk3.png") def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height self.attackCount = 0
    – Grayve Oniboru
    2 days ago










  • def draw(self, win): self.attacks() if (self.attack): if self.attackCount + 1 >= 9: win.blit(attack[0], [self.attackCount//3],(self.x, self.y)) self.attackCount += 1 else: win.blit(char[0], [self.attackCount//3] (self.x ,self.y)) self.attackCount += 1
    – Grayve Oniboru
    2 days ago










  • Please read the minimal, complete and verifiable example page and edit your code to make it runnable.
    – skrx
    20 hours ago


















  • Ok im not sure what to do with these comments and I hope someone can help me. Im not sure what I dont get. I just know the issue lies within these lines that are giving me the "AttributeError: list object has no attribute draw" and the other issue I get when I change the attack to attacks is: UnboundLocalError: local variable 'attack' reference before assignment.
    – Grayve Oniboru
    2 days ago












  • class attacks(object): attack = pygame.image.load("atk3.png") def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height self.attackCount = 0
    – Grayve Oniboru
    2 days ago










  • def draw(self, win): self.attacks() if (self.attack): if self.attackCount + 1 >= 9: win.blit(attack[0], [self.attackCount//3],(self.x, self.y)) self.attackCount += 1 else: win.blit(char[0], [self.attackCount//3] (self.x ,self.y)) self.attackCount += 1
    – Grayve Oniboru
    2 days ago










  • Please read the minimal, complete and verifiable example page and edit your code to make it runnable.
    – skrx
    20 hours ago
















Ok im not sure what to do with these comments and I hope someone can help me. Im not sure what I dont get. I just know the issue lies within these lines that are giving me the "AttributeError: list object has no attribute draw" and the other issue I get when I change the attack to attacks is: UnboundLocalError: local variable 'attack' reference before assignment.
– Grayve Oniboru
2 days ago






Ok im not sure what to do with these comments and I hope someone can help me. Im not sure what I dont get. I just know the issue lies within these lines that are giving me the "AttributeError: list object has no attribute draw" and the other issue I get when I change the attack to attacks is: UnboundLocalError: local variable 'attack' reference before assignment.
– Grayve Oniboru
2 days ago














class attacks(object): attack = pygame.image.load("atk3.png") def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height self.attackCount = 0
– Grayve Oniboru
2 days ago




class attacks(object): attack = pygame.image.load("atk3.png") def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height self.attackCount = 0
– Grayve Oniboru
2 days ago












def draw(self, win): self.attacks() if (self.attack): if self.attackCount + 1 >= 9: win.blit(attack[0], [self.attackCount//3],(self.x, self.y)) self.attackCount += 1 else: win.blit(char[0], [self.attackCount//3] (self.x ,self.y)) self.attackCount += 1
– Grayve Oniboru
2 days ago




def draw(self, win): self.attacks() if (self.attack): if self.attackCount + 1 >= 9: win.blit(attack[0], [self.attackCount//3],(self.x, self.y)) self.attackCount += 1 else: win.blit(char[0], [self.attackCount//3] (self.x ,self.y)) self.attackCount += 1
– Grayve Oniboru
2 days ago












Please read the minimal, complete and verifiable example page and edit your code to make it runnable.
– skrx
20 hours ago




Please read the minimal, complete and verifiable example page and edit your code to make it runnable.
– skrx
20 hours ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Grayve Oniboru is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361931%2fi-cant-figure-out-this-space-key-and-attack-animation%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Grayve Oniboru is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Grayve Oniboru is a new contributor. Be nice, and check out our Code of Conduct.













Grayve Oniboru is a new contributor. Be nice, and check out our Code of Conduct.












Grayve Oniboru is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361931%2fi-cant-figure-out-this-space-key-and-attack-animation%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]