From 73d10b343f7799ec013ffd237b877d49fd3fcb2d Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Sat, 30 Mar 2024 22:41:49 +0800 Subject: [PATCH] Hazard respawn is also working now Still need to emit particles on HazardHarm tho --- app.c | 4 ++++ app_render.cpp | 19 +++++++++++++++++++ player.c | 15 +++++++++++++++ player.h | 10 ++++++++++ 4 files changed, 48 insertions(+) diff --git a/app.c b/app.c index e4729b5..8d34805 100644 --- a/app.c +++ b/app.c @@ -81,6 +81,10 @@ App *app_NewApp() { misc_InstantiateTextbox(app, text3, "Press ; to dash.\nYou can only dash one time midair.", misc_TextboxUpright(70, 70), -180); entity_Commit(app->entity, text3); + Entity *respawn1 = entity_Create(app->entity, "respawn1"); + misc_InstantiateHazardRespawn(app, respawn1, box2(300, 500, 400, 50), vec2(500, 550)); + entity_Commit(app->entity, respawn1); + return app; } diff --git a/app_render.cpp b/app_render.cpp index 3dd33fe..e1a87cd 100644 --- a/app_render.cpp +++ b/app_render.cpp @@ -51,6 +51,25 @@ void app_Render(App *app) { (int)round(box.lefttop.x + box.size.x), (int)round(box.lefttop.y + box.size.y)); } + 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)); + } } } diff --git a/player.c b/player.c index 165115c..3646a56 100644 --- a/player.c +++ b/player.c @@ -151,7 +151,22 @@ void player_Advance(System_Player *sys, Duration deltaTime) { } + // Respawn if fallen out of the world + if (p->super->position->position.y > 5000) + player_HazardHarm(sys); + + // Check OnGround again if (dabs(sys->player->super->position->velocity.y) > EPS) sys->player->onGround = false; } + + +void player_HazardHarm(System_Player *sys) { + if (!sys->player) + return; + sys->player->storedSpeedY = 0; + sys->player->super->position->velocity = vec2(0, 0); + sys->player->super->position->position = sys->player->hazardRespawn; + sys->player->super->position->position.y -= EPS; // Stay loose! +} diff --git a/player.h b/player.h index 1799fd4..6ad65eb 100644 --- a/player.h +++ b/player.h @@ -52,6 +52,16 @@ void player_DeleteEntity(System_Player *sys, uintptr_t id); // Called on every frame. void player_Advance(System_Player *sys, Duration deltaTime); +// Harm the player. +// The player is hit backwards, releasing a puff of smoke. +// +// To be implemented +// void player_Harm(System_Player *sys, Vec2 source); + +// Hazard harm the player. +// The player is teleported to the hazard respawn point. +void player_HazardHarm(System_Player *sys); + #ifdef __cplusplus }