I'm currently using this code for jumping:
if not Jump:
if keys[pygame.K_UP]:
Jump=True
right=False #right, left and standing are for character's facing
left=False # and they serve no purpose for jumping
standing=False
steps=0
else:
if jumpCount >= -8.5:
standing=False
neg=1
if JumpCount < 0:
neg=-1
y-=(JumpCount**2)/2 *neg
jumpCount-=1
else:
Jump=False
jumpCount=8.5 # I've set it to 8.5 bc that value works for me best
Anyway, this code works for basic jumping, but a problem occurs if I want to jump, let's say, on a box. I tried to set it up like this:
self.line1=[self.x,self.y+60] #this is the bottom left coordinate of the
#character
self.line2=[self.x+28,self.y+60] #this is the bottom right coordinate
def on(self,a):
if (a.line1[0]+12)>self.x and (a.line1[0]+12)<(self.x+40): # self.x+40
#is the top right coordinate of the box
if a.line1[1]<=self.y and (a.line1[1]+a.v)>=self.y:
return True
return False
def collision(self,a):
if self.on(a):
a.y=self.y-60
a.Jump=False
return
def all(self,a):
self.on(a)
self.collision(a)
return
But this doesn't work. I've managed to set up that when the character hits sides of the box it can't go further, but I couldn't do the jumping part. Is it possible to jump on something with this code, or should I change the jumping code completely, use gravity-style jumping or something? Any kind of help is welcome.