Simple overworld

This commit is contained in:
theo@manjaro 2021-11-22 22:14:09 +01:00
parent 510c5240b9
commit b0212e98b3
19 changed files with 1699 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 810 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 813 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 861 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 805 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 821 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 862 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 808 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 796 B

View File

@ -89,10 +89,12 @@ class Game():
self.globals = {} # Un dico pour ranger toute les valeurs globales, pour communiquer entre objets par exemples self.globals = {} # Un dico pour ranger toute les valeurs globales, pour communiquer entre objets par exemples
self.globals["camerax"] = 0 self.globals["camerax"] = 0
self.globals["cameray"] = 0 self.globals["cameray"] = 0
self.globals["scamerax"] = 3 self.globals["scamerax"] = 0
self.globals["scameray"] = 0 self.globals["scameray"] = 0
self.globals["players"] = [] self.globals["players"] = []
self.globals["hitpose"] = False self.globals["hitpose"] = False
self.globals["finishedlevels"] = [] # Levels where the player went to the end
self.globals["completedlevels"] = [] # Levels where the player kicked all non-respawnable ennemies
self.scaleCamera() self.scaleCamera()
settings = {"sfx":1,"bgm":1} settings = {"sfx":1,"bgm":1}
@ -104,7 +106,7 @@ class Game():
self.pasttime = time.time() self.pasttime = time.time()
# Je charge la scene de base # Je charge la scene de base
scenes.ingame(self) scenes.overworld(self)
def set_camera(self,posx,posy): def set_camera(self,posx,posy):
self.globals["camerax"], self.globals["cameray"] = posx,posy self.globals["camerax"], self.globals["cameray"] = posx,posy

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -4,6 +4,7 @@ from gamedata.objects.ingame.ennemies.crate import Crate
from gamedata.objects.ingame.ennemies.balloon import Balloon from gamedata.objects.ingame.ennemies.balloon import Balloon
from gamedata.objects.ingame.ennemies.spring import Spring 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.levels import Levels
class TilesetRenderer(BaseObject): class TilesetRenderer(BaseObject):
@ -69,7 +70,7 @@ class TilesetRenderer(BaseObject):
self.layers = [] self.layers = []
self.spawns = [] self.spawns = []
spawnlists = {"Spawns":self.spawns} spawnlists = {"Spawns":self.spawns}
ennemies = {"Robot":Robot,"Crate":Crate,"Balloon":Balloon,"Spring":Spring,"WaterChange":WaterChange} ennemies = {"Robot":Robot,"Crate":Crate,"Balloon":Balloon,"Spring":Spring,"WaterChange":WaterChange,"Levels":Levels}
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

View File

@ -0,0 +1,96 @@
from gamedata.objects.base import BaseObject
class Levels(BaseObject):
def __init__(self,x,y,game,nodes,customvalues):
super().__init__(0,0,game)
self.nodes = nodes
self.customvalues = customvalues
self.blueflags = self.game.getSpriteDir("flags/blue/")
self.greenflags= self.game.getSpriteDir("flags/green/")
self.flagbase = self.game.sprite_lib["flags/base.png"]
self.playerwalking = self.game.getSpriteDir("player/walking/")
self.playerstill = self.game.sprite_lib["player/still.png"]
self.flagsindex = []
self.names = []
self.textnumbers = []
for i,v in enumerate(self.nodes):
v["x"]+=8 # Center on tiles
v["y"]+=8
self.flagsindex.append(self.game.lib.randint(1,3))
# Get sprites for "Level N"
sprites = self.game.getchars("Level "+str(i+1))
text = self.game.pygame.Surface((len(sprites)*9,9),flags=self.game.pygame.SRCALPHA)
for j,s in enumerate(sprites):
if s:
text.blit(s,[j*9,0])
self.textnumbers.append(text)
# Get sprites for the level's name
if str(i) in customvalues.keys():
sprites = self.game.getchars(customvalues[str(i)])
text = self.game.pygame.Surface((len(sprites)*9,9),flags=self.game.pygame.SRCALPHA)
for i,v in enumerate(sprites):
if v:
text.blit(v,[i*9,0])
self.names.append(text)
else:
self.names.append(None)
self.animspeed = 7
self.cursor = 0 # Which level is selected
self.tileset = self.game.gameloop.findname("TilesetRenderer")[0]
self.maxwidth = self.tileset.layers[0]["surface"].get_width()
def step(self):
for i in range(len(self.flagsindex)):
self.flagsindex[i]+=self.animspeed*self.game.dt
if self.game.inputs["keys"]["right"]["timer"]==1:
self.cursor+=1
if self.game.inputs["keys"]["left"]["timer"]==1:
self.cursor-=1
if self.game.inputs["keys"]["up"]["timer"]==1:
# Launch the level
self.game.scenes.ingame(self.game,level="Level "+str(self.cursor+1))
self.cursor = min(self.cursor,len(self.nodes)-1)
self.cursor = max(0,self.cursor)
self.playerx = self.nodes[self.cursor]["x"]
self.game.globals["camerax"] = self.playerx-self.game.globals["cameraw"]/2
self.game.globals["camerax"] = max(0,self.game.globals["camerax"])
self.game.globals["camerax"] = min(self.maxwidth-self.game.globals["cameraw"],self.game.globals["camerax"])
def draw(self):
for i,v in enumerate(self.nodes): # Draw flags
sprites = self.blueflags
sprite = sprites[int(self.flagsindex[i])%len(sprites)]
x = v["x"]-sprite.get_width()/2-self.game.globals["camerax"]+8
y = v["y"]-sprite.get_height()-self.game.globals["cameray"]
self.game.window.blit(self.flagbase,[v["x"]-self.game.globals["camerax"]-8,v["y"]-self.game.globals["cameray"]-2])
self.game.window.blit(sprite,[x,y])
# Draw player
sprite = self.playerstill
x = self.nodes[self.cursor]["x"]-self.game.globals["camerax"]-sprite.get_width()/2
y = self.nodes[self.cursor]["y"]-self.game.globals["cameray"]-sprite.get_height()/2
self.game.window.blit(sprite,[x,y])
# Draw level's number
sprite = self.textnumbers[self.cursor]
x = self.nodes[self.cursor]["x"]-self.game.globals["camerax"]-sprite.get_width()/2
y = self.nodes[self.cursor]["y"]-self.game.globals["cameray"]-sprite.get_height()/2-50
self.game.window.blit(sprite,[x,y])
# Draw the level's name
if self.names[self.cursor]:
sprite = self.names[self.cursor]
x = self.nodes[self.cursor]["x"]-self.game.globals["camerax"]-sprite.get_width()/2
y = self.nodes[self.cursor]["y"]-self.game.globals["cameray"]-sprite.get_height()/2-40
self.game.window.blit(sprite,[x,y])

View File

@ -28,6 +28,12 @@ def ingame(game,level="Level 2"):
p1 = Player(game) p1 = Player(game)
game.gameloop.summon(p1) game.gameloop.summon(p1)
def overworld(game):
game.scaleCamera(416,234)
game.gameloop.reinit()
tileset = TilesetRenderer(0,0,game,"Overworld")
game.gameloop.summon(tileset)
def options(game): def options(game):
game.gameloop.reinit() game.gameloop.reinit()
game.globals["camerax"] = 0 game.globals["camerax"] = 0