Random monster in zone

pull/2/head
bgiraudr 7 months ago
parent a875d3d359
commit ab67a00d79
  1. 3
      CMakeLists.txt
  2. 61
      assets-cg/converters.py
  3. 2
      assets-cg/maps/testCarte.tmx
  4. 8
      assets-cg/monsters/fxconv-metadata.txt
  5. 0
      assets-cg/monsters/monsters.txt
  6. 5
      assets-cg/monsters/test.json
  7. 16
      assets-cg/monsters/test2.json
  8. BIN
      assets-cg/monsters/test2.png
  9. 5
      include/map.h
  10. 7
      include/monster.h
  11. 18
      src/map.c
  12. 30
      src/monster.c
  13. 2
      src/player.c

@ -61,7 +61,8 @@ set(ASSETS_cg
assets-cg/uf8x9
assets-cg/capacites/capacites.txt
assets-cg/monsters/test.png
assets-cg/monsters/test.json
assets-cg/monsters/test2.png
assets-cg/monsters/monsters.txt
)
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)

@ -187,11 +187,20 @@ def parseZone(layer):
zone += fxconv.u32(to[0])
zone += fxconv.u32(to[1])
monsters = bytes()
try:
zone += fxconv.u32(i["properties"][0]["value"])
monster_list = i["properties"][1]["value"].split(";")
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.ptr(monsters)
return zone
def convert_capa(input, output, params, target):
@ -229,23 +238,35 @@ def convert_capa(input, output, params, target):
fxconv.elf(capacities, output, "_" + params["name"], **target)
def convert_monster(input, output, params, target):
file = open(input, "r")
data = json.load(file)
stats = fxconv.Structure()
if len(data["stats"]) != 6: raise Exception(f"convert_monster : Les statistiques de {data['name']} sont mauvaises")
for i in data["stats"].values():
stats+=fxconv.u32(i)
moves = bytes()
for i in data["moves"]:
moves+=fxconv.u16(i)
monster = fxconv.Structure()
monster += fxconv.string(data["name"])
monster += fxconv.ptr(f"img_{data['sprite']}")
monster += fxconv.u32(len(data["moves"]))
monster += fxconv.ptr(stats)
monster += fxconv.ptr(moves)
fxconv.elf(monster, output, "_" + params["name"], **target)
liste_file = list(pathlib.Path(input).parent.glob('*.json'))
monsters = fxconv.Structure()
monsters += fxconv.u32(len(liste_file))
for f in liste_file:
file = open(f,"r")
data = json.load(file)
stats = fxconv.Structure()
if len(data["stats"]) != 4: raise Exception(f"convert_monster : Les statistiques de {data['name']} sont mauvaises")
stats+=fxconv.u32(data["stats"]["atk"])
stats+=fxconv.u32(data["stats"]["def"])
stats+=fxconv.u32(data["stats"]["pv"])
stats+=fxconv.u32(1)
stats+=fxconv.u32(data["stats"]["xp"])
stats+=fxconv.u32(data["stats"]["pv"])
moves = bytes()
for i in data["moves"]:
moves+=fxconv.u16(i)
monster = fxconv.Structure()
monster += fxconv.string(data["name"])
monster += fxconv.ptr(f"img_{data['sprite']}")
monster += fxconv.u32(data["id"])
monster += fxconv.u32(len(data["moves"]))
monster += fxconv.ptr(stats)
monster += fxconv.ptr(moves)
monsters += fxconv.ptr(monster)
fxconv.elf(monsters, output, "_" + params["name"], **target)

@ -205,11 +205,13 @@
<object id="57" x="400" y="464" width="32" height="48">
<properties>
<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">
<properties>
<property name="level" type="int" value="5"/>
<property name="monsters" value="1;2"/>
</properties>
</object>
</objectgroup>

@ -1,7 +1,7 @@
test.png:
*.png:
type: bopti-image
name: img_test
name_regex: (.*)\.png img_\1
*.json:
monsters.txt:
custom-type: monster
name_regex: (.*)\.json monster_\1
name: monsters

@ -1,13 +1,12 @@
{
"name":"test",
"sprite":"test",
"id":1,
"stats":{
"atk":10,
"def":10,
"pv":20,
"level":1,
"xp":300,
"max_pv":20
"xp":300
},
"moves":[
0,

@ -0,0 +1,16 @@
{
"name":"Citron",
"sprite":"test2",
"id":2,
"stats":{
"atk":80,
"def":5,
"pv":45,
"xp":150
},
"moves":[
0,
1,
2
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

@ -12,6 +12,8 @@ struct Zone {
int start_x, start_y;
int end_x, end_y;
int level;
int nbMonsters;
short *monsters;
};
struct Map {
@ -53,4 +55,5 @@ struct Vec2 locate_tile(struct Map const *map, int tile);
struct Teleporter get_teleporter_xy(struct Map *map, struct Vec2 pos);
int get_level_zone(struct Player *player, struct Map *map);
int is_in_zone(struct Player *player, struct Map *map);
struct Zone get_zone(struct Player *player, struct Map *map);

@ -8,11 +8,18 @@
struct Monster {
char *name;
bopti_image_t *sprite;
int id;
int nbMoves;
struct Stats *stats;
short *moves;
};
struct Monsters {
int nbMonsters;
struct Monster *monster[];
};
struct Monster *get_monster_id(int id);
struct Monster *generate_monster(struct Game *game);
struct Move *monster_select(struct Player *player, struct Monster *monster);
struct Monster *copyMonster(struct Monster *source);

@ -67,12 +67,22 @@ struct Teleporter get_teleporter_xy(struct Map *map, struct Vec2 pos) {
return map->teleporters[0];
}
int get_level_zone(struct Player *player, struct Map *map) {
int is_in_zone(struct Player *player, struct Map *map) {
const int posx = player->pos.x;
const int posy = player->pos.y;
for(int i = 0; i < map->zone_count; i++) {
const struct Zone zone = map->zones[i];
if(zone.start_x <= posx && zone.start_y <= posy && zone.end_x >= posx && zone.end_y >= posy) return zone.level;
struct Zone zone = map->zones[i];
if(zone.start_x <= posx && zone.start_y <= posy && zone.end_x >= posx && zone.end_y >= posy) return 1;
}
return -1;
return 0;
}
struct Zone get_zone(struct Player *player, struct Map *map) {
const int posx = player->pos.x;
const int posy = player->pos.y;
for(int i = 0; i < map->zone_count; i++) {
struct Zone zone = map->zones[i];
if(zone.start_x <= posx && zone.start_y <= posy && zone.end_x >= posx && zone.end_y >= posy) return zone;
}
return map->zones[0];
}

@ -9,16 +9,33 @@
#include "map.h"
#include "util.h"
struct Monster *generate_monster(struct Game *game) {
extern struct Monster monster_test;
#include <gint/display.h>
#include <gint/keyboard.h>
extern struct Monsters monsters;
struct Monster *get_monster_id(int id) {
for(int i = 0; i < monsters.nbMonsters; i++) {
if(monsters.monster[i]->id == id) return monsters.monster[i];
}
return monsters.monster[0];
}
struct Monster *monster = copyMonster(&monster_test);
struct Monster *generate_monster(struct Game *game) {
srand(rtc_ticks());
int level_zone = get_level_zone(game->player, game->map);
//En cas d'erreur / aucune zone trouvée
if(level_zone == -1) {
int level_zone;
//set the monster depends of the current zone
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;
} else {
monster = copyMonster(get_monster_id(0));
level_zone = game->player->stats.level;
}
@ -62,6 +79,7 @@ struct Monster *copyMonster(struct Monster *source) {
dest->name = source->name;
dest->nbMoves = source->nbMoves;
dest->sprite = source->sprite;
dest->id = source->id;
dest->moves = malloc(dest->nbMoves * sizeof *source->moves);
memcpy(dest->moves, source->moves, dest->nbMoves * sizeof *source->moves);

@ -93,7 +93,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;
// draw_classic_move(200,DHEIGHT/2-30, move);
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]);
}

Loading…
Cancel
Save