2024-07-18 10:53:51 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
2024-07-19 18:24:45 +02:00
|
|
|
from sprite_stacking_engine.stacked_sprite import *
|
2024-07-18 10:53:51 +02:00
|
|
|
from random import uniform
|
|
|
|
|
|
|
|
P = "player"
|
2024-07-18 17:21:05 +02:00
|
|
|
A, B, C = "Robot", "Building", "Bla"
|
2024-07-18 10:53:51 +02:00
|
|
|
|
2024-07-19 13:38:42 +02:00
|
|
|
MAP = [ # two dimensional object matrix
|
2024-07-18 10:53:51 +02:00
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
[0, 0, 0, 0, 0, B, B, B, B],
|
|
|
|
[0, 0, A, A, 0, B, B, B, B],
|
|
|
|
[0, 0, A, A, P, B, B, B, B],
|
|
|
|
[0, 0, A, A, 0, B, B, B, B],
|
2024-07-18 17:21:05 +02:00
|
|
|
[0, 0, 0, 0, C, B, B, B, B],
|
2024-07-18 10:53:51 +02:00
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
[0, 0, 0, 0, 0, 0, 0, 0, 0],
|
|
|
|
]
|
|
|
|
|
|
|
|
MAP_SIZE = MAP_WIDTH, MAP_HEIGHT = vec2(len(MAP), len(MAP[0]))
|
|
|
|
MAP_CENTER = MAP_SIZE / 2
|
|
|
|
|
|
|
|
|
|
|
|
class Scene:
|
2024-07-19 18:24:45 +02:00
|
|
|
def __init__(self, engine):
|
|
|
|
self.engine = engine
|
|
|
|
self.app = engine.app
|
2024-07-18 10:53:51 +02:00
|
|
|
self.load_scene()
|
|
|
|
|
|
|
|
def load_scene(self):
|
|
|
|
rand_rot = lambda: uniform(0, 360)
|
|
|
|
rand_pos = lambda pos: pos + vec2(uniform(-0.25, 0.25))
|
|
|
|
|
2024-07-19 13:38:42 +02:00
|
|
|
for j, row in enumerate(MAP): # loop through all objects on the map
|
2024-07-18 10:53:51 +02:00
|
|
|
for i, name in enumerate(row):
|
|
|
|
pos = vec2(i, j) + vec2(0.5)
|
|
|
|
|
|
|
|
if name == "player":
|
2024-07-19 18:24:45 +02:00
|
|
|
self.engine.player.offset = pos * TILE_SIZE
|
2024-07-18 10:53:51 +02:00
|
|
|
|
|
|
|
elif name:
|
2024-07-18 17:21:05 +02:00
|
|
|
if name == "Bla":
|
2024-07-19 18:24:45 +02:00
|
|
|
AnimatedStackedSprite(self.engine, name=name, pos=rand_pos(pos), rot=rand_rot())
|
2024-07-18 17:21:05 +02:00
|
|
|
|
|
|
|
else:
|
2024-07-19 18:24:45 +02:00
|
|
|
StackedSprite(self.engine, name=name, pos=rand_pos(pos), rot=rand_rot())
|