add some events

pull/2/head
bgiraudr 5 months ago
parent 8c3138209b
commit 53bf0daaa3
  1. 3
      assets-cg/items/1.json
  2. 3
      assets-cg/items/2.json
  3. 2
      assets-cg/maps/testCarte.tmx
  4. 3
      include/item.h
  5. 4
      include/player.h
  6. 27
      src/event.c
  7. 3
      src/inventory.c
  8. 7
      src/item.c
  9. 50
      src/player.c
  10. 7
      src/talkable.c

@ -4,6 +4,7 @@
"sprite":"item",
"description":"Redonne 20HP",
"action":[
"xp:20"
"pp:all",
"give:Obj2*3"
]
}

@ -4,7 +4,6 @@
"sprite":"item2",
"description":"test2",
"action":[
"xp:40",
"move:2"
"pp:3"
]
}

@ -188,7 +188,7 @@
<object id="62" gid="267" x="448" y="432" width="16" height="16">
<properties>
<property name="name" value="Pancarte"/>
<property name="text" value="Cadeau;~give:1"/>
<property name="text" value="Cadeau;~give:Obj2"/>
</properties>
</object>
</objectgroup>

@ -18,4 +18,5 @@ struct Items {
struct Item *get_item_id(int id);
void select_item(struct Game *game, int pos);
void remove_item_pos(struct Inventory *inventory, int pos);
void remove_item_pos(struct Inventory *inventory, int pos);
struct Item *get_item_from_name(const char *name);

@ -52,4 +52,6 @@ void draw_ui(struct Player *player);
int get_nb_moves(struct Player *player);
void reset_pp(struct Player *player);
void check_level(struct Player *player, int prec_level);
void add_xp(struct Player *player, int xp);
void add_xp(struct Player *player, int xp);
int select_capacity(struct Player *player, char* context, bool allow_back);
void add_pp(struct Player *player, int amount);

@ -15,8 +15,14 @@ bool handle_event(struct Game *game, char const *event)
// Isoler le nom et la quantité
int len=strlen(event), qty=1;
char *star = strchr(event, '*');
char name[20];
if(star) len=star-event, qty=atoi(star+1);
add_item_to_inventory(game, &game->player->inventory, get_item_id(2));
strncpy(name,event,len);
name[len] = '\0';
while(qty) {
add_item_to_inventory(game, &game->player->inventory, get_item_from_name(name));
qty--;
}
return true;
}
else if(!strncmp(event, "xp:", 3)) {
@ -24,14 +30,25 @@ bool handle_event(struct Game *game, char const *event)
add_xp(game->player, atoi(event));
return true;
}
else if(!strncmp(event, "hp:", 3)) {
event += 3;
game->player->stats.pv += atoi(event);
if(game->player->stats.pv > game->player->stats.max_pv) game->player->stats.pv = game->player->stats.max_pv;
return true;
}
else if(!strcmp(event, "pp:all")) {
reset_pp(game->player);
return true;
}
else if(!strncmp(event, "pp:", 3)) {
event += 3;
add_pp(game->player, atoi(event));
return true;
}
else if(!strncmp(event, "move:", 5)) {
event += 5;
add_move(game->player, get_move_id(atoi(event)));
return true;
}
else if(!strcmp(event, "test:test")) {
// etc, n'importe quoi de compliqué
return true;
}
return false;
}

@ -24,9 +24,6 @@ int get_first_free_space(struct Inventory *inventory) {
bool add_item_to_inventory(struct Game *game, struct Inventory *inventory, struct Item *item) {
int index = get_first_free_space(inventory);
extern bopti_image_t img_dialogue;
dimage(42,DHEIGHT-75,&img_dialogue);
if(index < NB_PLAYER_ITEMS) {
format_text(50, DHEIGHT-47, C_BLACK, "Vous ajoutez %s à votre inventaire !", item->name);
dupdate();

@ -28,4 +28,11 @@ void select_item(struct Game *game, int pos) {
handle_event(game, curr_line);
curr_line = strtok(NULL, delim);
}
}
struct Item *get_item_from_name(const char *name) {
for(int i = 0; i < items.nbItems; i++) {
if(!strcmp(items.items[i]->name, name)) return items.items[i];
}
return items.items[0];
}

@ -1,5 +1,6 @@
#include <gint/keyboard.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include "player.h"
@ -8,6 +9,8 @@
#include "stats.h"
#include "capacite.h"
#include "util.h"
#include "talkable.h"
extern struct LevelUpPlayer levelupplayer;
extern bopti_image_t img_dialogue;
@ -125,6 +128,7 @@ void replace_capacities(struct Player *player, struct Move move) {
if(selection > NB_PLAYER_MOVES-1) selection = NB_PLAYER_MOVES-1;
if(selection < 0) selection = 0;
dtext(130,15,C_BLACK, "Remplacer");
draw_classic_move(200,DHEIGHT/2-30, &move);
draw_player_moves(player);
@ -147,6 +151,36 @@ void replace_capacities(struct Player *player, struct Move move) {
}
}
int select_capacity(struct Player *player, char* context, bool allow_back) {
int selection = 0;
int buffer = keydown(KEY_SHIFT);
while(1) {
clearevents();
dclear(C_WHITE);
selection += keydown(KEY_DOWN) - keydown(KEY_UP);
if(selection > NB_PLAYER_MOVES-1) selection = NB_PLAYER_MOVES-1;
if(selection < 0) selection = 0;
dtext(130,10,C_BLACK,context);
draw_player_moves(player);
dtext(105, 42+65*selection , C_RED, "[X]");
dupdate();
if(keydown(KEY_SHIFT)) {
if(buffer) buffer = 0;
else break;
}
if(keydown(KEY_EXIT) && allow_back) {
selection = -1;
break;
}
while(keydown_any(KEY_DOWN,KEY_UP, KEY_SHIFT,0)) clearevents();
}
return selection;
}
void draw_ui(struct Player *player) {
int index = get_nb_moves(player);
@ -160,6 +194,9 @@ void reset_pp(struct Player *player) {
for(int i = 0; i < index; i++) {
player->moves[i]->pp = player->moves[i]->init_pp;
}
format_text(50, DHEIGHT-47, C_BLACK, "Vous regagnez les PPs de l'ensemble de vos capacités");
dupdate();
wait_for_input(KEY_SHIFT);
}
void add_xp(struct Player *player, int xp) {
@ -168,13 +205,20 @@ void add_xp(struct Player *player, int xp) {
//niveau suivant une progession N³
int calc_level = (int)pow(player->stats.xp, 0.33);
for(int i = player->stats.level; i < calc_level; i++) {
// draw_battle(game->player, monster);
dimage(42,DHEIGHT-75,&img_dialogue);
dprint(50,DHEIGHT-47,C_BLACK,"Vous passez au niveau %d !", i+1);
format_text(50, DHEIGHT-47, C_BLACK, "Vous passez au niveau %d !", i+1);
dupdate();
wait_for_input(KEY_SHIFT);
}
int prec = player->stats.level;
player->stats.level = calc_level;
check_level(player, prec);
}
void add_pp(struct Player *player, int amount) {
int selection = select_capacity(player, "Choisir une capacité", false);
player->moves[selection]->pp += amount;
if(player->moves[selection]->pp > player->moves[selection]->init_pp) player->moves[selection]->pp = player->moves[selection]->init_pp;
format_text(50, DHEIGHT-47, C_BLACK, "Vous regagnez %d PPs sur %s", amount, player->moves[selection]->name);
dupdate();
wait_for_input(KEY_SHIFT);
}

@ -43,7 +43,6 @@ char *skip_spaces(char *str)
/*draw the dialog of a specified talkable tile*/
void draw_dialog(struct Game *game) {
extern bopti_image_t img_dialogue;
const char *delim = ";";
int direction = game->player->direction;
@ -58,10 +57,8 @@ void draw_dialog(struct Game *game) {
char *event = strchr(curr_line, '~');
if(event) handle_event(game, curr_line+1);
else {
dimage(43,31,&img_dialogue);
dprint(50,40, C_BLACK, "%s", talk->name);
format_text(50, 58, C_BLACK, curr_line);
dprint(50,40, C_BLACK, "%s", talk->name);
dupdate();
wait_for_input(KEY_SHIFT);
@ -82,6 +79,8 @@ struct Talkable* get_dialog_xy(struct Map *map, int x, int y) {
void format_text(int x, int y, const int color, char const *format, ...) {
int const DIALOG_WIDTH = 295, LINE_HEIGHT = 13;
extern bopti_image_t img_dialogue;
dimage(x-7,y-26,&img_dialogue);
char text_arg[512];
va_list args;

Loading…
Cancel
Save