40 lines
1.8 KiB
Python
40 lines
1.8 KiB
Python
|
from gamedata.objects.base import BaseObject
|
||
|
|
||
|
class Hitbox(BaseObject):
|
||
|
|
||
|
def __init__(self,x,y,game,w=16,h=16,teamid=-1,kbmod=1,dmg=2,vkbmod=1,hkbmod=1,anchor = [0,0]):
|
||
|
|
||
|
super().__init__(x,y,game,w,h)
|
||
|
|
||
|
self.teamid = teamid
|
||
|
self.kbmod = kbmod # Global knockback multiplier
|
||
|
self.vkbmod = vkbmod # Vertical knockback multiplier
|
||
|
self.hkbmod = hkbmod # Horizontal knockback multiplier
|
||
|
self.dmg = dmg # Percentages that will be added
|
||
|
self.anchor = anchor # Rect that will be used as an origin
|
||
|
|
||
|
self.hitted = {} # Storing wich player it has touched
|
||
|
self.hitmargin = 0.5 # Time interval between two hits
|
||
|
|
||
|
def genkb(self,damage):
|
||
|
return 20+damage/5
|
||
|
|
||
|
def step(self):
|
||
|
if not self.game.globals["hitpose"]:
|
||
|
for player in self.game.globals["players"]:
|
||
|
if player.teamid!=self.teamid:
|
||
|
if player.rect.colliderect(self.rect):
|
||
|
if not player.playerid in self.hitted.keys():
|
||
|
self.hitted[player.playerid] = 0
|
||
|
if self.game.elapsedtime - self.hitted[player.playerid] >= self.hitmargin:
|
||
|
kb = self.genkb(player.damage)
|
||
|
player.horkb = kb*self.kbmod*self.hkbmod*player.multkb
|
||
|
player.verkb = kb*self.kbmod*self.vkbmod*player.multkb
|
||
|
player.hitpose = True
|
||
|
player.hitposetimer.reset()
|
||
|
|
||
|
self.hitted[player.playerid] = self.game.elapsedtime
|
||
|
|
||
|
def draw(self):
|
||
|
self.game.pygame.draw.rect(self.game.window,[100,100,255,50],(self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"],self.rect[2],self.rect[3]))
|