Overflown/gamedata/objects/ingame/ennemies/spring.py
2021-11-21 12:28:27 +01:00

75 lines
3.1 KiB
Python

from gamedata.objects.ingame.ennemies.ennemy import Ennemy
class Spring(Ennemy):
def __init__(self,*args):
super().__init__(*args)
spritesnormal = self.game.getSpriteDir("spring/normal/")
spritesside = self.game.getSpriteDir("spring/side/")
spritesdiagonal = self.game.getSpriteDir("spring/diagonal/")
self.sprite = spritesnormal[0]
self.rect[2],self.rect[3] = self.sprite.get_width(),round(self.sprite.get_height()/2)
self.spriteindex = 0
self.animspeed = 8
self.sfx = self.game.sound_lib["sfx/spring.wav"]
self.longsfx = self.game.sound_lib["sfx/longspring.wav"]
# Zone in with the player is colliding
# Formatting the angle ( clockwise, in degrees, starting at the top )
if "angle" in self.customvalues:
angle = self.customvalues["angle"]
else:
angle = 0
# Sprite,flipx,flipy
self.orientations = [[spritesnormal,False,False],[spritesdiagonal,False,False],[spritesside,False,False],[spritesdiagonal,False,True],[spritesnormal,False,True],[spritesdiagonal,True,True],[spritesside,True,False],[spritesdiagonal,True,False]]
orientation = self.orientations[int((angle/360*len(self.orientations))+0.5)%len(self.orientations)]
self.sprites = []
for i in orientation[0]:
self.sprites.append(self.game.pygame.transform.flip(i,orientation[1],orientation[2]))
self.sprite = self.sprites[0]
angle = self.game.math.radians(angle-90)
# Offsetting the zone
distance = self.rect[3]
self.ratiox = self.game.math.cos(angle)
self.ratioy = self.game.math.sin(angle)
offx = self.ratiox*distance
offy = self.ratioy*distance
self.jumpcenter = [self.rect.center[0]+offx,self.rect.center[1]+offy]
self.jumpradius = 10
if "strength" in self.customvalues:
self.jumpstrength = self.customvalues["strength"]
else:
self.jumpstrength = 5
self.candie = False
self.canhit = False
def step(self):
super().step()
# Check for collision with player
if self.player.verspd*self.ratioy<0 or abs(self.ratioy)<0.3:
if self.game.math.sqrt((self.player.rect.center[0]-self.jumpcenter[0])**2+(self.player.rect.center[1]-self.jumpcenter[1])**2)<self.jumpradius and not self.player.onground:
# Yeet the player
force = self.jumpstrength
if self.player.fastfall:
force*=1.5
self.longsfx.play()
else:
self.sfx.play()
self.player.yeet(self.ratiox*force,self.ratioy*force,resetcombo=False)
self.spriteindex = len(self.sprites)
self.spriteindex-=self.animspeed*self.game.dt
if self.spriteindex<0:
self.spriteindex=0
self.sprite = self.sprites[int(self.spriteindex)]
def draw(self):
self.game.window.blit(self.sprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])