add item spawns in level 1

This commit is contained in:
Lephenixnoir 2022-03-16 19:00:22 +00:00
parent 2094618c01
commit 28a397a6e8
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
7 changed files with 106 additions and 73 deletions

View File

@ -29,6 +29,26 @@ def convert(input, output, params, target):
return 1
MONSTER_IDS = {
"slime/1": 1,
"bat/2": 2,
"fire_slime/4": 3,
"gunslinger/8": 4,
}
ITEM_IDS = {
"life": 0,
"potion_atk": 1,
"potion_cooldown": 2,
"potion_def": 3,
"potion_freeze": 4,
"potion_hp": 5,
"potion_speed": 6,
"scepter1": 101,
"scepter2": 102,
"sword1": 103,
"sword2": 104,
}
def convert_level(input, params):
RE_VALUES = {
"name": re.compile(r'.*'),
@ -36,7 +56,8 @@ def convert_level(input, params):
"spawner": re.compile(r'\d+,\d+'),
"player_spawn": re.compile(r'\d+,\d+'),
"wave": re.compile(r'\d+s(\s+\d+\*[a-z_]+/\d+)+'),
"delay": re.compile(r'\d+s')
"delay": re.compile(r'\d+s'),
"item": re.compile(r'[a-zA-Z_][a-zA-Z0-9_]*'),
}
with open(input, "r") as fp:
lines = [l for l in fp.read().splitlines() if l]
@ -107,17 +128,9 @@ def convert_level(input, params):
duration = int(duration[:-1])
for i, desc in enumerate(monsters):
count, identity = desc.split("*")
if identity == "slime/1":
identity = 1
elif identity == "bat/2":
identity = 2
elif identity == "fire_slime/4":
identity = 3
elif identity == "gunslinger/8":
identity = 4
else:
if identity not in MONSTER_IDS:
raise fxconv.FxconvError(f"unknown monster {identity}")
monsters[i] = (identity, int(count))
monsters[i] = (MONSTER_IDS[identity], int(count))
m = bytes()
for identity, amount in monsters:
@ -133,10 +146,9 @@ def convert_level(input, params):
event_count += 1
elif key == "item":
raise fxconv.FxconvError("coming soon x3")
events += fxconv.u32(LEVEL_EVENT_ITEM)
events += fxconv.u32(2 * 65536)
events += fxconv.u32(the_item)
events += fxconv.u32(ITEM_IDS[value])
event_count += 1
o = fxconv.Structure()

View File

@ -6,11 +6,11 @@ player_spawn: 12,5
spawner: 18,5
spawner: 5,7
wave: 8s 8*slime/1
wave: 12s 10*slime/1 4*bat/2
delay: 2s
wave: 4s 8*bat/2
delay: 2s
wave: 12s 12*slime/1
wave: 18s 10*slime/1 4*bat/2
item: life
wave: 4s 6*bat/2
item: sword1
wave: 8s 16*slime/1 8*bat/2
delay: 2s
wave: 6s 8*slime/1 8*bat/2 2*fire_slime/4

View File

@ -127,6 +127,33 @@ void game_next_event(game_t *g)
for(int i = 0; i < event->wave->entry_count; i++)
g->wave_left[i] = event->wave->entries[i].amount;
}
if(event && event->type == LEVEL_EVENT_ITEM) {
int x=-1, y=-1;
for(int i = 0; i < 100; i++) {
int cx = rand() % g->map->width;
int cy = rand() % g->map->height;
map_cell_t const *cell = map_cell(g->map, cx, cy);
__auto_type tiles = g->map->tileset->tiles;
if(!tiles[cell->base].solid &&
(!cell->decor || !tiles[cell->decor].solid)) {
x = cx;
y = cy;
break;
}
}
/* If a position can't be found, place the item on the player */
if(x < 0 || y < 0) {
physical_t *p = getcomp(g->player, physical);
x = ffloor(p->x);
y = ffloor(p->y);
}
entity_t *item = item_make(event->item,
(vec2){ fix(x)+fix(0.5), fix(y)+fix(0.5) });
game_add_entity(g, item);
}
}
void game_shake(game_t *g, int amplitude, fixed_t duration)

View File

@ -5,6 +5,33 @@
#include "comp/visible.h"
#include <gint/defs/util.h>
anim_t const *item_anim(int item)
{
if(item == ITEM_LIFE)
return &anims_item_life;
else if(item == ITEM_POTION_ATK)
return &anims_item_potion_atk;
else if(item == ITEM_POTION_COOLDOWN)
return &anims_item_potion_cooldown;
else if(item == ITEM_POTION_DEF)
return &anims_item_potion_def;
else if(item == ITEM_POTION_FRZ)
return &anims_item_potion_frz;
else if(item == ITEM_POTION_HP)
return &anims_item_potion_hp;
else if(item == ITEM_POTION_SPD)
return &anims_item_potion_spd;
else if(item == ITEM_SCEPTER1)
return &anims_item_stick1;
else if(item == ITEM_SCEPTER2)
return &anims_item_stick2;
else if(item == ITEM_SWORD1)
return &anims_item_sword1;
else if(item == ITEM_SWORD2)
return &anims_item_sword2;
return NULL;
}
entity_t *item_make(int type, vec2 position)
{
entity_t *e = aoe_make(AOE_ITEM, position, fix(9999.0));
@ -22,40 +49,9 @@ entity_t *item_make(int type, vec2 position)
aoe->repeat_delay = 0;
aoe->data.item.type = type;
if(type == ITEM_LIFE) {
visible_set_anim(e, &anims_item_life, 1);
}
else if(type == ITEM_POTION_ATK) {
visible_set_anim(e, &anims_item_potion_atk, 1);
}
else if(type == ITEM_POTION_COOLDOWN) {
visible_set_anim(e, &anims_item_potion_cooldown, 1);
}
else if(type == ITEM_POTION_DEF) {
visible_set_anim(e, &anims_item_potion_def, 1);
}
else if(type == ITEM_POTION_FRZ) {
visible_set_anim(e, &anims_item_potion_frz, 1);
}
else if(type == ITEM_POTION_HP) {
visible_set_anim(e, &anims_item_potion_hp, 1);
}
else if(type == ITEM_POTION_SPD) {
visible_set_anim(e, &anims_item_potion_spd, 1);
}
else if(type == ITEM_SCEPTER1) {
visible_set_anim(e, &anims_item_stick1, 1);
}
else if(type == ITEM_SCEPTER2) {
visible_set_anim(e, &anims_item_stick2, 1);
}
else if(type == ITEM_SWORD1) {
visible_set_anim(e, &anims_item_sword1, 1);
}
else if(type == ITEM_SWORD2) {
visible_set_anim(e, &anims_item_sword2, 1);
}
anim_t const *anim = item_anim(type);
if(anim)
visible_set_anim(e, anim, 1);
return e;
}

View File

@ -6,6 +6,7 @@
#include "comp/entity.h"
#include "geometry.h"
#include "anim.h"
enum {
ITEM_LIFE = 0,
@ -24,6 +25,9 @@ enum {
/**/ ITEM_EQUIPMENT_END,
};
/* Animation for each item. */
anim_t const *item_anim(int item);
/* Create an item. This is just an AOE with a particular type. */
entity_t *item_make(int item, vec2 position);

View File

@ -144,21 +144,6 @@ int main(void)
game_add_entity(&game, player);
game.player = player;
int x=0, y=0;
for(int i = 0; i < 100; i++) {
y = rand() % game.map->height;
x = rand() % game.map->width;
map_cell_t const *cell = map_cell(game.map, x, y);
__auto_type tiles = game.map->tileset->tiles;
if(!tiles[cell->base].solid &&
(!cell->decor || !tiles[cell->decor].solid))
break;
}
entity_t *item = item_make(ITEM_LIFE,
(vec2){ fix(x)+fix(0.5), fix(y)+fix(0.5) });
game_add_entity(&game, item);
//---
// Main loop
//---

View File

@ -4,11 +4,12 @@
#include "comp/mechanical.h"
#include "comp/fighter.h"
#include "comp/particle.h"
#include "anim.h"
#include "enemies.h"
#include "game.h"
#include "item.h"
#include "render.h"
#include "skills.h"
#include "game.h"
#include "anim.h"
#include <gint/display.h>
#include <gint/defs/util.h>
@ -299,6 +300,7 @@ static void render_entities(game_t const *g, camera_t const *camera,
static int render_info_delay(int x, int y, level_event_t const *event)
{
(void)event;
extern bopti_image_t img_hud_delay;
dimage(x, y, &img_hud_delay);
return img_hud_delay.width;
@ -333,11 +335,18 @@ static int render_info_wave(int x, int y, level_event_t const *event,
static int render_info_item(int x, int y, level_event_t const *event)
{
int w;
dsize("Item", NULL, &w, NULL);
anim_t const *anim = item_anim(event->item);
dprint(x, y, C_WHITE, "Item");
return w;
if(anim) {
anim_frame_render(x+5, y+5, anim->start[0]);
return anim->start[0]->w;
}
else {
int w;
dsize("Item", NULL, &w, NULL);
dprint(x, y, C_WHITE, "Item");
return w;
}
}
static void render_info(int x, int y, game_t const *g)