163 lines
2.7 KiB
C
Executable File
163 lines
2.7 KiB
C
Executable File
#include "world.h"
|
|
#include "tile.h"
|
|
#include "mario.h"
|
|
#include "ennemi.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 death={0,0};
|
|
|
|
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
|
|
{
|
|
return &death;
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
tuyau_t* i=(tuyau_t*)cell;
|
|
draw_tile(sx, sy, &tuyau, i->x, i->y);
|
|
}
|
|
|
|
if (cell->type==EARTH)
|
|
{
|
|
earth_t* i=(earth_t*)cell;
|
|
draw_tile(sx, sy, &earth, i->x, i->y);
|
|
}
|
|
if (cell->type==BRICK)
|
|
{
|
|
brick_t* i=(brick_t*)cell;
|
|
if (i->time_hit_id)
|
|
{
|
|
i->time_hit_id++;
|
|
sy+=2+(i->time_hit_id-4)/4;
|
|
if (i->time_hit_id==8)
|
|
i->time_hit_id=0;
|
|
}
|
|
if (i->time_hit_id || i->content==0 || i->number)
|
|
draw_tile(sx, sy, &brick, 0, 0);
|
|
else
|
|
draw_tile(sx, sy, &gift, 1, 0);
|
|
if (i->content==1 && i->time_hit_id && i->time_hit_id<=4)
|
|
draw_tile(sx, sy+8, &coin, 0, 0);
|
|
}
|
|
|
|
if (cell->type==GIFT)
|
|
{
|
|
gift_t* i=(gift_t*)cell;
|
|
if (i->time_hit_id)
|
|
{
|
|
i->time_hit_id++;
|
|
sy+=2+(i->time_hit_id-4)/4;
|
|
if (i->time_hit_id==8)
|
|
i->time_hit_id=0;
|
|
}
|
|
if (i->time_hit_id || i->number)
|
|
draw_tile(sx, sy, &gift, 0, 0);
|
|
else
|
|
draw_tile(sx, sy, &gift, 1, 0);
|
|
if (i->content==1 && i->time_hit_id && i->time_hit_id<=4)
|
|
draw_tile(sx, sy+8, &coin, 0, 0);
|
|
}
|
|
|
|
if (cell->type==COIN)
|
|
{
|
|
coin_t* i=cell;
|
|
draw_tile(sx, sy, &coin, i->taken, 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);
|
|
}
|
|
|
|
static int min(const int x, const int y)
|
|
{
|
|
return (x>y?y:x);
|
|
}
|
|
|
|
int world_get_real_x0(int x) //mario delta en 0,0
|
|
{return min(max(mario_x_max-54,0),w_current_x*8-128);}
|
|
|
|
int world_get_real_y0(int y) //mario delta en 0,0
|
|
{return min(max(y-24,0),w_current_y*8-64);}
|
|
|
|
|
|
|
|
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;
|
|
display_ennemi_table();
|
|
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;
|
|
|
|
}
|
|
} |