Add mutations menus cursor, and background, and improve plane's traffic.

This commit is contained in:
Shadow15510 2021-05-27 22:09:01 +02:00
parent 0df11fb8d4
commit b1c3ed89b9
11 changed files with 73 additions and 32 deletions

View File

@ -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

Binary file not shown.

BIN
assets-fx/cursor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 629 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 677 B

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -1,3 +1,5 @@
#include <gint/timer.h>
#include <gint/clock.h>
#include <gint/keyboard.h>
#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);
}

View File

@ -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 */

View File

@ -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();
}

View File

@ -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]);

View File

@ -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;
}