predictCollisions func added to Game.cpp

This commit is contained in:
2022-05-13 23:20:08 -04:00
parent e28a9cebdb
commit 36adcdeac7
7 changed files with 70 additions and 20 deletions

View File

@ -43,13 +43,15 @@ public:
{
case SDLK_UP:
if(Game::gsm->currentState == GameStateManager::ST_COREGAME){
if(transform->position.y>0){
// if(transform->position.y>0){
// ====== Get Player.yTile and scan column up ScreenTilesHeight/2 on Player.xTile-1, Player.xTile, and Player.xTile+1 return first hit that is > 0 for each row.
// transform->tilePos.x
transform->velocity.y = -1;
// if(Game::playerIsGrounded){
sprite->Play("Walk");
sprite->Play("Walk");
// }
sprite->spriteFlip = SDL_FLIP_NONE;
}
// }
}
break;
case SDLK_DOWN:
@ -59,6 +61,8 @@ public:
// if(Game::playerIsGrounded){
sprite->Play("Walk");
// }
int *borders;
borders = Game::predictCollisions();
sprite->spriteFlip = SDL_FLIP_NONE;
}
}
@ -73,13 +77,22 @@ public:
// }
// transform->lastSafePos = Vector2D(transform->position.x,transform->position.y);
// printf("lastSafePos .x: %g .y: %g \n",transform->lastSafePos.x,transform->lastSafePos.y);
if(transform->position.x>0){
// Game::pTileX
// if(transform->position.x>0){
// ====== For Each Row ====
// for (int r=Game::pTileY-1;r<=Game::pTileY+1;r++){
// ====== For Each Tile (Column) =====
// for (int c=Game::pTileX;c>Game::pTileX-Game::camera.w;c--){
//
//
// }
// }
transform->velocity.x = -1;
// if(Game::playerIsGrounded){
sprite->Play("Walk");
// }
sprite->spriteFlip = SDL_FLIP_NONE;
}
// }
}
break;
case SDLK_RIGHT:
@ -135,7 +148,7 @@ public:
{
Mix_PlayChannel(-1, Game::assets->GetSoundClip("bwoop"),0);
}
transform->lastSafePos = Vector2D(transform->position.x,transform->position.y);
// transform->lastSafePos = Vector2D(transform->position.x,transform->position.y);
Game::gravityOnPlayer = true;
sprite->Play("Jump");
transform->velocity.y = -2;

View File

@ -18,7 +18,8 @@ public:
Vector2D position;
Vector2D velocity;
Vector2D lastSafePos;
// Vector2D lastSafePos;
Vector2D tilePos;
int height = 40;
int width = 30;
@ -56,14 +57,19 @@ public:
void init() override
{
velocity.Zero();
lastSafePos.Zero();
tilePos.Zero();
// lastSafePos.Zero();
}
void update() override
{
position.x += velocity.x * speed;
position.y += velocity.y * speed;
}
void updateTilePosition(int x,int y){
tilePos.x = x;
tilePos.y = y;
}
};