supercasiobros/src/world.c

142 lines
3.3 KiB
C
Raw Normal View History

2019-11-16 11:44:09 +01:00
#include "world.h"
#include "tile.h"
2019-11-20 15:33:34 +01:00
#include <gint/display.h>
2019-11-16 11:44:09 +01:00
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
2019-11-20 15:33:34 +01:00
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;
2019-11-16 11:44:09 +01:00
world_t world_get(int x, int y)
{
2019-11-20 15:33:34 +01:00
x/=8;
y/=8;
if (0<=x && x<current_x && 0<=y && y<current_y)
return current[x*current_y+y];
2019-11-16 11:44:09 +01:00
else
{
2019-11-20 15:33:34 +01:00
world_t cell={DEATH,0,0,0};
2019-11-16 11:44:09 +01:00
return cell;
}
}
void display_cell(int cx, int cy, int sx, int sy)
{
2019-11-20 15:33:34 +01:00
2019-11-16 11:44:09 +01:00
world_t cell=world_get(cx,cy);
2019-11-20 15:33:34 +01:00
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);
2019-11-16 11:44:09 +01:00
}
2019-11-20 15:33:34 +01:00
int world_get_ctg(int x, int y)
2019-11-16 12:02:30 +01:00
{
2019-11-20 15:33:34 +01:00
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);;}
*/
2019-11-16 12:02:30 +01:00
2019-11-20 15:33:34 +01:00
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;
}
2019-11-16 12:02:30 +01:00
}