#include "background.h" #include "player.h" #include #include #include #include extern struct Map map_level1; extern struct Map map_level2; extern struct Map map_level3; extern bool drawbackground; struct Map *map_level; Background::Background( ) { map_level = &map_level2; } Background::~Background( ) { } void Background::ChangeMap( int level, Player *MyPlayer ) { if(level==1) map_level = &map_level1; else if(level==2) map_level = &map_level2; else if(level==3) map_level = &map_level3; else map_level = &map_level1; UpdateDataMap( MyPlayer ); } void Background::UpdateDataMap( Player *MyPlayer ) { for(int i=0; iw; i++) { for(int j=0; j<=map_level->h; j++) { uint16_t index = (j) * map_level->w + (i) % map_level->w; uint16_t currentTile = map_level->layers[1][ index ]; if (currentTile==11) { MyPlayer->x = libnum::num( i*16 - 4 + 8 ); MyPlayer->y = libnum::num( j*16 + 8 ); MyPlayer->vx = 0; MyPlayer->vy = 0; MyPlayer->Update( 0.0f, 0.0f, 0.0f ); } } } } void Background::Render( void ) { for(int u=!drawbackground; unblayers;u++) { for(int i=0; iw; i++) { for(int j=0; j<=map_level->h; j++) { uint16_t index = (j) * map_level->w + (i) % map_level->w; uint16_t currentTile = map_level->layers[u][ index ]; if (currentTile!=0 && currentTile!=11) { uint16_t xtile = ((currentTile % map_level->tileset_size)-1) * 16; uint16_t ytile = (currentTile / map_level->tileset_size) * 16; azrp_subimage_p8( i*16-4, j*16, map_level->tileset, xtile, ytile, 16, 16, DIMAGE_NONE ); } } } } } void Background::Update( float dt ) { } bool Background::CanGo( Player *MyPlayer ) { int tileX = ((int) MyPlayer->x+4) >> 4 ; int tileY = ((int) MyPlayer->y+8) >> 4; int tileIndex = tileY*map_level->w + tileX; int tileValue = map_level->layers[0][ tileIndex ]; if (tileValue==0 || tileValue==1) return true; else return false; }