2019-11-16 11:44:09 +01:00
|
|
|
#include "world.h"
|
|
|
|
#include "tile.h"
|
|
|
|
|
2019-11-16 12:02:30 +01:00
|
|
|
#define min(x,y) (x>y?y:x)
|
|
|
|
#define max(x,y) (x<y?y:x)
|
2019-11-16 11:44:09 +01:00
|
|
|
|
|
|
|
static world global = {0};
|
|
|
|
|
|
|
|
world_t world_get(int x, int y)
|
|
|
|
{
|
|
|
|
if (0<=x && x<=W_SIZE_X && 0<=y && y<=W_SIZE_Y)
|
|
|
|
return global[x][y];
|
|
|
|
else
|
|
|
|
{
|
2019-11-16 12:02:30 +01:00
|
|
|
world_t cell = {W_DEATH,0,0};
|
2019-11-16 11:44:09 +01:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void display_cell(int cx, int cy, int sx, int sy)
|
|
|
|
{
|
|
|
|
world_t cell=world_get(cx,cy);
|
|
|
|
if (cell.type==W_TUYAU)
|
|
|
|
tuyau_draw(cell.state, sx, sy);
|
|
|
|
}
|
|
|
|
|
2019-11-16 12:02:30 +01:00
|
|
|
void world_draw(int x, int y)
|
|
|
|
{
|
|
|
|
int c_top, c_left;
|
|
|
|
int s_top, s_left;
|
|
|
|
|
|
|
|
c_left = max(0, x/8-8);
|
|
|
|
c_top = max(0, y/8-4);
|
|
|
|
|
|
|
|
s_left = (x+1)%8 - 8;
|
|
|
|
s_top = (y+1)%8 - 8;
|
|
|
|
for (int t=s_left, cx=c_left; t<128; t+=8, cx++)
|
|
|
|
for (int u=s_top, cy=c_top; u<64; u+=8, cy++)
|
|
|
|
display_cell(cx,cy, t,u);
|
|
|
|
|
|
|
|
}
|