From 5dfa2a06afdbd1f81c28fb902d821dd4b382089f Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Tue, 16 Nov 2021 11:32:31 +0100 Subject: [PATCH] Added simple water --- gamedata/objects/combat/movable.py | 1 + gamedata/objects/combat/player.py | 41 ++++++++++++++++++++---------- gamedata/objects/combat/water.py | 28 ++++++++++++++++++++ gamedata/scenes.py | 3 +++ 4 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 gamedata/objects/combat/water.py diff --git a/gamedata/objects/combat/movable.py b/gamedata/objects/combat/movable.py index 5395853..53978e6 100644 --- a/gamedata/objects/combat/movable.py +++ b/gamedata/objects/combat/movable.py @@ -7,6 +7,7 @@ class Movable(BaseObject): self.sprite = game.sprite_lib["icon.png"] self.tileset = game.gameloop.findname("TilesetRenderer")[0] + self.water = game.gameloop.findname("Water")[0] super().__init__(x,y,game,self.sprite.get_width(),self.sprite.get_height()) diff --git a/gamedata/objects/combat/player.py b/gamedata/objects/combat/player.py index c739251..2e7da34 100644 --- a/gamedata/objects/combat/player.py +++ b/gamedata/objects/combat/player.py @@ -36,13 +36,19 @@ class Player(Movable): self.stepsize = 20 self.gravity = 15 - self.maxgravity = 80 + self.maxgravity = 30 self.jump = -5 self.verspd = self.maxgravity + self.gravityway = 1 + def step(self): if not self.hitpose: + + self.gravityway = 1 + if self.rect.center[1]>self.water.rect[1]: + self.gravityway = -1 if not self.game.globals["hitpose"]: keys = self.game.inputs["keys"] if self.controlled: @@ -52,15 +58,24 @@ class Player(Movable): # Si je suis sur le sol self.onground = False self.onceilling = False - if self.checkcollisions(0,1): + if self.checkcollisions(0,self.gravityway): self.onground = True - self.verspd=min(0,self.verspd) + if self.gravityway > 0: + self.verspd=min(0,self.verspd) + else: + self.verspd=max(0,self.verspd) else: - self.verspd+=self.gravity*self.game.dt - self.verspd= min(self.maxgravity,self.verspd) - if self.checkcollisions(0,-1): + self.verspd+=self.gravity*self.game.dt*self.gravityway + if self.gravityway>0: + self.verspd= min(self.maxgravity,self.verspd) + else: + self.verspd = max(-self.maxgravity,self.verspd) + if self.checkcollisions(0,-self.gravityway): self.onceilling = True - self.verspd= max(0,self.verspd) # Se cogne au plafond BONK + if self.gravityway>0: + self.verspd= max(0,self.verspd) # Se cogne au plafond BONK + else: + self.verspd = min(0,self.verspd) # Adding knockback self.horspd+=self.horkb @@ -69,12 +84,12 @@ class Player(Movable): self.jumped = False if self.onground: if 0