mirror of https://github.com/bgiraudr/Adoranda.git
now can have 3 moves (or more but ui goes brr)
This commit is contained in:
parent
15ca37b2c5
commit
9cacf4b617
|
@ -2,4 +2,6 @@
|
|||
/*the size of one tile*/
|
||||
#define TILE_SIZE 16
|
||||
|
||||
#define NB_INTERIORS 2
|
||||
#define NB_INTERIORS 2
|
||||
|
||||
#define NB_PLAYER_MOVES 3
|
|
@ -4,7 +4,7 @@
|
|||
#include "vec2.h"
|
||||
#include "stats.h"
|
||||
#include "capacite.h"
|
||||
|
||||
#include "define.h"
|
||||
|
||||
struct Player {
|
||||
/*current position of the player on the map - Tile*/
|
||||
|
@ -13,7 +13,7 @@ struct Player {
|
|||
struct Vec2f pos_visual;
|
||||
|
||||
struct Stats stats;
|
||||
struct Move moves[2];
|
||||
struct Move moves[NB_PLAYER_MOVES];
|
||||
/*player mid - offset pixels*/
|
||||
int x_mid, y_mid;
|
||||
/*the direction the player facing to*/
|
||||
|
@ -35,4 +35,5 @@ struct Player init_player(void);
|
|||
void add_move(struct Player *player, struct Move move);
|
||||
void draw_player_moves(struct Player *player);
|
||||
void replace_capacities(struct Player *player, struct Move move);
|
||||
void draw_ui(struct Player *player);
|
||||
void draw_ui(struct Player *player);
|
||||
int get_nb_moves(struct Player *player);
|
11
src/battle.c
11
src/battle.c
|
@ -13,6 +13,7 @@ void create_battle(struct Player *player) {
|
|||
}
|
||||
|
||||
int during_battle(struct Player *player) {
|
||||
const int nbMove = get_nb_moves(player);
|
||||
int tour = 0;
|
||||
|
||||
int selection = 0;
|
||||
|
@ -21,16 +22,14 @@ int during_battle(struct Player *player) {
|
|||
while(1) {
|
||||
clearevents();
|
||||
|
||||
if(player->moves[1].name != NULL) {
|
||||
selection += keydown(KEY_RIGHT) - keydown(KEY_LEFT);
|
||||
}
|
||||
selection += keydown(KEY_RIGHT) - keydown(KEY_LEFT);
|
||||
|
||||
if(selection > 1) selection = 1;
|
||||
if(selection > nbMove-1) selection = nbMove-1;
|
||||
if(selection < 0) selection = 0;
|
||||
|
||||
dclear(C_RGB(25,25,25));
|
||||
draw_ui(player);
|
||||
dtext(95 + (selection * 190), DHEIGHT-15 , C_RED, "[X]");
|
||||
dtext(58 + (selection * 130), DHEIGHT-15 , C_RED, "[X]");
|
||||
dupdate();
|
||||
|
||||
if(keydown(KEY_SHIFT)) {
|
||||
|
@ -41,7 +40,7 @@ int during_battle(struct Player *player) {
|
|||
player->stats.pv--;
|
||||
break;
|
||||
}
|
||||
while(keydown(KEY_SHIFT)) clearevents();
|
||||
while(keydown_any(KEY_RIGHT, KEY_LEFT, KEY_SHIFT, 0)) clearevents();
|
||||
}
|
||||
|
||||
execute_move(&player->stats, player->moves[selection]);
|
||||
|
|
|
@ -25,7 +25,7 @@ void draw_move(int x, int y, int x2, int y2, struct Move move) {
|
|||
}
|
||||
|
||||
void draw_classic_move(int x, int y, struct Move move) {
|
||||
draw_move(x, y, x+170, y+60, move);
|
||||
draw_move(x, y, x+125, y+60, move);
|
||||
}
|
||||
|
||||
void execute_move(struct Stats *player_stats, struct Move move) {
|
||||
|
|
45
src/player.c
45
src/player.c
|
@ -55,18 +55,25 @@ int player_facing(struct Game const *game) {
|
|||
return TILE_SOLID;
|
||||
}
|
||||
|
||||
void add_move(struct Player *player, struct Move move) {
|
||||
if(player->moves[1].name == NULL) {
|
||||
player->moves[1] = move;
|
||||
} else {
|
||||
replace_capacities(player, move);
|
||||
int get_nb_moves(struct Player *player) {
|
||||
for(int i = 0; i < NB_PLAYER_MOVES; i++) {
|
||||
if(player->moves[i].name == NULL) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return NB_PLAYER_MOVES;
|
||||
}
|
||||
|
||||
void add_move(struct Player *player, struct Move move) {
|
||||
int index = get_nb_moves(player);
|
||||
if(index != NB_PLAYER_MOVES) player->moves[index] = move;
|
||||
else replace_capacities(player, move);
|
||||
}
|
||||
|
||||
void draw_player_moves(struct Player *player) {
|
||||
draw_classic_move(0,0,player->moves[0]);
|
||||
if(player->moves[1].name != NULL) {
|
||||
draw_classic_move(0,80,player->moves[1]);
|
||||
int index = get_nb_moves(player);
|
||||
for(int i = 0; i < index; i++) {
|
||||
draw_classic_move(0,65*i,player->moves[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,15 +83,16 @@ void replace_capacities(struct Player *player, struct Move move) {
|
|||
while(1) {
|
||||
clearevents();
|
||||
|
||||
selection += keydown(KEY_RIGHT) - keydown(KEY_LEFT);
|
||||
if(selection > 1) selection = 1;
|
||||
selection += keydown(KEY_DOWN) - keydown(KEY_UP);
|
||||
if(selection > NB_PLAYER_MOVES-1) selection = NB_PLAYER_MOVES-1;
|
||||
if(selection < 0) selection = 0;
|
||||
|
||||
draw_classic_move(115,DHEIGHT/2-65, move);
|
||||
draw_classic_move(20,DHEIGHT/2+5, player->moves[0]);
|
||||
draw_classic_move(210,DHEIGHT/2+5, player->moves[1]);
|
||||
draw_classic_move(200,DHEIGHT/2-30, move);
|
||||
for(int i = 0; i < NB_PLAYER_MOVES; i++) {
|
||||
draw_classic_move(0,65*i, player->moves[i]);
|
||||
}
|
||||
|
||||
dtext(95 + (selection * 190), DHEIGHT/2+50 , C_RED, "[X]");
|
||||
dtext(105, 45+65*selection , C_RED, "[X]");
|
||||
dupdate();
|
||||
|
||||
if(keydown(KEY_SHIFT)) {
|
||||
|
@ -95,7 +103,7 @@ void replace_capacities(struct Player *player, struct Move move) {
|
|||
selection = -1;
|
||||
break;
|
||||
}
|
||||
while(keydown(KEY_SHIFT)) clearevents();
|
||||
while(keydown_any(KEY_DOWN,KEY_UP, KEY_SHIFT,0)) clearevents();
|
||||
}
|
||||
if(selection >= 0) {
|
||||
player->moves[selection] = move;
|
||||
|
@ -103,9 +111,10 @@ void replace_capacities(struct Player *player, struct Move move) {
|
|||
}
|
||||
|
||||
void draw_ui(struct Player *player) {
|
||||
draw_classic_move(20,DHEIGHT-80, player->moves[0]);
|
||||
if(player->moves[1].name != NULL) {
|
||||
draw_classic_move(210,DHEIGHT-80, player->moves[1]);
|
||||
int index = get_nb_moves(player);
|
||||
|
||||
for(int i = 0; i < index; i++) {
|
||||
draw_classic_move(2+132*i,DHEIGHT-80, player->moves[i]);
|
||||
}
|
||||
|
||||
const int WIDTH_HP = 100;
|
||||
|
|
Loading…
Reference in New Issue