Changed hitbox system
This commit is contained in:
parent
8f2d2b20f1
commit
d9d51042e3
@ -48,8 +48,7 @@ class Game():
|
||||
self.globals["cameray"] = 0
|
||||
self.globals["scamerax"] = 3
|
||||
self.globals["scameray"] = 0
|
||||
self.globals["players"] = []
|
||||
self.globals["hitpose"] = False
|
||||
self.globals["debug"] = True
|
||||
self.scaleCamera()
|
||||
|
||||
settings = {"sfx":1,"bgm":1}
|
||||
|
@ -3,10 +3,12 @@ import random,math
|
||||
|
||||
class Lemming(BaseObject):
|
||||
def __init__(self,x,y,game,speedmargin=5):
|
||||
super().__init__(x,y,game)
|
||||
super().__init__(x,y,game,w=45,h=45)
|
||||
self.direction = random.randint(0,360)
|
||||
self.radius = 30 # Radius in which the mouse can click
|
||||
self.basespeed = 50+random.randint(-speedmargin,speedmargin) # Speed that he normally walks by
|
||||
self.holdrect = self.rect.copy()
|
||||
self.holdradius = 60
|
||||
self.holdrect = self.holdrect.inflate(self.holdradius,self.holdradius)
|
||||
self.basespeed = 40+random.randint(-speedmargin,speedmargin) # Speed that he normally walks by
|
||||
self.normalspeed = self.basespeed # Speed "objective"
|
||||
self.speed = 0 # Current speed, leaning towards objective speed
|
||||
|
||||
@ -47,22 +49,20 @@ class Lemming(BaseObject):
|
||||
|
||||
# Mouse selection
|
||||
mouse=self.game.inputs["mouse"]
|
||||
distance = math.sqrt((mouse["campos"][0]-self.rect.center[0])**2+(mouse["campos"][1]-self.rect.center[1])**2)
|
||||
if self.selected:
|
||||
# Caching mouse relative movement
|
||||
self.cachedrel.append(mouse["rel"])
|
||||
if len(self.cachedrel)>self.cachedrelsize:
|
||||
self.cachedrel.pop(0)
|
||||
# Releasing it
|
||||
if mouse["click"]==0 or distance>4*self.radius:
|
||||
if mouse["click"]==0 or not self.holdrect.collidepoint(mouse["campos"]):
|
||||
self.launch()
|
||||
if self.game.inputs["mouse"]["click"]==1:
|
||||
if distance<=self.radius:
|
||||
if self.rect.collidepoint(mouse["campos"]):
|
||||
self.selected = True
|
||||
|
||||
# Animation
|
||||
self.spriteindex+=self.game.dt*self.animspeed*self.speed
|
||||
|
||||
def launch(self):
|
||||
# Launch itself in the mouse direction
|
||||
if len(self.cachedrel)>self.mincachedsize:
|
||||
@ -81,9 +81,20 @@ class Lemming(BaseObject):
|
||||
self.resty = vely-int(vely)
|
||||
self.rect[0]+=int(velx)
|
||||
self.rect[1]+=int(vely)
|
||||
self.holdrect[0]+=int(velx)
|
||||
self.holdrect[1]+=int(vely)
|
||||
|
||||
def draw(self):
|
||||
orientation = self.orientations[int(self.direction%360/361*4)]
|
||||
sprites = self.sprites[orientation]
|
||||
self.game.lib.drawcenter(self.game,self.game.sprite_lib["lemmings/shadow.png"],self.rect.center[0],self.rect.center[1])
|
||||
self.game.lib.drawcenter(self.game,sprites[int(self.spriteindex)%len(sprites)],self.rect.center[0],self.rect.center[1])
|
||||
if self.game.globals["debug"]:
|
||||
s = self.game.pygame.Surface(self.rect.size)
|
||||
s.fill([255,0,0])
|
||||
s.set_alpha(30)
|
||||
self.game.window.blit(s,self.rect[:2])
|
||||
s = self.game.pygame.Surface(self.holdrect.size)
|
||||
s.fill([0,255,0])
|
||||
s.set_alpha(30)
|
||||
self.game.window.blit(s,self.holdrect[:2])
|
||||
|
Loading…
Reference in New Issue
Block a user