142 lines
3.3 KiB
C
142 lines
3.3 KiB
C
#include "world.h"
|
|
#include "tile.h"
|
|
#include <gint/display.h>
|
|
|
|
#define min(x,y) (x>y?y:x)
|
|
#define max(x,y) (x<y?y:x)
|
|
|
|
static world_t tuyau_sample[]=
|
|
{
|
|
{EARTH,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
|
{EARTH,1,0,0}, {TUYAU, 0, 3, 0}, {TUYAU, 0, 3, 0}, {TUYAU, 0, 2, 0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
|
{EARTH,1,0,0}, {TUYAU, 1, 3, 0}, {TUYAU, 1, 3, 0}, {TUYAU, 1, 2, 0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
|
{EARTH,1,1,0}, {EARTH,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {BRICK,0,0,0}, {0,0,0,0}, {0,0,0,0},
|
|
{EARTH,1,1,0}, {EARTH,1,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {GIFT,0,0,0}, {COIN,0,0,0}, {COIN,0,0,0},
|
|
{EARTH,2,1,0}, {EARTH,2,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {BRICK,0,0,0}, {0,0,0,0}, {0,0,0,0}
|
|
};
|
|
|
|
static world_t * current = tuyau_sample;
|
|
static int current_x=6;
|
|
static int current_y=8;
|
|
|
|
world_t world_get(int x, int y)
|
|
{
|
|
x/=8;
|
|
y/=8;
|
|
if (0<=x && x<current_x && 0<=y && y<current_y)
|
|
return current[x*current_y+y];
|
|
else
|
|
{
|
|
world_t cell={DEATH,0,0,0};
|
|
return cell;
|
|
}
|
|
}
|
|
|
|
void display_cell(int cx, int cy, int sx, int sy)
|
|
{
|
|
|
|
|
|
world_t cell=world_get(cx,cy);
|
|
if (cell.type==DEATH)
|
|
{
|
|
extern image_t img_death;
|
|
dimage(sx, sy, &img_death);
|
|
return;
|
|
}
|
|
|
|
if (cell.type==TUYAU)
|
|
draw_tile(sx, sy, &tuyau, cell.p1, cell.p2);
|
|
|
|
if (cell.type==EARTH)
|
|
draw_tile(sx, sy, &earth, cell.p1, cell.p2);
|
|
|
|
if (cell.type==BRICK)
|
|
draw_tile(sx, sy, &brick, 0, cell.p1);
|
|
|
|
if (cell.type==GIFT)
|
|
draw_tile(sx, sy, &gift, cell.p1, 0);
|
|
|
|
if (cell.type==COIN)
|
|
draw_tile(sx, sy, &coin, cell.p1, 0);
|
|
|
|
}
|
|
|
|
int world_get_ctg(int x, int y)
|
|
{
|
|
world_t c=world_get(x,y);
|
|
if (c.type==DEATH)
|
|
{
|
|
return CTG_DEATH;
|
|
}
|
|
switch (c.type)
|
|
{
|
|
case COIN:
|
|
case EMPTY:
|
|
return CTG_EMPTY;
|
|
case DEATH:
|
|
return CTG_DEATH;
|
|
case TUYAU:
|
|
case GIFT:
|
|
case BRICK:
|
|
case EARTH:
|
|
return CTG_SOIL;
|
|
default:
|
|
return CTG_EMPTY;
|
|
}
|
|
}
|
|
/*
|
|
static world_get_leftx(int x)
|
|
{
|
|
int r = max(x-63,0)%8;// if (r>0) r-=8;
|
|
return r;
|
|
}
|
|
|
|
static world_get_bottomy(int x)
|
|
{
|
|
int r = max(x-31,0)%8;// if (r>0) r-=8;
|
|
return r;
|
|
}
|
|
*/
|
|
|
|
int world_get_real_x0(int x) //mario delta en 0,0
|
|
{return max(x-63,0);}
|
|
|
|
int world_get_real_y0(int x) //mario delta en 0,0
|
|
{return max(x-31,0);}
|
|
/*
|
|
static int get_cleft(int c)
|
|
{return max(0, max(c-63,0)/8);}
|
|
|
|
static int get_ctop(int c)
|
|
{return max(0, max(c-31,0)/8);;}
|
|
*/
|
|
|
|
|
|
|
|
|
|
void world_draw(int x, int y)
|
|
{
|
|
int s_left = world_get_real_x0(x)%8-8;
|
|
int s_top = world_get_real_y0(y)%8-8;
|
|
|
|
|
|
int tx, ty, rx, ry;
|
|
|
|
tx=s_left;
|
|
rx=world_get_real_x0(x)-8;
|
|
while (tx<128)
|
|
{
|
|
ry=world_get_real_y0(y)-8;
|
|
ty=s_top;
|
|
while (ty<64)
|
|
{
|
|
display_cell(rx,ry, tx, ty);
|
|
ty+=8;
|
|
ry+=8;
|
|
}
|
|
tx+=8;
|
|
rx+=8;
|
|
}
|
|
|
|
|
|
} |