Add Game as singleton

This commit is contained in:
2023-11-15 08:18:56 +01:00
parent 274612b035
commit d37936ce7f
6 changed files with 55 additions and 27 deletions

View File

@@ -7,13 +7,14 @@
void updateAnimations(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
Animation *anim = ecs_field(it, Animation, 1);
TextureRegion *t = ecs_field(it, TextureRegion, 2);
float dt = GetFrameTime();
for (i32 i = 0; i < it->count; i++) {
anim[i].frameDuration = GAME->frameDuration;
anim[i].frameDuration = game->frameDuration;
anim[i].elapsed += dt;
if (anim[i].elapsed < anim[i].frameDuration) continue;
@@ -66,7 +67,7 @@ void updatePos(ecs_iter_t *it) {
void targetFinish(ecs_iter_t *it) {
for (i32 i = 0; i < it->count; i++) {
ecs_entity_t e = it->entities[i];
Path *path = ecs_get(it->world, e, Path);
Path *path = ecs_get_mut(it->world, e, Path);
if (!path) continue;
path->curWaypoint++;
if (path->curWaypoint >= path->numWaypoints) {

View File

@@ -3,10 +3,11 @@
#include "../game_state.h"
void uiTask(ecs_iter_t *it) {
const Game *game = ecs_singleton_get(ECS, Game);
Vector2 mousePos = GetMousePosition();
Vector2 worldPos = GetScreenToWorld2D(mousePos, GAME->camera);
Vector2 worldPos = GetScreenToWorld2D(mousePos, game->camera);
BzTileMap *map = &GAME->map;
const BzTileMap *map = &game->map;
i32 tileX = (i32) worldPos.x / map->tileWidth;
i32 tileY = (i32) worldPos.y / map->tileHeight;