From 2ca249f666d4200ac7a7a5762a8b52caad8da908 Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Tue, 14 Sep 2021 17:01:58 +0200 Subject: [PATCH] Added screenshake --- gamedata/objects/ingame/lemmings.py | 10 ++++++---- gamedata/objects/ingame/spawner.py | 6 ++++-- gamedata/objects/ingame/tiles.py | 6 +++--- gamedata/scenes.py | 2 ++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/gamedata/objects/ingame/lemmings.py b/gamedata/objects/ingame/lemmings.py index fb8d97b..f16f2a3 100644 --- a/gamedata/objects/ingame/lemmings.py +++ b/gamedata/objects/ingame/lemmings.py @@ -83,6 +83,8 @@ class Lemming(BaseObject): dead = False if dead: self.manager.death() + self.game.globals["scamerax"]+=5 + self.game.globals["scameray"]+=5 self.game.gameloop.delid(self.id) def launch(self): @@ -109,14 +111,14 @@ class Lemming(BaseObject): 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]) + self.game.lib.drawcenter(self.game,self.game.sprite_lib["lemmings/shadow.png"],self.rect.center[0]-self.game.globals["camerax"],self.rect.center[1]-self.game.globals["cameray"]) + self.game.lib.drawcenter(self.game,sprites[int(self.spriteindex)%len(sprites)],self.rect.center[0]-self.game.globals["camerax"],self.rect.center[1]-self.game.globals["cameray"]) 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]) + self.game.window.blit(s,(self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"])) 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]) + self.game.window.blit(s,(self.holdrect[0]-self.game.globals["camerax"],self.holdrect[1]-self.game.globals["cameray"])) diff --git a/gamedata/objects/ingame/spawner.py b/gamedata/objects/ingame/spawner.py index e4ee151..f9f5bc5 100644 --- a/gamedata/objects/ingame/spawner.py +++ b/gamedata/objects/ingame/spawner.py @@ -19,12 +19,14 @@ class Spawner(BaseObject): lemming.move(-lemming.rect[2]/2,-lemming.rect[3]/2) self.game.gameloop.summon(lemming) self.game.gameloop.delid(self.id) + self.game.globals["scamerax"]+=3 + self.game.globals["scameray"]+=3 def draw(self): # Display the lemming falling currentdistance = self.distance*self.timer.getratio()**2 - self.game.lib.drawcenter(self.game,self.fallsprite,self.rect[0],self.rect[1]-currentdistance) + self.game.lib.drawcenter(self.game,self.fallsprite,self.rect[0]-self.game.globals["camerax"],self.rect[1]-currentdistance-self.game.globals["cameray"]) # Draw the shadow - self.game.lib.drawcenter(self.game,self.sprite,self.rect[0],self.rect[1]) + self.game.lib.drawcenter(self.game,self.sprite,self.rect[0]-self.game.globals["camerax"],self.rect[1]-self.game.globals["cameray"]) diff --git a/gamedata/objects/ingame/tiles.py b/gamedata/objects/ingame/tiles.py index 39c9afc..52fad00 100644 --- a/gamedata/objects/ingame/tiles.py +++ b/gamedata/objects/ingame/tiles.py @@ -52,13 +52,13 @@ class Tiles(BaseObject): def draw(self): # Drawing the ground - self.game.window.blit(self.game.sprite_lib["ingame.png"],(0,0)) + self.game.window.blit(self.game.sprite_lib["ingame.png"],(-self.game.globals["camerax"],-self.game.globals["cameray"])) if self.game.globals["debug"]: # Drawing the grid for y in range(len(self.grid)): for x in range(len(self.grid[y])): if self.grid[y][x]==1: - self.game.window.blit(self.debugcell,[self.rect[0]+x*self.cellsize,self.rect[1]+y*self.cellsize]) + self.game.window.blit(self.debugcell,[self.rect[0]+x*self.cellsize-self.game.globals["camerax"],self.rect[1]+y*self.cellsize-self.game.globals["cameray"]]) # Draw spawn points for point in self.spawns: - self.game.pygame.draw.circle(self.game.window,[100,100,0],point,radius=3) + self.game.pygame.draw.circle(self.game.window,[100,100,0],[point[0]-self.game.globals["camerax"],point[1]-self.game.globals["cameray"]],radius=3) diff --git a/gamedata/scenes.py b/gamedata/scenes.py index 44a5ddc..d9ef1f3 100644 --- a/gamedata/scenes.py +++ b/gamedata/scenes.py @@ -18,6 +18,8 @@ def main(game): def ingame(game): game.gameloop.reinit() + game.globals["camerax"] = 0 + game.globals["cameray"] = 0 game.gameloop.summon(Manager(game)) def options(game):