Modified hitbox behavior
This commit is contained in:
parent
01a97402dd
commit
870a931ee5
@ -51,7 +51,26 @@ class Ennemy(Movable):
|
|||||||
if not self.player:
|
if not self.player:
|
||||||
self.player = next(iter(self.game.gameloop.findname("Player")),None)
|
self.player = next(iter(self.game.gameloop.findname("Player")),None)
|
||||||
else:
|
else:
|
||||||
if self.canhit:
|
if self.candie:
|
||||||
|
for rect in self.player.hitrects:
|
||||||
|
if self.rect.colliderect(rect):
|
||||||
|
# Die
|
||||||
|
self.dead = True
|
||||||
|
self.deadtrigger()
|
||||||
|
# Add particles
|
||||||
|
self.game.addParticle(self.dustparticles,self.rect.center[0]+self.particleoffsetx,self.rect.center[1]+self.particleoffsety) # Dust
|
||||||
|
self.game.addParticle([self.deadsprite],self.rect.center[0]+self.particleoffsetx,self.rect.center[1]+self.particleoffsety,fps=0.6,vely=-1.5,modvely=0.15) # Die sprite
|
||||||
|
# Boost the player vertically
|
||||||
|
if not self.player.fastfall:
|
||||||
|
if self.player.rect[1]>self.rect[1]:
|
||||||
|
direction = 1
|
||||||
|
else:
|
||||||
|
direction = -1
|
||||||
|
self.player.verspd = self.player.gravity/3*direction
|
||||||
|
if not self.player.fastfall:
|
||||||
|
self.player.canfastfall = True
|
||||||
|
self.player.upcombo()
|
||||||
|
if self.canhit and not self.dead:
|
||||||
if self.rect.colliderect(self.player):
|
if self.rect.colliderect(self.player):
|
||||||
# Knock it horizontally
|
# Knock it horizontally
|
||||||
if self.player.rect[0]>self.rect[0]:
|
if self.player.rect[0]>self.rect[0]:
|
||||||
@ -59,24 +78,6 @@ class Ennemy(Movable):
|
|||||||
else:
|
else:
|
||||||
hor = -1
|
hor = -1
|
||||||
self.player.yeet(hor*6,self.player.gravityway*-3,dmg=self.damage)
|
self.player.yeet(hor*6,self.player.gravityway*-3,dmg=self.damage)
|
||||||
if self.candie and self.player.canhit:
|
|
||||||
if self.rect.colliderect(self.player.hitrect):
|
|
||||||
# Die
|
|
||||||
self.dead = True
|
|
||||||
self.deadtrigger()
|
|
||||||
# Add particles
|
|
||||||
self.game.addParticle(self.dustparticles,self.rect.center[0]+self.particleoffsetx,self.rect.center[1]+self.particleoffsety) # Dust
|
|
||||||
self.game.addParticle([self.deadsprite],self.rect.center[0]+self.particleoffsetx,self.rect.center[1]+self.particleoffsety,fps=0.6,vely=-1.5,modvely=0.15) # Die sprite
|
|
||||||
# Boost the player vertically
|
|
||||||
if not self.player.fastfall:
|
|
||||||
if self.player.rect[1]>self.rect[1]:
|
|
||||||
direction = 1
|
|
||||||
else:
|
|
||||||
direction = -1
|
|
||||||
self.player.verspd = self.player.gravity/3*direction
|
|
||||||
if not self.player.fastfall:
|
|
||||||
self.player.canfastfall = True
|
|
||||||
self.player.upcombo()
|
|
||||||
elif self.respawn:
|
elif self.respawn:
|
||||||
if not self.onscreen:
|
if not self.onscreen:
|
||||||
self.dead = False
|
self.dead = False
|
||||||
|
@ -49,9 +49,13 @@ class Player(Movable):
|
|||||||
|
|
||||||
self.water = self.game.gameloop.findname("Water")[0]
|
self.water = self.game.gameloop.findname("Water")[0]
|
||||||
|
|
||||||
self.hitrect = self.rect.copy()
|
self.lowerhitrect = self.rect.copy()
|
||||||
self.hitrect[2] = round(self.hitrect[2]*1)
|
self.lowerhitrect[2] = round(self.rect[2]*0.5)
|
||||||
self.hitrect[3] = round(self.hitrect[3]*0.7)
|
self.lowerhitrect[3] = round(self.rect[3]*0.2)
|
||||||
|
self.upperhitrect = self.lowerhitrect.copy()
|
||||||
|
self.upperhitrect[3] = round(self.rect[3]*0.4)
|
||||||
|
self.upperhitrectwidth=round(self.rect[2])
|
||||||
|
self.hitrects = [self.lowerhitrect,self.upperhitrect]
|
||||||
self.canhit = False
|
self.canhit = False
|
||||||
|
|
||||||
self.dustparticles = game.getSpriteDir("particles/dust/")
|
self.dustparticles = game.getSpriteDir("particles/dust/")
|
||||||
@ -228,15 +232,23 @@ class Player(Movable):
|
|||||||
for i in self.spikes:
|
for i in self.spikes:
|
||||||
if i.collidepoint(self.rect.center):
|
if i.collidepoint(self.rect.center):
|
||||||
self.die()
|
self.die()
|
||||||
# Updated hitrect
|
|
||||||
self.hitrect[0] = self.rect.center[0]-self.hitrect[2]/2
|
# Update stomp hitrect
|
||||||
offset = 0
|
self.lowerhitrect[0] = self.rect.center[0]-self.lowerhitrect[2]/2
|
||||||
|
self.lowerhitrect[1] = self.rect.center[1]-self.lowerhitrect[3]/2+20*self.gravityway
|
||||||
|
|
||||||
|
# Update bonk hitrect
|
||||||
|
canhit = abs(self.verspd)>1.8
|
||||||
if self.verspd>0:
|
if self.verspd>0:
|
||||||
offset = 1
|
offset = 1
|
||||||
elif self.verspd<0:
|
else:
|
||||||
offset = -1
|
offset = -1
|
||||||
self.canhit = abs(self.verspd)>2
|
self.upperhitrect[0] = self.rect.center[0]-self.upperhitrect[2]/2
|
||||||
self.hitrect[1] = self.rect.center[1]-self.hitrect[3]/2+10*offset
|
self.upperhitrect[1] = self.rect.center[1]-self.upperhitrect[3]/2+10*offset
|
||||||
|
if canhit:
|
||||||
|
self.upperhitrect[2] = self.upperhitrectwidth
|
||||||
|
else:
|
||||||
|
self.upperhitrect[2] = 0
|
||||||
|
|
||||||
# Reducing the knockback
|
# Reducing the knockback
|
||||||
if self.horkb>0:
|
if self.horkb>0:
|
||||||
@ -319,6 +331,8 @@ class Player(Movable):
|
|||||||
self.deadsfx.play()
|
self.deadsfx.play()
|
||||||
self.depth = 5
|
self.depth = 5
|
||||||
self.rect[2],self.rect[3] = 0,0
|
self.rect[2],self.rect[3] = 0,0
|
||||||
|
for rect in self.hitrects:
|
||||||
|
rect[2] = 0
|
||||||
self.dead = True
|
self.dead = True
|
||||||
|
|
||||||
t = Transition(self.game,time=1,holdtime=0.5,level="Level "+str(self.game.globals["levelname"]+1))
|
t = Transition(self.game,time=1,holdtime=0.5,level="Level "+str(self.game.globals["levelname"]+1))
|
||||||
@ -336,6 +350,11 @@ class Player(Movable):
|
|||||||
flipy = self.fastfall<0
|
flipy = self.fastfall<0
|
||||||
sprite = self.game.pygame.transform.flip(self.sprite,self.flipx,flipy)
|
sprite = self.game.pygame.transform.flip(self.sprite,self.flipx,flipy)
|
||||||
self.game.window.blit(sprite,[self.rect[0]-self.game.globals["camerax"]-self.spriteoffset,self.rect[1]-self.game.globals["cameray"]])
|
self.game.window.blit(sprite,[self.rect[0]-self.game.globals["camerax"]-self.spriteoffset,self.rect[1]-self.game.globals["cameray"]])
|
||||||
|
|
||||||
|
# Hitrects
|
||||||
|
if self.game.globals["allunlocked"]:
|
||||||
|
for rect in self.hitrects:
|
||||||
|
self.game.pygame.draw.rect(self.game.window,[255,0,0],[rect[0]-self.game.globals["camerax"],rect[1]-self.game.globals["cameray"],rect[2],rect[3]])
|
||||||
else:
|
else:
|
||||||
if self.deathtimer.getloops()%2==0:
|
if self.deathtimer.getloops()%2==0:
|
||||||
self.game.window.blit(self.retrytext,[self.game.globals["cameraw"]/2-self.retrytext.get_width()/2,self.game.globals["camerah"]/2-self.retrytext.get_height()/2])
|
self.game.window.blit(self.retrytext,[self.game.globals["cameraw"]/2-self.retrytext.get_width()/2,self.game.globals["camerah"]/2-self.retrytext.get_height()/2])
|
||||||
|
Loading…
Reference in New Issue
Block a user