2024-03-04 13:41:01 +08:00
|
|
|
|
2024-03-05 11:40:42 +08:00
|
|
|
#include "app.h"
|
2024-03-08 14:51:29 +08:00
|
|
|
#include "camera.h"
|
2024-03-05 11:40:42 +08:00
|
|
|
#include "entity.h"
|
2024-04-22 05:11:11 +08:00
|
|
|
#include "gametime.h"
|
2024-03-05 11:40:42 +08:00
|
|
|
#include "input.h"
|
2024-03-26 12:17:21 +08:00
|
|
|
#include "particle.h"
|
2024-03-05 11:40:42 +08:00
|
|
|
#include "physics.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "types.h"
|
2024-03-28 14:04:43 +08:00
|
|
|
#include "render_bundle.h"
|
2024-03-30 22:05:49 +08:00
|
|
|
#include "render_component.h"
|
|
|
|
#include "mapper_misc.h"
|
2024-03-04 13:41:01 +08:00
|
|
|
#include <stdlib.h>
|
2024-03-04 16:13:43 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
2024-03-04 13:41:01 +08:00
|
|
|
App *app_NewApp() {
|
2024-03-28 14:04:43 +08:00
|
|
|
render_LoadBundle("bundles.txt");
|
|
|
|
|
2024-04-02 15:42:04 +08:00
|
|
|
App *app = zero_malloc(sizeof(App));
|
2024-03-04 13:41:01 +08:00
|
|
|
|
2024-03-26 12:17:21 +08:00
|
|
|
app->input = input_NewSystem(app);
|
|
|
|
app->physics = physics_NewSystem(app);
|
|
|
|
app->player = player_NewSystem(app);
|
|
|
|
app->entity = entity_NewSystem(app);
|
|
|
|
app->camera = camera_NewSystem(app);
|
|
|
|
app->particle = particle_NewSystem(app);
|
2024-04-22 05:11:11 +08:00
|
|
|
app->time = gametime_NewSystem(app);
|
2024-03-04 13:41:01 +08:00
|
|
|
|
2024-04-02 15:42:04 +08:00
|
|
|
app->switch_level = NULL;
|
2024-04-15 16:21:24 +08:00
|
|
|
app->clear_color = 0;
|
2024-04-02 15:42:04 +08:00
|
|
|
app->wantQuit = false;
|
2024-04-22 05:28:50 +08:00
|
|
|
app->paused = false;
|
2024-03-04 15:05:21 +08:00
|
|
|
|
2024-03-04 16:13:43 +08:00
|
|
|
|
|
|
|
Entity *player = entity_Create(app->entity, "player");
|
2024-03-05 11:55:26 +08:00
|
|
|
ADD_COMPONENT(player, player);
|
|
|
|
ADD_COMPONENT(player, position);
|
2024-03-04 16:13:43 +08:00
|
|
|
player->position->position = vec2(500, 500);
|
|
|
|
player->position->velocity = vec2(0, 0);
|
2024-03-05 11:55:26 +08:00
|
|
|
ADD_COMPONENT(player, hitbox);
|
2024-03-04 16:13:43 +08:00
|
|
|
player->hitbox->box.lefttop = vec2(-20, -80);
|
2024-04-14 15:08:24 +08:00
|
|
|
|
|
|
|
app_QueueLoadLevel(app, "intro.txt");
|
|
|
|
_app_SwitchLevel(app);
|
2024-04-02 08:56:35 +08:00
|
|
|
|
2024-03-04 13:41:01 +08:00
|
|
|
return app;
|
|
|
|
}
|
|
|
|
|
|
|
|
void app_DeleteApp(App *app) {
|
|
|
|
input_DeleteSystem(app->input);
|
2024-03-04 14:20:50 +08:00
|
|
|
entity_DeleteSystem(app->entity);
|
2024-03-04 13:41:01 +08:00
|
|
|
physics_DeleteSystem(app->physics);
|
|
|
|
player_DeleteSystem(app->player);
|
2024-03-08 14:51:29 +08:00
|
|
|
camera_DeleteSystem(app->camera);
|
2024-04-22 05:11:11 +08:00
|
|
|
particle_DeleteSystem(app->particle);
|
|
|
|
gametime_DeleteSystem(app->time);
|
2024-03-04 13:41:01 +08:00
|
|
|
|
|
|
|
free(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void app_Advance(App *app, Duration deltaTime) {
|
2024-04-02 15:42:04 +08:00
|
|
|
// Limit deltaTime to 20ms (1/50 second)
|
|
|
|
if (deltaTime.microseconds > 20000)
|
|
|
|
deltaTime.microseconds = 20000;
|
|
|
|
|
|
|
|
if (app->switch_level != NULL)
|
|
|
|
_app_SwitchLevel(app);
|
|
|
|
|
2024-03-04 13:41:01 +08:00
|
|
|
input_Advance(app->input);
|
2024-04-22 05:28:50 +08:00
|
|
|
|
|
|
|
if (!app->paused) {
|
|
|
|
gametime_Advance(app->time, deltaTime);
|
|
|
|
particle_Advance(app->particle, deltaTime);
|
|
|
|
player_Advance(app->player, deltaTime);
|
|
|
|
physics_Advance(app->physics, deltaTime);
|
|
|
|
entity_Advance(app->entity, deltaTime);
|
|
|
|
camera_Advance(app->camera, deltaTime);
|
|
|
|
}
|
2024-03-04 13:41:01 +08:00
|
|
|
}
|