PinmikPanik/gamedata/objects/ingame/manager.py

134 lines
5.3 KiB
Python
Raw Normal View History

2021-09-11 14:33:20 +02:00
from gamedata.objects.base import BaseObject
2021-09-13 10:34:34 +02:00
from gamedata.objects.ingame.spawner import Spawner
2021-09-11 15:12:53 +02:00
from gamedata.objects.ingame.tiles import Tiles
2021-09-14 16:09:42 +02:00
from gamedata.objects.ingame.clouds import Clouds
2021-09-15 13:48:58 +02:00
from gamedata.objects.ingame.skies import Skies
2021-09-17 15:00:19 +02:00
from gamedata.objects.ingame.demo import Demo
2021-09-11 14:33:20 +02:00
class Manager(BaseObject):
def __init__(self,game):
super().__init__(0,0,game)
2021-09-18 20:44:22 +02:00
self.score = 0
2021-09-11 15:12:53 +02:00
self.lives = 5
self.basetime = 10
self.steptime = 2
2021-09-13 13:13:38 +02:00
self.speedmargin = 7
2021-09-15 21:09:15 +02:00
self.speedstep = 2.2
2021-09-11 15:12:53 +02:00
self.spawntimer = game.lib.Timer(self.basetime) # Time elapsing each lemming spawn
2021-09-14 16:09:42 +02:00
self.deathtimer = game.lib.Timer(1) # Time between each life loss
2021-09-13 19:13:54 +02:00
self.started = False
2021-09-13 11:14:58 +02:00
self.invincible = False
2021-09-11 15:12:53 +02:00
2021-09-13 19:13:54 +02:00
self.endtimer = game.lib.Timer(1) # Black fade if game's over
self.endrect = game.pygame.Surface((game.DISPLAY_WIDTH,game.DISPLAY_HEIGHT))
self.endrect.fill([0]*3)
2021-09-15 13:48:58 +02:00
# Sky gradients
self.game.gameloop.summon(Skies(game))
2021-09-19 21:32:42 +02:00
# Dash sfx for the pinmiks
self.sfx = game.sound_lib["sfx/dash.wav"]
self.can_sfx = True
self.sfxtimer = game.lib.Timer(0.4)
2021-09-14 16:09:42 +02:00
# Clouds in the background
self.clouds = Clouds(game,game.DISPLAY_WIDTH,speed=30,cameraratio=0.8)
self.cloudsdark = Clouds(game,game.DISPLAY_WIDTH,speed=10,cameraratio=0.4,spritename="cloudsdark.png")
self.game.gameloop.summon(self.cloudsdark)
self.game.gameloop.summon(self.clouds)
2021-09-11 15:12:53 +02:00
# Summon the tiles
2021-09-13 22:16:02 +02:00
self.tiles = Tiles(288,0,game)
2021-09-11 15:12:53 +02:00
game.gameloop.summon(self.tiles)
2021-09-13 10:34:34 +02:00
2021-09-17 15:00:19 +02:00
# Demo
self.demo = None
self.demotimer = game.lib.Timer(4)
2021-09-18 18:27:52 +02:00
# Unlocks
self.skins = game.lib.getunlocks(self.game.globals["highscore"])
2021-09-18 18:27:52 +02:00
# Spawn the first batch
self.game.gameloop.summon(Spawner(self.game,self.tiles,skins=self.skins))
self.game.gameloop.summon(Spawner(self.game,self.tiles,skins=self.skins))
self.game.gameloop.summon(Spawner(self.game,self.tiles,skins=self.skins))
2021-09-19 21:32:42 +02:00
def dash(self):
# Called by pinmiks when dashing
if self.can_sfx:
self.sfx.play()
self.can_sfx = False
2021-09-11 14:33:20 +02:00
def step(self):
2021-09-19 21:32:42 +02:00
if not self.can_sfx:
if self.sfxtimer.tick(self.game.dt):
self.can_sfx = True
2021-09-18 20:44:22 +02:00
lemmings = self.game.gameloop.findname("Lemming")
nblemmings = len(lemmings) + len(self.game.gameloop.findname("Spawner"))
2021-09-13 11:14:58 +02:00
# Updating score
2021-09-19 12:20:43 +02:00
if not self.game.globals["pause"]:
for lemming in lemmings:
2021-09-20 13:37:25 +02:00
if not lemming.selected:
self.score+=lemming.scoreratio*self.game.dt
2021-09-19 12:20:43 +02:00
# Pausing the game
if self.game.inputs["keys"]["escape"]["timer"]==1:
self.game.globals["pause"] = not self.game.globals["pause"]
2021-09-13 11:14:58 +02:00
# Spawning more lemmings
2021-09-13 19:13:54 +02:00
if (self.lives>0 and nblemmings>0):
2021-10-18 11:42:34 +02:00
if not self.game.globals["pause"]:
if self.spawntimer.tick(self.game.dt):
self.game.gameloop.summon(Spawner(self.game,self.tiles,speedmargin=int(self.speedmargin+0.5),skins=self.skins))
self.speedmargin+=self.speedstep
self.spawntimer = self.game.lib.Timer(self.basetime+nblemmings*self.steptime)
2021-09-13 19:13:54 +02:00
else:
# Game over
if self.endtimer.tick(self.game.dt):
2021-09-17 11:03:32 +02:00
self.game.globals["score"] = int(self.score)
2021-09-18 11:07:14 +02:00
self.game.scene = self.game.scenes.gameover
2021-09-19 12:20:43 +02:00
self.game.globals["pause"] = False
2021-09-11 14:33:20 +02:00
2021-09-13 11:14:58 +02:00
if self.invincible:
if self.deathtimer.tick(self.game.dt):
self.invincible = False
2021-09-17 15:00:19 +02:00
if not self.demo:
if self.demotimer.tick(self.game.dt):
self.demo = self.game.gameloop.summon(Demo(self.game))
2021-09-13 11:14:58 +02:00
def death(self):
if not self.invincible:
self.lives-=1
self.invincible = True
2021-09-13 13:13:38 +02:00
else:
self.deathtimer.tick(self.deathtimer.getmax()/3)
2021-09-13 11:14:58 +02:00
2021-09-11 14:33:20 +02:00
def draw(self):
pass
2021-09-13 11:33:40 +02:00
def afterdraw(self):
2021-09-15 20:56:56 +02:00
# Draw vignette
self.game.realwindow.blit(self.game.sprite_lib["vignette.png"],[0,0])
# Draw score and lives with outline
2021-09-13 11:33:40 +02:00
txtsurfacescore = self.game.fontfile.render("Score : "+str(int(self.score)),False,[150,255,150])
2021-09-14 16:09:42 +02:00
txtsurfacescoreblack = self.game.fontfile.render("Score : "+str(int(self.score)),False,[0]*3)
txtsurfacelives = self.game.fontfile.render("Lives : "+str(int(self.lives)),False,[255,150,150])
txtsurfacelivesblack = self.game.fontfile.render("Lives : "+str(int(self.lives)),False,[0]*3)
border = 2
for x in range(-border,border+1):
for y in range(-border,border+1):
self.game.realwindow.blit(txtsurfacescoreblack,[20+x,20+y])
2021-09-13 11:33:40 +02:00
self.game.realwindow.blit(txtsurfacescore,[20,20])
2021-09-14 16:09:42 +02:00
for x in range(-border,border+1):
for y in range(-border,border+1):
self.game.realwindow.blit(txtsurfacelivesblack,[20+x,20*2+y+txtsurfacescore.get_height()])
2021-09-13 11:33:40 +02:00
self.game.realwindow.blit(txtsurfacelives,[20,20*2+txtsurfacescore.get_height()])
2021-09-13 19:13:54 +02:00
self.endrect.set_alpha((1-self.endtimer.getratio())*255)
2021-09-19 12:20:43 +02:00
if self.game.globals["pause"]:
self.endrect.set_alpha(100)
2021-09-18 11:07:14 +02:00
if self.endtimer.getloops()>=1:
self.endrect.set_alpha(255)
2021-09-13 19:13:54 +02:00
self.game.realwindow.blit(self.endrect,[0,0])