Areas can now handle events

pull/2/head
bgiraudr 5 months ago
parent 53bf0daaa3
commit 90503c7e97
  1. 37
      assets-cg/converters.py
  2. 13
      assets-cg/maps/testCarte.tmx
  3. 1
      include/map.h
  4. 6
      src/engine.c
  5. 8
      src/monster.c
  6. 9
      src/player.c

@ -189,28 +189,25 @@ def parseZone(layer):
zone += fxconv.u32(origin[1])
zone += fxconv.u32(to[0])
zone += fxconv.u32(to[1])
zone += fxconv.string(i["properties"][0]["value"]) #event
print(i["properties"][0]["value"])
monsters = bytes()
try:
zone += fxconv.u32(i["properties"][0]["value"])
monster_list_raw = i["properties"][1]["value"].split(";")
monster_list = []
#x-y notation generate an array
for i in monster_list_raw:
if "-" in i:
a = i.split("-")
monster_list.extend(list(range(int(a[0]),int(a[1])+1)))
else:
monster_list.append(int(i))
zone += fxconv.u32(len(monster_list))
for j in monster_list:
monsters += fxconv.u16(int(j))
except IndexError:
raise Exception(f"parseZone() : La zone {origin};{to} n'a pas de monstres associés")
except KeyError:
print(f"parseZone() : Zone {origin};{to} sans niveau de référence, passage automatique à -1")
zone += fxconv.u32(-1)
zone += fxconv.u32(int(i["properties"][1]["value"]) if i["properties"][1]["value"] != "" else -1) #level
monster_list_raw = []
if i["properties"][2]["value"] != "": monster_list_raw = i["properties"][2]["value"].split(";") #monster list
monster_list = []
#x-y notation generate an array
for i in monster_list_raw:
if "-" in i:
a = i.split("-")
monster_list.extend(list(range(int(a[0]),int(a[1])+1)))
else:
monster_list.append(int(i))
zone += fxconv.u32(len(monster_list))
for j in monster_list:
monsters += fxconv.u16(int(j))
zone += fxconv.ptr(monsters)
return zone

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="100" height="38" tilewidth="16" tileheight="16" infinite="0" nextlayerid="14" nextobjectid="63">
<map version="1.8" tiledversion="1.8.4" orientation="orthogonal" renderorder="right-down" width="100" height="38" tilewidth="16" tileheight="16" infinite="0" nextlayerid="14" nextobjectid="65">
<editorsettings>
<export target="testCarte.json" format="json"/>
</editorsettings>
@ -216,12 +216,21 @@
<objectgroup id="13" name="zone">
<object id="57" x="400" y="464" width="32" height="48">
<properties>
<property name="event" value=""/>
<property name="level" type="int" value="30"/>
<property name="monsters" value="1"/>
</properties>
</object>
<object id="58" x="304" y="560" width="112" height="32">
<object id="58" x="256" y="464" width="112" height="32">
<properties>
<property name="event" value="xp:30"/>
<property name="level" value=""/>
<property name="monsters" value=""/>
</properties>
</object>
<object id="64" x="304" y="560" width="112" height="32">
<properties>
<property name="event" value=""/>
<property name="level" type="int" value="5"/>
<property name="monsters" value="1;2"/>
</properties>

@ -11,6 +11,7 @@ struct Teleporter {
struct Zone {
int start_x, start_y;
int end_x, end_y;
char *event;
int level;
int nbMonsters;
short *monsters;

@ -1,5 +1,6 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <string.h>
#include "engine.h"
#include "game.h"
@ -15,6 +16,7 @@
#include "util.h"
#include "inventory.h"
#include "item.h"
#include "event.h"
/*draw the current state of the game*/
void engine_draw(struct Game const *game) {
@ -145,6 +147,10 @@ void engine_action(struct Game *game, int action) {
void engine_check_position(struct Game *game) {
static struct Map *old_map;
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);
}
int player_curr_tile = map_get_player_tile(game);
if(player_curr_tile == TILE_DOOR_IN) {

@ -31,8 +31,12 @@ struct Monster *generate_monster(struct Game *game) {
struct Monster *monster;
if(is_in_zone(game->player, game->map)) {
struct Zone zone = get_zone(game->player, game->map);
monster = copyMonster(get_monster_id(zone.monsters[rand_range(0,zone.nbMonsters)]));
level_zone = zone.level;
if(zone.nbMonsters != 0) {
monster = copyMonster(get_monster_id(zone.monsters[rand_range(0,zone.nbMonsters)]));
} else {
monster = copyMonster(get_monster_id(0));
}
level_zone = zone.level != -1 ? zone.level : game->player->stats.level;
} else {
monster = copyMonster(get_monster_id(0));
level_zone = game->player->stats.level;

@ -96,14 +96,13 @@ int get_nb_moves(struct Player *player) {
void add_move(struct Player *player, struct Move move) {
int index = get_nb_moves(player);
dimage(42,DHEIGHT-75,&img_dialogue);
if(index != NB_PLAYER_MOVES) {
dprint(50,DHEIGHT-47,C_BLACK,"Vous apprenez %s !", move.name);
format_text(50, DHEIGHT-47, C_BLACK, "Vous apprenez %s !", move.name);
dupdate();
wait_for_input(KEY_SHIFT);
player->moves[index] = copy_move(move);
} else {
dprint(50,DHEIGHT-47,C_BLACK,"Vous pouvez apprendre %s !", move.name);
format_text(50, DHEIGHT-47, C_BLACK, "Vous pouvez apprendre %s !", move.name);
dupdate();
wait_for_input(KEY_SHIFT);
replace_capacities(player, move);
@ -128,7 +127,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");
dtext(180,15,C_BLACK, "Remplacer");
draw_classic_move(200,DHEIGHT/2-30, &move);
draw_player_moves(player);
@ -162,7 +161,7 @@ int select_capacity(struct Player *player, char* context, bool allow_back) {
if(selection > NB_PLAYER_MOVES-1) selection = NB_PLAYER_MOVES-1;
if(selection < 0) selection = 0;
dtext(130,10,C_BLACK,context);
dtext(180,10,C_BLACK,context);
draw_player_moves(player);
dtext(105, 42+65*selection , C_RED, "[X]");

Loading…
Cancel
Save