Added simple water
This commit is contained in:
parent
5b026041cc
commit
5dfa2a06af
@ -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())
|
||||
|
||||
|
@ -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<keys["up"]["timer"]<=3:
|
||||
self.verspd= self.jump
|
||||
self.verspd= self.jump*self.gravityway
|
||||
self.jumped = True
|
||||
if self.verspd==0:
|
||||
self.move(0,-self.stepsize)
|
||||
self.move(0,-self.stepsize*self.gravityway)
|
||||
super().step()
|
||||
self.move(0,self.stepsize)
|
||||
self.move(0,self.stepsize*self.gravityway)
|
||||
else:
|
||||
super().step()
|
||||
|
||||
@ -96,9 +111,9 @@ class Player(Movable):
|
||||
if semi!=self.checkcollisions(0,0,classic=False) and semi:
|
||||
self.rect.bottom = semi.top+1
|
||||
falled = True
|
||||
if not falled:
|
||||
if 0<self.verspd <= self.fastfallmargin or (abs(self.verspd)<abs(self.currentspdv) and abs(self.verspd)<=self.fastfallmargin/1.8):
|
||||
self.verspd = self.maxgravity/4
|
||||
if not falled: # Check for fastfall
|
||||
if abs(self.verspd) <= self.fastfallmargin and not self.onground:
|
||||
self.verspd = self.maxgravity/5*self.gravityway
|
||||
|
||||
else: # If I'm in hitpose
|
||||
if self.hitposetimer.tick(self.game.dt):
|
||||
|
28
gamedata/objects/combat/water.py
Normal file
28
gamedata/objects/combat/water.py
Normal file
@ -0,0 +1,28 @@
|
||||
from gamedata.objects.base import BaseObject
|
||||
|
||||
class Water(BaseObject):
|
||||
|
||||
def __init__(self,y,game):
|
||||
|
||||
super().__init__(0,y,game,game.DISPLAY_WIDTH,game.DISPLAY_HEIGHT)
|
||||
|
||||
self.destinationy = y
|
||||
self.speed = 10
|
||||
|
||||
self.sprite = game.pygame.Surface((game.DISPLAY_WIDTH,game.DISPLAY_HEIGHT),flags=game.pygame.SRCALPHA)
|
||||
self.sprite.fill([10,100,180])
|
||||
self.sprite.set_alpha(200)
|
||||
|
||||
self.surfacepoints = []
|
||||
self.nbpoints = 50
|
||||
for i in range(self.nbpoints):
|
||||
self.surfacepoints.append([game.DISPLAY_WIDTH/self.nbpoints*i,0])
|
||||
|
||||
def step(self):
|
||||
|
||||
self.rect[1] += (self.destinationy-self.rect[1])*self.game.dt*self.speed
|
||||
|
||||
def draw(self):
|
||||
|
||||
# Draw the water to the screen
|
||||
self.game.window.blit(self.sprite,[self.rect[0],self.rect[1]-self.game.globals["cameray"]])
|
@ -8,6 +8,7 @@ from gamedata.objects.combat.player import Player
|
||||
from gamedata.objects.combat.manager import FightManager
|
||||
from gamedata.objects.combat.hitbox import Hitbox
|
||||
from gamedata.objects.combat.tileset import TilesetRenderer
|
||||
from gamedata.objects.combat.water import Water
|
||||
|
||||
def main(game):
|
||||
game.scaleCamera()
|
||||
@ -27,6 +28,8 @@ def fight(game):
|
||||
game.gameloop.summon(tileset)
|
||||
box = Hitbox(100,80,game)
|
||||
game.gameloop.summon(box)
|
||||
water = Water(200,game)
|
||||
game.gameloop.summon(water)
|
||||
p1 = Player(game)
|
||||
game.gameloop.summon(p1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user