Added limited seclection of borders while moving player

This commit is contained in:
Sylvain PILLOT 2023-05-18 22:34:45 +02:00
parent 592d1ce66c
commit 580c0e2d61
3 changed files with 29 additions and 10 deletions

View File

@ -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->nextx<azrp_width && MyPlayer->nexty >=0 && MyPlayer->nexty<azrp_height)
return true;
else
return false;
}
/*RETURN true if the player is above a solid tile*/
@ -509,10 +512,20 @@ void Level::UpdateBorders( void )
MyLevelBorders.clear();
uint16_t xp = MyPlayer.tileX;
uint16_t yp = MyPlayer.tileY;
for( int i=10; i<map_level->w; 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; i<map_level->w; i++)
for( int i=xmin; i<=xmax; i++)
{
for( int j=10; j<map_level->h; j++)
//for( int j=10; j<map_level->h; j++)
for( int j=ymin; j<=ymax; j++)
{
uint16_t index = j * map_level->w + i;
int16_t currentTile = map_level->layers[0][ index ];

View File

@ -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();
}

View File

@ -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;