supercasiobros/src/world.c

261 lines
4.7 KiB
C
Raw Normal View History

2019-11-16 11:44:09 +01:00
#include "world.h"
#include "tile.h"
#include "mario.h"
2019-12-04 19:27:27 +01:00
#include "ennemi.h"
2019-11-20 15:33:34 +01:00
#include <gint/display.h>
#include "bonus.h"
2020-01-06 20:56:10 +01:00
#include <liblog.h>
#include "constants.h"
#include "ennemi.h"
#include <plateforme.h>
2020-01-24 12:08:40 +01:00
#include <tuyau.h>
2020-01-06 20:56:10 +01:00
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()
{
2019-12-07 19:26:55 +01:00
return w_current_x*8;
}
2019-11-16 11:44:09 +01:00
2019-12-04 19:27:27 +01:00
world_t death={0,0};
2019-11-20 18:31:20 +01:00
world_t* world_get(int x, int y)
2019-11-16 11:44:09 +01:00
{
2019-12-04 19:27:27 +01:00
x/=8;
y/=8;
2019-12-07 19:26:55 +01:00
if (0<=x && x<w_current_x && 0<=y && y<w_current_y)
2019-12-04 19:27:27 +01:00
return &w_current[x*w_current_y+y];
else
{
return &death;
}
2019-11-16 11:44:09 +01:00
}
void display_cell(int cx, int cy, int sx, int sy, int plan)
2019-11-16 11:44:09 +01:00
{
2019-12-04 19:27:27 +01:00
const world_t * cell=world_get(cx,cy);
2019-12-07 19:26:55 +01:00
if (cell==0)
2019-12-04 19:27:27 +01:00
return;
2019-12-07 19:26:55 +01:00
if (plan==1)
2019-12-04 19:27:27 +01:00
{
if (cell->type==TUYAU)
{
2019-12-07 19:26:55 +01:00
tuyau_t* i=(tuyau_t*)cell;
draw_tile(sx, sy, &tuyau, i->x, i->y);
}
2019-12-04 19:27:27 +01:00
if (cell->type==EARTH)
2019-12-04 19:27:27 +01:00
{
2019-12-07 19:26:55 +01:00
earth_t* i=(earth_t*)cell;
draw_tile(sx, sy, &earth, i->x, i->y);
2019-12-04 19:27:27 +01:00
}
2019-12-08 16:34:32 +01:00
if (cell->type==BLOC)
{
draw_tile(sx, sy, &bloc, 0, 0);
}
2019-12-04 19:27:27 +01:00
if (cell->type==BLOC)
2019-12-04 19:27:27 +01:00
{
2019-12-07 19:26:55 +01:00
draw_tile(sx, sy, &bloc, 0, 0);
2019-12-04 19:27:27 +01:00
}
if (cell->type==BRICK)
{
2019-12-07 19:26:55 +01:00
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;
2019-12-07 14:32:38 +01:00
if (i->state==1 && i->time_hit_id==0)
i->type=0;
}
if (i->hidden==0)
{
2019-12-07 14:32:38 +01:00
if (i->time_hit_id || i->content==0 || i->number>0)
draw_tile(sx, sy, &brick, 0, i->state);
else
draw_tile(sx, sy, &gift, 1, 0);
if (i->content==1 && i->time_hit_id && i->time_hit_id<=4)
2019-12-07 19:26:55 +01:00
draw_tile(sx, sy+8, &coin, 0, 0);
}
}
if (cell->type==GIFT)
{
gift_t* i=(gift_t*)cell;
2019-12-07 14:32:38 +01:00
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->hidden==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)
2019-12-07 19:26:55 +01:00
draw_tile(sx, sy+8, &coin, 0, 0);
}
}
}
else
2019-12-04 19:27:27 +01:00
{
if (cell->type==COIN)
{
coin_t* i=cell;
2019-12-07 19:26:55 +01:00
draw_tile(sx, sy, &coin, i->taken, 0);
}
if (cell->type==BUISSON || cell->type==NUAGE || cell->type==COLLINE || cell->type==CASTLE || cell->type==END_LEVEL)
{
deco_t* i=(deco_t*)cell;
if (i->type==BUISSON)
draw_tile(sx, sy, &buisson, i->x, i->y);
if (i->type==NUAGE)
draw_tile(sx, sy, &nuage, i->x, i->y);
if (i->type==COLLINE)
draw_tile(sx, sy, &colline, i->x, i->y);
if (i->type==CASTLE)
draw_tile(sx, sy, &castle, i->x, i->y);
if (i->type==END_LEVEL)
draw_tile(sx-8, sy, &end_level, 0, i->y);
}
2019-12-04 19:27:27 +01:00
}
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-12-04 19:27:27 +01:00
world_t *c=world_get(x,y);
2019-12-07 19:26:55 +01:00
if (c==0)
2019-12-04 19:27:27 +01:00
{
return CTG_DEATH;
}
if (plateforme_check_collide(x,y))
return CTG_SOIL;
2019-12-07 19:26:55 +01:00
switch (c->type)
2019-12-04 19:27:27 +01:00
{
case TUYAU:
case GIFT:
case BRICK:
case EARTH:
2019-12-08 16:34:32 +01:00
case BLOC:
2019-12-04 19:27:27 +01:00
return CTG_SOIL;
default:
return CTG_EMPTY;
}
2019-11-20 15:33:34 +01:00
}
2019-11-20 18:31:20 +01:00
static int max(const int x, const int y)
2019-11-20 15:33:34 +01:00
{
2019-12-07 19:26:55 +01:00
return (x<y?y:x);
2019-12-04 19:27:27 +01:00
}
static int min(const int x, const int y)
{
2019-12-07 19:26:55 +01:00
return (x>y?y:x);
2019-11-20 15:33:34 +01:00
}
static int max_cy=0;
void reset_camera()
{
max_cy=mario.p.y;
mario_x_max=mario.p.x;
}
int world_get_real_x0() //mario delta en 0,0
{ //if (mario.p.x>mario_x_max)
// mario_x_max=mario.p.x;
//if (mario_x_max-40>mario.p.x)
// mario_x_max=mario.p.x;
//return min(max(mario_x_max-40,0),w_current_x*8-128);
return min(max(mario.p.x-40,0),w_current_x*8-128);
2019-12-07 19:26:55 +01:00
}
2019-11-20 15:33:34 +01:00
void reload_camera()
{
const int step=3; // on ajoute 1/3
max_cy+=(mario.p.y-max_cy)/step;
}
int world_get_real_y0() //mario delta en 0,0
2020-01-11 19:15:06 +01:00
{
//static int y=mario.p.y;
return /*min(*/max(max_cy-24,0)/*,w_current_y*8-64)*/;
2020-01-11 19:15:06 +01:00
}
2019-11-16 12:02:30 +01:00
2019-11-20 15:33:34 +01:00
void world_draw(int x, int y)
{
reload_camera();
int mx0=world_get_real_x0();
int my0=world_get_real_y0();
2019-12-04 19:27:27 +01:00
int sx0=mx0%8;
int sy0=my0%8;
int mx=mx0;
for (int i=0; i<=17; i++)
{
int my=my0;
2019-12-07 19:26:55 +01:00
for (int j=0; j<=9; j++)
{
display_cell(mx, my, 8*i-sx0, 8*j-sy0,0); //ap
my+=8;
}
mx+=8;
}
bonus_draw();
2019-12-07 14:32:38 +01:00
display_ennemi_table();
bullet_display();
display_plateformes();
2019-12-04 19:27:27 +01:00
mario_draw();
2019-12-04 19:27:27 +01:00
//int mx, my;
mx=mx0;
2019-12-04 19:27:27 +01:00
for (int i=0; i<=17; i++)
{
int my=my0;
2019-12-07 19:26:55 +01:00
for (int j=0; j<=9; j++)
2019-12-04 19:27:27 +01:00
{
display_cell(mx, my, 8*i-sx0, 8*j-sy0,1); //pp
2019-12-04 19:27:27 +01:00
my+=8;
}
mx+=8;
2019-12-04 19:27:27 +01:00
}
//teleporteurs_display();
2020-01-06 20:56:10 +01:00
//dvline(teleporteurs[0].x-world_get_real_x0(),C_BLACK);
2019-12-08 16:34:32 +01:00
}
void world_move()
{
2020-01-06 20:56:10 +01:00
ll_sendp(LEVEL_INFO,"\n[I;%d] Refresh wrld",frame_id);
for (int i=0; i<ennemis_global_size; i++)
{
move_ennemi(&ennemis_global[i]);
}
ll_sendp(LEVEL_INFO,"\n > Moved ennemies");
2019-12-08 16:34:32 +01:00
bonus_move();
2020-01-06 20:56:10 +01:00
ll_sendp(LEVEL_INFO,"\n > Moved bonus");
2019-12-08 16:34:32 +01:00
bullet_move();
2020-01-06 20:56:10 +01:00
ll_sendp(LEVEL_INFO,"\n > Moved bullets");
move_plateformes();
2019-12-08 16:34:32 +01:00
mario_move();
2020-01-06 20:56:10 +01:00
ll_sendp(LEVEL_INFO,"\n > Moved mario !\n");
2020-01-24 12:08:40 +01:00
teleport_active();
2020-01-06 20:56:10 +01:00
}