2 Commits

7 changed files with 232 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

@@ -39,6 +39,40 @@ namespace draw
surface* managed[50];
int num_managed = 0;
namespace stencil
{
static bool enabled = false;
static uint8_t value = 0;
static surface *stencil = nullptr;
void init()
{
if (stencil) freeSurface(stencil);
stencil = createSurface(screen->w, screen->h);
}
void enable() { enabled = true; }
void disable() { enabled = false; }
void clear(const uint8_t val)
{
if (!stencil) return;
memset(stencil->pixels, val, stencil->w*stencil->h);
}
void set(const uint8_t val)
{
if (!stencil) return;
value = val;
}
const uint8_t query(const int x, const int y)
{
if (!stencil) return 0;
return stencil->pixels[x+y*stencil->w];
}
}
// Inicialització de tot el que fa falta per a carregar gràfics i pintar en pantalla
void init(const std::string &titol, const uint16_t width, const uint16_t height, const int zoom, const bool fullscreen)
{
@@ -362,7 +396,10 @@ namespace draw
// Si pintem a "destination", mirem que estiga dins del "viewport" i sinó fora
if (surface == destination) {
if (x+viewport.x >= 0 && y+viewport.y >= 0 && x < viewport.w && y < viewport.h)
{
surface->pixels[(viewport.x+x) + (y+viewport.y) * surface->w] = color_indices[color];
if (stencil::stencil && stencil::enabled) stencil::stencil->pixels[(viewport.x+x) + (y+viewport.y) * stencil::stencil->w] = stencil::value;
}
} else {
// Si no es destinations, pintem i au
surface->pixels[x + y * surface->w] = color_indices[color];

View File

@@ -119,4 +119,14 @@ namespace draw
/// @brief Refresca la pantalla
void render();
namespace stencil
{
void init();
void enable();
void disable();
void clear(const uint8_t val);
void set(const uint8_t val);
const uint8_t query(const int x, const int y);
}
}

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);