Browse Source

Updated Scufeng. Quit button.

Aaro Saila 2 tuần trước cách đây
mục cha
commit
7dc1fb980f

+ 16 - 7
src/game/MainMenu.c

@@ -1,7 +1,6 @@
-#include <stdio.h>
-
 #include "scufeng/engine.h"
 #include "scufeng/Mesh.h"
+#include "scufeng/log.h"
 #include "cglm/vec3.h"
 
 #include "MainMenu.h"
@@ -12,7 +11,7 @@ MainMenu MainMenu_alloc(const unsigned int screen_w, const unsigned int screen_h
 
     mm.title_text = SEMesh_string_alloc("Pong", 1.0f, GLM_VEC3_ONE);
     mm.title_text.transform.pos[0] = screen_w / 2.0f;
-    mm.title_text.transform.pos[1] = screen_h * 0.8f;
+    mm.title_text.transform.pos[1] = screen_h * 0.2f;
 
     mm.sp_text = SEMesh_string_alloc("Singleplayer", 1.0f, GLM_VEC3_ONE);
     mm.sp_text.transform.pos[0] = screen_w * 0.25f;
@@ -22,6 +21,10 @@ MainMenu MainMenu_alloc(const unsigned int screen_w, const unsigned int screen_h
     mm.mp_text.transform.pos[0] = screen_w - mm.sp_text.transform.pos[0];
     mm.mp_text.transform.pos[1] = mm.sp_text.transform.pos[1];
 
+    mm.quit_text = SEMesh_string_alloc("Quit", 1.0f, GLM_VEC3_ONE);
+    mm.quit_text.transform.pos[0] = screen_w / 2.0f;
+    mm.quit_text.transform.pos[1] = screen_h * 0.8f;
+
     return mm;
 }
 
@@ -31,14 +34,19 @@ static Screen MainMenu_input_handle(MainMenu *const mm) {
         se_get_mouse_pos(&x, &y);
 
         if (SEMesh_rect_is_pos_inside(&mm->sp_text, x, y)) {
-            printf("SP\n");
+            SE_LOG("SP");
             return PONG_SINGLEPLAYER;
         }
 
         if (SEMesh_rect_is_pos_inside(&mm->mp_text, x, y)) {
-            printf("MP\n");
+            SE_LOG("MP");
             return PONG_MULTIPLAYER;
         }
+
+        if (SEMesh_rect_is_pos_inside(&mm->quit_text, x, y)) {
+            SE_LOG("Quit");
+            se_window_close();
+        }
     }
 
     return PONG_MAIN_MENU;
@@ -49,10 +57,11 @@ Screen MainMenu_tick(MainMenu *const mm) {
     if (screen != PONG_MAIN_MENU) {
         return screen;
     }
-    const SEMesh *meshes[] = {
+    SEMesh *meshes[] = {
         &mm->title_text,
         &mm->sp_text,
-        &mm->mp_text
+        &mm->mp_text,
+        &mm->quit_text
     };
     SEMesh_render_multiple_2d(meshes, sizeof(meshes) / sizeof(meshes[0]));
 

+ 1 - 0
src/game/MainMenu.h

@@ -8,6 +8,7 @@ typedef struct {
     SEMesh title_text;
     SEMesh sp_text;
     SEMesh mp_text;
+    SEMesh quit_text;
 } MainMenu;
 
 MainMenu MainMenu_alloc(const unsigned int screen_w, const unsigned int screen_h);

+ 3 - 3
src/game/game_common.c

@@ -17,7 +17,7 @@ static void pos_convert(
     const unsigned int screen_h
 ) {
     render_pos[0] = state_pos[0] * screen_w;
-    render_pos[1] = (1.0f - state_pos[1]) * screen_h;
+    render_pos[1] = state_pos[1] * screen_h;
 }
 
 void GameShapes_update(
@@ -75,7 +75,7 @@ void GameShapes_render(
     const unsigned int screen_w,
     const unsigned int screen_h
 ) {
-    const SEMesh *meshes[] = {
+    SEMesh *meshes[] = {
         &shapes->paddle_l,
         &shapes->paddle_r,
         &shapes->ball
@@ -83,7 +83,7 @@ void GameShapes_render(
     SEMesh_render_multiple_2d(meshes, sizeof(meshes) / sizeof(meshes[0]));
 
     const float score_w = 0.25f;
-    const float score_h = 0.9f;
+    const float score_h = 0.1f;
     char score_txt[4] = { 0 };
     snprintf(score_txt, 4, "%d", state->score_l);
     se_text_render(

+ 1 - 1
subprojects/scufeng/GIT_COMMIT

@@ -1 +1 @@
-47f838af2a4cae2c992ae394f8b7ba7c381bafe0
+126f1a9383328e45b9b37bb255e0eba838685255

+ 5 - 1
subprojects/scufeng/include/scufeng/Mesh.h

@@ -54,6 +54,10 @@ typedef struct {
 void SEMesh_free(SEMesh *const mesh);
 void SEMesh_set_draw_mode(SEMesh *mesh, const SEDrawMode mode);
 void SEMesh_render(const SEMesh *const mesh);
+void SEMesh_color_set(SEMesh *const mesh, const vec4 color);
+void SEMesh_line_segment_coords_set(SEMesh *const mesh, const vec2 a, const vec2 b);
+SEMesh SEMesh_line_segment_color_alloc(const vec2 a, const vec2 b, const vec4 color);
+void SEMesh_bbox_render_2d(const SEMesh *const mesh);
 void SEMesh_bbox_get_2d(
     const SEMesh *const mesh,
     float *left,
@@ -68,7 +72,7 @@ SEMesh SEMesh_string_alloc(
     const float scale,
     const vec3 color
 );
-void SEMesh_render_multiple_2d(const SEMesh *const *const meshes, const size_t meshes_n);
+void SEMesh_render_multiple_2d(SEMesh *const *const meshes, const size_t meshes_n);
 // void SEShape_transform_apply(SEShape *const shape);
 
 #endif // SCUFENG_SHAPE_H_

BIN
subprojects/scufeng/libscufeng.a