Added hitbox on player
This commit is contained in:
parent
73d9751608
commit
df7d544c31
@ -15,8 +15,12 @@ class Player(Movable):
|
||||
|
||||
self.water = self.game.gameloop.findname("Water")[0]
|
||||
|
||||
self.speed = 200
|
||||
self.hitrect = self.rect.copy()
|
||||
self.hitrect[2] = round(self.hitrect[2]*0.7)
|
||||
self.hitrect[3] = round(self.hitrect[3]*0.7)
|
||||
self.canhit = False
|
||||
|
||||
self.speed = 200
|
||||
self.controlled = True
|
||||
|
||||
self.playerid = 0
|
||||
@ -56,6 +60,7 @@ class Player(Movable):
|
||||
|
||||
if not self.hitpose:
|
||||
|
||||
|
||||
if self.water and self.rect.y>self.water.rect.y: # Reverse gravity underwater
|
||||
if self.gravityway == 1:
|
||||
self.gravityway = -1
|
||||
@ -115,7 +120,16 @@ class Player(Movable):
|
||||
if self.leaptimer<0 and not self.onground:
|
||||
self.verspd = -abs(self.verspd) # Small leap
|
||||
self.jumped = True
|
||||
super().step()
|
||||
super().step() # Actually move
|
||||
# Updated hitrect
|
||||
self.hitrect[0] = self.rect.center[0]-self.hitrect[2]/2
|
||||
offset = 0
|
||||
if self.verspd>0:
|
||||
offset = 1
|
||||
elif self.verspd<0:
|
||||
offset = -1
|
||||
self.canhit = abs(self.verspd)>2
|
||||
self.hitrect[1] = self.rect.center[1]-self.hitrect[3]/2+10*offset
|
||||
|
||||
# Reducing the knockback
|
||||
if self.horkb>0:
|
||||
@ -152,3 +166,6 @@ class Player(Movable):
|
||||
|
||||
def draw(self):
|
||||
self.game.window.blit(self.sprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])
|
||||
|
||||
if self.canhit:
|
||||
self.game.pygame.draw.rect(self.game.window,[255,100,100],[self.hitrect[0]-self.game.globals["camerax"],self.hitrect[1]-self.game.globals["cameray"],self.hitrect[2],self.hitrect[3]])
|
||||
|
Loading…
Reference in New Issue
Block a user