- [NEW] Selecció de actors en l'editor amb el ratolí

This commit is contained in:
2024-07-11 08:25:34 +02:00
parent b794ebe608
commit c4cbda9b23
5 changed files with 185 additions and 166 deletions

View File

@@ -20,6 +20,50 @@ actor{
movement: CW
}
actor{
name: TAULETA
bmp: caixes.gif
bmp-rect: 0 64 32 32
bmp-offset: 0 32
pos: 24 8 0
size: 8 8 5
movement: CW
}
actor{
name: S-SHOES
bmp: objectes.gif
bmp-rect: 162 0 28 22
bmp-offset: -3 24
pos: 48 8 0
size: 4 4 4
anim-cycle: SEQ
anim-wait: 2
flags: SPECIAL
movement: CW
}
actor{
name: ARMARI02
bmp: caixes.gif
bmp-rect: 96 32 24 32
bmp-offset: -8 36
pos: 8 8 8
size: 8 4 8
movement: CW
}
actor{
name: TV
bmp: caixes.gif
bmp-rect: 32 64 32 32
bmp-offset: 0 32
pos: 24 7 5
size: 8 5 8
orient: XP
movement: CW
}
actor{
name: TAULA01
bmp: caixes.gif
@@ -32,6 +76,17 @@ actor{
movement: CW
}
actor{
name: NES
bmp: caixes.gif
bmp-rect: 96 0 32 32
bmp-offset: 0 32
pos: 24 16 0
size: 8 8 6
flags: PICKABLE PUSHABLE GRAVITY
movement: CW
}
actor{
name: TAULA02
bmp: caixes.gif
@@ -44,48 +99,6 @@ actor{
movement: CW
}
actor{
name: ARMARI02
bmp: caixes.gif
bmp-rect: 96 32 24 32
bmp-offset: -8 36
pos: 8 8 8
size: 8 4 8
movement: CW
}
actor{
name: TAULETA
bmp: caixes.gif
bmp-rect: 0 64 32 32
bmp-offset: 0 32
pos: 24 8 0
size: 8 8 5
movement: CW
}
actor{
name: TV
bmp: caixes.gif
bmp-rect: 32 64 32 32
bmp-offset: 0 32
pos: 24 7 5
size: 8 5 8
orient: XP
movement: CW
}
actor{
name: NES
bmp: caixes.gif
bmp-rect: 96 0 32 32
bmp-offset: 0 32
pos: 24 16 0
size: 8 8 6
flags: PICKABLE PUSHABLE GRAVITY
movement: CW
}
actor{
name: ROOMBA
bmp: caixes.gif
@@ -97,16 +110,3 @@ actor{
flags: MOVING
movement: Y
}
actor{
name: S-SHOES
bmp: objectes.gif
bmp-rect: 162 0 28 22
bmp-offset: -3 24
pos: 48 8 0
size: 4 4 4
anim-cycle: SEQ
anim-wait: 2
flags: SPECIAL
movement: CW
}

View File

@@ -26,26 +26,6 @@ actor{
movement: CW
}
actor{
name: KALLAX-A
bmp: altres.gif
bmp-rect: 0 48 24 27
bmp-offset: 0 31
pos: 0 8 0
size: 4 8 8
movement: CW
}
actor{
name: KALLAX-A03
bmp: altres.gif
bmp-rect: 72 48 24 27
bmp-offset: 0 31
pos: 0 16 0
size: 4 8 8
movement: CW
}
actor{
name: KALLAX-A04
bmp: altres.gif
@@ -80,16 +60,6 @@ actor{
movement: CW
}
actor{
name: BOX01
bmp: caixes.gif
bmp-rect: 128 32 32 32
bmp-offset: 0 32
pos: 16 24 0
size: 8 8 8
movement: CW
}
actor{
name: KALLAX-A07
bmp: altres.gif
@@ -102,60 +72,6 @@ actor{
movement: CW
}
actor{
name: BOX02
bmp: caixes.gif
bmp-rect: 160 32 32 32
bmp-offset: 0 32
pos: 24 24 0
size: 8 8 8
react-push: XP
movement: CW
}
actor{
name: KALLAX-A08
bmp: altres.gif
bmp-rect: 24 48 24 27
bmp-offset: -8 31
pos: 32 0 0
size: 8 4 8
orient: YP
flags: ORIENTABLE
movement: CW
}
actor{
name: KALLAX-A01
bmp: altres.gif
bmp-rect: 24 48 24 27
bmp-offset: 0 31
pos: 0 8 8
size: 4 8 8
movement: CW
}
actor{
name: KALLAX-A02
bmp: altres.gif
bmp-rect: 48 48 24 27
bmp-offset: 0 31
pos: 0 16 8
size: 4 8 8
movement: CW
}
actor{
name: BOX03
bmp: caixes.gif
bmp-rect: 128 0 32 32
bmp-offset: 0 32
pos: 16 24 8
size: 8 8 8
react-push: XP
movement: CW
}
actor{
name: KALLAX-A06
bmp: altres.gif
@@ -169,15 +85,14 @@ actor{
}
actor{
name: BOX04
bmp: caixes.gif
bmp-rect: 32 64 32 32
bmp-offset: 0 32
pos: 24 24 8
size: 8 8 8
name: KALLAX-A08
bmp: altres.gif
bmp-rect: 24 48 24 27
bmp-offset: -8 31
pos: 32 0 0
size: 8 4 8
orient: YP
flags: ORIENTABLE
react-push: XP
movement: CW
}
@@ -192,3 +107,88 @@ actor{
flags: ORIENTABLE
movement: CW
}
actor{
name: KALLAX-A
bmp: altres.gif
bmp-rect: 0 48 24 27
bmp-offset: 0 31
pos: 0 8 0
size: 4 8 8
movement: CW
}
actor{
name: KALLAX-A01
bmp: altres.gif
bmp-rect: 24 48 24 27
bmp-offset: 0 31
pos: 0 8 8
size: 4 8 8
movement: CW
}
actor{
name: KALLAX-A03
bmp: altres.gif
bmp-rect: 72 48 24 27
bmp-offset: 0 31
pos: 0 16 0
size: 4 8 8
movement: CW
}
actor{
name: KALLAX-A02
bmp: altres.gif
bmp-rect: 48 48 24 27
bmp-offset: 0 31
pos: 0 16 8
size: 4 8 8
movement: CW
}
actor{
name: BOX01
bmp: caixes.gif
bmp-rect: 128 32 32 32
bmp-offset: 0 32
pos: 16 24 0
size: 8 8 8
movement: CW
}
actor{
name: BOX03
bmp: caixes.gif
bmp-rect: 128 0 32 32
bmp-offset: 0 32
pos: 16 24 8
size: 8 8 8
react-push: XP
movement: CW
}
actor{
name: BOX02
bmp: caixes.gif
bmp-rect: 160 32 32 32
bmp-offset: 0 32
pos: 24 24 0
size: 8 8 8
react-push: XP
movement: CW
}
actor{
name: BOX04
bmp: caixes.gif
bmp-rect: 32 64 32 32
bmp-offset: 0 32
pos: 24 24 8
size: 8 8 8
orient: YP
flags: ORIENTABLE
react-push: XP
movement: CW
}

View File

@@ -23,6 +23,13 @@ namespace actor
actor_t *picked = nullptr;
static bool room_changed = false;
int current_tag = 0;
void resetTag()
{
current_tag = 0;
}
actor_t *getFirst()
{
return first;
@@ -44,6 +51,7 @@ namespace actor
actor_t *create(std::string name, vec3_t p, vec3_t s, std::string bmp, SDL_Rect r, SDL_Point o)
{
actor_t *act = (actor_t*)malloc(sizeof(actor_t));
act->tag = current_tag++;
strcpy(act->name, name.c_str());
strcpy(act->bmp, bmp.c_str());
act->pos = p;
@@ -65,6 +73,7 @@ namespace actor
actor_t *createEmptyActor()
{
actor_t *act = (actor_t*)malloc(sizeof(actor_t));
act->tag = current_tag++;
act->pos = {0, 0, 0};
act->size = {8,8,8};
act->bmp_rect = {0,0,32,32};
@@ -991,6 +1000,7 @@ namespace actor
draw::pushSource();
draw::setSource(act->surface);
if (editor::isEditing() && (act==selected)) draw::swapcol(1, room::getColor(1)); // Si està seleccionat, que canvie de color
draw::stencil::set(act->tag);
draw::draw(x, y, act->bmp_rect.w, act->bmp_rect.h, act->bmp_rect.x+ao, act->bmp_rect.y+oo, flip);
draw::swapcol(1, room::getColor(0)); // Tornem al color per defecte
draw::popSource();
@@ -1016,18 +1026,20 @@ namespace actor
}
act = act->next;
}
return nullptr;
}
/*
act = dirty;
actor_t *findByTag(const int tag)
{
actor_t *act = first;
while (act)
{
if (name == act->name)
if (tag == act->tag)
{
return act;
}
act = act->next;
}
*/
return nullptr;
}
@@ -1119,6 +1131,7 @@ namespace actor
void clear(const bool all)
{
resetTag();
actor_t *hero = nullptr;
actor_t *act = first;
while (act)
@@ -1127,25 +1140,10 @@ namespace actor
if (!all && (act->flags & FLAG_HERO)) {
hero = act;
} else {
//draw::freeSurface(act->surface);
free(act);
}
act = tmp;
}
/*
act = dirty;
while (act)
{
actor_t *tmp = act->next;
if (act->flags & FLAG_HERO) {
hero = act;
} else {
//draw::freeSurface(act->surface);
free(act);
}
act = tmp;
}
*/
if (picked)
{
free(picked);

View File

@@ -100,8 +100,12 @@ namespace actor
int inner_x;
int inner_y;
int tag;
};
void resetTag();
// Torna el primer actor de la llista
actor_t *getFirst();
@@ -140,6 +144,8 @@ namespace actor
actor_t *find(std::string name);
actor_t *findByTag(const int tag);
actor_t *find_at(const int x, const int y, const int z);
actor_t *get_collision(actor_t *act);

View File

@@ -22,7 +22,9 @@ namespace modules
::game::setUpdateTicks(64);
actor::templates::load();
if (editor::isDevMode()) {
if (editor::isDevMode())
{
draw::stencil::init();
FILE* f = fopen("data/gifs.txt", "r");
int buffer_len=255;
@@ -287,11 +289,24 @@ namespace modules
if (editor::isDevMode()) draw::setViewport(100,0,320,240);
room::draw();
draw::stencil::enable();
draw::stencil::clear(255);
actor::draw(actor::getFirst());
draw::stencil::disable();
room::draw2();
draw::swapcol(1, WHITE+LIGHT);
actor::draw(actor::getPicked(), false);
if (editor::isDevMode() && input::mouseBtn(1))
{
const uint8_t val = draw::stencil::query(input::mouseX(), input::mouseY());
if (val != 255)
{
actor::select(actor::findByTag(val));
section = SECTION_ACTOR;
}
}
const int col1 = room::getColor(1);
const int col2 = room::getColor(2);
const int col3 = room::getColor(3);