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"
|
|
|
|
#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-03-04 13:41:01 +08:00
|
|
|
App *app = malloc(sizeof(App));
|
|
|
|
|
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-03-04 13:41:01 +08:00
|
|
|
|
2024-03-04 15:05:21 +08:00
|
|
|
app->wantQuit = false;
|
|
|
|
|
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);
|
|
|
|
player->hitbox->box.size = vec2(40, 80);
|
|
|
|
entity_Commit(app->entity, player);
|
|
|
|
|
|
|
|
Entity *hit1 = entity_Create(app->entity, "hit1");
|
2024-03-05 11:55:26 +08:00
|
|
|
ADD_COMPONENT(hit1, hitbox);
|
2024-03-04 16:13:43 +08:00
|
|
|
hit1->hitbox->box.lefttop = vec2(200, 200);
|
|
|
|
hit1->hitbox->box.size = vec2(100, 400);
|
|
|
|
hit1->hitbox->fixed = true;
|
|
|
|
entity_Commit(app->entity, hit1);
|
|
|
|
|
|
|
|
Entity *hit2 = entity_Create(app->entity, "hit2");
|
2024-03-05 11:55:26 +08:00
|
|
|
ADD_COMPONENT(hit2, hitbox);
|
2024-03-04 16:13:43 +08:00
|
|
|
hit2->hitbox->box.lefttop = vec2(700, 200);
|
|
|
|
hit2->hitbox->box.size = vec2(100, 400);
|
|
|
|
hit2->hitbox->fixed = true;
|
|
|
|
entity_Commit(app->entity, hit2);
|
|
|
|
|
2024-03-05 10:42:17 +08:00
|
|
|
Entity *hit3 = entity_Create(app->entity, "hit3");
|
2024-03-05 11:55:26 +08:00
|
|
|
ADD_COMPONENT(hit3, hitbox);
|
2024-03-05 10:42:17 +08:00
|
|
|
hit3->hitbox->box.lefttop = vec2(100, 550);
|
|
|
|
hit3->hitbox->box.size = vec2(800, 30);
|
|
|
|
hit3->hitbox->fixed = true;
|
|
|
|
entity_Commit(app->entity, hit3);
|
|
|
|
|
2024-03-30 22:05:49 +08:00
|
|
|
Entity *text1 = entity_Create(app->entity, "text_plate_large_1");
|
|
|
|
ADD_COMPONENT(text1, position);
|
|
|
|
text1->position->position = vec2(600, 550);
|
|
|
|
text1->render = render_NewComponent(app, "info_plate");
|
|
|
|
misc_InstantiateTextbox(app, text1, "So long lives this,\nAnd this gives life to thee.", misc_TextboxUpright(110, 110), -220);
|
|
|
|
entity_Commit(app->entity, text1);
|
|
|
|
|
|
|
|
Entity *text2 = entity_Create(app->entity, "text_plate_1");
|
|
|
|
ADD_COMPONENT(text2, position);
|
|
|
|
text2->position->position = vec2(250, 200);
|
|
|
|
text2->render = render_NewComponent(app, "info_plate_small_1");
|
|
|
|
misc_InstantiateTextbox(app, text2, "Press Space to jump.\nYou can jump again midair.", misc_TextboxUpright(70, 70), -180);
|
|
|
|
entity_Commit(app->entity, text2);
|
|
|
|
|
|
|
|
Entity *text3 = entity_Create(app->entity, "text_plate_2");
|
|
|
|
ADD_COMPONENT(text3, position);
|
|
|
|
text3->position->position = vec2(750, 200);
|
|
|
|
text3->render = render_NewComponent(app, "info_plate_small_2");
|
|
|
|
misc_InstantiateTextbox(app, text3, "Press ; to dash.\nYou can only dash one time midair.", misc_TextboxUpright(70, 70), -180);
|
|
|
|
entity_Commit(app->entity, text3);
|
|
|
|
|
2024-03-30 22:41:49 +08:00
|
|
|
Entity *respawn1 = entity_Create(app->entity, "respawn1");
|
|
|
|
misc_InstantiateHazardRespawn(app, respawn1, box2(300, 500, 400, 50), vec2(500, 550));
|
|
|
|
entity_Commit(app->entity, respawn1);
|
|
|
|
|
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-03-04 13:41:01 +08:00
|
|
|
|
|
|
|
free(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void app_Advance(App *app, Duration deltaTime) {
|
2024-03-26 12:17:21 +08:00
|
|
|
particle_Advance(app->particle, deltaTime);
|
2024-03-04 13:41:01 +08:00
|
|
|
input_Advance(app->input);
|
|
|
|
player_Advance(app->player, deltaTime);
|
|
|
|
physics_Advance(app->physics, deltaTime);
|
2024-03-04 14:20:50 +08:00
|
|
|
entity_Advance(app->entity, deltaTime);
|
2024-03-08 14:51:29 +08:00
|
|
|
camera_Advance(app->camera, deltaTime);
|
2024-03-04 13:41:01 +08:00
|
|
|
}
|