diff --git a/src/level.cpp b/src/level.cpp index 22f707f..b23181e 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -192,11 +192,14 @@ int Level::GetTileForeground( uint16_t x, uint16_t y ) /*RETURN true if the player can go in the target position*/ bool Level::CanGo( Player *MyPlayer ) { - uint16_t targetTile = this->GetTileBackgroundINT( (int) MyPlayer->nextx, (int) MyPlayer->nexty ); +// uint16_t targetTile = this->GetTileBackgroundINT( (int) MyPlayer->nextx, (int) MyPlayer->nexty ); - if (targetTile!=0) return false; +// if (targetTile!=0) return false; - return true; + if (MyPlayer->nextx >=0 && MyPlayer->nextxnexty >=0 && MyPlayer->nextyw; i++) + uint16_t xmin = max( xp - 1, 0 ); + uint16_t xmax = min( xp + 1, map_level->w-1 ); + + uint16_t ymin = max( yp - 1, 0 ); + uint16_t ymax = min( yp + 1, map_level->h-1 ); + + // for( int i=10; iw; i++) + for( int i=xmin; i<=xmax; i++) { - for( int j=10; jh; j++) + //for( int j=10; jh; j++) + for( int j=ymin; j<=ymax; j++) { uint16_t index = j * map_level->w + i; int16_t currentTile = map_level->layers[0][ index ]; diff --git a/src/main.cpp b/src/main.cpp index 33e22d8..9b08e96 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -122,7 +122,7 @@ static void render( void ) #if(BIAS) if (texttodraw>=1) azrp_draw_text(1,01, "FPS = %.0f - Mem Free = %d", (float) (1000.0f / elapsedTime), _uram_stats->free_memory + extram_stats->free_memory ); - if (texttodraw==1) azrp_draw_text(1,11, "PlayX = %d - PlayY = %d", MyPlayer.tileX, MyPlayer.tileY ); + if (texttodraw>=1) azrp_draw_text(1,11, "PlayX = %d - PlayY = %d", MyPlayer.tileX, MyPlayer.tileY ); if (texttodraw>=2) azrp_draw_text(1,31, "Update = %.3f ms", (float) time_update / 1000.0f ); if (texttodraw>=2) azrp_draw_text(1,41, "Render = %.3f ms", (float) time_render / 1000.0f ); @@ -230,6 +230,10 @@ bool AddMoreRAM( void ) kmalloc_add_arena(&extended_ram ); return true; } + else + { + return false; + } } void FreeMoreRAM( void ) @@ -295,8 +299,7 @@ int main(void) render(); - azrp_circle( (int) MyPlayer.currx, (int) MyPlayer.curry, 16, C_RED ); - azrp_circle( (int) MyPlayer.currx, (int) MyPlayer.curry, 17, C_RED ); + azrp_circle( (int) MyPlayer.currx, (int) MyPlayer.curry, 8, C_RED ); azrp_update(); } diff --git a/src/player.cpp b/src/player.cpp index 3c8aaca..faf82c3 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -62,8 +62,11 @@ void Player::Update( float dt ) this->nextx = this->currx + this->vx * DeltaTime; this->nexty = this->curry + this->vy * DeltaTime; - this->currx = this->nextx; - this->curry = this->nexty; + if (MyLevel.CanGo( this )) + { + this->currx = this->nextx; + this->curry = this->nexty; + } this->tileX = ((int) this->currx) / 16; this->tileY = ((int) this->curry) / 16;