- ordenacio correcta
- tiles de 32 pixels
This commit is contained in:
BIN
data/test.gif
BIN
data/test.gif
Binary file not shown.
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.4 KiB |
@@ -11,7 +11,7 @@ namespace actor
|
|||||||
return first;
|
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));
|
actor_t *act = (actor_t*)malloc(sizeof(actor_t));
|
||||||
act->pos = p;
|
act->pos = p;
|
||||||
@@ -36,14 +36,24 @@ namespace actor
|
|||||||
{
|
{
|
||||||
while (dirty)
|
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)
|
if (first)
|
||||||
{
|
{
|
||||||
actor_t *current = first;
|
actor_t *current = first;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
const int z_index2 = current->pos.x + current->pos.y + current->pos.z;
|
//const int z_index2 = current->pos.x + current->pos.y + current->pos.z;
|
||||||
if (z_index > z_index2)
|
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)
|
if (current->next)
|
||||||
{
|
{
|
||||||
@@ -58,15 +68,6 @@ namespace actor
|
|||||||
break;
|
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
|
else
|
||||||
@@ -82,7 +83,7 @@ namespace actor
|
|||||||
{
|
{
|
||||||
if (!act) return;
|
if (!act) return;
|
||||||
const int x = 148-act->bmp_offset.x + act->pos.x*2 - act->pos.y*2;
|
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);
|
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);
|
if (draw_all && act->next) draw(act->next);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,23 +3,18 @@
|
|||||||
|
|
||||||
namespace actor
|
namespace actor
|
||||||
{
|
{
|
||||||
struct pos_t
|
struct vec3_t
|
||||||
{
|
{
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct size_t
|
|
||||||
{
|
|
||||||
int w, h, d;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct actor_t
|
struct actor_t
|
||||||
{
|
{
|
||||||
SDL_Rect bmp_rect;
|
SDL_Rect bmp_rect;
|
||||||
SDL_Point bmp_offset;
|
SDL_Point bmp_offset;
|
||||||
|
|
||||||
pos_t pos;
|
vec3_t pos;
|
||||||
size_t size;
|
vec3_t size;
|
||||||
|
|
||||||
actor_t *prev;
|
actor_t *prev;
|
||||||
actor_t *next;
|
actor_t *next;
|
||||||
@@ -27,7 +22,7 @@ namespace actor
|
|||||||
|
|
||||||
actor_t *getFirst();
|
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);
|
void setDirty(actor_t *act);
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ void game::init()
|
|||||||
draw::loadPalette("test.gif");
|
draw::loadPalette("test.gif");
|
||||||
game::setUpdateTicks(64);
|
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);
|
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::setDirty(box);
|
||||||
actor::reorder();
|
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_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_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_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();
|
actor::reorder();
|
||||||
|
|
||||||
draw::cls(8);
|
draw::cls(8);
|
||||||
@@ -37,7 +39,7 @@ bool game::loop()
|
|||||||
{
|
{
|
||||||
for (int x=0;x<8;++x)
|
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());
|
actor::draw(actor::getFirst());
|
||||||
|
|||||||
Reference in New Issue
Block a user