From 4b4f052fea4f21a43c1eadadd9afa496066b6881 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 6 Feb 2020 16:56:01 +0100 Subject: [PATCH] Review game templates --- templates/advance_game/Makefile | 13 +- templates/advance_game/advance_game.c | 7 +- .../advance_game/resources/raylib_logo.png | Bin 3760 -> 0 bytes templates/advance_game/screens/screen_logo.c | 162 +++++++++++++++--- templates/advance_game/screens/screens.h | 8 +- templates/simple_game/Makefile | 11 +- templates/standard_game/Makefile | 11 +- 7 files changed, 175 insertions(+), 37 deletions(-) delete mode 100644 templates/advance_game/resources/raylib_logo.png diff --git a/templates/advance_game/Makefile b/templates/advance_game/Makefile index 4375b15d5..0be208f89 100644 --- a/templates/advance_game/Makefile +++ b/templates/advance_game/Makefile @@ -25,8 +25,8 @@ # Define required raylib variables PROJECT_NAME ?= advance_game -RAYLIB_VERSION ?= 2.5.0 -RAYLIB_API_VERSION ?= 2 +RAYLIB_VERSION ?= 3.0.0 +RAYLIB_API_VERSION ?= 3 RAYLIB_PATH ?= ../.. # Define default options @@ -164,7 +164,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI) endif ifeq ($(PLATFORM),PLATFORM_WEB) # 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() CC = emcc endif @@ -208,7 +208,10 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP) ifeq ($(PLATFORM_OS),WINDOWS) # resource file contains windows executable icon and properties # -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 ifeq ($(PLATFORM_OS),LINUX) ifeq ($(RAYLIB_LIBTYPE),STATIC) @@ -238,7 +241,7 @@ ifeq ($(PLATFORM),PLATFORM_WEB) # --profiling # include information for code profiling # --memory-init-file 0 # to avoid an external memory initialization code file (.mem) # --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 CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html diff --git a/templates/advance_game/advance_game.c b/templates/advance_game/advance_game.c index 7e2e7f213..64ce9d21a 100644 --- a/templates/advance_game/advance_game.c +++ b/templates/advance_game/advance_game.c @@ -19,6 +19,11 @@ #include #endif +GameScreen currentScreen = 0; +Font font = { 0 }; +Music music = { 0 }; +Sound fxCoin = { 0 }; + //---------------------------------------------------------------------------------- // Global Variables Definition (local to this module) //---------------------------------------------------------------------------------- @@ -153,7 +158,7 @@ static void UpdateTransition(void) { if (!transFadeOut) { - transAlpha += 0.02f; + 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 diff --git a/templates/advance_game/resources/raylib_logo.png b/templates/advance_game/resources/raylib_logo.png deleted file mode 100644 index 66545627719a2ab9aa73a0a801d94a0ea078b278..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3760 zcmaJ^X;_n27ETBl!y=o4A`%rD#-R#`fH;-Jh@t}(#v%eb1f)WxXwV=8fe<#uk;Q5q zpbao+1sWEyRInv9L3zLh1CCFq0zxcmD2sr|7LqXMehFY(+aEmS`@VbbIp=-fbI!fz zy!X26X`5-|a5%j^yWRHTaCrEM$1T=?e~%3)_UMVZ&z**=6q)}551L`yKiZDN-N@FF z2W!DIDRQ?z6Ng)J2mRrj8Ks}VOS7n*eo-GYLZf1WPaeT}2Om8iwQ=uGpViS08yz>= z+q;j^oMAb6kK1-1R^U+Qqmx}fRHih`OWX@Lxvq};s$S6eoqj^GzkyV0I8C;lnez7ILGAoG-y@^YOQ-ZDD4VBIau+%He>p z@f?Y`!a^v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a5b*(A|uq1`(te%Aa& zVX~$JI~|}w3t4bsn7?zMdEe374sHhOail)1ILnM8qHW5^24qS727v%>M`Oz4qLtiU z++W}(VlG@~8 120) + // Update LOGO screen variables here! + if (state == 0) // State 0: Small box blinking { - 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 void DrawLogoScreen(void) { - // TODO: Draw LOGO screen here! - DrawTextEx(font, "LOGO SCREEN", (Vector2){ 20, 10 }, font.baseSize*3, 4, GRAY); - DrawText("WAIT for 2 SECONDS...", 290, 400, 20, GRAY); - - DrawTexture(logo, GetScreenWidth()/2 - logo.width/2, 100, WHITE); + if (state == 0) + { + if ((framesCounter/10)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK); + } + 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 void UnloadLogoScreen(void) { - // TODO: Unload LOGO screen variables here! - - UnloadTexture(logo); + // Unload LOGO screen variables here! } // Logo Screen should finish? diff --git a/templates/advance_game/screens/screens.h b/templates/advance_game/screens/screens.h index 71e399eac..6ebafda3c 100644 --- a/templates/advance_game/screens/screens.h +++ b/templates/advance_game/screens/screens.h @@ -34,10 +34,10 @@ typedef enum GameScreen { LOGO = 0, TITLE, OPTIONS, GAMEPLAY, ENDING } GameScree //---------------------------------------------------------------------------------- // Global Variables Definition //---------------------------------------------------------------------------------- -GameScreen currentScreen; -Font font; -Music music; -Sound fxCoin; +extern GameScreen currentScreen; +extern Font font; +extern Music music; +extern Sound fxCoin; #ifdef __cplusplus extern "C" { // Prevents name mangling of functions diff --git a/templates/simple_game/Makefile b/templates/simple_game/Makefile index cc1d1e42b..04345a991 100644 --- a/templates/simple_game/Makefile +++ b/templates/simple_game/Makefile @@ -25,8 +25,8 @@ # Define required raylib variables PROJECT_NAME ?= simple_game -RAYLIB_VERSION ?= 2.5.0 -RAYLIB_API_VERSION ?= 2 +RAYLIB_VERSION ?= 3.0.0 +RAYLIB_API_VERSION ?= 3 RAYLIB_PATH ?= ../.. # Define default options @@ -164,7 +164,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI) endif ifeq ($(PLATFORM),PLATFORM_WEB) # 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() CC = emcc endif @@ -240,6 +240,11 @@ ifeq ($(PLATFORM),PLATFORM_WEB) # --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 + # 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 CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html EXT = .html diff --git a/templates/standard_game/Makefile b/templates/standard_game/Makefile index 5a86e8c92..d2f03ce88 100644 --- a/templates/standard_game/Makefile +++ b/templates/standard_game/Makefile @@ -25,8 +25,8 @@ # Define required raylib variables PROJECT_NAME ?= standard_game -RAYLIB_VERSION ?= 2.5.0 -RAYLIB_API_VERSION ?= 2 +RAYLIB_VERSION ?= 3.0.0 +RAYLIB_API_VERSION ?= 3 RAYLIB_PATH ?= ../.. # Define default options @@ -164,7 +164,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI) endif ifeq ($(PLATFORM),PLATFORM_WEB) # 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() CC = emcc endif @@ -240,6 +240,11 @@ ifeq ($(PLATFORM),PLATFORM_WEB) # --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 + # 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 CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html EXT = .html