added basic collision

This commit is contained in:
Return0ne 2021-11-18 17:44:12 -05:00
parent 528aa248f3
commit 53130a6d19
2 changed files with 30 additions and 3 deletions

View File

@ -13,6 +13,7 @@ Make sure to read the LICENSE file
* More clean code
* Build Guide
* Hitboxes
* Hitboxes working in .h files
* Screen Boundaries
* Projectiles
* Portable Binaries of the game

View File

@ -30,11 +30,27 @@ void Func_MainGameLoop()
Texture2D enemy = LoadTexture("assets/enemy.png");
Texture2D arctic = LoadTexture("assets/arctic.png");
// Hitboxes
Rectangle EnemyHitbox = { GetScreenWidth()/2.0f - 30, GetScreenHeight()/2.0f - 30, 290, 300};
Rectangle TuxHitbox = { GetScreenWidth()/2.0f - 30, GetScreenHeight()/2.0f - 30, 90, 40};
Rectangle boxCollision = { 0 };
bool collision = false;
// GameLoop
while (!WindowShouldClose()) {
Func_ShowPos();
Func_Controls();
TuxHitbox.x = TuxPos_x+50;
TuxHitbox.y = TuxPos_y+50;
EnemyHitbox.x = EnemyPos_x;
EnemyHitbox.y = EnemyPos_y;
collision = CheckCollisionRecs(EnemyHitbox, TuxHitbox);
if (collision) boxCollision = GetCollisionRec(EnemyHitbox, TuxHitbox);
BeginDrawing();
ClearBackground(RAYWHITE);
@ -42,8 +58,18 @@ void Func_MainGameLoop()
DrawTexture(arctic, 50, 0, RAYWHITE);
DrawTexture(tux, TuxPos_x, TuxPos_y, RAYWHITE);
DrawTexture(enemy, EnemyPos_x, EnemyPos_y, RAYWHITE);
DrawText("Tux Vs X ENGINE PROTOTYPE please read the LINCENSE", 50, 18, 20, BLACK);
if (IsKeyDown(KEY_SPACE)) {
DrawRectangleRec(EnemyHitbox, RED);
DrawRectangleRec(TuxHitbox, BLUE);
}
if (collision) {
DrawText("FINALY BASIC AWFUL COLLISION", 50, 18, 20, BLACK);
} else {
DrawText("Tux Vs X ENGINE PROTOTYPE please read the LINCENSE", 50, 18, 20, BLACK);
}
EndDrawing();
}
// Unload Textures