Return to repo list

tzed

Simple story-driven open world 2D CRPG.
Return to HMagellan.com

commit 0f9dcfcb095d750fe5cb77e13990011fe934c46b
parent 058bfaba5be555d04f8c47dea9791b01652908d2
Author: Erik Letson <hmagellan@hmagellan.com>
Date:   Sun,  6 Jun 2021 17:28:58 -0500

sheets load

Diffstat:
Rdata/img/enemies.png -> data/img/enemies1.png | 0
Adata/json/anims.json | 0
Adata/json/sheets.json | 20++++++++++++++++++++
Adata/json/sounds.json | 0
Msrc/game.py | 2+-
Msrc/images.py | 12+++++++-----
6 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/data/img/enemies.png b/data/img/enemies1.png Binary files differ. diff --git a/data/json/anims.json b/data/json/anims.json diff --git a/data/json/sheets.json b/data/json/sheets.json @@ -0,0 +1,20 @@ +{ + "tiles1": { + "filename" : "tiles1.png", + "dimensions" : [16, 16], + "anim_class" : null, + "alpha" : false + }, + "chars1" : { + "filename" : "chars1.png", + "dimensions" : [16, 16], + "anim_class" : null, + "alpha" : false + }, + "enemies1": { + "filename" : "enemies1.png", + "dimensions" : [16, 16], + "anim_class" : null, + "alpha" : false + } +} diff --git a/data/json/sounds.json b/data/json/sounds.json diff --git a/src/game.py b/src/game.py @@ -43,7 +43,7 @@ class Game(object): # Setup (This is WIP) #self.sheet_system.load_animations_from_json("anims.json") - #self.sheet_system.load_sheets_from_json("sheets.json") + self.sheet_system.load_sheets_from_json("sheets.json") #self.sound_system.load_sounds_from_json("sounds.json") self.subsystem_bus.update_system_fetch_data() diff --git a/src/images.py b/src/images.py @@ -47,7 +47,7 @@ class SheetSystem(subsystem.GameSubsystem): an = {} if self.sheets_def[j]["anim_class"] != None: an = self.animations[self.sheets_def[j]["anim_class"]] - self.loaded_sheets[j] = Sheet(self, self.sheets_def[j]["filename"], j, tuple(self.sheets_def[j]["dimensions"]), self.sheets_def[j]["total_sprites"], an, self.sheets_def[j]["alpha"]) + self.loaded_sheets[j] = Sheet(self, self.sheets_def[j]["filename"], j, tuple(self.sheets_def[j]["dimensions"]), an, self.sheets_def[j]["alpha"]) def load_animations_from_json(self, anim_json): """ @@ -101,24 +101,23 @@ class Sheet(object): (that is, all sprites are the same dimensions). """ - def __init__(self, manager, filename, name, sprite_size, total_sprites, animations, alpha): + def __init__(self, manager, filename, name, sprite_size, animations, alpha): # Important values self.manager = manager self.filename = filename self.name = name self.sprite_dimensions = sprite_size - self.total_sprites = total_sprites self.sprites = {} self.animations = animations self.alpha = alpha # Try and load all sprites on the sheet, or log if we failed - if not self.load_sheet(filename, sprite_size, total_sprites): + if not self.load_sheet(filename, sprite_size): self.sprites = {} print("Failed to load sheet: " + filename) - def load_sheet(self, filename, sprite_size, total_sprites): + def load_sheet(self, filename, sprite_size): """ Load a sheet and divide it into subsurfaces for use as images by sprite entities. @@ -139,6 +138,9 @@ class Sheet(object): x = 0 y = 0 + # Calculate total sprites + total_sprites = (self.sheet.get_width() // sprite_size[0]) * (self.sheet.get_height() // sprite_size[1]) + # While there are still more sprites to load, load them while len(self.sprites) < total_sprites: