diff --git a/CMakeLists.txt b/CMakeLists.txt index b06f075..380d150 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,7 @@ set(ASSETS_cg assets-cg/img/player.png assets-cg/img/wall.png assets-cg/img/spike.png + assets-cg/img/end.png # ... ) diff --git a/assets-cg/img/end.png b/assets-cg/img/end.png new file mode 100644 index 0000000..6af4e86 Binary files /dev/null and b/assets-cg/img/end.png differ diff --git a/assets-cg/img/fxconv-metadata.txt b/assets-cg/img/fxconv-metadata.txt index d40aaa3..38c561a 100644 --- a/assets-cg/img/fxconv-metadata.txt +++ b/assets-cg/img/fxconv-metadata.txt @@ -8,4 +8,8 @@ wall.png: spike.png: type: bopti-image - name: img_spike \ No newline at end of file + name: img_spike + +end.png: + type: bopti-image + name: img_end \ No newline at end of file diff --git a/include/main.h b/include/main.h index 2bad117..152261d 100644 --- a/include/main.h +++ b/include/main.h @@ -3,32 +3,21 @@ #define LEVEL_SIZE 16 #define TILE_SIZE 12 -/* see we use a typedef like bellow - * its lazy and allow you to type - * Vec2 instead of struct TwoValues */ +// struct for a pair of values typedef struct Vec2 { int x, y; } Vec2; -/* we do da same with player cause laziness never killed nobody - * wait */ +// struct for player's data typedef struct Player { Vec2 pos; Vec2 spawn; } Player; -/* using a typedef is what cool kids do at least i think - * you might no remember what `int x` is :( - * if x is declared with `tile_t x` you know x is some tile :) - * knowledge is power and cool - * as bonus it looks cool in function declaration - * cool stuff told u :D */ +// used for tiles typedef int tile_t; Vec2 search(tile_t x, tile_t level[16][16]); -/* here u can see i replaced x and y arguments with your twovalues struct - * u made smthing use it - * it will be handy in the future and makes better looking code */ int collide_pixel(Vec2 pos, tile_t obj, tile_t level[16][16]); int collide(Vec2 pos, int h, tile_t obj, tile_t level[16][16]); Player level_reset(Player player); diff --git a/src/levels.c b/src/levels.c index 65e98dc..040adee 100644 --- a/src/levels.c +++ b/src/levels.c @@ -1,12 +1,10 @@ #include "main.h" -/* see use tile_t cause these stuff are tiles - * would you believe it? */ const tile_t level[16][16] = { {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {1, 3, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 3, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, - {1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1}, + {1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 4, 0, 0, 1}, {1, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1}, diff --git a/src/main.c b/src/main.c index 0133e20..21cbdb2 100644 --- a/src/main.c +++ b/src/main.c @@ -1,3 +1,6 @@ +// ZkwuL by Massena +// Optimisation and rewrite thanks to KikooDX + #include #include #include "main.h" @@ -21,7 +24,7 @@ Vec2 search(tile_t x, tile_t level[16][16]) { int collide_pixel(Vec2 pos, tile_t obj, tile_t level[LEVEL_SIZE][LEVEL_SIZE]) { // Check if there's something in (x, y) - if(obj == level[pos.x / TILE_SIZE][pos.y / TILE_SIZE]) { + if(obj == level[pos.y / TILE_SIZE][pos.x / TILE_SIZE]) { return 1; } else { @@ -30,9 +33,8 @@ int collide_pixel(Vec2 pos, tile_t obj, tile_t level[LEVEL_SIZE][LEVEL_SIZE]) { } int collide(Vec2 pos, int h, tile_t obj, tile_t level[LEVEL_SIZE][LEVEL_SIZE]) { - /* tl = top left - * br = bottom right - * avoid repetition later on ezier to work on */ + // tl = top left + // br = bottom right const Vec2 pos_tl = (Vec2){pos.x + h, pos.y + h}; const Vec2 pos_br = (Vec2){pos.x + TILE_SIZE - h - 1, pos.y + TILE_SIZE - h - 1}; // Check if there's something in @@ -57,10 +59,12 @@ int main(void) { extern bopti_image_t img_player; extern bopti_image_t img_wall; extern bopti_image_t img_spike; + extern bopti_image_t img_end; extern tile_t level[LEVEL_SIZE][LEVEL_SIZE]; int running = 1; + int timer = 0; // lol // player Player player = { @@ -87,6 +91,11 @@ int main(void) { // spikes dimage(m * TILE_SIZE, n * TILE_SIZE, &img_spike); break; + case 4: + // end ring + dsubimage(m * TILE_SIZE, n * TILE_SIZE, &img_end, + ((timer / 30) % 4) * 12, 0, 12, 12, 0); + break; } } } @@ -96,7 +105,7 @@ int main(void) { dupdate(); - /* if something has x and y, you probably want to use your Vec2 struct */ + // Vec2 mov = { .x = keydown(KEY_RIGHT) - keydown(KEY_LEFT), .y = keydown(KEY_DOWN) - keydown(KEY_UP) @@ -117,7 +126,11 @@ int main(void) { player = level_reset(player); } - if(keydown(KEY_EXIT)) running = 0; + if(keydown(KEY_EXIT) || collide(player.pos, 0, 4, level)) { + running = 0; + } + + ++timer; // lol^2 } return 1;