summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoredGuy <osome3717@gmail.com>2026-03-25 20:55:53 +0300
committerBoredGuy <osome3717@gmail.com>2026-03-25 20:55:53 +0300
commit4cfe20847f2bd2c46176eb5cccb1afeda4420769 (patch)
tree87957e7bbb5ba2ce509e609f8394a9853719916e
parent3af894f7590841cda2f4880ec49ccd488e3faa99 (diff)
Refactor Level Loading(undone!)HEADmaster
-rw-r--r--src/constants.h4
-rw-r--r--src/game.c78
-rw-r--r--src/player.c4
3 files changed, 49 insertions, 37 deletions
diff --git a/src/constants.h b/src/constants.h
index 5fc959f..f16466e 100644
--- a/src/constants.h
+++ b/src/constants.h
@@ -3,12 +3,12 @@
#define WINDOW_WIDTH 1280
#define WINDOW_HEIGHT 640
-#define TARGET_FPS 144
+#define TARGET_FPS 120
#define MAX_ENTITY_COUNT 500
#define ENTITY_MAX_ANIMATIONS 10
#define ANIMATION_MAX_FRAMES 4
-#define GRAVITY 200
+#define GRAVITY 400
#endif
diff --git a/src/game.c b/src/game.c
index 21b80fd..0bf4677 100644
--- a/src/game.c
+++ b/src/game.c
@@ -64,13 +64,16 @@ void init_game() {
memset(&game, 0, sizeof(struct game));
}
-void set_background(const char* background_name) {
+static void set_background(const char* background_name) {
if (strcmp(background_name, "color_hills") == 0)
game.background_texture = color_hills;
else if (strcmp(background_name, "color_desert") == 0)
game.background_texture = color_desert;
}
+static void load_image_layer_object(const cJSON* layer);
+static void load_tile_layer_object(const cJSON* layer);
+
void load_level_from_tiled_tmj(const char* filename) {
cJSON *level_data_json = cJSON_Parse(filename);
@@ -94,48 +97,57 @@ void load_level_from_tiled_tmj(const char* filename) {
continue;
if (strcmp(type->valuestring, "imagelayer") == 0) {
- const cJSON* properties = NULL;
- properties = cJSON_GetObjectItemCaseSensitive(layer, "properties");
+ load_image_layer_object(layer);
+ } else if (strcmp(type->valuestring, "tilelayer") == 0) {
+ load_tile_layer_object(layer);
+ }
+ }
+ }
- if (cJSON_IsArray(properties)) {
- const cJSON* property = NULL;
+ cJSON_Delete(level_data_json);
+}
- cJSON_ArrayForEach(property, properties) {
- const cJSON* name = cJSON_GetObjectItemCaseSensitive(property, "name");
- const cJSON* bg_name = cJSON_GetObjectItemCaseSensitive(property, "value");
- if (!cJSON_IsString(name)
- || !cJSON_IsString(bg_name)
- || strcmp(name->valuestring, "bg_name") != 0)
- continue;
+static void load_image_layer_object(const cJSON* layer) {
+ const cJSON* properties = NULL;
+ properties = cJSON_GetObjectItemCaseSensitive(layer, "properties");
- set_background(bg_name->valuestring);
- }
+ if (cJSON_IsArray(properties)) {
+ const cJSON* property = NULL;
- }
- } else if (strcmp(type->valuestring, "tilelayer") == 0) {
- const cJSON* width = cJSON_GetObjectItemCaseSensitive(layer, "width");
- const cJSON* data = cJSON_GetObjectItemCaseSensitive(layer, "data");
- int c = 0;
+ cJSON_ArrayForEach(property, properties) {
+ const cJSON* name = cJSON_GetObjectItemCaseSensitive(property, "name");
+ const cJSON* bg_name = cJSON_GetObjectItemCaseSensitive(property, "value");
- if (!cJSON_IsArray(data) || !cJSON_IsNumber(width))
- continue;
+ if (!cJSON_IsString(name)
+ || !cJSON_IsString(bg_name)
+ || strcmp(name->valuestring, "bg_name") != 0)
+ continue;
- const cJSON* tile = NULL;
- cJSON_ArrayForEach(tile, data) {
+ set_background(bg_name->valuestring);
+ }
- if (cJSON_IsNumber(tile) && tile->valueint != 0) {
- int x_pos = (c % width->valueint) * BLOCK_WIDTH + BLOCK_WIDTH / 2;
- int y_pos = (c / width->valueint) * BLOCK_HEIGHT + BLOCK_HEIGHT / 2;
+ }
+}
- add_wall(x_pos, y_pos, tile->valueint - 1);
- }
+static void load_tile_layer_object(const cJSON* layer) {
+ const cJSON* width = cJSON_GetObjectItemCaseSensitive(layer, "width");
+ const cJSON* data = cJSON_GetObjectItemCaseSensitive(layer, "data");
+ int c = 0;
- c++;
- }
- }
+ if (!cJSON_IsArray(data) || !cJSON_IsNumber(width))
+ return;
+
+ const cJSON* tile = NULL;
+ cJSON_ArrayForEach(tile, data) {
+
+ if (cJSON_IsNumber(tile) && tile->valueint != 0) {
+ int x_pos = (c % width->valueint) * BLOCK_WIDTH + BLOCK_WIDTH / 2;
+ int y_pos = (c / width->valueint) * BLOCK_HEIGHT + BLOCK_HEIGHT / 2;
+
+ add_wall(x_pos, y_pos, tile->valueint - 1);
}
- }
- cJSON_Delete(level_data_json);
+ c++;
+ }
}
diff --git a/src/player.c b/src/player.c
index fccbcee..e5be1ac 100644
--- a/src/player.c
+++ b/src/player.c
@@ -14,9 +14,9 @@
#define COLLIDER_XOFF 0
#define COLLIDER_YOFF 14
-#define TOP_SPEEDX 100
+#define TOP_SPEEDX 300
#define TOP_SPEEDY 100
-#define ACCEL_X 200
+#define ACCEL_X 400
#define JUMP_SPEEDY 250