supercasiobros/src/world.c

117 lines
2.1 KiB
C
Executable File

#include "world.h"
#include "tile.h"
#include "mario.h"
#include <gint/display.h>
world_t * w_current=0;
image_t * w_fond=0;
int w_current_x=0;
int w_current_y=0;
int w_mario_startx=0;
int w_mario_starty=0;
int world_get_width()
{
return w_current_x*8;
}
world_t* world_get(int x, int y)
{
x/=8;
y/=8;
if (0<=x && x<w_current_x && 0<=y && y<w_current_y)
return &w_current[x*w_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(mario_x_max-54,0);}
int world_get_real_y0(int y) //mario delta en 0,0
{return max(y-24,0);}
void world_draw(int x, int y)
{
dimage(0,0,w_fond);
int mx0=world_get_real_x0(x);
int my0=world_get_real_y0(y);
int sx0=mx0%8;
int sy0=my0%8;
mario_draw();
//int mx, my;
int mx=mx0;
for (int i=0; i<=17; i++)
{
int my=my0;
for (int j=0; j<=9; j++)
{
display_cell(mx, my, 8*i-sx0, 8*j-sy0);
my+=8;
}
mx+=8;
}
}