Added background clouds

This commit is contained in:
theo@manjaro 2021-09-14 16:09:42 +02:00
parent df215051f7
commit 8547c71d5c
7 changed files with 48 additions and 6 deletions

View File

@ -9,3 +9,7 @@ All the textures are edited by myself to fit the [Famicube palette](https://losp
## Little characters
[GraphxKid - OpenGameArt](https://opengameart.org/content/arcade-platformer-assets)
## Clouds
[Jetrel - OpenGameArt](https://opengameart.org/content/old-frogatto-clouds)

BIN
gamedata/assets/clouds.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

@ -12,8 +12,8 @@ class BackgroundDrawer(BaseObject):
game = self.game
self.tilew = sprite.get_width()
self.tileh = sprite.get_height()
nbw = round(self.rect[2]/self.tilew+1.5)
nbh = round(self.rect[3]/self.tileh+1.5)
nbw = round(self.rect[2]/self.tilew+2)
nbh = round(self.rect[3]/self.tileh+2)
sw = nbw*self.tileh
sh = nbh*self.tileh
self.sprite = game.pygame.Surface((sw,sh),game.pygame.SRCALPHA)

View File

@ -8,5 +8,5 @@ class MovingBackground(BackgroundDrawer):
self.spdy = spdy
def step(self):
self.rect[0]+=self.spdx
self.rect[1]+=self.spdy
self.rect[0]+=self.spdx*self.game.dt
self.rect[1]+=self.spdy*self.game.dt

View File

@ -0,0 +1,21 @@
from gamedata.objects.base import BaseObject
class Clouds(BaseObject):
def __init__(self,game,minwidth,speed=30,cameraratio=1,spritename="clouds.png"):
super().__init__(0,0,game)
self.sprite = game.sprite_lib[spritename]
self.speed = speed
self.minwidth = minwidth
self.cameraratio = cameraratio
depth = -1
self.horoffset = 0
def step(self):
self.horoffset+=self.game.dt*self.speed
def draw(self):
offset = (self.horoffset-self.game.globals["camerax"]*self.cameraratio)%self.sprite.get_width()
nbsprites = round((self.minwidth+offset)//self.sprite.get_width()+2)
for i in range(nbsprites):
self.game.window.blit(self.sprite,[(i-1)*self.sprite.get_width()+offset,0])

View File

@ -1,6 +1,7 @@
from gamedata.objects.base import BaseObject
from gamedata.objects.ingame.spawner import Spawner
from gamedata.objects.ingame.tiles import Tiles
from gamedata.objects.ingame.clouds import Clouds
class Manager(BaseObject):
def __init__(self,game):
@ -12,7 +13,7 @@ class Manager(BaseObject):
self.speedmargin = 7
self.stepmargin = 2
self.spawntimer = game.lib.Timer(self.basetime) # Time elapsing each lemming spawn
self.deathtimer = game.lib.Timer(1) # Time betwin each life loss
self.deathtimer = game.lib.Timer(1) # Time between each life loss
self.started = False
self.invincible = False
self.scoreratio = 0.2 # Points earned per seconds and per lemming
@ -21,6 +22,12 @@ class Manager(BaseObject):
self.endrect = game.pygame.Surface((game.DISPLAY_WIDTH,game.DISPLAY_HEIGHT))
self.endrect.fill([0]*3)
# 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)
# Summon the tiles
self.tiles = Tiles(288,0,game)
game.gameloop.summon(self.tiles)
@ -59,8 +66,18 @@ class Manager(BaseObject):
def afterdraw(self):
txtsurfacescore = self.game.fontfile.render("Score : "+str(int(self.score)),False,[150,255,150])
txtsurfacelives = self.game.fontfile.render("Lives : "+str(int(max(0,self.lives))),False,[255,150,150])
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])
self.game.realwindow.blit(txtsurfacescore,[20,20])
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()])
self.game.realwindow.blit(txtsurfacelives,[20,20*2+txtsurfacescore.get_height()])
self.endrect.set_alpha((1-self.endtimer.getratio())*255)