Added shooter ennemy

This commit is contained in:
theo@manjaro 2021-11-25 15:11:23 +01:00
parent 475cd8b9e2
commit a773aeb4a6
13 changed files with 144 additions and 44 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 839 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 820 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 812 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 820 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 839 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

View File

@ -22,6 +22,8 @@ class Ennemy(Movable):
self.candie = True self.candie = True
self.cancombo = True self.cancombo = True
self.onscreen = True
self.nodes = nodes self.nodes = nodes
self.customvalues = customvalues self.customvalues = customvalues
@ -32,6 +34,16 @@ class Ennemy(Movable):
def step(self): def step(self):
self.onscreen = True
if self.rect.center[0] < self.game.globals["camerax"]-self.respawnmargin:
self.onscreen = False
if self.rect.center[0] > self.game.globals["camerax"]+self.game.globals["cameraw"]+self.respawnmargin:
self.onscreen = False
if self.rect.center[1] < self.game.globals["cameray"]-self.respawnmargin:
self.onscreen = False
if self.rect.center[1] > self.game.globals["cameray"]+self.game.globals["camerah"]+self.respawnmargin:
self.onscreen = False
if not self.dead: if not self.dead:
super().step() super().step()
# Check for collision with player # Check for collision with player
@ -65,11 +77,7 @@ class Ennemy(Movable):
self.player.canfastfall = True self.player.canfastfall = True
self.player.upcombo() self.player.upcombo()
elif self.respawn: elif self.respawn:
if not self.onscreen:
if self.rect.center[0] < self.game.globals["camerax"]-self.respawnmargin: self.dead = False
self.dead = False # Respawn
if self.rect.center[0] > self.game.globals["camerax"]+self.game.globals["cameraw"]+self.respawnmargin:
self.dead = False # Respawn
else: else:
self.game.gameloop.delid(self.id) self.game.gameloop.delid(self.id)

View File

@ -0,0 +1,34 @@
from gamedata.objects.ingame.ennemies.ennemy import Ennemy
class Projectile(Ennemy):
def __init__(self,*args):
super().__init__(*args)
self.flip = self.customvalues["flip"]
self.sprite = self.game.pygame.transform.flip(self.game.sprite_lib["shooter/spike.png"],self.flip,False)
self.rect[2],self.rect[3] = self.sprite.get_size()
self.rect[0]-=(self.rect[2])/2
self.rect[1]-=(self.rect[3])/2
self.spd = 120
self.candie = False
self.collisions = False
def step(self):
movement = -self.spd*self.game.dt
if self.flip:
movement*=-1
self.horspd=movement
super().step()
if not self.onscreen:
self.game.gameloop.delid(self.id)
def draw(self):
self.game.window.blit(self.sprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])

View File

@ -0,0 +1,44 @@
from gamedata.objects.ingame.ennemies.ennemy import Ennemy
from gamedata.objects.ingame.ennemies.projectile import Projectile
class Shooter(Ennemy):
def __init__(self,*args):
super().__init__(*args)
self.sprites = self.game.getSpriteDir("shooter/")
self.projectilesprite = self.game.getSpriteDir("shooter/spike.png")
self.sprite = self.sprites[0]
self.spriteindex = 0
self.animspeed = 6
self.rect[2],self.rect[3] = self.sprite.get_size()
self.rect[0]+=(16-self.rect[2])/2
self.rect[1]+=(16-self.rect[3])/2
self.shoottimer = self.game.lib.Timer(2)
self.candie = False
def step(self):
if self.spriteindex == 0:
self.sprite = self.sprites[0]
if self.shoottimer.tick(self.game.dt):
self.spriteindex+=self.animspeed*self.game.dt
# Shoot
p = Projectile(self.rect.center[0],self.rect.center[1],self.game,self.nodes,self.customvalues)
self.game.gameloop.summon(p)
else:
self.spriteindex+=self.animspeed*self.game.dt
self.sprite = self.sprites[int(self.spriteindex)%len(self.sprites)]
if int(self.spriteindex)>=len(self.sprites):
self.spriteindex = 0
super().step()
def draw(self):
sprite = self.game.pygame.transform.flip(self.sprite,self.customvalues["flip"],False)
self.game.window.blit(sprite,(self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]))

View File

@ -12,6 +12,8 @@ class Squid(Ennemy):
self.rect[2],self.rect[3] = self.deadsprite.get_size() self.rect[2],self.rect[3] = self.deadsprite.get_size()
self.flip = False
self.speed = 40 self.speed = 40
self.spriteindex = 0 self.spriteindex = 0
@ -54,6 +56,9 @@ class Squid(Ennemy):
self.spriteindex += self.speed*self.game.dt*0.15 self.spriteindex += self.speed*self.game.dt*0.15
if self.player:
self.flip = self.player.rect.center[0]>self.rect.center[0]
super().step() # Actually move super().step() # Actually move
@ -63,4 +68,5 @@ class Squid(Ennemy):
self.sprite = self.sprites[int(self.spriteindex)%len(self.sprites)] self.sprite = self.sprites[int(self.spriteindex)%len(self.sprites)]
if self.fallingway>0: if self.fallingway>0:
self.sprite = self.sprites[1] self.sprite = self.sprites[1]
self.game.window.blit(self.sprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]]) sprite = self.game.pygame.transform.flip(self.sprite,self.flip,False)
self.game.window.blit(sprite,[self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]])

View File

@ -21,55 +21,62 @@ class Movable(BaseObject):
self.hrest = 0 self.hrest = 0
self.vrest = 0 self.vrest = 0
self.collisions = True
def step(self): def step(self):
self.move(self.horspd,self.verspd) self.move(self.horspd,self.verspd,collisions=self.collisions)
def move(self,movex,movey): def move(self,movex,movey,collisions = True):
hstoped = False hstoped = False
hor = int(movex+self.hrest) hor = int(movex+self.hrest)
self.hrest = movex+self.hrest-hor self.hrest = movex+self.hrest-hor
while abs(hor)>0: if collisions:
if hor>=self.tilew: while abs(hor)>0:
diffx = self.tilew if hor>=self.tilew:
elif hor<=-self.tilew: diffx = self.tilew
diffx = -self.tilew elif hor<=-self.tilew:
else: diffx = -self.tilew
diffx = hor
rect = self.checkcollisions(diffx,0)
if rect:
hor = 0
self.hrest = 0
hstopped = True
if diffx>0:
self.rect.right = rect.left
else: else:
self.rect.left = rect.right diffx = hor
else: rect = self.checkcollisions(diffx,0)
hor-=diffx if rect:
self.rect[0]+=diffx hor = 0
self.hrest = 0
hstopped = True
if diffx>0:
self.rect.right = rect.left
else:
self.rect.left = rect.right
else:
hor-=diffx
self.rect[0]+=diffx
vstoped = False vstoped = False
ver = int(movey+self.vrest) ver = int(movey+self.vrest)
self.vrest = movey+self.vrest-ver self.vrest = movey+self.vrest-ver
while abs(ver)>0: if collisions:
if abs(ver)>self.tileh: while abs(ver)>0:
diffy = self.tileh*abs(ver)/ver if abs(ver)>self.tileh:
else: diffy = self.tileh*abs(ver)/ver
diffy = ver
rect = self.checkcollisions(0,diffy)
if rect:
vstopped = True
ver = 0
self.vrest = 0
if diffy>0:
self.rect.bottom = rect.top
else: else:
self.rect.top = rect.bottom diffy = ver
else: rect = self.checkcollisions(0,diffy)
ver-=diffy if rect:
self.rect[1]+=diffy vstopped = True
ver = 0
self.vrest = 0
if diffy>0:
self.rect.bottom = rect.top
else:
self.rect.top = rect.bottom
else:
ver-=diffy
self.rect[1]+=diffy
else:
self.rect[0]+=hor
self.rect[1]+=ver
def checkcollisions(self,offx,offy,classic=True,semi=True): def checkcollisions(self,offx,offy,classic=True,semi=True):
temprect = self.rect.copy() temprect = self.rect.copy()

View File

@ -6,6 +6,7 @@ from gamedata.objects.ingame.ennemies.spring import Spring
from gamedata.objects.ingame.ennemies.waterchange import WaterChange from gamedata.objects.ingame.ennemies.waterchange import WaterChange
from gamedata.objects.ingame.ennemies.trashbag import TrashBag from gamedata.objects.ingame.ennemies.trashbag import TrashBag
from gamedata.objects.ingame.ennemies.squid import Squid from gamedata.objects.ingame.ennemies.squid import Squid
from gamedata.objects.ingame.ennemies.shooter import Shooter
from gamedata.objects.ingame.endflag import EndFlag from gamedata.objects.ingame.endflag import EndFlag
from gamedata.objects.levels import Levels from gamedata.objects.levels import Levels
from gamedata.objects.ripple import Ripple from gamedata.objects.ripple import Ripple
@ -84,7 +85,7 @@ class TilesetRenderer(BaseObject):
self.bgm.set_volume(self.game.globals["bgmvolume"]) self.bgm.set_volume(self.game.globals["bgmvolume"])
self.bgm.play(-1) self.bgm.play(-1)
spawnlists = {"Spawns":self.spawns} spawnlists = {"Spawns":self.spawns}
ennemies = {"Robot":Robot,"Crate":Crate,"Balloon":Balloon,"Spring":Spring,"WaterChange":WaterChange,"Levels":Levels,"End":EndFlag,"TrashBag":TrashBag,"Ripple":Ripple,"Squid":Squid} ennemies = {"Robot":Robot,"Crate":Crate,"Balloon":Balloon,"Spring":Spring,"WaterChange":WaterChange,"Levels":Levels,"End":EndFlag,"TrashBag":TrashBag,"Ripple":Ripple,"Squid":Squid,"Shooter":Shooter}
self.queue = [] # For spawning ennemies after beeing initialized self.queue = [] # For spawning ennemies after beeing initialized
if "layers" in json.keys() and type(json["layers"]).__name__=="list": if "layers" in json.keys() and type(json["layers"]).__name__=="list":
solidlayer = False solidlayer = False