Ajout de saut et gravité
This commit is contained in:
parent
6bc7d96db3
commit
dff1fa4175
@ -15,7 +15,10 @@ class Player(BaseObject):
|
|||||||
|
|
||||||
self.speed = 300
|
self.speed = 300
|
||||||
|
|
||||||
self.gravity = 200
|
self.gravity = 800
|
||||||
|
self.maxgrav = 400
|
||||||
|
self.jump = -400
|
||||||
|
self.vertical = self.maxgrav
|
||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
keys = self.game.inputs["keys"]
|
keys = self.game.inputs["keys"]
|
||||||
@ -32,14 +35,18 @@ class Player(BaseObject):
|
|||||||
self.onground = True
|
self.onground = True
|
||||||
break
|
break
|
||||||
|
|
||||||
print(self.onground)
|
|
||||||
|
|
||||||
if not self.onground:
|
if not self.onground:
|
||||||
ver = self.gravity
|
self.vertical += self.gravity*self.game.dt
|
||||||
|
self.vertical = min(self.maxgrav,self.vertical)
|
||||||
else:
|
else:
|
||||||
ver = 0
|
if keys["up"]["timer"]==1:
|
||||||
|
self.vertical = self.jump
|
||||||
|
else:
|
||||||
|
self.vertical = 0
|
||||||
|
|
||||||
self.move(hor*self.speed*self.game.dt,ver*self.game.dt)
|
print(self.vertical)
|
||||||
|
|
||||||
|
self.move(hor*self.speed*self.game.dt,self.vertical*self.game.dt)
|
||||||
|
|
||||||
def getgridpos(self,modx=0,mody=0):
|
def getgridpos(self,modx=0,mody=0):
|
||||||
result = {}
|
result = {}
|
||||||
|
Loading…
Reference in New Issue
Block a user