2021-11-22 23:33:11 +00:00
|
|
|
#include <stdbool.h>
|
2021-08-28 22:48:16 +00:00
|
|
|
#include "raylib.h"
|
2021-09-12 19:23:15 +00:00
|
|
|
|
2021-08-28 22:48:16 +00:00
|
|
|
#include "Controls.h"
|
2021-09-05 16:30:50 +00:00
|
|
|
#include "Debug.h"
|
2021-09-18 15:22:16 +00:00
|
|
|
#include "Copying.h"
|
2021-08-28 22:48:16 +00:00
|
|
|
|
2021-11-29 16:03:12 +00:00
|
|
|
/* Functions */
|
2021-11-22 23:33:11 +00:00
|
|
|
|
2021-11-22 01:46:42 +00:00
|
|
|
|
2021-11-29 16:03:12 +00:00
|
|
|
/* Globles */
|
2021-08-28 22:48:16 +00:00
|
|
|
|
|
|
|
// Position Varaibles
|
|
|
|
float EnemyPos_x = 482.0f, EnemyPos_y = 62.0f;
|
2021-09-05 16:30:50 +00:00
|
|
|
float TuxPos_x = 32.0f, TuxPos_y = 62.0f;
|
2021-08-28 22:48:16 +00:00
|
|
|
|
2021-11-19 22:36:33 +00:00
|
|
|
// Toggle bools
|
|
|
|
bool ShowHitbox = false;
|
2021-11-22 23:33:11 +00:00
|
|
|
bool ToggleShowPos = false;
|
2021-11-19 22:36:33 +00:00
|
|
|
|
2021-08-28 22:48:16 +00:00
|
|
|
// Setup Code
|
2021-11-22 23:33:11 +00:00
|
|
|
void Setup()
|
2021-08-28 22:48:16 +00:00
|
|
|
{
|
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 450;
|
|
|
|
|
|
|
|
InitWindow(screenWidth, screenHeight, "Tux Vs Windows");
|
|
|
|
|
2021-11-29 16:03:12 +00:00
|
|
|
InitAudioDevice();
|
|
|
|
|
2021-08-28 22:48:16 +00:00
|
|
|
SetTargetFPS(60);
|
|
|
|
}
|
|
|
|
|
|
|
|
// GameLoop Code
|
2021-11-22 23:33:11 +00:00
|
|
|
void MainGameLoop()
|
2021-08-28 22:48:16 +00:00
|
|
|
{
|
2021-11-29 16:03:12 +00:00
|
|
|
// Load Assets
|
|
|
|
Texture2D tux = LoadTexture("assets/gfx/tux.png");
|
|
|
|
Texture2D enemy = LoadTexture("assets/gfx/enemy.png");
|
|
|
|
Texture2D arctic = LoadTexture("assets/gfx/arctic.png");
|
|
|
|
Sound sfxHit = LoadSound("assets/sfx/hit.wav");
|
2021-08-28 22:48:16 +00:00
|
|
|
|
2021-11-18 22:44:12 +00:00
|
|
|
// 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};
|
|
|
|
|
|
|
|
|
|
|
|
bool collision = false;
|
|
|
|
|
2021-11-22 01:46:42 +00:00
|
|
|
// GameLoop
|
2021-11-19 22:36:33 +00:00
|
|
|
while (!WindowShouldClose()) {
|
|
|
|
|
2021-11-22 01:46:42 +00:00
|
|
|
// Checks and calls the Pos show function
|
2021-11-22 23:33:11 +00:00
|
|
|
if (IsKeyPressed(KEY_P)) ToggleShowPos = !ToggleShowPos;
|
|
|
|
if (ToggleShowPos==true) ShowPos();
|
2021-11-22 01:46:42 +00:00
|
|
|
|
2021-11-22 23:33:11 +00:00
|
|
|
Controls();
|
2021-08-28 22:48:16 +00:00
|
|
|
|
2021-11-18 22:44:12 +00:00
|
|
|
TuxHitbox.x = TuxPos_x+50;
|
|
|
|
TuxHitbox.y = TuxPos_y+50;
|
|
|
|
EnemyHitbox.x = EnemyPos_x;
|
|
|
|
EnemyHitbox.y = EnemyPos_y;
|
|
|
|
|
|
|
|
collision = CheckCollisionRecs(EnemyHitbox, TuxHitbox);
|
|
|
|
|
2021-08-28 22:48:16 +00:00
|
|
|
BeginDrawing();
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
|
2021-09-18 15:22:16 +00:00
|
|
|
// Put the sprites and text on the screen
|
2021-08-28 22:48:16 +00:00
|
|
|
DrawTexture(arctic, 50, 0, RAYWHITE);
|
|
|
|
DrawTexture(tux, TuxPos_x, TuxPos_y, RAYWHITE);
|
|
|
|
DrawTexture(enemy, EnemyPos_x, EnemyPos_y, RAYWHITE);
|
2021-11-18 22:44:12 +00:00
|
|
|
|
2021-11-22 23:33:11 +00:00
|
|
|
CheckHitboxToggle();
|
2021-11-19 22:36:33 +00:00
|
|
|
|
|
|
|
if (ShowHitbox==true) {
|
2021-11-18 22:44:12 +00:00
|
|
|
DrawRectangleRec(EnemyHitbox, RED);
|
|
|
|
DrawRectangleRec(TuxHitbox, BLUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collision) {
|
2021-11-22 01:46:42 +00:00
|
|
|
DrawText("FINALY BASIC AWFUL COLLISION", 50, 18, 20, MAROON);
|
2021-11-29 16:03:12 +00:00
|
|
|
PlaySound(sfxHit);
|
2021-11-18 22:44:12 +00:00
|
|
|
} else {
|
|
|
|
DrawText("Tux Vs X ENGINE PROTOTYPE please read the LINCENSE", 50, 18, 20, BLACK);
|
|
|
|
}
|
|
|
|
|
2021-11-22 01:46:42 +00:00
|
|
|
DrawText("Press 'H' to toggle hitboxes", 50, 72, 20, DARKGREEN);
|
|
|
|
DrawText("Press 'P' to toggle printing of the positions", 50, 95, 20, DARKGREEN);
|
2021-11-19 22:36:33 +00:00
|
|
|
|
2021-08-28 22:48:16 +00:00
|
|
|
EndDrawing();
|
2021-11-19 22:36:33 +00:00
|
|
|
}
|
2021-11-29 16:03:12 +00:00
|
|
|
// Unload Assets
|
2021-08-28 22:48:16 +00:00
|
|
|
UnloadTexture(tux);
|
|
|
|
UnloadTexture(enemy);
|
|
|
|
UnloadTexture(arctic);
|
2021-11-29 16:03:12 +00:00
|
|
|
UnloadSound(sfxHit);
|
2021-08-28 22:48:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2021-11-22 23:33:11 +00:00
|
|
|
Setup();
|
|
|
|
MainGameLoop();
|
2021-11-29 16:03:12 +00:00
|
|
|
|
|
|
|
CloseAudioDevice();
|
2021-08-28 22:48:16 +00:00
|
|
|
CloseWindow();
|
2021-11-29 16:03:12 +00:00
|
|
|
|
2021-11-22 23:33:11 +00:00
|
|
|
License();
|
2021-09-18 15:22:16 +00:00
|
|
|
|
2021-08-28 22:48:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|