Review game templates

This commit is contained in:
Ray 2020-02-06 16:56:01 +01:00
parent 2de92e3c07
commit 4b4f052fea
7 changed files with 175 additions and 37 deletions

View file

@ -25,8 +25,8 @@
# Define required raylib variables # Define required raylib variables
PROJECT_NAME ?= advance_game PROJECT_NAME ?= advance_game
RAYLIB_VERSION ?= 2.5.0 RAYLIB_VERSION ?= 3.0.0
RAYLIB_API_VERSION ?= 2 RAYLIB_API_VERSION ?= 3
RAYLIB_PATH ?= ../.. RAYLIB_PATH ?= ../..
# Define default options # Define default options
@ -164,7 +164,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI)
endif endif
ifeq ($(PLATFORM),PLATFORM_WEB) ifeq ($(PLATFORM),PLATFORM_WEB)
# HTML5 emscripten compiler # HTML5 emscripten compiler
# WARNING: To compile to HTML5, code must be redesigned # WARNING: To compile to HTML5, code must be redesigned
# to use emscripten.h and emscripten_set_main_loop() # to use emscripten.h and emscripten_set_main_loop()
CC = emcc CC = emcc
endif endif
@ -208,7 +208,10 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(PLATFORM_OS),WINDOWS) ifeq ($(PLATFORM_OS),WINDOWS)
# resource file contains windows executable icon and properties # resource file contains windows executable icon and properties
# -Wl,--subsystem,windows hides the console window # -Wl,--subsystem,windows hides the console window
CFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data -Wl,--subsystem,windows CFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data
ifeq ($(BUILD_MODE), RELEASE)
CFLAGS += -Wl,--subsystem,windows
endif
endif endif
ifeq ($(PLATFORM_OS),LINUX) ifeq ($(PLATFORM_OS),LINUX)
ifeq ($(RAYLIB_LIBTYPE),STATIC) ifeq ($(RAYLIB_LIBTYPE),STATIC)
@ -238,7 +241,7 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
# --profiling # include information for code profiling # --profiling # include information for code profiling
# --memory-init-file 0 # to avoid an external memory initialization code file (.mem) # --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
# --preload-file resources # specify a resources folder for data compilation # --preload-file resources # specify a resources folder for data compilation
CFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=16777216 --preload-file resources CFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=67108864 --preload-file resources
# Define a custom shell .html and output extension # Define a custom shell .html and output extension
CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html

View file

@ -19,6 +19,11 @@
#include <emscripten/emscripten.h> #include <emscripten/emscripten.h>
#endif #endif
GameScreen currentScreen = 0;
Font font = { 0 };
Music music = { 0 };
Sound fxCoin = { 0 };
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Global Variables Definition (local to this module) // Global Variables Definition (local to this module)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -153,7 +158,7 @@ static void UpdateTransition(void)
{ {
if (!transFadeOut) if (!transFadeOut)
{ {
transAlpha += 0.02f; transAlpha += 0.05f;
// NOTE: Due to float internal representation, condition jumps on 1.0f instead of 1.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 // For that reason we compare against 1.01f, to avoid last frame loading stop

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -31,10 +31,23 @@
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Logo screen global variables // Logo screen global variables
static int framesCounter; static int framesCounter = 0;
static int finishScreen; static int finishScreen = 0;
static Texture2D logo; 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 char raylib[8] = { 0 }; // raylib text array, max 8 letters
static int state = 0; // Tracking animation states (State Machine)
static float alpha = 1.0f; // Useful for fading
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Logo Screen Functions Definition // Logo Screen Functions Definition
@ -43,43 +56,150 @@ static Texture2D logo;
// Logo Screen Initialization logic // Logo Screen Initialization logic
void InitLogoScreen(void) void InitLogoScreen(void)
{ {
// TODO: Initialize LOGO screen variables here! // Initialize LOGO screen variables here!
framesCounter = 0;
finishScreen = 0; finishScreen = 0;
framesCounter = 0;
lettersCount = 0;
logo = LoadTexture("resources/raylib_logo.png"); logoPositionX = GetScreenWidth()/2 - 128;
logoPositionY = GetScreenHeight()/2 - 128;
topSideRecWidth = LOGO_RECS_SIDE;
leftSideRecHeight = LOGO_RECS_SIDE;
bottomSideRecWidth = LOGO_RECS_SIDE;
rightSideRecHeight = LOGO_RECS_SIDE;
for (int i = 0; i < 8; i++) raylib[i] = '\0';
state = 0;
alpha = 1.0f;
} }
// Logo Screen Update logic // Logo Screen Update logic
void UpdateLogoScreen(void) void UpdateLogoScreen(void)
{ {
// TODO: Update LOGO screen variables here! // Update LOGO screen variables here!
if (state == 0) // State 0: Small box blinking
framesCounter++; // Count frames
// Wait for 2 seconds (120 frames) before jumping to TITLE screen
if (framesCounter > 120)
{ {
finishScreen = true; framesCounter++;
if (framesCounter == 80)
{
state = 1;
framesCounter = 0; // Reset counter... will be used later...
}
}
else if (state == 1) // State 1: Top and left bars growing
{
topSideRecWidth += 8;
leftSideRecHeight += 8;
if (topSideRecWidth == 256) state = 2;
}
else if (state == 2) // State 2: Bottom and right bars growing
{
bottomSideRecWidth += 8;
rightSideRecHeight += 8;
if (bottomSideRecWidth == 256) state = 3;
}
else if (state == 3) // State 3: Letters appearing (one by one)
{
framesCounter++;
if (framesCounter/10) // Every 12 frames, one more letter!
{
lettersCount++;
framesCounter = 0;
}
switch (lettersCount)
{
case 1: raylib[0] = 'r'; break;
case 2: raylib[1] = 'a'; break;
case 3: raylib[2] = 'y'; break;
case 4: raylib[3] = 'l'; break;
case 5: raylib[4] = 'i'; break;
case 6: raylib[5] = 'b'; break;
default: break;
}
// When all letters have appeared...
if (lettersCount >= 10)
{
state = 4;
framesCounter = 0;
}
}
else if (state == 4)
{
framesCounter++;
if (framesCounter > 100)
{
alpha -= 0.02f;
if (alpha <= 0.0f)
{
alpha = 0.0f;
finishScreen = 1;
}
}
} }
} }
// Logo Screen Draw logic // Logo Screen Draw logic
void DrawLogoScreen(void) void DrawLogoScreen(void)
{ {
// TODO: Draw LOGO screen here! if (state == 0)
DrawTextEx(font, "LOGO SCREEN", (Vector2){ 20, 10 }, font.baseSize*3, 4, GRAY); {
DrawText("WAIT for 2 SECONDS...", 290, 400, 20, GRAY); if ((framesCounter/10)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK);
}
DrawTexture(logo, GetScreenWidth()/2 - logo.width/2, 100, WHITE); else if (state == 1)
{
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
}
else if (state == 2)
{
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)
{
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(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48, 50, Fade(BLACK, alpha));
}
else if (state == 4)
{
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(raylib, 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 // Logo Screen Unload logic
void UnloadLogoScreen(void) void UnloadLogoScreen(void)
{ {
// TODO: Unload LOGO screen variables here! // Unload LOGO screen variables here!
UnloadTexture(logo);
} }
// Logo Screen should finish? // Logo Screen should finish?

View file

@ -34,10 +34,10 @@ typedef enum GameScreen { LOGO = 0, TITLE, OPTIONS, GAMEPLAY, ENDING } GameScree
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
GameScreen currentScreen; extern GameScreen currentScreen;
Font font; extern Font font;
Music music; extern Music music;
Sound fxCoin; extern Sound fxCoin;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { // Prevents name mangling of functions extern "C" { // Prevents name mangling of functions

View file

@ -25,8 +25,8 @@
# Define required raylib variables # Define required raylib variables
PROJECT_NAME ?= simple_game PROJECT_NAME ?= simple_game
RAYLIB_VERSION ?= 2.5.0 RAYLIB_VERSION ?= 3.0.0
RAYLIB_API_VERSION ?= 2 RAYLIB_API_VERSION ?= 3
RAYLIB_PATH ?= ../.. RAYLIB_PATH ?= ../..
# Define default options # Define default options
@ -164,7 +164,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI)
endif endif
ifeq ($(PLATFORM),PLATFORM_WEB) ifeq ($(PLATFORM),PLATFORM_WEB)
# HTML5 emscripten compiler # HTML5 emscripten compiler
# WARNING: To compile to HTML5, code must be redesigned # WARNING: To compile to HTML5, code must be redesigned
# to use emscripten.h and emscripten_set_main_loop() # to use emscripten.h and emscripten_set_main_loop()
CC = emcc CC = emcc
endif endif
@ -240,6 +240,11 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
# --preload-file resources # specify a resources folder for data compilation # --preload-file resources # specify a resources folder for data compilation
CFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=16777216 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 CFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=16777216 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1
# NOTE: Simple raylib examples are compiled to be interpreter by emterpreter, that way,
# we can compile same code for ALL platforms with no change required, but, working on bigger
# projects, code needs to be refactored to avoid a blocking while() loop, moving Update and Draw
# logic to a self contained function: UpdateDrawFrame(), check core_basic_window_web.c for reference.
# Define a custom shell .html and output extension # Define a custom shell .html and output extension
CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
EXT = .html EXT = .html

View file

@ -25,8 +25,8 @@
# Define required raylib variables # Define required raylib variables
PROJECT_NAME ?= standard_game PROJECT_NAME ?= standard_game
RAYLIB_VERSION ?= 2.5.0 RAYLIB_VERSION ?= 3.0.0
RAYLIB_API_VERSION ?= 2 RAYLIB_API_VERSION ?= 3
RAYLIB_PATH ?= ../.. RAYLIB_PATH ?= ../..
# Define default options # Define default options
@ -164,7 +164,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI)
endif endif
ifeq ($(PLATFORM),PLATFORM_WEB) ifeq ($(PLATFORM),PLATFORM_WEB)
# HTML5 emscripten compiler # HTML5 emscripten compiler
# WARNING: To compile to HTML5, code must be redesigned # WARNING: To compile to HTML5, code must be redesigned
# to use emscripten.h and emscripten_set_main_loop() # to use emscripten.h and emscripten_set_main_loop()
CC = emcc CC = emcc
endif endif
@ -240,6 +240,11 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
# --preload-file resources # specify a resources folder for data compilation # --preload-file resources # specify a resources folder for data compilation
CFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=16777216 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 CFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=16777216 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1
# NOTE: Simple raylib examples are compiled to be interpreter by emterpreter, that way,
# we can compile same code for ALL platforms with no change required, but, working on bigger
# projects, code needs to be refactored to avoid a blocking while() loop, moving Update and Draw
# logic to a self contained function: UpdateDrawFrame(), check core_basic_window_web.c for reference.
# Define a custom shell .html and output extension # Define a custom shell .html and output extension
CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
EXT = .html EXT = .html