Skip to content

Commit

Permalink
Added health component gui
Browse files Browse the repository at this point in the history
  • Loading branch information
nemene21 committed Jul 12, 2024
1 parent 9931641 commit 8babee8
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 111 deletions.
20 changes: 12 additions & 8 deletions MakefileGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def toggle_web_mode():

WEB = not WEB
if WEB:
COMPILER = "emcc"
COMPILER = "emcc -DWEB"
INDEX = " index.html"
LDFLAGS = "-DWEB -L../libweb/"
LDFLAGS = "-L../libweb/"
LDLIBS = "-lraylib"
OBJ_DIR = "web_object_files"
else:
Expand Down Expand Up @@ -87,15 +87,17 @@ def generate_makefile():
next(2)

for source in source_files:
add(f"{OBJ_DIR}/{get_filename(source)}.o: {ROOT_DIR}/{source}.cpp")
next(); tab()
if not (WEB and get_filename(source) == "rich_presence"):
add(f"{OBJ_DIR}/{get_filename(source)}.o: {ROOT_DIR}/{source}.cpp")
next(); tab()

add(f"{COMPILER} {CFLAGS} -c {ROOT_DIR}/{source}.cpp -o $(@)")
next(2)
add(f"{COMPILER} {CFLAGS} -c {ROOT_DIR}/{source}.cpp -o $(@)")
next(2)

add("Build.exe: ")
for source in source_files:
add(OBJ_DIR + "/" + get_filename(source) + ".o ")
if not (WEB and get_filename(source) == "rich_presence"):
add(OBJ_DIR + "/" + get_filename(source) + ".o ")

next(); tab()
if not WEB:
Expand All @@ -107,7 +109,9 @@ def generate_makefile():
add(f"{COMPILER} {CFLAGS}")
add("../src/main.cpp ")
for source in source_files:
add(OBJ_DIR + "/" + get_filename(source) + ".o ")
if not (WEB and get_filename(source) == "rich_presence"):
add(OBJ_DIR + "/" + get_filename(source) + ".o ")

add("-o web_build/index.html -s ASSERTIONS=1 -s SAFE_HEAP=1 -s USE_GLFW=3 -s ASYNCIFY -s WASM=1 -s TOTAL_MEMORY=2048MB --shell-file shell.html ")
add("--preload-file assets ")

Expand Down
196 changes: 98 additions & 98 deletions build/Makefile

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions build/imgui.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[Window][Debug##Default]
Pos=108,31
Size=358,104
Collapsed=1
Pos=107,31
Size=744,577

17 changes: 17 additions & 0 deletions src/framework/components/health_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ HealthComponent::HealthComponent(Entity *entity, float max_hp):
max_hp {max_hp},
dead {dead} {}

void HealthComponent::draw_gui_info() {
if (ImGui::CollapsingHeader(("Health##" + std::to_string(id)).c_str())) {
ImGui::Indent(25.f);

ImGui::Text("Hp: ");
ImGui::SameLine();
ImGui::Text((std::to_string(hp) + "/" + std::to_string(max_hp)).c_str());

ImVec4 col = dead ? ImVec4{1, 0, 0, 1} : ImVec4{0, 1, 0, 1};
ImGui::Text("Died: ");
ImGui::SameLine();
ImGui::TextColored(col, dead ? "true" : "false");
ImGui::Unindent(25.f);
}
}


void HealthComponent::hurt(float damage) {
hp -= damage;

Expand Down
2 changes: 2 additions & 0 deletions src/framework/components/health_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class HealthComponent: public Component {
hurt_signal,
healed_signal;

virtual void draw_gui_info();

/// @brief Subtracts from hp
/// @param damage Damage to subtract
void hurt(float damage);
Expand Down
2 changes: 1 addition & 1 deletion src/framework/framework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RenderTexture2D ui_layer, game_layer, composition_layer;
ShaderPtr post_processing_ptr;
TexturePtr noise_texture,
paper_texture;

float background_color[4] = {0, 0, 0, 1};

clock_t frame_timer;
Expand Down
4 changes: 3 additions & 1 deletion src/framework/framework.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
#include <time.h>
#include <string>

#include <rich_presence.hpp>
#ifndef WEB
#include <rich_presence.hpp>
#endif

// Raylib
#include <raylib.h>
Expand Down
1 change: 1 addition & 0 deletions tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 8babee8

Please sign in to comment.