From c094aa2605338cb9e00bbd4a70fde26f50723bd5 Mon Sep 17 00:00:00 2001 From: mibi88 Date: Sun, 11 Dec 2022 17:53:17 +0100 Subject: [PATCH] v.0.1-4 --- CMakeLists.txt | 2 + assets-fx/fxconv-metadata.txt | 12 ++++++ assets-fx/milifont.png | Bin 0 -> 537 bytes assets-fx/score_bar.png | Bin 0 -> 125 bytes src/core.c | 75 ++++++++++++++++++++++++---------- src/core.h | 9 ++++ src/main.c | 6 +++ 7 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 assets-fx/milifont.png create mode 100644 assets-fx/score_bar.png diff --git a/CMakeLists.txt b/CMakeLists.txt index 25d2feb..f8d2c62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,8 @@ set(ASSETS_fx assets-fx/timer/3.png assets-fx/timer/2.png assets-fx/timer/1.png + assets-fx/score_bar.png + assets-fx/milifont.png # ... ) diff --git a/assets-fx/fxconv-metadata.txt b/assets-fx/fxconv-metadata.txt index 4834fea..0a37d81 100644 --- a/assets-fx/fxconv-metadata.txt +++ b/assets-fx/fxconv-metadata.txt @@ -7,3 +7,15 @@ game_over.png: you_won.png: type: bopti-image name: you_won +score_bar.png: + type: bopti-image + name: score_bar + +milifont.png: + name: milifont + type: font + charset: print + width: 3 + grid.size: 3x5 + grid.padding: 1 + proportional: true diff --git a/assets-fx/milifont.png b/assets-fx/milifont.png new file mode 100644 index 0000000000000000000000000000000000000000..03a1fca177d8f1021d5c697162213bac3790a6b0 GIT binary patch literal 537 zcmV+!0_OdRP)44T@{jmFQeJhHc7`L^Sy+8}t-9wD9BLji8zzsjAc*R&BX+kBH5F=%p#H z!B^>cOKwH^yTQmQv9h~MXCN8W zLSF%q7mg~6(N%NE90^5Y7k7J@;lP6{ArVxl3ANeqqn$`Z(txGvD^%6JDw_TMsUp8z#Hv2`WNI`G#^a zm`eq8jVklpm|Hofjp(aklfXDM1xi4zYIt~n%>+glnH`cVxbu7{%99yW&f__=JuGuD zEy`@h!aIFNlb<<|eDZw!CJzAv`Y+Gyx8y%yf2*PQ7$Z`=ko?@O7>&P-AbL b`ce4>DE#Zos3OJN00000NkvXXu0mjf$Mo&f literal 0 HcmV?d00001 diff --git a/assets-fx/score_bar.png b/assets-fx/score_bar.png new file mode 100644 index 0000000000000000000000000000000000000000..14df3112b71e267a6c323be32db03b3800c0d281 GIT binary patch literal 125 zcmeAS@N?(olHy`uVBq!ia0vp^4M5Dv!2%=$I^F~TDHl%{#}JRsrxi~q;l ZneQComUX%4F&$_ggQu&X%Q~loCIF%NDarr< literal 0 HcmV?d00001 diff --git a/src/core.c b/src/core.c index 733107b..523dfd3 100644 --- a/src/core.c +++ b/src/core.c @@ -20,30 +20,33 @@ #include "includes.h" Ship ship; +static Vector smoke_cubes[5]; + extern bopti_image_t map_1; extern bopti_image_t timer_3; extern bopti_image_t timer_2; extern bopti_image_t timer_1; +extern bopti_image_t score_bar; -int dgetpixel(int x, int y) // Thanks to Lephenixnoir -{ - int offset = (y << 2) + (x >> 5); - return (int)(gint_vram[offset] << (x & 31)) < 0 ? C_BLACK : C_WHITE; -} +int score_delay; int play_game(void) { - int collision = 0, ticks = 0, timer = 3; + int collision = 0, timer = 3, ticks = 0; + ship.score = 0; init_ship(); ship.scrolling.x = 0; ship.scrolling.y = 0; + for(int i = 0; i < 5; i++) + { + smoke_cubes[i].x = 0; + smoke_cubes[i].y = 0; + } while(timer != 0){ dclear(C_WHITE); - int i; - dimage(-ship.scrolling.x, 0, &map_1); calculate_tops(); - for(i = 0; i != 3; i++) - dline(ship.tops[i].x, ship.tops[i].y, ship.tops[(i + 1) % 3].x, ship.tops[(i + 1) % 3].y, C_BLACK); + dimage(-ship.scrolling.x, 0, &map_1); + draw(); if(timer == 3){ dimage(59, 25, &timer_3); }else if(timer == 2){ @@ -56,6 +59,9 @@ int play_game(void) timer--; } + score_delay = 0; + ship.score = 0; + while(1) { clearevents(); @@ -69,28 +75,54 @@ int play_game(void) calculate_tops(); dclear(C_WHITE); collision = move(); - draw(); - ship.thrust = true; - clearevents(); if(ship.scrolling.x >= 3328){ return 1; } if(collision == 1){ return 0; } + draw(); + dupdate(); + ship.thrust = true; + clearevents(); + ticks++; + score_delay++; + if(ticks>=SMOKE_CUBES_SPACING) + { + for(int i=0;i<4;i++) + { + smoke_cubes[i].x = smoke_cubes[i+1].x; + smoke_cubes[i].y = smoke_cubes[i+1].y; + } + smoke_cubes[4].x = ship.scrolling.x + MARGIN; + smoke_cubes[4].y = ship.position.y; + ticks = 0; + } + + if(score_delay>=SCORE_DELAY) + { + ship.score++; + score_delay=0; + } } } void draw(void) { - static Vector smoke_cubes[5]; int i; - for(i = 0; i != 3; i++) + for(i = 0; i < 3; i++) + { dline(ship.tops[i].x, ship.tops[i].y, ship.tops[(i + 1) % 3].x, ship.tops[(i + 1) % 3].y, C_BLACK); + } - dupdate(); + for(i = 0; i < 5; i++) + { + drect_border(smoke_cubes[i].x-1 - ship.scrolling.x, smoke_cubes[i].y-1, smoke_cubes[i].x+1 - ship.scrolling.x, smoke_cubes[i].y+1, C_WHITE, 1, C_BLACK); + } + dimage(0, 0, &score_bar); + dprint_opt(1, 1, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "Score : %d", ship.score); } int move(void) @@ -104,13 +136,14 @@ int move(void) ship.position.x += ship.speed.x; ship.position.y += ship.speed.y; - + ship.scrolling.x = ship.position.x; - + dimage(-ship.scrolling.x, 0, &map_1); - + // collision - for(i=0;i!=3;i++){ + for(i=0;i<3;i++) + { if(dgetpixel(ship.tops[i].x, ship.tops[i].y) == C_BLACK){ return 1; } @@ -132,7 +165,7 @@ void calculate_tops(void) init_tops(); - for(i = 0; i != 3; i++) + for(i = 0; i < 3; i++) { tmp.x = ship.tops[i].x; tmp.y = ship.tops[i].y; diff --git a/src/core.h b/src/core.h index 3f1e72e..28dc630 100644 --- a/src/core.h +++ b/src/core.h @@ -37,6 +37,13 @@ // Margin before the ship #define MARGIN 32 +// Time between the smoke cubes +#define SMOKE_CUBES_SPACING 8 + + +// Increment score_delay after SCORE_DELAY frames. +#define SCORE_DELAY 16 + // Relative position of tops of the ship /*#define SHIP_TOP_1_X 10 #define SHIP_TOP_1_Y 0 @@ -72,6 +79,8 @@ typedef struct bool thrust; Vector tops[3]; + + int score; } Ship; typedef struct diff --git a/src/main.c b/src/main.c index 0fc9ae0..049aa6c 100644 --- a/src/main.c +++ b/src/main.c @@ -29,6 +29,10 @@ extern bopti_image_t menu_play_inv; extern bopti_image_t menu_quit; extern bopti_image_t menu_quit_inv; +extern font_t milifont; + +extern Ship ship; + void waitkey(int key){ clearevents(); while(keydown(key)){ @@ -43,6 +47,7 @@ void end(){ }else if(stat == 1){ dimage(0, 0, &you_won); } + dprint_opt(57, 30, C_BLACK, C_WHITE, DTEXT_LEFT, DTEXT_TOP, "Score : %d", ship.score); if(stat == 0 || stat == 1){ dupdate(); stat = 0; @@ -63,6 +68,7 @@ void end(){ int main(void) { + dfont(&milifont); selection = PLAY; stat = 0; while(1){