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 zcmeAS@N?(olHy`uVBq!ia0y~yU}OMc4kiW$hRXu>h9F*Xkh>GZx^prw85kH?(j9#r z85lP9bN@+XWnf_7EbxddW?zV2q8oGaWGG}1mllOFS45^5Fd;4P1on7l%9zOXSU%vkL+`@lhImb^musIa2 z_@{Snos%a^cTU!trE}z0|33Nu*1T!=?_X7a!93~lSL5I8_6+9FS?}Eb^!v5CPapq= z*i-B&#rGcUt^8~DocG*E<_mgHdAE80|f7 zreX4)hP1Ny`STn8>prXh^L~}h{y7(a3SPGRQYpDQf5TO!WwkGapE2C>Ir1goAD{bt zBRhra*?adN*}`ADEb?zdMV;l<&&tb6{|L=_{PStgx&9g77M?#SoujP?*2g^QF|$qE z47oo-In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ifSTX-4 zlvAd?T3$f@!Cu|{`|T8}KmW@+Cq3segIZ;CvCIJ#{e-^j`Nefix2EpdU#4l#@HPlk zH+f7FFDSM+wA-I$H)4XCqgB=&A4 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