From de4a89e23185304d005f90860330bb861a30b929 Mon Sep 17 00:00:00 2001 From: Mark B Date: Sat, 14 May 2022 15:53:25 -0400 Subject: [PATCH 1/3] cleaned gameReset function and added a hitbox toggle --- include/README.md | 142 ++++++++++++++++++++++++++++++++++++++++++++++ src/Main.c | 33 ++++++----- 2 files changed, 158 insertions(+), 17 deletions(-) create mode 100644 include/README.md diff --git a/include/README.md b/include/README.md new file mode 100644 index 0000000..f719a57 --- /dev/null +++ b/include/README.md @@ -0,0 +1,142 @@ + + +**raylib is a simple and easy-to-use library to enjoy videogames programming.** + +raylib is highly inspired by Borland BGI graphics lib and by XNA framework and it's specially well suited for prototyping, tooling, graphical applications, embedded systems and education. + +*NOTE for ADVENTURERS: raylib is a programming library to enjoy videogames programming; no fancy interface, no visual helpers, no debug button... just coding in the most pure spartan-programmers way.* + +Ready to learn? Jump to [code examples!](https://www.raylib.com/examples.html) + +--- + +
+ +[![GitHub contributors](https://img.shields.io/github/contributors/raysan5/raylib)](https://github.com/raysan5/raylib/graphs/contributors) +[![GitHub All Releases](https://img.shields.io/github/downloads/raysan5/raylib/total)](https://github.com/raysan5/raylib/releases) +[![GitHub commits since tagged version](https://img.shields.io/github/commits-since/raysan5/raylib/4.0.0)](https://github.com/raysan5/raylib/commits/master) +[![License](https://img.shields.io/badge/license-zlib%2Flibpng-blue.svg)](LICENSE) + +[![Chat on Discord](https://img.shields.io/discord/426912293134270465.svg?logo=discord)](https://discord.gg/raylib) +[![GitHub stars](https://img.shields.io/github/stars/raysan5/raylib?style=social)](https://github.com/raysan5/raylib/stargazers) +[![Twitter Follow](https://img.shields.io/twitter/follow/raysan5?style=social)](https://twitter.com/raysan5) +[![Subreddit subscribers](https://img.shields.io/reddit/subreddit-subscribers/raylib?style=social)](https://www.reddit.com/r/raylib/) + +[![Windows](https://github.com/raysan5/raylib/workflows/Windows/badge.svg)](https://github.com/raysan5/raylib/actions?query=workflow%3AWindows) +[![Linux](https://github.com/raysan5/raylib/workflows/Linux/badge.svg)](https://github.com/raysan5/raylib/actions?query=workflow%3ALinux) +[![macOS](https://github.com/raysan5/raylib/workflows/macOS/badge.svg)](https://github.com/raysan5/raylib/actions?query=workflow%3AmacOS) +[![Android](https://github.com/raysan5/raylib/workflows/Android/badge.svg)](https://github.com/raysan5/raylib/actions?query=workflow%3AAndroid) +[![WebAssembly](https://github.com/raysan5/raylib/workflows/WebAssembly/badge.svg)](https://github.com/raysan5/raylib/actions?query=workflow%3AWebAssembly) + +[![CMakeBuilds](https://github.com/raysan5/raylib/workflows/CMakeBuilds/badge.svg)](https://github.com/raysan5/raylib/actions?query=workflow%3ACMakeBuilds) +[![Windows Examples](https://github.com/raysan5/raylib/actions/workflows/windows_examples.yml/badge.svg)](https://github.com/raysan5/raylib/actions/workflows/windows_examples.yml) +[![Linux Examples](https://github.com/raysan5/raylib/actions/workflows/linux_examples.yml/badge.svg)](https://github.com/raysan5/raylib/actions/workflows/linux_examples.yml) + +features +-------- + - **NO external dependencies**, all required libraries are [bundled into raylib](https://github.com/raysan5/raylib/tree/master/src/external) + - Multiple platforms supported: **Windows, Linux, MacOS, RPI, Android, HTML5... and more!** + - Written in plain C code (C99) in PascalCase/camelCase notation + - Hardware accelerated with OpenGL (**1.1, 2.1, 3.3, 4.3 or ES 2.0**) + - **Unique OpenGL abstraction layer** (usable as standalone module): [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.h) + - Multiple **Fonts** formats supported (TTF, XNA fonts, AngelCode fonts) + - Multiple texture formats supported, including **compressed formats** (DXT, ETC, ASTC) + - **Full 3D support**, including 3D Shapes, Models, Billboards, Heightmaps and more! + - Flexible Materials system, supporting classic maps and **PBR maps** + - **Animated 3D models** supported (skeletal bones animation) (IQM) + - Shaders support, including model and **postprocessing** shaders. + - **Powerful math module** for Vector, Matrix and Quaternion operations: [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.h) + - Audio loading and playing with streaming support (WAV, OGG, MP3, FLAC, XM, MOD) + - **VR stereo rendering** support with configurable HMD device parameters + - Huge examples collection with [+120 code examples](https://github.com/raysan5/raylib/tree/master/examples)! + - Bindings to [+50 programming languages](https://github.com/raysan5/raylib/blob/master/BINDINGS.md)! + - **Free and open source**. + +basic example +-------------- +This is a basic raylib example, it creates a window and it draws the text `"Congrats! You created your first window!"` in the middle of the screen. Check this example [running live on web here](https://www.raylib.com/examples/core/loader.html?name=core_basic_window). +```c +#include "raylib.h" + +int main(void) +{ + InitWindow(800, 450, "raylib [core] example - basic window"); + + while (!WindowShouldClose()) + { + BeginDrawing(); + ClearBackground(RAYWHITE); + DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY); + EndDrawing(); + } + + CloseWindow(); + + return 0; +} +``` + +build and installation +---------------------- + +raylib binary releases for Windows, Linux, macOS, Android and HTML5 are available at the [Github Releases page](https://github.com/raysan5/raylib/releases). + +raylib is also available via multiple [package managers](https://github.com/raysan5/raylib/issues/613) on multiple OS distributions. + +#### Installing and building raylib on multiple platforms + +[raylib Wiki](https://github.com/raysan5/raylib/wiki#development-platforms) contains detailed instructions on building and usage on multiple platforms. + + - [Working on Windows](https://github.com/raysan5/raylib/wiki/Working-on-Windows) + - [Working on macOS](https://github.com/raysan5/raylib/wiki/Working-on-macOS) + - [Working on GNU Linux](https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux) + - [Working on Chrome OS](https://github.com/raysan5/raylib/wiki/Working-on-Chrome-OS) + - [Working on FreeBSD](https://github.com/raysan5/raylib/wiki/Working-on-FreeBSD) + - [Working on Raspberry Pi](https://github.com/raysan5/raylib/wiki/Working-on-Raspberry-Pi) + - [Working for Android](https://github.com/raysan5/raylib/wiki/Working-for-Android) + - [Working for Web (HTML5)](https://github.com/raysan5/raylib/wiki/Working-for-Web-(HTML5)) + - [Working anywhere with CMake](https://github.com/raysan5/raylib/wiki/Working-with-CMake) + +*Note that Wiki is open for edit, if you find some issue while building raylib for your target platform, feel free to edit the Wiki or open and issue related to it.* + +#### Setup raylib with multiple IDEs + +raylib has been developed on Windows platform using [Notepad++](https://notepad-plus-plus.org/) and [MinGW GCC](https://www.mingw-w64.org/) compiler but it can be used with other IDEs on multiple platforms. + +[Projects directory](https://github.com/raysan5/raylib/tree/master/projects) contains several ready-to-use **project templates** to build raylib and code examples with multiple IDEs. + +*Note that there are lots of IDEs supported, some of the provided templates could require some review, please, if you find some issue with some template or you think they could be improved, feel free to send a PR or open a related issue.* + +learning and docs +------------------ + +raylib is designed to be learned using [the examples](https://github.com/raysan5/raylib/tree/master/examples) as the main reference. There is no standard API documentation but there is a [**cheatsheet**](https://www.raylib.com/cheatsheet/cheatsheet.html) containing all the functions available on the library and a short description of each one of them, input parameters and result value names should be intuitive enough to understand how each function works. + +Some additional documentation about raylib design can be found in raylib GitHub Wiki. Here the more relevant links: + + - [raylib cheatsheet](https://www.raylib.com/cheatsheet/cheatsheet.html) + - [raylib architecture](https://github.com/raysan5/raylib/wiki/raylib-architecture) + - [raylib library design](https://github.com/raysan5/raylib/wiki) + - [raylib examples collection](https://github.com/raysan5/raylib/tree/master/examples) + - [raylib games collection](https://github.com/raysan5/raylib-games) + + +contact and networks +--------------------- + +raylib is present in several networks and raylib community is growing everyday. If you are using raylib and enjoying it, feel free to join us in any of these networks. The most active network is our [Discord server](https://discord.gg/raylib)! :) + + - Webpage: [https://www.raylib.com](https://www.raylib.com) + - Discord: [https://discord.gg/raylib](https://discord.gg/raylib) + - Twitter: [https://www.twitter.com/raysan5](https://www.twitter.com/raysan5) + - Twitch: [https://www.twitch.tv/raysan5](https://www.twitch.tv/raysan5) + - Reddit: [https://www.reddit.com/r/raylib](https://www.reddit.com/r/raylib) + - Patreon: [https://www.patreon.com/raylib](https://www.patreon.com/raylib) + - YouTube: [https://www.youtube.com/channel/raylib](https://www.youtube.com/c/raylib) + +license +------- + +raylib is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check [LICENSE](LICENSE) for further details. + +raylib uses internally some libraries for window/graphics/inputs management and also to support different fileformats loading, all those libraries are embedded with and are available in [src/external](https://github.com/raysan5/raylib/tree/master/src/external) directory. Check [raylib dependencies LICENSES](https://github.com/raysan5/raylib/wiki/raylib-dependencies) on raylib Wiki for details. diff --git a/src/Main.c b/src/Main.c index 816ffec..1df22e0 100644 --- a/src/Main.c +++ b/src/Main.c @@ -37,6 +37,7 @@ static Player player = { 0 }; static Ball ball = { 0 }; static bool pause; static bool mute; +static bool ShowHitbox; static int pauseTimer; static int score, bestscore; static int selected = 0; @@ -98,14 +99,15 @@ void gameSetup(void) }; ball.position = (Vector2){ 50, 50 }; + ball.speed = (Vector2){ 400.0f, 300.0f }; ball.radius = 20; ball.growth = 2; - ball.speed = (Vector2){ 400.0f, 400.0f }; ball.color = MAROON; ball.active = true; pause = 0; mute = 0; + ShowHitbox = 0; pauseTimer = 0; score = 0; @@ -151,10 +153,19 @@ void updateGame(void) else if (player.hitbox.y <= 0) player.hitbox.y = 0; if (IsKeyPressed(KEY_D)) ball.active = !ball.active; + + if (IsKeyPressed(KEY_H)) ShowHitbox = !ShowHitbox; + if (IsKeyPressed(KEY_R)) { gameReset(); currentScreen = TITLE; } + + if (player.hp <= 0) { + gameReset(); + currentScreen = GAMEOVER; + } + if (ball.active) { score++; // moveiement oof the balls @@ -174,17 +185,12 @@ void updateGame(void) } if (CheckCollisionCircleRec(ball.position, ball.radius, player.hitbox)) { - player.hp--; + player.hp -= GetFrameTime() * 3.0f; player.currentframe = 1; } else player.currentframe = 0; - if (ball.radius <= 100) ball.radius += GetFrameTime() * ball.growth; } - if (player.hp <= 0) { - gameReset(); - currentScreen = GAMEOVER; - } } else pauseTimer++; @@ -239,7 +245,7 @@ void drawGame(void) DrawText(TextFormat("SCORE: %i", score), 10, 30, 20, BLUE); DrawText(TextFormat("BALL SIZE: %f", ball.radius), 10, 50, 20, PINK); if (ball.active) DrawCircleV(ball.position, (float)ball.radius, ball.color); - // DrawRectangleRec(player.hitbox, BLUE); + if (ShowHitbox) DrawRectangleRec(player.hitbox, BLUE); DrawTextureRec(player.sprite, player.frameRec, player.sprite_pos, WHITE); if (pause && ((pauseTimer/30)%2)) DrawText("PAUSED", 330, 190, 30, PURPLE); break; @@ -273,12 +279,6 @@ void gameReset(void) player.currentframe = 0; player.hp = 30; - player.frameRec = (Rectangle) { - 0.0f, - 0.0f, - (float) player.sprite.width/2, - (float) player.sprite.height - }; player.hitbox = (Rectangle) { GetScreenWidth()/2.0f - 30, GetScreenHeight()/2.0f - 30, @@ -288,11 +288,10 @@ void gameReset(void) ball.position = (Vector2){ 50, 50 }; ball.radius = 20; - ball.growth = 2; - ball.speed = (Vector2){ 400.0f, 400.0f }; - ball.color = MAROON; ball.active = true; + ShowHitbox = 0; + pauseTimer = 0; score = 0; } From 26c96e3274c618ad0c626cc8120296ac8bf45fa3 Mon Sep 17 00:00:00 2001 From: Mark B Date: Sun, 15 May 2022 13:04:19 -0400 Subject: [PATCH 2/3] changed SOURCE CODE to MORE GAMES & fixed the dumb html5 scrolling bug --- html5/shell.html | 321 ++++++----------------------------------------- src/Main.c | 8 +- 2 files changed, 45 insertions(+), 284 deletions(-) diff --git a/html5/shell.html b/html5/shell.html index fe022b1..3cdaa33 100644 --- a/html5/shell.html +++ b/html5/shell.html @@ -4,190 +4,36 @@ - Avoid: the game + raylib web game - - + + - + - + - + - + - - - - -
- -
- - - - - - - - {{{ SCRIPT }}} - + }; + + {{{ SCRIPT }}} + diff --git a/src/Main.c b/src/Main.c index 1df22e0..d53971e 100644 --- a/src/Main.c +++ b/src/Main.c @@ -127,7 +127,7 @@ void updateGame(void) if ((selected == 0) && (IsKeyPressed(KEY_ENTER))) currentScreen = GAMEPLAY; if ((selected == -1) && (IsKeyPressed(KEY_ENTER))) currentScreen = CREDITS; - if ((selected == -2) && (IsKeyPressed(KEY_ENTER))) OpenURL("https://gitdab.com/Canneddonuts/Avoid.git"); + if ((selected == -2) && (IsKeyPressed(KEY_ENTER))) OpenURL("https://canneddonuts.itch.io/"); break; case GAMEPLAY: @@ -234,8 +234,8 @@ void drawGame(void) if (selected == -1) DrawText("CREDITS", 340, 240, 20, WHITE); else DrawText("CREDITS", 340, 240, 20, BLUE); - if (selected == -2) DrawText("SOURCE CODE", 315, 260, 20, WHITE); - else DrawText("SOURCE CODE", 315, 260, 20, BLUE); + if (selected == -2) DrawText("MORE GAMES", 320, 260, 20, WHITE); + else DrawText("MORE GAMES", 320, 260, 20, BLUE); break; case GAMEPLAY: @@ -258,7 +258,7 @@ void drawGame(void) case CREDITS: DrawRectangle(0, 0, screenWidth, screenHeight, GREEN); - DrawText("Avoid", 330, 20, 50, PINK); + DrawText("Avoid", 330, 20, 50, MAGENTA); DrawText("Programming by Return0ne", 10, 210, 20, BLUE); DrawText("Morale support by Tobi/Tobrella and Jelly_man", 10, 240, 20, BLUE); DrawText("Powered by raylib 4.0", 10, 270, 20, BLUE); From 794d00a4d798c24e412bd976d42cc073ad784d9d Mon Sep 17 00:00:00 2001 From: Mark B Date: Tue, 17 May 2022 19:03:22 -0400 Subject: [PATCH 3/3] added TITLE option on the gameover screen --- html5/shell.html | 10 ++++----- src/Main.c | 56 +++++++++++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/html5/shell.html b/html5/shell.html index 3cdaa33..ce48746 100644 --- a/html5/shell.html +++ b/html5/shell.html @@ -4,15 +4,15 @@ - raylib web game + Avoid - + - + @@ -22,10 +22,10 @@ - + - + diff --git a/src/Main.c b/src/Main.c index d53971e..60b048b 100644 --- a/src/Main.c +++ b/src/Main.c @@ -31,6 +31,9 @@ typedef struct Player { } Player; // Game variables +static int pauseTimer; +static int score, bestscore; +static int titleSelected = 0, gameoverSelected = 0; static GameScreen currentScreen = { 0 }; static Sound fxbounce = { 0 }; static Player player = { 0 }; @@ -38,9 +41,6 @@ static Ball ball = { 0 }; static bool pause; static bool mute; static bool ShowHitbox; -static int pauseTimer; -static int score, bestscore; -static int selected = 0; // Game functions static void gameSetup(void); @@ -58,12 +58,13 @@ int main(void) gameSetup(); + #if defined(PLATFORM_WEB) emscripten_set_main_loop(gameLoop, 0, 1); #else - SetTargetFPS(60); + SetTargetFPS(60); - while (!WindowShouldClose()) gameLoop(); + while (!WindowShouldClose()) gameLoop(); #endif unloadGame(); @@ -99,7 +100,7 @@ void gameSetup(void) }; ball.position = (Vector2){ 50, 50 }; - ball.speed = (Vector2){ 400.0f, 300.0f }; + ball.speed = (Vector2){ 6.0f, 5.0f }; ball.radius = 20; ball.growth = 2; ball.color = MAROON; @@ -108,7 +109,6 @@ void gameSetup(void) pause = 0; mute = 0; ShowHitbox = 0; - pauseTimer = 0; score = 0; } @@ -120,14 +120,14 @@ void updateGame(void) switch(currentScreen) { case TITLE: - if (IsKeyPressed(KEY_UP)) selected++; - if (IsKeyPressed(KEY_DOWN)) selected--; - if (selected > 0) selected--; - if (selected < -2) selected++; + if (IsKeyPressed(KEY_UP)) titleSelected++; + if (IsKeyPressed(KEY_DOWN)) titleSelected--; + if (titleSelected > 0) titleSelected--; + if (titleSelected < -2) titleSelected++; - if ((selected == 0) && (IsKeyPressed(KEY_ENTER))) currentScreen = GAMEPLAY; - if ((selected == -1) && (IsKeyPressed(KEY_ENTER))) currentScreen = CREDITS; - if ((selected == -2) && (IsKeyPressed(KEY_ENTER))) OpenURL("https://canneddonuts.itch.io/"); + if ((titleSelected == 0) && (IsKeyPressed(KEY_ENTER))) currentScreen = GAMEPLAY; + if ((titleSelected == -1) && (IsKeyPressed(KEY_ENTER))) currentScreen = CREDITS; + if ((titleSelected == -2) && (IsKeyPressed(KEY_ENTER))) OpenURL("https://canneddonuts.itch.io/"); break; case GAMEPLAY: @@ -169,8 +169,8 @@ void updateGame(void) if (ball.active) { score++; // moveiement oof the balls - ball.position.x += GetFrameTime() * ball.speed.x; - ball.position.y += GetFrameTime() * ball.speed.y; + ball.position.x += ball.speed.x; + ball.position.y += ball.speed.y; if (score >= bestscore) bestscore = score; // Ballz to da wallz collies @@ -197,11 +197,17 @@ void updateGame(void) break; case GAMEOVER: - if (score > bestscore) bestscore = score; - if (IsKeyPressed(KEY_ENTER)) { + if (IsKeyPressed(KEY_UP)) gameoverSelected++; + if (IsKeyPressed(KEY_DOWN)) gameoverSelected--; + if (gameoverSelected > 0) gameoverSelected--; + if (gameoverSelected < -1) gameoverSelected++; + + if ((gameoverSelected == 0) && (IsKeyPressed(KEY_ENTER))) { gameReset(); currentScreen = GAMEPLAY; } + + if ((gameoverSelected == -1) && (IsKeyPressed(KEY_ENTER))) gameReset(); break; case CREDITS: if (IsKeyPressed(KEY_ENTER)) currentScreen = TITLE; @@ -228,13 +234,13 @@ void drawGame(void) DrawText("Press 'R' to restart", 10, 120, 10, RED); DrawText("Press 'ENTER' to select an option", 10, 140, 10, RED); DrawText("Avoid", 330, 20, 50, BLUE); - if (selected == 0) DrawText("PLAY", 360, 220, 20, WHITE); + if (titleSelected == 0) DrawText("PLAY", 360, 220, 20, WHITE); else DrawText("PLAY", 360, 220, 20, BLUE); - if (selected == -1) DrawText("CREDITS", 340, 240, 20, WHITE); + if (titleSelected == -1) DrawText("CREDITS", 340, 240, 20, WHITE); else DrawText("CREDITS", 340, 240, 20, BLUE); - if (selected == -2) DrawText("MORE GAMES", 320, 260, 20, WHITE); + if (titleSelected == -2) DrawText("MORE GAMES", 320, 260, 20, WHITE); else DrawText("MORE GAMES", 320, 260, 20, BLUE); break; @@ -253,7 +259,11 @@ void drawGame(void) case GAMEOVER: DrawRectangle(0, 0, screenWidth, screenHeight, BLUE); DrawText("GAMEOVER", 250, 20, 50, RED); - DrawText("PRESS ENTER TO RESET", 270, 220, 20, WHITE); + if (gameoverSelected == 0) DrawText("RETRY", 350, 200, 20, WHITE); + else DrawText("RETRY", 350, 200, 20, RED); + + if (gameoverSelected == -1) DrawText("TITLE", 350, 230, 20, WHITE); + else DrawText("TITLE", 350, 230, 20, RED); break; case CREDITS: @@ -294,6 +304,8 @@ void gameReset(void) pauseTimer = 0; score = 0; + + gameoverSelected = 0; } void gameLoop(void)