#🔒 jumping in a street fighter style game

331 messages · Page 1 of 1 (latest)

raven doveBOT
#

@rough pagoda

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

rough pagoda
#

im trying to make my character jump and come back down in my game, i have 6 or 7 sprites for the jump ready as well but im not sure how to create this

olive meadow
#

Do you know how gravity works in real life

#

Like with acceleration/velocity

rough pagoda
rough pagoda
#

Do I model it the same way?

olive meadow
#

You have a constant acceleration

#

When they jump you give them a certain upward speed

#

And decrease that by the acceleration each frame

rough pagoda
#

Ok thank you I’ll give it a go

olive meadow
#

Yeah good luck you can always ask about it more as you go

rough pagoda
#

Ok thanks will do

#

What do you think a reasonable constant acceleration should be?

olive meadow
#

Something pretty small

#

Bc it happens every frame

#

What’s the frame rate of your game

#

Maybe like .02?

rough pagoda
olive meadow
#

Getting anything to work?

rough pagoda
#

No i have no idea😭

#

How can I decrease it in each frame?

#

Do I use a for loop?

mossy plume
#
# constatnt gravity
G = 0.2
# changeing velocity
velY = 0
# Current y position
y = 0

if jumping:
  velY = 12

# gameLoop
while True:
  y -= velY
  velY -= G
```I'm pretty sure this works. lemme know
#

And replace the game loop with your own loop and the if statment with the jump event in your code

rough pagoda
#

How can I get the animation in there as well?

#

I’ve got the sprites in a list

mossy plume
#

Hold on, lemme think about it for a sec

#

What kind of animation?

rough pagoda
#

So it’s 6 sprites in a list

#

Making up the jump

mossy plume
#

Is it also prepering for a jump?

rough pagoda
#

Yeah I think the first is

#

The bottom ones

mossy plume
#

Okay, I guess you can

#

Like

#

use the velocity

#

as the number for the list

#

index

#

Like:```py
animList = [0...6]

if velY > 0:
currentImage = animList[int(velY / 2)]

#

I think this should work?

rough pagoda
#

Can you run this and tell me where I’ve gone wrong please ?

mossy plume
#

Sure, run what though?

rough pagoda
#

Wait I’ll send the code

mossy plume
#

Okay

rough pagoda
#

It doesn’t actually drop down

olive meadow
mossy plume
mossy plume
olive meadow
#

No problem anyone can help and I was busy for a sec

mossy plume
#

Okay

rough pagoda
#

I’m removing it in the draw method no?

olive meadow
#

And yeah I’d pick the sprite based on the velocity

mossy plume
#

Is there a chance that you are both walking and jumping?

olive meadow
#

Did you get it to jump without the animation

rough pagoda
mossy plume
#

No, I see it

#

I think

#

You need to += gravity to velocity instead of -=

#

I think

#

I'm not sure

rough pagoda
#

Ohhh

#

Makes sense

mossy plume
#

I don't think it's that though

rough pagoda
#

Yh no that didn’t change anything

#

Maybe i need to change the numbers for the gravity and the other variables?

mossy plume
#

I dont really, understand?

olive meadow
#

Lemme see the snippet of the code for the gravity

rough pagoda
#

One sec

olive meadow
#

Also try to get it without animation

mossy plume
#

Excuse me if I'm wrong but you're never setting onGround to true?

mossy plume
#

That shouldn't change anything though

rough pagoda
#

Where would that go?

mossy plume
#

Idk

#

You need collision

rough pagoda
#

With what?

#

The like floor level?

mossy plume
#

Yea Yea

rough pagoda
#

But need to sort out the gravity bit first I think cause it’s not actually moving down

mossy plume
#

Yea I guess

#

Have you tried decreasing the 12?

#

I mean, maybe?

#

Wait it doesn't fall at all?

rough pagoda
#

Nope

olive meadow
#

First thing I see is you can’t jump while moving left and right

rough pagoda
#

It just goes up and stays there

olive meadow
#

Bc of if statements

rough pagoda
#

Yeah I’ll change that

#

Should I put the jump loop at the top?

#

Like above the left and right

mossy plume
mossy plume
#

Instead of elif just if

rough pagoda
#

Ok cool

#

Should the left and right be elifs though?

#

Cause you can’t go both left and right no?

mossy plume
#

Alright, sure

#

but if you are adding to x and then subtracting from x it shouldn't matter

rough pagoda
#

It bugs out when I change any of them to ifs

mossy plume
#

Oh right okay

rough pagoda
#

Like the animations don’t disappear and they leave like a trail behind the character

mossy plume
#

I see

#

Than sure use an elif

rough pagoda
#

Any idea why it’s not going down?

mossy plume
#

I don't have any, sorry

olive meadow
#

What’s the issue rn

#

First we need to figure out the jumping forget about the animations

#

It will be much easier to add them after

rough pagoda
#

Yeah that’s what we’re trying

#

I took the animation part out

olive meadow
#

What happens when you jump

rough pagoda
#

The character moves up by like a cm and just stays there

#

And just keeps going up when I continue to press it

#

There’s no downward movement

mossy plume
#

i think I got it

#

You are cheking something with the x velocity?

rough pagoda
#

No what should I be checking?

mossy plume
#

You shouldn't

#

but there's an if statement in the beginning of the draw method

rough pagoda
#

Oh yh that’s meant to be to avoid the player coming off screen but it didn’t really work haha

mossy plume
#

Lol

#

Okay, sorry

rough pagoda
#

It’s a bit of a mess haha

#

Can you help me fix that one first maybe?😭

#

Like to avoid the player from moving too far left and too far right

mossy plume
#

Okay, Are you sure though?

rough pagoda
#

About what?

mossy plume
#

That you want to do that first

rough pagoda
#

Yes I need to do it anyway and it seems easier than the whole jump thing

mossy plume
#

Okay

rough pagoda
#

At the moment when I reach the off screen boundary the character just fully disappears

mossy plume
#

I think it needs a like

#

the width of the chracter

rough pagoda
#

Does that

mossy plume
#

because you not drawing the chracter

#

you need to only prevent from going further

olive meadow
#

I get off work in 23 minutes i can help a lot more frequently then sorry

mossy plume
#

Like:```py
def draw(self):
if not self.x-self.vel>=0 or not self.x+self.vel < screenWidth:
velX = 0

mossy plume
#

Are you like making sure no one sees you help other people?

#

Lol

#

And there is a better way of saying that

#

Im jjust no good english

#

Did you get it?

rough pagoda
#

It took my character completely off the screen

mossy plume
#

?

rough pagoda
#

Wait did you mean like this?

mossy plume
#

Not exactly

olive meadow
mossy plume
#

Dude

#

You need to remove some white spaces from the code after that

mossy plume
rough pagoda
#

Do I need the ‘ if self.walkCount+1>36 bit

mossy plume
#

I think

rough pagoda
#

Should it be indented though?

mossy plume
#

Wdym by indented

#

?

mossy plume
rough pagoda
mossy plume
#

Like

#

Over white spaced or not over?

rough pagoda
#

I don’t know what you mean by that

#

Wait

mossy plume
#

Waiting

rough pagoda
#

See how the top if is further left than the rest

#

Should it be like that

mossy plume
#

Yes

mossy plume
#

Im sorry

rough pagoda
#

So whats wrong with it

mossy plume
#

Wdym?

rough pagoda
#

Like why’s it not working

mossy plume
#

Oh

#

Do you mind showing me a video?

rough pagoda
#

It does that

#

Doesn’t show the character at all

mossy plume
#

Okay

#

I mean

#

Not okay

#

Did you indent it?

rough pagoda
#

I’ve left it as I showed you

mossy plume
#

Than it shouldn't work

rough pagoda
#

Shouldn’t ?

#

Bro your confusing me 😭

#

What should I be indenting

mossy plume
rough pagoda
#

Now the character gets stuck on the boundary

#

Like it prevents him from going over but it freezes him there

mossy plume
#

Is that not what you wanted?

#

Oh okay

#

Let me think about it for a sec

rough pagoda
#

And for some reason the animations for the standing and walking have stopped

mossy plume
#

Oh sorry,

#

My bad

#

it should be just X

#

x

#

small x

#

instead of velX

#

Could you repaste your code?

rough pagoda
#

Yeah one sec

mossy plume
#

Does it give you any errors?

#
if  not self.x-self.vel>0:
                self.x=1
if not self.x+self.vel<SCREEN_WIDTH:
  self.x = SCREEN_WIDTH
rough pagoda
#

No but it makes my character freeze on the border

rough pagoda
mossy plume
#

Okay

rough pagoda
#

Yes it works on one side now

#

But on the right side it doesn’t stop him

mossy plume
#

That was an overlook on my side

rough pagoda
#

He just goes through the right side and starts at the left side

mossy plume
olive meadow
#

Did you guys get the borders figured out

mossy plume
#

I think so

rough pagoda
#

The boundary is a bit too far on the right side I’m trying to fix it

mossy plume
#

Oh right that would be do to the fact that we are subtracting from the total width instead of adding or the other way around I think

olive meadow
#

Well I can help now so lmk if there’s an issue

rough pagoda
#

The barriers like off screen

#

See

olive meadow
#

Whats the code for the right barrier

#

Should be ScreenWidth - playerwidth

rough pagoda
olive meadow
olive meadow
rough pagoda
#

Ok think ive got it

mossy plume
#

minus one I think

rough pagoda
#

I dont know why the animations have gone all weird though

#

Ok yh perfect the barriers work

mossy plume
#

Now jumping?

olive meadow
#

Oh i bet i know why jumping didnt work

rough pagoda
#

Not yet cause the animations are still bugging

mossy plume
mossy plume
olive meadow
#

You are setting self.jump to false as soon as it is true

mossy plume
#

Ohhhhhhhhh

#

So this whole thing needs to change

rough pagoda
#

The animations arent like moving like before

#

Even when hes still he should have an animation for standing but when i set them barriers its just stopped all of that

rough pagoda
mossy plume
#

No

olive meadow
#

I would

mossy plume
#

No why?

olive meadow
#

You only want self.jump to be false once the character gets back to the floor

mossy plume
olive meadow
#

I said to not put it at the end

mossy plume
#

Oh sorry

#

Ohhh sorry

#

I miss read it

rough pagoda
#

Ok ok

#

Oh should I replace it with the on ground one being set to true?

mossy plume
#

No?

#

Do you want your chracter to start on the ground?

#

BTW the vel variable and the gravity var, does each chrarcter needs one of his own?

#

I mean

#

can't they be outside the class?

rough pagoda
#

No every characters gonna have the same

#

Oh yh😭

#

Ok so now the character does go down but he goes through the floor

#

Progress !!🤣

mossy plume
#

Lol

rough pagoda
#

But he’s also going really high up

#

Like off the screen high and then coming back down really slow

mossy plume
#

You can change the 12 to something else

#

lower value

rough pagoda
#

Ok cool

mossy plume
#

Oh and you can also change the gravity

rough pagoda
#

Lower or higher?

mossy plume
#

The gravity heigher, the "jumpStreangth" if you will lower

rough pagoda
#

Ok nice it’s better now I think

#

I can’t really tell how high it’s going cause it goes invisible

mossy plume
#

How do you mean?

rough pagoda
#

But when I crouch or move side to side I can see where abouts it is

#

See if i dont press crouch its just invisible

mossy plume
#

Interesting

#

I think I know why

#

in the jump state you are not window.blit ing the chracter

rough pagoda
#

Oh yeah

#

Ill put the standing animation into it for now

mossy plume
#

You can put the jump anim

#

I think

rough pagoda
#

And then what do i put inside the []

mossy plume
#

The walkCount?

#

No

#

the velocity

#

int(y_vel)

rough pagoda
#

Ok ill give it a go

mossy plume
#

It also needs to be as long as the y velocity is grater then 6

#

sorry grater then 0

rough pagoda
#

Wait wheres that gonna go

#

Elif sef.jump== true AND self.y_vel>6???

mossy plume
#

No

#

wait no

#

You should keep a sepreate variable for jumping animation I think

rough pagoda
#

Wdum?

mossy plume
#

What do you mean?

#

What don't you understand?

#

so I can better help you

rough pagoda
#

What seperate variable ?

#

I should make a new one?

mossy plume
#

Yeah

rough pagoda
#

Why?

#

Also for the jump surely it shouldn’t just be one set number in the [] cause it’s 6 different sprite images

mossy plume
#

Idk, it's very late out here

rough pagoda
mossy plume
rough pagoda
#

For taking up your time with this shit haha

mossy plume
#

Nah it fine

rough pagoda
mossy plume
#

Okay

#
self.jumpCount = 0

# seperate piece of code AKA: draw method
elif self.jumping:
  image = jumping[jumpCout]
  if jumpCount < 6:
    jumpCount += 1
#

I think this should do it

#

I think ima go

#

Good night

rough pagoda
#

Ok thank you so much

#

If I have any more problems can you help me tomorrow please ?

raven doveBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.