#include "world.h" #include "tile.h" #include "mario.h" #include "ennemi.h" #include #include "bonus.h" #include #include "constants.h" #include "ennemi.h" #include 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 && xtype==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==BLOC) { draw_tile(sx, sy, &bloc, 0, 0); } if (cell->type==BLOC) { draw_tile(sx, sy, &bloc, 0, 0); } 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->state==1 && i->time_hit_id==0) i->type=0; } if (i->hidden==0) { 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) 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->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) draw_tile(sx, sy+8, &coin, 0, 0); } } } else { if (cell->type==COIN) { coin_t* i=cell; 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); } } } int world_get_ctg(int x, int y) { world_t *c=world_get(x,y); if (c==0) { return CTG_DEATH; } if (plateforme_check_collide(x,y)) return CTG_SOIL; switch (c->type) { case TUYAU: case GIFT: case BRICK: case EARTH: case BLOC: return CTG_SOIL; default: return CTG_EMPTY; } } static int max(const int x, const int y) { return (xy?y:x); } 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); } 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 { //static int y=mario.p.y; return /*min(*/max(max_cy-24,0)/*,w_current_y*8-64)*/; } void world_draw(int x, int y) { reload_camera(); int mx0=world_get_real_x0(); int my0=world_get_real_y0(); int sx0=mx0%8; int sy0=my0%8; 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,0); //ap my+=8; } mx+=8; } bonus_draw(); display_ennemi_table(); bullet_display(); display_plateformes(); mario_draw(); //int mx, my; 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,1); //pp my+=8; } mx+=8; } //teleporteurs_display(); //dvline(teleporteurs[0].x-world_get_real_x0(),C_BLACK); } void world_move() { ll_sendp(LEVEL_INFO,"\n[I;%d] Refresh wrld",frame_id); for (int i=0; i Moved ennemies"); bonus_move(); ll_sendp(LEVEL_INFO,"\n > Moved bonus"); bullet_move(); ll_sendp(LEVEL_INFO,"\n > Moved bullets"); move_plateformes(); mario_move(); ll_sendp(LEVEL_INFO,"\n > Moved mario !\n"); }