From 2a1c7388dd6ddb12710418ac1ddbdf27308da7c5 Mon Sep 17 00:00:00 2001 From: bit6tream Date: Tue, 26 Dec 2023 04:04:54 +0300 Subject: [PATCH] Initial commit --- src/Makefile | 11 ++-- src/raylib_game.c | 143 ---------------------------------------------- src/sinister.c | 104 +++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 149 deletions(-) delete mode 100644 src/raylib_game.c create mode 100644 src/sinister.c diff --git a/src/Makefile b/src/Makefile index e7d416e..b1e93c9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -29,7 +29,7 @@ PLATFORM ?= PLATFORM_DESKTOP # Define project variables -PROJECT_NAME ?= raylib_game +PROJECT_NAME ?= sinister PROJECT_VERSION ?= 1.0 PROJECT_BUILD_PATH ?= . @@ -220,17 +220,17 @@ ifeq ($(PLATFORM),PLATFORM_WEB) # --preload-file resources # specify a resources folder for data compilation # --source-map-base # allow debugging in browser with source map LDFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=$(BUILD_WEB_HEAP_SIZE) -s FORCE_FILESYSTEM=1 - + # Build using asyncify ifeq ($(BUILD_WEB_ASYNCIFY),TRUE) LDFLAGS += -s ASYNCIFY endif - + # Add resources building if required ifeq ($(BUILD_WEB_RESOURCES),TRUE) LDFLAGS += --preload-file $(BUILD_WEB_RESOURCES_PATH) endif - + # Add debug mode flags if required ifeq ($(BUILD_MODE),DEBUG) LDFLAGS += -s ASSERTIONS=1 --profiling @@ -298,7 +298,7 @@ endif # Define source code files required #------------------------------------------------------------------------------------------------ -PROJECT_SOURCE_FILES ?= raylib_game.c +PROJECT_SOURCE_FILES ?= sinister.c # Define all object files from source files OBJS = $(patsubst %.c, %.o, $(PROJECT_SOURCE_FILES)) @@ -341,4 +341,3 @@ ifeq ($(PLATFORM),PLATFORM_WEB) del *.o *.html *.js endif @echo Cleaning done - diff --git a/src/raylib_game.c b/src/raylib_game.c deleted file mode 100644 index a3cf651..0000000 --- a/src/raylib_game.c +++ /dev/null @@ -1,143 +0,0 @@ -/******************************************************************************************* -* -* raylib gamejam template -* -* Template originally created with raylib 4.5-dev, last time updated with raylib 5.0 -* -* Template licensed under an unmodified zlib/libpng license, which is an OSI-certified, -* BSD-like license that allows static linking with closed source software -* -* Copyright (c) 2022-2023 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -#if defined(PLATFORM_WEB) - #define CUSTOM_MODAL_DIALOGS // Force custom modal dialogs usage - #include // Emscripten library - LLVM to JavaScript compiler -#endif - -#include // Required for: printf() -#include // Required for: -#include // Required for: - -//---------------------------------------------------------------------------------- -// Defines and Macros -//---------------------------------------------------------------------------------- -// Simple log system to avoid printf() calls if required -// NOTE: Avoiding those calls, also avoids const strings memory usage -#define SUPPORT_LOG_INFO -#if defined(SUPPORT_LOG_INFO) - #define LOG(...) printf(__VA_ARGS__) -#else - #define LOG(...) -#endif - -//---------------------------------------------------------------------------------- -// Types and Structures Definition -//---------------------------------------------------------------------------------- -typedef enum { - SCREEN_LOGO = 0, - SCREEN_TITLE, - SCREEN_GAMEPLAY, - SCREEN_ENDING -} GameScreen; - -// TODO: Define your custom data types here - -//---------------------------------------------------------------------------------- -// Global Variables Definition -//---------------------------------------------------------------------------------- -static const int screenWidth = 1280; -static const int screenHeight = 720; - -static RenderTexture2D target = { 0 }; // Render texture to render our game - -// TODO: Define global variables here, recommended to make them static - -//---------------------------------------------------------------------------------- -// Module Functions Declaration -//---------------------------------------------------------------------------------- -static void UpdateDrawFrame(void); // Update and Draw one frame - -//------------------------------------------------------------------------------------ -// Program main entry point -//------------------------------------------------------------------------------------ -int main(void) -{ -#if !defined(_DEBUG) - SetTraceLogLevel(LOG_NONE); // Disable raylib trace log messsages -#endif - - // Initialization - //-------------------------------------------------------------------------------------- - InitWindow(screenWidth, screenHeight, "raylib gamejam template"); - - // TODO: Load resources / Initialize variables at this point - - // Render texture to draw full screen, enables screen scaling - // NOTE: If screen is scaled, mouse input should be scaled proportionally - target = LoadRenderTexture(screenWidth, screenHeight); - SetTextureFilter(target.texture, TEXTURE_FILTER_BILINEAR); - -#if defined(PLATFORM_WEB) - emscripten_set_main_loop(UpdateDrawFrame, 60, 1); -#else - SetTargetFPS(60); // Set our game frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button - { - UpdateDrawFrame(); - } -#endif - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadRenderTexture(target); - - // TODO: Unload all loaded resources at this point - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} - -//-------------------------------------------------------------------------------------------- -// Module functions definition -//-------------------------------------------------------------------------------------------- -// Update and draw frame -void UpdateDrawFrame(void) -{ - // Update - //---------------------------------------------------------------------------------- - // TODO: Update variables / Implement example logic at this point - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - // Render game screen to a texture, - // it could be useful for scaling or further sahder postprocessing - BeginTextureMode(target); - ClearBackground(RAYWHITE); - - // TODO: Draw your game screen here - DrawRectangle(10, 10, screenWidth - 20, screenHeight - 20, SKYBLUE); - - EndTextureMode(); - - // Render to screen (main framebuffer) - BeginDrawing(); - ClearBackground(RAYWHITE); - - // Draw render texture to screen, scaled if required - DrawTexturePro(target.texture, (Rectangle){ 0, 0, (float)target.texture.width, -(float)target.texture.height }, (Rectangle){ 0, 0, (float)target.texture.width, (float)target.texture.height }, (Vector2){ 0, 0 }, 0.0f, WHITE); - - // TODO: Draw everything that requires to be drawn at this point, maybe UI? - - EndDrawing(); - //---------------------------------------------------------------------------------- -} \ No newline at end of file diff --git a/src/sinister.c b/src/sinister.c new file mode 100644 index 0000000..989b205 --- /dev/null +++ b/src/sinister.c @@ -0,0 +1,104 @@ +/******************************************************************************************* + * + * raylib gamejam template + * + * Template originally created with raylib 4.5-dev, last time updated with raylib 5.0 + * + * Template licensed under an unmodified zlib/libpng license, which is an OSI-certified, + * BSD-like license that allows static linking with closed source software + * + * Copyright (c) 2022-2023 Ramon Santamaria (@raysan5) + * + ********************************************************************************************/ + +#include "raylib.h" + +#if defined(PLATFORM_WEB) +#define CUSTOM_MODAL_DIALOGS +#include +#endif + +#include +#include +#include + +#define SUPPORT_LOG_INFO +#if defined(SUPPORT_LOG_INFO) +#define LOG(...) printf(__VA_ARGS__) +#else +#define LOG(...) +#endif + +#define MAX(a, b) ((a) > (b) ? (a) : (b)) + +static const int screenWidth = 500; +static const int screenHeight = 700; + +static RenderTexture2D target = { 0 }; + +void UpdateDrawFrame(void) { + BeginTextureMode(target); { + ClearBackground(BLACK); + + DrawRectangle(0, 0, screenWidth, screenHeight, SKYBLUE); + } EndTextureMode(); + + + BeginDrawing(); { + ClearBackground(BLACK); + + float width = (float)target.texture.width; + float height = (float)target.texture.height; + + float aspect = width / height; + + float finalHeight = MAX((float)GetScreenHeight(), height); + + float finalWidth = finalHeight * aspect; + + DrawTexturePro(target.texture, + (Rectangle) { + .x = 0, + .y = 0, + .width = width, + .height = -height + }, + (Rectangle) { + .x = (float)GetScreenWidth() / 2, + .y = (float)GetScreenHeight() / 2, + .width = finalWidth, + .height = finalHeight, + }, + (Vector2) { finalWidth / 2, finalHeight / 2 }, + 0.0f, + WHITE); + } + EndDrawing(); +} + + +int main(void) { +#if !defined(_DEBUG) + SetTraceLogLevel(LOG_NONE); +#endif + InitWindow(screenWidth, screenHeight, "sinister"); + SetWindowState(FLAG_WINDOW_RESIZABLE); + + target = LoadRenderTexture(screenWidth, screenHeight); + /* SetTextureFilter(target.texture, TEXTURE_FILTER_BILINEAR); */ + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 60, 1); +#else + SetTargetFPS(60); + + while (!WindowShouldClose()) { + UpdateDrawFrame(); + } +#endif + + UnloadRenderTexture(target); + CloseWindow(); + + return 0; +}