- Ja carrega habitació i actors de arxiu
- Els templates deurien funcionar quan s'active la funcionalitat
This commit is contained in:
@@ -8,11 +8,23 @@ door-texture: 1
|
|||||||
under-door-texture: 1
|
under-door-texture: 1
|
||||||
|
|
||||||
actor{
|
actor{
|
||||||
template: box
|
name: BOX
|
||||||
pos: 32 32 0
|
bmp: test.gif
|
||||||
|
bmp-rect: 32 0 32 32
|
||||||
|
bmp-offset: 0 32
|
||||||
|
pos: 32 32 8
|
||||||
|
size: 8 8 8
|
||||||
|
orient: NONE
|
||||||
|
flags: PUSHABLE GRAVITY
|
||||||
}
|
}
|
||||||
|
|
||||||
actor{
|
actor{
|
||||||
template: box
|
name: BOX2
|
||||||
pos: 32 32 8
|
bmp: test.gif
|
||||||
|
bmp-rect: 32 0 32 32
|
||||||
|
bmp-offset: 0 32
|
||||||
|
pos: 32 32 0
|
||||||
|
size: 8 8 8
|
||||||
|
orient: NONE
|
||||||
|
flags: pushable gravity
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ actor{
|
|||||||
orient: NONE
|
orient: NONE
|
||||||
movement: CW
|
movement: CW
|
||||||
anim-cycle: WALK
|
anim-cycle: WALK
|
||||||
anim-speed: 0
|
anim-wait: 0
|
||||||
flags: PUSH GRAV
|
flags: PUSH GRAV
|
||||||
react-mask: NONE
|
react-mask: NONE
|
||||||
react-push: NONE
|
react-push: NONE
|
||||||
|
|||||||
183
source/actor.cpp
183
source/actor.cpp
@@ -47,26 +47,97 @@ namespace actor
|
|||||||
return act;
|
return act;
|
||||||
}
|
}
|
||||||
|
|
||||||
void createFromFile(char **buffer)
|
actor_t *createEmptyActor()
|
||||||
{
|
{
|
||||||
actor_t *act = (actor_t*)malloc(sizeof(actor_t));
|
actor_t *act = (actor_t*)malloc(sizeof(actor_t));
|
||||||
|
act->pos = {0, 0, 0};
|
||||||
|
act->size = {8,8,8};
|
||||||
|
act->bmp_rect = {0,0,32,32};
|
||||||
|
act->bmp_offset = {0,0};
|
||||||
|
act->anim_cycle = act->orient = act->movement = 0;
|
||||||
|
act->push = act->mov_push = PUSH_NONE;
|
||||||
|
act->below = act->above = nullptr;
|
||||||
|
act->prev = act->next = nullptr;
|
||||||
|
act->anim_wait = act->anim_wait_count = 0;
|
||||||
|
act->anim_frame=0;
|
||||||
|
act->react_mask = act->react_push = 0;
|
||||||
|
return act;
|
||||||
|
}
|
||||||
|
|
||||||
|
actor_t *createFromFile(char **buffer)
|
||||||
|
{
|
||||||
if (*buffer)
|
if (*buffer)
|
||||||
{
|
{
|
||||||
|
actor_t *t = createEmptyActor();
|
||||||
while (**buffer != 0)
|
while (**buffer != 0)
|
||||||
{
|
{
|
||||||
const char* key = file::readString(buffer);
|
const char* key = file::readString(buffer);
|
||||||
|
|
||||||
if (util::strcomp(key, "pos:")) {
|
if (util::strcomp(key, "name:")) {
|
||||||
act->pos.x = file::readInt(buffer);
|
const char *val = file::readString(buffer);
|
||||||
act->pos.y = file::readInt(buffer);
|
strcpy(t->name, val);
|
||||||
act->pos.z = file::readInt(buffer);
|
} else if (util::strcomp(key, "bmp:")) {
|
||||||
} else if (util::strcomp(key, "height:")) {
|
const char *val = file::readString(buffer);
|
||||||
const int val = file::readInt(buffer);
|
strcpy(t->bmp, val);
|
||||||
inner_h = SDL_clamp(val, 0, 3);
|
t->surface = draw::loadSurface(t->bmp);
|
||||||
|
} else if (util::strcomp(key, "bmp-rect:")) {
|
||||||
|
t->bmp_rect.x = file::readInt(buffer);
|
||||||
|
t->bmp_rect.y = file::readInt(buffer);
|
||||||
|
t->bmp_rect.w = file::readInt(buffer);
|
||||||
|
t->bmp_rect.h = file::readInt(buffer);
|
||||||
|
} else if (util::strcomp(key, "bmp-offset:")) {
|
||||||
|
t->bmp_offset.x = file::readInt(buffer);
|
||||||
|
t->bmp_offset.y = file::readInt(buffer);
|
||||||
|
} else if (util::strcomp(key, "pos:")) {
|
||||||
|
t->pos.x = file::readInt(buffer);
|
||||||
|
t->pos.y = file::readInt(buffer);
|
||||||
|
t->pos.z = file::readInt(buffer);
|
||||||
|
} else if (util::strcomp(key, "size:")) {
|
||||||
|
t->size.x = file::readInt(buffer);
|
||||||
|
t->size.y = file::readInt(buffer);
|
||||||
|
t->size.z = file::readInt(buffer);
|
||||||
|
} else if (util::strcomp(key, "orient:")) {
|
||||||
|
t->orient = util::stringToInt(file::readString(buffer), {"none", "xp", "xn", "yp", "yn", "zp", "zn"}, {0, 1, 2, 4, 8, 16, 32});
|
||||||
|
} else if (util::strcomp(key, "movement:")) {
|
||||||
|
t->movement = util::stringToInt(file::readString(buffer), {"none", "x", "y", "z", "cw", "ccw", "rand", "hunt"},{MOV_NONE, MOV_X, MOV_Y, MOV_Z, MOV_CW, MOV_CCW, MOV_RAND, MOV_HUNT});
|
||||||
|
} else if (util::strcomp(key, "anim-cycle:")) {
|
||||||
|
t->anim_cycle = util::stringToInt(file::readString(buffer), {"walk", "seq"},{0, 1});
|
||||||
|
} else if (util::strcomp(key, "anim-wait:")) {
|
||||||
|
t->anim_wait = file::readInt(buffer);
|
||||||
|
} else if (util::strcomp(key, "flags:")) {
|
||||||
|
const char *str = file::readString(buffer, true);
|
||||||
|
int value = 0;
|
||||||
|
while (str)
|
||||||
|
{
|
||||||
|
value |= util::stringToInt(str, { "none", "hero", "pushable", "reactive", "moving", "animated", "orientable", "deadly", "gravity", "pickable", "special", "noeditor" },{ FLAG_NONE, FLAG_HERO, FLAG_PUSHABLE, FLAG_REACTIVE, FLAG_MOVING, FLAG_ANIMATED, FLAG_ORIENTABLE, FLAG_DEADLY, FLAG_GRAVITY, FLAG_PICKABLE, FLAG_SPECIAL, FLAG_NOEDITOR });
|
||||||
|
str = file::readString(buffer, true);
|
||||||
|
}
|
||||||
|
t->flags = value;
|
||||||
|
} else if (util::strcomp(key, "react-push:")) {
|
||||||
|
const char *str = file::readString(buffer, true);
|
||||||
|
int value = 0;
|
||||||
|
while (str)
|
||||||
|
{
|
||||||
|
value |= util::stringToInt(str, { "none", "xp", "xn", "yp", "yn", "zp", "zn" }, { PUSH_NONE, PUSH_XP, PUSH_XN, PUSH_YP, PUSH_YN, PUSH_ZP, PUSH_ZN });
|
||||||
|
str = file::readString(buffer, true);
|
||||||
|
}
|
||||||
|
t->react_push = value;
|
||||||
|
} else if (util::strcomp(key, "react-mask:")) {
|
||||||
|
const char *str = file::readString(buffer, true);
|
||||||
|
int value = 0;
|
||||||
|
while (str)
|
||||||
|
{
|
||||||
|
value |= util::stringToInt(str, { "none", "xp", "xn", "yp", "yn", "zp", "zn" }, { PUSH_NONE, PUSH_XP, PUSH_XN, PUSH_YP, PUSH_YN, PUSH_ZP, PUSH_ZN });
|
||||||
|
str = file::readString(buffer, true);
|
||||||
|
}
|
||||||
|
t->react_mask = value;
|
||||||
|
} else if (util::strcomp(key, "}")) {
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return t;
|
||||||
}
|
}
|
||||||
setDirty(act, true);
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool check_2d_collision(actor_t *obj1, actor_t *obj2)
|
const bool check_2d_collision(actor_t *obj1, actor_t *obj2)
|
||||||
@@ -846,35 +917,50 @@ namespace actor
|
|||||||
void load()
|
void load()
|
||||||
{
|
{
|
||||||
templates.clear();
|
templates.clear();
|
||||||
FILE *f = fopen("data/templates.txt", "r");
|
char filename[] = "templates.txt";
|
||||||
if (!f) return;
|
int filesize=0;
|
||||||
int size = 0;
|
char *buffer = file::getFileBuffer(filename, filesize, true);
|
||||||
fscanf(f, "TEMPLATES %i\n", &size);
|
char *original_buffer = buffer;
|
||||||
|
|
||||||
fclose(f);
|
if (buffer)
|
||||||
|
{
|
||||||
|
while (*buffer != 0)
|
||||||
|
{
|
||||||
|
const char* key = file::readString(&buffer);
|
||||||
|
|
||||||
|
if (util::strcomp(key, "actor{"))
|
||||||
|
{
|
||||||
|
actor_t *t = createFromFile(&buffer);
|
||||||
|
templates.push_back(*t);
|
||||||
|
free(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(original_buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void save()
|
void save()
|
||||||
{
|
{
|
||||||
FILE *f = fopen("data/templates.txt", "w");
|
FILE *f = fopen("data/templates.txt", "w");
|
||||||
fprintf(f, "TEMPLATES %i\n", templates.size());
|
|
||||||
|
|
||||||
for (int i=0; i<templates.size(); ++i)
|
for (int i=0; i<templates.size(); ++i)
|
||||||
{
|
{
|
||||||
actor_t t = templates[i];
|
actor_t t = templates[i];
|
||||||
fprintf(f, "name = %s\n", t.name);
|
fprintf(f, "actor{\n");
|
||||||
fprintf(f, "bmp = %s\n", t.bmp);
|
fprintf(f, " name: %s\n", t.name);
|
||||||
fprintf(f, "bmp_rect = %i %i %i %i\n", t.bmp_rect.x, t.bmp_rect.y, t.bmp_rect.w, t.bmp_rect.h);
|
fprintf(f, " bmp: %s\n", t.bmp);
|
||||||
fprintf(f, "bmp_offset = %i %i\n", t.bmp_offset.x, t.bmp_offset.y);
|
fprintf(f, " bmp-rect: %i %i %i %i\n", t.bmp_rect.x, t.bmp_rect.y, t.bmp_rect.w, t.bmp_rect.h);
|
||||||
fprintf(f, "pos = %i %i %i\n", t.pos.x, t.pos.y, t.pos.z);
|
fprintf(f, " bmp-offset: %i %i\n", t.bmp_offset.x, t.bmp_offset.y);
|
||||||
fprintf(f, "size = %i %i %i\n", t.size.x, t.size.y, t.size.z);
|
fprintf(f, " pos: %i %i %i\n", t.pos.x, t.pos.y, t.pos.z);
|
||||||
fprintf(f, "orient = %s\n", numToOrient(t.orient));
|
fprintf(f, " size: %i %i %i\n", t.size.x, t.size.y, t.size.z);
|
||||||
fprintf(f, "anim_cycle = %s\n", t.anim_cycle==0 ? "WALK" : "SEQ");
|
fprintf(f, " orient: %s\n", numToOrient(t.orient));
|
||||||
fprintf(f, "anim_wait = %i\n", t.anim_wait);
|
fprintf(f, " anim-cycle: %s\n", t.anim_cycle==0 ? "WALK" : "SEQ");
|
||||||
fprintf(f, "flags = %s\n", numToFlags(t.flags));
|
fprintf(f, " anim-wait: %i\n", t.anim_wait);
|
||||||
fprintf(f, "react_mask = %s\n", numToOrient(t.react_mask));
|
fprintf(f, " flags: %s\n", numToFlags(t.flags));
|
||||||
fprintf(f, "react_push = %s\n", numToOrient(t.react_push));
|
fprintf(f, " react-mask: %s\n", numToOrient(t.react_mask));
|
||||||
fprintf(f, "movement = %s\n\n", numToMov(t.movement));
|
fprintf(f, " react-push: %s\n", numToOrient(t.react_push));
|
||||||
|
fprintf(f, " movement: %s\n\n", numToMov(t.movement));
|
||||||
|
fprintf(f, "}\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
@@ -890,21 +976,34 @@ namespace actor
|
|||||||
return &templates[index];
|
return &templates[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(actor_t *actor){
|
actor_t *getByName(const char *name)
|
||||||
|
{
|
||||||
|
for (int i=0;i<templates.size();++i) if (util::strcomp(name, templates[i].name)) return &templates[i];
|
||||||
|
//for (auto t : templates) if (util::strcomp(name, t.name)) return &t;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void copy(actor_t *dest, actor_t *source)
|
||||||
|
{
|
||||||
|
strcpy(dest->name, source->name);
|
||||||
|
strcpy(dest->bmp, source->bmp);
|
||||||
|
dest->bmp_rect = source->bmp_rect;
|
||||||
|
dest->bmp_offset = source->bmp_offset;
|
||||||
|
dest->pos = source->pos;
|
||||||
|
dest->size = source->size;
|
||||||
|
dest->orient = source->orient;
|
||||||
|
dest->anim_cycle = source->anim_cycle;
|
||||||
|
dest->anim_wait = source->anim_wait;
|
||||||
|
dest->flags = source->flags;
|
||||||
|
dest->react_mask = source->react_mask;
|
||||||
|
dest->react_push = source->react_push;
|
||||||
|
dest->movement = source->movement;
|
||||||
|
}
|
||||||
|
|
||||||
|
void add(actor_t *actor)
|
||||||
|
{
|
||||||
actor_t new_template;
|
actor_t new_template;
|
||||||
strcpy(new_template.name, actor->name);
|
copy(&new_template, actor);
|
||||||
strcpy(new_template.bmp, actor->bmp);
|
|
||||||
new_template.bmp_rect = actor->bmp_rect;
|
|
||||||
new_template.bmp_offset = actor->bmp_offset;
|
|
||||||
new_template.pos = actor->pos;
|
|
||||||
new_template.size = actor->size;
|
|
||||||
new_template.orient = actor->orient;
|
|
||||||
new_template.anim_cycle = actor->anim_cycle;
|
|
||||||
new_template.anim_wait = actor->anim_wait;
|
|
||||||
new_template.flags = actor->flags;
|
|
||||||
new_template.react_mask = actor->react_mask;
|
|
||||||
new_template.react_push = actor->react_push;
|
|
||||||
new_template.movement = actor->movement;
|
|
||||||
templates.push_back(new_template);
|
templates.push_back(new_template);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ namespace actor
|
|||||||
// Torna un nou actor
|
// Torna un nou actor
|
||||||
actor_t *create(std::string name, vec3_t p, vec3_t s, std::string bmp, SDL_Rect r, SDL_Point o);
|
actor_t *create(std::string name, vec3_t p, vec3_t s, std::string bmp, SDL_Rect r, SDL_Point o);
|
||||||
|
|
||||||
void createFromFile(char **buffer);
|
actor_t *createFromFile(char **buffer);
|
||||||
|
|
||||||
void setDirty(actor_t *act, const bool force=false);
|
void setDirty(actor_t *act, const bool force=false);
|
||||||
|
|
||||||
@@ -119,6 +119,8 @@ namespace actor
|
|||||||
void save();
|
void save();
|
||||||
const int size();
|
const int size();
|
||||||
actor_t *get(const int index);
|
actor_t *get(const int index);
|
||||||
|
actor_t *getByName(const char *name);
|
||||||
|
void copy(actor_t *dest, actor_t *source);
|
||||||
void add(actor_t *actor);
|
void add(actor_t *actor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,6 +73,7 @@ void game::init()
|
|||||||
|
|
||||||
restart();
|
restart();
|
||||||
|
|
||||||
|
/*
|
||||||
actor::actor_t *box = actor::create("BOX", {32,32,16}, {8,8,8}, "test.gif", {32,0,32,32}, {0,32});
|
actor::actor_t *box = actor::create("BOX", {32,32,16}, {8,8,8}, "test.gif", {32,0,32,32}, {0,32});
|
||||||
box->flags = FLAG_PUSHABLE | FLAG_GRAVITY;
|
box->flags = FLAG_PUSHABLE | FLAG_GRAVITY;
|
||||||
box->movement = MOV_CW;
|
box->movement = MOV_CW;
|
||||||
@@ -84,7 +85,7 @@ void game::init()
|
|||||||
box->movement = MOV_CW;
|
box->movement = MOV_CW;
|
||||||
box->mov_push = PUSH_XN;
|
box->mov_push = PUSH_XN;
|
||||||
actor::setDirty(box, true);
|
actor::setDirty(box, true);
|
||||||
|
*/
|
||||||
actor::select(actor::find("BOX"));
|
actor::select(actor::find("BOX"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,8 +101,8 @@ namespace room
|
|||||||
|
|
||||||
// Després intentem carregar els valors segons el arxiu que toca, si existeix
|
// Després intentem carregar els valors segons el arxiu que toca, si existeix
|
||||||
char filename[] = "rooms/00.txt";
|
char filename[] = "rooms/00.txt";
|
||||||
filename[6] = int(room/10)*48;
|
filename[6] = int(room/10)+48;
|
||||||
filename[7] = (room%10)*48;
|
filename[7] = (room%10)+48;
|
||||||
int filesize=0;
|
int filesize=0;
|
||||||
char *buffer = file::getFileBuffer(filename, filesize, true);
|
char *buffer = file::getFileBuffer(filename, filesize, true);
|
||||||
char *original_buffer = buffer;
|
char *original_buffer = buffer;
|
||||||
@@ -165,7 +165,8 @@ namespace room
|
|||||||
exits[5] = SDL_clamp(val, 0, 64);
|
exits[5] = SDL_clamp(val, 0, 64);
|
||||||
|
|
||||||
} else if (util::strcomp(key, "actor{")) {
|
} else if (util::strcomp(key, "actor{")) {
|
||||||
actor::createFromFile(&buffer);
|
actor::actor_t *act = actor::createFromFile(&buffer);
|
||||||
|
actor::setDirty(act, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(original_buffer);
|
free(original_buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user