Only execute event once for area

This commit is contained in:
bgiraudr 2022-05-22 16:46:31 +02:00
parent 83920a57bc
commit 367c61effd
16 changed files with 146 additions and 75 deletions

View File

@ -22,8 +22,6 @@ def convert(input, output, params, target):
elif params["custom-type"] == "table_type":
convert_table_type(input, output, params, target)
return 0
elif params["custom-type"] == "test":
test(input, output, params, target)
else:
return 1
@ -93,6 +91,11 @@ def convert_map(input, output, params, target):
teleporter = fxconv.Structure()
zone = fxconv.Structure()
try:
idmap = data["properties"][0]["value"]
except KeyError:
raise Exception("La carte n'a pas d'identifiant")
for layer in objectLayers:
if layer.get("name") == DIALOG_LAYOUT:
nbDialog = len(layer["objects"])
@ -102,7 +105,7 @@ def convert_map(input, output, params, target):
teleporter = parseTeleporter(layer)
elif layer.get("name") == ZONE_LAYOUT:
nbZone = len(layer["objects"])
zone = parseZone(layer)
zone = parseZone(layer, idmap)
else:
print("UNKNOWN LAYER FOUND : " + layer.get("name"))
@ -183,17 +186,22 @@ def parseTeleporter(layer):
raise Exception("parseTeleporter() : Un téléporteur est mal configuré")
return teleporter
def parseZone(layer):
def parseZone(layer, idmap):
zone = fxconv.Structure()
idZone = 0
for i in layer["objects"]:
origin = (int(i['x']/16), int(i['y']/16))
to = (int(origin[0]+i['width']/16)-1, int(origin[1]+i['height']/16)-1)
if len(i["properties"][0]["value"]) != 0:
zone += fxconv.u32(int(f"{idmap}{idZone}{idmap}")) #id zone is {mapid}{idzone}{mapid}
idZone+=1
else: zone += fxconv.u32(0)
zone += fxconv.u32(origin[0])
zone += fxconv.u32(origin[1])
zone += fxconv.u32(to[0])
zone += fxconv.u32(to[1])
event = bytes(i["properties"][0]["value"], "utf-8")
event += bytes(128 - len(event))
zone += event #event

View File

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.8" tiledversion="1.8.2" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="16" tileheight="16" infinite="0" nextlayerid="13" nextobjectid="45">
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="100" height="100" tilewidth="16" tileheight="16" infinite="0" nextlayerid="13" nextobjectid="45">
<editorsettings>
<export target="interior_1.json" format="json"/>
</editorsettings>
<properties>
<property name="id" type="int" value="2"/>
</properties>
<tileset firstgid="1" source="tileset.tsx"/>
<layer id="5" name="1" width="100" height="100">
<data encoding="csv">

View File

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="12" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="13" nextobjectid="38">
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="12" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="13" nextobjectid="38">
<editorsettings>
<export target="interior_1.json" format="json"/>
</editorsettings>
<properties>
<property name="id" type="int" value="3"/>
</properties>
<tileset firstgid="1" source="tileset_in.tsx"/>
<layer id="5" name="1" width="12" height="10">
<data encoding="csv">

View File

@ -1,8 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.8" tiledversion="1.8.1" orientation="orthogonal" renderorder="right-down" width="15" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="16" nextobjectid="43">
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="15" height="10" tilewidth="16" tileheight="16" infinite="0" nextlayerid="16" nextobjectid="43">
<editorsettings>
<export target="interior_1.json" format="json"/>
</editorsettings>
<properties>
<property name="id" type="int" value="4"/>
</properties>
<tileset firstgid="1" source="tileset_in.tsx"/>
<layer id="11" name="1" width="15" height="10">
<data encoding="csv">

View File

@ -3,6 +3,9 @@
<editorsettings>
<export target="testCarte.json" format="json"/>
</editorsettings>
<properties>
<property name="identifiant" type="int" value="1"/>
</properties>
<tileset firstgid="1" source="tileset.tsx"/>
<layer id="5" name="1" width="100" height="38">
<data encoding="csv">

View File

@ -25,7 +25,6 @@ struct Capacities {
enum status {
MISS,
SUCCESS,
CRIT,
HEAL,
ATK,
DEF,
@ -43,7 +42,7 @@ enum categorie {
struct Move default_move();
struct Move get_move_id(int id);
void draw_move(int x, int y, int x2, int y2, struct Move *move);
void draw_move(int x, int y, int x2, int y2, struct Move *move, int selected);
void draw_classic_move(int x, int y, struct Move *move);
int execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct Move *move, int ismonster);
int calc_damage(struct Stats *attacker, struct Stats *target, struct Move *move);
@ -53,4 +52,5 @@ float crit(struct Stats *attacker);
int is_crit();
int is_miss(struct Move *move);
int self_effect(struct Stats *stats, struct Move *move);
float stab(char *type, char *move);
float stab(char *type, char *move);
void draw_special_move(int x, int y, struct Move *move, int selected);

View File

@ -1,9 +1,8 @@
#pragma once
/*the size of one tile*/
#define TILE_SIZE 16
#define NB_INTERIORS 2
#define NB_PLAYER_MOVES 3
#define NB_PLAYER_ITEMS 30
#define NB_TYPES 4
#define NB_TYPES 4
#define NB_STO_ZONE 300

View File

@ -9,6 +9,7 @@ struct Teleporter {
};
struct Zone {
int id;
int start_x, start_y;
int end_x, end_y;
char event[128];
@ -58,4 +59,5 @@ struct Vec2 locate_tile(struct Map const *map, int tile);
struct Teleporter get_teleporter_xy(struct Map *map, struct Vec2 pos);
int is_in_zone(struct Player *player, struct Map *map);
struct Zone get_zone(struct Player *player, struct Map *map);
struct Zone get_zone(struct Player *player, struct Map *map);
void addZoneToPlayer(struct Player *player, struct Zone zone);

View File

@ -32,6 +32,7 @@ struct Player {
/*the current animation*/
int idle;
struct AnimData anim;
int eventListZone[NB_STO_ZONE];
};
struct LevelUp {
@ -50,7 +51,7 @@ 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 curr_select);
int get_nb_moves(struct Player *player);
void reset_pp(struct Player *player);
void check_level(struct Player *player, int prec_level);
@ -58,4 +59,6 @@ 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);
void change_type(struct Player *player, struct Type type);
int yes_no_question(char const *format, ...);
bool has_move(struct Player *player, struct Move move);
int get_nb_eventzone(struct Player *player);
bool check_eventzone(struct Player *player, int id);

View File

@ -5,4 +5,5 @@ void wait_for_input(int input);
int rand_range(int low, int high);
void format_text_opt(int x, int y, int width, int height, const int color, char const *format, ...);
char *word_boundary_before(char *str, char *limit);
char *skip_spaces(char *str);
char *skip_spaces(char *str);
int yes_no_question(char const *format, ...);

View File

@ -76,9 +76,6 @@ void check_move_status(int status, struct Player *player, struct Monster *monste
draw_battle(player, monster);
switch(status){
case CRIT:
draw_status(name, "réalise un coup critique !");
break;
case MISS:
draw_status(name, "rate son attaque !");
break;
@ -108,6 +105,11 @@ void check_move_status(int status, struct Player *player, struct Monster *monste
dupdate();
wait_for_input(KEY_SHIFT);
}
if(is_crit() && (status == LESS_EFFECTIVE || status == SUPER_EFFECTIVE)) {
draw_status(name, "réalise un coup critique !");
dupdate();
wait_for_input(KEY_SHIFT);
}
}
/*When a battle is finish, compute xp gain and gain level*/
@ -153,7 +155,7 @@ int select_move(struct Player *player, struct Monster *monster, int prec_selecte
dclear(C_RGB(25,25,25));
draw_battle(player, monster);
draw_ui(player);
draw_ui(player, selection);
dtext(58 + (selection * 130), DHEIGHT-15 , C_RED, "[X]");
dupdate();

View File

@ -49,12 +49,13 @@ struct Move *copy_move(struct Move move) {
return copyMove;
}
void draw_move(int x, int y, int x2, int y2, struct Move *move) {
void draw_move(int x, int y, int x2, int y2, struct Move *move, int selected) {
extern bopti_image_t img_capacite;
extern bopti_image_t img_categories;
const int font_size = 8;
draw_change_one_color(x, y, &img_capacite, 0xE6D6, getTypeFromName(move->type).color);
if(!selected) draw_change_one_color(x, y, &img_capacite, 0xE6D6, getTypeFromName(move->type).color);
else draw_change_one_color(x, y, &img_capacite, 0xE6D6, 0x0FE0);
dsubimage(x+96, y+7, &img_categories, 20*move->categorie, 0, 20, 10, DIMAGE_NONE);
int color = move->pp > 0 ? C_BLACK : C_RED;
@ -73,8 +74,12 @@ void draw_move(int x, int y, int x2, int y2, struct Move *move) {
}
}
void draw_special_move(int x, int y, struct Move *move, int selected) {
draw_move(x, y, x+125, y+60, move, selected);
}
void draw_classic_move(int x, int y, struct Move *move) {
draw_move(x, y, x+125, y+60, move);
draw_move(x, y, x+125, y+60, move, 0);
}
int execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct Move *move, int ismonster) {
@ -98,7 +103,6 @@ int execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct
if(typeEffect == 2) return SUPER_EFFECTIVE;
if(typeEffect == 0.5) return LESS_EFFECTIVE;
if(typeEffect == 0) return NOT_EFFECTIVE;
if(is_crit()) return CRIT;
} else {
if(ismonster) {
return self_effect(monster_stats, move);
@ -137,7 +141,7 @@ float stab(char *type, char *move) {
int is_crit() {
//une chance sur 16 d'avoir un coup critique
const int proba_crit = 16;
const int proba_crit = 2;
return rand_range(0,proba_crit)==0;
}

View File

@ -152,7 +152,12 @@ void engine_check_position(struct Game *game) {
static struct Vec2 old_pos;
if(is_in_zone(game->player, game->map)) {
struct Zone zone = get_zone(game->player, game->map);
if(strcmp(zone.event, "")) handle_event(game, zone.event);
if(!check_eventzone(game->player, zone.id)) {
if(strcmp(zone.event, "")) {
addZoneToPlayer(game->player, zone);
handle_event(game, zone.event);
}
}
}
int player_curr_tile = map_get_player_tile(game);

View File

@ -95,4 +95,8 @@ struct Zone get_zone(struct Player *player, struct Map *map) {
if(zone.start_x <= posx && zone.start_y <= posy && zone.end_x >= posx && zone.end_y >= posy) return zone;
}
return default_zone;
}
void addZoneToPlayer(struct Player *player, struct Zone zone) {
player->eventListZone[get_nb_eventzone(player)] = zone.id;
}

View File

@ -98,18 +98,32 @@ int get_nb_moves(struct Player *player) {
return NB_PLAYER_MOVES;
}
bool has_move(struct Player *player, struct Move move) {
int index = get_nb_moves(player);
for(int i = 0; i < index; i++) {
if(player->moves[i]->id == move.id) return true;
}
return false;
}
void add_move(struct Player *player, struct Move move) {
int index = get_nb_moves(player);
if(index != NB_PLAYER_MOVES) {
draw_text(50, DHEIGHT-47, C_BLACK, "Vous apprenez %s !", move.name);
dupdate();
wait_for_input(KEY_SHIFT);
player->moves[index] = copy_move(move);
if(!has_move(player, move)) {
if(index != NB_PLAYER_MOVES) {
draw_text(50, DHEIGHT-47, C_BLACK, "Vous apprenez %s !", move.name);
dupdate();
wait_for_input(KEY_SHIFT);
player->moves[index] = copy_move(move);
} else {
draw_text(50, DHEIGHT-47, C_BLACK, "Vous pouvez apprendre %s !", move.name);
dupdate();
wait_for_input(KEY_SHIFT);
replace_capacities(player, move);
}
} else {
draw_text(50, DHEIGHT-47, C_BLACK, "Vous pouvez apprendre %s !", move.name);
draw_text(50, DHEIGHT-47, C_BLACK, "Vous connaissez déjà la capacité %s !", move.name);
dupdate();
wait_for_input(KEY_SHIFT);
replace_capacities(player, move);
}
}
@ -184,11 +198,11 @@ int select_capacity(struct Player *player, char* context, bool allow_back) {
return selection;
}
void draw_ui(struct Player *player) {
void draw_ui(struct Player *player, int curr_select) {
int index = get_nb_moves(player);
for(int i = 0; i < index; i++) {
draw_classic_move(2+132*i,DHEIGHT-70, player->moves[i]);
draw_special_move(2+132*i,DHEIGHT-70, player->moves[i], i == curr_select);
}
}
@ -226,44 +240,6 @@ void add_pp(struct Player *player, int amount) {
wait_for_input(KEY_SHIFT);
}
int yes_no_question(char const *format, ...) {
char text_arg[512];
va_list args;
va_start(args, format);
vsnprintf(text_arg, 512, format, args);
va_end(args);
int selection = 0;
int buffer = keydown(KEY_SHIFT);
while(1) {
clearevents();
dclear(C_WHITE);
selection += keydown(KEY_RIGHT) - keydown(KEY_LEFT);
if(selection > 1) selection = 1;
if(selection < 0) selection = 0;
format_text_opt(95,10, 200, 13, C_BLACK, text_arg);
dtext(95,150,C_BLACK, "NON");
dtext(285,150,C_BLACK, "OUI");
dtext(95 + (selection * 190), DHEIGHT-47, C_RED, "[X]");
dupdate();
if(keydown(KEY_SHIFT)) {
if(buffer) buffer = 0;
else break;
}
if(keydown(KEY_EXIT)) {
selection = 0;
break;
}
while(keydown_any(KEY_LEFT,KEY_RIGHT, KEY_SHIFT,0)) clearevents();
}
return selection;
}
void change_type(struct Player *player, struct Type type) {
if(strcmp(player->stats.type, type.name) != 0) {
int selection = yes_no_question("Voulez vous changer votre type %s en %s ?", player->stats.type, type.name);
@ -273,4 +249,21 @@ void change_type(struct Player *player, struct Type type) {
dupdate();
wait_for_input(KEY_SHIFT);
}
}
int get_nb_eventzone(struct Player *player) {
for(int i = 0; i < 300; i++) {
if(player->eventListZone[i] == 0) {
return i;
}
}
return 0;
}
bool check_eventzone(struct Player *player, int id) {
for(int i = 0; i < 300; i++) {
if(player->eventListZone[i] == id) return true;
if(player->eventListZone[i] == 0) return false;
}
return false;
}

View File

@ -66,4 +66,42 @@ void format_text_opt(int x, int y, int width, int height, const int color, char
text = skip_spaces(last_word);
y += LINE_HEIGHT;
}
}
int yes_no_question(char const *format, ...) {
char text_arg[512];
va_list args;
va_start(args, format);
vsnprintf(text_arg, 512, format, args);
va_end(args);
int selection = 0;
int buffer = keydown(KEY_SHIFT);
while(1) {
clearevents();
dclear(C_WHITE);
selection += keydown(KEY_RIGHT) - keydown(KEY_LEFT);
if(selection > 1) selection = 1;
if(selection < 0) selection = 0;
format_text_opt(95,10, 200, 13, C_BLACK, text_arg);
dtext(95,150,C_BLACK, "NON");
dtext(285,150,C_BLACK, "OUI");
dtext(95 + (selection * 190), DHEIGHT-47, C_RED, "[X]");
dupdate();
if(keydown(KEY_SHIFT)) {
if(buffer) buffer = 0;
else break;
}
if(keydown(KEY_EXIT)) {
selection = 0;
break;
}
while(keydown_any(KEY_LEFT,KEY_RIGHT, KEY_SHIFT,0)) clearevents();
}
return selection;
}