Created the main file and integrated the engine into it.
This commit is contained in:
parent
9b1d91934b
commit
85a9518faf
9 changed files with 91 additions and 60 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"Bla": {
|
||||
"path": "../assets/stacked_sprites/animated/bla/",
|
||||
"path": "assets/stacked_sprites/animated/bla/",
|
||||
"layers": 3,
|
||||
"scale": 16
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
{
|
||||
"Robot": {
|
||||
"path": "../assets/stacked_sprites/Robot.png",
|
||||
"path": "assets/stacked_sprites/Robot.png",
|
||||
"layers": 16,
|
||||
"scale": 8
|
||||
},
|
||||
"Building": {
|
||||
"path": "../assets/stacked_sprites/Building.png",
|
||||
"path": "assets/stacked_sprites/Building.png",
|
||||
"layers": 80,
|
||||
"scale": 4
|
||||
}
|
||||
|
|
44
moss.py
Normal file
44
moss.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import pygame
|
||||
from wobbl_tools import pg
|
||||
from sprite_stacking_engine.engine import Engine
|
||||
|
||||
|
||||
class Moss:
|
||||
def __init__(self):
|
||||
self.screen = pygame.display.set_mode((1400, 800))
|
||||
self.clock = pygame.time.Clock()
|
||||
self.engine = Engine(self)
|
||||
self.time = 0
|
||||
self.delta_time = 0.01
|
||||
|
||||
self.running = True
|
||||
|
||||
def update(self):
|
||||
pygame.display.set_caption(f"{self.clock.get_fps(): .1f}")
|
||||
self.delta_time = self.clock.tick(60)
|
||||
self.engine.update()
|
||||
|
||||
def draw(self):
|
||||
self.engine.draw()
|
||||
|
||||
self.screen.blit(self.engine.surface, (0, 0))
|
||||
|
||||
pygame.display.flip()
|
||||
|
||||
def get_time(self):
|
||||
self.time = pygame.time.get_ticks() * 0.001
|
||||
|
||||
def tick(self):
|
||||
self.engine.check_events()
|
||||
self.get_time()
|
||||
self.update()
|
||||
self.draw()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
game = Moss()
|
||||
|
||||
while game.running:
|
||||
game.tick()
|
|
@ -1,8 +1,7 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
from random import randrange
|
||||
from settings import *
|
||||
from sprite_stacking_engine.settings import *
|
||||
|
||||
|
||||
class Cache:
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
from settings import *
|
||||
from stacked_sprite import StackedSprite
|
||||
from cache import Cache
|
||||
from player import Player
|
||||
from scene import Scene
|
||||
from sprite_stacking_engine.settings import *
|
||||
from sprite_stacking_engine.cache import Cache
|
||||
from sprite_stacking_engine.player import Player
|
||||
from sprite_stacking_engine.scene import Scene
|
||||
|
||||
|
||||
class App:
|
||||
def __init__(self):
|
||||
self.screen = pygame.display.set_mode(RES)
|
||||
self.clock = pygame.time.Clock()
|
||||
self.time = 0
|
||||
self.delta_time = 0.01
|
||||
class Engine:
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.surface = pygame.Surface(self.app.screen.get_size()) # surface to draw the sprites on
|
||||
# groups
|
||||
self.main_group = pygame.sprite.LayeredUpdates()
|
||||
# game objects
|
||||
|
@ -23,13 +20,10 @@ class App:
|
|||
|
||||
def update(self):
|
||||
self.main_group.update()
|
||||
pygame.display.set_caption(f"{self.clock.get_fps(): .1f}")
|
||||
self.delta_time = self.clock.tick(60)
|
||||
|
||||
def draw(self):
|
||||
self.screen.fill(BG_COLOR)
|
||||
self.main_group.draw(self.screen)
|
||||
pygame.display.flip()
|
||||
self.surface.fill(BG_COLOR)
|
||||
self.main_group.draw(self.surface)
|
||||
|
||||
def check_events(self):
|
||||
for event in pygame.event.get():
|
||||
|
@ -37,17 +31,7 @@ class App:
|
|||
pygame.quit()
|
||||
sys.exit()
|
||||
|
||||
def get_time(self):
|
||||
self.time = pygame.time.get_ticks() * 0.001
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
def tick(self):
|
||||
self.check_events()
|
||||
self.get_time()
|
||||
self.update()
|
||||
self.draw()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = App()
|
||||
app.run()
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from settings import *
|
||||
from sprite_stacking_engine.settings import *
|
||||
import math
|
||||
|
||||
|
||||
class Player(pygame.sprite.Sprite):
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.group = app.main_group
|
||||
def __init__(self, engine):
|
||||
self.engine = engine
|
||||
self.app = engine.app
|
||||
self.group = self.engine.main_group
|
||||
super().__init__(self.group)
|
||||
|
||||
self.group.change_layer(self, CENTER.y) # simpy set the layer to the y center of the screen because that is -
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from stacked_sprite import *
|
||||
from sprite_stacking_engine.stacked_sprite import *
|
||||
from random import uniform
|
||||
|
||||
P = "player"
|
||||
|
@ -23,8 +23,9 @@ MAP_CENTER = MAP_SIZE / 2
|
|||
|
||||
|
||||
class Scene:
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
def __init__(self, engine):
|
||||
self.engine = engine
|
||||
self.app = engine.app
|
||||
self.load_scene()
|
||||
|
||||
def load_scene(self):
|
||||
|
@ -36,11 +37,11 @@ class Scene:
|
|||
pos = vec2(i, j) + vec2(0.5)
|
||||
|
||||
if name == "player":
|
||||
self.app.player.offset = pos * TILE_SIZE
|
||||
self.engine.player.offset = pos * TILE_SIZE
|
||||
|
||||
elif name:
|
||||
if name == "Bla":
|
||||
AnimatedStackedSprite(self.app, name=name, pos=rand_pos(pos), rot=rand_rot())
|
||||
AnimatedStackedSprite(self.engine, name=name, pos=rand_pos(pos), rot=rand_rot())
|
||||
|
||||
else:
|
||||
StackedSprite(self.app, name=name, pos=rand_pos(pos), rot=rand_rot())
|
||||
StackedSprite(self.engine, name=name, pos=rand_pos(pos), rot=rand_rot())
|
||||
|
|
|
@ -27,8 +27,8 @@ NUM_ANGLES = 180 # multiple of 360
|
|||
TRANSP_COLOR = (45, 54, 76)
|
||||
OUTLINE = True
|
||||
|
||||
SPRITE_ATTRS = load_json("../assets/stacked_sprites/sprite_properties.json")
|
||||
ANIMATED_SPRITE_ATTRS = load_json("../assets/stacked_sprites/animated/sprite_properties.json")
|
||||
SPRITE_ATTRS = load_json("assets/stacked_sprites/sprite_properties.json")
|
||||
ANIMATED_SPRITE_ATTRS = load_json("assets/stacked_sprites/animated/sprite_properties.json")
|
||||
|
||||
# SPRITE_ATTRS = {
|
||||
# "Robot": {
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
#!/usr/bin/python3
|
||||
import pygame
|
||||
|
||||
from settings import *
|
||||
from sprite_stacking_engine.settings import *
|
||||
import math
|
||||
|
||||
|
||||
class StackedSprite(pygame.sprite.Sprite):
|
||||
def __init__(self, app, name, pos, rot=0):
|
||||
self.app = app
|
||||
def __init__(self, engine, name, pos, rot=0):
|
||||
self.engine = engine
|
||||
self.app = engine.app
|
||||
self.name = name
|
||||
self.pos = vec2(pos) * TILE_SIZE
|
||||
self.player = self.app.player
|
||||
self.group = self.app.main_group
|
||||
self.player = engine.player
|
||||
self.group = engine.main_group
|
||||
super().__init__(self.group)
|
||||
|
||||
self.attrs = SPRITE_ATTRS[name] # get attributes
|
||||
|
@ -21,8 +22,8 @@ class StackedSprite(pygame.sprite.Sprite):
|
|||
|
||||
self.y_offset = vec2(0, -self.attrs["layers"] / 2 * self.attrs["scale"]) # calculate the y offset because the -
|
||||
# images position in pygame is the position of the top left corner of the image and we use the bottom position
|
||||
self.cache = self.app.cache.stacked_sprite_cache
|
||||
self.viewing_angle = app.cache.viewing_angle
|
||||
self.cache = engine.cache.stacked_sprite_cache
|
||||
self.viewing_angle = engine.cache.viewing_angle
|
||||
self.rotated_sprites = self.cache[name]["rotated_sprites"]
|
||||
self.angle = 0
|
||||
self.screen_position = vec2(0)
|
||||
|
@ -52,12 +53,13 @@ class StackedSprite(pygame.sprite.Sprite):
|
|||
|
||||
|
||||
class AnimatedStackedSprite(pygame.sprite.Sprite): # stacked sprite class for animated sprites, works nearly the same
|
||||
def __init__(self, app, name, pos, rot=0):
|
||||
self.app = app
|
||||
def __init__(self, engine, name, pos, rot=0):
|
||||
self.engine = engine
|
||||
self.app = engine.app
|
||||
self.name = name
|
||||
self.pos = vec2(pos) * TILE_SIZE
|
||||
self.player = self.app.player
|
||||
self.group = self.app.main_group
|
||||
self.player = engine.player
|
||||
self.group = engine.main_group
|
||||
super().__init__(self.group)
|
||||
|
||||
self.attrs = ANIMATED_SPRITE_ATTRS[name]
|
||||
|
@ -67,8 +69,8 @@ class AnimatedStackedSprite(pygame.sprite.Sprite): # stacked sprite class for a
|
|||
|
||||
self.attrs["animated"] = True # set the animated attribute to true so that the cache knows that this sprite -
|
||||
self.y_offset = vec2(0, -self.attrs["layers"] / 2 * self.attrs["scale"]) # is animated
|
||||
self.cache = self.app.cache.stacked_sprite_cache
|
||||
self.viewing_angle = app.cache.viewing_angle
|
||||
self.cache = engine.cache.stacked_sprite_cache
|
||||
self.viewing_angle = engine.cache.viewing_angle
|
||||
self.frame = list(self.cache[name]["frames"].keys())[0] # set the frame to the first frame
|
||||
self.rotated_sprites = self.cache[name]["frames"][self.frame]["rotated_sprites"]
|
||||
self.angle = 0
|
||||
|
|
Loading…
Reference in a new issue