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-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) {
|
|
|
|
if (e->misc->textbox) {
|
|
|
|
setlinecolor(RGB(0, 0, 255));
|
|
|
|
Box2 box = camera_TransformBox2(app->camera, box2_Offset(e->misc->textbox->trigger_box, e->position->position));
|
|
|
|
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 22:41:49 +08:00
|
|
|
if (e->misc->respawn) {
|
|
|
|
setlinecolor(RGB(255, 0, 255));
|
|
|
|
Box2 box;
|
|
|
|
Vec2 pos;
|
|
|
|
if (e->position) {
|
|
|
|
box = camera_TransformBox2(app->camera, box2_Offset(e->misc->respawn->trigger_box, e->position->position));
|
|
|
|
pos = camera_TransformVec2(app->camera, vec2_Add(e->misc->respawn->respawn_pos, e->position->position));
|
|
|
|
} else {
|
|
|
|
box = camera_TransformBox2(app->camera, e->misc->respawn->trigger_box);
|
|
|
|
pos = camera_TransformVec2(app->camera, e->misc->respawn->respawn_pos);
|
|
|
|
}
|
|
|
|
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));
|
|
|
|
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-03-30 21:25:39 +08:00
|
|
|
}
|
2024-03-04 16:13:43 +08:00
|
|
|
}
|
2024-03-19 15:14:23 +08:00
|
|
|
|
|
|
|
static FillMode mode_rotate = {
|
|
|
|
.rotate = Duration{.microseconds = 100 * 1000}};
|
|
|
|
|
|
|
|
|
|
|
|
setfillcolor(RGB(255, 255, 255));
|
|
|
|
setbkcolor(RGB(0, 0, 0));
|
|
|
|
render_SetModes(mode_rotate, since);
|
|
|
|
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
|
|
|
// render_DrawBundleW(app, render_FindBundle("info_plate"), vec2(600, 550));
|
2024-03-30 21:25:39 +08:00
|
|
|
render_DrawBundleW(app, render_FindBundle("info_plate_small_1"), vec2(250, 200));
|
|
|
|
render_DrawBundleW(app, render_FindBundle("info_plate_small_2"), vec2(750, 200));
|
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;
|
|
|
|
// 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
|
|
|
}
|