Better player movement on map
This commit is contained in:
parent
b0212e98b3
commit
f3e0ee8fdc
@ -14,6 +14,9 @@ class Levels(BaseObject):
|
|||||||
|
|
||||||
self.playerwalking = self.game.getSpriteDir("player/walking/")
|
self.playerwalking = self.game.getSpriteDir("player/walking/")
|
||||||
self.playerstill = self.game.sprite_lib["player/still.png"]
|
self.playerstill = self.game.sprite_lib["player/still.png"]
|
||||||
|
self.flip = False
|
||||||
|
self.moving = False
|
||||||
|
self.spriteindex = 0
|
||||||
|
|
||||||
self.flagsindex = []
|
self.flagsindex = []
|
||||||
self.names = []
|
self.names = []
|
||||||
@ -44,6 +47,8 @@ class Levels(BaseObject):
|
|||||||
|
|
||||||
self.animspeed = 7
|
self.animspeed = 7
|
||||||
self.cursor = 0 # Which level is selected
|
self.cursor = 0 # Which level is selected
|
||||||
|
self.playerx = self.nodes[0]["x"]
|
||||||
|
self.playery = self.nodes[1]["y"]
|
||||||
|
|
||||||
self.tileset = self.game.gameloop.findname("TilesetRenderer")[0]
|
self.tileset = self.game.gameloop.findname("TilesetRenderer")[0]
|
||||||
self.maxwidth = self.tileset.layers[0]["surface"].get_width()
|
self.maxwidth = self.tileset.layers[0]["surface"].get_width()
|
||||||
@ -52,17 +57,29 @@ class Levels(BaseObject):
|
|||||||
for i in range(len(self.flagsindex)):
|
for i in range(len(self.flagsindex)):
|
||||||
self.flagsindex[i]+=self.animspeed*self.game.dt
|
self.flagsindex[i]+=self.animspeed*self.game.dt
|
||||||
|
|
||||||
if self.game.inputs["keys"]["right"]["timer"]==1:
|
if not self.moving:
|
||||||
self.cursor+=1
|
if self.game.inputs["keys"]["right"]["timer"]>0:
|
||||||
if self.game.inputs["keys"]["left"]["timer"]==1:
|
self.cursor+=1
|
||||||
self.cursor-=1
|
self.flip = False
|
||||||
if self.game.inputs["keys"]["up"]["timer"]==1:
|
if self.game.inputs["keys"]["left"]["timer"]>0:
|
||||||
# Launch the level
|
self.cursor-=1
|
||||||
self.game.scenes.ingame(self.game,level="Level "+str(self.cursor+1))
|
self.flip = True
|
||||||
|
if self.game.inputs["keys"]["up"]["timer"]>0:
|
||||||
|
# Launch the level
|
||||||
|
self.game.scenes.ingame(self.game,level="Level "+str(self.cursor+1))
|
||||||
self.cursor = min(self.cursor,len(self.nodes)-1)
|
self.cursor = min(self.cursor,len(self.nodes)-1)
|
||||||
self.cursor = max(0,self.cursor)
|
self.cursor = max(0,self.cursor)
|
||||||
|
|
||||||
self.playerx = self.nodes[self.cursor]["x"]
|
speedx = (self.nodes[self.cursor]["x"]-self.playerx)
|
||||||
|
speedy = (self.nodes[self.cursor]["y"]-self.playery)
|
||||||
|
|
||||||
|
self.moving = (abs(speedx)+1)*(abs(speedy)+1)>3
|
||||||
|
if self.moving:
|
||||||
|
self.spriteindex += self.animspeed*self.game.dt
|
||||||
|
else:
|
||||||
|
self.spriteindex = 0
|
||||||
|
self.playerx += speedx*4*self.game.dt
|
||||||
|
self.playery += speedy*4*self.game.dt
|
||||||
|
|
||||||
self.game.globals["camerax"] = self.playerx-self.game.globals["cameraw"]/2
|
self.game.globals["camerax"] = self.playerx-self.game.globals["cameraw"]/2
|
||||||
self.game.globals["camerax"] = max(0,self.game.globals["camerax"])
|
self.game.globals["camerax"] = max(0,self.game.globals["camerax"])
|
||||||
@ -78,9 +95,13 @@ class Levels(BaseObject):
|
|||||||
self.game.window.blit(sprite,[x,y])
|
self.game.window.blit(sprite,[x,y])
|
||||||
|
|
||||||
# Draw player
|
# Draw player
|
||||||
sprite = self.playerstill
|
if self.moving:
|
||||||
x = self.nodes[self.cursor]["x"]-self.game.globals["camerax"]-sprite.get_width()/2
|
sprite = self.playerwalking[int(self.spriteindex)%len(self.playerwalking)]
|
||||||
y = self.nodes[self.cursor]["y"]-self.game.globals["cameray"]-sprite.get_height()/2
|
else:
|
||||||
|
sprite = self.playerstill
|
||||||
|
sprite = self.game.pygame.transform.flip(sprite,self.flip,False)
|
||||||
|
x = self.playerx-self.game.globals["camerax"]-sprite.get_width()/2
|
||||||
|
y = self.playery-self.game.globals["cameray"]-sprite.get_height()/2-6
|
||||||
self.game.window.blit(sprite,[x,y])
|
self.game.window.blit(sprite,[x,y])
|
||||||
|
|
||||||
# Draw level's number
|
# Draw level's number
|
||||||
|
Loading…
Reference in New Issue
Block a user