diff --git a/CMakeLists.txt b/CMakeLists.txt index b6f3adf..5e3e91b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ set(ASSETS_fx assets-fx/planes.png assets-fx/bground.png assets-fx/mutations.png - assets-fx/piece.png + assets-fx/cursor.png assets-fx/title.png assets-fx/mutations_table/abilities_1.txt assets-fx/mutations_table/abilities_2.txt diff --git a/Plague.g1a b/Plague.g1a index d6987f5..1175150 100644 Binary files a/Plague.g1a and b/Plague.g1a differ diff --git a/assets-fx/cursor.png b/assets-fx/cursor.png new file mode 100644 index 0000000..c16cb9b Binary files /dev/null and b/assets-fx/cursor.png differ diff --git a/assets-fx/piece.png b/assets-fx/piece.png deleted file mode 100644 index d0c2a63..0000000 Binary files a/assets-fx/piece.png and /dev/null differ diff --git a/assets-fx/pieces.png b/assets-fx/pieces.png deleted file mode 100644 index 985aedf..0000000 Binary files a/assets-fx/pieces.png and /dev/null differ diff --git a/assets-fx/planes.png b/assets-fx/planes.png index fae3c21..5995dc0 100644 Binary files a/assets-fx/planes.png and b/assets-fx/planes.png differ diff --git a/src/core.c b/src/core.c index e66e00b..063c56c 100644 --- a/src/core.c +++ b/src/core.c @@ -1,3 +1,5 @@ +#include +#include #include #include "core.h" @@ -45,13 +47,7 @@ void next_frame(struct game *current_game) int get_inputs(const int background, int *mutation_menu) { - int opt = GETKEY_DEFAULT & ~GETKEY_REP_ARROWS; - int timeout = 1; - - key_event_t ev = getkey_opt(opt, &timeout); - if(ev.type == KEYEV_NONE) return background; - - int key = ev.key; + int key = rtc_key(); if (key == KEY_OPTN && (background == 1 || background == 2)) return (background % 2) + 1; if (key == KEY_VARS) return 3; @@ -98,15 +94,55 @@ int get_inputs(const int background, int *mutation_menu) } +int rtc_key(void) +{ + int opt = GETKEY_DEFAULT & ~GETKEY_REP_ARROWS; + int timeout = 1; + + key_event_t ev = getkey_opt(opt, &timeout); + if(ev.type == KEYEV_NONE) return 0; + + return ev.key; +} + + +int callback_tick(volatile int *tick) +{ + *tick = 1; + return TIMER_CONTINUE; +} + + void manage_mutation(struct game *current_game, const int mutation_menu) { int key = 0, end = 0; - int cursor_x = 1, cursor_y = 1; - while (!end) - { - display_mutation(current_game, mutation_menu, cursor_x, cursor_y); - key = getkey().key; + struct cursor c = {0, 0, 0}; + static volatile int tick = 1; + int t = timer_configure(TIMER_ANY, CURSOR_TICK*1000, GINT_CALL(callback_tick, &tick)); + if (t >= 0) timer_start(t); + + + while (!end) + { + // Cursor blinking gestion + while (!tick) sleep(); + tick = 0; + c.display = (c.display + 1) % 2; + + // Display the mutation menu + display_mutation(current_game, mutation_menu, c); + + // Get the key + key = rtc_key(); + if (key == KEY_EXIT) end = 1; + + + if (key == KEY_LEFT && c.x > 0) c.x--; + if (key == KEY_RIGHT && c.x < 7) c.x++; + if (key == KEY_UP && c.y > 0) c.y--; + if (key == KEY_DOWN && c.y < 3) c.y++; } + if (t >= 0) timer_stop(t); } diff --git a/src/core.h b/src/core.h index 87a3f51..cf93a01 100644 --- a/src/core.h +++ b/src/core.h @@ -1,9 +1,9 @@ #ifndef _PLAGUE_CORE_H #define _PLAGUE_CORE_H - // Duration for internal clock #define ENGINE_TICK 50 +#define CURSOR_TICK 200 // Number of planes on screen #define NB_PLANES 5 @@ -11,7 +11,6 @@ // Number of humans #define TOTAL_POP 10000000000 - // game : all statistics of the current game struct game { @@ -38,7 +37,6 @@ struct game struct plane *planes[NB_PLANES + 1]; }; - // plane : information about planes struct plane { @@ -51,20 +49,35 @@ struct plane // Coordinates of the plane's destination int dest_x, dest_y; - //Coordinates of the plane's departure + // Coordinates of the plane's departure int depa_x, depa_y; }; +//cursor : cursor information for mutations selection +struct cursor +{ + // Cursor's coordinates + int x, y; + + // If the cursor should be displayed + int display; +}; + // get_inputs : detect and manage inputs int get_inputs(const int background, int *mutation_menu); - // next_frame : compute the plane's positions void next_frame(struct game *current_game); +// rtc_key : get the key with RTC system +int rtc_key(void); + +// callback_timer : basic timer +int callback_tick(volatile int *tick); // manage_mutation : an independant sub-programm which allow to select, buy and see the mutations. void manage_mutation(struct game *current_game, const int mutation_menu); + #endif /* _PLAGUE_CORE_H */ \ No newline at end of file diff --git a/src/display_engine.c b/src/display_engine.c index 4d4ac48..3fae5b4 100644 --- a/src/display_engine.c +++ b/src/display_engine.c @@ -79,10 +79,10 @@ void display_foreground(const int background, const struct game *current_game) } -void display_mutation(const struct game *current_game, const int mutation_menu, const int cursor_x, const int cursor_y) +void display_mutation(const struct game *current_game, const int mutation_menu, const struct cursor c) { extern const bopti_image_t img_mutations; - extern bopti_image_t img_piece; + extern bopti_image_t img_cursor; // Load symptoms extern struct mutation_table mt_symptoms_1; @@ -122,14 +122,15 @@ void display_mutation(const struct game *current_game, const int mutation_menu, } dclear(C_WHITE); + display_background(5); for (int i = 0 ; i < 4 ; i++) { for (int j = 0 ; j < 8; j++) { - if (table[i][j]) dsubimage(i*16, j*16, &img_mutations, 16 * (mutation_menu - 1), 0, 16 * (table[i][j] - 1), 15, 15); + if (table[i][j]) dsubimage(j*16, i*16, &img_mutations, 16 * (mutation_menu - 1), 16 * (table[i][j] - 1), 15, 15, DIMAGE_NONE); } } - dimage(16 * (cursor_x - 1), 16 * (cursor_y - 1), &img_piece); + dsubimage((16 * c.x) - 1, (16 * c.y) - 1, &img_cursor, 0, 17 * (c.display), 17, 17, DIMAGE_NONE); dupdate(); } diff --git a/src/display_engine.h b/src/display_engine.h index ffe944e..e9c7e9c 100644 --- a/src/display_engine.h +++ b/src/display_engine.h @@ -8,7 +8,7 @@ void display_background(const int background); void display_foreground(const int background, const struct game *current_game); // display_mutation : display the mutation selection screen -void display_mutation(const struct game *current_game, const int mutation_menu, const int cursor_x, const int cursor_y); +void display_mutation(const struct game *current_game, const int mutation_menu, const struct cursor c); // init_mat : copy src into dest void init_mat(int x, int y, int dest[][x], int src[][x]); diff --git a/src/main.c b/src/main.c index abb3ba2..7d94cbc 100644 --- a/src/main.c +++ b/src/main.c @@ -19,9 +19,6 @@ static void title_screen(void); // main_loop : display background, foreground and manage inputs void main_loop(struct game *current_game); -// callback_timer : basic timer -int callback_tick(volatile int *tick); - int main(void) { @@ -117,9 +114,3 @@ void main_loop(struct game *current_game) if (t >= 0) timer_stop(t); } - -int callback_tick(volatile int *tick) -{ - *tick = 1; - return TIMER_CONTINUE; -}