- ordenacio correcta

- tiles de 32 pixels
This commit is contained in:
2023-03-01 20:09:46 +01:00
parent 7a2bf7fa43
commit 53212f4bfa
4 changed files with 24 additions and 26 deletions

View File

@@ -11,7 +11,7 @@ namespace actor
return first;
}
actor_t *create(pos_t p, size_t s, SDL_Rect r, SDL_Point o)
actor_t *create(vec3_t p, vec3_t s, SDL_Rect r, SDL_Point o)
{
actor_t *act = (actor_t*)malloc(sizeof(actor_t));
act->pos = p;
@@ -36,14 +36,24 @@ namespace actor
{
while (dirty)
{
const int z_index = dirty->pos.x + dirty->pos.y + dirty->pos.z;
//const int z_index = dirty->pos.x + dirty->pos.y + dirty->pos.z;
if (first)
{
actor_t *current = first;
while (true)
{
const int z_index2 = current->pos.x + current->pos.y + current->pos.z;
if (z_index > z_index2)
//const int z_index2 = current->pos.x + current->pos.y + current->pos.z;
if ((dirty->pos.z < current->pos.z+current->size.z) && (current->pos.x+current->size.x+current->pos.y > dirty->pos.x+dirty->size.x+dirty->pos.y))
{
dirty->prev = current->prev;
current->prev = dirty;
if (dirty->prev) dirty->prev->next = dirty;
dirty = dirty->next;
current->prev->next = current;
if (current==first) first=current->prev;
break;
}
else
{
if (current->next)
{
@@ -58,15 +68,6 @@ namespace actor
break;
}
}
else
{
dirty->prev = current->prev;
current->prev = dirty;
if (dirty->prev) dirty->prev->next = dirty;
dirty = dirty->next;
current->prev->next = current;
break;
}
}
}
else
@@ -82,7 +83,7 @@ namespace actor
{
if (!act) return;
const int x = 148-act->bmp_offset.x + act->pos.x*2 - act->pos.y*2;
const int y = 91-act->bmp_offset.y + act->pos.x + act->pos.y;
const int y = 91-act->bmp_offset.y + act->pos.x + act->pos.y - act->pos.z*2;
draw::draw(x, y, act->bmp_rect.w, act->bmp_rect.h, act->bmp_rect.x, act->bmp_rect.y);
if (draw_all && act->next) draw(act->next);
}

View File

@@ -3,23 +3,18 @@
namespace actor
{
struct pos_t
struct vec3_t
{
int x, y, z;
};
struct size_t
{
int w, h, d;
};
struct actor_t
{
SDL_Rect bmp_rect;
SDL_Point bmp_offset;
pos_t pos;
size_t size;
vec3_t pos;
vec3_t size;
actor_t *prev;
actor_t *next;
@@ -27,7 +22,7 @@ namespace actor
actor_t *getFirst();
actor_t *create(pos_t p, size_t s, SDL_Rect r, SDL_Point o);
actor_t *create(vec3_t p, vec3_t s, SDL_Rect r, SDL_Point o);
void setDirty(actor_t *act);

View File

@@ -15,9 +15,9 @@ void game::init()
draw::loadPalette("test.gif");
game::setUpdateTicks(64);
box = actor::create({0,0,0}, {6,6,6}, {24,0,24,24}, {0,24});
box = actor::create({16,16,0}, {8,8,8}, {32,0,32,32}, {0,32});
actor::setDirty(box);
box = actor::create({6,0,0}, {6,6,6}, {24,0,24,24}, {0,24});
box = actor::create({8,0,0}, {8,8,8}, {32,0,32,32}, {0,32});
actor::setDirty(box);
actor::reorder();
}
@@ -30,6 +30,8 @@ bool game::loop()
if (input::keyDown(SDL_SCANCODE_RIGHT) && box->pos.x<42) { box->pos.x++; actor::setDirty(box); }
if (input::keyDown(SDL_SCANCODE_UP) && box->pos.y>0) { box->pos.y--; actor::setDirty(box); }
if (input::keyDown(SDL_SCANCODE_DOWN) && box->pos.y<42) { box->pos.y++; actor::setDirty(box); }
if (input::keyDown(SDL_SCANCODE_Z) && box->pos.z>0) { box->pos.z--; actor::setDirty(box); }
if (input::keyDown(SDL_SCANCODE_A) && box->pos.z<42) { box->pos.z++; actor::setDirty(box); }
actor::reorder();
draw::cls(8);
@@ -37,7 +39,7 @@ bool game::loop()
{
for (int x=0;x<8;++x)
{
draw::draw(148+x*12-y*12,80+x*6+y*6,24,11,0,13);
draw::draw(148+x*16-y*16,76+x*8+y*8,32,15,0,1);
}
}
actor::draw(actor::getFirst());