use game template

This commit is contained in:
Jeffery Myers committed 2022-04-23 08:48:40 -07:00
1 parent 7026528c19
commit aa720c9af7
21 files changed
+1109 -8

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
raylib-master
_build
_bin
.vs
+8 -5
View File
@@ -9,7 +9,7 @@ https://youtu.be/oHIh01L6xQQ
Download the game premake repository from
https://github.com/raylib-extras/game-premake/tree/no_edit
Download the zip file, or clone the repository. It doens't matter what one you use.
Rename the folder whatever you want. This will be where your entire game proejct will be located.
Rename the folder whatever you want. This will be the name of your game.
#(OPTIONAL) Get Raylib
If you wish to use a specific version of raylib, follow the instructions below. If you want the current developmetn version, skip this section and premake will download raylib for you.
@@ -20,11 +20,14 @@ https://github.com/raysan5/raylib
Download the zip file, or clone the repository. It doens't matter what one you use.
Put the raylib sources in a folder called raylib inside your game folder (The same folder this file is in). The folder must be named raylib, it can not be raylib-master. The raylib folder should contain all the sources from raylib (including the 'src' folder)
# Rename the _app folder
Rename the _app folder to whatever you want your game's executable name to be.
# Example app
This repository is pre-populated wit the raylib game template. It is a great starting point for your game.
https://github.com/raysan5/raylib-game-template
If you want to have a different starting point, simply repalce the files in the game folder with your own files.
## Using C++
By default this process is setup to build a project using C. If you want to use C++, simply rename the main.c file that is inside the _app folder to main.cpp. The scripts will take care of the rest.
By default this process is setup to build a project using C. If you want to use C++, you can replace these files with cpp files.
# Generate Projects
For windows users, there are two batch files you can use depending on what compiler you are using. For linux users you can simply use a terminal.
@@ -68,5 +71,5 @@ Open your terminal, change to the game folder and type.
make
This will build your game
This will build your starting game template
View File
File renamed without changes.
+1 -1
View File
@@ -1,7 +1,7 @@
baseName = path.getbasename(os.getcwd());
project (workspaceName)
project (baseName)
kind "ConsoleApp"
location "../_build"
targetdir "../_bin/%{cfg.buildcfg}"
+39
View File
@@ -0,0 +1,39 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "game-premake", "_build\game-premake.vcxproj", "{5197A086-3DFA-2F2B-E67F-68E1D2C1FBAD}"
ProjectSection(ProjectDependencies) = postProject
{8898EA18-743A-15EF-5DF5-284349369C3F} = {8898EA18-743A-15EF-5DF5-284349369C3F}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "raylib", "_build\raylib.vcxproj", "{8898EA18-743A-15EF-5DF5-284349369C3F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5197A086-3DFA-2F2B-E67F-68E1D2C1FBAD}.Debug|Win32.ActiveCfg = Debug|Win32
{5197A086-3DFA-2F2B-E67F-68E1D2C1FBAD}.Debug|Win32.Build.0 = Debug|Win32
{5197A086-3DFA-2F2B-E67F-68E1D2C1FBAD}.Debug|x64.ActiveCfg = Debug|x64
{5197A086-3DFA-2F2B-E67F-68E1D2C1FBAD}.Debug|x64.Build.0 = Debug|x64
{5197A086-3DFA-2F2B-E67F-68E1D2C1FBAD}.Release|Win32.ActiveCfg = Release|Win32
{5197A086-3DFA-2F2B-E67F-68E1D2C1FBAD}.Release|Win32.Build.0 = Release|Win32
{5197A086-3DFA-2F2B-E67F-68E1D2C1FBAD}.Release|x64.ActiveCfg = Release|x64
{5197A086-3DFA-2F2B-E67F-68E1D2C1FBAD}.Release|x64.Build.0 = Release|x64
{8898EA18-743A-15EF-5DF5-284349369C3F}.Debug|Win32.ActiveCfg = Debug|Win32
{8898EA18-743A-15EF-5DF5-284349369C3F}.Debug|Win32.Build.0 = Debug|Win32
{8898EA18-743A-15EF-5DF5-284349369C3F}.Debug|x64.ActiveCfg = Debug|x64
{8898EA18-743A-15EF-5DF5-284349369C3F}.Debug|x64.Build.0 = Debug|x64
{8898EA18-743A-15EF-5DF5-284349369C3F}.Release|Win32.ActiveCfg = Release|Win32
{8898EA18-743A-15EF-5DF5-284349369C3F}.Release|Win32.Build.0 = Release|Win32
{8898EA18-743A-15EF-5DF5-284349369C3F}.Release|x64.ActiveCfg = Release|x64
{8898EA18-743A-15EF-5DF5-284349369C3F}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
+89
View File
@@ -0,0 +1,89 @@
## C Coding Style Conventions
Code element | Convention | Example
--- | :---: | ---
Defines | ALL_CAPS | `#define PLATFORM_DESKTOP`
Macros | ALL_CAPS | `#define MIN(a,b) (((a)<(b))?(a):(b))`
Variables | lowerCase | `int screenWidth = 0;`, `float targetFrameTime = 0.016f;`
Local variables | lowerCase | `Vector2 playerPosition = { 0 };`
Global variables | lowerCase | `bool fullscreen = false;`
Constants | lowerCase | `const int maxValue = 8;`
Pointers | MyType *pointer | `Texture2D *array = NULL;`
float values | always x.xf | `float gravity = 10.0f`
Operators | value1*value2 | `int product = value*6;`
Operators | value1/value2 | `int division = value/4;`
Operators | value1 + value2 | `int sum = value + 10;`
Operators | value1 - value2 | `int res = value - 5;`
Enum | TitleCase | `enum TextureFormat`
Enum members | ALL_CAPS | `PIXELFORMAT_UNCOMPRESSED_R8G8B8`
Struct | TitleCase | `struct Texture2D`, `struct Material`
Struct typedef | TitleCase | `typedef struct Texture { ... } Texture;`
Struct members | lowerCase | `texture.width`, `color.r`
Functions | TitleCase | `InitWindow()`, `LoadImageFromMemory()`
Functions params | lowerCase | `width`, `height`
Ternary Operator | (condition)? result1 : result2 | `printf("Value is 0: %s", (value == 0)? "yes" : "no");`
Other conventions:
- All defined variables are ALWAYS initialized
- Four spaces are used, instead of TABS
- Trailing spaces are always avoided
- Control flow statements are followed **by a space**:
```c
if (condition) value = 0;
while (!WindowShouldClose())
{
}
for (int i = 0; i < NUM_VALUES; i++) printf("%i", i);
switch (value)
{
case 0:
{
} break;
case 2: break;
default: break;
}
```
- All conditions are always between parenthesis, but not boolean values:
```c
if ((value > 1) && (value < 50) && valueActive)
{
}
```
- Braces and curly brackets always open-close in aligned mode:
```c
void SomeFunction()
{
// TODO: Do something here!
}
```
## Files and Directories Naming Conventions
- Directories are named using `snake_case`: `resources/models`, `resources/fonts`
- Files are named using `snake_case`: `main_title.png`, `cubicmap.png`, `sound.wav`
_NOTE: Spaces and special characters are always avoided in the files/dir naming!_
## Games/Examples Directories Organization Conventions
- Resource files are organized by context and usage in the game. Loading requirements for data are also considered (grouping data when required).
- Descriptive names are used for the files, just reading the name of the file it should be possible to know what is that file and where fits in the game.
```
resources/audio/fx/long_jump.wav
resources/audio/music/main_theme.ogg
resources/screens/logo/logo.png
resources/screens/title/title.png
resources/screens/gameplay/background.png
resources/characters/player.png
resources/characters/enemy_slime.png
resources/common/font_arial.ttf
resources/common/gui.png
```
_NOTE: Some resources require to be loaded all at once while other require to be loaded only at initialization (gui, font)._
+16
View File
@@ -0,0 +1,16 @@
Copyright (c) 2021-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.
+60
View File
@@ -0,0 +1,60 @@
-----------------------------------
_DISCLAIMER:_
Welcome to **raylib game template**!
This template provides a base structure to start developing a small raylib game in plain C. The repo is also pre-configured with a default `LICENSE` (zlib/libpng) and a `README.md` (this one) to be properly filled by users. Feel free to change the LICENSE as required.
All the sections defined by `$(Data to Fill)` are expected to be edited and filled properly. It's recommended to delete this disclaimer message after editing this `README.md` file.
This template has been created to be used with raylib (www.raylib.com) and it's licensed under an unmodified zlib/libpng license.
_Copyright (c) 2014-2022 Ramon Santamaria ([@raysan5](https://twitter.com/raysan5))_
-----------------------------------
## $(Game Title)
![$(Game Title)](screenshots/screenshot000.png "$(Game Title)")
### Description
$(Your Game Description)
### Features
- $(Game Feature 01)
- $(Game Feature 02)
- $(Game Feature 03)
### Controls
Keyboard:
- $(Game Control 01)
- $(Game Control 02)
- $(Game Control 03)
### Screenshots
_TODO: Show your game to the world, animated GIFs recommended!._
### Developers
- $(Developer 01) - $(Role/Tasks Developed)
- $(Developer 02) - $(Role/Tasks Developed)
- $(Developer 03) - $(Role/Tasks Developed)
### Links
- YouTube Gameplay: $(YouTube Link)
- itch.io Release: $(itch.io Game Page)
- Steam Release: $(Steam Game Page)
### License
This game sources are 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.
$(Additional Licenses)
*Copyright (c) $(Year) $(User Name) ($(User Twitter/GitHub Name))*
+21
View File
@@ -0,0 +1,21 @@
baseName = path.getbasename(os.getcwd());
project (workspaceName)
kind "ConsoleApp"
location "../_build"
targetdir "../_bin/%{cfg.buildcfg}"
filter "action:vs*"
debugdir "$(SolutionDir)"
filter {}
vpaths
{
["Header Files/*"] = { "**.h"},
["Source Files/*"] = {"**.c", "**.cpp"},
}
files {"**.c", "**.cpp", "**.h"}
includedirs { "./", "src"}
link_raylib();
+293
View File
@@ -0,0 +1,293 @@
/*******************************************************************************************
*
* raylib game template
*
* <Game title>
* <Game description>
*
* This game has been created using raylib (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2021 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
#include "screens.h" // NOTE: Declares global (extern) variables and screens functions
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#endif
//----------------------------------------------------------------------------------
// Shared Variables Definition (global)
// NOTE: Those variables are shared between modules through screens.h
//----------------------------------------------------------------------------------
GameScreen currentScreen = 0;
Font font = { 0 };
Music music = { 0 };
Sound fxCoin = { 0 };
//----------------------------------------------------------------------------------
// Local Variables Definition (local to this module)
//----------------------------------------------------------------------------------
static const int screenWidth = 800;
static const int screenHeight = 450;
// Required variables to manage screen transitions (fade-in, fade-out)
static float transAlpha = 0.0f;
static bool onTransition = false;
static bool transFadeOut = false;
static int transFromScreen = -1;
static int transToScreen = -1;
//----------------------------------------------------------------------------------
// Local Functions Declaration
//----------------------------------------------------------------------------------
static void ChangeToScreen(int screen); // Change to screen, no transition effect
static void TransitionToScreen(int screen); // Request transition to next screen
static void UpdateTransition(void); // Update transition effect
static void DrawTransition(void); // Draw transition effect (full-screen rectangle)
static void UpdateDrawFrame(void); // Update and draw one frame
//----------------------------------------------------------------------------------
// Main entry point
//----------------------------------------------------------------------------------
int main(void)
{
// Initialization
//---------------------------------------------------------
InitWindow(screenWidth, screenHeight, "raylib game template");
InitAudioDevice(); // Initialize audio device
// Load global data (assets that must be available in all screens, i.e. font)
font = LoadFont("resources/mecha.png");
music = LoadMusicStream("resources/ambient.ogg");
fxCoin = LoadSound("resources/coin.wav");
SetMusicVolume(music, 1.0f);
PlayMusicStream(music);
// Setup and init first screen
currentScreen = LOGO;
InitLogoScreen();
#if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 60, 1);
#else
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
UpdateDrawFrame();
}
#endif
// De-Initialization
//--------------------------------------------------------------------------------------
// Unload current screen data before closing
switch (currentScreen)
{
case LOGO: UnloadLogoScreen(); break;
case TITLE: UnloadTitleScreen(); break;
case GAMEPLAY: UnloadGameplayScreen(); break;
case ENDING: UnloadEndingScreen(); break;
default: break;
}
// Unload global data loaded
UnloadFont(font);
UnloadMusicStream(music);
UnloadSound(fxCoin);
CloseAudioDevice(); // Close audio context
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}
//----------------------------------------------------------------------------------
// Module specific Functions Definition
//----------------------------------------------------------------------------------
// Change to next screen, no transition
static void ChangeToScreen(int screen)
{
// Unload current screen
switch (currentScreen)
{
case LOGO: UnloadLogoScreen(); break;
case TITLE: UnloadTitleScreen(); break;
case GAMEPLAY: UnloadGameplayScreen(); break;
case ENDING: UnloadEndingScreen(); break;
default: break;
}
// Init next screen
switch (screen)
{
case LOGO: InitLogoScreen(); break;
case TITLE: InitTitleScreen(); break;
case GAMEPLAY: InitGameplayScreen(); break;
case ENDING: InitEndingScreen(); break;
default: break;
}
currentScreen = screen;
}
// Request transition to next screen
static void TransitionToScreen(int screen)
{
onTransition = true;
transFadeOut = false;
transFromScreen = currentScreen;
transToScreen = screen;
transAlpha = 0.0f;
}
// Update transition effect (fade-in, fade-out)
static void UpdateTransition(void)
{
if (!transFadeOut)
{
transAlpha += 0.05f;
// NOTE: Due to float internal representation, condition jumps on 1.0f instead of 1.05f
// For that reason we compare against 1.01f, to avoid last frame loading stop
if (transAlpha > 1.01f)
{
transAlpha = 1.0f;
// Unload current screen
switch (transFromScreen)
{
case LOGO: UnloadLogoScreen(); break;
case TITLE: UnloadTitleScreen(); break;
case OPTIONS: UnloadOptionsScreen(); break;
case GAMEPLAY: UnloadGameplayScreen(); break;
case ENDING: UnloadEndingScreen(); break;
default: break;
}
// Load next screen
switch (transToScreen)
{
case LOGO: InitLogoScreen(); break;
case TITLE: InitTitleScreen(); break;
case GAMEPLAY: InitGameplayScreen(); break;
case ENDING: InitEndingScreen(); break;
default: break;
}
currentScreen = transToScreen;
// Activate fade out effect to next loaded screen
transFadeOut = true;
}
}
else // Transition fade out logic
{
transAlpha -= 0.02f;
if (transAlpha < -0.01f)
{
transAlpha = 0.0f;
transFadeOut = false;
onTransition = false;
transFromScreen = -1;
transToScreen = -1;
}
}
}
// Draw transition effect (full-screen rectangle)
static void DrawTransition(void)
{
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(BLACK, transAlpha));
}
// Update and draw game frame
static void UpdateDrawFrame(void)
{
// Update
//----------------------------------------------------------------------------------
UpdateMusicStream(music); // NOTE: Music keeps playing between screens
if (!onTransition)
{
switch(currentScreen)
{
case LOGO:
{
UpdateLogoScreen();
if (FinishLogoScreen()) TransitionToScreen(TITLE);
} break;
case TITLE:
{
UpdateTitleScreen();
if (FinishTitleScreen() == 1) TransitionToScreen(OPTIONS);
else if (FinishTitleScreen() == 2) TransitionToScreen(GAMEPLAY);
} break;
case OPTIONS:
{
UpdateOptionsScreen();
if (FinishOptionsScreen()) TransitionToScreen(TITLE);
} break;
case GAMEPLAY:
{
UpdateGameplayScreen();
if (FinishGameplayScreen() == 1) TransitionToScreen(ENDING);
//else if (FinishGameplayScreen() == 2) TransitionToScreen(TITLE);
} break;
case ENDING:
{
UpdateEndingScreen();
if (FinishEndingScreen() == 1) TransitionToScreen(TITLE);
} break;
default: break;
}
}
else UpdateTransition(); // Update transition (fade-in, fade-out)
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
switch(currentScreen)
{
case LOGO: DrawLogoScreen(); break;
case TITLE: DrawTitleScreen(); break;
case OPTIONS: DrawOptionsScreen(); break;
case GAMEPLAY: DrawGameplayScreen(); break;
case ENDING: DrawEndingScreen(); break;
default: break;
}
// Draw full screen rectangle in front of everything
if (onTransition) DrawTransition();
//DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
}
+79
View File
@@ -0,0 +1,79 @@
/**********************************************************************************************
*
* raylib - Advance Game template
*
* Ending Screen Functions Definitions (Init, Update, Draw, Unload)
*
* Copyright (c) 2014-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.
*
**********************************************************************************************/
#include "raylib.h"
#include "screens.h"
//----------------------------------------------------------------------------------
// Module Variables Definition (local)
//----------------------------------------------------------------------------------
static int framesCounter = 0;
static int finishScreen = 0;
//----------------------------------------------------------------------------------
// Ending Screen Functions Definition
//----------------------------------------------------------------------------------
// Ending Screen Initialization logic
void InitEndingScreen(void)
{
// TODO: Initialize ENDING screen variables here!
framesCounter = 0;
finishScreen = 0;
}
// Ending Screen Update logic
void UpdateEndingScreen(void)
{
// TODO: Update ENDING screen variables here!
// Press enter or tap to return to TITLE screen
if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
{
finishScreen = 1;
PlaySound(fxCoin);
}
}
// Ending Screen Draw logic
void DrawEndingScreen(void)
{
// TODO: Draw ENDING screen here!
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), BLUE);
DrawTextEx(font, "ENDING SCREEN", (Vector2){ 20, 10 }, font.baseSize*3, 4, DARKBLUE);
DrawText("PRESS ENTER or TAP to RETURN to TITLE SCREEN", 120, 220, 20, DARKBLUE);
}
// Ending Screen Unload logic
void UnloadEndingScreen(void)
{
// TODO: Unload ENDING screen variables here!
}
// Ending Screen should finish?
int FinishEndingScreen(void)
{
return finishScreen;
}
+79
View File
@@ -0,0 +1,79 @@
/**********************************************************************************************
*
* raylib - Advance Game template
*
* Gameplay Screen Functions Definitions (Init, Update, Draw, Unload)
*
* Copyright (c) 2014-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.
*
**********************************************************************************************/
#include "raylib.h"
#include "screens.h"
//----------------------------------------------------------------------------------
// Module Variables Definition (local)
//----------------------------------------------------------------------------------
static int framesCounter = 0;
static int finishScreen = 0;
//----------------------------------------------------------------------------------
// Gameplay Screen Functions Definition
//----------------------------------------------------------------------------------
// Gameplay Screen Initialization logic
void InitGameplayScreen(void)
{
// TODO: Initialize GAMEPLAY screen variables here!
framesCounter = 0;
finishScreen = 0;
}
// Gameplay Screen Update logic
void UpdateGameplayScreen(void)
{
// TODO: Update GAMEPLAY screen variables here!
// Press enter or tap to change to ENDING screen
if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
{
finishScreen = 1;
PlaySound(fxCoin);
}
}
// Gameplay Screen Draw logic
void DrawGameplayScreen(void)
{
// TODO: Draw GAMEPLAY screen here!
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), PURPLE);
DrawTextEx(font, "GAMEPLAY SCREEN", (Vector2){ 20, 10 }, font.baseSize*3, 4, MAROON);
DrawText("PRESS ENTER or TAP to JUMP to ENDING SCREEN", 130, 220, 20, MAROON);
}
// Gameplay Screen Unload logic
void UnloadGameplayScreen(void)
{
// TODO: Unload GAMEPLAY screen variables here!
}
// Gameplay Screen should finish?
int FinishGameplayScreen(void)
{
return finishScreen;
}
+173
View File
@@ -0,0 +1,173 @@
/**********************************************************************************************
*
* raylib - Advance Game template
*
* Logo Screen Functions Definitions (Init, Update, Draw, Unload)
*
* Copyright (c) 2014-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.
*
**********************************************************************************************/
#include "raylib.h"
#include "screens.h"
//----------------------------------------------------------------------------------
// Module Variables Definition (local)
//----------------------------------------------------------------------------------
static int framesCounter = 0;
static int finishScreen = 0;
static int logoPositionX = 0;
static int logoPositionY = 0;
static int lettersCount = 0;
static int topSideRecWidth = 0;
static int leftSideRecHeight = 0;
static int bottomSideRecWidth = 0;
static int rightSideRecHeight = 0;
static int state = 0; // Logo animation states
static float alpha = 1.0f; // Useful for fading
//----------------------------------------------------------------------------------
// Logo Screen Functions Definition
//----------------------------------------------------------------------------------
// Logo Screen Initialization logic
void InitLogoScreen(void)
{
finishScreen = 0;
framesCounter = 0;
lettersCount = 0;
logoPositionX = GetScreenWidth()/2 - 128;
logoPositionY = GetScreenHeight()/2 - 128;
topSideRecWidth = 16;
leftSideRecHeight = 16;
bottomSideRecWidth = 16;
rightSideRecHeight = 16;
state = 0;
alpha = 1.0f;
}
// Logo Screen Update logic
void UpdateLogoScreen(void)
{
if (state == 0) // State 0: Top-left square corner blink logic
{
framesCounter++;
if (framesCounter == 80)
{
state = 1;
framesCounter = 0; // Reset counter... will be used later...
}
}
else if (state == 1) // State 1: Bars animation logic: top and left
{
topSideRecWidth += 8;
leftSideRecHeight += 8;
if (topSideRecWidth == 256) state = 2;
}
else if (state == 2) // State 2: Bars animation logic: bottom and right
{
bottomSideRecWidth += 8;
rightSideRecHeight += 8;
if (bottomSideRecWidth == 256) state = 3;
}
else if (state == 3) // State 3: "raylib" text-write animation logic
{
framesCounter++;
if (lettersCount < 10)
{
if (framesCounter/12) // Every 12 frames, one more letter!
{
lettersCount++;
framesCounter = 0;
}
}
else // When all letters have appeared, just fade out everything
{
if (framesCounter > 200)
{
alpha -= 0.02f;
if (alpha <= 0.0f)
{
alpha = 0.0f;
finishScreen = 1; // Jump to next screen
}
}
}
}
}
// Logo Screen Draw logic
void DrawLogoScreen(void)
{
if (state == 0) // Draw blinking top-left square corner
{
if ((framesCounter/10)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK);
}
else if (state == 1) // Draw bars animation: top and left
{
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
}
else if (state == 2) // Draw bars animation: bottom and right
{
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK);
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK);
}
else if (state == 3) // Draw "raylib" text-write animation + "powered by"
{
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
DrawText(TextSubtext("raylib", 0, lettersCount), GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48, 50, Fade(BLACK, alpha));
if (framesCounter > 20) DrawText("powered by", logoPositionX, logoPositionY - 27, 20, Fade(DARKGRAY, alpha));
}
}
// Logo Screen Unload logic
void UnloadLogoScreen(void)
{
// Unload LOGO screen variables here!
}
// Logo Screen should finish?
int FinishLogoScreen(void)
{
return finishScreen;
}
+69
View File
@@ -0,0 +1,69 @@
/**********************************************************************************************
*
* raylib - Advance Game template
*
* Options Screen Functions Definitions (Init, Update, Draw, Unload)
*
* Copyright (c) 2014-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.
*
**********************************************************************************************/
#include "raylib.h"
#include "screens.h"
//----------------------------------------------------------------------------------
// Module Variables Definition (local)
//----------------------------------------------------------------------------------
static int framesCounter = 0;
static int finishScreen = 0;
//----------------------------------------------------------------------------------
// Options Screen Functions Definition
//----------------------------------------------------------------------------------
// Options Screen Initialization logic
void InitOptionsScreen(void)
{
// TODO: Initialize OPTIONS screen variables here!
framesCounter = 0;
finishScreen = 0;
}
// Options Screen Update logic
void UpdateOptionsScreen(void)
{
// TODO: Update OPTIONS screen variables here!
}
// Options Screen Draw logic
void DrawOptionsScreen(void)
{
// TODO: Draw OPTIONS screen here!
}
// Options Screen Unload logic
void UnloadOptionsScreen(void)
{
// TODO: Unload OPTIONS screen variables here!
}
// Options Screen should finish?
int FinishOptionsScreen(void)
{
return finishScreen;
}
+80
View File
@@ -0,0 +1,80 @@
/**********************************************************************************************
*
* raylib - Advance Game template
*
* Title Screen Functions Definitions (Init, Update, Draw, Unload)
*
* Copyright (c) 2014-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.
*
**********************************************************************************************/
#include "raylib.h"
#include "screens.h"
//----------------------------------------------------------------------------------
// Module Variables Definition (local)
//----------------------------------------------------------------------------------
static int framesCounter = 0;
static int finishScreen = 0;
//----------------------------------------------------------------------------------
// Title Screen Functions Definition
//----------------------------------------------------------------------------------
// Title Screen Initialization logic
void InitTitleScreen(void)
{
// TODO: Initialize TITLE screen variables here!
framesCounter = 0;
finishScreen = 0;
}
// Title Screen Update logic
void UpdateTitleScreen(void)
{
// TODO: Update TITLE screen variables here!
// Press enter or tap to change to GAMEPLAY screen
if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
{
//finishScreen = 1; // OPTIONS
finishScreen = 2; // GAMEPLAY
PlaySound(fxCoin);
}
}
// Title Screen Draw logic
void DrawTitleScreen(void)
{
// TODO: Draw TITLE screen here!
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), GREEN);
DrawTextEx(font, "TITLE SCREEN", (Vector2){ 20, 10 }, font.baseSize*3, 4, DARKGREEN);
DrawText("PRESS ENTER or TAP to JUMP to GAMEPLAY SCREEN", 120, 220, 20, DARKGREEN);
}
// Title Screen Unload logic
void UnloadTitleScreen(void)
{
// TODO: Unload TITLE screen variables here!
}
// Title Screen should finish?
int FinishTitleScreen(void)
{
return finishScreen;
}
+95
View File
@@ -0,0 +1,95 @@
/**********************************************************************************************
*
* raylib - Advance Game template
*
* Screens Functions Declarations (Init, Update, Draw, Unload)
*
* Copyright (c) 2014-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.
*
**********************************************************************************************/
#ifndef SCREENS_H
#define SCREENS_H
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
typedef enum GameScreen { LOGO = 0, TITLE, OPTIONS, GAMEPLAY, ENDING } GameScreen;
//----------------------------------------------------------------------------------
// Global Variables Declaration (shared by several modules)
//----------------------------------------------------------------------------------
extern GameScreen currentScreen;
extern Font font;
extern Music music;
extern Sound fxCoin;
#ifdef __cplusplus
extern "C" { // Prevents name mangling of functions
#endif
//----------------------------------------------------------------------------------
// Logo Screen Functions Declaration
//----------------------------------------------------------------------------------
void InitLogoScreen(void);
void UpdateLogoScreen(void);
void DrawLogoScreen(void);
void UnloadLogoScreen(void);
int FinishLogoScreen(void);
//----------------------------------------------------------------------------------
// Title Screen Functions Declaration
//----------------------------------------------------------------------------------
void InitTitleScreen(void);
void UpdateTitleScreen(void);
void DrawTitleScreen(void);
void UnloadTitleScreen(void);
int FinishTitleScreen(void);
//----------------------------------------------------------------------------------
// Options Screen Functions Declaration
//----------------------------------------------------------------------------------
void InitOptionsScreen(void);
void UpdateOptionsScreen(void);
void DrawOptionsScreen(void);
void UnloadOptionsScreen(void);
int FinishOptionsScreen(void);
//----------------------------------------------------------------------------------
// Gameplay Screen Functions Declaration
//----------------------------------------------------------------------------------
void InitGameplayScreen(void);
void UpdateGameplayScreen(void);
void DrawGameplayScreen(void);
void UnloadGameplayScreen(void);
int FinishGameplayScreen(void);
//----------------------------------------------------------------------------------
// Ending Screen Functions Declaration
//----------------------------------------------------------------------------------
void InitEndingScreen(void);
void UpdateEndingScreen(void);
void DrawEndingScreen(void);
void UnloadEndingScreen(void);
int FinishEndingScreen(void);
#ifdef __cplusplus
}
#endif
#endif // SCREENS_H
+2 -2
View File
@@ -54,12 +54,12 @@ workspace (workspaceName)
architecture "x86_64"
targetdir "bin/%{cfg.buildcfg}/"
startproject(workspaceName)
startproject("game")
check_raylib();
include ("raylib_premake5.lua")
include ("app")
include ("game")
folders = os.matchdirs("*")
for _, folderName in ipairs(folders) do
+1
View File
@@ -0,0 +1 @@
Assets license.
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB