2024-03-04 14:20:50 +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-04-15 16:21:24 +08:00
|
|
|
#include "mapper_misc.h"
|
2024-03-26 12:17:21 +08:00
|
|
|
#include "particle.h"
|
2024-03-05 11:40:42 +08:00
|
|
|
#include "physics.h"
|
2024-03-04 16:13:43 +08:00
|
|
|
#include "easyx.h"
|
2024-03-30 18:55:43 +08:00
|
|
|
#include "render_bundle.h"
|
2024-03-30 22:05:49 +08:00
|
|
|
#include "render_component.h"
|
2024-03-04 16:13:43 +08:00
|
|
|
#include "util/tree.h"
|
2024-03-19 15:14:23 +08:00
|
|
|
#include "types.h"
|
|
|
|
#include "render_util.h"
|
2024-03-04 16:13:43 +08:00
|
|
|
#include <math.h>
|
2024-03-04 14:20:50 +08:00
|
|
|
#include <graphics.h>
|
|
|
|
|
|
|
|
|
2024-03-19 15:14:23 +08:00
|
|
|
namespace {
|
|
|
|
TimePoint since = time_Now();
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
2024-03-04 15:05:21 +08:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
2024-03-04 16:13:43 +08:00
|
|
|
void app_Render(App *app) {
|
2024-03-30 21:25:39 +08:00
|
|
|
render_SetModes(render_ModeDefault, time_Now());
|
|
|
|
|
2024-03-04 16:13:43 +08:00
|
|
|
for (tree_Node *i = tree_FirstNode(app->entity->entities);
|
|
|
|
i != NULL;
|
|
|
|
i = tree_Node_Next(i)) {
|
|
|
|
Entity *e = (Entity *)(i->data);
|
|
|
|
if (e->hitbox) {
|
|
|
|
if (e->hitbox->fixed)
|
|
|
|
setlinecolor(RGB(0, 255, 0));
|
|
|
|
else
|
|
|
|
setlinecolor(RGB(255, 255, 0));
|
|
|
|
|
2024-03-08 14:51:29 +08:00
|
|
|
Box2 box = camera_TransformBox2(app->camera, physics_HitboxAbsolute(e->hitbox));
|
2024-03-04 16:13:43 +08:00
|
|
|
rectangle(
|
|
|
|
(int)round(box.lefttop.x),
|
|
|
|
(int)round(box.lefttop.y),
|
|
|
|
(int)round(box.lefttop.x + box.size.x),
|
|
|
|
(int)round(box.lefttop.y + box.size.y));
|
|
|
|
}
|
2024-03-30 21:25:39 +08:00
|
|
|
if (e->misc) {
|
2024-04-02 15:56:49 +08:00
|
|
|
if (e->misc->textbox)
|
2024-03-30 21:25:39 +08:00
|
|
|
setlinecolor(RGB(0, 0, 255));
|
2024-04-02 15:56:49 +08:00
|
|
|
if (e->misc->respawn_pos) {
|
2024-03-30 22:41:49 +08:00
|
|
|
setlinecolor(RGB(255, 0, 255));
|
|
|
|
Vec2 pos;
|
2024-04-02 15:56:49 +08:00
|
|
|
if (e->position)
|
|
|
|
pos = camera_TransformVec2(app->camera, vec2_Add(*e->misc->respawn_pos, e->position->position));
|
|
|
|
else
|
|
|
|
pos = camera_TransformVec2(app->camera, *e->misc->respawn_pos);
|
2024-03-30 22:41:49 +08:00
|
|
|
line((int)round(pos.x + 12), (int)round(pos.y), (int)round(pos.x - 12), (int)round(pos.y));
|
|
|
|
line((int)round(pos.x), (int)round(pos.y + 12), (int)round(pos.x), (int)round(pos.y - 12));
|
|
|
|
}
|
2024-04-02 15:56:49 +08:00
|
|
|
if (e->misc->trigger_flags & misc_Hazard)
|
2024-04-02 08:56:35 +08:00
|
|
|
setlinecolor(RGB(255, 0, 0));
|
2024-04-15 16:21:24 +08:00
|
|
|
if (e->misc->trigger_flags & misc_CameraFocus)
|
|
|
|
setlinecolor(RGB(0, 255, 255));
|
2024-04-14 15:22:55 +08:00
|
|
|
if (e->misc->change_level)
|
|
|
|
setlinecolor(RGB(255, 255, 0));
|
2024-04-02 15:56:49 +08:00
|
|
|
Box2 box;
|
|
|
|
if (e->position)
|
|
|
|
box = camera_TransformBox2(app->camera, box2_Offset(e->misc->trigger, e->position->position));
|
|
|
|
else
|
|
|
|
box = camera_TransformBox2(app->camera, e->misc->trigger);
|
|
|
|
rectangle(
|
|
|
|
(int)round(box.lefttop.x),
|
|
|
|
(int)round(box.lefttop.y),
|
|
|
|
(int)round(box.lefttop.x + box.size.x),
|
|
|
|
(int)round(box.lefttop.y + box.size.y));
|
2024-03-30 21:25:39 +08:00
|
|
|
}
|
2024-03-04 16:13:43 +08:00
|
|
|
}
|
2024-04-02 15:04:05 +08:00
|
|
|
if (app->player->player) {
|
|
|
|
setlinecolor(RGB(255, 0, 255));
|
|
|
|
Vec2 respawn = camera_TransformVec2(app->camera, app->player->player->hazardRespawn);
|
|
|
|
circle((int)round(respawn.x), (int)round(respawn.y), 6);
|
|
|
|
}
|
2024-03-19 15:14:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
setfillcolor(RGB(255, 255, 255));
|
|
|
|
setbkcolor(RGB(0, 0, 0));
|
2024-03-30 22:45:12 +08:00
|
|
|
render_SetModes(render_ModeRotate, since);
|
2024-03-19 15:14:23 +08:00
|
|
|
render_FillCircleW(app, vec2(200, 100), 20);
|
2024-03-26 12:17:21 +08:00
|
|
|
|
2024-03-30 18:55:43 +08:00
|
|
|
|
2024-03-30 22:05:49 +08:00
|
|
|
// Draw entities
|
|
|
|
for (tree_Node *i = tree_FirstNode(app->entity->entities);
|
|
|
|
i != NULL;
|
|
|
|
i = tree_Node_Next(i)) {
|
|
|
|
Entity *e = (Entity *)i->data;
|
|
|
|
if (e->render) {
|
|
|
|
Component_Render *r = e->render;
|
|
|
|
|
|
|
|
// Calculate global position as offset
|
|
|
|
Vec2 pos = {.x = 0.0, .y = 0.0};
|
|
|
|
if (e->position)
|
|
|
|
pos = e->position->position;
|
2024-04-15 16:21:24 +08:00
|
|
|
// Has fillbox
|
|
|
|
if (r->fillbox.size.x > EPS) {
|
|
|
|
Box2 cam = camera_TransformBox2(app->camera, r->fillbox);
|
|
|
|
setfillcolor(r->fillcolor);
|
|
|
|
fillrectangle(
|
|
|
|
(int)round(cam.lefttop.x),
|
|
|
|
(int)round(cam.lefttop.y),
|
|
|
|
(int)round(cam.lefttop.x + cam.size.x),
|
|
|
|
(int)round(cam.lefttop.y + cam.size.y));
|
|
|
|
}
|
2024-03-30 22:05:49 +08:00
|
|
|
// Has bundle
|
|
|
|
if (r->bundle)
|
|
|
|
render_DrawBundleW(app, r->bundle, pos);
|
|
|
|
// Has custom rendering
|
|
|
|
if (r->custom)
|
|
|
|
r->custom(app, e, camera_TransformVec2(app->camera, pos), r->custom_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-30 18:55:43 +08:00
|
|
|
|
2024-03-26 12:17:21 +08:00
|
|
|
// Draw particles
|
2024-03-30 18:55:43 +08:00
|
|
|
setfillcolor(RGB(255, 255, 255));
|
|
|
|
setbkcolor(RGB(0, 0, 0));
|
2024-03-26 12:17:21 +08:00
|
|
|
particle_Render(app->particle);
|
2024-03-30 22:05:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
settextcolor(RGB(255, 255, 255));
|
2024-03-04 14:20:50 +08:00
|
|
|
}
|
2024-03-04 15:05:21 +08:00
|
|
|
}
|