supercasiobros/src/world.c

127 lines
3.8 KiB
C
Executable File

#include "world.h"
#include "tile.h"
#include <gint/display.h>
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, 2, 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, 1, 3, 0}, {TUYAU, 1, 2, 0}, {0,0,0,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},
{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,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,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,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,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,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}
};
static world_t * current = tuyau_sample;
static int current_x=12;
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 0;
}
}
void display_cell(int cx, int cy, int sx, int sy)
{
const world_t * cell=world_get(cx,cy);
if (cell==0)
{
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==0)
{
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 int max(const int x, const int y)
{
return (x<y?y:x);
}
int world_get_real_x0(int x) //mario delta en 0,0
{return max(x-63,0);}
int world_get_real_y0(int y) //mario delta en 0,0
{return max(y-31,0);}
void world_draw(int x, int y)
{
int mx0=world_get_real_x0(x);
int my0=world_get_real_y0(y);
int sx0=mx0%8;
int sy0=my0%8;
//int mx, my;
int mx=mx0;
for (int i=0; i<=16; i++)
{
int my=my0;
for (int j=0; j<=8; j++)
{
display_cell(mx, my, 8*i-sx0, 8*j-sy0);
my+=8;
}
mx+=8;
}
}