Added day cycle

This commit is contained in:
theo@manjaro 2021-09-15 13:48:58 +02:00
parent 2ca249f666
commit b5f893b51e
6 changed files with 51 additions and 0 deletions

View File

@ -13,3 +13,7 @@ All the textures are edited by myself to fit the [Famicube palette](https://losp
## Clouds
[Jetrel - OpenGameArt](https://opengameart.org/content/old-frogatto-clouds)
## Sky gradients
[rh0 - OpenGameArt](https://opengameart.org/content/18-gradient-skies-640x480)

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

View File

@ -2,6 +2,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
from gamedata.objects.ingame.skies import Skies
class Manager(BaseObject):
def __init__(self,game):
@ -22,6 +23,9 @@ class Manager(BaseObject):
self.endrect = game.pygame.Surface((game.DISPLAY_WIDTH,game.DISPLAY_HEIGHT))
self.endrect.fill([0]*3)
# Sky gradients
self.game.gameloop.summon(Skies(game))
# 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")

View File

@ -0,0 +1,43 @@
from gamedata.objects.base import BaseObject
import math
class Skies(BaseObject):
def __init__(self,game,basesky="skies/base.png",nightsky="skies/night.png",daysky="skies/day.png"):
super().__init__(0,0,game,game.DISPLAY_WIDTH,game.DISPLAY_HEIGHT)
size = [game.DISPLAY_WIDTH,game.DISPLAY_HEIGHT]
self.basesky = game.pygame.transform.scale(game.sprite_lib[basesky],size)
self.nightsky = game.pygame.transform.scale(game.sprite_lib[nightsky],size)
self.daysky = game.pygame.transform.scale(game.sprite_lib[daysky],size)
self.blackrect = game.pygame.Surface(size)
self.blackrect.fill([0]*3)
self.speed = 0.02
self.timeelapsed = 0
self.depth = -2
self.blackrectalpha = 0.5
def step(self):
self.timeelapsed+=self.game.dt
self.cosvalue = math.cos(self.timeelapsed*self.speed)
def draw(self):
self.game.window.blit(self.basesky,[0,0])
if self.cosvalue<0:
self.nightsky.set_alpha(-self.cosvalue*255)
self.game.window.blit(self.nightsky,[0,0])
else:
self.daysky.set_alpha(self.cosvalue*255)
self.game.window.blit(self.daysky,[0,0])
def afterdraw(self):
if self.cosvalue<0:
self.blackrect.set_alpha(-self.cosvalue*255*self.blackrectalpha)
self.game.realwindow.blit(self.blackrect,[0,0])