Compare commits

...

4 Commits

8 changed files with 1588 additions and 24 deletions

View File

@ -4,3 +4,6 @@ A dumb raylib test which you can play [here](https://canneddonuts.itch.io/avoid-
## To-do
- build guide/better Makefile
- fix the dumb bug when the ball gets stuck
## Preview
![Alt Text](./doc-assets/preview.gif)

BIN
assets/gfx/player.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 B

View File

@ -1,2 +1,2 @@
#!/bin/sh
emcc -o html5/index.html src/Main.c -Os -Wall /usr/local/lib/libraylib.a -I. -I/usr/local/include/raylib.h -L. -L/usr/local/lib/libraylib.a -s USE_GLFW=3 -DPLATFORM_WEB --preload-file assets/sfx/boing.wav --preload-file assets/bgm/01-Slipin-Sunday.ogg --shell-file html5/shell.html
emcc -o html5/index.html src/Main.c -Os -Wall /usr/local/lib/libraylib.a -I. -I/usr/local/include/raylib.h -L. -L/usr/local/lib/libraylib.a -s USE_GLFW=3 -DPLATFORM_WEB --preload-file assets/sfx/boing.wav --preload-file assets/gfx/player.png --shell-file html5/shell.html

BIN
doc-assets/preview.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.

16
include/LICENSE Normal file
View File

@ -0,0 +1,16 @@
Copyright (c) 2013-2022 Ramon Santamaria (@raysan5)
This software is provided "as-is", without any express or implied warranty. In no event
will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial
applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you
wrote the original software. If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented
as being the original software.
3. This notice may not be removed or altered from any source distribution.

1536
include/raylib.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,11 @@
#include "../include/raylib.h"
#if defined(PLATFORM_WEB)
#include "/usr/local/include/raylib.h"
#include <emscripten/emscripten.h>
#else
#include "raylib.h"
#endif
// screen variables
static const int screenWidth = 800;
static const int screenHeight = 450;
@ -23,13 +24,16 @@ typedef struct Ball {
} Ball;
typedef struct Player {
Texture2D sprite;
int currentframe;
Vector2 sprite_pos;
Rectangle frameRec;
Rectangle hitbox;
int hp;
} Player;
// Game variables
static GameScreen currentScreen = { 0 };
static Music Bgm01 = { 0 };
static Sound fxbounce = { 0 };
static Player player = { 0 };
static Ball ball = { 0 };
@ -73,20 +77,24 @@ void GameInit(void)
{
currentScreen = TITLE;
Bgm01 = LoadMusicStream("assets/bgm/01-Slipin-Sunday.ogg");
fxbounce = LoadSound("assets/sfx/boing.wav");
PlayMusicStream(Bgm01);
SetMasterVolume(0.2);
player.sprite = LoadTexture("assets/gfx/player.png");
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,
50,
50
70,
70
};
ball.position = (Vector2){ 50, 50 };
@ -105,7 +113,7 @@ void GameInit(void)
void UpdateGame(void)
{
if ((IsKeyDown(KEY_LEFT_SHIFT)) && (IsKeyPressed(KEY_F))) ToggleFullscreen();
if ((IsKeyDown(KEY_LEFT_ALT)) && (IsKeyPressed(KEY_F))) ToggleFullscreen();
switch(currentScreen) {
case TITLE:
@ -119,14 +127,8 @@ void UpdateGame(void)
if ((selected == -2) && (IsKeyPressed(KEY_ENTER))) OpenURL("https://gitdab.com/Canneddonuts/Avoid.git");
break;
case GAMEPLAY:
UpdateMusicStream(Bgm01);
if (IsKeyPressed(KEY_M)) {
mute = !mute;
if (mute) PauseMusicStream(Bgm01);
else ResumeMusicStream(Bgm01);
}
if (IsKeyPressed(KEY_M)) mute = !mute;
if (IsKeyPressed(KEY_ENTER)) pause = !pause;
@ -137,6 +139,9 @@ void UpdateGame(void)
if (IsKeyDown(KEY_UP)) player.hitbox.y -= GetFrameTime() * 300.0f;
if (IsKeyDown(KEY_DOWN)) player.hitbox.y += GetFrameTime() * 300.0f;
player.sprite_pos = (Vector2){ player.hitbox.x, player.hitbox.y };
player.frameRec.x = (float)player.currentframe*(float)player.sprite.width/2;
// Player to da wallz collies
if ((player.hitbox.x + player.hitbox.width) >= GetScreenWidth()) player.hitbox.x = GetScreenWidth() - player.hitbox.width;
else if (player.hitbox.x <= 0) player.hitbox.x = 0;
@ -164,10 +169,13 @@ void UpdateGame(void)
if (!mute) PlaySoundMulti(fxbounce);
}
if (CheckCollisionCircleRec(ball.position, ball.radius, player.hitbox)) player.hp--;
if (CheckCollisionCircleRec(ball.position, ball.radius, player.hitbox)) {
player.hp--;
player.currentframe = 1;
} else player.currentframe = 0;
if (BallFrameCounter <= 2500) ball.radius += GetFrameTime() * ball.growth;
if (ball.radius <= 100) ball.radius += GetFrameTime() * ball.growth;
}
if (player.hp <= 0) currentScreen = GAMEOVER;
@ -201,7 +209,7 @@ void DrawGame(void)
DrawText("Press the arrow keys to move", 10, 40, 10, RED);
DrawText("Press 'ENTER' to pause", 10, 60, 10, RED);
DrawText("Press 'M' to mute", 10, 80, 10, RED);
DrawText("Press 'LSHIFT' + 'F' for full screen", 10, 100, 10, RED);
DrawText("Press 'Left-ALT' + 'F' for full screen", 10, 100, 10, RED);
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);
@ -222,7 +230,8 @@ void DrawGame(void)
DrawText(TextFormat("BALL FRAMES: %i", BallFrameCounter), 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);
// 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;
@ -257,6 +266,6 @@ void UpdateDrawFrame(void)
void UnloadGame(void)
{
UnloadMusicStream(Bgm01);
UnloadSound(fxbounce);
UnloadTexture(player.sprite);
}