From 53130a6d1920a9a55f7b5595d609812339eaea75 Mon Sep 17 00:00:00 2001 From: Mark B Date: Thu, 18 Nov 2021 17:44:12 -0500 Subject: [PATCH 1/4] added basic collision --- README.md | 3 ++- src/Main.c | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b8b07fb..d6f2c30 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Main.c b/src/Main.c index 08a6baa..c8f5eed 100644 --- a/src/Main.c +++ b/src/Main.c @@ -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 From 6749eeb679308f81fba0b5df5e5ffb236d1f0d3d Mon Sep 17 00:00:00 2001 From: Mark B Date: Fri, 19 Nov 2021 17:36:33 -0500 Subject: [PATCH 2/4] added hitbox toggle --- src/Main.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Main.c b/src/Main.c index c8f5eed..6ad4e7a 100644 --- a/src/Main.c +++ b/src/Main.c @@ -1,6 +1,5 @@ #include "raylib.h" - #include "Controls.h" #include "Debug.h" #include "Copying.h" @@ -11,6 +10,9 @@ float EnemyPos_x = 482.0f, EnemyPos_y = 62.0f; float TuxPos_x = 32.0f, TuxPos_y = 62.0f; +// Toggle bools +bool ShowHitbox = false; + // Setup Code void Func_Setup() { @@ -39,7 +41,8 @@ void Func_MainGameLoop() bool collision = false; // GameLoop - while (!WindowShouldClose()) { + while (!WindowShouldClose()) { + Func_ShowPos(); Func_Controls(); @@ -59,7 +62,9 @@ void Func_MainGameLoop() DrawTexture(tux, TuxPos_x, TuxPos_y, RAYWHITE); DrawTexture(enemy, EnemyPos_x, EnemyPos_y, RAYWHITE); - if (IsKeyDown(KEY_SPACE)) { + Func_CheckHitboxToggle(); + + if (ShowHitbox==true) { DrawRectangleRec(EnemyHitbox, RED); DrawRectangleRec(TuxHitbox, BLUE); } @@ -70,14 +75,21 @@ void Func_MainGameLoop() DrawText("Tux Vs X ENGINE PROTOTYPE please read the LINCENSE", 50, 18, 20, BLACK); } + DrawText("Press 'H' to toggle hitboxes", 50, 72, 20, BLACK); + EndDrawing(); - } + } // Unload Textures UnloadTexture(tux); UnloadTexture(enemy); UnloadTexture(arctic); } +void Func_CheckHitboxToggle() +{ + if (IsKeyPressed(KEY_H)) ShowHitbox = !ShowHitbox; +} + int main() { From d748b0479fe40ce4d0032b33e30a0b37733732b5 Mon Sep 17 00:00:00 2001 From: Mark B Date: Sun, 21 Nov 2021 20:46:42 -0500 Subject: [PATCH 3/4] QOL improvement to the showpos function --- Makefile | 5 ++++- src/Controls.c | 8 ++++---- src/Copying.c | 1 + src/Main.c | 16 ++++++++++++---- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 0d4e600..87fb62f 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,11 @@ OBJS = src/Main.c src/Controls.c src/Debug.c src/Copying.c #compiler to use -CC = gcc +CC = cc +#gimmie dem warnings yo + +COMPILER_FLAGS = -Wall #libs we linkin bro diff --git a/src/Controls.c b/src/Controls.c index d236194..32a0196 100644 --- a/src/Controls.c +++ b/src/Controls.c @@ -6,8 +6,8 @@ // Controls void Func_Controls() { - if (IsKeyDown(KEY_LEFT)) {TuxPos_x -= GetFrameTime() * 800.0f;} - if (IsKeyDown(KEY_RIGHT)) {TuxPos_x += GetFrameTime() * 800.0f;} - if (IsKeyDown(KEY_UP)) {TuxPos_y -= GetFrameTime() * 800.0f;} - if (IsKeyDown(KEY_DOWN)) {TuxPos_y += GetFrameTime() * 800.0f;} + if (IsKeyDown(KEY_LEFT)) TuxPos_x -= GetFrameTime() * 800.0f; + if (IsKeyDown(KEY_RIGHT)) TuxPos_x += GetFrameTime() * 800.0f; + if (IsKeyDown(KEY_UP)) TuxPos_y -= GetFrameTime() * 800.0f; + if (IsKeyDown(KEY_DOWN)) TuxPos_y += GetFrameTime() * 800.0f; } diff --git a/src/Copying.c b/src/Copying.c index fdb54b6..cd618b6 100644 --- a/src/Copying.c +++ b/src/Copying.c @@ -10,5 +10,6 @@ void Func_License() "This program comes with ABSOLUTELY NO WARRANTY; \n" "This is free software, and you are welcome to redistribute it\n" "under certain conditions; for details read the LICENSE.\n" + "For the source code go to https://gitdab.com/Canneddonuts/Tux_Vs_X_ENGINE.git\n" ); } diff --git a/src/Main.c b/src/Main.c index 6ad4e7a..8c9ff1d 100644 --- a/src/Main.c +++ b/src/Main.c @@ -4,6 +4,9 @@ #include "Debug.h" #include "Copying.h" +// Functions +void Func_CheckHitboxToggle(); + // Globles // Position Varaibles @@ -12,6 +15,7 @@ float TuxPos_x = 32.0f, TuxPos_y = 62.0f; // Toggle bools bool ShowHitbox = false; +bool ShowPos = false; // Setup Code void Func_Setup() @@ -40,10 +44,13 @@ void Func_MainGameLoop() Rectangle boxCollision = { 0 }; bool collision = false; - // GameLoop + // GameLoop while (!WindowShouldClose()) { - Func_ShowPos(); + // Checks and calls the Pos show function + if (IsKeyPressed(KEY_P)) ShowPos = !ShowPos; + if (ShowPos==true) Func_ShowPos(); + Func_Controls(); TuxHitbox.x = TuxPos_x+50; @@ -70,12 +77,13 @@ void Func_MainGameLoop() } if (collision) { - DrawText("FINALY BASIC AWFUL COLLISION", 50, 18, 20, BLACK); + DrawText("FINALY BASIC AWFUL COLLISION", 50, 18, 20, MAROON); } else { DrawText("Tux Vs X ENGINE PROTOTYPE please read the LINCENSE", 50, 18, 20, BLACK); } - DrawText("Press 'H' to toggle hitboxes", 50, 72, 20, BLACK); + DrawText("Press 'H' to toggle hitboxes", 50, 72, 20, DARKGREEN); + DrawText("Press 'P' to toggle printing of the positions", 50, 95, 20, DARKGREEN); EndDrawing(); } From d766ed5fcecfd019c5f3ce50a0deffbe8de5a611 Mon Sep 17 00:00:00 2001 From: Mark B Date: Sun, 21 Nov 2021 21:01:53 -0500 Subject: [PATCH 4/4] added a guide to switch branches in the readme --- README.md | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index d6f2c30..2beeef8 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,25 @@ # Tux Vs X ENGINE -A remake of the first game I made. -

This time made with C and raylib.

- -

Sprites made by Jelly_poi.

-

Programming and design by M-C-O-B.

- -Make sure to read the LICENSE file - - -# TO-DO - -* More clean code -* Build Guide -* Hitboxes working in .h files -* Screen Boundaries -* Projectiles -* Portable Binaries of the game +A remake of the first game I made. +

This time made with C and raylib.

+ +

Sprites made by Jelly_poi.

+

Programming and design by M-C-O-B.

+ +Make sure to read the LICENSE file + + +# TO-DO + +* More clean code +* Build Guide +* Hitboxes working in .h files +* Screen Boundaries +* Projectiles +* Portable Binaries of the game + +# BRANCHES + +

To see new code use

+ +git checkout unstable