diff --git a/asset-src/gfx/player.piskel b/asset-src/gfx/player.piskel new file mode 100644 index 0000000..5fc2a22 --- /dev/null +++ b/asset-src/gfx/player.piskel @@ -0,0 +1 @@ +{"modelVersion":2,"piskel":{"name":"birbis3","description":"","fps":1,"height":70,"width":70,"layers":["{\"name\":\"Layer 1\",\"opacity\":1,\"frameCount\":3,\"chunks\":[{\"layout\":[[0],[1],[2]],\"base64PNG\":\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANIAAABGCAYAAAC5bsoXAAADj0lEQVR4nO2YTW7jMAxGtexter25UA4zq56nwACeRdDCcWRbPxRJie8BAgZtJxLJ70VxUgIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABW2lDb364ZnGenn3wD6mEtSsNJOFESyYvvcZlungdm+X5dEexyIUipSysh0/J1ET0RwkKPsWq4gROoWKfdziZ50oyPEcyESIhWv/M3TJdKf7d92t9oaqpSTff2IhEgtIh3X4ZYqYnqRWmVqxoEYiNQv0plMbz2yxCIvNTJNVxwiDRHp6iOduUiWmSmVadoCEWn4jZTeRdPHQWZyvXhmBpFuEcmAtSQCIqXXv9HFeU5kJDIuFJHkREp5aWxFcpqT108uiIRINyLtf17bE5Fv7Zzm5E0kERyIgUgyH+0ke9ItkuOcIFLl+rul7Kpqj7UkwksmNHdNs5996Rtuay7cFo1Ii4jkYO6tIvXJ5KBgRFpEJAczl8hImOIRqX3JvQPPn6OzfLT1xUFBiGQnkphMDuYtKVJ9XxwUhEi2IuV6UvWNnYNZS0tUnxUHRQ1bAlgHX0ukY2iKRbKe8WCRymVyUBQi+RCp+uOM9XwRCZGsVkopiYhkPVuBbCASInWJdBWiEJnZwTMSInWJdBaiEJk5gEiI1CVSLkQh8nICX38jUrNI4bJyAyIh0liRrGfpKBNrNwiREAmR/DbNOvhuRHKYlcfXx/b4+kCkkiZVNwqRxolUyO/cFtmnm5cwB9p7j3XwZxNJa25e8lEEIiFSLdxGGRBpDZH2vRzZT82ZechGMdFF8nAGCY4ijapHW6Jp5oJI9meQICdSrqaeOrmNLkAk+zNIUSJTa53afZpuJohkfwZJrmTqqVO7R9PNJLJIWg/oFpwJ1VKn1W001UyiiqT1cG6JhEgW/ZlyHl7CbLn3dEMrRFKkUWf0smc3XsJste+UQ6ugp1bL22i6maws0tm3VlEk+qFXpJFn87CnCBFEOn5rFUmiPaU1W/Vo6tlEEUnieWFmSmu26NESs4kq0oj9PFJae+5vNPplta84EUUasZdXSuq/+v2ovtWcSXLfYawsUm6faQYjQO1tVPI6WmeS3ncolu/YmvtGvJWka5Z4nZbzuJ/X1fODxsG1944m04h6pURq+T9u5xVNpNyeo/bxwEq1uq7h7sFS+2aw2HvEHl6IUqcZNQ+fIwZx9boatxMBAxGiiwQgQmlILUQavTfAFf8BsIa/63/h/PcAAAAASUVORK5CYII=\"}]}"],"hiddenFrames":[null]}} \ No newline at end of file diff --git a/assets/gfx/player.png b/assets/gfx/player.png index f1709a8..004e5fe 100644 Binary files a/assets/gfx/player.png and b/assets/gfx/player.png differ diff --git a/src/Main.c b/src/Main.c index 5db40ca..6b152e9 100644 --- a/src/Main.c +++ b/src/Main.c @@ -1,10 +1,11 @@ /* -- Avoid a game by Canneddonuts +- Avoid ~ a game by Canneddonuts - Filename ~ Main.c - Author ~ Return0ne - 2022 - *no license* */ + #include "../include/raylib.h" #if defined(PLATFORM_WEB) @@ -30,11 +31,12 @@ typedef struct Ball { typedef struct Player { Texture2D sprite; + float speed; + int hp; int currentframe; Vector2 sprite_pos; Rectangle frameRec; Rectangle hitbox; - int hp; } Player; // Game variables @@ -47,7 +49,7 @@ static Player player = { 0 }; static Ball ball = { 0 }; static bool pause; static bool mute; -static bool ShowHitbox; +static bool DebugMode; // Game functions static void gameSetup(void); @@ -91,11 +93,12 @@ void gameSetup(void) player.sprite = LoadTexture("assets/gfx/player.png"); player.currentframe = 0; + player.speed = 300.0f; player.hp = 30; player.frameRec = (Rectangle) { 0.0f, 0.0f, - (float) player.sprite.width/2, + (float) player.sprite.width/3, (float) player.sprite.height }; player.hitbox = (Rectangle) { @@ -114,7 +117,7 @@ void gameSetup(void) pause = 0; mute = 0; - ShowHitbox = 0; + DebugMode = 0; pauseTimer = 0; score = 0; } @@ -143,13 +146,19 @@ void updateGame(void) if (!pause) { // Controls - if (IsKeyDown(KEY_LEFT)) player.hitbox.x -= GetFrameTime() * 300.0f; - if (IsKeyDown(KEY_RIGHT)) player.hitbox.x += GetFrameTime() * 300.0f; - if (IsKeyDown(KEY_UP)) player.hitbox.y -= GetFrameTime() * 300.0f; - if (IsKeyDown(KEY_DOWN)) player.hitbox.y += GetFrameTime() * 300.0f; + if (IsKeyDown(KEY_LEFT)) player.hitbox.x -= GetFrameTime() * player.speed; + if (IsKeyDown(KEY_RIGHT)) player.hitbox.x += GetFrameTime() * player.speed; + if (IsKeyDown(KEY_UP)) player.hitbox.y -= GetFrameTime() * player.speed; + if (IsKeyDown(KEY_DOWN)) player.hitbox.y += GetFrameTime() * player.speed; + if (IsKeyDown(KEY_X)) { + // player.speed *= 2; + player.speed = 600.0f; + if (player.currentframe != 1) player.currentframe = 2; + } else player.speed = 300.0f; + player.sprite_pos = (Vector2){ player.hitbox.x, player.hitbox.y }; - player.frameRec.x = (float)player.currentframe*(float)player.sprite.width/2; + player.frameRec.x = (float)player.currentframe*(float)player.sprite.width/3; // Player to da wallz collies if ((player.hitbox.x + player.hitbox.width) >= GetScreenWidth()) player.hitbox.x = GetScreenWidth() - player.hitbox.width; @@ -158,9 +167,9 @@ void updateGame(void) if ((player.hitbox.y + player.hitbox.height) >= GetScreenHeight()) player.hitbox.y = GetScreenHeight() - player.hitbox.height; else if (player.hitbox.y <= 0) player.hitbox.y = 0; - if (IsKeyPressed(KEY_D)) ball.active = !ball.active; + if (IsKeyPressed(KEY_B)) ball.active = !ball.active; - if (IsKeyPressed(KEY_H)) ShowHitbox = !ShowHitbox; + if (IsKeyPressed(KEY_D)) DebugMode = !DebugMode; if (IsKeyPressed(KEY_R)) { gameReset(); @@ -174,7 +183,7 @@ void updateGame(void) if (ball.active) { score++; - // moveiement of the balls + // movement of the ball ball.position.x += GetFrameTime() * ball.speed.x; ball.position.y += GetFrameTime() * ball.speed.y; @@ -232,7 +241,7 @@ void drawGame(void) DrawRectangle(0, 0, screenWidth, screenHeight, ORANGE); DrawText("Controls", 10, 10, 30, PURPLE); DrawText(TextFormat("BEST: %i", bestscore), 600, 0, 30, WHITE); - DrawText("Press the arrow keys to move", 10, 40, 10, RED); + DrawText("Press the arrow keys to move and 'X' to dash", 10, 40, 10, RED); DrawText("Press 'ENTER' to pause", 10, 60, 10, RED); DrawText("Press 'M' to mute", 10, 80, 10, RED); DrawText("Press 'Left-ALT' + 'F' for full screen", 10, 100, 10, RED); @@ -254,9 +263,13 @@ void drawGame(void) DrawFPS(10, 430); DrawText(TextFormat("HP: %i", player.hp), 10, 10, 20, RED); DrawText(TextFormat("SCORE: %i", score), 10, 30, 20, BLUE); - DrawText(TextFormat("BALL SIZE: %f", ball.radius), 10, 50, 20, PINK); + if (DebugMode) { + DrawText(TextFormat("BALL SIZE: %f", ball.radius), 10, 50, 20, GREEN); + DrawText(TextFormat("BALL POS X: %f, BALL POS Y: %f", ball.position.x, ball.position.y), 10, 70, 20, GREEN); + DrawText(TextFormat("BALL SPEED X: %f, BALL SPEED Y: %f", ball.speed.x, ball.speed.y), 10, 90, 20, GREEN); + DrawRectangleRec(player.hitbox, BLUE); + } if (ball.active) DrawCircleV(ball.position, (float)ball.radius, ball.color); - 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; @@ -290,6 +303,7 @@ void gameReset(void) { // code to reset all variables without reloading assets player.currentframe = 0; + player.speed = 300.0f; player.hp = 30; player.hitbox = (Rectangle) { GetScreenWidth()/2.0f - 30, @@ -302,7 +316,7 @@ void gameReset(void) ball.radius = 20; ball.active = true; - ShowHitbox = 0; + DebugMode = 0; pauseTimer = 0; score = 0;