From a5492dd5fc8500d05ae7a3cc5afbd5c7d3d00c94 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 2 Jan 2016 11:00:23 +0100 Subject: Corrected compilation flag... ...to avoid .mem file creation --- games/just_do_GGJ2015/src/makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'games') diff --git a/games/just_do_GGJ2015/src/makefile b/games/just_do_GGJ2015/src/makefile index 32bee4dc..4c36b154 100644 --- a/games/just_do_GGJ2015/src/makefile +++ b/games/just_do_GGJ2015/src/makefile @@ -72,7 +72,7 @@ else CFLAGS = -O2 -Wall -std=c99 endif ifeq ($(PLATFORM),PLATFORM_WEB) - CFLAGS = -O2 -Wall -std=c99 -s USE_GLFW=3 + CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 #-s ASSERTIONS=1 --preload-file resources #-s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing #-s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) -- cgit v1.2.3 From e97438114f6b1606c9b1d1e621150fc4f3f6a08e Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 2 Jan 2016 11:14:04 +0100 Subject: Reviewed code --- games/floppy/floppy.c | 53 +++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'games') diff --git a/games/floppy/floppy.c b/games/floppy/floppy.c index 0617797e..0c0cb5f2 100644 --- a/games/floppy/floppy.c +++ b/games/floppy/floppy.c @@ -2,16 +2,6 @@ * * raylib game - Floppy Bird * -* Welcome to raylib! -* -* To test examples, just press F6 and execute raylib_compile_execute script -* Note that compiled executable is placed in the same folder as .c file -* -* You can find all basic examples on C:\raylib\raylib\examples folder or -* raylib official webpage: www.raylib.com -* -* Enjoy using raylib. :) -* * This game has been created using raylib 1.1 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * @@ -86,10 +76,21 @@ int main() { // Update //---------------------------------------------------------------------------------- - backScroll--; + // Background scroll logic + backScroll--; if (backScroll <= -800) backScroll = 0; + // Player movement logic + if (!gameover) + { + if (IsKeyDown(KEY_SPACE)) floppyPos.y -= 3; + else floppyPos.y += 1; + + if (IsKeyPressed(KEY_SPACE)) PlaySound(jump); + } + + // Tubes moving logic for (int i = 0; i < MAX_TUBES; i++) tubesPos[i].x -= tubesSpeedX; for (int i = 0; i < MAX_TUBES*2; i += 2) @@ -98,12 +99,7 @@ int main() tubesRecs[i+1].x = tubesPos[i/2].x; } - if (IsKeyDown(KEY_SPACE) && !gameover) floppyPos.y -= 3; - else floppyPos.y += 1; - - if (IsKeyPressed(KEY_SPACE) && !gameover) PlaySound(jump); - - // Check Collisions + // Check collisions player-tubes for (int i = 0; i < MAX_TUBES*2; i++) { if (CheckCollisionCircleRec((Vector2){ floppyPos.x + floppy.width/2, floppyPos.y + floppy.height/2 }, floppy.width/2, tubesRecs[i])) @@ -122,6 +118,7 @@ int main() } } + // Gameover logic for reset if (gameover && IsKeyPressed(KEY_ENTER)) { for (int i = 0; i < MAX_TUBES; i++) @@ -147,7 +144,6 @@ int main() gameover = false; score = 0; } - //---------------------------------------------------------------------------------- // Draw @@ -156,32 +152,39 @@ int main() ClearBackground(RAYWHITE); + // Draw scrolling background DrawTexture(background, backScroll, 0, WHITE); DrawTexture(background, screenWidth + backScroll, 0, WHITE); - if (!gameover) - { - DrawTextureEx(floppy, floppyPos, 0, 1.0, WHITE); - //DrawCircleLines(floppyPos.x + floppy.width/2, floppyPos.y + floppy.height/2, floppy.width/2, RED); - } - + // Draw moving tubes for (int i = 0; i < MAX_TUBES; i++) { if (tubesPos[i].x <= 800) DrawTextureEx(tubes, tubesPos[i], 0, 1.0, WHITE); + // Draw collision recs //DrawRectangleLines(tubesRecs[i*2].x, tubesRecs[i*2].y, tubesRecs[i*2].width, tubesRecs[i*2].height, RED); //DrawRectangleLines(tubesRecs[i*2 + 1].x, tubesRecs[i*2 + 1].y, tubesRecs[i*2 + 1].width, tubesRecs[i*2 + 1].height, RED); } + // Draw scores DrawText(FormatText("%04i", score), 20, 20, 40, PINK); DrawText(FormatText("HI-SCORE: %04i", hiscore), 20, 70, 20, VIOLET); - if (gameover) + // Draw player or game over messages + if (!gameover) + { + DrawTextureEx(floppy, floppyPos, 0, 1.0, WHITE); + + // Draw collision circle + //DrawCircleLines(floppyPos.x + floppy.width/2, floppyPos.y + floppy.height/2, floppy.width/2, RED); + } + else { DrawText("GAME OVER", 100, 180, 100, MAROON); DrawText("PRESS ENTER to RETRY!", 280, 280, 20, RED); } + // Draw screen light flash when passing through a tube if (superfx) { DrawRectangle(0, 0, screenWidth, screenHeight, GOLD); -- cgit v1.2.3 From 63ea3449d3119338684a8056b508f42291a8cff5 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 2 Jan 2016 11:14:24 +0100 Subject: Reorganized folders --- games/just_do/just_do.c | 358 +++++++++++++++++++++ games/just_do/makefile | 246 ++++++++++++++ games/just_do/resources/ambient.ogg | Bin 0 -> 2672956 bytes games/just_do/resources/win.wav | Bin 0 -> 6748 bytes games/just_do/screens/screen_level00.c | 167 ++++++++++ games/just_do/screens/screen_level01.c | 163 ++++++++++ games/just_do/screens/screen_level02.c | 170 ++++++++++ games/just_do/screens/screen_level03.c | 134 ++++++++ games/just_do/screens/screen_level04.c | 147 +++++++++ games/just_do/screens/screen_level05.c | 185 +++++++++++ games/just_do/screens/screen_level06.c | 156 +++++++++ games/just_do/screens/screen_level07.c | 178 ++++++++++ games/just_do/screens/screen_level08.c | 157 +++++++++ games/just_do/screens/screen_level09.c | 199 ++++++++++++ games/just_do/screens/screen_level10.c | 153 +++++++++ games/just_do/screens/screen_logo.c | 227 +++++++++++++ games/just_do/screens/screens.h | 150 +++++++++ games/just_do_GGJ2015/src/just_do.c | 358 --------------------- games/just_do_GGJ2015/src/makefile | 246 -------------- games/just_do_GGJ2015/src/resources/ambient.ogg | Bin 2672956 -> 0 bytes games/just_do_GGJ2015/src/resources/win.wav | Bin 6748 -> 0 bytes games/just_do_GGJ2015/src/screens/screen_level00.c | 167 ---------- games/just_do_GGJ2015/src/screens/screen_level01.c | 163 ---------- games/just_do_GGJ2015/src/screens/screen_level02.c | 170 ---------- games/just_do_GGJ2015/src/screens/screen_level03.c | 134 -------- games/just_do_GGJ2015/src/screens/screen_level04.c | 147 --------- games/just_do_GGJ2015/src/screens/screen_level05.c | 185 ----------- games/just_do_GGJ2015/src/screens/screen_level06.c | 156 --------- games/just_do_GGJ2015/src/screens/screen_level07.c | 178 ---------- games/just_do_GGJ2015/src/screens/screen_level08.c | 157 --------- games/just_do_GGJ2015/src/screens/screen_level09.c | 199 ------------ games/just_do_GGJ2015/src/screens/screen_level10.c | 153 --------- games/just_do_GGJ2015/src/screens/screen_logo.c | 227 ------------- games/just_do_GGJ2015/src/screens/screens.h | 150 --------- 34 files changed, 2790 insertions(+), 2790 deletions(-) create mode 100644 games/just_do/just_do.c create mode 100644 games/just_do/makefile create mode 100644 games/just_do/resources/ambient.ogg create mode 100644 games/just_do/resources/win.wav create mode 100644 games/just_do/screens/screen_level00.c create mode 100644 games/just_do/screens/screen_level01.c create mode 100644 games/just_do/screens/screen_level02.c create mode 100644 games/just_do/screens/screen_level03.c create mode 100644 games/just_do/screens/screen_level04.c create mode 100644 games/just_do/screens/screen_level05.c create mode 100644 games/just_do/screens/screen_level06.c create mode 100644 games/just_do/screens/screen_level07.c create mode 100644 games/just_do/screens/screen_level08.c create mode 100644 games/just_do/screens/screen_level09.c create mode 100644 games/just_do/screens/screen_level10.c create mode 100644 games/just_do/screens/screen_logo.c create mode 100644 games/just_do/screens/screens.h delete mode 100644 games/just_do_GGJ2015/src/just_do.c delete mode 100644 games/just_do_GGJ2015/src/makefile delete mode 100644 games/just_do_GGJ2015/src/resources/ambient.ogg delete mode 100644 games/just_do_GGJ2015/src/resources/win.wav delete mode 100644 games/just_do_GGJ2015/src/screens/screen_level00.c delete mode 100644 games/just_do_GGJ2015/src/screens/screen_level01.c delete mode 100644 games/just_do_GGJ2015/src/screens/screen_level02.c delete mode 100644 games/just_do_GGJ2015/src/screens/screen_level03.c delete mode 100644 games/just_do_GGJ2015/src/screens/screen_level04.c delete mode 100644 games/just_do_GGJ2015/src/screens/screen_level05.c delete mode 100644 games/just_do_GGJ2015/src/screens/screen_level06.c delete mode 100644 games/just_do_GGJ2015/src/screens/screen_level07.c delete mode 100644 games/just_do_GGJ2015/src/screens/screen_level08.c delete mode 100644 games/just_do_GGJ2015/src/screens/screen_level09.c delete mode 100644 games/just_do_GGJ2015/src/screens/screen_level10.c delete mode 100644 games/just_do_GGJ2015/src/screens/screen_logo.c delete mode 100644 games/just_do_GGJ2015/src/screens/screens.h (limited to 'games') diff --git a/games/just_do/just_do.c b/games/just_do/just_do.c new file mode 100644 index 00000000..beac9e14 --- /dev/null +++ b/games/just_do/just_do.c @@ -0,0 +1,358 @@ +/******************************************************************************************* +* +* JUST DO - Global Game Jam 2015 Videogame +* Experimental puzzle game that lets the user try to find a logic solution to +* different shape-color-based situations. +* +* Developed by: Ramon Santamaria (Ray San) +* +* This game has been created using raylib (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* raylib - Copyright (c) 2015 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" +#include "screens/screens.h" // NOTE: Defines currentScreen + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- +const int screenWidth = 1280; // Moved to screens.h +const int screenHeight = 720; // Moved to screens.h + +// Required variables to manage screen transitions (fade-in, fade-out) +float transAlpha = 0; +bool onTransition = false; +bool transFadeOut = false; +int transFromScreen = -1; +int transToScreen = -1; +int framesCounter = 0; + +//static Sound levelWin; + +//---------------------------------------------------------------------------------- +// Local Functions Declaration +//---------------------------------------------------------------------------------- +void TransitionToScreen(int screen); +void UpdateTransition(void); +void DrawTransition(void); + +void UpdateDrawFrame(void); // Update and Draw one frame + +//---------------------------------------------------------------------------------- +// Main entry point +//---------------------------------------------------------------------------------- +int main(void) +{ + // Initialization + //--------------------------------------------------------- + const char windowTitle[30] = "JUST DO"; + + //SetupFlags(FLAG_FULLSCREEN_MODE); + InitWindow(screenWidth, screenHeight, windowTitle); + + // TODO: Load global data here (assets that must be available in all screens, i.e. fonts) + InitAudioDevice(); + + levelWin = LoadSound("resources/win.wav"); + + // Setup and Init first screen + currentScreen = LOGO; + InitLogoScreen(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 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 + { + + if (IsKeyPressed(KEY_SPACE)) PlaySound(levelWin); + + UpdateDrawFrame(); + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + + // TODO: Unload all global loaded data (i.e. fonts) here! + UnloadSound(levelWin); + + CloseAudioDevice(); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//---------------------------------------------------------------------------------- +// Local Functions Definition +//---------------------------------------------------------------------------------- +void TransitionToScreen(int screen) +{ + onTransition = true; + transFromScreen = currentScreen; + transToScreen = screen; +} + +void UpdateTransition(void) +{ + if (!transFadeOut) + { + transAlpha += 0.02f; + + if (transAlpha >= 1.0) + { + transAlpha = 1.0; + currentScreen = transToScreen; + transFadeOut = true; + framesCounter = 0; + } + } + else // Transition fade out logic + { + transAlpha -= 0.02f; + + if (transAlpha <= 0) + { + transAlpha = 0; + transFadeOut = false; + onTransition = false; + transFromScreen = -1; + transToScreen = -1; + } + } +} + +void DrawTransition(void) +{ + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, transAlpha)); +} + +void UpdateDrawFrame(void) +{ + // Update + //---------------------------------------------------------------------------------- + if (!onTransition) + { + if (IsKeyPressed('0')) + { + TransitionToScreen(LEVEL00); + InitLevel00Screen(); + } + else if (IsKeyPressed('1')) + { + TransitionToScreen(LEVEL01); + InitLevel01Screen(); + } + else if (IsKeyPressed('2')) + { + TransitionToScreen(LEVEL02); + InitLevel02Screen(); + } + else if (IsKeyPressed('3')) + { + TransitionToScreen(LEVEL03); + InitLevel03Screen(); + } + else if (IsKeyPressed('4')) + { + TransitionToScreen(LEVEL04); + InitLevel04Screen(); + } + else if (IsKeyPressed('5')) + { + TransitionToScreen(LEVEL05); + InitLevel05Screen(); + } + else if (IsKeyPressed('6')) + { + TransitionToScreen(LEVEL06); + InitLevel06Screen(); + } + else if (IsKeyPressed('7')) + { + TransitionToScreen(LEVEL07); + InitLevel07Screen(); + } + else if (IsKeyPressed('8')) + { + TransitionToScreen(LEVEL08); + InitLevel08Screen(); + } + else if (IsKeyPressed('9')) + { + TransitionToScreen(LEVEL09); + InitLevel08Screen(); + } + + switch(currentScreen) + { + case LOGO: + { + UpdateLogoScreen(); + + if (FinishLogoScreen()) + { + UnloadLogoScreen(); + TransitionToScreen(LEVEL00); + InitLevel00Screen(); + + PlayMusicStream("resources/ambient.ogg"); + SetMusicVolume(0.6f); + } + } break; + case LEVEL00: + { + UpdateLevel00Screen(); + + if (FinishLevel00Screen()) + { + UnloadLevel00Screen(); + TransitionToScreen(LEVEL01); + InitLevel01Screen(); + } + } break; + case LEVEL01: + { + UpdateLevel01Screen(); + + if (FinishLevel01Screen()) + { + UnloadLevel01Screen(); + TransitionToScreen(LEVEL02); + InitLevel02Screen(); + } + } break; + case LEVEL02: + { + UpdateLevel02Screen(); + + if (FinishLevel02Screen()) + { + UnloadLevel02Screen(); + TransitionToScreen(LEVEL03); + InitLevel03Screen(); + } + } break; + case LEVEL03: + { + UpdateLevel03Screen(); + + if (FinishLevel03Screen()) + { + UnloadLevel03Screen(); + TransitionToScreen(LEVEL04); + InitLevel04Screen(); + } + } break; + case LEVEL04: + { + UpdateLevel04Screen(); + + if (FinishLevel04Screen()) + { + UnloadLevel04Screen(); + TransitionToScreen(LEVEL05); + InitLevel05Screen(); + } + } break; + case LEVEL05: + { + UpdateLevel05Screen(); + + if (FinishLevel05Screen()) + { + UnloadLevel05Screen(); + TransitionToScreen(LEVEL06); + InitLevel06Screen(); + } + } break; + case LEVEL06: + { + UpdateLevel06Screen(); + + if (FinishLevel06Screen()) + { + UnloadLevel06Screen(); + TransitionToScreen(LEVEL07); + InitLevel07Screen(); + } + } break; + case LEVEL07: + { + UpdateLevel07Screen(); + + if (FinishLevel07Screen()) + { + UnloadLevel07Screen(); + TransitionToScreen(LEVEL08); + InitLevel08Screen(); + } + } break; + case LEVEL08: + { + UpdateLevel08Screen(); + + if (FinishLevel08Screen()) + { + UnloadLevel08Screen(); + TransitionToScreen(LEVEL09); + InitLevel09Screen(); + } + } break; + case LEVEL09: + { + UpdateLevel09Screen(); + + if (FinishLevel09Screen()) + { + UnloadLevel09Screen(); + TransitionToScreen(LEVEL00); + InitLevel00Screen(); + } + } break; + default: break; + } + } + else UpdateTransition(); // Update transition (fade-in, fade-out) + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + switch(currentScreen) + { + case LOGO: DrawLogoScreen(); break; + case LEVEL00: DrawLevel00Screen(); break; + case LEVEL01: DrawLevel01Screen(); break; + case LEVEL02: DrawLevel02Screen(); break; + case LEVEL03: DrawLevel03Screen(); break; + case LEVEL04: DrawLevel04Screen(); break; + case LEVEL05: DrawLevel05Screen(); break; + case LEVEL06: DrawLevel06Screen(); break; + case LEVEL07: DrawLevel07Screen(); break; + case LEVEL08: DrawLevel08Screen(); break; + case LEVEL09: DrawLevel09Screen(); break; + default: break; + } + + if (onTransition) DrawTransition(); + + EndDrawing(); + //---------------------------------------------------------------------------------- +} \ No newline at end of file diff --git a/games/just_do/makefile b/games/just_do/makefile new file mode 100644 index 00000000..4c36b154 --- /dev/null +++ b/games/just_do/makefile @@ -0,0 +1,246 @@ +#************************************************************************************************** +# +# raylib - Advance Game +# +# makefile to compile advance game for desktop platforms, Raspberry Pi and HTML5 (emscripten) +# +# Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +# +# 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. +# +#************************************************************************************************** + +# define raylib platform to compile for +# possible platforms: PLATFORM_DESKTOP PLATFORM_RPI PLATFORM_WEB +# WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop() +PLATFORM ?= PLATFORM_DESKTOP + +# determine PLATFORM_OS in case PLATFORM_DESKTOP selected +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + # No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows + ifeq ($(OS),Windows_NT) + PLATFORM_OS=WINDOWS + LIBPATH=win32 + else + UNAMEOS:=$(shell uname) + ifeq ($(UNAMEOS),Linux) + PLATFORM_OS=LINUX + LIBPATH=linux + else + ifeq ($(UNAMEOS),Darwin) + PLATFORM_OS=OSX + LIBPATH=osx + endif + endif + endif +endif + +# define compiler: gcc for C program, define as g++ for C++ +ifeq ($(PLATFORM),PLATFORM_WEB) + # define emscripten compiler + CC = emcc +else +ifeq ($(PLATFORM_OS),OSX) + # define llvm compiler for mac + CC = clang +else + # define default gcc compiler + CC = gcc +endif +endif + +# define compiler flags: +# -O2 defines optimization level +# -Wall turns on most, but not all, compiler warnings +# -std=c99 use standard C from 1999 revision +ifeq ($(PLATFORM),PLATFORM_RPI) + CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline +else + CFLAGS = -O2 -Wall -std=c99 +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 + #-s ASSERTIONS=1 --preload-file resources + #-s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing + #-s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) +endif + +#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes + +# define any directories containing required header files +ifeq ($(PLATFORM),PLATFORM_RPI) + INCLUDES = -I. -I../../src -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads +else + INCLUDES = -I. -I../../src -I../../../src +# external libraries headers +# GLFW3 + INCLUDES += -I../../external/glfw3/include +# GLEW + INCLUDES += -I../../external/glew/include +# OpenAL Soft + INCLUDES += -I../../external/openal_soft/include +endif + +# define library paths containing required libs +ifeq ($(PLATFORM),PLATFORM_RPI) + LFLAGS = -L. -L../../src -L/opt/vc/lib +else + LFLAGS = -L. -L../../src -L../../../src + # external libraries to link with + # GLFW3 + LFLAGS += -L../../external/glfw3/lib/$(LIBPATH) + ifneq ($(PLATFORM_OS),OSX) + # OpenAL Soft + LFLAGS += -L../../external/openal_soft/lib/$(LIBPATH) + # GLEW + LFLAGS += -L../../external/glew/lib/$(LIBPATH) + endif +endif + +# define any libraries to link into executable +# if you want to link libraries (libname.so or libname.a), use the -lname +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),LINUX) + # libraries for Debian GNU/Linux desktop compiling + # requires the following packages: + # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev + LIBS = -lraylib -lglfw -lGLEW -lGL -lopenal + endif + ifeq ($(PLATFORM_OS),OSX) + # libraries for OS X 10.9 desktop compiling + # requires the following packages: + # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev + LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAl -framework Cocoa + else + # libraries for Windows desktop compiling + # NOTE: GLFW3 and OpenAL Soft libraries should be installed + LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32 + endif +endif +ifeq ($(PLATFORM),PLATFORM_RPI) + # libraries for Raspberry Pi compiling + # NOTE: OpenAL Soft library should be installed (libopenal1 package) + LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + LIBS = ../../src/libraylib.bc +endif + +# define additional parameters and flags for windows +ifeq ($(PLATFORM_OS),WINDOWS) + # resources file contains windows exe icon + # -Wl,--subsystem,windows hides the console window + WINFLAGS = ../../src/resources -Wl,--subsystem,windows +endif + +ifeq ($(PLATFORM),PLATFORM_WEB) + EXT = .html +endif + +# define all screen object files required +SCREENS = \ + screens/screen_logo.o \ + screens/screen_level00.o \ + screens/screen_level01.o \ + screens/screen_level02.o \ + screens/screen_level03.o \ + screens/screen_level04.o \ + screens/screen_level05.o \ + screens/screen_level06.o \ + screens/screen_level07.o \ + screens/screen_level08.o \ + screens/screen_level09.o \ + +# typing 'make' will invoke the first target entry in the file, +# in this case, the 'default' target entry is just_do +default: just_do + +# compile just_do +just_do: just_do.c $(SCREENS) + $(CC) -o $@$(EXT) $< $(SCREENS) $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) + +# compile screen LOGO +screens/screen_logo.o: screens/screen_logo.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LEVEL00 +screens/screen_level00.o: screens/screen_level00.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LEVEL01 +screens/screen_level01.o: screens/screen_level01.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LEVEL02 +screens/screen_level02.o: screens/screen_level02.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LEVEL03 +screens/screen_level03.o: screens/screen_level03.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LEVEL04 +screens/screen_level04.o: screens/screen_level04.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LEVEL05 +screens/screen_level05.o: screens/screen_level05.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LEVEL06 +screens/screen_level06.o: screens/screen_level06.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LEVEL07 +screens/screen_level07.o: screens/screen_level07.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LEVEL08 +screens/screen_level08.o: screens/screen_level08.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LEVEL09 +screens/screen_level09.o: screens/screen_level09.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# clean everything +clean: +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),OSX) + find . -type f -perm +ugo+x -delete + rm -f *.o + else + ifeq ($(PLATFORM_OS),LINUX) + find . -type f -executable -delete + rm -f *.o + else + del *.o *.exe + endif + endif +endif +ifeq ($(PLATFORM),PLATFORM_RPI) + find . -type f -executable -delete + rm -f *.o +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + del *.o *.html *.js +endif + @echo Cleaning done + +# instead of defining every module one by one, we can define a pattern +# this pattern below will automatically compile every module defined on $(OBJS) +#%.exe : %.c +# $(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) diff --git a/games/just_do/resources/ambient.ogg b/games/just_do/resources/ambient.ogg new file mode 100644 index 00000000..af7f836e Binary files /dev/null and b/games/just_do/resources/ambient.ogg differ diff --git a/games/just_do/resources/win.wav b/games/just_do/resources/win.wav new file mode 100644 index 00000000..72520f99 Binary files /dev/null and b/games/just_do/resources/win.wav differ diff --git a/games/just_do/screens/screen_level00.c b/games/just_do/screens/screen_level00.c new file mode 100644 index 00000000..99f29849 --- /dev/null +++ b/games/just_do/screens/screen_level00.c @@ -0,0 +1,167 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Level00 Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Level00 screen global variables +static int framesCounter; +static int finishScreen; + +static Rectangle boundsU, boundsO; + +static bool mouseOverU = false; +static bool mouseOverO = false; +static bool placedU = false; +static bool placedO = false; + +static bool done = false; +static int levelTimeSec = 0; +static bool levelFinished = false; + +//---------------------------------------------------------------------------------- +// Level00 Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Level00 Screen Initialization logic +void InitLevel00Screen(void) +{ + // Initialize Level00 screen variables here! + framesCounter = 0; + finishScreen = 0; + + boundsU = (Rectangle){GetScreenWidth()/2 - 265, -200, MeasureText("U", 160) + 40, 160 }; + boundsO = (Rectangle){GetScreenWidth() - 370, -30, MeasureText("O", 160) + 40, 160 }; +} + +// Level00 Screen Update logic +void UpdateLevel00Screen(void) +{ + // Update Level00 screen variables here! + if (!done) framesCounter++; + + if (!done) + { + if (!placedU) boundsU.y += 2; + + if (boundsU.y >= GetScreenHeight()) boundsU.y = -boundsU.height; + + Vector2 mousePos = GetMousePosition(); + + if (CheckCollisionPointRec(mousePos, boundsU)) + { + mouseOverU = true; + + if (!placedU && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + if ((boundsU.y > GetScreenHeight()/2 - 110) && ((boundsU.y + boundsU.height) < (GetScreenHeight()/2 + 100))) + { + placedU = true; + } + } + } + else mouseOverU = false; + + if (CheckCollisionPointRec(mousePos, boundsO)) + { + mouseOverO = true; + + if (!placedO && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) boundsO.y += 100; + + if (boundsO.y >= (GetScreenHeight()/2 - 130)) placedO = true; + } + else mouseOverO = false; + + if (placedO && placedU) + { + done = true; + PlaySound(levelWin); + } + } + + if (done && !levelFinished) + { + levelTimeSec = framesCounter/60; + levelFinished = true; + framesCounter = 0; + } + + if (levelFinished) + { + framesCounter++; + + if ((framesCounter > 30) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; + } +} + +// Level00 Screen Draw logic +void DrawLevel00Screen(void) +{ + // Draw Level00 screen + DrawText("U", boundsU.x, boundsU.y + 10, 160, GRAY); + DrawText("J", GetScreenWidth()/2 - MeasureText("JUST DO", 160)/2, GetScreenHeight()/2 - 80, 160, GRAY); + DrawText("ST D", GetScreenWidth()/2 - MeasureText("JUST DO", 160)/2 + 210, GetScreenHeight()/2 - 80, 160, GRAY); + DrawText("O", boundsO.x, boundsO.y + 10, 160, GRAY); + + DrawText("by RAMON SANTAMARIA (@raysan5)", 370, GetScreenHeight()/2 + 100, 30, Fade(LIGHTGRAY, 0.4f)); + + if (mouseOverU && !placedU) DrawRectangleLines(boundsU.x - 20, boundsU.y, boundsU.width, boundsU.height, Fade(LIGHTGRAY, 0.8f)); + //DrawRectangleBordersRec(boundsU, -20, 0, 20, Fade(RED, 0.3f)); + + if (mouseOverO && !placedO) DrawRectangleLines(boundsO.x - 20, boundsO.y, boundsO.width, boundsO.height, Fade(LIGHTGRAY, 0.8f)); + //DrawRectangleBordersRec(boundsO, -20, 0, 20, Fade(RED, 0.3f)); + + if (levelFinished) + { + DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); + DrawText("LEVEL 00", GetScreenWidth()/2 - MeasureText("LEVEL 00", 30)/2, 20, 30, GRAY); + DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); + } + else DrawText("LEVEL 00", GetScreenWidth()/2 - MeasureText("LEVEL 00", 30)/2, 20, 30, LIGHTGRAY); +} + +// Level00 Screen Unload logic +void UnloadLevel00Screen(void) +{ + // TODO: Unload Level00 screen variables here! +} + +// Level00 Screen should finish? +int FinishLevel00Screen(void) +{ + return finishScreen; +} + +void DrawRectangleBordersRec(Rectangle rec, int offsetX, int offsetY, int borderSize, Color col) +{ + DrawRectangle(rec.x + offsetX, rec.y + offsetY, rec.width, borderSize, col); + DrawRectangle(rec.x + offsetX, rec.y + borderSize + offsetY, borderSize, rec.height - borderSize*2, col); + DrawRectangle(rec.x + rec.width - borderSize + offsetX, rec.y + borderSize + offsetY, borderSize, rec.height - borderSize*2, col); + DrawRectangle(rec.x + offsetX, rec.y + rec.height - borderSize + offsetY, rec.width, borderSize, col); +} \ No newline at end of file diff --git a/games/just_do/screens/screen_level01.c b/games/just_do/screens/screen_level01.c new file mode 100644 index 00000000..cedcb2e0 --- /dev/null +++ b/games/just_do/screens/screen_level01.c @@ -0,0 +1,163 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Level01 Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Level01 screen global variables +static int framesCounter; +static int finishScreen; + +static Rectangle innerLeftRec, outerLeftRec; +static Rectangle innerRightRec, outerRightRec; + +static bool done = false; +static int levelTimeSec = 0; +static bool levelFinished = false; + +//---------------------------------------------------------------------------------- +// Level01 Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Level01 Screen Initialization logic +void InitLevel01Screen(void) +{ + // Initialize Level01 screen variables here! + framesCounter = 0; + finishScreen = 0; + + outerLeftRec = (Rectangle){ 0, 0, GetScreenWidth()/2, GetScreenHeight() }; + outerRightRec = (Rectangle){ GetScreenWidth()/2, 0, GetScreenWidth()/2, GetScreenHeight() }; + + innerLeftRec = (Rectangle){ GetScreenWidth()/4 - 200, GetScreenHeight()/2 - 200, 400, 400}; + innerRightRec = (Rectangle){ GetScreenWidth()/2 + GetScreenWidth()/4 - 200, GetScreenHeight()/2 - 200, 400, 400}; +} + +// Level01 Screen Update logic +void UpdateLevel01Screen(void) +{ + // Update Level01 screen + framesCounter++; + + if (!done) + { + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + if (CheckCollisionPointRec(GetMousePosition(), innerLeftRec)) + { + if (innerRightRec.width > 0) + { + innerRightRec.x += 20; + innerRightRec.y += 20; + innerRightRec.width -= 40; + innerRightRec.height -= 40; + } + } + else if (CheckCollisionPointRec(GetMousePosition(), innerRightRec)) + { + if (innerLeftRec.width > 0) + { + innerLeftRec.x += 20; + innerLeftRec.y += 20; + innerLeftRec.width -= 40; + innerLeftRec.height -= 40; + } + } + else if (CheckCollisionPointRec(GetMousePosition(), outerLeftRec)) + { + innerLeftRec.x -= 20; + innerLeftRec.y -= 20; + innerLeftRec.width += 40; + innerLeftRec.height += 40; + } + else if (CheckCollisionPointRec(GetMousePosition(), outerRightRec)) + { + innerRightRec.x -= 20; + innerRightRec.y -= 20; + innerRightRec.width += 40; + innerRightRec.height += 40; + } + } + + + if (((innerRightRec.width == 0) && (innerLeftRec.height >= GetScreenHeight())) || + ((innerLeftRec.width == 0) && (innerRightRec.height >= GetScreenHeight()))) + { + done = true; + PlaySound(levelWin); + } + } + + if (done && !levelFinished) + { + levelTimeSec = framesCounter/60; + levelFinished = true; + framesCounter = 0; + } + + if (levelFinished) + { + framesCounter++; + + if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; + } +} + +// Level01 Screen Draw logic +void DrawLevel01Screen(void) +{ + // Draw Level01 screen + if (!levelFinished) DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), LIGHTGRAY); + else DrawRectangle(60, 60, GetScreenWidth() - 120, GetScreenHeight() - 120, LIGHTGRAY); + + DrawRectangleRec(outerLeftRec, GRAY); + DrawRectangleRec(innerLeftRec, RAYWHITE); + DrawRectangleRec(outerRightRec, RAYWHITE); + DrawRectangleRec(innerRightRec, GRAY); + + if (levelFinished) + { + DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); + DrawText("LEVEL 01", GetScreenWidth()/2 - MeasureText("LEVEL 01", 30)/2, 20, 30, GRAY); + DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); + } + else DrawText("LEVEL 01", GetScreenWidth()/2 - MeasureText("LEVEL 01", 30)/2, 20, 30, LIGHTGRAY); +} + +// Level01 Screen Unload logic +void UnloadLevel01Screen(void) +{ + // TODO: Unload Level01 screen variables here! +} + +// Level01 Screen should finish? +int FinishLevel01Screen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/just_do/screens/screen_level02.c b/games/just_do/screens/screen_level02.c new file mode 100644 index 00000000..ccfa355e --- /dev/null +++ b/games/just_do/screens/screen_level02.c @@ -0,0 +1,170 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Level02 Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +#include + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Level02 screen global variables +static int framesCounter; +static int finishScreen; + +static Vector2 bouncingBallPos; +static float bouncingBallRadius = 40; +static Vector2 bouncingBallSpeed; + +static Vector2 holeCirclePos; +static float holeCircleRadius = 50; + +static bool ballOnHole = false; + +static int levelTimeSec = 0; +static bool levelFinished = false; + +//---------------------------------------------------------------------------------- +// Level02 Screen Functions Definition +//---------------------------------------------------------------------------------- +float Vector2Distance(Vector2 v1, Vector2 v2); + +// Level02 Screen Initialization logic +void InitLevel02Screen(void) +{ + // TODO: Initialize Level02 screen variables here! + framesCounter = 0; + finishScreen = 0; + + bouncingBallPos = (Vector2){ 120, 80 }; + bouncingBallSpeed = (Vector2){ 6, 8 }; + holeCirclePos = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 }; +} + +// Level02 Screen Update logic +void UpdateLevel02Screen(void) +{ + // Update Level02 screen + framesCounter++; + + if (!ballOnHole) + { + bouncingBallPos.x += bouncingBallSpeed.x; + bouncingBallPos.y += bouncingBallSpeed.y; + + if (((bouncingBallPos.x - bouncingBallRadius) <= 0) || ((bouncingBallPos.x + bouncingBallRadius) >= GetScreenWidth())) bouncingBallSpeed.x *= -1; + if (((bouncingBallPos.y - bouncingBallRadius) <= 0) || ((bouncingBallPos.y + bouncingBallRadius) >= GetScreenHeight())) bouncingBallSpeed.y *= -1; + + Vector2 mousePos = GetMousePosition(); + + if (CheckCollisionPointCircle(mousePos, bouncingBallPos, 120)) + { + bouncingBallPos.x = GetRandomValue(80, 1200); + bouncingBallPos.y = GetRandomValue(80, 650); + } + + if (CheckCollisionPointCircle(mousePos, holeCirclePos, 120)) + { + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + { + holeCirclePos = mousePos; + + if ((holeCirclePos.x - holeCircleRadius) <= 0) holeCirclePos.x = holeCircleRadius; + else if ((holeCirclePos.x + holeCircleRadius) >= GetScreenWidth()) holeCirclePos.x = GetScreenWidth() - holeCircleRadius; + + if ((holeCirclePos.y - holeCircleRadius) <= 0) holeCirclePos.y = holeCircleRadius; + else if ((holeCirclePos.y + holeCircleRadius) >= GetScreenHeight()) holeCirclePos.y = GetScreenHeight() - holeCircleRadius; + } + } + + if (Vector2Distance(bouncingBallPos, holeCirclePos) < 20) + { + ballOnHole = true; + PlaySound(levelWin); + } + } + + if (ballOnHole && !levelFinished) + { + levelTimeSec = framesCounter/60; + levelFinished = true; + framesCounter = 0; + } + + if (levelFinished) + { + framesCounter++; + + if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; + } +} + +// Level02 Screen Draw logic +void DrawLevel02Screen(void) +{ + // Draw Level02 screen + + DrawCircleV(holeCirclePos, holeCircleRadius, LIGHTGRAY); + DrawCircleV(bouncingBallPos, bouncingBallRadius, DARKGRAY); + + DrawCircleLines(bouncingBallPos.x, bouncingBallPos.y, 120, Fade(LIGHTGRAY, 0.8f)); + + + + if (levelFinished) + { + DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); + DrawText("LEVEL 02", GetScreenWidth()/2 - MeasureText("LEVEL 02", 30)/2, 20, 30, GRAY); + DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); + } + else DrawText("LEVEL 02", GetScreenWidth()/2 - MeasureText("LEVEL 02", 30)/2, 20, 30, LIGHTGRAY); +} + +// Level02 Screen Unload logic +void UnloadLevel02Screen(void) +{ + // TODO: Unload Level02 screen variables here! +} + +// Level02 Screen should finish? +int FinishLevel02Screen(void) +{ + return finishScreen; +} + +// Calculate distance between two points +float Vector2Distance(Vector2 v1, Vector2 v2) +{ + float result; + + float dx = v2.x - v1.x; + float dy = v2.y - v1.y; + + result = sqrt(dx*dx + dy*dy); + + return result; +} \ No newline at end of file diff --git a/games/just_do/screens/screen_level03.c b/games/just_do/screens/screen_level03.c new file mode 100644 index 00000000..e8732414 --- /dev/null +++ b/games/just_do/screens/screen_level03.c @@ -0,0 +1,134 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Level03 Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Level03 screen global variables +static int framesCounter; +static int finishScreen; + +static Rectangle holeRec, pieceRec; +static bool showPiece = false; +static bool pieceSelected = false; + +static bool done = false; +static int levelTimeSec = 0; +static bool levelFinished = false; + +//---------------------------------------------------------------------------------- +// Level03 Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Level03 Screen Initialization logic +void InitLevel03Screen(void) +{ + // Initialize Level03 screen variables here! + framesCounter = 0; + finishScreen = 0; + + holeRec = (Rectangle){ GetScreenWidth()/2 - 50, GetScreenHeight()/2 - 50, 100, 100 }; + pieceRec = (Rectangle){ 200, 400, 100, 100 }; +} + +// Level03 Screen Update logic +void UpdateLevel03Screen(void) +{ + // Update Level03 screen variables here! + framesCounter++; + + Vector2 mousePos = GetMousePosition(); + + if (!done) + { + if (CheckCollisionPointRec(mousePos, holeRec)) showPiece = true; + else showPiece = false; + + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + { + if (CheckCollisionPointRec(mousePos, pieceRec)) + { + pieceSelected = true; + + pieceRec.x = ((int)mousePos.x - 50); + pieceRec.y = ((int)mousePos.y - 50); + } + } + + if ((pieceRec.x == holeRec.x) && !(CheckCollisionPointRec(mousePos, holeRec))) + { + done = true; + PlaySound(levelWin); + } + } + + if (done && !levelFinished) + { + levelTimeSec = framesCounter/60; + levelFinished = true; + framesCounter = 0; + } + + if (levelFinished) + { + framesCounter++; + + if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; + } +} + +// Level03 Screen Draw logic +void DrawLevel03Screen(void) +{ + // Draw Level03 screen + DrawRectangleRec(holeRec, GRAY); + DrawRectangleRec(pieceRec, RAYWHITE); + + if (showPiece) DrawRectangleLines(pieceRec.x, pieceRec.y, pieceRec.width, pieceRec.height, Fade(LIGHTGRAY, 0.8f)); + + if (levelFinished) + { + DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); + DrawText("LEVEL 03", GetScreenWidth()/2 - MeasureText("LEVEL 03", 30)/2, 20, 30, GRAY); + DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); + } + else DrawText("LEVEL 03", GetScreenWidth()/2 - MeasureText("LEVEL 03", 30)/2, 20, 30, LIGHTGRAY); +} + +// Level03 Screen Unload logic +void UnloadLevel03Screen(void) +{ + // TODO: Unload Level03 screen variables here! +} + +// Level03 Screen should finish? +int FinishLevel03Screen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/just_do/screens/screen_level04.c b/games/just_do/screens/screen_level04.c new file mode 100644 index 00000000..c4e4e2c0 --- /dev/null +++ b/games/just_do/screens/screen_level04.c @@ -0,0 +1,147 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Level04 Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Level04 screen global variables +static int framesCounter; +static int finishScreen; + +static Vector2 circlesCenter; +static float innerCircleRadius = 40; +static float outerCircleRadius = 300; + +static bool done = false; +static int levelTimeSec = 0; +static bool levelFinished = false; + +//---------------------------------------------------------------------------------- +// Level04 Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Level04 Screen Initialization logic +void InitLevel04Screen(void) +{ + // Initialize Level04 screen variables here! + framesCounter = 0; + finishScreen = 0; + + circlesCenter = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 }; +} + +// Level04 Screen Update logic +void UpdateLevel04Screen(void) +{ + // Update Level04 screen variables here! + framesCounter++; + + if (!done) + { + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + { + if (CheckCollisionPointCircle(GetMousePosition(), circlesCenter, innerCircleRadius)) + { + innerCircleRadius += 2; + } + else if (CheckCollisionPointCircle(GetMousePosition(), circlesCenter, outerCircleRadius)) + { + outerCircleRadius += 2; + } + else + { + outerCircleRadius -= 2; + + if (outerCircleRadius <= 260) outerCircleRadius = 260; + } + } + else + { + if (!done) + { + innerCircleRadius -= 2; + if (outerCircleRadius > 300) outerCircleRadius -= 2; + } + } + + if (innerCircleRadius >= 270) innerCircleRadius = 270; + else if (innerCircleRadius <= 40) innerCircleRadius = 40; + + if (outerCircleRadius >= 600) outerCircleRadius = 600; + + if (innerCircleRadius >= outerCircleRadius) + { + done = true; + PlaySound(levelWin); + } + } + + if (done && !levelFinished) + { + levelTimeSec = framesCounter/60; + levelFinished = true; + framesCounter = 0; + } + + if (levelFinished) + { + framesCounter++; + + if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; + } +} + +// Level04 Screen Draw logic +void DrawLevel04Screen(void) +{ + // Draw Level04 screen here! + //DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), GRAY); + DrawCircleV(circlesCenter, outerCircleRadius, GRAY); + DrawCircleV(circlesCenter, innerCircleRadius, RAYWHITE); + + if (levelFinished) + { + DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); + DrawText("LEVEL 04", GetScreenWidth()/2 - MeasureText("LEVEL 04", 30)/2, 20, 30, GRAY); + DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); + } + else DrawText("LEVEL 04", GetScreenWidth()/2 - MeasureText("LEVEL 04", 30)/2, 20, 30, LIGHTGRAY); +} + +// Level04 Screen Unload logic +void UnloadLevel04Screen(void) +{ + // TODO: Unload Level04 screen variables here! +} + +// Level04 Screen should finish? +int FinishLevel04Screen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/just_do/screens/screen_level05.c b/games/just_do/screens/screen_level05.c new file mode 100644 index 00000000..f2e4d852 --- /dev/null +++ b/games/just_do/screens/screen_level05.c @@ -0,0 +1,185 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Level05 Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +#define NUM_CIRCLES 10 + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Level05 screen global variables +static int framesCounter; +static int finishScreen; + +static Vector2 circleCenter; +static float circleRadius[NUM_CIRCLES]; +static bool circleLocked[NUM_CIRCLES]; +static Color circleColor[NUM_CIRCLES]; + +static bool done = false; +static int levelTimeSec = 0; +static bool levelFinished = false; + +//---------------------------------------------------------------------------------- +// Level05 Screen Functions Definition +//---------------------------------------------------------------------------------- +static bool CheckColor(Color col1, Color col2); + +// Level05 Screen Initialization logic +void InitLevel05Screen(void) +{ + // Initialize Level05 screen variables here! + framesCounter = 0; + finishScreen = 0; + + circleCenter = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 }; + + for (int i = 0; i < NUM_CIRCLES; i++) + { + circleRadius[i] = 760/NUM_CIRCLES*(NUM_CIRCLES - i); + circleLocked[i] = false; + } + + // That's a dirty hack to give sonme coherence to this puzzle... + circleColor[9] = GRAY; + circleColor[8] = RAYWHITE; + circleColor[7] = RAYWHITE; + circleColor[6] = GRAY; + circleColor[5] = RAYWHITE; + circleColor[4] = GRAY; + circleColor[3] = GRAY; + circleColor[2] = GRAY; + circleColor[1] = RAYWHITE; + circleColor[0] = GRAY; +} + +// Level05 Screen Update logic +void UpdateLevel05Screen(void) +{ + // Update Level05 screen variables here! + framesCounter++; + + if (!done) + { + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + for (int i = NUM_CIRCLES - 1; i >= 0; i--) + { + if (CheckCollisionPointCircle(GetMousePosition(), circleCenter, circleRadius[i])) + { + if (i == 0) + { + if (CheckColor(circleColor[8], GRAY)) circleColor[8] = RAYWHITE; + else circleColor[8] = GRAY; + } + else if (i == 2) + { + if (CheckColor(circleColor[5], GRAY)) circleColor[5] = RAYWHITE; + else circleColor[5] = GRAY; + } + else if (i == 3) + { + if (CheckColor(circleColor[6], GRAY)) circleColor[6] = RAYWHITE; + else circleColor[6] = GRAY; + } + else + { + if (CheckColor(circleColor[i], GRAY)) circleColor[i] = RAYWHITE; + else circleColor[i] = GRAY; + } + return; + } + } + } + + // Check all cicles done + for (int i = 0; i < NUM_CIRCLES; i++) + { + done = true; + + if (CheckColor(circleColor[i], RAYWHITE)) + { + done = false; + return; + } + + //if (done) PlaySound(levelWin); + } + } + + if (done && !levelFinished) + { + levelTimeSec = framesCounter/60; + levelFinished = true; + framesCounter = 0; + } + + if (levelFinished) + { + framesCounter++; + + if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; + } +} + +// Level05 Screen Draw logic +void DrawLevel05Screen(void) +{ + // Draw Level05 screen + for (int i = 0; i < NUM_CIRCLES; i++) + { + DrawPoly(circleCenter, 64, circleRadius[i], 0.0f, circleColor[i]); + } + + + + if (levelFinished) + { + DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); + DrawText("LEVEL 05", GetScreenWidth()/2 - MeasureText("LEVEL 05", 30)/2, 20, 30, GRAY); + DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); + } + else DrawText("LEVEL 05", GetScreenWidth()/2 - MeasureText("LEVEL 05", 30)/2, 20, 30, LIGHTGRAY); +} + +// Level05 Screen Unload logic +void UnloadLevel05Screen(void) +{ + // TODO: Unload Level05 screen variables here! +} + +// Level05 Screen should finish? +int FinishLevel05Screen(void) +{ + return finishScreen; +} + +static bool CheckColor(Color col1, Color col2) +{ + return ((col1.r == col2.r) && (col1.g == col2.g) && (col1.b == col2.b) && (col1.a == col2.a)); +} \ No newline at end of file diff --git a/games/just_do/screens/screen_level06.c b/games/just_do/screens/screen_level06.c new file mode 100644 index 00000000..b5881db4 --- /dev/null +++ b/games/just_do/screens/screen_level06.c @@ -0,0 +1,156 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Level06 Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Level06 screen global variables +static int framesCounter; +static int finishScreen; + +static Rectangle centerRec; + +static Rectangle movingRecs[4]; +static int speedRecs[4]; +static bool stoppedRec[4]; +static int mouseOverNum = -1; + +static bool done = false; +static int levelTimeSec = 0; +static bool levelFinished = false; + +//---------------------------------------------------------------------------------- +// Level06 Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Level06 Screen Initialization logic +void InitLevel06Screen(void) +{ + // Initialize Level06 screen variables here! + framesCounter = 0; + finishScreen = 0; + + centerRec = (Rectangle){ GetScreenWidth()/2 - 100, 0, 200, GetScreenHeight() }; + + for (int i = 0; i < 4; i++) + { + movingRecs[i] = (Rectangle){ GetRandomValue(0, 5)*150, (i*150) + 90, 100, 100 }; + stoppedRec[i] = false; + speedRecs[i] = GetRandomValue(4, 8); + } +} + +// Level06 Screen Update logic +void UpdateLevel06Screen(void) +{ + // Update Level06 screen variables here! + framesCounter++; + + if (!done) + { + for (int i = 0; i < 4; i++) + { + if (!stoppedRec[i]) movingRecs[i].x += speedRecs[i]; + + if (movingRecs[i].x >= GetScreenWidth()) movingRecs[i].x = -movingRecs[i].width; + + if (CheckCollisionPointRec(GetMousePosition(), movingRecs[i])) + { + mouseOverNum = i; + + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + if (i == 0) stoppedRec[3] = !stoppedRec[3]; + else if (i == 1) stoppedRec[2] = !stoppedRec[2]; + else if (i == 2) stoppedRec[0] = !stoppedRec[0]; + else if (i == 3) stoppedRec[1] = !stoppedRec[1]; + } + } + } + + // Check if all boxes are aligned + if (((movingRecs[0].x > centerRec.x) && ((movingRecs[0].x + movingRecs[0].width) < (centerRec.x + centerRec.width))) && + ((movingRecs[1].x > centerRec.x) && ((movingRecs[1].x + movingRecs[1].width) < (centerRec.x + centerRec.width))) && + ((movingRecs[2].x > centerRec.x) && ((movingRecs[2].x + movingRecs[2].width) < (centerRec.x + centerRec.width))) && + ((movingRecs[3].x > centerRec.x) && ((movingRecs[3].x + movingRecs[3].width) < (centerRec.x + centerRec.width)))) + { + done = true; + PlaySound(levelWin); + } + } + + + if (done && !levelFinished) + { + levelTimeSec = framesCounter/60; + levelFinished = true; + framesCounter = 0; + } + + if (levelFinished) + { + framesCounter++; + + if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; + } +} + +// Level06 Screen Draw logic +void DrawLevel06Screen(void) +{ + // Draw Level06 screen + DrawRectangleRec(centerRec, LIGHTGRAY); + + for (int i = 0; i < 4; i++) + { + DrawRectangleRec(movingRecs[i], GRAY); + } + + if (!done & (mouseOverNum >= 0)) DrawRectangleLines(movingRecs[mouseOverNum].x - 5, movingRecs[mouseOverNum].y - 5, movingRecs[mouseOverNum].width + 10, movingRecs[mouseOverNum].height + 10, Fade(LIGHTGRAY, 0.8f)); + + if (levelFinished) + { + DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); + DrawText("LEVEL 06", GetScreenWidth()/2 - MeasureText("LEVEL 06", 30)/2, 20, 30, GRAY); + DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); + } + else DrawText("LEVEL 06", GetScreenWidth()/2 - MeasureText("LEVEL 06", 30)/2, 20, 30, LIGHTGRAY); +} + +// Level06 Screen Unload logic +void UnloadLevel06Screen(void) +{ + // TODO: Unload Level06 screen variables here! +} + +// Level06 Screen should finish? +int FinishLevel06Screen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/just_do/screens/screen_level07.c b/games/just_do/screens/screen_level07.c new file mode 100644 index 00000000..d305b025 --- /dev/null +++ b/games/just_do/screens/screen_level07.c @@ -0,0 +1,178 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Level07 Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Level07 screen global variables +static int framesCounter; +static int finishScreen; + +static Vector2 leftCirclePos, middleCirclePos, rightCirclePos; +static Vector2 leftBtnPos, middleBtnPos, rightBtnPos; +static float circleRadius = 100; +static float btnRadius = 80; + +static bool leftCircleActive, middleCircleActive, rightCircleActive; +static Color leftCircleColor, middleCircleColor, rightCircleColor; + +static bool done = false; +static int levelTimeSec = 0; +static bool levelFinished = false; + +//---------------------------------------------------------------------------------- +// Level07 Screen Functions Definition +//---------------------------------------------------------------------------------- +static bool CheckColor(Color col1, Color col2); + +// Level07 Screen Initialization logic +void InitLevel07Screen(void) +{ + // Initialize Level07 screen variables here! + framesCounter = 0; + finishScreen = 0; + + leftCirclePos = (Vector2){ GetScreenWidth()/2 - 340, GetScreenHeight()/2 - 100 }; + middleCirclePos = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 - 100 }; + rightCirclePos = (Vector2){ GetScreenWidth()/2 + 340, GetScreenHeight()/2 - 100 }; + + leftBtnPos = (Vector2){ GetScreenWidth()/2 - 340, GetScreenHeight()/2 + 120 }; + middleBtnPos = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 + 120 }; + rightBtnPos = (Vector2){ GetScreenWidth()/2 + 340, GetScreenHeight()/2 + 120 }; + + leftCircleActive = false; + middleCircleActive = true; + rightCircleActive = false; + + leftCircleColor = GRAY; + middleCircleColor = GRAY; + rightCircleColor = GRAY; +} + +// Level07 Screen Update logic +void UpdateLevel07Screen(void) +{ + // Update Level07 screen variables here! + framesCounter++; + + if (!done) + { + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + if (CheckCollisionPointCircle(GetMousePosition(), leftBtnPos, btnRadius)) leftCircleActive = !leftCircleActive; + else if (CheckCollisionPointCircle(GetMousePosition(), middleBtnPos, btnRadius)) middleCircleActive = !middleCircleActive; + else if (CheckCollisionPointCircle(GetMousePosition(), rightBtnPos, btnRadius)) rightCircleActive = !rightCircleActive; + + if (rightCircleActive && CheckCollisionPointCircle(GetMousePosition(), leftCirclePos, circleRadius)) + { + if (CheckColor(leftCircleColor, GRAY)) leftCircleColor = LIGHTGRAY; + else leftCircleColor = GRAY; + } + + if (middleCircleActive && CheckCollisionPointCircle(GetMousePosition(), middleCirclePos, circleRadius)) + { + if (CheckColor(middleCircleColor, GRAY)) middleCircleColor = LIGHTGRAY; + else middleCircleColor = GRAY; + } + + if (rightCircleActive && leftCircleActive && CheckCollisionPointCircle(GetMousePosition(), rightCirclePos, circleRadius)) + { + if (CheckColor(rightCircleColor, GRAY)) rightCircleColor = LIGHTGRAY; + else rightCircleColor = GRAY; + } + } + + // Check all cicles done + if (CheckColor(leftCircleColor, LIGHTGRAY) && CheckColor(middleCircleColor, LIGHTGRAY) && CheckColor(rightCircleColor, LIGHTGRAY) && + !leftCircleActive && !middleCircleActive && !rightCircleActive) + { + done = true; + PlaySound(levelWin); + } + } + + if (done && !levelFinished) + { + levelTimeSec = framesCounter/60; + levelFinished = true; + framesCounter = 0; + } + + if (levelFinished) + { + framesCounter++; + + if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; + } +} + +// Level07 Screen Draw logic +void DrawLevel07Screen(void) +{ + // Draw Level07 screen here! + DrawCircleV(leftCirclePos, circleRadius, leftCircleColor); + DrawCircleV(middleCirclePos, circleRadius, middleCircleColor); + DrawCircleV(rightCirclePos, circleRadius, rightCircleColor); + + if (leftCircleActive) DrawCircleV(leftBtnPos, btnRadius, GRAY); + else DrawCircleV(leftBtnPos, btnRadius, LIGHTGRAY); + + if (middleCircleActive) DrawCircleV(middleBtnPos, btnRadius, GRAY); + else DrawCircleV(middleBtnPos, btnRadius, LIGHTGRAY); + + if (rightCircleActive) DrawCircleV(rightBtnPos, btnRadius, GRAY); + else DrawCircleV(rightBtnPos, btnRadius, LIGHTGRAY); + + + + if (levelFinished) + { + DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); + DrawText("LEVEL 07", GetScreenWidth()/2 - MeasureText("LEVEL 07", 30)/2, 20, 30, GRAY); + DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); + } + else DrawText("LEVEL 07", GetScreenWidth()/2 - MeasureText("LEVEL 07", 30)/2, 20, 30, LIGHTGRAY); +} + +// Level07 Screen Unload logic +void UnloadLevel07Screen(void) +{ + // TODO: Unload Level07 screen variables here! +} + +// Level07 Screen should finish? +int FinishLevel07Screen(void) +{ + return finishScreen; +} + +static bool CheckColor(Color col1, Color col2) +{ + return ((col1.r == col2.r) && (col1.g == col2.g) && (col1.b == col2.b) && (col1.a == col2.a)); +} \ No newline at end of file diff --git a/games/just_do/screens/screen_level08.c b/games/just_do/screens/screen_level08.c new file mode 100644 index 00000000..4cb0443b --- /dev/null +++ b/games/just_do/screens/screen_level08.c @@ -0,0 +1,157 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Level08 Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Level08 screen global variables +static int framesCounter; +static int finishScreen; + +static Rectangle leftColumnRec, middleColumnRec, rightColumnRec; +static Rectangle movingBox; +static int moveSpeed = 4; + +static bool leftColumnActive, middleColumnActive, rightColumnActive; + +static bool done = false; +static int levelTimeSec = 0; +static bool levelFinished = false; + +//---------------------------------------------------------------------------------- +// Level08 Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Level08 Screen Initialization logic +void InitLevel08Screen(void) +{ + // TODO: Initialize Level08 screen variables here! + framesCounter = 0; + finishScreen = 0; + + movingBox = (Rectangle){ 20, GetScreenHeight()/2 - 20, 40, 40 }; + + leftColumnRec = (Rectangle){ 240, 0, 100, GetScreenHeight() }; + middleColumnRec = (Rectangle){ GetScreenWidth()/2 - 50, 0, 100, GetScreenHeight() }; + rightColumnRec = (Rectangle){ 920, 0, 100, GetScreenHeight() }; + + leftColumnActive = true; + middleColumnActive = false; + rightColumnActive = true; +} + +// Level08 Screen Update logic +void UpdateLevel08Screen(void) +{ + // Update Level08 screen variables here! + framesCounter++; + + if (!done) + { + movingBox.x += moveSpeed; + + if (movingBox.x <= 0) moveSpeed *= -1; + + if ((leftColumnActive && (CheckCollisionRecs(leftColumnRec, movingBox))) || + (middleColumnActive && (CheckCollisionRecs(middleColumnRec, movingBox))) || + (rightColumnActive && (CheckCollisionRecs(rightColumnRec, movingBox)))) moveSpeed *= -1; + + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + if (CheckCollisionPointRec(GetMousePosition(), leftColumnRec)) + { + middleColumnActive = false; + rightColumnActive = true; + } + else if (CheckCollisionPointRec(GetMousePosition(), middleColumnRec)) + { + rightColumnActive = false; + leftColumnActive = true; + } + else if (CheckCollisionPointRec(GetMousePosition(), rightColumnRec)) + { + leftColumnActive = false; + middleColumnActive = true; + } + } + + if (movingBox.x >= 1100) + { + done = true; + PlaySound(levelWin); + } + } + + if (done && !levelFinished) + { + levelTimeSec = framesCounter/60; + levelFinished = true; + framesCounter = 0; + } + + if (levelFinished) + { + framesCounter++; + + if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; + } +} + +// Level08 Screen Draw logic +void DrawLevel08Screen(void) +{ + // Draw Level08 screen + DrawRectangle(1100, GetScreenHeight()/2 - 20, 40, 40, GRAY); + + DrawRectangleRec(movingBox, LIGHTGRAY); + + if (leftColumnActive) DrawRectangleRec(leftColumnRec, GRAY); + if (middleColumnActive) DrawRectangleRec(middleColumnRec, GRAY); + if (rightColumnActive) DrawRectangleRec(rightColumnRec, GRAY); + + if (levelFinished) + { + DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); + DrawText("LEVEL 08", GetScreenWidth()/2 - MeasureText("LEVEL 08", 30)/2, 20, 30, GRAY); + DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); + } + else DrawText("LEVEL 08", GetScreenWidth()/2 - MeasureText("LEVEL 08", 30)/2, 20, 30, LIGHTGRAY); +} + +// Level08 Screen Unload logic +void UnloadLevel08Screen(void) +{ + // TODO: Unload Level08 screen variables here! +} + +// Level08 Screen should finish? +int FinishLevel08Screen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/just_do/screens/screen_level09.c b/games/just_do/screens/screen_level09.c new file mode 100644 index 00000000..d20f4bfb --- /dev/null +++ b/games/just_do/screens/screen_level09.c @@ -0,0 +1,199 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Level09 Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +#define NUM_BOXES 21 + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Level09 screen global variables +static int framesCounter; +static int finishScreen; + +static Rectangle bwRecs[NUM_BOXES]; +static Color bwColors[NUM_BOXES]; +static bool activated[NUM_BOXES]; +static int resetCounter = 0; +static bool enableCounter = 0; + +static bool done = false; +static int levelTimeSec = 0; +static bool levelFinished = false; + +//---------------------------------------------------------------------------------- +// Level09 Screen Functions Definition +//---------------------------------------------------------------------------------- +static bool CheckColor(Color col1, Color col2); + +// Level09 Screen Initialization logic +void InitLevel09Screen(void) +{ + // Initialize Level09 screen variables here! + framesCounter = 0; + finishScreen = 0; + + for (int i = 0; i < NUM_BOXES; i++) + { + bwRecs[i].x = GetScreenWidth()/7*(i%7); + bwRecs[i].y = GetScreenHeight()/3*(i/7); + bwRecs[i].width = GetScreenWidth()/7; + bwRecs[i].height = GetScreenHeight()/3; + + activated[i] = false; + + if (i%2 == 0) bwColors[i] = LIGHTGRAY; + else bwColors[i] = GRAY; + } + + bwColors[10] = RAYWHITE; +} + +// Level09 Screen Update logic +void UpdateLevel09Screen(void) +{ + // Update Level09 screen variables here! + framesCounter++; + if (enableCounter) resetCounter++; + + if (!done) + { + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + for (int i = 0; i < NUM_BOXES; i++) + { + if (CheckCollisionPointRec(GetMousePosition(), bwRecs[i])) + { + if (i == 10) + { + if (CheckColor(bwColors[i], RAYWHITE)) + { + bwColors[i] = LIGHTGRAY; + enableCounter = true; + resetCounter = 0; + activated[1] = true; + } + else + { + bwColors[i] = RAYWHITE; + enableCounter = false; + resetCounter = 5*60; + + for (int i = 0; i < NUM_BOXES; i++) activated[i] = false; + } + } + else if ((i%2 == 1) && enableCounter) + { + if (activated[i]) + { + bwColors[i] = LIGHTGRAY; + if (i != 19) activated[i + 2] = true; + } + } + } + } + } + + if (resetCounter > (4*60 + 10)) + { + for (int i = 0; i < NUM_BOXES; i++) + { + if (i%2 == 0) bwColors[i] = LIGHTGRAY; + else bwColors[i] = GRAY; + + activated[i] = false; + } + + bwColors[10] = RAYWHITE; + enableCounter = false; + resetCounter = 0; + } + + for (int i = 0; i < NUM_BOXES; i++) + { + done = true; + + if (!CheckColor(bwColors[i], LIGHTGRAY)) + { + done = false; + return; + } + + //if (done) PlaySound(levelWin); + } + } + + if (done && !levelFinished) + { + levelTimeSec = framesCounter/60; + levelFinished = true; + framesCounter = 0; + } + + if (levelFinished) + { + framesCounter++; + + if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; + } +} + +// Level09 Screen Draw logic +void DrawLevel09Screen(void) +{ + // Draw Level09 screen + for (int i = 0; i < NUM_BOXES; i++) + { + DrawRectangleRec(bwRecs[i], bwColors[i]); + } + + if (levelFinished) + { + DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(RAYWHITE, 0.6f)); + DrawText("LEVEL 09", GetScreenWidth()/2 - MeasureText("LEVEL 09", 30)/2, 20, 30, GRAY); + DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); + } + else DrawText("LEVEL 09", GetScreenWidth()/2 - MeasureText("LEVEL 09", 30)/2, 20, 30, LIGHTGRAY); +} + +// Level09 Screen Unload logic +void UnloadLevel09Screen(void) +{ + // TODO: Unload Level09 screen variables here! +} + +// Level09 Screen should finish? +int FinishLevel09Screen(void) +{ + return finishScreen; +} + +static bool CheckColor(Color col1, Color col2) +{ + return ((col1.r == col2.r) && (col1.g == col2.g) && (col1.b == col2.b) && (col1.a == col2.a)); +} \ No newline at end of file diff --git a/games/just_do/screens/screen_level10.c b/games/just_do/screens/screen_level10.c new file mode 100644 index 00000000..33806006 --- /dev/null +++ b/games/just_do/screens/screen_level10.c @@ -0,0 +1,153 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Level10 Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Level10 screen global variables +static int framesCounter; +static int finishScreen; + +static Rectangle leftColumnRec, middleColumnRec, rightColumnRec; +static Rectangle movingBox; +static int moveSpeed = 4; + +static bool leftColumnActive, middleColumnActive, rightColumnActive; + +static bool done = false; +static int levelTimeSec = 0; +static bool levelFinished = false; + +//---------------------------------------------------------------------------------- +// Level10 Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Level10 Screen Initialization logic +void InitLevel10Screen(void) +{ + // TODO: Initialize Level10 screen variables here! + framesCounter = 0; + finishScreen = 0; + + movingBox = (Rectangle){ 20, GetScreenHeight()/2 - 20, 40, 40 }; + + leftColumnRec = (Rectangle){ 240, 0, 100, GetScreenHeight() }; + middleColumnRec = (Rectangle){ GetScreenWidth()/2 - 50, 0, 100, GetScreenHeight() }; + rightColumnRec = (Rectangle){ 920, 0, 100, GetScreenHeight() }; + + leftColumnActive = true; + middleColumnActive = false; + rightColumnActive = true; +} + +// Level10 Screen Update logic +void UpdateLevel10Screen(void) +{ + // Update Level10 screen variables here! + framesCounter++; + + if (!done) + { + movingBox.x += moveSpeed; + + if (movingBox.x <= 0) moveSpeed *= -1; + + if ((leftColumnActive && (CheckCollisionRecs(leftColumnRec, movingBox))) || + (middleColumnActive && (CheckCollisionRecs(middleColumnRec, movingBox))) || + (rightColumnActive && (CheckCollisionRecs(rightColumnRec, movingBox)))) moveSpeed *= -1; + + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + if (CheckCollisionPointRec(GetMousePosition(), leftColumnRec)) + { + middleColumnActive = false; + rightColumnActive = true; + } + else if (CheckCollisionPointRec(GetMousePosition(), middleColumnRec)) + { + rightColumnActive = false; + leftColumnActive = true; + } + else if (CheckCollisionPointRec(GetMousePosition(), rightColumnRec)) + { + leftColumnActive = false; + middleColumnActive = true; + } + } + } + + if (movingBox.x >= 1100) done = true; + + if (done && !levelFinished) + { + levelTimeSec = framesCounter/60; + levelFinished = true; + framesCounter = 0; + } + + if (levelFinished) + { + framesCounter++; + + if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; + } +} + +// Level10 Screen Draw logic +void DrawLevel10Screen(void) +{ + // Draw Level10 screen + DrawRectangle(1100, GetScreenHeight()/2 - 20, 40, 40, GRAY); + + DrawRectangleRec(movingBox, LIGHTGRAY); + + if (leftColumnActive) DrawRectangleRec(leftColumnRec, GRAY); + if (middleColumnActive) DrawRectangleRec(middleColumnRec, GRAY); + if (rightColumnActive) DrawRectangleRec(rightColumnRec, GRAY); + + if (levelFinished) + { + DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); + DrawText("LEVEL 08", GetScreenWidth()/2 - MeasureText("LEVEL 08", 30)/2, 20, 30, GRAY); + DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); + } + else DrawText("LEVEL 08", GetScreenWidth()/2 - MeasureText("LEVEL 08", 30)/2, 20, 30, LIGHTGRAY); +} + +// Level10 Screen Unload logic +void UnloadLevel10Screen(void) +{ + // TODO: Unload Level10 screen variables here! +} + +// Level10 Screen should finish? +int FinishLevel10Screen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/just_do/screens/screen_logo.c b/games/just_do/screens/screen_logo.c new file mode 100644 index 00000000..9639602d --- /dev/null +++ b/games/just_do/screens/screen_logo.c @@ -0,0 +1,227 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Logo Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +#include + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Logo screen global variables +static int framesCounter; +static int finishScreen; + +const char msgLogoA[64] = "A simple and easy-to-use library"; +const char msgLogoB[64] = "to learn videogames programming"; + +int logoPositionX; +int logoPositionY; + +int raylibLettersCount = 0; + +int topSideRecWidth = 16; +int leftSideRecHeight = 16; + +int bottomSideRecWidth = 16; +int rightSideRecHeight = 16; + +char raylib[8] = " \0"; // raylib text array, max 8 letters + +int logoScreenState = 0; // Tracking animation states (State Machine) +bool msgLogoADone = false; +bool msgLogoBDone = false; + +int lettersCounter = 0; +char msgBuffer[128] = { ' ' }; + +//---------------------------------------------------------------------------------- +// Logo Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Logo Screen Initialization logic +void InitLogoScreen(void) +{ + // Initialize LOGO screen variables here! + framesCounter = 0; + finishScreen = 0; + + logoPositionX = GetScreenWidth()/2 - 128; + logoPositionY = GetScreenHeight()/2 - 128; +} + +// Logo Screen Update logic +void UpdateLogoScreen(void) +{ + // Update LOGO screen + framesCounter++; // Count frames + + // Update LOGO screen variables + if (logoScreenState == 0) // State 0: Small box blinking + { + framesCounter++; + + if (framesCounter == 120) + { + logoScreenState = 1; + framesCounter = 0; // Reset counter... will be used later... + } + } + else if (logoScreenState == 1) // State 1: Top and left bars growing + { + topSideRecWidth += 4; + leftSideRecHeight += 4; + + if (topSideRecWidth == 256) logoScreenState = 2; + } + else if (logoScreenState == 2) // State 2: Bottom and right bars growing + { + bottomSideRecWidth += 4; + rightSideRecHeight += 4; + + if (bottomSideRecWidth == 256) + { + lettersCounter = 0; + for (int i = 0; i < strlen(msgBuffer); i++) msgBuffer[i] = ' '; + + logoScreenState = 3; + } + } + else if (logoScreenState == 3) // State 3: Letters appearing (one by one) + { + framesCounter++; + + // Every 12 frames, one more letter! + if ((framesCounter%12) == 0) raylibLettersCount++; + + switch (raylibLettersCount) + { + 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; + } + + if (raylibLettersCount >= 10) + { + // Write raylib description messages + if ((framesCounter%2) == 0) lettersCounter++; + + if (!msgLogoADone) + { + if (lettersCounter <= strlen(msgLogoA)) strncpy(msgBuffer, msgLogoA, lettersCounter); + else + { + for (int i = 0; i < strlen(msgBuffer); i++) msgBuffer[i] = ' '; + + lettersCounter = 0; + msgLogoADone = true; + } + } + else if (!msgLogoBDone) + { + if (lettersCounter <= strlen(msgLogoB)) strncpy(msgBuffer, msgLogoB, lettersCounter); + else + { + msgLogoBDone = true; + framesCounter = 0; + PlaySound(levelWin); + } + } + } + } + + // Wait for 2 seconds (60 frames) before jumping to TITLE screen + if (msgLogoBDone) + { + framesCounter++; + + if (framesCounter > 90) finishScreen = true; + } +} + +// Logo Screen Draw logic +void DrawLogoScreen(void) +{ + // Draw LOGO screen + if (logoScreenState == 0) + { + if ((framesCounter/15)%2) DrawRectangle(logoPositionX, logoPositionY - 60, 16, 16, BLACK); + } + else if (logoScreenState == 1) + { + DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK); + DrawRectangle(logoPositionX, logoPositionY - 60, 16, leftSideRecHeight, BLACK); + } + else if (logoScreenState == 2) + { + DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK); + DrawRectangle(logoPositionX, logoPositionY - 60, 16, leftSideRecHeight, BLACK); + + DrawRectangle(logoPositionX + 240, logoPositionY - 60, 16, rightSideRecHeight, BLACK); + DrawRectangle(logoPositionX, logoPositionY + 240 - 60, bottomSideRecWidth, 16, BLACK); + } + else if (logoScreenState == 3) + { + DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK); + DrawRectangle(logoPositionX, logoPositionY + 16 - 60, 16, leftSideRecHeight - 32, BLACK); + + DrawRectangle(logoPositionX + 240, logoPositionY + 16 - 60, 16, rightSideRecHeight - 32, BLACK); + DrawRectangle(logoPositionX, logoPositionY + 240 - 60, bottomSideRecWidth, 16, BLACK); + + DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112 - 60, 224, 224, RAYWHITE); + + DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48 - 60, 50, BLACK); + + if (!msgLogoADone) DrawText(msgBuffer, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 230, 30, GRAY); + else + { + DrawText(msgLogoA, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 230, 30, GRAY); + + if (!msgLogoBDone) DrawText(msgBuffer, GetScreenWidth()/2 - MeasureText(msgLogoB, 30)/2, logoPositionY + 280, 30, GRAY); + else + { + DrawText(msgLogoB, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 280, 30, GRAY); + } + } + } +} + +// Logo Screen Unload logic +void UnloadLogoScreen(void) +{ + // TODO: Unload LOGO screen variables here! +} + +// Logo Screen should finish? +int FinishLogoScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/just_do/screens/screens.h b/games/just_do/screens/screens.h new file mode 100644 index 00000000..7fa59405 --- /dev/null +++ b/games/just_do/screens/screens.h @@ -0,0 +1,150 @@ +/********************************************************************************************** +* +* raylib - Standard Game template +* +* Screens Functions Declarations (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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, LEVEL00, LEVEL01, LEVEL02, LEVEL03, LEVEL04, LEVEL05, LEVEL06, LEVEL07, LEVEL08, LEVEL09 } GameScreen; + +//---------------------------------------------------------------------------------- +// Global Variables Definition +//---------------------------------------------------------------------------------- +GameScreen currentScreen; +Sound levelWin; + +#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); + +//---------------------------------------------------------------------------------- +// Level00 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitLevel00Screen(void); +void UpdateLevel00Screen(void); +void DrawLevel00Screen(void); +void UnloadLevel00Screen(void); +int FinishLevel00Screen(void); + +//---------------------------------------------------------------------------------- +// Level01 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitLevel01Screen(void); +void UpdateLevel01Screen(void); +void DrawLevel01Screen(void); +void UnloadLevel01Screen(void); +int FinishLevel01Screen(void); + +//---------------------------------------------------------------------------------- +// Level02 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitLevel02Screen(void); +void UpdateLevel02Screen(void); +void DrawLevel02Screen(void); +void UnloadLevel02Screen(void); +int FinishLevel02Screen(void); + +//---------------------------------------------------------------------------------- +// Level03 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitLevel03Screen(void); +void UpdateLevel03Screen(void); +void DrawLevel03Screen(void); +void UnloadLevel03Screen(void); +int FinishLevel03Screen(void); + +//---------------------------------------------------------------------------------- +// Level04 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitLevel04Screen(void); +void UpdateLevel04Screen(void); +void DrawLevel04Screen(void); +void UnloadLevel04Screen(void); +int FinishLevel04Screen(void); + +//---------------------------------------------------------------------------------- +// Level05 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitLevel05Screen(void); +void UpdateLevel05Screen(void); +void DrawLevel05Screen(void); +void UnloadLevel05Screen(void); +int FinishLevel05Screen(void); + +//---------------------------------------------------------------------------------- +// Level06 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitLevel06Screen(void); +void UpdateLevel06Screen(void); +void DrawLevel06Screen(void); +void UnloadLevel06Screen(void); +int FinishLevel06Screen(void); + +//---------------------------------------------------------------------------------- +// Level07 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitLevel07Screen(void); +void UpdateLevel07Screen(void); +void DrawLevel07Screen(void); +void UnloadLevel07Screen(void); +int FinishLevel07Screen(void); + +//---------------------------------------------------------------------------------- +// Level08 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitLevel08Screen(void); +void UpdateLevel08Screen(void); +void DrawLevel08Screen(void); +void UnloadLevel08Screen(void); +int FinishLevel08Screen(void); + +//---------------------------------------------------------------------------------- +// Level09 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitLevel09Screen(void); +void UpdateLevel09Screen(void); +void DrawLevel09Screen(void); +void UnloadLevel09Screen(void); +int FinishLevel09Screen(void); + + +void DrawRectangleBordersRec(Rectangle rec, int offsetX, int offsetY, int borderSize, Color col); + +#ifdef __cplusplus +} +#endif + +#endif // SCREENS_H \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/just_do.c b/games/just_do_GGJ2015/src/just_do.c deleted file mode 100644 index beac9e14..00000000 --- a/games/just_do_GGJ2015/src/just_do.c +++ /dev/null @@ -1,358 +0,0 @@ -/******************************************************************************************* -* -* JUST DO - Global Game Jam 2015 Videogame -* Experimental puzzle game that lets the user try to find a logic solution to -* different shape-color-based situations. -* -* Developed by: Ramon Santamaria (Ray San) -* -* This game has been created using raylib (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* raylib - Copyright (c) 2015 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -********************************************************************************************/ - -#include "raylib.h" -#include "screens/screens.h" // NOTE: Defines currentScreen - -#if defined(PLATFORM_WEB) - #include -#endif - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- -const int screenWidth = 1280; // Moved to screens.h -const int screenHeight = 720; // Moved to screens.h - -// Required variables to manage screen transitions (fade-in, fade-out) -float transAlpha = 0; -bool onTransition = false; -bool transFadeOut = false; -int transFromScreen = -1; -int transToScreen = -1; -int framesCounter = 0; - -//static Sound levelWin; - -//---------------------------------------------------------------------------------- -// Local Functions Declaration -//---------------------------------------------------------------------------------- -void TransitionToScreen(int screen); -void UpdateTransition(void); -void DrawTransition(void); - -void UpdateDrawFrame(void); // Update and Draw one frame - -//---------------------------------------------------------------------------------- -// Main entry point -//---------------------------------------------------------------------------------- -int main(void) -{ - // Initialization - //--------------------------------------------------------- - const char windowTitle[30] = "JUST DO"; - - //SetupFlags(FLAG_FULLSCREEN_MODE); - InitWindow(screenWidth, screenHeight, windowTitle); - - // TODO: Load global data here (assets that must be available in all screens, i.e. fonts) - InitAudioDevice(); - - levelWin = LoadSound("resources/win.wav"); - - // Setup and Init first screen - currentScreen = LOGO; - InitLogoScreen(); - -#if defined(PLATFORM_WEB) - emscripten_set_main_loop(UpdateDrawFrame, 0, 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 - { - - if (IsKeyPressed(KEY_SPACE)) PlaySound(levelWin); - - UpdateDrawFrame(); - } -#endif - - // De-Initialization - //-------------------------------------------------------------------------------------- - - // TODO: Unload all global loaded data (i.e. fonts) here! - UnloadSound(levelWin); - - CloseAudioDevice(); - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} - -//---------------------------------------------------------------------------------- -// Local Functions Definition -//---------------------------------------------------------------------------------- -void TransitionToScreen(int screen) -{ - onTransition = true; - transFromScreen = currentScreen; - transToScreen = screen; -} - -void UpdateTransition(void) -{ - if (!transFadeOut) - { - transAlpha += 0.02f; - - if (transAlpha >= 1.0) - { - transAlpha = 1.0; - currentScreen = transToScreen; - transFadeOut = true; - framesCounter = 0; - } - } - else // Transition fade out logic - { - transAlpha -= 0.02f; - - if (transAlpha <= 0) - { - transAlpha = 0; - transFadeOut = false; - onTransition = false; - transFromScreen = -1; - transToScreen = -1; - } - } -} - -void DrawTransition(void) -{ - DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, transAlpha)); -} - -void UpdateDrawFrame(void) -{ - // Update - //---------------------------------------------------------------------------------- - if (!onTransition) - { - if (IsKeyPressed('0')) - { - TransitionToScreen(LEVEL00); - InitLevel00Screen(); - } - else if (IsKeyPressed('1')) - { - TransitionToScreen(LEVEL01); - InitLevel01Screen(); - } - else if (IsKeyPressed('2')) - { - TransitionToScreen(LEVEL02); - InitLevel02Screen(); - } - else if (IsKeyPressed('3')) - { - TransitionToScreen(LEVEL03); - InitLevel03Screen(); - } - else if (IsKeyPressed('4')) - { - TransitionToScreen(LEVEL04); - InitLevel04Screen(); - } - else if (IsKeyPressed('5')) - { - TransitionToScreen(LEVEL05); - InitLevel05Screen(); - } - else if (IsKeyPressed('6')) - { - TransitionToScreen(LEVEL06); - InitLevel06Screen(); - } - else if (IsKeyPressed('7')) - { - TransitionToScreen(LEVEL07); - InitLevel07Screen(); - } - else if (IsKeyPressed('8')) - { - TransitionToScreen(LEVEL08); - InitLevel08Screen(); - } - else if (IsKeyPressed('9')) - { - TransitionToScreen(LEVEL09); - InitLevel08Screen(); - } - - switch(currentScreen) - { - case LOGO: - { - UpdateLogoScreen(); - - if (FinishLogoScreen()) - { - UnloadLogoScreen(); - TransitionToScreen(LEVEL00); - InitLevel00Screen(); - - PlayMusicStream("resources/ambient.ogg"); - SetMusicVolume(0.6f); - } - } break; - case LEVEL00: - { - UpdateLevel00Screen(); - - if (FinishLevel00Screen()) - { - UnloadLevel00Screen(); - TransitionToScreen(LEVEL01); - InitLevel01Screen(); - } - } break; - case LEVEL01: - { - UpdateLevel01Screen(); - - if (FinishLevel01Screen()) - { - UnloadLevel01Screen(); - TransitionToScreen(LEVEL02); - InitLevel02Screen(); - } - } break; - case LEVEL02: - { - UpdateLevel02Screen(); - - if (FinishLevel02Screen()) - { - UnloadLevel02Screen(); - TransitionToScreen(LEVEL03); - InitLevel03Screen(); - } - } break; - case LEVEL03: - { - UpdateLevel03Screen(); - - if (FinishLevel03Screen()) - { - UnloadLevel03Screen(); - TransitionToScreen(LEVEL04); - InitLevel04Screen(); - } - } break; - case LEVEL04: - { - UpdateLevel04Screen(); - - if (FinishLevel04Screen()) - { - UnloadLevel04Screen(); - TransitionToScreen(LEVEL05); - InitLevel05Screen(); - } - } break; - case LEVEL05: - { - UpdateLevel05Screen(); - - if (FinishLevel05Screen()) - { - UnloadLevel05Screen(); - TransitionToScreen(LEVEL06); - InitLevel06Screen(); - } - } break; - case LEVEL06: - { - UpdateLevel06Screen(); - - if (FinishLevel06Screen()) - { - UnloadLevel06Screen(); - TransitionToScreen(LEVEL07); - InitLevel07Screen(); - } - } break; - case LEVEL07: - { - UpdateLevel07Screen(); - - if (FinishLevel07Screen()) - { - UnloadLevel07Screen(); - TransitionToScreen(LEVEL08); - InitLevel08Screen(); - } - } break; - case LEVEL08: - { - UpdateLevel08Screen(); - - if (FinishLevel08Screen()) - { - UnloadLevel08Screen(); - TransitionToScreen(LEVEL09); - InitLevel09Screen(); - } - } break; - case LEVEL09: - { - UpdateLevel09Screen(); - - if (FinishLevel09Screen()) - { - UnloadLevel09Screen(); - TransitionToScreen(LEVEL00); - InitLevel00Screen(); - } - } break; - default: break; - } - } - else UpdateTransition(); // Update transition (fade-in, fade-out) - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - switch(currentScreen) - { - case LOGO: DrawLogoScreen(); break; - case LEVEL00: DrawLevel00Screen(); break; - case LEVEL01: DrawLevel01Screen(); break; - case LEVEL02: DrawLevel02Screen(); break; - case LEVEL03: DrawLevel03Screen(); break; - case LEVEL04: DrawLevel04Screen(); break; - case LEVEL05: DrawLevel05Screen(); break; - case LEVEL06: DrawLevel06Screen(); break; - case LEVEL07: DrawLevel07Screen(); break; - case LEVEL08: DrawLevel08Screen(); break; - case LEVEL09: DrawLevel09Screen(); break; - default: break; - } - - if (onTransition) DrawTransition(); - - EndDrawing(); - //---------------------------------------------------------------------------------- -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/makefile b/games/just_do_GGJ2015/src/makefile deleted file mode 100644 index 4c36b154..00000000 --- a/games/just_do_GGJ2015/src/makefile +++ /dev/null @@ -1,246 +0,0 @@ -#************************************************************************************************** -# -# raylib - Advance Game -# -# makefile to compile advance game for desktop platforms, Raspberry Pi and HTML5 (emscripten) -# -# Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -# -# 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. -# -#************************************************************************************************** - -# define raylib platform to compile for -# possible platforms: PLATFORM_DESKTOP PLATFORM_RPI PLATFORM_WEB -# WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop() -PLATFORM ?= PLATFORM_DESKTOP - -# determine PLATFORM_OS in case PLATFORM_DESKTOP selected -ifeq ($(PLATFORM),PLATFORM_DESKTOP) - # No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows - ifeq ($(OS),Windows_NT) - PLATFORM_OS=WINDOWS - LIBPATH=win32 - else - UNAMEOS:=$(shell uname) - ifeq ($(UNAMEOS),Linux) - PLATFORM_OS=LINUX - LIBPATH=linux - else - ifeq ($(UNAMEOS),Darwin) - PLATFORM_OS=OSX - LIBPATH=osx - endif - endif - endif -endif - -# define compiler: gcc for C program, define as g++ for C++ -ifeq ($(PLATFORM),PLATFORM_WEB) - # define emscripten compiler - CC = emcc -else -ifeq ($(PLATFORM_OS),OSX) - # define llvm compiler for mac - CC = clang -else - # define default gcc compiler - CC = gcc -endif -endif - -# define compiler flags: -# -O2 defines optimization level -# -Wall turns on most, but not all, compiler warnings -# -std=c99 use standard C from 1999 revision -ifeq ($(PLATFORM),PLATFORM_RPI) - CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline -else - CFLAGS = -O2 -Wall -std=c99 -endif -ifeq ($(PLATFORM),PLATFORM_WEB) - CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 - #-s ASSERTIONS=1 --preload-file resources - #-s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing - #-s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) -endif - -#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes - -# define any directories containing required header files -ifeq ($(PLATFORM),PLATFORM_RPI) - INCLUDES = -I. -I../../src -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -else - INCLUDES = -I. -I../../src -I../../../src -# external libraries headers -# GLFW3 - INCLUDES += -I../../external/glfw3/include -# GLEW - INCLUDES += -I../../external/glew/include -# OpenAL Soft - INCLUDES += -I../../external/openal_soft/include -endif - -# define library paths containing required libs -ifeq ($(PLATFORM),PLATFORM_RPI) - LFLAGS = -L. -L../../src -L/opt/vc/lib -else - LFLAGS = -L. -L../../src -L../../../src - # external libraries to link with - # GLFW3 - LFLAGS += -L../../external/glfw3/lib/$(LIBPATH) - ifneq ($(PLATFORM_OS),OSX) - # OpenAL Soft - LFLAGS += -L../../external/openal_soft/lib/$(LIBPATH) - # GLEW - LFLAGS += -L../../external/glew/lib/$(LIBPATH) - endif -endif - -# define any libraries to link into executable -# if you want to link libraries (libname.so or libname.a), use the -lname -ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),LINUX) - # libraries for Debian GNU/Linux desktop compiling - # requires the following packages: - # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev - LIBS = -lraylib -lglfw -lGLEW -lGL -lopenal - endif - ifeq ($(PLATFORM_OS),OSX) - # libraries for OS X 10.9 desktop compiling - # requires the following packages: - # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev - LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAl -framework Cocoa - else - # libraries for Windows desktop compiling - # NOTE: GLFW3 and OpenAL Soft libraries should be installed - LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32 - endif -endif -ifeq ($(PLATFORM),PLATFORM_RPI) - # libraries for Raspberry Pi compiling - # NOTE: OpenAL Soft library should be installed (libopenal1 package) - LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal -endif -ifeq ($(PLATFORM),PLATFORM_WEB) - LIBS = ../../src/libraylib.bc -endif - -# define additional parameters and flags for windows -ifeq ($(PLATFORM_OS),WINDOWS) - # resources file contains windows exe icon - # -Wl,--subsystem,windows hides the console window - WINFLAGS = ../../src/resources -Wl,--subsystem,windows -endif - -ifeq ($(PLATFORM),PLATFORM_WEB) - EXT = .html -endif - -# define all screen object files required -SCREENS = \ - screens/screen_logo.o \ - screens/screen_level00.o \ - screens/screen_level01.o \ - screens/screen_level02.o \ - screens/screen_level03.o \ - screens/screen_level04.o \ - screens/screen_level05.o \ - screens/screen_level06.o \ - screens/screen_level07.o \ - screens/screen_level08.o \ - screens/screen_level09.o \ - -# typing 'make' will invoke the first target entry in the file, -# in this case, the 'default' target entry is just_do -default: just_do - -# compile just_do -just_do: just_do.c $(SCREENS) - $(CC) -o $@$(EXT) $< $(SCREENS) $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) - -# compile screen LOGO -screens/screen_logo.o: screens/screen_logo.c - $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) - -# compile screen LEVEL00 -screens/screen_level00.o: screens/screen_level00.c - $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) - -# compile screen LEVEL01 -screens/screen_level01.o: screens/screen_level01.c - $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) - -# compile screen LEVEL02 -screens/screen_level02.o: screens/screen_level02.c - $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) - -# compile screen LEVEL03 -screens/screen_level03.o: screens/screen_level03.c - $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) - -# compile screen LEVEL04 -screens/screen_level04.o: screens/screen_level04.c - $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) - -# compile screen LEVEL05 -screens/screen_level05.o: screens/screen_level05.c - $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) - -# compile screen LEVEL06 -screens/screen_level06.o: screens/screen_level06.c - $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) - -# compile screen LEVEL07 -screens/screen_level07.o: screens/screen_level07.c - $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) - -# compile screen LEVEL08 -screens/screen_level08.o: screens/screen_level08.c - $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) - -# compile screen LEVEL09 -screens/screen_level09.o: screens/screen_level09.c - $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) - -# clean everything -clean: -ifeq ($(PLATFORM),PLATFORM_DESKTOP) - ifeq ($(PLATFORM_OS),OSX) - find . -type f -perm +ugo+x -delete - rm -f *.o - else - ifeq ($(PLATFORM_OS),LINUX) - find . -type f -executable -delete - rm -f *.o - else - del *.o *.exe - endif - endif -endif -ifeq ($(PLATFORM),PLATFORM_RPI) - find . -type f -executable -delete - rm -f *.o -endif -ifeq ($(PLATFORM),PLATFORM_WEB) - del *.o *.html *.js -endif - @echo Cleaning done - -# instead of defining every module one by one, we can define a pattern -# this pattern below will automatically compile every module defined on $(OBJS) -#%.exe : %.c -# $(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) diff --git a/games/just_do_GGJ2015/src/resources/ambient.ogg b/games/just_do_GGJ2015/src/resources/ambient.ogg deleted file mode 100644 index af7f836e..00000000 Binary files a/games/just_do_GGJ2015/src/resources/ambient.ogg and /dev/null differ diff --git a/games/just_do_GGJ2015/src/resources/win.wav b/games/just_do_GGJ2015/src/resources/win.wav deleted file mode 100644 index 72520f99..00000000 Binary files a/games/just_do_GGJ2015/src/resources/win.wav and /dev/null differ diff --git a/games/just_do_GGJ2015/src/screens/screen_level00.c b/games/just_do_GGJ2015/src/screens/screen_level00.c deleted file mode 100644 index 99f29849..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_level00.c +++ /dev/null @@ -1,167 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Level00 Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Level00 screen global variables -static int framesCounter; -static int finishScreen; - -static Rectangle boundsU, boundsO; - -static bool mouseOverU = false; -static bool mouseOverO = false; -static bool placedU = false; -static bool placedO = false; - -static bool done = false; -static int levelTimeSec = 0; -static bool levelFinished = false; - -//---------------------------------------------------------------------------------- -// Level00 Screen Functions Definition -//---------------------------------------------------------------------------------- - -// Level00 Screen Initialization logic -void InitLevel00Screen(void) -{ - // Initialize Level00 screen variables here! - framesCounter = 0; - finishScreen = 0; - - boundsU = (Rectangle){GetScreenWidth()/2 - 265, -200, MeasureText("U", 160) + 40, 160 }; - boundsO = (Rectangle){GetScreenWidth() - 370, -30, MeasureText("O", 160) + 40, 160 }; -} - -// Level00 Screen Update logic -void UpdateLevel00Screen(void) -{ - // Update Level00 screen variables here! - if (!done) framesCounter++; - - if (!done) - { - if (!placedU) boundsU.y += 2; - - if (boundsU.y >= GetScreenHeight()) boundsU.y = -boundsU.height; - - Vector2 mousePos = GetMousePosition(); - - if (CheckCollisionPointRec(mousePos, boundsU)) - { - mouseOverU = true; - - if (!placedU && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - { - if ((boundsU.y > GetScreenHeight()/2 - 110) && ((boundsU.y + boundsU.height) < (GetScreenHeight()/2 + 100))) - { - placedU = true; - } - } - } - else mouseOverU = false; - - if (CheckCollisionPointRec(mousePos, boundsO)) - { - mouseOverO = true; - - if (!placedO && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) boundsO.y += 100; - - if (boundsO.y >= (GetScreenHeight()/2 - 130)) placedO = true; - } - else mouseOverO = false; - - if (placedO && placedU) - { - done = true; - PlaySound(levelWin); - } - } - - if (done && !levelFinished) - { - levelTimeSec = framesCounter/60; - levelFinished = true; - framesCounter = 0; - } - - if (levelFinished) - { - framesCounter++; - - if ((framesCounter > 30) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; - } -} - -// Level00 Screen Draw logic -void DrawLevel00Screen(void) -{ - // Draw Level00 screen - DrawText("U", boundsU.x, boundsU.y + 10, 160, GRAY); - DrawText("J", GetScreenWidth()/2 - MeasureText("JUST DO", 160)/2, GetScreenHeight()/2 - 80, 160, GRAY); - DrawText("ST D", GetScreenWidth()/2 - MeasureText("JUST DO", 160)/2 + 210, GetScreenHeight()/2 - 80, 160, GRAY); - DrawText("O", boundsO.x, boundsO.y + 10, 160, GRAY); - - DrawText("by RAMON SANTAMARIA (@raysan5)", 370, GetScreenHeight()/2 + 100, 30, Fade(LIGHTGRAY, 0.4f)); - - if (mouseOverU && !placedU) DrawRectangleLines(boundsU.x - 20, boundsU.y, boundsU.width, boundsU.height, Fade(LIGHTGRAY, 0.8f)); - //DrawRectangleBordersRec(boundsU, -20, 0, 20, Fade(RED, 0.3f)); - - if (mouseOverO && !placedO) DrawRectangleLines(boundsO.x - 20, boundsO.y, boundsO.width, boundsO.height, Fade(LIGHTGRAY, 0.8f)); - //DrawRectangleBordersRec(boundsO, -20, 0, 20, Fade(RED, 0.3f)); - - if (levelFinished) - { - DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); - DrawText("LEVEL 00", GetScreenWidth()/2 - MeasureText("LEVEL 00", 30)/2, 20, 30, GRAY); - DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); - } - else DrawText("LEVEL 00", GetScreenWidth()/2 - MeasureText("LEVEL 00", 30)/2, 20, 30, LIGHTGRAY); -} - -// Level00 Screen Unload logic -void UnloadLevel00Screen(void) -{ - // TODO: Unload Level00 screen variables here! -} - -// Level00 Screen should finish? -int FinishLevel00Screen(void) -{ - return finishScreen; -} - -void DrawRectangleBordersRec(Rectangle rec, int offsetX, int offsetY, int borderSize, Color col) -{ - DrawRectangle(rec.x + offsetX, rec.y + offsetY, rec.width, borderSize, col); - DrawRectangle(rec.x + offsetX, rec.y + borderSize + offsetY, borderSize, rec.height - borderSize*2, col); - DrawRectangle(rec.x + rec.width - borderSize + offsetX, rec.y + borderSize + offsetY, borderSize, rec.height - borderSize*2, col); - DrawRectangle(rec.x + offsetX, rec.y + rec.height - borderSize + offsetY, rec.width, borderSize, col); -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screen_level01.c b/games/just_do_GGJ2015/src/screens/screen_level01.c deleted file mode 100644 index cedcb2e0..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_level01.c +++ /dev/null @@ -1,163 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Level01 Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Level01 screen global variables -static int framesCounter; -static int finishScreen; - -static Rectangle innerLeftRec, outerLeftRec; -static Rectangle innerRightRec, outerRightRec; - -static bool done = false; -static int levelTimeSec = 0; -static bool levelFinished = false; - -//---------------------------------------------------------------------------------- -// Level01 Screen Functions Definition -//---------------------------------------------------------------------------------- - -// Level01 Screen Initialization logic -void InitLevel01Screen(void) -{ - // Initialize Level01 screen variables here! - framesCounter = 0; - finishScreen = 0; - - outerLeftRec = (Rectangle){ 0, 0, GetScreenWidth()/2, GetScreenHeight() }; - outerRightRec = (Rectangle){ GetScreenWidth()/2, 0, GetScreenWidth()/2, GetScreenHeight() }; - - innerLeftRec = (Rectangle){ GetScreenWidth()/4 - 200, GetScreenHeight()/2 - 200, 400, 400}; - innerRightRec = (Rectangle){ GetScreenWidth()/2 + GetScreenWidth()/4 - 200, GetScreenHeight()/2 - 200, 400, 400}; -} - -// Level01 Screen Update logic -void UpdateLevel01Screen(void) -{ - // Update Level01 screen - framesCounter++; - - if (!done) - { - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - { - if (CheckCollisionPointRec(GetMousePosition(), innerLeftRec)) - { - if (innerRightRec.width > 0) - { - innerRightRec.x += 20; - innerRightRec.y += 20; - innerRightRec.width -= 40; - innerRightRec.height -= 40; - } - } - else if (CheckCollisionPointRec(GetMousePosition(), innerRightRec)) - { - if (innerLeftRec.width > 0) - { - innerLeftRec.x += 20; - innerLeftRec.y += 20; - innerLeftRec.width -= 40; - innerLeftRec.height -= 40; - } - } - else if (CheckCollisionPointRec(GetMousePosition(), outerLeftRec)) - { - innerLeftRec.x -= 20; - innerLeftRec.y -= 20; - innerLeftRec.width += 40; - innerLeftRec.height += 40; - } - else if (CheckCollisionPointRec(GetMousePosition(), outerRightRec)) - { - innerRightRec.x -= 20; - innerRightRec.y -= 20; - innerRightRec.width += 40; - innerRightRec.height += 40; - } - } - - - if (((innerRightRec.width == 0) && (innerLeftRec.height >= GetScreenHeight())) || - ((innerLeftRec.width == 0) && (innerRightRec.height >= GetScreenHeight()))) - { - done = true; - PlaySound(levelWin); - } - } - - if (done && !levelFinished) - { - levelTimeSec = framesCounter/60; - levelFinished = true; - framesCounter = 0; - } - - if (levelFinished) - { - framesCounter++; - - if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; - } -} - -// Level01 Screen Draw logic -void DrawLevel01Screen(void) -{ - // Draw Level01 screen - if (!levelFinished) DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), LIGHTGRAY); - else DrawRectangle(60, 60, GetScreenWidth() - 120, GetScreenHeight() - 120, LIGHTGRAY); - - DrawRectangleRec(outerLeftRec, GRAY); - DrawRectangleRec(innerLeftRec, RAYWHITE); - DrawRectangleRec(outerRightRec, RAYWHITE); - DrawRectangleRec(innerRightRec, GRAY); - - if (levelFinished) - { - DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); - DrawText("LEVEL 01", GetScreenWidth()/2 - MeasureText("LEVEL 01", 30)/2, 20, 30, GRAY); - DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); - } - else DrawText("LEVEL 01", GetScreenWidth()/2 - MeasureText("LEVEL 01", 30)/2, 20, 30, LIGHTGRAY); -} - -// Level01 Screen Unload logic -void UnloadLevel01Screen(void) -{ - // TODO: Unload Level01 screen variables here! -} - -// Level01 Screen should finish? -int FinishLevel01Screen(void) -{ - return finishScreen; -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screen_level02.c b/games/just_do_GGJ2015/src/screens/screen_level02.c deleted file mode 100644 index ccfa355e..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_level02.c +++ /dev/null @@ -1,170 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Level02 Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -#include - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Level02 screen global variables -static int framesCounter; -static int finishScreen; - -static Vector2 bouncingBallPos; -static float bouncingBallRadius = 40; -static Vector2 bouncingBallSpeed; - -static Vector2 holeCirclePos; -static float holeCircleRadius = 50; - -static bool ballOnHole = false; - -static int levelTimeSec = 0; -static bool levelFinished = false; - -//---------------------------------------------------------------------------------- -// Level02 Screen Functions Definition -//---------------------------------------------------------------------------------- -float Vector2Distance(Vector2 v1, Vector2 v2); - -// Level02 Screen Initialization logic -void InitLevel02Screen(void) -{ - // TODO: Initialize Level02 screen variables here! - framesCounter = 0; - finishScreen = 0; - - bouncingBallPos = (Vector2){ 120, 80 }; - bouncingBallSpeed = (Vector2){ 6, 8 }; - holeCirclePos = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 }; -} - -// Level02 Screen Update logic -void UpdateLevel02Screen(void) -{ - // Update Level02 screen - framesCounter++; - - if (!ballOnHole) - { - bouncingBallPos.x += bouncingBallSpeed.x; - bouncingBallPos.y += bouncingBallSpeed.y; - - if (((bouncingBallPos.x - bouncingBallRadius) <= 0) || ((bouncingBallPos.x + bouncingBallRadius) >= GetScreenWidth())) bouncingBallSpeed.x *= -1; - if (((bouncingBallPos.y - bouncingBallRadius) <= 0) || ((bouncingBallPos.y + bouncingBallRadius) >= GetScreenHeight())) bouncingBallSpeed.y *= -1; - - Vector2 mousePos = GetMousePosition(); - - if (CheckCollisionPointCircle(mousePos, bouncingBallPos, 120)) - { - bouncingBallPos.x = GetRandomValue(80, 1200); - bouncingBallPos.y = GetRandomValue(80, 650); - } - - if (CheckCollisionPointCircle(mousePos, holeCirclePos, 120)) - { - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) - { - holeCirclePos = mousePos; - - if ((holeCirclePos.x - holeCircleRadius) <= 0) holeCirclePos.x = holeCircleRadius; - else if ((holeCirclePos.x + holeCircleRadius) >= GetScreenWidth()) holeCirclePos.x = GetScreenWidth() - holeCircleRadius; - - if ((holeCirclePos.y - holeCircleRadius) <= 0) holeCirclePos.y = holeCircleRadius; - else if ((holeCirclePos.y + holeCircleRadius) >= GetScreenHeight()) holeCirclePos.y = GetScreenHeight() - holeCircleRadius; - } - } - - if (Vector2Distance(bouncingBallPos, holeCirclePos) < 20) - { - ballOnHole = true; - PlaySound(levelWin); - } - } - - if (ballOnHole && !levelFinished) - { - levelTimeSec = framesCounter/60; - levelFinished = true; - framesCounter = 0; - } - - if (levelFinished) - { - framesCounter++; - - if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; - } -} - -// Level02 Screen Draw logic -void DrawLevel02Screen(void) -{ - // Draw Level02 screen - - DrawCircleV(holeCirclePos, holeCircleRadius, LIGHTGRAY); - DrawCircleV(bouncingBallPos, bouncingBallRadius, DARKGRAY); - - DrawCircleLines(bouncingBallPos.x, bouncingBallPos.y, 120, Fade(LIGHTGRAY, 0.8f)); - - - - if (levelFinished) - { - DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); - DrawText("LEVEL 02", GetScreenWidth()/2 - MeasureText("LEVEL 02", 30)/2, 20, 30, GRAY); - DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); - } - else DrawText("LEVEL 02", GetScreenWidth()/2 - MeasureText("LEVEL 02", 30)/2, 20, 30, LIGHTGRAY); -} - -// Level02 Screen Unload logic -void UnloadLevel02Screen(void) -{ - // TODO: Unload Level02 screen variables here! -} - -// Level02 Screen should finish? -int FinishLevel02Screen(void) -{ - return finishScreen; -} - -// Calculate distance between two points -float Vector2Distance(Vector2 v1, Vector2 v2) -{ - float result; - - float dx = v2.x - v1.x; - float dy = v2.y - v1.y; - - result = sqrt(dx*dx + dy*dy); - - return result; -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screen_level03.c b/games/just_do_GGJ2015/src/screens/screen_level03.c deleted file mode 100644 index e8732414..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_level03.c +++ /dev/null @@ -1,134 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Level03 Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Level03 screen global variables -static int framesCounter; -static int finishScreen; - -static Rectangle holeRec, pieceRec; -static bool showPiece = false; -static bool pieceSelected = false; - -static bool done = false; -static int levelTimeSec = 0; -static bool levelFinished = false; - -//---------------------------------------------------------------------------------- -// Level03 Screen Functions Definition -//---------------------------------------------------------------------------------- - -// Level03 Screen Initialization logic -void InitLevel03Screen(void) -{ - // Initialize Level03 screen variables here! - framesCounter = 0; - finishScreen = 0; - - holeRec = (Rectangle){ GetScreenWidth()/2 - 50, GetScreenHeight()/2 - 50, 100, 100 }; - pieceRec = (Rectangle){ 200, 400, 100, 100 }; -} - -// Level03 Screen Update logic -void UpdateLevel03Screen(void) -{ - // Update Level03 screen variables here! - framesCounter++; - - Vector2 mousePos = GetMousePosition(); - - if (!done) - { - if (CheckCollisionPointRec(mousePos, holeRec)) showPiece = true; - else showPiece = false; - - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) - { - if (CheckCollisionPointRec(mousePos, pieceRec)) - { - pieceSelected = true; - - pieceRec.x = ((int)mousePos.x - 50); - pieceRec.y = ((int)mousePos.y - 50); - } - } - - if ((pieceRec.x == holeRec.x) && !(CheckCollisionPointRec(mousePos, holeRec))) - { - done = true; - PlaySound(levelWin); - } - } - - if (done && !levelFinished) - { - levelTimeSec = framesCounter/60; - levelFinished = true; - framesCounter = 0; - } - - if (levelFinished) - { - framesCounter++; - - if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; - } -} - -// Level03 Screen Draw logic -void DrawLevel03Screen(void) -{ - // Draw Level03 screen - DrawRectangleRec(holeRec, GRAY); - DrawRectangleRec(pieceRec, RAYWHITE); - - if (showPiece) DrawRectangleLines(pieceRec.x, pieceRec.y, pieceRec.width, pieceRec.height, Fade(LIGHTGRAY, 0.8f)); - - if (levelFinished) - { - DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); - DrawText("LEVEL 03", GetScreenWidth()/2 - MeasureText("LEVEL 03", 30)/2, 20, 30, GRAY); - DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); - } - else DrawText("LEVEL 03", GetScreenWidth()/2 - MeasureText("LEVEL 03", 30)/2, 20, 30, LIGHTGRAY); -} - -// Level03 Screen Unload logic -void UnloadLevel03Screen(void) -{ - // TODO: Unload Level03 screen variables here! -} - -// Level03 Screen should finish? -int FinishLevel03Screen(void) -{ - return finishScreen; -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screen_level04.c b/games/just_do_GGJ2015/src/screens/screen_level04.c deleted file mode 100644 index c4e4e2c0..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_level04.c +++ /dev/null @@ -1,147 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Level04 Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Level04 screen global variables -static int framesCounter; -static int finishScreen; - -static Vector2 circlesCenter; -static float innerCircleRadius = 40; -static float outerCircleRadius = 300; - -static bool done = false; -static int levelTimeSec = 0; -static bool levelFinished = false; - -//---------------------------------------------------------------------------------- -// Level04 Screen Functions Definition -//---------------------------------------------------------------------------------- - -// Level04 Screen Initialization logic -void InitLevel04Screen(void) -{ - // Initialize Level04 screen variables here! - framesCounter = 0; - finishScreen = 0; - - circlesCenter = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 }; -} - -// Level04 Screen Update logic -void UpdateLevel04Screen(void) -{ - // Update Level04 screen variables here! - framesCounter++; - - if (!done) - { - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) - { - if (CheckCollisionPointCircle(GetMousePosition(), circlesCenter, innerCircleRadius)) - { - innerCircleRadius += 2; - } - else if (CheckCollisionPointCircle(GetMousePosition(), circlesCenter, outerCircleRadius)) - { - outerCircleRadius += 2; - } - else - { - outerCircleRadius -= 2; - - if (outerCircleRadius <= 260) outerCircleRadius = 260; - } - } - else - { - if (!done) - { - innerCircleRadius -= 2; - if (outerCircleRadius > 300) outerCircleRadius -= 2; - } - } - - if (innerCircleRadius >= 270) innerCircleRadius = 270; - else if (innerCircleRadius <= 40) innerCircleRadius = 40; - - if (outerCircleRadius >= 600) outerCircleRadius = 600; - - if (innerCircleRadius >= outerCircleRadius) - { - done = true; - PlaySound(levelWin); - } - } - - if (done && !levelFinished) - { - levelTimeSec = framesCounter/60; - levelFinished = true; - framesCounter = 0; - } - - if (levelFinished) - { - framesCounter++; - - if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; - } -} - -// Level04 Screen Draw logic -void DrawLevel04Screen(void) -{ - // Draw Level04 screen here! - //DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), GRAY); - DrawCircleV(circlesCenter, outerCircleRadius, GRAY); - DrawCircleV(circlesCenter, innerCircleRadius, RAYWHITE); - - if (levelFinished) - { - DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); - DrawText("LEVEL 04", GetScreenWidth()/2 - MeasureText("LEVEL 04", 30)/2, 20, 30, GRAY); - DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); - } - else DrawText("LEVEL 04", GetScreenWidth()/2 - MeasureText("LEVEL 04", 30)/2, 20, 30, LIGHTGRAY); -} - -// Level04 Screen Unload logic -void UnloadLevel04Screen(void) -{ - // TODO: Unload Level04 screen variables here! -} - -// Level04 Screen should finish? -int FinishLevel04Screen(void) -{ - return finishScreen; -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screen_level05.c b/games/just_do_GGJ2015/src/screens/screen_level05.c deleted file mode 100644 index f2e4d852..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_level05.c +++ /dev/null @@ -1,185 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Level05 Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -#define NUM_CIRCLES 10 - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Level05 screen global variables -static int framesCounter; -static int finishScreen; - -static Vector2 circleCenter; -static float circleRadius[NUM_CIRCLES]; -static bool circleLocked[NUM_CIRCLES]; -static Color circleColor[NUM_CIRCLES]; - -static bool done = false; -static int levelTimeSec = 0; -static bool levelFinished = false; - -//---------------------------------------------------------------------------------- -// Level05 Screen Functions Definition -//---------------------------------------------------------------------------------- -static bool CheckColor(Color col1, Color col2); - -// Level05 Screen Initialization logic -void InitLevel05Screen(void) -{ - // Initialize Level05 screen variables here! - framesCounter = 0; - finishScreen = 0; - - circleCenter = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 }; - - for (int i = 0; i < NUM_CIRCLES; i++) - { - circleRadius[i] = 760/NUM_CIRCLES*(NUM_CIRCLES - i); - circleLocked[i] = false; - } - - // That's a dirty hack to give sonme coherence to this puzzle... - circleColor[9] = GRAY; - circleColor[8] = RAYWHITE; - circleColor[7] = RAYWHITE; - circleColor[6] = GRAY; - circleColor[5] = RAYWHITE; - circleColor[4] = GRAY; - circleColor[3] = GRAY; - circleColor[2] = GRAY; - circleColor[1] = RAYWHITE; - circleColor[0] = GRAY; -} - -// Level05 Screen Update logic -void UpdateLevel05Screen(void) -{ - // Update Level05 screen variables here! - framesCounter++; - - if (!done) - { - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - { - for (int i = NUM_CIRCLES - 1; i >= 0; i--) - { - if (CheckCollisionPointCircle(GetMousePosition(), circleCenter, circleRadius[i])) - { - if (i == 0) - { - if (CheckColor(circleColor[8], GRAY)) circleColor[8] = RAYWHITE; - else circleColor[8] = GRAY; - } - else if (i == 2) - { - if (CheckColor(circleColor[5], GRAY)) circleColor[5] = RAYWHITE; - else circleColor[5] = GRAY; - } - else if (i == 3) - { - if (CheckColor(circleColor[6], GRAY)) circleColor[6] = RAYWHITE; - else circleColor[6] = GRAY; - } - else - { - if (CheckColor(circleColor[i], GRAY)) circleColor[i] = RAYWHITE; - else circleColor[i] = GRAY; - } - return; - } - } - } - - // Check all cicles done - for (int i = 0; i < NUM_CIRCLES; i++) - { - done = true; - - if (CheckColor(circleColor[i], RAYWHITE)) - { - done = false; - return; - } - - //if (done) PlaySound(levelWin); - } - } - - if (done && !levelFinished) - { - levelTimeSec = framesCounter/60; - levelFinished = true; - framesCounter = 0; - } - - if (levelFinished) - { - framesCounter++; - - if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; - } -} - -// Level05 Screen Draw logic -void DrawLevel05Screen(void) -{ - // Draw Level05 screen - for (int i = 0; i < NUM_CIRCLES; i++) - { - DrawPoly(circleCenter, 64, circleRadius[i], 0.0f, circleColor[i]); - } - - - - if (levelFinished) - { - DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); - DrawText("LEVEL 05", GetScreenWidth()/2 - MeasureText("LEVEL 05", 30)/2, 20, 30, GRAY); - DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); - } - else DrawText("LEVEL 05", GetScreenWidth()/2 - MeasureText("LEVEL 05", 30)/2, 20, 30, LIGHTGRAY); -} - -// Level05 Screen Unload logic -void UnloadLevel05Screen(void) -{ - // TODO: Unload Level05 screen variables here! -} - -// Level05 Screen should finish? -int FinishLevel05Screen(void) -{ - return finishScreen; -} - -static bool CheckColor(Color col1, Color col2) -{ - return ((col1.r == col2.r) && (col1.g == col2.g) && (col1.b == col2.b) && (col1.a == col2.a)); -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screen_level06.c b/games/just_do_GGJ2015/src/screens/screen_level06.c deleted file mode 100644 index b5881db4..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_level06.c +++ /dev/null @@ -1,156 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Level06 Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Level06 screen global variables -static int framesCounter; -static int finishScreen; - -static Rectangle centerRec; - -static Rectangle movingRecs[4]; -static int speedRecs[4]; -static bool stoppedRec[4]; -static int mouseOverNum = -1; - -static bool done = false; -static int levelTimeSec = 0; -static bool levelFinished = false; - -//---------------------------------------------------------------------------------- -// Level06 Screen Functions Definition -//---------------------------------------------------------------------------------- - -// Level06 Screen Initialization logic -void InitLevel06Screen(void) -{ - // Initialize Level06 screen variables here! - framesCounter = 0; - finishScreen = 0; - - centerRec = (Rectangle){ GetScreenWidth()/2 - 100, 0, 200, GetScreenHeight() }; - - for (int i = 0; i < 4; i++) - { - movingRecs[i] = (Rectangle){ GetRandomValue(0, 5)*150, (i*150) + 90, 100, 100 }; - stoppedRec[i] = false; - speedRecs[i] = GetRandomValue(4, 8); - } -} - -// Level06 Screen Update logic -void UpdateLevel06Screen(void) -{ - // Update Level06 screen variables here! - framesCounter++; - - if (!done) - { - for (int i = 0; i < 4; i++) - { - if (!stoppedRec[i]) movingRecs[i].x += speedRecs[i]; - - if (movingRecs[i].x >= GetScreenWidth()) movingRecs[i].x = -movingRecs[i].width; - - if (CheckCollisionPointRec(GetMousePosition(), movingRecs[i])) - { - mouseOverNum = i; - - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - { - if (i == 0) stoppedRec[3] = !stoppedRec[3]; - else if (i == 1) stoppedRec[2] = !stoppedRec[2]; - else if (i == 2) stoppedRec[0] = !stoppedRec[0]; - else if (i == 3) stoppedRec[1] = !stoppedRec[1]; - } - } - } - - // Check if all boxes are aligned - if (((movingRecs[0].x > centerRec.x) && ((movingRecs[0].x + movingRecs[0].width) < (centerRec.x + centerRec.width))) && - ((movingRecs[1].x > centerRec.x) && ((movingRecs[1].x + movingRecs[1].width) < (centerRec.x + centerRec.width))) && - ((movingRecs[2].x > centerRec.x) && ((movingRecs[2].x + movingRecs[2].width) < (centerRec.x + centerRec.width))) && - ((movingRecs[3].x > centerRec.x) && ((movingRecs[3].x + movingRecs[3].width) < (centerRec.x + centerRec.width)))) - { - done = true; - PlaySound(levelWin); - } - } - - - if (done && !levelFinished) - { - levelTimeSec = framesCounter/60; - levelFinished = true; - framesCounter = 0; - } - - if (levelFinished) - { - framesCounter++; - - if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; - } -} - -// Level06 Screen Draw logic -void DrawLevel06Screen(void) -{ - // Draw Level06 screen - DrawRectangleRec(centerRec, LIGHTGRAY); - - for (int i = 0; i < 4; i++) - { - DrawRectangleRec(movingRecs[i], GRAY); - } - - if (!done & (mouseOverNum >= 0)) DrawRectangleLines(movingRecs[mouseOverNum].x - 5, movingRecs[mouseOverNum].y - 5, movingRecs[mouseOverNum].width + 10, movingRecs[mouseOverNum].height + 10, Fade(LIGHTGRAY, 0.8f)); - - if (levelFinished) - { - DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); - DrawText("LEVEL 06", GetScreenWidth()/2 - MeasureText("LEVEL 06", 30)/2, 20, 30, GRAY); - DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); - } - else DrawText("LEVEL 06", GetScreenWidth()/2 - MeasureText("LEVEL 06", 30)/2, 20, 30, LIGHTGRAY); -} - -// Level06 Screen Unload logic -void UnloadLevel06Screen(void) -{ - // TODO: Unload Level06 screen variables here! -} - -// Level06 Screen should finish? -int FinishLevel06Screen(void) -{ - return finishScreen; -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screen_level07.c b/games/just_do_GGJ2015/src/screens/screen_level07.c deleted file mode 100644 index d305b025..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_level07.c +++ /dev/null @@ -1,178 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Level07 Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Level07 screen global variables -static int framesCounter; -static int finishScreen; - -static Vector2 leftCirclePos, middleCirclePos, rightCirclePos; -static Vector2 leftBtnPos, middleBtnPos, rightBtnPos; -static float circleRadius = 100; -static float btnRadius = 80; - -static bool leftCircleActive, middleCircleActive, rightCircleActive; -static Color leftCircleColor, middleCircleColor, rightCircleColor; - -static bool done = false; -static int levelTimeSec = 0; -static bool levelFinished = false; - -//---------------------------------------------------------------------------------- -// Level07 Screen Functions Definition -//---------------------------------------------------------------------------------- -static bool CheckColor(Color col1, Color col2); - -// Level07 Screen Initialization logic -void InitLevel07Screen(void) -{ - // Initialize Level07 screen variables here! - framesCounter = 0; - finishScreen = 0; - - leftCirclePos = (Vector2){ GetScreenWidth()/2 - 340, GetScreenHeight()/2 - 100 }; - middleCirclePos = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 - 100 }; - rightCirclePos = (Vector2){ GetScreenWidth()/2 + 340, GetScreenHeight()/2 - 100 }; - - leftBtnPos = (Vector2){ GetScreenWidth()/2 - 340, GetScreenHeight()/2 + 120 }; - middleBtnPos = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 + 120 }; - rightBtnPos = (Vector2){ GetScreenWidth()/2 + 340, GetScreenHeight()/2 + 120 }; - - leftCircleActive = false; - middleCircleActive = true; - rightCircleActive = false; - - leftCircleColor = GRAY; - middleCircleColor = GRAY; - rightCircleColor = GRAY; -} - -// Level07 Screen Update logic -void UpdateLevel07Screen(void) -{ - // Update Level07 screen variables here! - framesCounter++; - - if (!done) - { - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - { - if (CheckCollisionPointCircle(GetMousePosition(), leftBtnPos, btnRadius)) leftCircleActive = !leftCircleActive; - else if (CheckCollisionPointCircle(GetMousePosition(), middleBtnPos, btnRadius)) middleCircleActive = !middleCircleActive; - else if (CheckCollisionPointCircle(GetMousePosition(), rightBtnPos, btnRadius)) rightCircleActive = !rightCircleActive; - - if (rightCircleActive && CheckCollisionPointCircle(GetMousePosition(), leftCirclePos, circleRadius)) - { - if (CheckColor(leftCircleColor, GRAY)) leftCircleColor = LIGHTGRAY; - else leftCircleColor = GRAY; - } - - if (middleCircleActive && CheckCollisionPointCircle(GetMousePosition(), middleCirclePos, circleRadius)) - { - if (CheckColor(middleCircleColor, GRAY)) middleCircleColor = LIGHTGRAY; - else middleCircleColor = GRAY; - } - - if (rightCircleActive && leftCircleActive && CheckCollisionPointCircle(GetMousePosition(), rightCirclePos, circleRadius)) - { - if (CheckColor(rightCircleColor, GRAY)) rightCircleColor = LIGHTGRAY; - else rightCircleColor = GRAY; - } - } - - // Check all cicles done - if (CheckColor(leftCircleColor, LIGHTGRAY) && CheckColor(middleCircleColor, LIGHTGRAY) && CheckColor(rightCircleColor, LIGHTGRAY) && - !leftCircleActive && !middleCircleActive && !rightCircleActive) - { - done = true; - PlaySound(levelWin); - } - } - - if (done && !levelFinished) - { - levelTimeSec = framesCounter/60; - levelFinished = true; - framesCounter = 0; - } - - if (levelFinished) - { - framesCounter++; - - if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; - } -} - -// Level07 Screen Draw logic -void DrawLevel07Screen(void) -{ - // Draw Level07 screen here! - DrawCircleV(leftCirclePos, circleRadius, leftCircleColor); - DrawCircleV(middleCirclePos, circleRadius, middleCircleColor); - DrawCircleV(rightCirclePos, circleRadius, rightCircleColor); - - if (leftCircleActive) DrawCircleV(leftBtnPos, btnRadius, GRAY); - else DrawCircleV(leftBtnPos, btnRadius, LIGHTGRAY); - - if (middleCircleActive) DrawCircleV(middleBtnPos, btnRadius, GRAY); - else DrawCircleV(middleBtnPos, btnRadius, LIGHTGRAY); - - if (rightCircleActive) DrawCircleV(rightBtnPos, btnRadius, GRAY); - else DrawCircleV(rightBtnPos, btnRadius, LIGHTGRAY); - - - - if (levelFinished) - { - DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); - DrawText("LEVEL 07", GetScreenWidth()/2 - MeasureText("LEVEL 07", 30)/2, 20, 30, GRAY); - DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); - } - else DrawText("LEVEL 07", GetScreenWidth()/2 - MeasureText("LEVEL 07", 30)/2, 20, 30, LIGHTGRAY); -} - -// Level07 Screen Unload logic -void UnloadLevel07Screen(void) -{ - // TODO: Unload Level07 screen variables here! -} - -// Level07 Screen should finish? -int FinishLevel07Screen(void) -{ - return finishScreen; -} - -static bool CheckColor(Color col1, Color col2) -{ - return ((col1.r == col2.r) && (col1.g == col2.g) && (col1.b == col2.b) && (col1.a == col2.a)); -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screen_level08.c b/games/just_do_GGJ2015/src/screens/screen_level08.c deleted file mode 100644 index 4cb0443b..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_level08.c +++ /dev/null @@ -1,157 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Level08 Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Level08 screen global variables -static int framesCounter; -static int finishScreen; - -static Rectangle leftColumnRec, middleColumnRec, rightColumnRec; -static Rectangle movingBox; -static int moveSpeed = 4; - -static bool leftColumnActive, middleColumnActive, rightColumnActive; - -static bool done = false; -static int levelTimeSec = 0; -static bool levelFinished = false; - -//---------------------------------------------------------------------------------- -// Level08 Screen Functions Definition -//---------------------------------------------------------------------------------- - -// Level08 Screen Initialization logic -void InitLevel08Screen(void) -{ - // TODO: Initialize Level08 screen variables here! - framesCounter = 0; - finishScreen = 0; - - movingBox = (Rectangle){ 20, GetScreenHeight()/2 - 20, 40, 40 }; - - leftColumnRec = (Rectangle){ 240, 0, 100, GetScreenHeight() }; - middleColumnRec = (Rectangle){ GetScreenWidth()/2 - 50, 0, 100, GetScreenHeight() }; - rightColumnRec = (Rectangle){ 920, 0, 100, GetScreenHeight() }; - - leftColumnActive = true; - middleColumnActive = false; - rightColumnActive = true; -} - -// Level08 Screen Update logic -void UpdateLevel08Screen(void) -{ - // Update Level08 screen variables here! - framesCounter++; - - if (!done) - { - movingBox.x += moveSpeed; - - if (movingBox.x <= 0) moveSpeed *= -1; - - if ((leftColumnActive && (CheckCollisionRecs(leftColumnRec, movingBox))) || - (middleColumnActive && (CheckCollisionRecs(middleColumnRec, movingBox))) || - (rightColumnActive && (CheckCollisionRecs(rightColumnRec, movingBox)))) moveSpeed *= -1; - - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - { - if (CheckCollisionPointRec(GetMousePosition(), leftColumnRec)) - { - middleColumnActive = false; - rightColumnActive = true; - } - else if (CheckCollisionPointRec(GetMousePosition(), middleColumnRec)) - { - rightColumnActive = false; - leftColumnActive = true; - } - else if (CheckCollisionPointRec(GetMousePosition(), rightColumnRec)) - { - leftColumnActive = false; - middleColumnActive = true; - } - } - - if (movingBox.x >= 1100) - { - done = true; - PlaySound(levelWin); - } - } - - if (done && !levelFinished) - { - levelTimeSec = framesCounter/60; - levelFinished = true; - framesCounter = 0; - } - - if (levelFinished) - { - framesCounter++; - - if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; - } -} - -// Level08 Screen Draw logic -void DrawLevel08Screen(void) -{ - // Draw Level08 screen - DrawRectangle(1100, GetScreenHeight()/2 - 20, 40, 40, GRAY); - - DrawRectangleRec(movingBox, LIGHTGRAY); - - if (leftColumnActive) DrawRectangleRec(leftColumnRec, GRAY); - if (middleColumnActive) DrawRectangleRec(middleColumnRec, GRAY); - if (rightColumnActive) DrawRectangleRec(rightColumnRec, GRAY); - - if (levelFinished) - { - DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); - DrawText("LEVEL 08", GetScreenWidth()/2 - MeasureText("LEVEL 08", 30)/2, 20, 30, GRAY); - DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); - } - else DrawText("LEVEL 08", GetScreenWidth()/2 - MeasureText("LEVEL 08", 30)/2, 20, 30, LIGHTGRAY); -} - -// Level08 Screen Unload logic -void UnloadLevel08Screen(void) -{ - // TODO: Unload Level08 screen variables here! -} - -// Level08 Screen should finish? -int FinishLevel08Screen(void) -{ - return finishScreen; -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screen_level09.c b/games/just_do_GGJ2015/src/screens/screen_level09.c deleted file mode 100644 index d20f4bfb..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_level09.c +++ /dev/null @@ -1,199 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Level09 Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -#define NUM_BOXES 21 - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Level09 screen global variables -static int framesCounter; -static int finishScreen; - -static Rectangle bwRecs[NUM_BOXES]; -static Color bwColors[NUM_BOXES]; -static bool activated[NUM_BOXES]; -static int resetCounter = 0; -static bool enableCounter = 0; - -static bool done = false; -static int levelTimeSec = 0; -static bool levelFinished = false; - -//---------------------------------------------------------------------------------- -// Level09 Screen Functions Definition -//---------------------------------------------------------------------------------- -static bool CheckColor(Color col1, Color col2); - -// Level09 Screen Initialization logic -void InitLevel09Screen(void) -{ - // Initialize Level09 screen variables here! - framesCounter = 0; - finishScreen = 0; - - for (int i = 0; i < NUM_BOXES; i++) - { - bwRecs[i].x = GetScreenWidth()/7*(i%7); - bwRecs[i].y = GetScreenHeight()/3*(i/7); - bwRecs[i].width = GetScreenWidth()/7; - bwRecs[i].height = GetScreenHeight()/3; - - activated[i] = false; - - if (i%2 == 0) bwColors[i] = LIGHTGRAY; - else bwColors[i] = GRAY; - } - - bwColors[10] = RAYWHITE; -} - -// Level09 Screen Update logic -void UpdateLevel09Screen(void) -{ - // Update Level09 screen variables here! - framesCounter++; - if (enableCounter) resetCounter++; - - if (!done) - { - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - { - for (int i = 0; i < NUM_BOXES; i++) - { - if (CheckCollisionPointRec(GetMousePosition(), bwRecs[i])) - { - if (i == 10) - { - if (CheckColor(bwColors[i], RAYWHITE)) - { - bwColors[i] = LIGHTGRAY; - enableCounter = true; - resetCounter = 0; - activated[1] = true; - } - else - { - bwColors[i] = RAYWHITE; - enableCounter = false; - resetCounter = 5*60; - - for (int i = 0; i < NUM_BOXES; i++) activated[i] = false; - } - } - else if ((i%2 == 1) && enableCounter) - { - if (activated[i]) - { - bwColors[i] = LIGHTGRAY; - if (i != 19) activated[i + 2] = true; - } - } - } - } - } - - if (resetCounter > (4*60 + 10)) - { - for (int i = 0; i < NUM_BOXES; i++) - { - if (i%2 == 0) bwColors[i] = LIGHTGRAY; - else bwColors[i] = GRAY; - - activated[i] = false; - } - - bwColors[10] = RAYWHITE; - enableCounter = false; - resetCounter = 0; - } - - for (int i = 0; i < NUM_BOXES; i++) - { - done = true; - - if (!CheckColor(bwColors[i], LIGHTGRAY)) - { - done = false; - return; - } - - //if (done) PlaySound(levelWin); - } - } - - if (done && !levelFinished) - { - levelTimeSec = framesCounter/60; - levelFinished = true; - framesCounter = 0; - } - - if (levelFinished) - { - framesCounter++; - - if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; - } -} - -// Level09 Screen Draw logic -void DrawLevel09Screen(void) -{ - // Draw Level09 screen - for (int i = 0; i < NUM_BOXES; i++) - { - DrawRectangleRec(bwRecs[i], bwColors[i]); - } - - if (levelFinished) - { - DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(RAYWHITE, 0.6f)); - DrawText("LEVEL 09", GetScreenWidth()/2 - MeasureText("LEVEL 09", 30)/2, 20, 30, GRAY); - DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); - } - else DrawText("LEVEL 09", GetScreenWidth()/2 - MeasureText("LEVEL 09", 30)/2, 20, 30, LIGHTGRAY); -} - -// Level09 Screen Unload logic -void UnloadLevel09Screen(void) -{ - // TODO: Unload Level09 screen variables here! -} - -// Level09 Screen should finish? -int FinishLevel09Screen(void) -{ - return finishScreen; -} - -static bool CheckColor(Color col1, Color col2) -{ - return ((col1.r == col2.r) && (col1.g == col2.g) && (col1.b == col2.b) && (col1.a == col2.a)); -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screen_level10.c b/games/just_do_GGJ2015/src/screens/screen_level10.c deleted file mode 100644 index 33806006..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_level10.c +++ /dev/null @@ -1,153 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Level10 Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Level10 screen global variables -static int framesCounter; -static int finishScreen; - -static Rectangle leftColumnRec, middleColumnRec, rightColumnRec; -static Rectangle movingBox; -static int moveSpeed = 4; - -static bool leftColumnActive, middleColumnActive, rightColumnActive; - -static bool done = false; -static int levelTimeSec = 0; -static bool levelFinished = false; - -//---------------------------------------------------------------------------------- -// Level10 Screen Functions Definition -//---------------------------------------------------------------------------------- - -// Level10 Screen Initialization logic -void InitLevel10Screen(void) -{ - // TODO: Initialize Level10 screen variables here! - framesCounter = 0; - finishScreen = 0; - - movingBox = (Rectangle){ 20, GetScreenHeight()/2 - 20, 40, 40 }; - - leftColumnRec = (Rectangle){ 240, 0, 100, GetScreenHeight() }; - middleColumnRec = (Rectangle){ GetScreenWidth()/2 - 50, 0, 100, GetScreenHeight() }; - rightColumnRec = (Rectangle){ 920, 0, 100, GetScreenHeight() }; - - leftColumnActive = true; - middleColumnActive = false; - rightColumnActive = true; -} - -// Level10 Screen Update logic -void UpdateLevel10Screen(void) -{ - // Update Level10 screen variables here! - framesCounter++; - - if (!done) - { - movingBox.x += moveSpeed; - - if (movingBox.x <= 0) moveSpeed *= -1; - - if ((leftColumnActive && (CheckCollisionRecs(leftColumnRec, movingBox))) || - (middleColumnActive && (CheckCollisionRecs(middleColumnRec, movingBox))) || - (rightColumnActive && (CheckCollisionRecs(rightColumnRec, movingBox)))) moveSpeed *= -1; - - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) - { - if (CheckCollisionPointRec(GetMousePosition(), leftColumnRec)) - { - middleColumnActive = false; - rightColumnActive = true; - } - else if (CheckCollisionPointRec(GetMousePosition(), middleColumnRec)) - { - rightColumnActive = false; - leftColumnActive = true; - } - else if (CheckCollisionPointRec(GetMousePosition(), rightColumnRec)) - { - leftColumnActive = false; - middleColumnActive = true; - } - } - } - - if (movingBox.x >= 1100) done = true; - - if (done && !levelFinished) - { - levelTimeSec = framesCounter/60; - levelFinished = true; - framesCounter = 0; - } - - if (levelFinished) - { - framesCounter++; - - if ((framesCounter > 90) && (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) finishScreen = true; - } -} - -// Level10 Screen Draw logic -void DrawLevel10Screen(void) -{ - // Draw Level10 screen - DrawRectangle(1100, GetScreenHeight()/2 - 20, 40, 40, GRAY); - - DrawRectangleRec(movingBox, LIGHTGRAY); - - if (leftColumnActive) DrawRectangleRec(leftColumnRec, GRAY); - if (middleColumnActive) DrawRectangleRec(middleColumnRec, GRAY); - if (rightColumnActive) DrawRectangleRec(rightColumnRec, GRAY); - - if (levelFinished) - { - DrawRectangleBordersRec((Rectangle){0, 0, GetScreenWidth(), GetScreenHeight()}, 0, 0, 60, Fade(LIGHTGRAY, 0.6f)); - DrawText("LEVEL 08", GetScreenWidth()/2 - MeasureText("LEVEL 08", 30)/2, 20, 30, GRAY); - DrawText(FormatText("DONE! (Seconds: %03i)", levelTimeSec), GetScreenWidth()/2 - MeasureText("DONE! (Seconds: 000)", 30)/2, GetScreenHeight() - 40, 30, GRAY); - } - else DrawText("LEVEL 08", GetScreenWidth()/2 - MeasureText("LEVEL 08", 30)/2, 20, 30, LIGHTGRAY); -} - -// Level10 Screen Unload logic -void UnloadLevel10Screen(void) -{ - // TODO: Unload Level10 screen variables here! -} - -// Level10 Screen should finish? -int FinishLevel10Screen(void) -{ - return finishScreen; -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screen_logo.c b/games/just_do_GGJ2015/src/screens/screen_logo.c deleted file mode 100644 index 9639602d..00000000 --- a/games/just_do_GGJ2015/src/screens/screen_logo.c +++ /dev/null @@ -1,227 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Logo Screen Functions Definitions (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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" - -#include - -//---------------------------------------------------------------------------------- -// Global Variables Definition (local to this module) -//---------------------------------------------------------------------------------- - -// Logo screen global variables -static int framesCounter; -static int finishScreen; - -const char msgLogoA[64] = "A simple and easy-to-use library"; -const char msgLogoB[64] = "to learn videogames programming"; - -int logoPositionX; -int logoPositionY; - -int raylibLettersCount = 0; - -int topSideRecWidth = 16; -int leftSideRecHeight = 16; - -int bottomSideRecWidth = 16; -int rightSideRecHeight = 16; - -char raylib[8] = " \0"; // raylib text array, max 8 letters - -int logoScreenState = 0; // Tracking animation states (State Machine) -bool msgLogoADone = false; -bool msgLogoBDone = false; - -int lettersCounter = 0; -char msgBuffer[128] = { ' ' }; - -//---------------------------------------------------------------------------------- -// Logo Screen Functions Definition -//---------------------------------------------------------------------------------- - -// Logo Screen Initialization logic -void InitLogoScreen(void) -{ - // Initialize LOGO screen variables here! - framesCounter = 0; - finishScreen = 0; - - logoPositionX = GetScreenWidth()/2 - 128; - logoPositionY = GetScreenHeight()/2 - 128; -} - -// Logo Screen Update logic -void UpdateLogoScreen(void) -{ - // Update LOGO screen - framesCounter++; // Count frames - - // Update LOGO screen variables - if (logoScreenState == 0) // State 0: Small box blinking - { - framesCounter++; - - if (framesCounter == 120) - { - logoScreenState = 1; - framesCounter = 0; // Reset counter... will be used later... - } - } - else if (logoScreenState == 1) // State 1: Top and left bars growing - { - topSideRecWidth += 4; - leftSideRecHeight += 4; - - if (topSideRecWidth == 256) logoScreenState = 2; - } - else if (logoScreenState == 2) // State 2: Bottom and right bars growing - { - bottomSideRecWidth += 4; - rightSideRecHeight += 4; - - if (bottomSideRecWidth == 256) - { - lettersCounter = 0; - for (int i = 0; i < strlen(msgBuffer); i++) msgBuffer[i] = ' '; - - logoScreenState = 3; - } - } - else if (logoScreenState == 3) // State 3: Letters appearing (one by one) - { - framesCounter++; - - // Every 12 frames, one more letter! - if ((framesCounter%12) == 0) raylibLettersCount++; - - switch (raylibLettersCount) - { - 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; - } - - if (raylibLettersCount >= 10) - { - // Write raylib description messages - if ((framesCounter%2) == 0) lettersCounter++; - - if (!msgLogoADone) - { - if (lettersCounter <= strlen(msgLogoA)) strncpy(msgBuffer, msgLogoA, lettersCounter); - else - { - for (int i = 0; i < strlen(msgBuffer); i++) msgBuffer[i] = ' '; - - lettersCounter = 0; - msgLogoADone = true; - } - } - else if (!msgLogoBDone) - { - if (lettersCounter <= strlen(msgLogoB)) strncpy(msgBuffer, msgLogoB, lettersCounter); - else - { - msgLogoBDone = true; - framesCounter = 0; - PlaySound(levelWin); - } - } - } - } - - // Wait for 2 seconds (60 frames) before jumping to TITLE screen - if (msgLogoBDone) - { - framesCounter++; - - if (framesCounter > 90) finishScreen = true; - } -} - -// Logo Screen Draw logic -void DrawLogoScreen(void) -{ - // Draw LOGO screen - if (logoScreenState == 0) - { - if ((framesCounter/15)%2) DrawRectangle(logoPositionX, logoPositionY - 60, 16, 16, BLACK); - } - else if (logoScreenState == 1) - { - DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK); - DrawRectangle(logoPositionX, logoPositionY - 60, 16, leftSideRecHeight, BLACK); - } - else if (logoScreenState == 2) - { - DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK); - DrawRectangle(logoPositionX, logoPositionY - 60, 16, leftSideRecHeight, BLACK); - - DrawRectangle(logoPositionX + 240, logoPositionY - 60, 16, rightSideRecHeight, BLACK); - DrawRectangle(logoPositionX, logoPositionY + 240 - 60, bottomSideRecWidth, 16, BLACK); - } - else if (logoScreenState == 3) - { - DrawRectangle(logoPositionX, logoPositionY - 60, topSideRecWidth, 16, BLACK); - DrawRectangle(logoPositionX, logoPositionY + 16 - 60, 16, leftSideRecHeight - 32, BLACK); - - DrawRectangle(logoPositionX + 240, logoPositionY + 16 - 60, 16, rightSideRecHeight - 32, BLACK); - DrawRectangle(logoPositionX, logoPositionY + 240 - 60, bottomSideRecWidth, 16, BLACK); - - DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112 - 60, 224, 224, RAYWHITE); - - DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48 - 60, 50, BLACK); - - if (!msgLogoADone) DrawText(msgBuffer, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 230, 30, GRAY); - else - { - DrawText(msgLogoA, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 230, 30, GRAY); - - if (!msgLogoBDone) DrawText(msgBuffer, GetScreenWidth()/2 - MeasureText(msgLogoB, 30)/2, logoPositionY + 280, 30, GRAY); - else - { - DrawText(msgLogoB, GetScreenWidth()/2 - MeasureText(msgLogoA, 30)/2, logoPositionY + 280, 30, GRAY); - } - } - } -} - -// Logo Screen Unload logic -void UnloadLogoScreen(void) -{ - // TODO: Unload LOGO screen variables here! -} - -// Logo Screen should finish? -int FinishLogoScreen(void) -{ - return finishScreen; -} \ No newline at end of file diff --git a/games/just_do_GGJ2015/src/screens/screens.h b/games/just_do_GGJ2015/src/screens/screens.h deleted file mode 100644 index 7fa59405..00000000 --- a/games/just_do_GGJ2015/src/screens/screens.h +++ /dev/null @@ -1,150 +0,0 @@ -/********************************************************************************************** -* -* raylib - Standard Game template -* -* Screens Functions Declarations (Init, Update, Draw, Unload) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -* 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, LEVEL00, LEVEL01, LEVEL02, LEVEL03, LEVEL04, LEVEL05, LEVEL06, LEVEL07, LEVEL08, LEVEL09 } GameScreen; - -//---------------------------------------------------------------------------------- -// Global Variables Definition -//---------------------------------------------------------------------------------- -GameScreen currentScreen; -Sound levelWin; - -#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); - -//---------------------------------------------------------------------------------- -// Level00 Screen Functions Declaration -//---------------------------------------------------------------------------------- -void InitLevel00Screen(void); -void UpdateLevel00Screen(void); -void DrawLevel00Screen(void); -void UnloadLevel00Screen(void); -int FinishLevel00Screen(void); - -//---------------------------------------------------------------------------------- -// Level01 Screen Functions Declaration -//---------------------------------------------------------------------------------- -void InitLevel01Screen(void); -void UpdateLevel01Screen(void); -void DrawLevel01Screen(void); -void UnloadLevel01Screen(void); -int FinishLevel01Screen(void); - -//---------------------------------------------------------------------------------- -// Level02 Screen Functions Declaration -//---------------------------------------------------------------------------------- -void InitLevel02Screen(void); -void UpdateLevel02Screen(void); -void DrawLevel02Screen(void); -void UnloadLevel02Screen(void); -int FinishLevel02Screen(void); - -//---------------------------------------------------------------------------------- -// Level03 Screen Functions Declaration -//---------------------------------------------------------------------------------- -void InitLevel03Screen(void); -void UpdateLevel03Screen(void); -void DrawLevel03Screen(void); -void UnloadLevel03Screen(void); -int FinishLevel03Screen(void); - -//---------------------------------------------------------------------------------- -// Level04 Screen Functions Declaration -//---------------------------------------------------------------------------------- -void InitLevel04Screen(void); -void UpdateLevel04Screen(void); -void DrawLevel04Screen(void); -void UnloadLevel04Screen(void); -int FinishLevel04Screen(void); - -//---------------------------------------------------------------------------------- -// Level05 Screen Functions Declaration -//---------------------------------------------------------------------------------- -void InitLevel05Screen(void); -void UpdateLevel05Screen(void); -void DrawLevel05Screen(void); -void UnloadLevel05Screen(void); -int FinishLevel05Screen(void); - -//---------------------------------------------------------------------------------- -// Level06 Screen Functions Declaration -//---------------------------------------------------------------------------------- -void InitLevel06Screen(void); -void UpdateLevel06Screen(void); -void DrawLevel06Screen(void); -void UnloadLevel06Screen(void); -int FinishLevel06Screen(void); - -//---------------------------------------------------------------------------------- -// Level07 Screen Functions Declaration -//---------------------------------------------------------------------------------- -void InitLevel07Screen(void); -void UpdateLevel07Screen(void); -void DrawLevel07Screen(void); -void UnloadLevel07Screen(void); -int FinishLevel07Screen(void); - -//---------------------------------------------------------------------------------- -// Level08 Screen Functions Declaration -//---------------------------------------------------------------------------------- -void InitLevel08Screen(void); -void UpdateLevel08Screen(void); -void DrawLevel08Screen(void); -void UnloadLevel08Screen(void); -int FinishLevel08Screen(void); - -//---------------------------------------------------------------------------------- -// Level09 Screen Functions Declaration -//---------------------------------------------------------------------------------- -void InitLevel09Screen(void); -void UpdateLevel09Screen(void); -void DrawLevel09Screen(void); -void UnloadLevel09Screen(void); -int FinishLevel09Screen(void); - - -void DrawRectangleBordersRec(Rectangle rec, int offsetX, int offsetY, int borderSize, Color col); - -#ifdef __cplusplus -} -#endif - -#endif // SCREENS_H \ No newline at end of file -- cgit v1.2.3 From 708e8c558cb843b5e4b071bc2b99102533bafaea Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 29 Jan 2016 07:26:06 -0800 Subject: Added a bunch of sample games Those games have been developed by students and ported to a common base template. Some of them still require some review to be consistent with each other (formatting, variables naming, code structure...) --- games/samples/arkanoid.c | 349 ++++++++++++++++ games/samples/asteroids.c | 596 ++++++++++++++++++++++++++ games/samples/asteroids_survival.c | 395 ++++++++++++++++++ games/samples/floppy.c | 246 +++++++++++ games/samples/gold_fever.c | 293 +++++++++++++ games/samples/gorilas.c | 571 +++++++++++++++++++++++++ games/samples/missile_commander.c | 539 ++++++++++++++++++++++++ games/samples/pang.c | 692 ++++++++++++++++++++++++++++++ games/samples/snake.c | 293 +++++++++++++ games/samples/space_invaders.c | 407 ++++++++++++++++++ games/samples/tetris.c | 835 +++++++++++++++++++++++++++++++++++++ 11 files changed, 5216 insertions(+) create mode 100644 games/samples/arkanoid.c create mode 100644 games/samples/asteroids.c create mode 100644 games/samples/asteroids_survival.c create mode 100644 games/samples/floppy.c create mode 100644 games/samples/gold_fever.c create mode 100644 games/samples/gorilas.c create mode 100644 games/samples/missile_commander.c create mode 100644 games/samples/pang.c create mode 100644 games/samples/snake.c create mode 100644 games/samples/space_invaders.c create mode 100644 games/samples/tetris.c (limited to 'games') diff --git a/games/samples/arkanoid.c b/games/samples/arkanoid.c new file mode 100644 index 00000000..f10f9383 --- /dev/null +++ b/games/samples/arkanoid.c @@ -0,0 +1,349 @@ +/******************************************************************************************* +* +* raylib - sample game: arkanoid +* +* Sample game Marc Palau and Ramon Santamaria +* +* This game has been created using raylib v1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include +#include +#include +#include + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Some Defines +//---------------------------------------------------------------------------------- + +#define PLAYER_MAX_LIFE 5 +#define LINES_OF_BRICKS 5 +#define BRICKS_PER_LINE 20 + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef enum GameScreen { LOGO, TITLE, GAMEPLAY, ENDING } GameScreen; + +typedef struct Player { + Vector2 position; + Vector2 size; + int life; +} Player; + +typedef struct Ball { + Vector2 position; + Vector2 speed; + int radius; + bool active; +} Ball; + +typedef struct Brick { + Vector2 position; + bool active; +} Brick; + +//------------------------------------------------------------------------------------ +// Global Variables Declaration +//------------------------------------------------------------------------------------ +static int screenWidth = 800; +static int screenHeight = 450; + +static int framesCounter; +static bool gameOver; +static bool pause; + +static Player player; +static Ball ball; +static Brick brick[LINES_OF_BRICKS][BRICKS_PER_LINE]; +static Vector2 brickSize; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static void InitGame(void); // Initialize game +static void UpdateGame(void); // Update game (one frame) +static void DrawGame(void); // Draw game (one frame) +static void UnloadGame(void); // Unload game +static void UpdateDrawFrame(void); // Update and Draw (one frame) + +// Additional module functions +static void UpdateBall(void); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "sample game: arkanoid"); + + InitGame(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateGame(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + DrawGame(); + //---------------------------------------------------------------------------------- + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadGame(); // Unload loaded data (textures, sounds, models...) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//------------------------------------------------------------------------------------ +// Module Functions Definitions (local) +//------------------------------------------------------------------------------------ + +// Initialize game variables +void InitGame(void) +{ + brickSize = (Vector2){ GetScreenWidth()/BRICKS_PER_LINE, 40 }; + + // Initialize player + player.position = (Vector2){ screenWidth/2, screenHeight*7/8 }; + player.size = (Vector2){ screenWidth/10, 20 }; + player.life = PLAYER_MAX_LIFE; + + // Initialize ball + ball.position = (Vector2){ screenWidth/2, screenHeight*7/8 - 30 }; + ball.speed = (Vector2){ 0, 0 }; + ball.radius = 7; + ball.active = false; + + // Initialize bricks + int initialDownPosition = 50; + + for (int i = 0; i < LINES_OF_BRICKS; i++) + { + for (int j = 0; j < BRICKS_PER_LINE; j++) + { + brick[i][j].position = (Vector2){ j*brickSize.x + brickSize.x/2, i*brickSize.y + initialDownPosition }; + brick[i][j].active = true; + } + } +} + +// Update game (one frame) +void UpdateGame(void) +{ + if (!gameOver) + { + if (IsKeyPressed('P')) pause = !pause; + + if (!pause) + { + // Player movement + if (IsKeyDown(KEY_LEFT)) player.position.x -= 5; + if ((player.position.x - player.size.x/2) <= 0) player.position.x = player.size.x/2; + if (IsKeyDown(KEY_RIGHT)) player.position.x += 5; + if ((player.position.x + player.size.x/2) >= screenWidth) player.position.x = screenWidth - player.size.x/2; + + // Launch ball + if (!ball.active) + { + if (IsKeyPressed(KEY_SPACE)) + { + ball.active = true; + ball.speed = (Vector2){ 0, -5 }; + } + } + + UpdateBall(); + + // Game over logic + if (player.life <= 0) gameOver = true; + else + { + gameOver = true; + + for (int i = 0; i < LINES_OF_BRICKS; i++) + { + for (int j = 0; j < BRICKS_PER_LINE; j++) + { + if (brick[i][j].active) gameOver = false; + } + } + } + } + } + else + { + if (IsKeyPressed(KEY_ENTER)) + { + InitGame(); + gameOver = false; + } + } + + +} + +// Draw game (one frame) +void DrawGame(void) +{ + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (!gameOver) + { + // Draw player bar + DrawRectangle(player.position.x - player.size.x/2, player.position.y - player.size.y/2, player.size.x, player.size.y, BLACK); + + // Draw player lives + for (int i = 0; i < player.life; i++) DrawRectangle(20 + 40*i, screenHeight - 30, 35, 10, LIGHTGRAY); + + // Draw ball + DrawCircleV(ball.position, ball.radius, MAROON); + + // Draw bricks + for (int i = 0; i < LINES_OF_BRICKS; i++) + { + for (int j = 0; j < BRICKS_PER_LINE; j++) + { + if (brick[i][j].active) + { + if ((i + j) % 2 == 0) DrawRectangle(brick[i][j].position.x - brickSize.x/2, brick[i][j].position.y - brickSize.y/2, brickSize.x, brickSize.y, GRAY); + else DrawRectangle(brick[i][j].position.x - brickSize.x/2, brick[i][j].position.y - brickSize.y/2, brickSize.x, brickSize.y, DARKGRAY); + } + } + } + + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); + } + else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); + + EndDrawing(); +} + +// Unload game variables +void UnloadGame(void) +{ + // TODO: Unload all dynamic loaded data (textures, sounds, models...) +} + +// Update and Draw (one frame) +void UpdateDrawFrame(void) +{ + UpdateGame(); + DrawGame(); +} + +//-------------------------------------------------------------------------------------- +// Additional module functions +//-------------------------------------------------------------------------------------- +static void UpdateBall() +{ + // Update position + if (ball.active) + { + ball.position.x += ball.speed.x; + ball.position.y += ball.speed.y; + } + else + { + ball.position = (Vector2){ player.position.x, screenHeight*7/8 - 30 }; + } + + // Bounce in x + if (((ball.position.x + ball.radius) >= screenWidth) || ((ball.position.x - ball.radius) <= 0)) ball.speed.x *= -1; + + // Bounce in y + if ((ball.position.y - ball.radius) <= 0) ball.speed.y *= -1; + + // Ball reaches bottom of the screen + if ((ball.position.y + ball.radius) >= screenHeight) + { + ball.speed = (Vector2){ 0, 0 }; + ball.active = false; + + player.life--; + } + + // Collision logic: ball vs player + if (CheckCollisionCircleRec(ball.position, ball.radius, + (Rectangle){ player.position.x - player.size.x/2, player.position.y - player.size.y/2, player.size.x, player.size.y})) + { + if (ball.speed.y > 0) + { + ball.speed.y *= -1; + ball.speed.x = (ball.position.x - player.position.x)/(player.size.x/2)*5; + } + } + + // Collision logic: ball vs bricks + for (int i = 0; i < LINES_OF_BRICKS; i++) + { + for (int j = 0; j < BRICKS_PER_LINE; j++) + { + if (brick[i][j].active) + { + // Hit below + if (((ball.position.y - ball.radius) <= (brick[i][j].position.y + brickSize.y/2)) && + ((ball.position.y - ball.radius) > (brick[i][j].position.y + brickSize.y/2 + ball.speed.y)) && + ((fabs(ball.position.x - brick[i][j].position.x)) < (brickSize.x/2 + ball.radius*2/3)) && (ball.speed.y < 0)) + { + brick[i][j].active = false; + ball.speed.y *= -1; + } + // Hit above + else if (((ball.position.y + ball.radius) >= (brick[i][j].position.y - brickSize.y/2)) && + ((ball.position.y + ball.radius) < (brick[i][j].position.y - brickSize.y/2 + ball.speed.y)) && + ((fabs(ball.position.x - brick[i][j].position.x)) < (brickSize.x/2 + ball.radius*2/3)) && (ball.speed.y > 0)) + { + brick[i][j].active = false; + ball.speed.y *= -1; + } + // Hit left + else if (((ball.position.x + ball.radius) >= (brick[i][j].position.x - brickSize.x/2)) && + ((ball.position.x + ball.radius) < (brick[i][j].position.x - brickSize.x/2 + ball.speed.x)) && + ((fabs(ball.position.y - brick[i][j].position.y)) < (brickSize.y/2 + ball.radius*2/3)) && (ball.speed.x > 0)) + { + brick[i][j].active = false; + ball.speed.x *= -1; + } + // Hit right + else if (((ball.position.x - ball.radius) <= (brick[i][j].position.x + brickSize.x/2)) && + ((ball.position.x - ball.radius) > (brick[i][j].position.x + brickSize.x/2 + ball.speed.x)) && + ((fabs(ball.position.y - brick[i][j].position.y)) < (brickSize.y/2 + ball.radius*2/3)) && (ball.speed.x < 0)) + { + brick[i][j].active = false; + ball.speed.x *= -1; + } + } + } + } +} \ No newline at end of file diff --git a/games/samples/asteroids.c b/games/samples/asteroids.c new file mode 100644 index 00000000..676b0154 --- /dev/null +++ b/games/samples/asteroids.c @@ -0,0 +1,596 @@ +/******************************************************************************************* +* +* raylib - sample game: asteroids +* +* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria +* +* This game has been created using raylib v1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Some Defines +//---------------------------------------------------------------------------------- +#define MAX_SPEED 6 +#define METEORS_SPEED 2 +#define NUM_SHOOTS 10 +#define NUM_BIG_METEORS 4 +#define NUM_MEDIUM_METEORS 8 +#define NUM_SMALL_METEORS 16 +#define SHIP_BASE_SIZE 20.0f + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- + +typedef struct Player { + Vector2 position; + Vector2 speed; + float acceleration; + float rotation; + Vector3 collider; + Color color; +} Player; + +typedef struct Shoot { + Vector2 position; + Vector2 speed; + float radius; + float rotation; + int lifeSpawn; + bool active; + Color color; +} Shoot; + +typedef struct BigMeteor { + Vector2 position; + Vector2 speed; + float radius; + bool active; + Color color; +} BigMeteor; + +typedef struct MediumMeteor { + Vector2 position; + Vector2 speed; + float radius; + bool active; + Color color; +} MediumMeteor; + +typedef struct SmallMeteor { + Vector2 position; + Vector2 speed; + float radius; + bool active; + Color color; +} SmallMeteor; + +//------------------------------------------------------------------------------------ +// Global Variables Declaration +//------------------------------------------------------------------------------------ +static int screenWidth = 800; +static int screenHeight = 450; + +static int framesCounter; +static bool gameOver; +static bool pause; +static bool victory; + +// NOTE: Defined triangle is isosceles with common angles of 70 degrees. +static float shipHeight; + +static Player player; +static Shoot shoot[NUM_SHOOTS]; +static BigMeteor bigMeteor[NUM_BIG_METEORS]; +static MediumMeteor mediumMeteor[NUM_MEDIUM_METEORS]; +static SmallMeteor smallMeteor[NUM_SMALL_METEORS]; + +static int countMediumMeteors; +static int countSmallMeteors; +static int meteorsDestroyed; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static void InitGame(void); // Initialize game +static void UpdateGame(void); // Update game (one frame) +static void DrawGame(void); // Draw game (one frame) +static void UnloadGame(void); // Unload game +static void UpdateDrawFrame(void); // Update and Draw (one frame) + +static void InitShoot(Shoot shoot); +static void DrawSpaceship(Vector2 position, float rotation, Color color); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "sample game: asteroids"); + + InitGame(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateGame(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + DrawGame(); + //---------------------------------------------------------------------------------- + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadGame(); // Unload loaded data (textures, sounds, models...) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//------------------------------------------------------------------------------------ +// Module Functions Definitions (local) +//------------------------------------------------------------------------------------ + +// Initialize game variables +void InitGame(void) +{ + int posx, posy; + int velx, vely; + bool correctRange = false; + victory = false; + pause = false; + + shipHeight = (SHIP_BASE_SIZE/2)/tanf(20*DEG2RAD); + + // Initialization player + player.position = (Vector2){screenWidth/2, screenHeight/2 - shipHeight/2}; + player.speed = (Vector2){0, 0}; + player.acceleration = 0; + player.rotation = 0; + player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12}; + player.color = LIGHTGRAY; + + meteorsDestroyed = 0; + + //InitShoot(&shoot); + + // Initialization shoot + for (int i = 0; i < NUM_SHOOTS; i++) + { + shoot[i].position = (Vector2){0, 0}; + shoot[i].speed = (Vector2){0, 0}; + shoot[i].radius = 2; + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + shoot[i].color = WHITE; + } + + for (int i = 0; i < NUM_BIG_METEORS; i++) + { + posx = GetRandomValue(0, screenWidth); + + while(!correctRange) + { + if (posx > screenWidth/2 - 150 && posx < screenWidth/2 + 150) posx = GetRandomValue(0, screenWidth); + else correctRange = true; + } + + correctRange = false; + + posy = GetRandomValue(0, screenHeight); + + while(!correctRange) + { + if (posy > screenHeight/2 - 150 && posy < screenHeight/2 + 150) posy = GetRandomValue(0, screenHeight); + else correctRange = true; + } + + bigMeteor[i].position = (Vector2){posx, posy}; + + correctRange = false; + velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + + while(!correctRange) + { + if (velx == 0 && vely == 0) + { + velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + } + else correctRange = true; + } + + bigMeteor[i].speed = (Vector2){velx, vely}; + bigMeteor[i].radius = 40; + bigMeteor[i].active = true; + bigMeteor[i].color = BLUE; + } + + for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + { + mediumMeteor[i].position = (Vector2){-100, -100}; + mediumMeteor[i].speed = (Vector2){0,0}; + mediumMeteor[i].radius = 20; + mediumMeteor[i].active = false; + mediumMeteor[i].color = BLUE; + } + + for (int i = 0; i < NUM_SMALL_METEORS; i++) + { + smallMeteor[i].position = (Vector2){-100, -100}; + smallMeteor[i].speed = (Vector2){0,0}; + smallMeteor[i].radius = 10; + smallMeteor[i].active = false; + smallMeteor[i].color = BLUE; + } + + countMediumMeteors = 0; + countSmallMeteors = 0; +} + +// Update game (one frame) +void UpdateGame(void) +{ + if (!gameOver) + { + if (IsKeyPressed('P')) pause = !pause; + + if (!pause) + { + // Player logic + + // Rotation + if (IsKeyDown(KEY_LEFT)) player.rotation -= 5; + if (IsKeyDown(KEY_RIGHT)) player.rotation += 5; + + // Speed + player.speed.x = sin(player.rotation*DEG2RAD)*MAX_SPEED; + player.speed.y = cos(player.rotation*DEG2RAD)*MAX_SPEED; + + // Controller + if (IsKeyDown(KEY_UP)) + { + if (player.acceleration < 1) player.acceleration += 0.04f; + } + else + { + if (player.acceleration > 0) player.acceleration -= 0.02f; + else if (player.acceleration < 0) player.acceleration = 0; + } + if (IsKeyDown(KEY_DOWN)) + { + if (player.acceleration > 0) player.acceleration -= 0.04f; + else if (player.acceleration < 0) player.acceleration = 0; + } + + // Movement + player.position.x += (player.speed.x*player.acceleration); + player.position.y -= (player.speed.y*player.acceleration); + + // Wall behaviour for player + if (player.position.x > screenWidth + shipHeight) player.position.x = -(shipHeight); + else if (player.position.x < -(shipHeight)) player.position.x = screenWidth + shipHeight; + if (player.position.y > (screenHeight + shipHeight)) player.position.y = -(shipHeight); + else if (player.position.y < -(shipHeight)) player.position.y = screenHeight + shipHeight; + + // Activation of shoot + if (IsKeyPressed(KEY_SPACE)) + { + for (int i = 0; i < NUM_SHOOTS; i++) + { + if (!shoot[i].active) + { + shoot[i].position = (Vector2){ player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight) }; + shoot[i].active = true; + shoot[i].speed.x = 1.5*sin(player.rotation*DEG2RAD)*MAX_SPEED; + shoot[i].speed.y = 1.5*cos(player.rotation*DEG2RAD)*MAX_SPEED; + shoot[i].rotation = player.rotation; + break; + } + } + } + + // Shoot life timer + for (int i = 0; i < NUM_SHOOTS; i++) + { + if (shoot[i].active) shoot[i].lifeSpawn++; + } + + // Shot logic + for (int i = 0; i < NUM_SHOOTS; i++) + { + if (shoot[i].active) + { + // Movement + shoot[i].position.x += shoot[i].speed.x; + shoot[i].position.y -= shoot[i].speed.y; + + // Wall behaviour for shoot + if (shoot[i].position.x > screenWidth + shoot[i].radius) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + } + else if (shoot[i].position.x < 0 - shoot[i].radius) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + } + if (shoot[i].position.y > screenHeight + shoot[i].radius) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + } + else if (shoot[i].position.y < 0 - shoot[i].radius) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + } + + // Life of shoot + if (shoot[i].lifeSpawn >= 60) + { + shoot[i].position = (Vector2){0, 0}; + shoot[i].speed = (Vector2){0, 0}; + shoot[i].lifeSpawn = 0; + shoot[i].active = false; + } + } + } + + // Collision Player to meteors + player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12}; + + for (int a = 0; a < NUM_BIG_METEORS; a++) + { + if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, bigMeteor[a].position, bigMeteor[a].radius) && bigMeteor[a].active) gameOver = true; + } + + for (int a = 0; a < NUM_MEDIUM_METEORS; a++) + { + if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, mediumMeteor[a].position, mediumMeteor[a].radius) && mediumMeteor[a].active) gameOver = true; + } + + for (int a = 0; a < NUM_SMALL_METEORS; a++) + { + if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, smallMeteor[a].position, smallMeteor[a].radius) && smallMeteor[a].active) gameOver = true; + } + + // Meteor logic + for (int i = 0; i < NUM_BIG_METEORS; i++) + { + if (bigMeteor[i].active) + { + // movement + bigMeteor[i].position.x += bigMeteor[i].speed.x; + bigMeteor[i].position.y += bigMeteor[i].speed.y; + + // wall behaviour + if (bigMeteor[i].position.x > screenWidth + bigMeteor[i].radius) bigMeteor[i].position.x = -(bigMeteor[i].radius); + else if (bigMeteor[i].position.x < 0 - bigMeteor[i].radius) bigMeteor[i].position.x = screenWidth + bigMeteor[i].radius; + if (bigMeteor[i].position.y > screenHeight + bigMeteor[i].radius) bigMeteor[i].position.y = -(bigMeteor[i].radius); + else if (bigMeteor[i].position.y < 0 - bigMeteor[i].radius) bigMeteor[i].position.y = screenHeight + bigMeteor[i].radius; + } + } + + for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + { + if (mediumMeteor[i].active) + { + // movement + mediumMeteor[i].position.x += mediumMeteor[i].speed.x; + mediumMeteor[i].position.y += mediumMeteor[i].speed.y; + + // wall behaviour + if (mediumMeteor[i].position.x > screenWidth + mediumMeteor[i].radius) mediumMeteor[i].position.x = -(mediumMeteor[i].radius); + else if (mediumMeteor[i].position.x < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.x = screenWidth + mediumMeteor[i].radius; + if (mediumMeteor[i].position.y > screenHeight + mediumMeteor[i].radius) mediumMeteor[i].position.y = -(mediumMeteor[i].radius); + else if (mediumMeteor[i].position.y < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.y = screenHeight + mediumMeteor[i].radius; + } + } + + for (int i = 0; i < NUM_SMALL_METEORS; i++) + { + if (smallMeteor[i].active) + { + // movement + smallMeteor[i].position.x += smallMeteor[i].speed.x; + smallMeteor[i].position.y += smallMeteor[i].speed.y; + + // wall behaviour + if (smallMeteor[i].position.x > screenWidth + smallMeteor[i].radius) smallMeteor[i].position.x = -(smallMeteor[i].radius); + else if (smallMeteor[i].position.x < 0 - smallMeteor[i].radius) smallMeteor[i].position.x = screenWidth + smallMeteor[i].radius; + if (smallMeteor[i].position.y > screenHeight + smallMeteor[i].radius) smallMeteor[i].position.y = -(smallMeteor[i].radius); + else if (smallMeteor[i].position.y < 0 - smallMeteor[i].radius) smallMeteor[i].position.y = screenHeight + smallMeteor[i].radius; + } + } + + // Collision behaviour + for (int i = 0; i < NUM_SHOOTS; i++) + { + if ((shoot[i].active)) + { + for (int a = 0; a < NUM_BIG_METEORS; a++) + { + if (bigMeteor[a].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, bigMeteor[a].position, bigMeteor[a].radius)) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + bigMeteor[a].active = false; + meteorsDestroyed++; + for (int j = 0; j < 2; j ++) + { + if (countMediumMeteors%2 == 0) + { + mediumMeteor[countMediumMeteors].position = (Vector2){bigMeteor[a].position.x, bigMeteor[a].position.y}; + mediumMeteor[countMediumMeteors].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1}; + } + else + { + mediumMeteor[countMediumMeteors].position = (Vector2){bigMeteor[a].position.x, bigMeteor[a].position.y}; + mediumMeteor[countMediumMeteors].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED}; + } + + mediumMeteor[countMediumMeteors].active = true; + countMediumMeteors ++; + } + //bigMeteor[a].position = (Vector2){-100, -100}; + bigMeteor[a].color = RED; + a = NUM_BIG_METEORS; + } + } + } + if ((shoot[i].active)) + { + for (int b = 0; b < NUM_MEDIUM_METEORS; b++) + { + if (mediumMeteor[b].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, mediumMeteor[b].position, mediumMeteor[b].radius)) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + mediumMeteor[b].active = false; + meteorsDestroyed++; + for (int j = 0; j < 2; j ++) + { + if (countSmallMeteors%2 == 0) + { + smallMeteor[countSmallMeteors].position = (Vector2){mediumMeteor[b].position.x, mediumMeteor[b].position.y}; + smallMeteor[countSmallMeteors].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1}; + } + else + { + smallMeteor[countSmallMeteors].position = (Vector2){mediumMeteor[b].position.x, mediumMeteor[b].position.y}; + smallMeteor[countSmallMeteors].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED}; + } + + smallMeteor[countSmallMeteors].active = true; + countSmallMeteors ++; + } + //mediumMeteor[b].position = (Vector2){-100, -100}; + mediumMeteor[b].color = GREEN; + b = NUM_MEDIUM_METEORS; + } + } + } + if ((shoot[i].active)) + { + for (int c = 0; c < NUM_SMALL_METEORS; c++) + { + if (smallMeteor[c].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, smallMeteor[c].position, smallMeteor[c].radius)) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + smallMeteor[c].active = false; + meteorsDestroyed++; + smallMeteor[c].color = YELLOW; + // smallMeteor[c].position = (Vector2){-100, -100}; + c = NUM_SMALL_METEORS; + } + } + } + } + } + + if (meteorsDestroyed == NUM_BIG_METEORS + NUM_MEDIUM_METEORS + NUM_SMALL_METEORS) victory = true; + } + else + { + if (IsKeyPressed(KEY_ENTER)) + { + InitGame(); + gameOver = false; + } + } +} + +// Draw game (one frame) +void DrawGame(void) +{ + BeginDrawing(); + + ClearBackground(DARKGRAY); + + if (!gameOver) + { + // Draw spaceship + Vector2 v1 = { player.position.x + sinf(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cosf(player.rotation*DEG2RAD)*(shipHeight) }; + Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; + Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; + DrawTriangleLines(v1, v2, v3, player.color); + + // Draw meteors + for (int i = 0; i < NUM_BIG_METEORS; i++) + { + if (bigMeteor[i].active) DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, bigMeteor[i].color); + else DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, Fade(bigMeteor[i].color, 0.25f)); + } + + for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + { + if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, mediumMeteor[i].color); + else DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(mediumMeteor[i].color, 0.25f)); + } + + for (int i = 0; i < NUM_SMALL_METEORS; i++) + { + if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, smallMeteor[i].color); + else DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(smallMeteor[i].color, 0.25f)); + } + + // Draw shoot + for (int i = 0; i < NUM_SHOOTS; i++) + { + if (shoot[i].active) DrawCircleV(shoot[i].position, shoot[i].radius, shoot[i].color); + } + + if (victory) DrawText("VICTORY", screenWidth/2 - MeasureText("VICTORY", 20)/2, screenHeight/2, 20, LIGHTGRAY); + + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); + } + else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); + + EndDrawing(); +} + +// Unload game variables +void UnloadGame(void) +{ + // TODO: Unload all dynamic loaded data (textures, sounds, models...) +} + +// Update and Draw (one frame) +void UpdateDrawFrame(void) +{ + UpdateGame(); + DrawGame(); +} \ No newline at end of file diff --git a/games/samples/asteroids_survival.c b/games/samples/asteroids_survival.c new file mode 100644 index 00000000..e2be9366 --- /dev/null +++ b/games/samples/asteroids_survival.c @@ -0,0 +1,395 @@ +/******************************************************************************************* +* +* raylib - sample game: asteroids survival +* +* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria +* +* This game has been created using raylib v1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Some Defines +//---------------------------------------------------------------------------------- +#define MAX_SPEED 6 +#define METEORS_SPEED 2 +#define NUM_SHOOTS 10 +#define NUM_BIG_METEORS 4 +#define NUM_MEDIUM_METEORS 8 +#define NUM_SMALL_METEORS 16 +#define SHIP_BASE_SIZE 20.0f + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- + +typedef struct Player { + Vector2 position; + Vector2 speed; + float acceleration; + float rotation; + Vector3 collider; + Color color; +} Player; + +typedef struct MediumMeteor { + Vector2 position; + Vector2 speed; + float radius; + bool active; + Color color; +} MediumMeteor; + +typedef struct SmallMeteor { + Vector2 position; + Vector2 speed; + float radius; + bool active; + Color color; +} SmallMeteor; + + +//------------------------------------------------------------------------------------ +// Global Variables Declaration +//------------------------------------------------------------------------------------ +static int screenWidth = 800; +static int screenHeight = 450; + +static int framesCounter; +static bool gameOver; +static bool pause; + +// NOTE: Defined triangle is isosceles with common angles of 70 degrees. +static float shipHeight; + +static Player player; +static MediumMeteor mediumMeteor[NUM_MEDIUM_METEORS]; +static SmallMeteor smallMeteor[NUM_SMALL_METEORS]; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static void InitGame(void); // Initialize game +static void UpdateGame(void); // Update game (one frame) +static void DrawGame(void); // Draw game (one frame) +static void UnloadGame(void); // Unload game +static void UpdateDrawFrame(void); // Update and Draw (one frame) + +static void DrawSpaceship(Vector2 position, float rotation, Color color); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "sample game: asteroids survival"); + + InitGame(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateGame(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + DrawGame(); + //---------------------------------------------------------------------------------- + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadGame(); // Unload loaded data (textures, sounds, models...) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//------------------------------------------------------------------------------------ +// Module Functions Definitions (local) +//------------------------------------------------------------------------------------ + +// Initialize game variables +void InitGame(void) +{ + int posx, posy; + int velx, vely; + bool correctRange = false; + + pause = false; + + framesCounter = 0; + + shipHeight = (SHIP_BASE_SIZE/2)/tanf(20*DEG2RAD); + + // Initialization player + player.position = (Vector2){screenWidth/2, screenHeight/2 - shipHeight/2}; + player.speed = (Vector2){0, 0}; + player.acceleration = 0; + player.rotation = 0; + player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12}; + player.color = LIGHTGRAY; + + for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + { + posx = GetRandomValue(0, screenWidth); + + while(!correctRange) + { + if (posx > screenWidth/2 - 150 && posx < screenWidth/2 + 150) posx = GetRandomValue(0, screenWidth); + else correctRange = true; + } + + correctRange = false; + + posy = GetRandomValue(0, screenHeight); + + while(!correctRange) + { + if (posy > screenHeight/2 - 150 && posy < screenHeight/2 + 150) posy = GetRandomValue(0, screenHeight); + else correctRange = true; + } + + correctRange = false; + velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + + while(!correctRange) + { + if (velx == 0 && vely == 0) + { + velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + } + else correctRange = true; + } + mediumMeteor[i].position = (Vector2){posx, posy}; + mediumMeteor[i].speed = (Vector2){velx, vely}; + mediumMeteor[i].radius = 20; + mediumMeteor[i].active = true; + mediumMeteor[i].color = GREEN; + } + + for (int i = 0; i < NUM_SMALL_METEORS; i++) + { + posx = GetRandomValue(0, screenWidth); + + while(!correctRange) + { + if (posx > screenWidth/2 - 150 && posx < screenWidth/2 + 150) posx = GetRandomValue(0, screenWidth); + else correctRange = true; + } + + correctRange = false; + + posy = GetRandomValue(0, screenHeight); + + while(!correctRange) + { + if (posy > screenHeight/2 - 150 && posy < screenHeight/2 + 150) posy = GetRandomValue(0, screenHeight); + else correctRange = true; + } + + correctRange = false; + velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + + while(!correctRange) + { + if (velx == 0 && vely == 0) + { + velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + } + else correctRange = true; + } + smallMeteor[i].position = (Vector2){posx, posy}; + smallMeteor[i].speed = (Vector2){velx, vely}; + smallMeteor[i].radius = 10; + smallMeteor[i].active = true; + smallMeteor[i].color = YELLOW; + } +} + +// Update game (one frame) +void UpdateGame(void) +{ + if (!gameOver) + { + if (IsKeyPressed('P')) pause = !pause; + + if (!pause) + { + framesCounter++; + + // Player logic + + // Rotation + if (IsKeyDown(KEY_LEFT)) player.rotation -= 5; + if (IsKeyDown(KEY_RIGHT)) player.rotation += 5; + + // Speed + player.speed.x = sin(player.rotation*DEG2RAD)*MAX_SPEED; + player.speed.y = cos(player.rotation*DEG2RAD)*MAX_SPEED; + + // Controller + if (IsKeyDown(KEY_UP)) + { + if (player.acceleration < 1) player.acceleration += 0.04f; + } + else + { + if (player.acceleration > 0) player.acceleration -= 0.02f; + else if (player.acceleration < 0) player.acceleration = 0; + } + if (IsKeyDown(KEY_DOWN)) + { + if (player.acceleration > 0) player.acceleration -= 0.04f; + else if (player.acceleration < 0) player.acceleration = 0; + } + + // Movement + player.position.x += (player.speed.x*player.acceleration); + player.position.y -= (player.speed.y*player.acceleration); + + // Wall behaviour for player + if (player.position.x > screenWidth + shipHeight) player.position.x = -(shipHeight); + else if (player.position.x < -(shipHeight)) player.position.x = screenWidth + shipHeight; + if (player.position.y > (screenHeight + shipHeight)) player.position.y = -(shipHeight); + else if (player.position.y < -(shipHeight)) player.position.y = screenHeight + shipHeight; + + // Collision Player to meteors + player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12}; + + for (int a = 0; a < NUM_MEDIUM_METEORS; a++) + { + if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, mediumMeteor[a].position, mediumMeteor[a].radius) && mediumMeteor[a].active) gameOver = true; + } + + for (int a = 0; a < NUM_SMALL_METEORS; a++) + { + if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, smallMeteor[a].position, smallMeteor[a].radius) && smallMeteor[a].active) gameOver = true; + } + + // Meteor logic + + for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + { + if (mediumMeteor[i].active) + { + // movement + mediumMeteor[i].position.x += mediumMeteor[i].speed.x; + mediumMeteor[i].position.y += mediumMeteor[i].speed.y; + + // wall behaviour + if (mediumMeteor[i].position.x > screenWidth + mediumMeteor[i].radius) mediumMeteor[i].position.x = -(mediumMeteor[i].radius); + else if (mediumMeteor[i].position.x < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.x = screenWidth + mediumMeteor[i].radius; + if (mediumMeteor[i].position.y > screenHeight + mediumMeteor[i].radius) mediumMeteor[i].position.y = -(mediumMeteor[i].radius); + else if (mediumMeteor[i].position.y < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.y = screenHeight + mediumMeteor[i].radius; + } + } + + for (int i = 0; i < NUM_SMALL_METEORS; i++) + { + if (smallMeteor[i].active) + { + // movement + smallMeteor[i].position.x += smallMeteor[i].speed.x; + smallMeteor[i].position.y += smallMeteor[i].speed.y; + + // wall behaviour + if (smallMeteor[i].position.x > screenWidth + smallMeteor[i].radius) smallMeteor[i].position.x = -(smallMeteor[i].radius); + else if (smallMeteor[i].position.x < 0 - smallMeteor[i].radius) smallMeteor[i].position.x = screenWidth + smallMeteor[i].radius; + if (smallMeteor[i].position.y > screenHeight + smallMeteor[i].radius) smallMeteor[i].position.y = -(smallMeteor[i].radius); + else if (smallMeteor[i].position.y < 0 - smallMeteor[i].radius) smallMeteor[i].position.y = screenHeight + smallMeteor[i].radius; + } + } + } + } + else + { + if (IsKeyPressed(KEY_ENTER)) + { + InitGame(); + gameOver = false; + } + } +} + +// Draw game (one frame) +void DrawGame(void) +{ + BeginDrawing(); + + ClearBackground(DARKGRAY); + + if (!gameOver) + { + // Draw spaceship + Vector2 v1 = { player.position.x + sinf(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cosf(player.rotation*DEG2RAD)*(shipHeight) }; + Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; + Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; + + DrawTriangleLines(v1, v2, v3, player.color); + + // Draw meteor + for (int i = 0;i < NUM_MEDIUM_METEORS; i++) + { + if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, mediumMeteor[i].color); + else DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(mediumMeteor[i].color, 0.25f)); + } + + for (int i = 0;i < NUM_SMALL_METEORS; i++) + { + if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, smallMeteor[i].color); + else DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(smallMeteor[i].color, 0.25f)); + } + + DrawText(FormatText("SURVIVAL TIME: %.02f", (float)framesCounter/60), 10, 10, 20, WHITE); + + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); + } + else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- +} + +// Unload game variables +void UnloadGame(void) +{ + // TODO: Unload all dynamic loaded data (textures, sounds, models...) +} + +// Update and Draw (one frame) +void UpdateDrawFrame(void) +{ + UpdateGame(); + DrawGame(); +} \ No newline at end of file diff --git a/games/samples/floppy.c b/games/samples/floppy.c new file mode 100644 index 00000000..d66f5bbe --- /dev/null +++ b/games/samples/floppy.c @@ -0,0 +1,246 @@ +/******************************************************************************************* +* +* raylib - sample game: floppy +* +* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria +* +* This game has been created using raylib v1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Some Defines +//---------------------------------------------------------------------------------- +#define MAX_TUBES 100 +#define FLOPPY_RADIUS 24 +#define TUBES_WIDTH 80 + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef struct Floppy { + Vector2 position; + int radius; + Color color; +} Floppy; + +typedef struct Tubes { + Rectangle rec; + Color color; + bool active; +} Tubes; + +//------------------------------------------------------------------------------------ +// Global Variables Declaration +//------------------------------------------------------------------------------------ +static int screenWidth = 800; +static int screenHeight = 450; + +static int framesCounter; +static bool gameOver; +static bool pause; +static int score; +static int hiScore = 0; + +static Floppy floppy; +static Tubes tubes[MAX_TUBES*2]; +static Vector2 tubesPos[MAX_TUBES]; +static int tubesSpeedX; +static bool superfx; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static void InitGame(void); // Initialize game +static void UpdateGame(void); // Update game (one frame) +static void DrawGame(void); // Draw game (one frame) +static void UnloadGame(void); // Unload game +static void UpdateDrawFrame(void); // Update and Draw (one frame) + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "sample game: floppy"); + + InitGame(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateGame(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + DrawGame(); + //---------------------------------------------------------------------------------- + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadGame(); // Unload loaded data (textures, sounds, models...) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} +//------------------------------------------------------------------------------------ +// Module Functions Definitions (local) +//------------------------------------------------------------------------------------ + +// Initialize game variables +void InitGame(void) +{ + floppy.radius = FLOPPY_RADIUS; + floppy.position = (Vector2){80, screenHeight/2 - floppy.radius}; + tubesSpeedX = 2; + + for (int i = 0; i < MAX_TUBES; i++) + { + tubesPos[i].x = 400 + 280*i; + tubesPos[i].y = -GetRandomValue(0, 120); + } + + for (int i = 0; i < MAX_TUBES*2; i += 2) + { + tubes[i].rec.x = tubesPos[i/2].x; + tubes[i].rec.y = tubesPos[i/2].y; + tubes[i].rec.width = TUBES_WIDTH; + tubes[i].rec.height = 255; + + tubes[i+1].rec.x = tubesPos[i/2].x; + tubes[i+1].rec.y = 600 + tubesPos[i/2].y - 255; + tubes[i+1].rec.width = TUBES_WIDTH; + tubes[i+1].rec.height = 255; + + tubes[i/2].active = true; + } + + score = 0; + + gameOver = false; + superfx = false; + pause = false; +} + +// Update game (one frame) +void UpdateGame(void) +{ + if (!gameOver) + { + if (IsKeyPressed('P')) pause = !pause; + + if (!pause) + { + for (int i = 0; i < MAX_TUBES; i++) tubesPos[i].x -= tubesSpeedX; + + for (int i = 0; i < MAX_TUBES*2; i += 2) + { + tubes[i].rec.x = tubesPos[i/2].x; + tubes[i+1].rec.x = tubesPos[i/2].x; + } + + if (IsKeyDown(KEY_SPACE) && !gameOver) floppy.position.y -= 3; + else floppy.position.y += 1; + + // Check Collisions + for (int i = 0; i < MAX_TUBES*2; i++) + { + if (CheckCollisionCircleRec(floppy.position, floppy.radius, tubes[i].rec)) + { + gameOver = true; + pause = false; + } + else if ((tubesPos[i/2].x < floppy.position.x) && tubes[i/2].active && !gameOver) + { + score += 100; + tubes[i/2].active = false; + + superfx = true; + + if (score > hiScore) hiScore = score; + } + } + } + } + else + { + if (IsKeyPressed(KEY_ENTER)) + { + InitGame(); + gameOver = false; + } + } +} + +// Draw game (one frame) +void DrawGame(void) +{ + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (!gameOver) + { + DrawCircle(floppy.position.x, floppy.position.y, floppy.radius, BLUE); + + // Draw tubes + for (int i = 0; i < MAX_TUBES; i++) + { + DrawRectangle(tubes[i*2].rec.x, tubes[i*2].rec.y, tubes[i*2].rec.width, tubes[i*2].rec.height, RED); + DrawRectangle(tubes[i*2 + 1].rec.x, tubes[i*2 + 1].rec.y, tubes[i*2 + 1].rec.width, tubes[i*2 + 1].rec.height, RED); + } + + // Draw flashing fx (one frame only) + if (superfx) + { + DrawRectangle(0, 0, screenWidth, screenHeight, GOLD); + superfx = false; + } + + DrawText(FormatText("%04i", score), 20, 20, 40, PINK); + DrawText(FormatText("HI-SCORE: %04i", hiScore), 20, 70, 20, VIOLET); + + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); + } + else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); + + EndDrawing(); +} + +// Unload game variables +void UnloadGame(void) +{ + // TODO: Unload all dynamic loaded data (textures, sounds, models...) +} + +// Update and Draw (one frame) +void UpdateDrawFrame(void) +{ + UpdateGame(); + DrawGame(); +} \ No newline at end of file diff --git a/games/samples/gold_fever.c b/games/samples/gold_fever.c new file mode 100644 index 00000000..d4c0d99f --- /dev/null +++ b/games/samples/gold_fever.c @@ -0,0 +1,293 @@ +/******************************************************************************************* +* +* raylib - sample game: gold fever +* +* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria +* +* This game has been created using raylib v1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef struct Player { + Vector2 position; + int radius; + Vector2 speed; + Color color; +} Player; + +typedef struct Enemy { + Vector2 position; + int radius; + int radiusBounds; + Vector2 speed; + bool moveRight; + Color colorBounds; + Color color; +} Enemy; + +typedef struct Points { + Vector2 position; + int radius; + int value; + bool active; + Color color; +} Points; + +typedef struct Exit { + Rectangle rec; + bool active; + bool save; + Color color; +} Exit; + +//------------------------------------------------------------------------------------ +// Global Variables Declaration +//------------------------------------------------------------------------------------ +static int screenWidth = 800; +static int screenHeight = 450; + +static int framesCounter; +static bool gameOver; +static bool pause; +static int score; +static int hiScore = 0; + +static Player player; +static Enemy enemy; +static Points points; +static Exit exit; +static bool follow; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static void InitGame(void); // Initialize game +static void UpdateGame(void); // Update game (one frame) +static void DrawGame(void); // Draw game (one frame) +static void UnloadGame(void); // Unload game +static void UpdateDrawFrame(void); // Update and Draw (one frame) + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + + InitWindow(screenWidth, screenHeight, "sample game: gold fever"); + + InitGame(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateGame(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + DrawGame(); + //---------------------------------------------------------------------------------- + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadGame(); // Unload loaded data (textures, sounds, models...) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//------------------------------------------------------------------------------------ +// Module Functions Definitions (local) +//------------------------------------------------------------------------------------ + +// Initialize game variables +void InitGame(void) +{ + pause = false; + score = 0; + + player.position = (Vector2){50, 50}; + player.radius = 20; + player.speed = (Vector2){5, 5}; + player.color = DARKGRAY; + + enemy.position = (Vector2){screenWidth - 50, screenHeight/2}; + enemy.radius = 20; + enemy.radiusBounds = 150; + enemy.speed = (Vector2){3, 3}; + enemy.moveRight = true; + enemy.color = MAROON; + enemy.colorBounds = RED; + follow = false; + + points.radius = 10; + points.position = (Vector2){GetRandomValue(points.radius, screenWidth - points.radius), GetRandomValue(points.radius, screenHeight - points.radius)}; + points.value = 100; + points.active = true; + points.color = GOLD; + + exit.rec.width = 50; + exit.rec.height = 50; + exit.rec.x = GetRandomValue(0, screenWidth - exit.rec.width); + exit.rec.y = GetRandomValue(0, screenHeight - exit.rec.height); + exit.active = false; + exit.save = false; + exit.color = PINK; +} + +// Update game (one frame) +void UpdateGame(void) +{ + if (!gameOver) + { + if (IsKeyPressed('P')) pause = !pause; + + if (!pause) + { + //Control player + if (IsKeyDown(KEY_RIGHT)) player.position.x += player.speed.x; + if (IsKeyDown(KEY_LEFT)) player.position.x -= player.speed.x; + if (IsKeyDown(KEY_UP)) player.position.y -= player.speed.y; + if (IsKeyDown(KEY_DOWN)) player.position.y += player.speed.y; + + //wall behaviour player + if (player.position.x - player.radius <= 0) player.position.x = player.radius; + if (player.position.x + player.radius >= screenWidth) player.position.x = screenWidth - player.radius; + if (player.position.y - player.radius <= 0) player.position.y = player.radius; + if (player.position.y + player.radius >= screenHeight) player.position.y = screenHeight - player.radius; + + //IA Enemy + if ( (follow || CheckCollisionCircles(player.position, player.radius, enemy.position, enemy.radiusBounds)) && !exit.save) + { + if (player.position.x > enemy.position.x) enemy.position.x += enemy.speed.x; + if (player.position.x < enemy.position.x) enemy.position.x -= enemy.speed.x; + + if (player.position.y > enemy.position.y) enemy.position.y += enemy.speed.y; + if (player.position.y < enemy.position.y) enemy.position.y -= enemy.speed.y; + } + else + { + if (enemy.moveRight) enemy.position.x += enemy.speed.x; + else enemy.position.x -= enemy.speed.x; + } + + //wall behaviour enemy + if (enemy.position.x - enemy.radius <= 0) enemy.moveRight = true; + if (enemy.position.x + enemy.radius >= screenWidth) enemy.moveRight = false; + + if (enemy.position.x - enemy.radius <= 0) enemy.position.x = enemy.radius; + if (enemy.position.x + enemy.radius >= screenWidth) enemy.position.x = screenWidth - enemy.radius; + if (enemy.position.y - enemy.radius <= 0) enemy.position.y = enemy.radius; + if (enemy.position.y + enemy.radius >= screenHeight) enemy.position.y = screenHeight - enemy.radius; + + //Collisions + if (CheckCollisionCircles(player.position, player.radius, points.position, points.radius) && points.active) + { + follow = true; + points.active = false; + exit.active = true; + } + + if (CheckCollisionCircles(player.position, player.radius, enemy.position, enemy.radius) && !exit.save) + { + gameOver = true; + + if (hiScore < score) hiScore = score; + } + + if (CheckCollisionCircleRec(player.position, player.radius, exit.rec)) + { + follow = false; + + if (!points.active) + { + score += points.value; + points.active = true; + enemy.speed.x += 0.5; + enemy.speed.y += 0.5; + points.position = (Vector2){GetRandomValue(points.radius, screenWidth - points.radius), GetRandomValue(points.radius, screenHeight - points.radius)}; + } + + exit.save = true; + } + else exit.save = false; + } + } + else + { + if (IsKeyPressed(KEY_ENTER)) + { + InitGame(); + gameOver = false; + } + } +} + +// Draw game (one frame) +void DrawGame(void) +{ + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (!gameOver) + { + if (follow) ClearBackground(RED); + + DrawCircleLines(enemy.position.x, enemy.position.y, enemy.radiusBounds, enemy.colorBounds); + DrawCircleV(enemy.position, enemy.radius, enemy.color); + + DrawCircleV(player.position, player.radius, player.color); + DrawCircleV(points.position, points.radius, points.color); + + if (exit.active) DrawRectangleRec(exit.rec, exit.color); + + DrawText(FormatText("SCORE: %04i", score), 10, 10, 20, GRAY); + DrawText(FormatText("HI-SCORE: %04i", hiScore), 300, 10, 20, GRAY); + + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); + } + else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); + + EndDrawing(); +} + +// Unload game variables +void UnloadGame(void) +{ + // TODO: Unload all dynamic loaded data (textures, sounds, models...) +} + +// Update and Draw (one frame) +void UpdateDrawFrame(void) +{ + UpdateGame(); + DrawGame(); +} \ No newline at end of file diff --git a/games/samples/gorilas.c b/games/samples/gorilas.c new file mode 100644 index 00000000..86fd3f5b --- /dev/null +++ b/games/samples/gorilas.c @@ -0,0 +1,571 @@ +/******************************************************************************************* +* +* raylib - sample game: gorilas +* +* Sample game Marc Palau and Ramon Santamaria +* +* This game has been created using raylib v1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include +#include +#include +#include + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Some Defines +//---------------------------------------------------------------------------------- +#define MAX_BUILDINGS 15 +#define MAX_EXPLOSIONS 200 +#define MAX_PLAYERS 2 + +#define BUILDING_RELATIVE_ERROR 30 // Building size random range % +#define BUILDING_MIN_RELATIVE_HEIGHT 20 // Minimum height in % of the screenHeight +#define BUILDING_MAX_RELATIVE_HEIGHT 60 // Maximum height in % of the screenHeight +#define BUILDING_MIN_GRAYSCALE_COLOR 120 // Minimum gray color for the buildings +#define BUILDING_MAX_GRAYSCALE_COLOR 200 // Maximum gray color for the buildings + +#define MIN_PLAYER_POSITION 5 // Minimum x position % +#define MAX_PLAYER_POSITION 20 // Maximum x position % + +#define GRAVITY 9.81f +#define DELTA_FPS 60 + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef struct Player { + Vector2 position; + Vector2 size; + + Vector2 aimingPoint; + int aimingAngle; + int aimingPower; + + Vector2 previousPoint; + int previousAngle; + int previousPower; + + Vector2 impactPoint; + + bool isLeftTeam; // This player belongs to the left or to the right team + bool isPlayer; // If is a player or an AI + bool isAlive; +} Player; + +typedef struct Building { + Rectangle rectangle; + Color color; +} Building; + +typedef struct Explosion { + Vector2 position; + int radius; + bool active; +} Explosion; + +typedef struct Ball { + Vector2 position; + Vector2 speed; + int radius; + bool active; +} Ball; + +//------------------------------------------------------------------------------------ +// Global Variables Declaration +//------------------------------------------------------------------------------------ +static int screenWidth = 800; +static int screenHeight = 450; + +static bool gameOver = false; +static bool pause = false; + +static Player player[MAX_PLAYERS]; +static Building building[MAX_BUILDINGS]; +static Explosion explosion[MAX_EXPLOSIONS]; +static Ball ball; + +static int playerTurn = 0; +static bool ballOnAir = false; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static void InitGame(void); // Initialize game +static void UpdateGame(void); // Update game (one frame) +static void DrawGame(void); // Draw game (one frame) +static void UnloadGame(void); // Unload game +static void UpdateDrawFrame(void); // Update and Draw (one frame) + +// Additional module functions +static void InitBuildings(void); +static void InitPlayers(void); +static bool UpdatePlayer(int playerTurn); +static bool UpdateBall(int playerTurn); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "sample game: gorilas"); + + InitGame(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateGame(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + DrawGame(); + //---------------------------------------------------------------------------------- + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadGame(); // Unload loaded data (textures, sounds, models...) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//------------------------------------------------------------------------------------ +// Module Functions Definitions (local) +//------------------------------------------------------------------------------------ + +// Initialize game variables +void InitGame(void) +{ + // Init shoot + ball.radius = 10; + ballOnAir = false; + ball.active = false; + + InitBuildings(); + InitPlayers(); + + // Init explosions + for (int i = 0; i < MAX_EXPLOSIONS; i++) + { + explosion[i].position = (Vector2){ 0.0f, 0.0f }; + explosion[i].radius = 30; + explosion[i].active = false; + } +} + +// Update game (one frame) +void UpdateGame(void) +{ + if (!gameOver) + { + if (IsKeyPressed('P')) pause = !pause; + + if (!pause) + { + if (!ballOnAir) ballOnAir = UpdatePlayer(playerTurn); // If we are aiming + else + { + if (UpdateBall(playerTurn)) // If collision + { + // Game over logic + bool leftTeamAlive = false; + bool rightTeamAlive = false; + + for (int i = 0; i < MAX_PLAYERS; i++) + { + if (player[i].isAlive) + { + if (player[i].isLeftTeam) leftTeamAlive = true; + if (!player[i].isLeftTeam) rightTeamAlive = true; + } + } + + if (leftTeamAlive && rightTeamAlive) + { + ballOnAir = false; + ball.active = false; + + playerTurn++; + + if (playerTurn == MAX_PLAYERS) playerTurn = 0; + } + else + { + gameOver = true; + + // if (leftTeamAlive) left team wins + // if (rightTeamAlive) right team wins + } + } + } + } + } + else + { + if (IsKeyPressed(KEY_ENTER)) + { + InitGame(); + gameOver = false; + } + } +} + +// Draw game (one frame) +void DrawGame(void) +{ + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (!gameOver) + { + // Draw buildings + for (int i = 0; i < MAX_BUILDINGS; i++) DrawRectangleRec(building[i].rectangle, building[i].color); + + // Draw explosions + for (int i = 0; i < MAX_EXPLOSIONS; i++) + { + if (explosion[i].active) DrawCircle(explosion[i].position.x, explosion[i].position.y, explosion[i].radius, RAYWHITE); + } + + // Draw players + for (int i = 0; i < MAX_PLAYERS; i++) + { + if (player[i].isAlive) + { + if (player[i].isLeftTeam) DrawRectangle(player[i].position.x - player[i].size.x/2, player[i].position.y - player[i].size.y/2, + player[i].size.x, player[i].size.y, BLUE); + else DrawRectangle(player[i].position.x - player[i].size.x/2, player[i].position.y - player[i].size.y/2, + player[i].size.x, player[i].size.y, RED); + } + } + + // Draw ball + if (ball.active) DrawCircle(ball.position.x, ball.position.y, ball.radius, MAROON); + + // Draw the angle and the power of the aim, and the previous ones + if (!ballOnAir) + { + // Draw shot information + /* + if (player[playerTurn].isLeftTeam) + { + DrawText(FormatText("Previous Point %i, %i", (int)player[playerTurn].previousPoint.x, (int)player[playerTurn].previousPoint.y), 20, 20, 20, DARKBLUE); + DrawText(FormatText("Previous Angle %i", player[playerTurn].previousAngle), 20, 50, 20, DARKBLUE); + DrawText(FormatText("Previous Power %i", player[playerTurn].previousPower), 20, 80, 20, DARKBLUE); + DrawText(FormatText("Aiming Point %i, %i", (int)player[playerTurn].aimingPoint.x, (int)player[playerTurn].aimingPoint.y), 20, 110, 20, DARKBLUE); + DrawText(FormatText("Aiming Angle %i", player[playerTurn].aimingAngle), 20, 140, 20, DARKBLUE); + DrawText(FormatText("Aiming Power %i", player[playerTurn].aimingPower), 20, 170, 20, DARKBLUE); + } + else + { + DrawText(FormatText("Previous Point %i, %i", (int)player[playerTurn].previousPoint.x, (int)player[playerTurn].previousPoint.y), screenWidth*3/4, 20, 20, DARKBLUE); + DrawText(FormatText("Previous Angle %i", player[playerTurn].previousAngle), screenWidth*3/4, 50, 20, DARKBLUE); + DrawText(FormatText("Previous Power %i", player[playerTurn].previousPower), screenWidth*3/4, 80, 20, DARKBLUE); + DrawText(FormatText("Aiming Point %i, %i", (int)player[playerTurn].aimingPoint.x, (int)player[playerTurn].aimingPoint.y), screenWidth*3/4, 110, 20, DARKBLUE); + DrawText(FormatText("Aiming Angle %i", player[playerTurn].aimingAngle), screenWidth*3/4, 140, 20, DARKBLUE); + DrawText(FormatText("Aiming Power %i", player[playerTurn].aimingPower), screenWidth*3/4, 170, 20, DARKBLUE); + } + */ + + // Draw aim + if (player[playerTurn].isLeftTeam) + { + // Previous aiming + DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 }, + (Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 }, + player[playerTurn].previousPoint, GRAY); + + // Actual aiming + DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 }, + (Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 }, + player[playerTurn].aimingPoint, DARKBLUE); + } + else + { + // Previous aiming + DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 }, + (Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 }, + player[playerTurn].previousPoint, GRAY); + + // Actual aiming + DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 }, + (Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 }, + player[playerTurn].aimingPoint, MAROON); + } + } + + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); + } + else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); + + EndDrawing(); +} + +// Unload game variables +void UnloadGame(void) +{ + // TODO: Unload all dynamic loaded data (textures, sounds, models...) +} + +// Update and Draw (one frame) +void UpdateDrawFrame(void) +{ + UpdateGame(); + DrawGame(); +} + +//-------------------------------------------------------------------------------------- +// Additional module functions +//-------------------------------------------------------------------------------------- +static void InitBuildings(void) +{ + // Horizontal generation + int currentWidth = 0; + + // We make sure the absolute error randomly generated for each building, has as a minimum value the screenWidth. + // This way all the screen will be filled with buildings. Each building will have a different, random width. + + float relativeWidth = 100/(100 - BUILDING_RELATIVE_ERROR); + float buildingWidthMean = (screenWidth*relativeWidth/MAX_BUILDINGS) + 1; // We add one to make sure we will cover the whole screen. + + // Vertical generation + int currentHeighth = 0; + int grayLevel; + + // Creation + for (int i = 0; i < MAX_BUILDINGS; i++) + { + // Horizontal + building[i].rectangle.x = currentWidth; + building[i].rectangle.width = GetRandomValue(buildingWidthMean*(100 - BUILDING_RELATIVE_ERROR/2)/100 + 1, buildingWidthMean*(100 + BUILDING_RELATIVE_ERROR)/100); + + currentWidth += building[i].rectangle.width; + + // Vertical + currentHeighth = GetRandomValue(BUILDING_MIN_RELATIVE_HEIGHT, BUILDING_MAX_RELATIVE_HEIGHT); + building[i].rectangle.y = screenHeight - (screenHeight*currentHeighth/100); + building[i].rectangle.height = screenHeight*currentHeighth/100 + 1; + + // Color + grayLevel = GetRandomValue(BUILDING_MIN_GRAYSCALE_COLOR, BUILDING_MAX_GRAYSCALE_COLOR); + building[i].color = (Color){ grayLevel, grayLevel, grayLevel, 255 }; + } +} + +static void InitPlayers(void) +{ + for (int i = 0; i < MAX_PLAYERS; i++) + { + player[i].isAlive = true; + + // Decide the team of this player + if (i % 2 == 0) player[i].isLeftTeam = true; + else player[i].isLeftTeam = false; + + // Now there is no AI + player[i].isPlayer = true; + + // Set size, by default by now + player[i].size = (Vector2){ 40, 40 }; + + // Set position + if (player[i].isLeftTeam) player[i].position.x = GetRandomValue(screenWidth*MIN_PLAYER_POSITION/100, screenWidth*MAX_PLAYER_POSITION/100); + else player[i].position.x = screenWidth - GetRandomValue(screenWidth*MIN_PLAYER_POSITION/100, screenWidth*MAX_PLAYER_POSITION/100); + + for (int j = 0; j < MAX_BUILDINGS; j++) + { + if (building[j].rectangle.x > player[i].position.x) + { + // Set the player in the center of the building + player[i].position.x = building[j-1].rectangle.x + building[j-1].rectangle.width/2; + // Set the player at the top of the building + player[i].position.y = building[j-1].rectangle.y - player[i].size.y/2; + break; + } + } + + // Set statistics to 0 + player[i].aimingPoint = player[i].position; + player[i].previousAngle = 0; + player[i].previousPower = 0; + player[i].previousPoint = player[i].position; + player[i].aimingAngle = 0; + player[i].aimingPower = 0; + + player[i].impactPoint = (Vector2){ -100, -100 }; + } +} + +static bool UpdatePlayer(int playerTurn) +{ + // If we are aiming at the firing quadrant, we calculate the angle + if (GetMousePosition().y <= player[playerTurn].position.y) + { + // Left team + if (player[playerTurn].isLeftTeam && GetMousePosition().x >= player[playerTurn].position.x) + { + // Distance (calculating the fire power) + player[playerTurn].aimingPower = sqrt(pow(player[playerTurn].position.x - GetMousePosition().x, 2) + pow(player[playerTurn].position.y - GetMousePosition().y, 2)); + // Calculates the angle via arcsin + player[playerTurn].aimingAngle = asin((player[playerTurn].position.y - GetMousePosition().y)/player[playerTurn].aimingPower)*RAD2DEG; + // Point of the screen we are aiming at + player[playerTurn].aimingPoint = GetMousePosition(); + + // Ball fired + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + player[playerTurn].previousPoint = player[playerTurn].aimingPoint; + player[playerTurn].previousPower = player[playerTurn].aimingPower; + player[playerTurn].previousAngle = player[playerTurn].aimingAngle; + ball.position = player[playerTurn].position; + + return true; + } + } + // Right team + else if (!player[playerTurn].isLeftTeam && GetMousePosition().x <= player[playerTurn].position.x) + { + // Distance (calculating the fire power) + player[playerTurn].aimingPower = sqrt(pow(player[playerTurn].position.x - GetMousePosition().x, 2) + pow(player[playerTurn].position.y - GetMousePosition().y, 2)); + // Calculates the angle via arcsin + player[playerTurn].aimingAngle = asin((player[playerTurn].position.y - GetMousePosition().y)/player[playerTurn].aimingPower)*RAD2DEG; + // Point of the screen we are aiming at + player[playerTurn].aimingPoint = GetMousePosition(); + + // Ball fired + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + player[playerTurn].previousPoint = player[playerTurn].aimingPoint; + player[playerTurn].previousPower = player[playerTurn].aimingPower; + player[playerTurn].previousAngle = player[playerTurn].aimingAngle; + ball.position = player[playerTurn].position; + + return true; + } + } + else + { + player[playerTurn].aimingPoint = player[playerTurn].position; + player[playerTurn].aimingPower = 0; + player[playerTurn].aimingAngle = 0; + } + } + else + { + player[playerTurn].aimingPoint = player[playerTurn].position; + player[playerTurn].aimingPower = 0; + player[playerTurn].aimingAngle = 0; + } + + return false; +} + +static bool UpdateBall(int playerTurn) +{ + static int explosionNumber = 0; + + // Activate ball + if (!ball.active) + { + if (player[playerTurn].isLeftTeam) + { + ball.speed.x = cos(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS; + ball.speed.y = -sin(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS; + ball.active = true; + } + else + { + ball.speed.x = -cos(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS; + ball.speed.y = -sin(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS; + ball.active = true; + } + } + + ball.position.x += ball.speed.x; + ball.position.y += ball.speed.y; + ball.speed.y += GRAVITY/DELTA_FPS; + + // Collision + if (ball.position.x + ball.radius < 0) return true; + else if (ball.position.x - ball.radius > screenWidth) return true; + else + { + // Player collision + for (int i = 0; i < MAX_PLAYERS; i++) + { + if (CheckCollisionCircleRec(ball.position, ball.radius, (Rectangle){ player[i].position.x - player[i].size.x/2, player[i].position.y - player[i].size.y/2, + player[i].size.x, player[i].size.y })) + { + // We can't hit ourselves + if (i == playerTurn) return false; + else + { + // We set the impact point + player[playerTurn].impactPoint.x = ball.position.x; + player[playerTurn].impactPoint.y = ball.position.y + ball.radius; + + // We destroy the player + player[i].isAlive = false; + return true; + } + } + } + + // Building collision + // NOTE: We only check building collision if we are not inside an explosion + for (int i = 0; i < MAX_BUILDINGS; i++) + { + if (CheckCollisionCircles(ball.position, ball.radius, explosion[i].position, explosion[i].radius - ball.radius)) + { + return false; + } + } + + for (int i = 0; i < MAX_BUILDINGS; i++) + { + if (CheckCollisionCircleRec(ball.position, ball.radius, building[i].rectangle)) + { + // We set the impact point + player[playerTurn].impactPoint.x = ball.position.x; + player[playerTurn].impactPoint.y = ball.position.y + ball.radius; + + // We create an explosion + explosion[explosionNumber].position = player[playerTurn].impactPoint; + explosion[explosionNumber].active = true; + explosionNumber++; + + return true; + } + } + } + + return false; +} \ No newline at end of file diff --git a/games/samples/missile_commander.c b/games/samples/missile_commander.c new file mode 100644 index 00000000..6317c41a --- /dev/null +++ b/games/samples/missile_commander.c @@ -0,0 +1,539 @@ +/******************************************************************************************* +* +* raylib - sample game: missile commander +* +* Sample game Marc Palau and Ramon Santamaria +* +* This game has been created using raylib v1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include +#include +#include +#include + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Some Defines +//---------------------------------------------------------------------------------- +#define MAX_MISSILES 100 +#define MAX_INTERCEPTORS 30 +#define MAX_EXPLOSIONS 100 +#define LAUNCHERS_AMOUNT 3 // Not a variable, should not be changed +#define BUILDINGS_AMOUNT 6 // Not a variable, should not be changed + +#define LAUNCHER_SIZE 80 +#define BUILDING_SIZE 60 +#define EXPLOSION_RADIUS 40 + +#define MISSILE_SPEED 1 +#define MISSILE_LAUNCH_FRAMES 80 +#define INTERCEPTOR_SPEED 10 +#define EXPLOSION_INCREASE_TIME 90 // In frames +#define EXPLOSION_TOTAL_TIME 210 // In frames + +#define EXPLOSION_COLOR (Color){ 125, 125, 125, 125 } + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef struct Missile { + Vector2 origin; + Vector2 position; + Vector2 objective; + Vector2 speed; + + bool active; +} Missile; + +typedef struct Interceptor { + Vector2 origin; + Vector2 position; + Vector2 objective; + Vector2 speed; + + bool active; +} Interceptor; + +typedef struct Explosion { + Vector2 position; + float radiusMultiplier; + int frame; + bool active; +} Explosion; + +typedef struct Launcher { + Vector2 position; + bool active; +} Launcher; + +typedef struct Building { + Vector2 position; + bool active; +} Building; + +//------------------------------------------------------------------------------------ +// Global Variables Declaration +//------------------------------------------------------------------------------------ +static int screenWidth = 800; +static int screenHeight = 450; + +static int framesCounter = 0; +static bool gameOver = false; +static bool pause = false; +static int score = 0; + +static Missile missile[MAX_MISSILES]; +static Interceptor interceptor[MAX_INTERCEPTORS]; +static Explosion explosion[MAX_EXPLOSIONS]; +static Launcher launcher[LAUNCHERS_AMOUNT]; +static Building building[BUILDINGS_AMOUNT]; +static int explosionIndex = 0; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static void InitGame(void); // Initialize game +static void UpdateGame(void); // Update game (one frame) +static void DrawGame(void); // Draw game (one frame) +static void UnloadGame(void); // Unload game +static void UpdateDrawFrame(void); // Update and Draw (one frame) + +// Additional module functions +static void UpdateOutgoingFire(); +static void UpdateIncomingFire(); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "sample game: missile commander"); + + InitGame(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateGame(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + DrawGame(); + //---------------------------------------------------------------------------------- + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadGame(); // Unload loaded data (textures, sounds, models...) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//-------------------------------------------------------------------------------------- +// Game Module Functions Definition +//-------------------------------------------------------------------------------------- + +// Initialize game variables +void InitGame(void) +{ + // Initialize missiles + for (int i = 0; i < MAX_MISSILES; i++) + { + missile[i].origin = (Vector2){ 0, 0 }; + missile[i].speed = (Vector2){ 0, 0 }; + missile[i].position = (Vector2){ 0, 0 }; + + missile[i].active = false; + } + + // Initialize interceptors + for (int i = 0; i < MAX_INTERCEPTORS; i++) + { + interceptor[i].origin = (Vector2){ 0, 0 }; + interceptor[i].speed = (Vector2){ 0, 0 }; + interceptor[i].position = (Vector2){ 0, 0 }; + + interceptor[i].active = false; + } + + // Initialize explosions + for (int i = 0; i < MAX_EXPLOSIONS; i++) + { + explosion[i].position = (Vector2){ 0, 0 }; + explosion[i].frame = 0; + explosion[i].active = false; + } + + // Initialize buildings and launchers + int sparcing = screenWidth/(LAUNCHERS_AMOUNT + BUILDINGS_AMOUNT + 1); + + // Buildings and launchers placing + launcher[0].position = (Vector2){ 1*sparcing, screenHeight - LAUNCHER_SIZE/2 }; + building[0].position = (Vector2){ 2*sparcing, screenHeight - BUILDING_SIZE/2 }; + building[1].position = (Vector2){ 3*sparcing, screenHeight - BUILDING_SIZE/2 }; + building[2].position = (Vector2){ 4*sparcing, screenHeight - BUILDING_SIZE/2 }; + launcher[1].position = (Vector2){ 5*sparcing, screenHeight - LAUNCHER_SIZE/2 }; + building[3].position = (Vector2){ 6*sparcing, screenHeight - BUILDING_SIZE/2 }; + building[4].position = (Vector2){ 7*sparcing, screenHeight - BUILDING_SIZE/2 }; + building[5].position = (Vector2){ 8*sparcing, screenHeight - BUILDING_SIZE/2 }; + launcher[2].position = (Vector2){ 9*sparcing, screenHeight - LAUNCHER_SIZE/2 }; + + // Buildings and launchers activation + for (int i = 0; i < LAUNCHERS_AMOUNT; i++) launcher[i].active = true; + for (int i = 0; i < BUILDINGS_AMOUNT; i++) building[i].active = true; + + // Initialize game variables + score = 0; +} + +// Update game (one frame) +void UpdateGame(void) +{ + if (!gameOver) + { + if (IsKeyPressed('P')) pause = !pause; + + if (!pause) + { + framesCounter++; + + static + float distance; + + // Interceptors update + for (int i = 0; i < MAX_INTERCEPTORS; i++) + { + if (interceptor[i].active) + { + // Update position + interceptor[i].position.x += interceptor[i].speed.x; + interceptor[i].position.y += interceptor[i].speed.y; + + // Distance to objective + distance = sqrt( pow(interceptor[i].position.x - interceptor[i].objective.x, 2) + + pow(interceptor[i].position.y - interceptor[i].objective.y, 2)); + + if (distance < INTERCEPTOR_SPEED) + { + // Interceptor dissapears + interceptor[i].active = false; + + // Explosion + explosion[explosionIndex].position = interceptor[i].position; + explosion[explosionIndex].active = true; + explosion[explosionIndex].frame = 0; + explosionIndex++; + if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0; + + break; + } + } + } + + // Missiles update + for (int i = 0; i < MAX_MISSILES; i++) + { + if (missile[i].active) + { + // Update position + missile[i].position.x += missile[i].speed.x; + missile[i].position.y += missile[i].speed.y; + + // Collision and missile out of bounds + if (missile[i].position.y > screenHeight) missile[i].active = false; + else + { + // CHeck collision with launchers + for (int j = 0; j < LAUNCHERS_AMOUNT; j++) + { + if (launcher[j].active) + { + if (CheckCollisionPointRec(missile[i].position, (Rectangle){ launcher[j].position.x - LAUNCHER_SIZE/2, launcher[j].position.y - LAUNCHER_SIZE/2, + LAUNCHER_SIZE, LAUNCHER_SIZE })) + { + // Missile dissapears + missile[i].active = false; + + // Explosion and destroy building + launcher[j].active = false; + + explosion[explosionIndex].position = missile[i].position; + explosion[explosionIndex].active = true; + explosion[explosionIndex].frame = 0; + explosionIndex++; + if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0; + + break; + } + } + } + + // CHeck collision with buildings + for (int j = 0; j < BUILDINGS_AMOUNT; j++) + { + if (building[j].active) + { + if (CheckCollisionPointRec(missile[i].position, (Rectangle){ building[j].position.x - BUILDING_SIZE/2, building[j].position.y - BUILDING_SIZE/2, + BUILDING_SIZE, BUILDING_SIZE })) + { + // Missile dissapears + missile[i].active = false; + + // Explosion and destroy building + building[j].active = false; + + explosion[explosionIndex].position = missile[i].position; + explosion[explosionIndex].active = true; + explosion[explosionIndex].frame = 0; + explosionIndex++; + if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0; + + break; + } + } + } + + // CHeck collision with explosions + for (int j = 0; j < MAX_EXPLOSIONS; j++) + { + if (explosion[j].active) + { + if (CheckCollisionPointCircle(missile[i].position, explosion[j].position, EXPLOSION_RADIUS*explosion[j].radiusMultiplier)) + { + // Missile dissapears and we earn 100 points + missile[i].active = false; + score += 100; + + explosion[explosionIndex].position = missile[i].position; + explosion[explosionIndex].active = true; + explosion[explosionIndex].frame = 0; + explosionIndex++; + if (explosionIndex == MAX_EXPLOSIONS) explosionIndex = 0; + + break; + } + } + } + } + } + } + + // Explosions update + for (int i = 0; i < MAX_EXPLOSIONS; i++) + { + if (explosion[i].active) + { + explosion[i].frame++; + + if (explosion[i].frame <= EXPLOSION_INCREASE_TIME) explosion[i].radiusMultiplier = explosion[i].frame/(float)EXPLOSION_INCREASE_TIME; + else if (explosion[i].frame <= EXPLOSION_TOTAL_TIME) explosion[i].radiusMultiplier = 1 - (explosion[i].frame - (float)EXPLOSION_INCREASE_TIME)/(float)EXPLOSION_TOTAL_TIME; + else + { + explosion[i].frame = 0; + explosion[i].active = false; + } + } + } + + // Fire logic + UpdateOutgoingFire(); + UpdateIncomingFire(); + + // Game over logic + int checker = 0; + + for (int i = 0; i < LAUNCHERS_AMOUNT; i++) + { + if (!launcher[i].active) checker++; + if (checker == LAUNCHERS_AMOUNT) gameOver = true; + } + + checker = 0; + for (int i = 0; i < BUILDINGS_AMOUNT; i++) + { + if (!building[i].active) checker++; + if (checker == BUILDINGS_AMOUNT) gameOver = true; + } + } + } + else + { + if (IsKeyPressed(KEY_ENTER)) + { + InitGame(); + gameOver = false; + } + } +} + +// Draw game (one frame) +void DrawGame(void) +{ + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (!gameOver) + { + // Draw missiles + for (int i = 0; i < MAX_MISSILES; i++) + { + if (missile[i].active) + { + DrawLine(missile[i].origin.x, missile[i].origin.y, missile[i].position.x, missile[i].position.y, RED); + + if (framesCounter % 16 < 8) DrawCircle(missile[i].position.x, missile[i].position.y, 3, YELLOW); + } + } + + // Draw interceptors + for (int i = 0; i < MAX_INTERCEPTORS; i++) + { + if (interceptor[i].active) + { + DrawLine(interceptor[i].origin.x, interceptor[i].origin.y, interceptor[i].position.x, interceptor[i].position.y, GREEN); + + if (framesCounter % 16 < 8) DrawCircle(interceptor[i].position.x, interceptor[i].position.y, 3, BLUE); + } + } + + // Draw explosions + for (int i = 0; i < MAX_EXPLOSIONS; i++) + { + if (explosion[i].active) DrawCircle(explosion[i].position.x, explosion[i].position.y, EXPLOSION_RADIUS*explosion[i].radiusMultiplier, EXPLOSION_COLOR); + } + + // Draw buildings and launchers + for (int i = 0; i < LAUNCHERS_AMOUNT; i++) + { + if (launcher[i].active) DrawRectangle(launcher[i].position.x - LAUNCHER_SIZE/2, launcher[i].position.y - LAUNCHER_SIZE/2, LAUNCHER_SIZE, LAUNCHER_SIZE, GRAY); + } + + for (int i = 0; i < BUILDINGS_AMOUNT; i++) + { + if (building[i].active) DrawRectangle(building[i].position.x - BUILDING_SIZE/2, building[i].position.y - BUILDING_SIZE/2, BUILDING_SIZE, BUILDING_SIZE, LIGHTGRAY); + } + + // Draw score + DrawText(FormatText("SCORE %4i", score), 20, 20, 40, LIGHTGRAY); + + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); + } + else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); + + EndDrawing(); +} + +// Unload game variables +void UnloadGame(void) +{ + // TODO: Unload all dynamic loaded data (textures, sounds, models...) +} + +// Update and Draw (one frame) +void UpdateDrawFrame(void) +{ + UpdateGame(); + DrawGame(); +} + +//-------------------------------------------------------------------------------------- +// Additional module functions +//-------------------------------------------------------------------------------------- +static void UpdateOutgoingFire() +{ + static int interceptorNumber = 0; + int launcherShooting = 0; + + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) launcherShooting = 1; + if (IsMouseButtonPressed(MOUSE_MIDDLE_BUTTON)) launcherShooting = 2; + if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) launcherShooting = 3; + + if (launcherShooting > 0 && launcher[launcherShooting - 1].active) + { + float module; + float sideX; + float sideY; + + // Activate the interceptor + interceptor[interceptorNumber].active = true; + + // Assign start position + interceptor[interceptorNumber].origin = launcher[launcherShooting - 1].position; + interceptor[interceptorNumber].position = interceptor[interceptorNumber].origin; + interceptor[interceptorNumber].objective = GetMousePosition(); + + // Calculate speed + module = sqrt( pow(interceptor[interceptorNumber].objective.x - interceptor[interceptorNumber].origin.x, 2) + + pow(interceptor[interceptorNumber].objective.y - interceptor[interceptorNumber].origin.y, 2)); + + sideX = (interceptor[interceptorNumber].objective.x - interceptor[interceptorNumber].origin.x)*INTERCEPTOR_SPEED/module; + sideY = (interceptor[interceptorNumber].objective.y - interceptor[interceptorNumber].origin.y)*INTERCEPTOR_SPEED/module; + + interceptor[interceptorNumber].speed = (Vector2){ sideX, sideY }; + + // Update + interceptorNumber++; + if (interceptorNumber == MAX_INTERCEPTORS) interceptorNumber = 0; + } +} + +static void UpdateIncomingFire() +{ + static int missileIndex = 0; + + // Launch missile + if (framesCounter % MISSILE_LAUNCH_FRAMES == 0) + { + float module; + float sideX; + float sideY; + + // Activate the missile + missile[missileIndex].active = true; + + // Assign start position + missile[missileIndex].origin = (Vector2){ GetRandomValue(20, screenWidth - 20), -10 }; + missile[missileIndex].position = missile[missileIndex].origin; + missile[missileIndex].objective = (Vector2){ GetRandomValue(20, screenWidth - 20), screenHeight + 10 }; + + // Calculate speed + module = sqrt( pow(missile[missileIndex].objective.x - missile[missileIndex].origin.x, 2) + + pow(missile[missileIndex].objective.y - missile[missileIndex].origin.y, 2)); + + sideX = (missile[missileIndex].objective.x - missile[missileIndex].origin.x)*MISSILE_SPEED/module; + sideY = (missile[missileIndex].objective.y - missile[missileIndex].origin.y)*MISSILE_SPEED/module; + + missile[missileIndex].speed = (Vector2){ sideX, sideY }; + + // Update + missileIndex++; + if (missileIndex == MAX_MISSILES) missileIndex = 0; + } +} \ No newline at end of file diff --git a/games/samples/pang.c b/games/samples/pang.c new file mode 100644 index 00000000..e7b2bb86 --- /dev/null +++ b/games/samples/pang.c @@ -0,0 +1,692 @@ +/******************************************************************************************* +* +* raylib - sample game: pang +* +* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria +* +* This game has been created using raylib v1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Some Defines +//---------------------------------------------------------------------------------- +#define MAX_SPEED 5 +#define METEORS_SPEED 2 +#define NUM_SHOOTS 1 +#define NUM_BIG_METEORS 2 +#define NUM_MEDIUM_METEORS 4 +#define NUM_SMALL_METEORS 8 +#define SHIP_BASE_SIZE 20.0f + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- + +typedef struct Player { + Vector2 position; + Vector2 speed; + float rotation; + Vector3 collider; + Color color; +} Player; + +typedef struct Shoot { + Vector2 position; + Vector2 speed; + float radius; + float rotation; + int lifeSpawn; + bool active; + Color color; +} Shoot; + +typedef struct BigMeteor { + Vector2 position; + Vector2 speed; + float radius; + int points; + bool active; + Color color; +} BigMeteor; + +typedef struct MediumMeteor { + Vector2 position; + Vector2 speed; + float radius; + int points; + bool active; + Color color; +} MediumMeteor; + +typedef struct SmallMeteor { + Vector2 position; + Vector2 speed; + float radius; + int points; + bool active; + Color color; +} SmallMeteor; + +typedef struct Points { + char letter; + Vector2 position; + int value; + Color color; + float alpha; +} Points; + +//------------------------------------------------------------------------------------ +// Global Variables Declaration +//------------------------------------------------------------------------------------ +static int screenWidth = 800; +static int screenHeight = 450; + +static int framesCounter; +static bool gameOver; +static bool pause; +static int score; + +static Player player; +static Shoot shoot[NUM_SHOOTS]; +static BigMeteor bigMeteor[NUM_BIG_METEORS]; +static MediumMeteor mediumMeteor[NUM_MEDIUM_METEORS]; +static SmallMeteor smallMeteor[NUM_SMALL_METEORS]; +static Points points[5]; + +// NOTE: Defined triangle is isosceles with common angles of 70 degrees. +static float shipHeight; +static float gravity; + +static int countMediumMeteors; +static int countSmallMeteors; +static int meteorsDestroyed; +static Vector2 linePosition; + +static bool victory; +static bool lose; +static bool awake; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static void InitGame(void); // Initialize game +static void UpdateGame(void); // Update game (one frame) +static void DrawGame(void); // Draw game (one frame) +static void UnloadGame(void); // Unload game +static void UpdateDrawFrame(void); // Update and Draw (one frame) + +static void InitShoot(Shoot shoot); +static void DrawSpaceship(Vector2 position, float rotation, Color color); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + InitWindow(screenWidth, screenHeight, "sample game: pang"); + + InitGame(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateGame(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + DrawGame(); + //---------------------------------------------------------------------------------- + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadGame(); // Unload loaded data (textures, sounds, models...) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//------------------------------------------------------------------------------------ +// Module Functions Definitions (local) +//------------------------------------------------------------------------------------ + +// Initialize game variables +static void InitGame(void) +{ + int posx, posy; + int velx = 0; + int vely = 0; + + framesCounter = 0; + gameOver = false; + pause = false; + score = 0; + + victory = false; + lose = false; + awake = true; + gravity = 0.25f; + + linePosition = (Vector2){ 0.0f , 0.0f }; + shipHeight = (SHIP_BASE_SIZE/2)/tanf(20*DEG2RAD); + + // Initialization player + player.position = (Vector2){ screenWidth/2, screenHeight }; + player.speed = (Vector2){ MAX_SPEED, MAX_SPEED }; + player.rotation = 0; + player.collider = (Vector3){ player.position.x, player.position.y - shipHeight/2.0f, 12.0f }; + player.color = LIGHTGRAY; + + meteorsDestroyed = 0; + + // Initialize shoots + for (int i = 0; i < NUM_SHOOTS; i++) + { + shoot[i].position = (Vector2){ 0, 0 }; + shoot[i].speed = (Vector2){ 0, 0 }; + shoot[i].radius = 2; + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + shoot[i].color = WHITE; + } + + // Initialize big meteors + for (int i = 0; i < NUM_BIG_METEORS; i++) + { + bigMeteor[i].radius = 40.0f; + posx = GetRandomValue(0 + bigMeteor[i].radius, screenWidth - bigMeteor[i].radius); + posy = GetRandomValue(0 + bigMeteor[i].radius, screenHeight/2); + + bigMeteor[i].position = (Vector2){ posx, posy }; + + while ((velx == 0) || (vely == 0)) + { + velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + } + + bigMeteor[i].speed = (Vector2){ velx, vely }; + bigMeteor[i].points = 200; + bigMeteor[i].active = true; + bigMeteor[i].color = BLUE; + } + + // Initialize medium meteors + for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + { + mediumMeteor[i].position = (Vector2){-100, -100}; + mediumMeteor[i].speed = (Vector2){0,0}; + mediumMeteor[i].radius = 20.0f; + mediumMeteor[i].points = 100; + mediumMeteor[i].active = false; + mediumMeteor[i].color = BLUE; + } + + // Initialize small meteors + for (int i = 0; i < NUM_SMALL_METEORS; i++) + { + smallMeteor[i].position = (Vector2){ -100, -100 }; + smallMeteor[i].speed = (Vector2){ 0, 0 }; + smallMeteor[i].radius = 10.0f; + smallMeteor[i].points = 50; + smallMeteor[i].active = false; + smallMeteor[i].color = BLUE; + } + + // Initialize animated points + for (int i = 0; i < 5; i++) + { + points[i].position = (Vector2){ 0, 0 }; + points[i].value = 0; + points[i].alpha = 0.0f; + } + + countMediumMeteors = 0; + countSmallMeteors = 0; +} + +// Update game (one frame) +void UpdateGame(void) +{ + if (!gameOver) + { + if (IsKeyPressed('P')) pause = !pause; + + if (!pause) + { + if (awake) + { + // Player logic + if (IsKeyDown(KEY_LEFT)) player.position.x -= player.speed.x; + if (IsKeyDown(KEY_RIGHT)) player.position.x += player.speed.x; + + // Wall behaviour for player + if (player.position.x + SHIP_BASE_SIZE/2 > screenWidth) player.position.x = screenWidth - SHIP_BASE_SIZE/2; + else if (player.position.x - SHIP_BASE_SIZE/2 < 0) player.position.x = 0 + SHIP_BASE_SIZE/2; + + // Activation of shoot + if (IsKeyPressed(KEY_SPACE)) + { + for (int i = 0; i < NUM_SHOOTS; i++) + { + if (!shoot[i].active) + { + shoot[i].position = (Vector2){ player.position.x, player.position.y - shipHeight }; + linePosition = (Vector2){ player.position.x, player.position.y}; + shoot[i].active = true; + shoot[i].speed.y = MAX_SPEED; + break; + } + } + } + + // Shoot life timer + for (int i = 0; i < NUM_SHOOTS; i++) + { + if (shoot[i].active) shoot[i].lifeSpawn++; + } + + // Shot logic + for (int i = 0; i < NUM_SHOOTS; i++) + { + if (shoot[i].active) + { + // Movement + shoot[i].position.y -= shoot[i].speed.y; + + // Wall behaviour for shoot + if (shoot[i].position.x > screenWidth + shoot[i].radius) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + } + else if (shoot[i].position.x < 0 - shoot[i].radius) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + } + + if (shoot[i].position.y > screenHeight + shoot[i].radius) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + } + else if (shoot[i].position.y < 0 - shoot[i].radius) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + } + + // Life of shoot + if (shoot[i].lifeSpawn >= 120) + { + shoot[i].position = (Vector2){0, 0}; + shoot[i].speed = (Vector2){0, 0}; + shoot[i].lifeSpawn = 0; + shoot[i].active = false; + } + } + } + + // Player collision with meteors + player.collider = (Vector3){player.position.x, player.position.y - shipHeight/2, 12}; + + for (int i = 0; i < NUM_BIG_METEORS; i++) + { + if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, bigMeteor[i].position, bigMeteor[i].radius) && bigMeteor[i].active) + { + gameOver = true; + } + } + + for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + { + if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, mediumMeteor[i].position, mediumMeteor[i].radius) && mediumMeteor[i].active) + { + gameOver = true; + } + } + + for (int i = 0; i < NUM_SMALL_METEORS; i++) + { + if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, smallMeteor[i].position, smallMeteor[i].radius) && smallMeteor[i].active) + { + gameOver = true; + } + } + + // Meteor logic + for (int i = 0; i < NUM_BIG_METEORS; i++) + { + if (bigMeteor[i].active) + { + // movement + bigMeteor[i].position.x += bigMeteor[i].speed.x; + bigMeteor[i].position.y += bigMeteor[i].speed.y; + + // wall behaviour + if (((bigMeteor[i].position.x + bigMeteor[i].radius) >= screenWidth) || ((bigMeteor[i].position.x - bigMeteor[i].radius) <= 0)) bigMeteor[i].speed.x *= -1; + if ((bigMeteor[i].position.y - bigMeteor[i].radius) <= 0) bigMeteor[i].speed.y *= -1.5; + + if ((bigMeteor[i].position.y + bigMeteor[i].radius) >= screenHeight) + { + bigMeteor[i].speed.y *= -1; + bigMeteor[i].position.y = screenHeight - bigMeteor[i].radius; + } + + bigMeteor[i].speed.y += gravity; + } + } + + for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + { + if (mediumMeteor[i].active) + { + // Movement logic + mediumMeteor[i].position.x += mediumMeteor[i].speed.x; + mediumMeteor[i].position.y += mediumMeteor[i].speed.y; + + // Wall behaviour + if (mediumMeteor[i].position.x + mediumMeteor[i].radius >= screenWidth || mediumMeteor[i].position.x - mediumMeteor[i].radius <= 0) mediumMeteor[i].speed.x *= -1; + if (mediumMeteor[i].position.y - mediumMeteor[i].radius <= 0) mediumMeteor[i].speed.y *= -1; + if (mediumMeteor[i].position.y + mediumMeteor[i].radius >= screenHeight) + { + mediumMeteor[i].speed.y *= -1; + mediumMeteor[i].position.y = screenHeight - mediumMeteor[i].radius; + } + + mediumMeteor[i].speed.y += gravity + 0.12f; + } + } + + for (int i = 0; i < NUM_SMALL_METEORS; i++) + { + if (smallMeteor[i].active) + { + // movement + smallMeteor[i].position.x += smallMeteor[i].speed.x; + smallMeteor[i].position.y += smallMeteor[i].speed.y; + + // wall behaviour + if (smallMeteor[i].position.x + smallMeteor[i].radius >= screenWidth || smallMeteor[i].position.x - smallMeteor[i].radius <= 0) smallMeteor[i].speed.x *= -1; + if (smallMeteor[i].position.y - smallMeteor[i].radius <= 0) smallMeteor[i].speed.y *= -1; + if (smallMeteor[i].position.y + smallMeteor[i].radius >= screenHeight) + { + smallMeteor[i].speed.y *= -1; + smallMeteor[i].position.y = screenHeight - smallMeteor[i].radius; + } + + smallMeteor[i].speed.y += gravity + 0.25f; + } + } + + // Collision behaviour + for (int i = 0; i < NUM_SHOOTS; i++) + { + if ((shoot[i].active)) + { + for (int a = 0; a < NUM_BIG_METEORS; a++) + { + if (bigMeteor[a].active && (bigMeteor[a].position.x - bigMeteor[a].radius <= linePosition.x && bigMeteor[a].position.x + bigMeteor[a].radius >= linePosition.x) + && (bigMeteor[a].position.y + bigMeteor[a].radius >= shoot[i].position.y)) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + bigMeteor[a].active = false; + meteorsDestroyed++; + score += bigMeteor[a].points; + + for (int z = 0; z < 5; z++) + { + if (points[z].alpha == 0.0f) + { + points[z].position = bigMeteor[a].position; + points[z].value = bigMeteor[a].points; + points[z].color = RED; + points[z].alpha = 1.0f; + z = 5; + } + } + + for (int j = 0; j < 2; j ++) + { + if ((countMediumMeteors%2) == 0) + { + mediumMeteor[countMediumMeteors].position = (Vector2){bigMeteor[a].position.x, bigMeteor[a].position.y}; + mediumMeteor[countMediumMeteors].speed = (Vector2){METEORS_SPEED*-1, METEORS_SPEED}; + } + else + { + mediumMeteor[countMediumMeteors].position = (Vector2){bigMeteor[a].position.x, bigMeteor[a].position.y}; + mediumMeteor[countMediumMeteors].speed = (Vector2){METEORS_SPEED, METEORS_SPEED}; + } + + mediumMeteor[countMediumMeteors].active = true; + countMediumMeteors ++; + } + + bigMeteor[a].color = RED; + a = NUM_BIG_METEORS; + } + } + } + + if ((shoot[i].active)) + { + for (int b = 0; b < NUM_MEDIUM_METEORS; b++) + { + if (mediumMeteor[b].active && (mediumMeteor[b].position.x - mediumMeteor[b].radius <= linePosition.x && mediumMeteor[b].position.x + mediumMeteor[b].radius >= linePosition.x) + && (mediumMeteor[b].position.y + mediumMeteor[b].radius >= shoot[i].position.y)) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + mediumMeteor[b].active = false; + meteorsDestroyed++; + score += mediumMeteor[b].points; + + for (int z = 0; z < 5; z++) + { + if (points[z].alpha == 0.0f) + { + points[z].position = mediumMeteor[b].position; + points[z].value = mediumMeteor[b].points; + points[z].color = GREEN; + points[z].alpha = 1.0f; + z = 5; + } + } + + for (int j = 0; j < 2; j ++) + { + if (countSmallMeteors%2 == 0) + { + smallMeteor[countSmallMeteors].position = (Vector2){mediumMeteor[b].position.x, mediumMeteor[b].position.y}; + smallMeteor[countSmallMeteors].speed = (Vector2){METEORS_SPEED*-1, METEORS_SPEED*-1}; + } + else + { + smallMeteor[countSmallMeteors].position = (Vector2){mediumMeteor[b].position.x, mediumMeteor[b].position.y}; + smallMeteor[countSmallMeteors].speed = (Vector2){METEORS_SPEED, METEORS_SPEED*-1}; + } + + smallMeteor[countSmallMeteors].active = true; + countSmallMeteors ++; + } + mediumMeteor[b].color = GREEN; + b = NUM_MEDIUM_METEORS; + } + } + } + + if ((shoot[i].active)) + { + for (int c = 0; c < NUM_SMALL_METEORS; c++) + { + if (smallMeteor[c].active && (smallMeteor[c].position.x - smallMeteor[c].radius <= linePosition.x && smallMeteor[c].position.x + smallMeteor[c].radius >= linePosition.x) + && (smallMeteor[c].position.y + smallMeteor[c].radius >= shoot[i].position.y)) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + smallMeteor[c].active = false; + meteorsDestroyed++; + smallMeteor[c].color = YELLOW; + score += smallMeteor[c].points; + + for (int z = 0; z < 5; z++) + { + if (points[z].alpha == 0.0f) + { + points[z].position = smallMeteor[c].position; + points[z].value = smallMeteor[c].points; + points[z].color = YELLOW; + points[z].alpha = 1.0f; + z = 5; + } + } + + c = NUM_SMALL_METEORS; + } + } + } + } + + for (int z = 0; z < 5; z++) + { + if (points[z].alpha > 0.0f) + { + points[z].position.y -= 2; + points[z].alpha -= 0.02f; + } + + if (points[z].alpha < 0.0f) points[z].alpha = 0.0f; + } + + if (meteorsDestroyed == (NUM_BIG_METEORS + NUM_MEDIUM_METEORS + NUM_SMALL_METEORS)) victory = true; + } + else + { + framesCounter++; + if (framesCounter%180 == 0) awake = false; + } + } + } + else + { + if (IsKeyPressed(KEY_ENTER)) + { + InitGame(); + gameOver = false; + } + } +} + +// Draw game (one frame) +void DrawGame(void) +{ + BeginDrawing(); + + ClearBackground(DARKGRAY); + + if (!gameOver) + { + // Draw player + Vector2 v1 = { player.position.x + sinf(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cosf(player.rotation*DEG2RAD)*(shipHeight) }; + Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; + Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; + DrawTriangleLines(v1, v2, v3, player.color); + + // Draw meteor + for (int i = 0;i < NUM_BIG_METEORS; i++) + { + if (bigMeteor[i].active) DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, bigMeteor[i].color); + else + { + DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, Fade(bigMeteor[i].color, 0.25f)); + //DrawText(FormatText("%i", bigMeteor[i].points), bigMeteor[i].position.x - MeasureText("200", 20)/2, bigMeteor[i].position.y - 10, 20, Fade(WHITE, 0.25f)); + } + } + + for (int i = 0;i < NUM_MEDIUM_METEORS; i++) + { + if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, mediumMeteor[i].color); + else + { + DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(mediumMeteor[i].color, 0.25f)); + //DrawText(FormatText("%i", mediumMeteor[i].points), mediumMeteor[i].position.x - MeasureText("100", 20)/2, mediumMeteor[i].position.y - 10, 20, Fade(WHITE, 0.25f)); + } + } + + for (int i = 0;i < NUM_SMALL_METEORS; i++) + { + if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, smallMeteor[i].color); + else + { + DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(smallMeteor[i].color, 0.25f)); + //DrawText(FormatText("%i", smallMeteor[i].points), smallMeteor[i].position.x - MeasureText("50", 10)/2, smallMeteor[i].position.y - 5, 10, Fade(WHITE, 0.25f)); + } + } + + // Draw shoot + + for (int i = 0; i < NUM_SHOOTS; i++) + { + if (shoot[i].active) DrawLine(linePosition.x, linePosition.y, shoot[i].position.x, shoot[i].position.y, RED); + } + + for (int z = 0; z < 5; z++) + { + if (points[z].alpha > 0.0f) + { + DrawText(FormatText("+%i", points[z].value), points[z].position.x, points[z].position.y, 20, Fade(points[z].color, points[z].alpha)); + } + } + + // Draw Text + DrawText(FormatText("SCORE: %i", score), 10, 10, 20, LIGHTGRAY); + + if (victory) DrawText("VICTORY", screenWidth/2 - MeasureText("VICTORY", 40)/2, screenHeight/2 - 40, 40, LIGHTGRAY); + + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, LIGHTGRAY); + } + else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, LIGHTGRAY); + + EndDrawing(); +} + +// Unload game variables +void UnloadGame(void) +{ + // TODO: Unload all dynamic loaded data (textures, sounds, models...) +} + +// Update and Draw (one frame) +void UpdateDrawFrame(void) +{ + UpdateGame(); + DrawGame(); +} \ No newline at end of file diff --git a/games/samples/snake.c b/games/samples/snake.c new file mode 100644 index 00000000..ac2f6132 --- /dev/null +++ b/games/samples/snake.c @@ -0,0 +1,293 @@ +/******************************************************************************************* +* +* raylib - sample game: snake +* +* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria +* +* This game has been created using raylib v1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Some Defines +//---------------------------------------------------------------------------------- +#define SNAKE_LENGTH 256 +#define SQUARE_SIZE 31 + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef struct Snake { + Vector2 position; + Vector2 size; + Vector2 speed; + Color color; +} Snake; + +typedef struct Food { + Vector2 position; + Vector2 size; + bool active; + Color color; +} Food; + +//------------------------------------------------------------------------------------ +// Global Variables Declaration +//------------------------------------------------------------------------------------ +static int screenWidth = 800; +static int screenHeight = 450; + +static int framesCounter; +static bool gameOver; +static bool pause; + +static Food fruit; +static Snake snake[SNAKE_LENGTH]; +static Vector2 snakePosition[SNAKE_LENGTH]; +static bool allowMove; +static Vector2 offset; +static int counterTail; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static void InitGame(void); // Initialize game +static void UpdateGame(void); // Update game (one frame) +static void DrawGame(void); // Draw game (one frame) +static void UnloadGame(void); // Unload game +static void UpdateDrawFrame(void); // Update and Draw (one frame) + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "sample game: snake"); + + InitGame(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateGame(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + DrawGame(); + //---------------------------------------------------------------------------------- + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadGame(); // Unload loaded data (textures, sounds, models...) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//------------------------------------------------------------------------------------ +// Module Functions Definitions (local) +//------------------------------------------------------------------------------------ + +// Initialize game variables +void InitGame(void) +{ + framesCounter = 0; + gameOver = false; + pause = false; + + counterTail = 1; + allowMove = false; + + offset.x = screenWidth%SQUARE_SIZE; + offset.y = screenHeight%SQUARE_SIZE; + + for (int i = 0; i < SNAKE_LENGTH; i++) + { + snake[i].position = (Vector2){ offset.x/2, offset.y/2 }; + snake[i].size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE }; + snake[i].speed = (Vector2){ SQUARE_SIZE, 0 }; + + if (i == 0) snake[i].color = DARKBLUE; + else snake[i].color = BLUE; + } + + for (int i = 0; i < SNAKE_LENGTH; i++) + { + snakePosition[i] = (Vector2){ 0.0f, 0.0f }; + } + + fruit.size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE }; + fruit.color = SKYBLUE; + fruit.active = false; +} + +// Update game (one frame) +void UpdateGame(void) +{ + if (!gameOver) + { + if (IsKeyPressed('P')) pause = !pause; + + if (!pause) + { + // control + if (IsKeyPressed(KEY_RIGHT) && (snake[0].speed.x == 0) && allowMove) + { + snake[0].speed = (Vector2){ SQUARE_SIZE, 0 }; + allowMove = false; + } + if (IsKeyPressed(KEY_LEFT) && (snake[0].speed.x == 0) && allowMove) + { + snake[0].speed = (Vector2){ -SQUARE_SIZE, 0 }; + allowMove = false; + } + if (IsKeyPressed(KEY_UP) && (snake[0].speed.y == 0) && allowMove) + { + snake[0].speed = (Vector2){ 0, -SQUARE_SIZE }; + allowMove = false; + } + if (IsKeyPressed(KEY_DOWN) && (snake[0].speed.y == 0) && allowMove) + { + snake[0].speed = (Vector2){ 0, SQUARE_SIZE }; + allowMove = false; + } + + // movement + for (int i = 0; i < counterTail; i++) snakePosition[i] = snake[i].position; + + if ((framesCounter%5) == 0) + { + for (int i = 0; i < counterTail; i++) + { + if (i == 0) + { + snake[0].position.x += snake[0].speed.x; + snake[0].position.y += snake[0].speed.y; + allowMove = true; + } + else snake[i].position = snakePosition[i-1]; + } + } + + // wall behaviour + if (((snake[0].position.x) > (screenWidth - offset.x)) || + ((snake[0].position.y) > (screenHeight - offset.y)) || + (snake[0].position.x < 0) || (snake[0].position.y < 0)) + { + gameOver = true; + } + + // collision with yourself + for (int i = 1; i < counterTail; i++) + { + if ((snake[0].position.x == snake[i].position.x) && (snake[0].position.y == snake[i].position.y)) gameOver = true; + } + + // TODO: review logic: fruit.position calculation + if (!fruit.active) + { + fruit.active = true; + fruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 }; + + for (int i = 0; i < counterTail; i++) + { + while ((fruit.position.x == snake[i].position.x) && (fruit.position.y == snake[i].position.y)) + { + fruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE }; + i = 0; + } + } + } + + // collision + if (CheckCollisionRecs((Rectangle){(int)snake[0].position.x, (int)snake[0].position.y, (int)snake[0].size.x, (int)snake[0].size.y}, + (Rectangle){(int)fruit.position.x, (int)fruit.position.y, (int)fruit.size.x, (int)fruit.size.y})) + { + snake[counterTail].position = snakePosition[counterTail - 1]; + counterTail += 1; + fruit.active = false; + } + + framesCounter++; + } + } + else + { + if (IsKeyPressed(KEY_ENTER)) + { + InitGame(); + gameOver = false; + } + } +} + +// Draw game (one frame) +void DrawGame(void) +{ + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (!gameOver) + { + // Draw grid lines + for (int i = 0; i < screenWidth/SQUARE_SIZE + 1; i++) + { + DrawLineV((Vector2){SQUARE_SIZE*i + offset.x/2, offset.y/2}, (Vector2){SQUARE_SIZE*i + offset.x/2, screenHeight - offset.y/2}, LIGHTGRAY); + } + + for (int i = 0; i < screenHeight/SQUARE_SIZE + 1; i++) + { + DrawLineV((Vector2){offset.x/2, SQUARE_SIZE*i + offset.y/2}, (Vector2){screenWidth - offset.x/2, SQUARE_SIZE*i + offset.y/2}, LIGHTGRAY); + } + + // Draw snake + for (int i = 0; i < counterTail; i++) DrawRectangleV(snake[i].position, snake[i].size, snake[i].color); + + // Draw fruit to pick + DrawRectangleV(fruit.position, fruit.size, fruit.color); + + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); + } + else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); + + EndDrawing(); +} + +// Unload game variables +void UnloadGame(void) +{ + // TODO: Unload all dynamic loaded data (textures, sounds, models...) +} + +// Update and Draw (one frame) +void UpdateDrawFrame(void) +{ + UpdateGame(); + DrawGame(); +} \ No newline at end of file diff --git a/games/samples/space_invaders.c b/games/samples/space_invaders.c new file mode 100644 index 00000000..9f380628 --- /dev/null +++ b/games/samples/space_invaders.c @@ -0,0 +1,407 @@ +/******************************************************************************************* +* +* raylib - sample game: space invaders +* +* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria +* +* This game has been created using raylib v1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Some Defines +//---------------------------------------------------------------------------------- +#define NUM_SHOOTS 50 +#define NUM_MAX_ENEMIES 50 +#define FIRST_WAVE 10 +#define SECOND_WAVE 20 +#define THIRD_WAVE 50 + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef enum { FIRST = 0, SECOND, THIRD } enemyWave; + +typedef struct Player{ + Rectangle rec; + Vector2 speed; + Color color; +} Player; + +typedef struct Enemy{ + Rectangle rec; + Vector2 speed; + bool active; + Color color; +} Enemy; + +typedef struct Shoot{ + Rectangle rec; + Vector2 speed; + bool active; + Color color; +} Shoot; + +//------------------------------------------------------------------------------------ +// Global Variables Declaration +//------------------------------------------------------------------------------------ +static int screenWidth = 800; +static int screenHeight = 450; + +static int framesCounter; +static bool gameOver; +static bool pause; +static int score; +static bool victory; + +static Player player; +static Enemy enemy[NUM_MAX_ENEMIES]; +static Shoot shoot[NUM_SHOOTS]; +static enemyWave wave; + +static int shootRate; +static float alpha; + +static int activeEnemies; +static int enemiesKill; +static bool smooth; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static void InitGame(void); // Initialize game +static void UpdateGame(void); // Update game (one frame) +static void DrawGame(void); // Draw game (one frame) +static void UnloadGame(void); // Unload game +static void UpdateDrawFrame(void); // Update and Draw (one frame) + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "sample game: space invaders"); + + InitGame(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateGame(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + DrawGame(); + //---------------------------------------------------------------------------------- + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadGame(); // Unload loaded data (textures, sounds, models...) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//------------------------------------------------------------------------------------ +// Module Functions Definitions (local) +//------------------------------------------------------------------------------------ + +// Initialize game variables +void InitGame(void) +{ + // Initialize game variables + shootRate = 0; + pause = false; + gameOver = false; + victory = false; + smooth = false; + wave = FIRST; + activeEnemies = FIRST_WAVE; + enemiesKill = 0; + score = 0; + alpha = 0; + + // Initialize player + player.rec.x = 20; + player.rec.y = 50; + player.rec.width = 10; + player.rec.height = 10; + player.speed.x = 5; + player.speed.y = 5; + player.color = BLACK; + + // Initialize enemies + for (int i = 0; i < NUM_MAX_ENEMIES; i++) + { + enemy[i].rec.width = 10; + enemy[i].rec.height = 10; + enemy[i].rec.x = GetRandomValue(screenWidth, screenWidth + 1000); + enemy[i].rec.y = GetRandomValue(0, screenHeight - enemy[i].rec.height); + enemy[i].speed.x = 5; + enemy[i].speed.y = 5; + enemy[i].active = true; + enemy[i].color = DARKGRAY; + } + + // Initialize shoots + for (int i = 0; i < NUM_SHOOTS; i++) + { + shoot[i].rec.x = player.rec.x; + shoot[i].rec.y = player.rec.y + player.rec.height/4; + shoot[i].rec.width = 10; + shoot[i].rec.height = 5; + shoot[i].speed.x = 7; + shoot[i].speed.y = 0; + shoot[i].active = false; + shoot[i].color = WHITE; + } +} + +// Update game (one frame) +void UpdateGame(void) +{ + if (!gameOver) + { + if (IsKeyPressed('P')) pause = !pause; + + if (!pause) + { + switch (wave) + { + case FIRST: + { + if (!smooth) + { + alpha += 0.02f; + + if (alpha >= 1.0f) smooth = true; + } + + if (smooth) alpha -= 0.02f; + + if (enemiesKill == activeEnemies) + { + enemiesKill = 0; + + for (int i = 0; i < activeEnemies; i++) + { + if (!enemy[i].active) enemy[i].active = true; + } + + activeEnemies = SECOND_WAVE; + wave = SECOND; + smooth = false; + alpha = 0.0f; + } + } break; + case SECOND: + { + if (!smooth) + { + alpha += 0.02f; + + if (alpha >= 1.0f) smooth = true; + } + + if (smooth) alpha -= 0.02f; + + if (enemiesKill == activeEnemies) + { + enemiesKill = 0; + + for (int i = 0; i < activeEnemies; i++) + { + if (!enemy[i].active) enemy[i].active = true; + } + + activeEnemies = THIRD_WAVE; + wave = THIRD; + smooth = false; + alpha = 0.0f; + } + } break; + case THIRD: + { + if (!smooth) + { + alpha += 0.02f; + + if (alpha >= 1.0f) smooth = true; + } + + if (smooth) alpha -= 0.02f; + + if (enemiesKill == activeEnemies) victory = true; + + } break; + default: break; + } + + // Player movement + if (IsKeyDown(KEY_RIGHT)) player.rec.x += player.speed.x; + if (IsKeyDown(KEY_LEFT)) player.rec.x -= player.speed.x; + if (IsKeyDown(KEY_UP)) player.rec.y -= player.speed.y; + if (IsKeyDown(KEY_DOWN)) player.rec.y += player.speed.y; + + // Player collision with enemy + for (int i = 0; i < activeEnemies; i++) + { + if (CheckCollisionRecs(player.rec, enemy[i].rec)) gameOver = true; + } + + // Enemy behaviour + for (int i = 0; i < activeEnemies; i++) + { + if (enemy[i].active) + { + enemy[i].rec.x -= enemy[i].speed.x; + + if (enemy[i].rec.x < 0) + { + enemy[i].rec.x = GetRandomValue(screenWidth, screenWidth + 1000); + enemy[i].rec.y = GetRandomValue(0, screenHeight - enemy[i].rec.height); + } + } + } + + // Wall behaviour + if (player.rec.x <= 0) player.rec.x = 0; + if (player.rec.x + player.rec.width >= screenWidth) player.rec.x = screenWidth - player.rec.width; + if (player.rec.y <= 0) player.rec.y = 0; + if (player.rec.y + player.rec.height >= screenHeight) player.rec.y = screenHeight - player.rec.height; + + //Shoot initialization + if (IsKeyDown(KEY_SPACE)) + { + shootRate += 5; + + for (int i = 0; i < NUM_SHOOTS; i++) + { + if (!shoot[i].active && shootRate%20 == 0) + { + shoot[i].rec.x = player.rec.x; + shoot[i].rec.y = player.rec.y + player.rec.height/4; + shoot[i].active = true; + break; + } + } + } + + // Shoot logic + for (int i = 0; i < NUM_SHOOTS; i++) + { + if (shoot[i].active) + { + // Movement + shoot[i].rec.x += shoot[i].speed.x; + + // Collision with enemy + for (int j = 0; j < activeEnemies; j++) + { + if (enemy[j].active) + { + if (CheckCollisionRecs(shoot[i].rec, enemy[j].rec)) + { + shoot[i].active = false; + enemy[j].active = false; + enemy[j].rec.x = GetRandomValue(screenWidth, screenWidth + 1000); + enemy[j].rec.y = GetRandomValue(0, screenHeight - enemy[j].rec.height); + shootRate = 0; + enemiesKill++; + score += 100; + } + + if (shoot[i].rec.x + shoot[i].rec.width >= screenWidth) + { + shoot[i].active = false; + shootRate = 0; + } + } + } + } + } + } + } + else + { + if (IsKeyPressed(KEY_ENTER)) + { + InitGame(); + gameOver = false; + } + } +} + +// Draw game (one frame) +void DrawGame(void) +{ + BeginDrawing(); + + ClearBackground(LIGHTGRAY); + + if (!gameOver) + { + DrawRectangleRec(player.rec, player.color); + + if (wave == FIRST) DrawText("FIRST WAVE", screenWidth/2 - MeasureText("FIRST WAVE", 40)/2, screenHeight/2 - 40, 40, Fade(BLACK, alpha)); + else if (wave == SECOND) DrawText("SECOND WAVE", screenWidth/2 - MeasureText("SECOND WAVE", 40)/2, screenHeight/2 - 40, 40, Fade(BLACK, alpha)); + else if (wave == THIRD) DrawText("THIRD WAVE", screenWidth/2 - MeasureText("THIRD WAVE", 40)/2, screenHeight/2 - 40, 40, Fade(BLACK, alpha)); + + for (int i = 0; i < activeEnemies; i++) + { + if (enemy[i].active) DrawRectangleRec(enemy[i].rec, enemy[i].color); + } + + for (int i = 0; i < NUM_SHOOTS; i++) + { + if (shoot[i].active) DrawRectangleRec(shoot[i].rec, shoot[i].color); + } + + DrawText(FormatText("%04i", score), 20, 20, 40, DARKGRAY); + + if (victory) DrawText("YOU WIN", screenWidth/2 - MeasureText("YOU WIN", 40)/2, screenHeight/2 - 40, 40, BLACK); + + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); + } + else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); + + EndDrawing(); +} + +// Unload game variables +void UnloadGame(void) +{ + // TODO: Unload all dynamic loaded data (textures, sounds, models...) +} + +// Update and Draw (one frame) +void UpdateDrawFrame(void) +{ + UpdateGame(); + DrawGame(); +} \ No newline at end of file diff --git a/games/samples/tetris.c b/games/samples/tetris.c new file mode 100644 index 00000000..8d550f3d --- /dev/null +++ b/games/samples/tetris.c @@ -0,0 +1,835 @@ +/******************************************************************************************* +* +* raylib - sample game: tetris +* +* Sample game Marc Palau and Ramon Santamaria +* +* This game has been created using raylib v1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include +#include +#include +#include + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Some Defines +//---------------------------------------------------------------------------------- +#define SQUARE_SIZE 30 + +#define GRID_HORIZONTAL_SIZE 12 +#define GRID_VERTICAL_SIZE 20 + +#define LATERAL_SPEED 10 +#define TURNING_SPEED 12 +#define FAST_FALL_AWAIT_COUNTER 30 + +#define FADING_TIME 33 + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef enum GridSquare { EMPTY, MOVING, FULL, BLOCK, FADING } GridSquare; + +//------------------------------------------------------------------------------------ +// Global Variables Declaration +//------------------------------------------------------------------------------------ +static int screenWidth = 800; +static int screenHeight = 620; + +static bool gameOver = false; +static bool pause = false; + +// Matrices +static GridSquare grid [GRID_HORIZONTAL_SIZE][GRID_VERTICAL_SIZE]; +static GridSquare piece [4][4]; +static GridSquare incomingPiece [4][4]; + +// Theese variables keep track of the active piece position +static int piecePositionX = 0; +static int piecePositionY = 0; + +// Game parameters +static Color fadingColor; +//static int fallingSpeed; // In frames + +static bool beginPlay = true; // This var is only true at the begining of the game, used for the first matrix creations +static bool pieceActive = false; +static bool detection = false; +static bool lineToDelete = false; + +// Statistics +static int level = 1; +static int lines = 0; + +// Counters +static int gravityMovementCounter = 0; +static int lateralMovementCounter = 0; +static int turnMovementCounter = 0; +static int fastFallMovementCounter = 0; + +static int fadeLineCounter = 0; + +// Based on level +static int gravitySpeed = 30; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static void InitGame(void); // Initialize game +static void UpdateGame(void); // Update game (one frame) +static void DrawGame(void); // Draw game (one frame) +static void UnloadGame(void); // Unload game +static void UpdateDrawFrame(void); // Update and Draw (one frame) + +// Additional module functions +static bool Createpiece(); +static void GetRandompiece(); +static void ResolveFallingMovement(); +static bool ResolveLateralMovement(); +static bool ResolveTurnMovement(); +static void CheckDetection(); +static void CheckCompletition(); +static void DeleteCompleteLines(); + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "sample game: tetris"); + + InitGame(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 1); +#else + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateGame(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + DrawGame(); + //---------------------------------------------------------------------------------- + } +#endif + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadGame(); // Unload loaded data (textures, sounds, models...) + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +//-------------------------------------------------------------------------------------- +// Game Module Functions Definition +//-------------------------------------------------------------------------------------- + +// Initialize game variables +void InitGame(void) +{ + // Initialize game statistics + level = 1; + lines = 0; + + fadingColor = GRAY; + + piecePositionX = 0; + piecePositionY = 0; + + pause = false; + + beginPlay = true; + pieceActive = false; + detection = false; + lineToDelete = false; + + // Counters + gravityMovementCounter = 0; + lateralMovementCounter = 0; + turnMovementCounter = 0; + fastFallMovementCounter = 0; + + fadeLineCounter = 0; + gravitySpeed = 30; + + // Initialize grid matrices + for (int i = 0; i < GRID_HORIZONTAL_SIZE; i++) + { + for (int j = 0; j < GRID_VERTICAL_SIZE; j++) + { + if ((j == GRID_VERTICAL_SIZE - 1) || (i == 0) || (i == GRID_HORIZONTAL_SIZE - 1)) grid[i][j] = BLOCK; + else grid[i][j] = EMPTY; + } + } + + // Initialize incoming piece matrices + for (int i = 0; i < 4; i++) + { + for (int j = 0; j< 4; j++) + { + incomingPiece[i][j] = EMPTY; + } + } +} + +// Update game (one frame) +void UpdateGame(void) +{ + if (!gameOver) + { + if (IsKeyPressed('P')) pause = !pause; + + if (!pause) + { + if (!lineToDelete) + { + if (!pieceActive) + { + // Get another piece + pieceActive = Createpiece(); + + // We leave a little time before starting the fast falling down + fastFallMovementCounter = 0; + } + else // Piece falling + { + // Counters update + fastFallMovementCounter++; + gravityMovementCounter++; + lateralMovementCounter++; + turnMovementCounter++; + + // We make sure to move if we've pressed the key this frame + if (IsKeyPressed(KEY_LEFT) || IsKeyPressed(KEY_RIGHT)) lateralMovementCounter = LATERAL_SPEED; + if (IsKeyPressed(KEY_UP)) turnMovementCounter = TURNING_SPEED; + + // Fall down + if (IsKeyDown(KEY_DOWN) && (fastFallMovementCounter >= FAST_FALL_AWAIT_COUNTER)) + { + // We make sure the piece is going to fall this frame + gravityMovementCounter += gravitySpeed; + } + + if (gravityMovementCounter >= gravitySpeed) + { + // Basic falling movement + CheckDetection(&detection); + + // Check if the piece has collided with another piece or with the boundings + ResolveFallingMovement(&detection, &pieceActive); + + // Check if we fullfilled a line and if so, erase the line and pull down the the lines above + CheckCompletition(&lineToDelete); + + gravityMovementCounter = 0; + } + + // Move laterally at player's will + if (lateralMovementCounter >= LATERAL_SPEED) + { + // Update the lateral movement and if success, reset the lateral counter + if (!ResolveLateralMovement()) lateralMovementCounter = 0; + } + + // Turn the piece at player's will + if (turnMovementCounter >= TURNING_SPEED) + { + // Update the turning movement and reset the turning counter + if (ResolveTurnMovement()) turnMovementCounter = 0; + } + } + + // Game over logic + for (int j = 0; j < 2; j++) + { + for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) + { + if (grid[i][j] == FULL) + { + gameOver = true; + } + } + } + } + else + { + // Animation when deleting lines + fadeLineCounter++; + + if (fadeLineCounter%8 < 4) fadingColor = MAROON; + else fadingColor = GRAY; + + if (fadeLineCounter >= FADING_TIME) + { + DeleteCompleteLines(); + fadeLineCounter = 0; + lineToDelete = false; + } + } + } + } + else + { + if (IsKeyPressed(KEY_ENTER)) + { + InitGame(); + gameOver = false; + } + } +} + +// Draw game (one frame) +void DrawGame(void) +{ + BeginDrawing(); + + ClearBackground(RAYWHITE); + + if (!gameOver) + { + // Draw gameplay area + Vector2 offset; + offset.x = screenWidth/2 - (GRID_HORIZONTAL_SIZE*SQUARE_SIZE/2); + offset.y = screenHeight/2 - ((GRID_VERTICAL_SIZE - 1)*SQUARE_SIZE/2) + SQUARE_SIZE*2; + + offset.y -= 60; // NOTE: Harcoded position! + + int controller = offset.x; + + for (int j = 0; j < GRID_VERTICAL_SIZE; j++) + { + for (int i = 0; i < GRID_HORIZONTAL_SIZE; i++) + { + // Draw each square of the grid + if (grid[i][j] == EMPTY) + { + DrawLine(offset.x, offset.y, offset.x + SQUARE_SIZE, offset.y, LIGHTGRAY ); + DrawLine(offset.x, offset.y, offset.x, offset.y + SQUARE_SIZE, LIGHTGRAY ); + DrawLine(offset.x + SQUARE_SIZE, offset.y, offset.x + SQUARE_SIZE, offset.y + SQUARE_SIZE, LIGHTGRAY ); + DrawLine(offset.x, offset.y + SQUARE_SIZE, offset.x + SQUARE_SIZE, offset.y + SQUARE_SIZE, LIGHTGRAY ); + offset.x += SQUARE_SIZE; + } + else if (grid[i][j] == FULL) + { + DrawRectangle(offset.x, offset.y, SQUARE_SIZE, SQUARE_SIZE, GRAY); + offset.x += SQUARE_SIZE; + } + else if (grid[i][j] == MOVING) + { + DrawRectangle(offset.x, offset.y, SQUARE_SIZE, SQUARE_SIZE, DARKGRAY); + offset.x += SQUARE_SIZE; + } + else if (grid[i][j] == BLOCK) + { + DrawRectangle(offset.x, offset.y, SQUARE_SIZE, SQUARE_SIZE, LIGHTGRAY); + offset.x += SQUARE_SIZE; + } + else if (grid[i][j] == FADING) + { + DrawRectangle(offset.x, offset.y, SQUARE_SIZE, SQUARE_SIZE, fadingColor); + offset.x += SQUARE_SIZE; + } + } + + offset.x = controller; + offset.y += SQUARE_SIZE; + } + + // Draw incoming piece + //offset.x = screenWidth/2 - (4*SQUARE_SIZE/2); + //offset.y = (screenHeight/2 - ((GRID_VERTICAL_SIZE - 1)*SQUARE_SIZE/2)) - (3*SQUARE_SIZE); + + // NOTE: Harcoded positions for the demo! + offset.x = 850; + offset.y = 75; + + int controler = offset.x; + + for (int j = 0; j < 4; j++) + { + for (int i = 0; i < 4; i++) + { + if (incomingPiece[i][j] == EMPTY) + { + DrawLine(offset.x, offset.y, offset.x + SQUARE_SIZE, offset.y, LIGHTGRAY ); + DrawLine(offset.x, offset.y, offset.x, offset.y + SQUARE_SIZE, LIGHTGRAY ); + DrawLine(offset.x + SQUARE_SIZE, offset.y, offset.x + SQUARE_SIZE, offset.y + SQUARE_SIZE, LIGHTGRAY ); + DrawLine(offset.x, offset.y + SQUARE_SIZE, offset.x + SQUARE_SIZE, offset.y + SQUARE_SIZE, LIGHTGRAY ); + offset.x += SQUARE_SIZE; + } + else if (incomingPiece[i][j] == MOVING) + { + DrawRectangle(offset.x, offset.y, SQUARE_SIZE, SQUARE_SIZE, GRAY); + offset.x += SQUARE_SIZE; + } + } + + offset.x = controler; + offset.y += SQUARE_SIZE; + } + + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); + } + else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); + + EndDrawing(); +} + +// Unload game variables +void UnloadGame(void) +{ + // TODO: Unload all dynamic loaded data (textures, sounds, models...) +} + +// Update and Draw (one frame) +void UpdateDrawFrame(void) +{ + UpdateGame(); + DrawGame(); +} + +//-------------------------------------------------------------------------------------- +// Additional module functions +//-------------------------------------------------------------------------------------- +static bool Createpiece() +{ + piecePositionX = (int)((GRID_HORIZONTAL_SIZE - 4)/2); + piecePositionY = 0; + + // If the game is starting and you are going to create the first piece, we create an extra one + if (beginPlay) + { + GetRandompiece(); + beginPlay = false; + } + + // We assign the incoming piece to the actual piece + for (int i = 0; i < 4; i++) + { + for (int j = 0; j< 4; j++) + { + piece[i][j] = incomingPiece[i][j]; + } + } + + // We assign a random piece to the incoming one + GetRandompiece(); + + // Assign the piece to the grid + for (int i = piecePositionX; i < piecePositionX + 4; i++) + { + for (int j = 0; j < 4; j++) + { + if (piece[i - (int)piecePositionX][j] == MOVING) grid[i][j] = MOVING; + } + } + + return true; +} + +static void GetRandompiece() +{ + srand(time(NULL)); + int random = rand() % 7; + + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + incomingPiece[i][j] = EMPTY; + } + } + + switch(random) + { + case 0: { incomingPiece[1][1] = MOVING; incomingPiece[2][1] = MOVING; incomingPiece[1][2] = MOVING; incomingPiece[2][2] = MOVING; } break; //Cube + case 1: { incomingPiece[1][0] = MOVING; incomingPiece[1][1] = MOVING; incomingPiece[1][2] = MOVING; incomingPiece[2][2] = MOVING; } break; //L + case 2: { incomingPiece[1][2] = MOVING; incomingPiece[2][0] = MOVING; incomingPiece[2][1] = MOVING; incomingPiece[2][2] = MOVING; } break; //L inversa + case 3: { incomingPiece[0][1] = MOVING; incomingPiece[1][1] = MOVING; incomingPiece[2][1] = MOVING; incomingPiece[3][1] = MOVING; } break; //Recta + case 4: { incomingPiece[1][0] = MOVING; incomingPiece[1][1] = MOVING; incomingPiece[1][2] = MOVING; incomingPiece[2][1] = MOVING; } break; //Creu tallada + case 5: { incomingPiece[1][1] = MOVING; incomingPiece[2][1] = MOVING; incomingPiece[2][2] = MOVING; incomingPiece[3][2] = MOVING; } break; //S + case 6: { incomingPiece[1][2] = MOVING; incomingPiece[2][2] = MOVING; incomingPiece[2][1] = MOVING; incomingPiece[3][1] = MOVING; } break; //S inversa + } +} + +static void ResolveFallingMovement(bool *detection, bool *pieceActive) +{ + // If we finished moving this piece, we stop it + if (*detection) + { + for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--) + { + for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) + { + if (grid[i][j] == MOVING) + { + grid[i][j] = FULL; + *detection = false; + *pieceActive = false; + } + } + } + } + // We move down the piece + else + { + for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--) + { + for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) + { + if (grid[i][j] == MOVING) + { + grid[i][j+1] = MOVING; + grid[i][j] = EMPTY; + } + } + } + piecePositionY++; + } +} + +static bool ResolveLateralMovement() +{ + bool collision = false; + + // Move left + if (IsKeyDown(KEY_LEFT)) + { + // Check if is possible to move to left + for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--) + { + for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) + { + if (grid[i][j] == MOVING) + { + // Check if we are touching the left wall or we have a full square at the left + if ((i-1 == 0) || (grid[i-1][j] == FULL)) collision = true; + } + } + } + // If able, move left + if (!collision) + { + for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--) + { + for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) // We check the matrix from left to right + { + // Move everything to the left + if (grid[i][j] == MOVING) + { + grid[i-1][j] = MOVING; + grid[i][j] = EMPTY; + } + } + } + + piecePositionX--; + } + } + + // Move right + else if (IsKeyDown(KEY_RIGHT)) + { + // Check if is possible to move to right + for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--) + { + for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) + { + if (grid[i][j] == MOVING) + { + // Check if we are touching the right wall or we have a full square at the right + if ((i+1 == GRID_HORIZONTAL_SIZE - 1) || (grid[i+1][j] == FULL)) + { + collision = true; + + } + } + } + } + // If able move right + if (!collision) + { + for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--) + { + for (int i = GRID_HORIZONTAL_SIZE - 1; i >= 1; i--) // We check the matrix from right to left + { + // Move everything to the right + if (grid[i][j] == MOVING) + { + grid[i+1][j] = MOVING; + grid[i][j] = EMPTY; + } + } + } + + piecePositionX++; + } + } + + return collision; +} + +static bool ResolveTurnMovement() +{ + // Input for turning the piece + if (IsKeyDown(KEY_UP)) + { + int aux; + bool checker = false; + + // Check all turning possibilities + if ((grid[piecePositionX + 3][piecePositionY] == MOVING) && + (grid[piecePositionX][piecePositionY] != EMPTY) && + (grid[piecePositionX][piecePositionY] != MOVING)) + { + checker = true; + } + if ((grid[piecePositionX + 3][piecePositionY + 3] == MOVING) && + (grid[piecePositionX + 3][piecePositionY] != EMPTY) && + (grid[piecePositionX + 3][piecePositionY] != MOVING)) + { + checker = true; + } + if ((grid[piecePositionX][piecePositionY + 3] == MOVING) && + (grid[piecePositionX + 3][piecePositionY + 3] != EMPTY) && + (grid[piecePositionX + 3][piecePositionY + 3] != MOVING)) + { + checker = true; + } + if ((grid[piecePositionX][piecePositionY] == MOVING) && + (grid[piecePositionX][piecePositionY + 3] != EMPTY) && + (grid[piecePositionX][piecePositionY + 3] != MOVING)) + { + checker = true; + } + + + if ((grid[piecePositionX + 1][piecePositionY] == MOVING) && + (grid[piecePositionX][piecePositionY + 2] != EMPTY) && + (grid[piecePositionX][piecePositionY + 2] != MOVING)) + { + checker = true; + } + if ((grid[piecePositionX + 3][piecePositionY + 1] == MOVING) && + (grid[piecePositionX + 1][piecePositionY] != EMPTY) && + (grid[piecePositionX + 1][piecePositionY] != MOVING)) + { + checker = true; + } + if ((grid[piecePositionX + 2][piecePositionY + 3] == MOVING) && + (grid[piecePositionX + 3][piecePositionY + 1] != EMPTY) && + (grid[piecePositionX + 3][piecePositionY + 1] != MOVING)) + { + checker = true; + } + if ((grid[piecePositionX][piecePositionY + 2] == MOVING) && + (grid[piecePositionX + 2][piecePositionY + 3] != EMPTY) && + (grid[piecePositionX + 2][piecePositionY + 3] != MOVING)) + { + checker = true; + } + + + if ((grid[piecePositionX + 2][piecePositionY] == MOVING) && + (grid[piecePositionX][piecePositionY + 1] != EMPTY) && + (grid[piecePositionX][piecePositionY + 1] != MOVING)) + { + checker = true; + } + if ((grid[piecePositionX + 3][piecePositionY + 2] == MOVING) && + (grid[piecePositionX + 2][piecePositionY] != EMPTY) && + (grid[piecePositionX + 2][piecePositionY] != MOVING)) + { + checker = true; + } + if ((grid[piecePositionX + 1][piecePositionY + 3] == MOVING) && + (grid[piecePositionX + 3][piecePositionY + 2] != EMPTY) && + (grid[piecePositionX + 3][piecePositionY + 2] != MOVING)) + { + checker = true; + } + if ((grid[piecePositionX][piecePositionY + 1] == MOVING) && + (grid[piecePositionX + 1][piecePositionY + 3] != EMPTY) && + (grid[piecePositionX + 1][piecePositionY + 3] != MOVING)) + { + checker = true; + } + + if ((grid[piecePositionX + 1][piecePositionY + 1] == MOVING) && + (grid[piecePositionX + 1][piecePositionY + 2] != EMPTY) && + (grid[piecePositionX + 1][piecePositionY + 2] != MOVING)) + { + checker = true; + } + + if ((grid[piecePositionX + 2][piecePositionY + 1] == MOVING) && + (grid[piecePositionX + 1][piecePositionY + 1] != EMPTY) && + (grid[piecePositionX + 1][piecePositionY + 1] != MOVING)) + { + checker = true; + } + if ((grid[piecePositionX + 2][piecePositionY + 2] == MOVING) && + (grid[piecePositionX + 2][piecePositionY + 1] != EMPTY) && + (grid[piecePositionX + 2][piecePositionY + 1] != MOVING)) + { + checker = true; + } + if ((grid[piecePositionX + 1][piecePositionY + 2] == MOVING) && + (grid[piecePositionX + 2][piecePositionY + 2] != EMPTY) && + (grid[piecePositionX + 2][piecePositionY + 2] != MOVING)) + { + checker = true; + } + + if (!checker) + { + aux = piece[0][0]; + piece[0][0] = piece[3][0]; + piece[3][0] = piece[3][3]; + piece[3][3] = piece[0][3]; + piece[0][3] = aux; + + aux = piece[1][0]; + piece[1][0] = piece[3][1]; + piece[3][1] = piece[2][3]; + piece[2][3] = piece[0][2]; + piece[0][2] = aux; + + aux = piece[2][0]; + piece[2][0] = piece[3][2]; + piece[3][2] = piece[1][3]; + piece[1][3] = piece[0][1]; + piece[0][1] = aux; + + aux = piece[1][1]; + piece[1][1] = piece[2][1]; + piece[2][1] = piece[2][2]; + piece[2][2] = piece[1][2]; + piece[1][2] = aux; + } + + for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--) + { + for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) + { + if (grid[i][j] == MOVING) + { + grid[i][j] = EMPTY; + } + } + } + + for (int i = piecePositionX; i < piecePositionX + 4; i++) + { + for (int j = piecePositionY; j < piecePositionY + 4; j++) + { + if (piece[i - piecePositionX][j - piecePositionY] == MOVING) + { + grid[i][j] = MOVING; + } + } + } + return true; + } + + return false; +} + +static void CheckDetection(bool *detection) +{ + for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--) + { + for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) + { + if ((grid[i][j] == MOVING) && ((grid[i][j+1] == FULL) || (grid[i][j+1] == BLOCK))) *detection = true; + } + } +} + +static void CheckCompletition(bool *lineToDelete) +{ + int calculator; + + for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--) + { + calculator = 0; + for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) + { + // Count each square of the line + if (grid[i][j] == FULL) + { + calculator++; + } + + // Check if we completed the whole line + if (calculator == GRID_HORIZONTAL_SIZE - 2) + { + *lineToDelete = true; + calculator = 0; + // points++; + + // Mark the completed line + for (int z = 1; z < GRID_HORIZONTAL_SIZE - 1; z++) + { + grid[z][j] = FADING; + } + } + } + } +} + +static void DeleteCompleteLines() +{ + // erase the completed line + for (int j = GRID_VERTICAL_SIZE - 2; j >= 0; j--) + { + while (grid[1][j] == FADING) + { + for (int i = 1; i < GRID_HORIZONTAL_SIZE - 1; i++) + { + grid[i][j] = EMPTY; + } + for (int j2 = j-1; j2 >= 0; j2--) + { + for (int i2 = 1; i2 < GRID_HORIZONTAL_SIZE - 1; i2++) + { + if (grid[i2][j2] == FULL) + { + grid[i2][j2+1] = FULL; + grid[i2][j2] = EMPTY; + } + else if (grid[i2][j2] == FADING) + { + grid[i2][j2+1] = FADING; + grid[i2][j2] = EMPTY; + } + } + } + } + } +} \ No newline at end of file -- cgit v1.2.3 From e484d58d9c9cc9a081675e2ceef4d55a276ce43c Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 31 Jan 2016 15:31:51 +0100 Subject: Uploaded gamejam game sources --- games/light_my_ritual/light_my_ritual.c | 271 +++++++ games/light_my_ritual/makefile | 203 +++++ games/light_my_ritual/resources/audio/ambient.ogg | Bin 0 -> 1274574 bytes .../light_my_ritual/resources/audio/light_off.wav | Bin 0 -> 9291 bytes games/light_my_ritual/resources/audio/light_on.wav | Bin 0 -> 2335 bytes games/light_my_ritual/resources/audio/ritual.ogg | Bin 0 -> 2592921 bytes games/light_my_ritual/resources/audio/start.wav | Bin 0 -> 14079 bytes games/light_my_ritual/resources/font_arcadian.png | Bin 0 -> 97566 bytes games/light_my_ritual/resources/lights_map.png | Bin 0 -> 430 bytes .../resources/textures/back_title.png | Bin 0 -> 182900 bytes .../resources/textures/background.png | Bin 0 -> 1231218 bytes games/light_my_ritual/resources/textures/book.png | Bin 0 -> 4402 bytes .../resources/textures/circle_level_i_off.png | Bin 0 -> 15448 bytes .../resources/textures/circle_level_i_on.png | Bin 0 -> 51443 bytes .../resources/textures/circle_level_ii_off.png | Bin 0 -> 27962 bytes .../resources/textures/circle_level_ii_on.png | Bin 0 -> 106608 bytes .../resources/textures/circle_level_iii_off.png | Bin 0 -> 37564 bytes .../resources/textures/circle_level_iii_on.png | Bin 0 -> 160307 bytes games/light_my_ritual/resources/textures/enemy.png | Bin 0 -> 2812 bytes .../resources/textures/foreground_level_i.png | Bin 0 -> 28111 bytes .../resources/textures/foreground_level_ii.png | Bin 0 -> 36121 bytes .../resources/textures/foreground_level_iii.png | Bin 0 -> 42136 bytes games/light_my_ritual/resources/textures/light.png | Bin 0 -> 2275 bytes .../resources/textures/light_glow.png | Bin 0 -> 8661 bytes .../resources/textures/light_ray.png | Bin 0 -> 8780 bytes .../resources/textures/msg_ritual.png | Bin 0 -> 114012 bytes .../light_my_ritual/resources/textures/player.png | Bin 0 -> 2899 bytes .../resources/textures/time_over.png | Bin 0 -> 115874 bytes games/light_my_ritual/resources/textures/title.png | Bin 0 -> 213549 bytes games/light_my_ritual/screens/screen_gameplay.c | 842 +++++++++++++++++++++ games/light_my_ritual/screens/screen_logo_raylib.c | 214 ++++++ games/light_my_ritual/screens/screen_title.c | 105 +++ games/light_my_ritual/screens/screens.h | 78 ++ 33 files changed, 1713 insertions(+) create mode 100644 games/light_my_ritual/light_my_ritual.c create mode 100644 games/light_my_ritual/makefile create mode 100644 games/light_my_ritual/resources/audio/ambient.ogg create mode 100644 games/light_my_ritual/resources/audio/light_off.wav create mode 100644 games/light_my_ritual/resources/audio/light_on.wav create mode 100644 games/light_my_ritual/resources/audio/ritual.ogg create mode 100644 games/light_my_ritual/resources/audio/start.wav create mode 100644 games/light_my_ritual/resources/font_arcadian.png create mode 100644 games/light_my_ritual/resources/lights_map.png create mode 100644 games/light_my_ritual/resources/textures/back_title.png create mode 100644 games/light_my_ritual/resources/textures/background.png create mode 100644 games/light_my_ritual/resources/textures/book.png create mode 100644 games/light_my_ritual/resources/textures/circle_level_i_off.png create mode 100644 games/light_my_ritual/resources/textures/circle_level_i_on.png create mode 100644 games/light_my_ritual/resources/textures/circle_level_ii_off.png create mode 100644 games/light_my_ritual/resources/textures/circle_level_ii_on.png create mode 100644 games/light_my_ritual/resources/textures/circle_level_iii_off.png create mode 100644 games/light_my_ritual/resources/textures/circle_level_iii_on.png create mode 100644 games/light_my_ritual/resources/textures/enemy.png create mode 100644 games/light_my_ritual/resources/textures/foreground_level_i.png create mode 100644 games/light_my_ritual/resources/textures/foreground_level_ii.png create mode 100644 games/light_my_ritual/resources/textures/foreground_level_iii.png create mode 100644 games/light_my_ritual/resources/textures/light.png create mode 100644 games/light_my_ritual/resources/textures/light_glow.png create mode 100644 games/light_my_ritual/resources/textures/light_ray.png create mode 100644 games/light_my_ritual/resources/textures/msg_ritual.png create mode 100644 games/light_my_ritual/resources/textures/player.png create mode 100644 games/light_my_ritual/resources/textures/time_over.png create mode 100644 games/light_my_ritual/resources/textures/title.png create mode 100644 games/light_my_ritual/screens/screen_gameplay.c create mode 100644 games/light_my_ritual/screens/screen_logo_raylib.c create mode 100644 games/light_my_ritual/screens/screen_title.c create mode 100644 games/light_my_ritual/screens/screens.h (limited to 'games') diff --git a/games/light_my_ritual/light_my_ritual.c b/games/light_my_ritual/light_my_ritual.c new file mode 100644 index 00000000..0f1dc47e --- /dev/null +++ b/games/light_my_ritual/light_my_ritual.c @@ -0,0 +1,271 @@ +/******************************************************************************************* +* +* GLOBAL GAME JAM 2016 - LIGHT MY RITUAL! +* +* Preparing a ritual session is not that easy. +* You must light all the candles before the astral alignment finishes... +* but dark creatures move in the shadows to put out all your lights! +* Be fast! Be smart! Light my ritual! +* +* 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) 2015 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" +#include "screens/screens.h" // NOTE: Defines global variable: currentScreen + +#include + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- +const int screenWidth = 1280; +const int screenHeight = 720; + +// Required variables to manage screen transitions (fade-in, fade-out) +float transAlpha = 0; +bool onTransition = false; +bool transFadeOut = false; +int transFromScreen = -1; +int transToScreen = -1; + +//---------------------------------------------------------------------------------- +// Local Functions Declaration +//---------------------------------------------------------------------------------- +void TransitionToScreen(int screen); +void ChangeToScreen(int screen); // No transition effect +void UpdateTransition(void); +void DrawTransition(void); + +void UpdateDrawFrame(void); // Update and Draw one frame + +//---------------------------------------------------------------------------------- +// Main entry point +//---------------------------------------------------------------------------------- +int main(void) +{ + // Initialization + //--------------------------------------------------------- + InitWindow(screenWidth, screenHeight, "GGJ16 - LIGHT MY RITUAL!"); + + // Global data loading (assets that must be available in all screens, i.e. fonts) + InitAudioDevice(); + + Image image = LoadImage("resources/lights_map.png"); // Load image in CPU memory (RAM) + + lightsMap = GetImageData(image); // Get image pixels data as an array of Color + lightsMapWidth = image.width; + lightsMapHeight = image.height; + + UnloadImage(image); // Unload image from CPU memory (RAM) + + //PlayMusicStream("resources/audio/come_play_with_me.ogg"); + + font = LoadSpriteFont("resources/font_arcadian.png"); + //doors = LoadTexture("resources/textures/doors.png"); + //sndDoor = LoadSound("resources/audio/door.ogg"); + + // Setup and Init first screen + currentScreen = LOGO_RL; + //InitTitleScreen(); + //InitGameplayScreen(); + rlInitLogoScreen(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 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 + //-------------------------------------------------------------------------------------- + switch (currentScreen) + { + case LOGO_RL: rlUnloadLogoScreen(); break; + case TITLE: UnloadTitleScreen(); break; + case GAMEPLAY: UnloadGameplayScreen(); break; + default: break; + } + + // Unload all global loaded data (i.e. fonts) here! + UnloadSpriteFont(font); + //UnloadSound(sndDoor); + + free(lightsMap); + + CloseAudioDevice(); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +void TransitionToScreen(int screen) +{ + onTransition = true; + transFromScreen = currentScreen; + transToScreen = screen; +} + +void ChangeToScreen(int screen) +{ + switch (currentScreen) + { + case LOGO_RL: rlUnloadLogoScreen(); break; + case TITLE: UnloadTitleScreen(); break; + case GAMEPLAY: UnloadGameplayScreen(); break; + default: break; + } + + switch (screen) + { + case LOGO_RL: rlInitLogoScreen(); break; + case TITLE: InitTitleScreen(); break; + case GAMEPLAY: InitGameplayScreen(); break; + default: break; + } + + currentScreen = screen; +} + +void UpdateTransition(void) +{ + if (!transFadeOut) + { + transAlpha += 0.05f; + + if (transAlpha >= 1.0) + { + transAlpha = 1.0; + + switch (transFromScreen) + { + case LOGO_RL: rlUnloadLogoScreen(); break; + case TITLE: UnloadTitleScreen(); break; + case GAMEPLAY: UnloadGameplayScreen(); break; + default: break; + } + + switch (transToScreen) + { + case LOGO_RL: + { + rlInitLogoScreen(); + currentScreen = LOGO_RL; + } break; + case TITLE: + { + InitTitleScreen(); + currentScreen = TITLE; + } break; + case GAMEPLAY: + { + InitGameplayScreen(); + currentScreen = GAMEPLAY; + } break; + default: break; + } + + transFadeOut = true; + } + } + else // Transition fade out logic + { + transAlpha -= 0.05f; + + if (transAlpha <= 0) + { + transAlpha = 0; + transFadeOut = false; + onTransition = false; + transFromScreen = -1; + transToScreen = -1; + } + } +} + +void DrawTransition(void) +{ + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(BLACK, transAlpha)); +} + +// Update and draw game frame +void UpdateDrawFrame(void) +{ + // Update + //---------------------------------------------------------------------------------- + if (!onTransition) + { + switch(currentScreen) + { + case LOGO_RL: + { + rlUpdateLogoScreen(); + + if (rlFinishLogoScreen()) TransitionToScreen(TITLE); + + } break; + case TITLE: + { + UpdateTitleScreen(); + + if (FinishTitleScreen() == 1) TransitionToScreen(GAMEPLAY); + + } break; + case GAMEPLAY: + { + UpdateGameplayScreen(); + + if (FinishGameplayScreen() == 1) ChangeToScreen(LOGO_RL); + else if (FinishGameplayScreen() == 2) TransitionToScreen(TITLE); + + } break; + default: break; + } + } + else + { + // Update transition (fade-in, fade-out) + UpdateTransition(); + } + + UpdateMusicStream(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + switch(currentScreen) + { + case LOGO_RL: rlDrawLogoScreen(); break; + case TITLE: DrawTitleScreen(); break; + case GAMEPLAY: DrawGameplayScreen(); break; + default: break; + } + + if (onTransition) DrawTransition(); + + //DrawFPS(10, 10); + + EndDrawing(); + //---------------------------------------------------------------------------------- +} + diff --git a/games/light_my_ritual/makefile b/games/light_my_ritual/makefile new file mode 100644 index 00000000..b7e1bb58 --- /dev/null +++ b/games/light_my_ritual/makefile @@ -0,0 +1,203 @@ +#************************************************************************************************** +# +# raylib - Advance Game +# +# makefile to compile advance game +# +# Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +# +# 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. +# +#************************************************************************************************** + +# define raylib platform if not defined (by default, compile for RPI) +# Other possible platform: PLATFORM_DESKTOP +PLATFORM ?= PLATFORM_DESKTOP + +# determine PLATFORM_OS in case PLATFORM_DESKTOP selected +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + # No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows + ifeq ($(OS),Windows_NT) + PLATFORM_OS=WINDOWS + LIBPATH=win32 + else + UNAMEOS:=$(shell uname) + ifeq ($(UNAMEOS),Linux) + PLATFORM_OS=LINUX + LIBPATH=linux + else + ifeq ($(UNAMEOS),Darwin) + PLATFORM_OS=OSX + LIBPATH=osx + endif + endif + endif +endif + +# define compiler: gcc for C program, define as g++ for C++ +ifeq ($(PLATFORM),PLATFORM_WEB) + # define emscripten compiler + CC = emcc +else +ifeq ($(PLATFORM_OS),OSX) + # define llvm compiler for mac + CC = clang +else + # define default gcc compiler + CC = gcc +endif +endif + +# define compiler flags: +# -O2 defines optimization level +# -Wall turns on most, but not all, compiler warnings +# -std=c99 use standard C from 1999 revision +ifeq ($(PLATFORM),PLATFORM_RPI) + CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline +else + CFLAGS = -O2 -Wall -std=c99 +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 --preload-file resources -s ALLOW_MEMORY_GROWTH=1 + #-s ASSERTIONS=1 --preload-file resources + #-s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing + #-s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) +endif + +# define any directories containing required header files +ifeq ($(PLATFORM),PLATFORM_RPI) + INCLUDES = -I. -I../../src -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads +else + INCLUDES = -I. -IC:/raylib/raylib/src -IC:/raylib/raylib/src +# external libraries headers +# GLFW3 + INCLUDES += -I../../external/glfw3/include +# GLEW + INCLUDES += -I../../external/glew/include +# OpenAL Soft + INCLUDES += -I../../external/openal_soft/include +endif + +# define library paths containing required libs +ifeq ($(PLATFORM),PLATFORM_RPI) + LFLAGS = -L. -L../../src -L/opt/vc/lib +else + LFLAGS = -L. -LC:/raylib/raylib/src -L../../../src + # external libraries to link with + # GLFW3 + LFLAGS += -L../../external/glfw3/lib/$(LIBPATH) + ifneq ($(PLATFORM_OS),OSX) + # OpenAL Soft + LFLAGS += -L../../external/openal_soft/lib/$(LIBPATH) + # GLEW + LFLAGS += -L../../external/glew/lib/$(LIBPATH) + endif +endif + +# define any libraries to link into executable +# if you want to link libraries (libname.so or libname.a), use the -lname +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),LINUX) + # libraries for Debian GNU/Linux desktop compiling + # requires the following packages: + # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev + LIBS = -lraylib -lglfw -lGLEW -lGL -lopenal + endif + ifeq ($(PLATFORM_OS),OSX) + # libraries for OS X 10.9 desktop compiling + # requires the following packages: + # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev + LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAl -framework Cocoa + else + # libraries for Windows desktop compiling + # NOTE: GLFW3 and OpenAL Soft libraries should be installed + LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32 + endif +endif +ifeq ($(PLATFORM),PLATFORM_RPI) + # libraries for Raspberry Pi compiling + # NOTE: OpenAL Soft library should be installed (libopenal1 package) + LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + LIBS = C:/raylib/raylib/src/libraylib.bc +endif + +# define additional parameters and flags for windows +ifeq ($(PLATFORM_OS),WINDOWS) + # resources file contains windows exe icon + # -Wl,--subsystem,windows hides the console window + WINFLAGS = C:/raylib/raylib/src/resources -Wl,--subsystem,windows +endif + +ifeq ($(PLATFORM),PLATFORM_WEB) + EXT = .html +endif + +# define all screen object files required +SCREENS = \ + screens/screen_logo_raylib.o \ + screens/screen_title.o \ + screens/screen_gameplay.o \ + +# typing 'make' will invoke the first target entry in the file, +# in this case, the 'default' target entry is advance_game +default: light_my_ritual + +# compile template - advance_game +light_my_ritual: light_my_ritual.c $(SCREENS) + $(CC) -o $@$(EXT) $< $(SCREENS) $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) + +# compile screen LOGO raylib +screens/screen_logo_raylib.o: screens/screen_logo_raylib.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen TITLE +screens/screen_title.o: screens/screen_title.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen ENDING +screens/screen_gameplay.o: screens/screen_gameplay.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# clean everything +clean: +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),OSX) + find . -type f -perm +ugo+x -delete + rm -f *.o + else + ifeq ($(PLATFORM_OS),LINUX) + find . -type f -executable -delete + rm -f *.o + else + del *.o *.exe + endif + endif +endif +ifeq ($(PLATFORM),PLATFORM_RPI) + find . -type f -executable -delete + rm -f *.o +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + del *.o *.html *.js +endif + @echo Cleaning done + +# instead of defining every module one by one, we can define a pattern +# this pattern below will automatically compile every module defined on $(OBJS) +#%.exe : %.c +# $(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) diff --git a/games/light_my_ritual/resources/audio/ambient.ogg b/games/light_my_ritual/resources/audio/ambient.ogg new file mode 100644 index 00000000..5828c516 Binary files /dev/null and b/games/light_my_ritual/resources/audio/ambient.ogg differ diff --git a/games/light_my_ritual/resources/audio/light_off.wav b/games/light_my_ritual/resources/audio/light_off.wav new file mode 100644 index 00000000..d2203e72 Binary files /dev/null and b/games/light_my_ritual/resources/audio/light_off.wav differ diff --git a/games/light_my_ritual/resources/audio/light_on.wav b/games/light_my_ritual/resources/audio/light_on.wav new file mode 100644 index 00000000..38b7ca58 Binary files /dev/null and b/games/light_my_ritual/resources/audio/light_on.wav differ diff --git a/games/light_my_ritual/resources/audio/ritual.ogg b/games/light_my_ritual/resources/audio/ritual.ogg new file mode 100644 index 00000000..4674ff7b Binary files /dev/null and b/games/light_my_ritual/resources/audio/ritual.ogg differ diff --git a/games/light_my_ritual/resources/audio/start.wav b/games/light_my_ritual/resources/audio/start.wav new file mode 100644 index 00000000..66ce7ac1 Binary files /dev/null and b/games/light_my_ritual/resources/audio/start.wav differ diff --git a/games/light_my_ritual/resources/font_arcadian.png b/games/light_my_ritual/resources/font_arcadian.png new file mode 100644 index 00000000..5c3df51a Binary files /dev/null and b/games/light_my_ritual/resources/font_arcadian.png differ diff --git a/games/light_my_ritual/resources/lights_map.png b/games/light_my_ritual/resources/lights_map.png new file mode 100644 index 00000000..362094cd Binary files /dev/null and b/games/light_my_ritual/resources/lights_map.png differ diff --git a/games/light_my_ritual/resources/textures/back_title.png b/games/light_my_ritual/resources/textures/back_title.png new file mode 100644 index 00000000..54921247 Binary files /dev/null and b/games/light_my_ritual/resources/textures/back_title.png differ diff --git a/games/light_my_ritual/resources/textures/background.png b/games/light_my_ritual/resources/textures/background.png new file mode 100644 index 00000000..367bdd30 Binary files /dev/null and b/games/light_my_ritual/resources/textures/background.png differ diff --git a/games/light_my_ritual/resources/textures/book.png b/games/light_my_ritual/resources/textures/book.png new file mode 100644 index 00000000..c0bfbdb3 Binary files /dev/null and b/games/light_my_ritual/resources/textures/book.png differ diff --git a/games/light_my_ritual/resources/textures/circle_level_i_off.png b/games/light_my_ritual/resources/textures/circle_level_i_off.png new file mode 100644 index 00000000..7961af7d Binary files /dev/null and b/games/light_my_ritual/resources/textures/circle_level_i_off.png differ diff --git a/games/light_my_ritual/resources/textures/circle_level_i_on.png b/games/light_my_ritual/resources/textures/circle_level_i_on.png new file mode 100644 index 00000000..1f217734 Binary files /dev/null and b/games/light_my_ritual/resources/textures/circle_level_i_on.png differ diff --git a/games/light_my_ritual/resources/textures/circle_level_ii_off.png b/games/light_my_ritual/resources/textures/circle_level_ii_off.png new file mode 100644 index 00000000..642adc3b Binary files /dev/null and b/games/light_my_ritual/resources/textures/circle_level_ii_off.png differ diff --git a/games/light_my_ritual/resources/textures/circle_level_ii_on.png b/games/light_my_ritual/resources/textures/circle_level_ii_on.png new file mode 100644 index 00000000..93b71b3a Binary files /dev/null and b/games/light_my_ritual/resources/textures/circle_level_ii_on.png differ diff --git a/games/light_my_ritual/resources/textures/circle_level_iii_off.png b/games/light_my_ritual/resources/textures/circle_level_iii_off.png new file mode 100644 index 00000000..daf50be9 Binary files /dev/null and b/games/light_my_ritual/resources/textures/circle_level_iii_off.png differ diff --git a/games/light_my_ritual/resources/textures/circle_level_iii_on.png b/games/light_my_ritual/resources/textures/circle_level_iii_on.png new file mode 100644 index 00000000..e2256e95 Binary files /dev/null and b/games/light_my_ritual/resources/textures/circle_level_iii_on.png differ diff --git a/games/light_my_ritual/resources/textures/enemy.png b/games/light_my_ritual/resources/textures/enemy.png new file mode 100644 index 00000000..dc0a911d Binary files /dev/null and b/games/light_my_ritual/resources/textures/enemy.png differ diff --git a/games/light_my_ritual/resources/textures/foreground_level_i.png b/games/light_my_ritual/resources/textures/foreground_level_i.png new file mode 100644 index 00000000..32b96740 Binary files /dev/null and b/games/light_my_ritual/resources/textures/foreground_level_i.png differ diff --git a/games/light_my_ritual/resources/textures/foreground_level_ii.png b/games/light_my_ritual/resources/textures/foreground_level_ii.png new file mode 100644 index 00000000..44f26003 Binary files /dev/null and b/games/light_my_ritual/resources/textures/foreground_level_ii.png differ diff --git a/games/light_my_ritual/resources/textures/foreground_level_iii.png b/games/light_my_ritual/resources/textures/foreground_level_iii.png new file mode 100644 index 00000000..0fc039d7 Binary files /dev/null and b/games/light_my_ritual/resources/textures/foreground_level_iii.png differ diff --git a/games/light_my_ritual/resources/textures/light.png b/games/light_my_ritual/resources/textures/light.png new file mode 100644 index 00000000..5d08326f Binary files /dev/null and b/games/light_my_ritual/resources/textures/light.png differ diff --git a/games/light_my_ritual/resources/textures/light_glow.png b/games/light_my_ritual/resources/textures/light_glow.png new file mode 100644 index 00000000..d31356c6 Binary files /dev/null and b/games/light_my_ritual/resources/textures/light_glow.png differ diff --git a/games/light_my_ritual/resources/textures/light_ray.png b/games/light_my_ritual/resources/textures/light_ray.png new file mode 100644 index 00000000..f9f877fa Binary files /dev/null and b/games/light_my_ritual/resources/textures/light_ray.png differ diff --git a/games/light_my_ritual/resources/textures/msg_ritual.png b/games/light_my_ritual/resources/textures/msg_ritual.png new file mode 100644 index 00000000..73f14d48 Binary files /dev/null and b/games/light_my_ritual/resources/textures/msg_ritual.png differ diff --git a/games/light_my_ritual/resources/textures/player.png b/games/light_my_ritual/resources/textures/player.png new file mode 100644 index 00000000..d6849478 Binary files /dev/null and b/games/light_my_ritual/resources/textures/player.png differ diff --git a/games/light_my_ritual/resources/textures/time_over.png b/games/light_my_ritual/resources/textures/time_over.png new file mode 100644 index 00000000..9f7935be Binary files /dev/null and b/games/light_my_ritual/resources/textures/time_over.png differ diff --git a/games/light_my_ritual/resources/textures/title.png b/games/light_my_ritual/resources/textures/title.png new file mode 100644 index 00000000..55eb593d Binary files /dev/null and b/games/light_my_ritual/resources/textures/title.png differ diff --git a/games/light_my_ritual/screens/screen_gameplay.c b/games/light_my_ritual/screens/screen_gameplay.c new file mode 100644 index 00000000..b91d2545 --- /dev/null +++ b/games/light_my_ritual/screens/screen_gameplay.c @@ -0,0 +1,842 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +#include + +#define MAX_LIGHTS_I 8 +#define MAX_LIGHTS_II 12 +#define MAX_LIGHTS_III 20 + +#define MAX_ENEMIES 8 + +#define MAX_PLAYER_ENERGY 40.0f +#define ENERGY_REFILL_RATIO 0.2f + +#define GAMEPAD_SENSITIVITY 4.0f // More sensitivity, more speed :P + +#define LIGHT_ANIM_FRAMES 7 + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef struct Player { + Vector2 position; + Vector2 speed; + int radius; + Color color; + float lightEnergy; +} Player; + +typedef struct Enemy { + Vector2 position; + Vector2 targetPos; // light target position + int targetNum; // light target number + float speed; // scalar value + int radius; + int active; + int awakeFramesDelay; + int framesCounter; + Color color; +} Enemy; + +typedef struct Light { + Vector2 position; + int radius; + int requiredEnergy; + bool active; + Color color; + + int framesCounter; + int currentFrame; + Rectangle frameRec; +} Light; + +typedef enum { LEVEL_I, LEVEL_II, LEVEL_III, LEVEL_FINISHED } LightedLevel; + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Gameplay screen global variables +static int framesCounter; +static int finishScreen; + +//static Texture2D background; + +static bool pause; + +static Player player; + +static Light lightsI[MAX_LIGHTS_I]; +static Light lightsII[MAX_LIGHTS_II]; +static Light lightsIII[MAX_LIGHTS_III]; + +static Enemy enemies[MAX_ENEMIES]; + +static int ritualLevel; +static int previousLightedLevel; +static int currentLightedLevel; + +static Vector2 lighterPosition; + +static int maxLightEnergy; +static int currentLightEnergy; + +static float ritualTime; +static bool startRitual; +static float alphaRitual; + +static bool timeOver; +static int nextStarsAlignment; + +static Texture2D background; +static Texture2D foregroundI; +static Texture2D foregroundII; +static Texture2D foregroundIII; +static Texture2D texPlayer; +static Texture2D texEnemy; +static Texture2D texLight; +static Texture2D lightGlow; +static Texture2D lightRay; +static Texture2D book; +static Texture2D texRitual; +static Texture2D texTimeOver; +static Texture2D circleIoff, circleIIoff, circleIIIoff; +static Texture2D circleIon, circleIIon, circleIIIon; + +static Rectangle lightOff, lightOn; + +static Sound fxLightOn, fxLightOff; + +// Debug variables +static bool enemiesStopped; + +//------------------------------------------------------------------------------------ +// Module Functions Declaration (local) +//------------------------------------------------------------------------------------ +static bool ColorEqual(Color col1, Color col2); // Check if two colors are equal +static Vector2 Vector2Subtract(Vector2 v1, Vector2 v2); +static void Vector2Normalize(Vector2 *v); +static void EnemyReset(Enemy *enemy); + +//---------------------------------------------------------------------------------- +// Gameplay Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Gameplay Screen Initialization logic +void InitGameplayScreen(void) +{ + framesCounter = 0; + finishScreen = 0; + pause = false; + + // Textures loading + background = LoadTexture("resources/textures/background.png"); + foregroundI = LoadTexture("resources/textures/foreground_level_i.png"); + foregroundII = LoadTexture("resources/textures/foreground_level_ii.png"); + foregroundIII = LoadTexture("resources/textures/foreground_level_iii.png"); + texPlayer = LoadTexture("resources/textures/player.png"); + texEnemy = LoadTexture("resources/textures/enemy.png"); + texLight = LoadTexture("resources/textures/light.png"); + lightGlow = LoadTexture("resources/textures/light_glow.png"); + lightRay = LoadTexture("resources/textures/light_ray.png"); + book = LoadTexture("resources/textures/book.png"); + texRitual = LoadTexture("resources/textures/msg_ritual.png"); + texTimeOver = LoadTexture("resources/textures/time_over.png"); + + circleIoff = LoadTexture("resources/textures/circle_level_i_off.png"); + circleIIoff = LoadTexture("resources/textures/circle_level_ii_off.png"); + circleIIIoff = LoadTexture("resources/textures/circle_level_iii_off.png"); + circleIon = LoadTexture("resources/textures/circle_level_i_on.png"); + circleIIon = LoadTexture("resources/textures/circle_level_ii_on.png"); + circleIIIon = LoadTexture("resources/textures/circle_level_iii_on.png"); + + lightOff = (Rectangle){ 0, 0, 64, 64 }; + lightOn = (Rectangle){ 64, 0, 64, 64 }; + + fxLightOn = LoadSound("resources/audio/light_on.wav"); + fxLightOff = LoadSound("resources/audio/light_off.wav"); + + // Initialize player + player.position = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 - 40 }; + player.radius = 20; + player.speed = (Vector2){5, 5}; + player.color = WHITE; + + // Initialize lights positions based on lights map image data + int kI = 0, kII = 0, kIII = 0; + for (int y = 0; y < lightsMapHeight; y++) + { + for (int x = 0; x < lightsMapWidth; x++) + { + if (ColorEqual(lightsMap[y*lightsMapWidth + x], (Color){ 255, 0, 0, 255 })) + { + // Store light position I + lightsI[kI].position.x = (float)x*10; + lightsI[kI].position.y = (float)y*10; + kI++; + + //printf("Light %02i position: %i, %i\n", kI, (int)lightsI[kI - 1].position.x, (int)lightsI[kI - 1].position.y); + } + else if (ColorEqual(lightsMap[y*lightsMapWidth + x], (Color){ 0, 255, 0, 255 })) + { + // Store light position II + lightsII[kII].position.x = (float)x*10; + lightsII[kII].position.y = (float)y*10; + kII++; + } + else if (ColorEqual(lightsMap[y*lightsMapWidth + x], (Color){ 0, 0, 255, 255 })) + { + // Store light position III + lightsIII[kIII].position.x = (float)x*10; + lightsIII[kIII].position.y = (float)y*10; + kIII++; + } + } + } + + // Initialize lights I + for (int i = 0; i < MAX_LIGHTS_I; i++) + { + lightsI[i].radius = 12; + lightsI[i].requiredEnergy = GetRandomValue(3, 9); + lightsI[i].active = false; + lightsI[i].color = GOLD; + + lightsI[i].framesCounter = 0; + lightsI[i].currentFrame = 0; + lightsI[i].frameRec = (Rectangle){ 0, 0, 64, 64 }; + } + + // Initialize lights II + for (int i = 0; i < MAX_LIGHTS_II; i++) + { + lightsII[i].radius = 8; + lightsII[i].requiredEnergy = GetRandomValue(3, 8); + lightsII[i].active = false; + lightsII[i].color = GOLD; + + lightsII[i].framesCounter = 0; + lightsII[i].currentFrame = 0; + lightsII[i].frameRec = (Rectangle){ 0, 0, 64, 64 }; + } + + // Initialize lights III + for (int i = 0; i < MAX_LIGHTS_III; i++) + { + lightsIII[i].radius = 8; + lightsIII[i].requiredEnergy = GetRandomValue(4, 10); + lightsIII[i].active = false; + lightsIII[i].color = GOLD; + + lightsIII[i].framesCounter = 0; + lightsIII[i].currentFrame = 0; + lightsIII[i].frameRec = (Rectangle){ 0, 0, 64, 64 }; + } + + // Initialize ritual level + ritualLevel = 0; + currentLightedLevel = LEVEL_I; + lighterPosition = (Vector2){ GetScreenWidth()/2, GetScreenHeight()/2 }; + + // Initialize enemies + for (int i = 0; i < MAX_ENEMIES; i++) EnemyReset(&enemies[i]); + + // Initialize max light energy (depends on lights randomness) + maxLightEnergy = 0; + + for (int i = 0; i < MAX_LIGHTS_I; i++) maxLightEnergy += lightsI[i].requiredEnergy; + for (int i = 0; i < MAX_LIGHTS_II; i++) maxLightEnergy += lightsII[i].requiredEnergy; + for (int i = 0; i < MAX_LIGHTS_III; i++) maxLightEnergy += lightsIII[i].requiredEnergy; + + //printf("Max light energy: %i\n", maxLightEnergy); + + // Initialize ritual variables + ritualTime = 0.0f; + startRitual = false;; + alphaRitual = 0.0f; + + timeOver = false; + nextStarsAlignment = GetRandomValue(500, 1000); + + enemiesStopped = false; + + PlayMusicStream("resources/audio/ritual.ogg"); +} + +// Gameplay Screen Update logic +void UpdateGameplayScreen(void) +{ + if (IsKeyPressed('P')) pause = !pause; + + if (!pause && (currentLightedLevel != LEVEL_FINISHED) && !timeOver) + { + framesCounter++; // Time starts counting to awake enemies + + // Player movement logic + if (IsKeyDown(KEY_RIGHT)) player.position.x += player.speed.x; + else if (IsKeyDown(KEY_LEFT)) player.position.x -= player.speed.x; + + if (IsKeyDown(KEY_UP)) player.position.y -= player.speed.y; + else if (IsKeyDown(KEY_DOWN)) player.position.y += player.speed.y; + + // Debug key to stop enemies + if (IsKeyPressed(KEY_S)) enemiesStopped = !enemiesStopped; + + /* + if (IsGamepadAvailable(GAMEPAD_PLAYER1)) + { + Vector2 movement = GetGamepadMovement(GAMEPAD_PLAYER1); + + player.position.x += movement.x*GAMEPAD_SENSITIVITY; + player.position.y += movement.y*GAMEPAD_SENSITIVITY; + } + */ + + // Player light energy filling logic + if (CheckCollisionCircles(player.position, player.radius, lighterPosition, 50)) + { + player.lightEnergy += ENERGY_REFILL_RATIO; + player.color = (Color){ 255, 255, 100, 255 }; + } + else player.color = WHITE; + + if (player.lightEnergy > MAX_PLAYER_ENERGY) player.lightEnergy = MAX_PLAYER_ENERGY; + + // Player vs lights collision detection (depends on lighted level) + if (currentLightedLevel == LEVEL_I) + { + for (int i = 0; i < MAX_LIGHTS_I; i++) + { + // Check player vs lightI collision + if (CheckCollisionCircles(player.position, player.radius, lightsI[i].position, lightsI[i].radius)) + { + if (!lightsI[i].active && (player.lightEnergy >= lightsI[i].requiredEnergy)) + { + lightsI[i].active = true; + lightsI[i].currentFrame = 1; + player.lightEnergy -= lightsI[i].requiredEnergy; + + PlaySound(fxLightOn); + } + } + } + } + else if (currentLightedLevel == LEVEL_II) + { + for (int i = 0; i < MAX_LIGHTS_II; i++) + { + if (CheckCollisionCircles(player.position, player.radius, lightsII[i].position, lightsII[i].radius)) + { + if (!lightsII[i].active && (player.lightEnergy >= lightsII[i].requiredEnergy)) + { + lightsII[i].active = true; + player.lightEnergy -= lightsII[i].requiredEnergy; + + PlaySound(fxLightOn); + } + } + } + } + else if (currentLightedLevel == LEVEL_III) + { + for (int i = 0; i < MAX_LIGHTS_III; i++) + { + if (CheckCollisionCircles(player.position, player.radius, lightsIII[i].position, lightsIII[i].radius)) + { + if (!lightsIII[i].active && (player.lightEnergy >= lightsIII[i].requiredEnergy)) + { + lightsIII[i].active = true; + player.lightEnergy -= lightsIII[i].requiredEnergy; + + PlaySound(fxLightOn); + } + } + } + } + + // Lights animation (it doesn't depend on currentLightedLevel) + for (int i = 0; i < MAX_LIGHTS_I; i++) + { + // Light animation + if (lightsI[i].active) + { + lightsI[i].framesCounter++; + + if (lightsI[i].framesCounter > 10) + { + lightsI[i].currentFrame++; + + if (lightsI[i].currentFrame > LIGHT_ANIM_FRAMES - 1) lightsI[i].currentFrame = 1; + + lightsI[i].framesCounter = 0; + } + } + + lightsI[i].frameRec.x = lightsI[i].currentFrame*texLight.width/LIGHT_ANIM_FRAMES; + } + + for (int i = 0; i < MAX_LIGHTS_II; i++) + { + // Light animation + if (lightsII[i].active) + { + lightsII[i].framesCounter++; + + if (lightsII[i].framesCounter > 10) + { + lightsII[i].currentFrame++; + + if (lightsII[i].currentFrame > LIGHT_ANIM_FRAMES - 1) lightsII[i].currentFrame = 1; + + lightsII[i].framesCounter = 0; + } + } + + lightsII[i].frameRec.x = lightsII[i].currentFrame*texLight.width/LIGHT_ANIM_FRAMES; + } + + for (int i = 0; i < MAX_LIGHTS_III; i++) + { + // Light animation + if (lightsIII[i].active) + { + lightsIII[i].framesCounter++; + + if (lightsIII[i].framesCounter > 10) + { + lightsIII[i].currentFrame++; + + if (lightsIII[i].currentFrame > LIGHT_ANIM_FRAMES - 1) lightsIII[i].currentFrame = 1; + + lightsIII[i].framesCounter = 0; + } + } + + lightsIII[i].frameRec.x = lightsIII[i].currentFrame*texLight.width/LIGHT_ANIM_FRAMES; + } + + // Enemies logic + if (!enemiesStopped) + { + for (int i = 0; i < MAX_ENEMIES; i++) + { + if (!enemies[i].active) enemies[i].framesCounter++; + + if (enemies[i].framesCounter > enemies[i].awakeFramesDelay) enemies[i].active = true; + + if (enemies[i].active) + { + // Move to the target + Vector2 dir = Vector2Subtract(enemies[i].targetPos, enemies[i].position); + Vector2Normalize(&dir); + + enemies[i].position.x += dir.x*enemies[i].speed; + enemies[i].position.y += dir.y*enemies[i].speed; + + if (currentLightedLevel == LEVEL_I) + { + if (CheckCollisionCircles(enemies[i].position, enemies[i].radius, enemies[i].targetPos, lightsI[enemies[i].targetNum].radius)) + { + lightsI[enemies[i].targetNum].active = false; + lightsI[enemies[i].targetNum].framesCounter = 0; + lightsI[enemies[i].targetNum].currentFrame = 0; + lightsI[enemies[i].targetNum].frameRec = (Rectangle){ 0, 0, 64, 64 }; + + EnemyReset(&enemies[i]); + + PlaySound(fxLightOff); + } + } + else if (currentLightedLevel == LEVEL_II) + { + if (CheckCollisionCircles(enemies[i].position, enemies[i].radius, enemies[i].targetPos, lightsII[enemies[i].targetNum].radius)) + { + lightsII[enemies[i].targetNum].active = false; + lightsII[enemies[i].targetNum].framesCounter = 0; + lightsII[enemies[i].targetNum].currentFrame = 0; + lightsII[enemies[i].targetNum].frameRec = (Rectangle){ 0, 0, 64, 64 }; + + EnemyReset(&enemies[i]); + + PlaySound(fxLightOff); + } + } + else if (currentLightedLevel == LEVEL_III) + { + if (CheckCollisionCircles(enemies[i].position, enemies[i].radius, enemies[i].targetPos, lightsIII[enemies[i].targetNum].radius)) + { + lightsIII[enemies[i].targetNum].active = false; + lightsIII[enemies[i].targetNum].framesCounter = 0; + lightsIII[enemies[i].targetNum].currentFrame = 0; + lightsIII[enemies[i].targetNum].frameRec = (Rectangle){ 0, 0, 64, 64 }; + + EnemyReset(&enemies[i]); + + PlaySound(fxLightOff); + } + } + } + } + } + + // Check current light energy (for right bar) + currentLightEnergy = 0; + + for (int i = 0; i < MAX_LIGHTS_I; i++) if (lightsI[i].active) currentLightEnergy += lightsI[i].requiredEnergy; + for (int i = 0; i < MAX_LIGHTS_II; i++) if (lightsII[i].active) currentLightEnergy += lightsII[i].requiredEnergy; + for (int i = 0; i < MAX_LIGHTS_III; i++) if (lightsIII[i].active) currentLightEnergy += lightsIII[i].requiredEnergy; + + // Check current lighted level + // Check ending conditions: all lights off, ritual level reached + previousLightedLevel = currentLightedLevel; + + currentLightedLevel = LEVEL_I; + + bool lightedLevel = true; + for (int i = 0; i < MAX_LIGHTS_I; i++) if (!lightsI[i].active) lightedLevel = false; + if (lightedLevel) currentLightedLevel = LEVEL_II; + + for (int i = 0; i < MAX_LIGHTS_II; i++) if (!lightsII[i].active) lightedLevel = false; + if (lightedLevel) currentLightedLevel = LEVEL_III; + + for (int i = 0; i < MAX_LIGHTS_III; i++) if (!lightsIII[i].active) lightedLevel = false; + if (lightedLevel) + { + currentLightedLevel = LEVEL_FINISHED; + + for (int i = 0; i < MAX_ENEMIES; i++) enemies[i].active = false; + } + + if (currentLightedLevel != previousLightedLevel) for (int i = 0; i < MAX_ENEMIES; i++) EnemyReset(&enemies[i]); + + ritualTime = (float)framesCounter/60; + + // Check game over condition (time run out) + if ((99.0f - ritualTime) <= 0.0f) + { + ritualTime = 99.0f; + timeOver = true; + } + } + + if (startRitual) + { + alphaRitual += 0.02f; + + SetMusicVolume(1.0f - alphaRitual); + + if (alphaRitual > 1.0f) finishScreen = 1; + } +} + +// Gameplay Screen Draw logic +void DrawGameplayScreen(void) +{ + DrawTexture(background, 0, 0, WHITE); + + // DrawText("STARS ARE ALIGNED! NO TIME TO LOOSE! LIGHT MY RITUAL!", + + // Draw foreground and circles + if ((currentLightedLevel == LEVEL_FINISHED) || (currentLightedLevel == LEVEL_III)) DrawTexture(foregroundIII, 0, 0, WHITE); + else if (currentLightedLevel == LEVEL_II) DrawTexture(foregroundII, 0, 0, WHITE); + else if (currentLightedLevel == LEVEL_I) DrawTexture(foregroundI, 0, 0, WHITE); + + // Draw lighted circles (depends on current lighted level) + switch (currentLightedLevel) + { + case LEVEL_FINISHED: + { + DrawTexture(circleIIIon, GetScreenWidth()/2 - circleIIIon.width/2, GetScreenHeight()/2 - circleIIIon.height/2, WHITE); + DrawTexture(circleIIon, GetScreenWidth()/2 - circleIIon.width/2, GetScreenHeight()/2 - circleIIon.height/2, WHITE); + DrawTexture(circleIon, GetScreenWidth()/2 - circleIon.width/2, GetScreenHeight()/2 - circleIon.height/2, WHITE); + } break; + case LEVEL_III: + { + DrawTexture(circleIIIoff, GetScreenWidth()/2 - circleIIIoff.width/2, GetScreenHeight()/2 - circleIIIoff.height/2, WHITE); + DrawTexture(circleIIon, GetScreenWidth()/2 - circleIIon.width/2, GetScreenHeight()/2 - circleIIon.height/2, WHITE); + DrawTexture(circleIon, GetScreenWidth()/2 - circleIon.width/2, GetScreenHeight()/2 - circleIon.height/2, WHITE); + } break; + case LEVEL_II: + { + DrawTexture(circleIIoff, GetScreenWidth()/2 - circleIIoff.width/2, GetScreenHeight()/2 - circleIIoff.height/2, WHITE); + DrawTexture(circleIon, GetScreenWidth()/2 - circleIon.width/2, GetScreenHeight()/2 - circleIon.height/2, WHITE); + } break; + case LEVEL_I: + { + DrawTexture(circleIoff, GetScreenWidth()/2 - circleIoff.width/2, GetScreenHeight()/2 - circleIoff.height/2, WHITE); + } break; + default: break; + } + + // Draw lights (depends on current lighted level) + switch (currentLightedLevel) + { + case LEVEL_FINISHED: + case LEVEL_III: + { + for (int i = 0; i < MAX_LIGHTS_III; i++) + { + //if (lightsIII[i].active) DrawCircleV(lightsIII[i].position, lightsIII[i].radius, GOLD); + //else DrawCircleLines(lightsIII[i].position.x, lightsIII[i].position.y, lightsIII[i].radius, GRAY); + + if (lightsIII[i].active) + { + DrawTextureRec(texLight, lightsIII[i].frameRec, (Vector2){ lightsIII[i].position.x - 32, lightsIII[i].position.y - 32 }, WHITE); + DrawTexture(lightGlow, lightsIII[i].position.x - lightGlow.width/2, lightsIII[i].position.y - lightGlow.height/2, Fade(WHITE, 0.3f)); + DrawText(FormatText("%02i", lightsIII[i].requiredEnergy), lightsIII[i].position.x - 10, lightsIII[i].position.y + 14, 20, GRAY); + } + else + { + DrawTextureRec(texLight, lightsIII[i].frameRec, (Vector2){ lightsIII[i].position.x - 32, lightsIII[i].position.y - 32 }, WHITE); + DrawText(FormatText("%02i", lightsIII[i].requiredEnergy), lightsIII[i].position.x - 10, lightsIII[i].position.y + 14, 20, YELLOW); + } + } + } + case LEVEL_II: + { + for (int i = 0; i < MAX_LIGHTS_II; i++) + { + //if (lightsII[i].active) DrawCircleV(lightsII[i].position, lightsII[i].radius, GOLD); + //else DrawCircleLines(lightsI[i].position.x, lightsI[i].position.y, lightsI[i].radius, GRAY); + + if (lightsII[i].active) + { + DrawTextureRec(texLight, lightsII[i].frameRec, (Vector2){ lightsII[i].position.x - 32, lightsII[i].position.y - 32 }, WHITE); + DrawTexture(lightGlow, lightsII[i].position.x - lightGlow.width/2, lightsII[i].position.y - lightGlow.height/2, Fade(WHITE, 0.3f)); + DrawText(FormatText("%02i", lightsII[i].requiredEnergy), lightsII[i].position.x - 10, lightsII[i].position.y + 14, 20, GRAY); + } + else + { + DrawTextureRec(texLight, lightsII[i].frameRec, (Vector2){ lightsII[i].position.x - 32, lightsII[i].position.y - 32 }, WHITE); + DrawText(FormatText("%02i", lightsII[i].requiredEnergy), lightsII[i].position.x - 10, lightsII[i].position.y + 14, 20, YELLOW); + } + } + } + case LEVEL_I: + { + for (int i = 0; i < MAX_LIGHTS_I; i++) + { + //if (lightsI[i].active) DrawCircleV(lightsI[i].position, lightsI[i].radius, GOLD); + //else DrawCircleLines(lightsI[i].position.x, lightsI[i].position.y, lightsI[i].radius, GRAY); + + if (lightsI[i].active) + { + DrawTextureRec(texLight, lightsI[i].frameRec, (Vector2){ lightsI[i].position.x - 32, lightsI[i].position.y - 32 }, WHITE); + DrawTexture(lightGlow, lightsI[i].position.x - lightGlow.width/2, lightsI[i].position.y - lightGlow.height/2, Fade(WHITE, 0.3f)); + DrawText(FormatText("%02i", lightsI[i].requiredEnergy), lightsI[i].position.x - 10, lightsI[i].position.y + 14, 20, GRAY); + } + else + { + DrawTextureRec(texLight, lightsI[i].frameRec, (Vector2){ lightsI[i].position.x - 32, lightsI[i].position.y - 32 }, WHITE); + DrawText(FormatText("%02i", lightsI[i].requiredEnergy), lightsI[i].position.x - 10, lightsI[i].position.y + 14, 20, YELLOW); + } + } + } + default: break; + } + + // Draw main lighter + DrawTexture(book, GetScreenWidth()/2 - book.width/2, GetScreenHeight()/2, WHITE); + DrawTexture(lightRay, GetScreenWidth()/2 - lightRay.width/2, 0, Fade(WHITE, 0.5f)); + + // Draw player + //DrawCircleV(player.position, player.radius, player.color); + DrawTexture(texPlayer, player.position.x - 32, player.position.y - 32, player.color); + + if (currentLightedLevel != LEVEL_FINISHED) + { + // Draw enemies (depends on current lighted level) + for (int i = 0; i < MAX_ENEMIES; i++) + { + if (enemies[i].active) + { + //DrawCircleV(enemies[i].position, enemies[i].radius, enemies[i].color); + DrawTextureRec(texEnemy, (Rectangle){ 0, 0, 64, 64 }, (Vector2){ enemies[i].position.x - 32, enemies[i].position.y - 32 }, WHITE); + } + } + + // Draw time left for ritual + DrawTextEx(font, FormatText("%02.2f", (99.0f - ritualTime)), (Vector2){ 560, 20 }, font.size, 0, WHITE); + + // Draw light energy bar + DrawRectangle(20, 30, 400, 20, GRAY); + DrawRectangle(20, 30, (400*player.lightEnergy)/MAX_PLAYER_ENERGY, 20, GOLD); + DrawRectangleLines(20, 30, 400, 20, LIGHTGRAY); + DrawText(FormatText("%03.0f", player.lightEnergy), 430, 30, 20, WHITE); + + // Draw level lighted bar (for completion) + DrawRectangle(GetScreenWidth() - 40, 30, 20, 660, GRAY); + DrawRectangle(GetScreenWidth() - 40, 30 + 660 - 660*currentLightEnergy/maxLightEnergy, 20, 660*currentLightEnergy/maxLightEnergy, YELLOW); + DrawRectangleLines(GetScreenWidth() - 40, 30, 20, 660, LIGHTGRAY); + + // Show message: "You run out of light!!!" if player.lightEnergy <= 0 + if (player.lightEnergy < 2) + { + if ((framesCounter/20)%2) DrawTextEx(font, "YOU'RE RUNNING OUT OF LIGHT!", (Vector2){ 20, 60 }, font.size/2, 0, WHITE); + } + } + else if (!timeOver) // LEVEL_FINISHED + { + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(BLACK, 0.4f)); + + // Wait some time before jumping to ending: raylib + DrawTexture(texRitual, GetScreenWidth()/2 - texRitual.width/2, 100, WHITE); + DrawTextEx(font, FormatText("BEST LIGHTING TIME: %02.2f", ritualTime), (Vector2){ 320, 340 }, 50, 0, WHITE); + DrawTextEx(font, "PRESS ENTER to START the RITUAL", (Vector2){ 160, 480 }, 60, 0, WHITE); + + if (IsKeyPressed(KEY_ENTER)) startRitual = true; + } + + if (timeOver) + { + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(BLACK, 0.4f)); + + DrawTexture(texTimeOver, GetScreenWidth()/2 - texTimeOver.width/2, 140, WHITE); + DrawTextEx(font, FormatText("NEXT STARS ALIGNMENT IN %i YEARS", nextStarsAlignment), (Vector2){ 200, 360 }, 50, 0, WHITE); + DrawTextEx(font, "PRESS ENTER to GO HOME...", (Vector2){ 260, 480 }, 60, 0, WHITE); + + if (IsKeyPressed(KEY_ENTER)) finishScreen = 2; + } + + if (startRitual) DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, alphaRitual)); + + if (pause) DrawTextEx(font, "RITUAL PAUSED", (Vector2){ GetScreenWidth()/2 - MeasureText("RITUAL PAUSED", 40)/2, 110 }, 50, 0, WHITE); +} + +// Gameplay Screen Unload logic +void UnloadGameplayScreen(void) +{ + // Unload GAMEPLAY screen variables here! + UnloadTexture(background); + UnloadTexture(foregroundI); + UnloadTexture(foregroundII); + UnloadTexture(foregroundIII); + UnloadTexture(texPlayer); + UnloadTexture(texEnemy); + UnloadTexture(texLight); + UnloadTexture(lightGlow); + UnloadTexture(lightRay); + UnloadTexture(book); + UnloadTexture(texRitual); + UnloadTexture(texTimeOver); + + // Unload circles + UnloadTexture(circleIoff); + UnloadTexture(circleIIoff); + UnloadTexture(circleIIIoff); + UnloadTexture(circleIon); + UnloadTexture(circleIIon); + UnloadTexture(circleIIIon); + + // Unload sounds + UnloadSound(fxLightOn); + UnloadSound(fxLightOff); +} + +// Gameplay Screen should finish? +int FinishGameplayScreen(void) +{ + return finishScreen; +} + +//------------------------------------------------------------------------------------ +// Module Functions Definitions (local) +//------------------------------------------------------------------------------------ + +// Check two colors if equal +static bool ColorEqual(Color col1, Color col2) +{ + return ((col1.r == col2.r) && (col1.g == col2.g) && (col1.b == col2.b) && (col1.a == col2.a)); +} + +// Substract two vectors +static Vector2 Vector2Subtract(Vector2 v1, Vector2 v2) +{ + Vector2 result; + + result.x = v1.x - v2.x; + result.y = v1.y - v2.y; + + return result; +} + +// Normalize provided vector +static void Vector2Normalize(Vector2 *v) +{ + float length, ilength; + + length = sqrt(v->x*v->x + v->y*v->y); + + if (length == 0) length = 1.0f; + + ilength = 1.0f/length; + + v->x *= ilength; + v->y *= ilength; +} + +// Reset enemy parameters +// NOTE: Depends on currentLightedLevel +static void EnemyReset(Enemy *enemy) +{ + enemy->active = false; + enemy->framesCounter = 0; + enemy->color = RED; + enemy->radius = 10; + + int side = GetRandomValue(0, 1); + + if (side) enemy->position = (Vector2){ GetRandomValue(50, 150), GetRandomValue(50, GetScreenHeight() - 50) }; + else enemy->position = (Vector2){ GetRandomValue(GetScreenWidth() - 150, GetScreenWidth() - 50), GetRandomValue(50, GetScreenHeight() - 50) }; + + // TODO: Choose only active lights + // TODO: if currentLightedLevel has no active lights, choose light from a lower level! + + if (currentLightedLevel == LEVEL_I) + { + enemy->targetNum = GetRandomValue(0, MAX_LIGHTS_I - 1); // LEVEL_I + enemy->targetPos = lightsI[enemy->targetNum].position; + enemy->speed = (float)GetRandomValue(15, 20)/10.0f; + enemy->awakeFramesDelay = GetRandomValue(90, 400); + } + else if (currentLightedLevel == LEVEL_II) + { + enemy->targetNum = GetRandomValue(0, MAX_LIGHTS_II - 1); // LEVEL_II + enemy->targetPos = lightsII[enemy->targetNum].position; + enemy->speed = (float)GetRandomValue(10, 20)/10.0f; + enemy->awakeFramesDelay = GetRandomValue(240, 800); + } + else if (currentLightedLevel == LEVEL_III) + { + enemy->targetNum = GetRandomValue(0, MAX_LIGHTS_III - 1); // LEVEL_III + enemy->targetPos = lightsIII[enemy->targetNum].position; + enemy->speed = (float)GetRandomValue(8, 18)/10.0f; + enemy->awakeFramesDelay = GetRandomValue(180, 1200); + } +} \ No newline at end of file diff --git a/games/light_my_ritual/screens/screen_logo_raylib.c b/games/light_my_ritual/screens/screen_logo_raylib.c new file mode 100644 index 00000000..40157b10 --- /dev/null +++ b/games/light_my_ritual/screens/screen_logo_raylib.c @@ -0,0 +1,214 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Logo Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +#define LOGO_RECS_SIDE 16 + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Logo screen global variables +static int framesCounter; +static int finishScreen; + +static int logoPositionX; +static int logoPositionY; + +static int lettersCount; + +static int topSideRecWidth; +static int leftSideRecHeight; + +static int bottomSideRecWidth; +static int rightSideRecHeight; + +static char raylib[8]; // raylib text array, max 8 letters +static int state; // Tracking animation states (State Machine) +static float alpha = 1.0f; // Useful for fading + +//---------------------------------------------------------------------------------- +// Logo Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Logo Screen Initialization logic +void rlInitLogoScreen(void) +{ + // Initialize LOGO screen variables here! + finishScreen = 0; + framesCounter = 0; + lettersCount = 0; + + 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; + + PlayMusicStream("resources/audio/ambient.ogg"); + SetMusicVolume(1.0f); +} + +// Logo Screen Update logic +void rlUpdateLogoScreen(void) +{ + // Update LOGO screen variables here! + if (state == 0) // State 0: Small box blinking + { + 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 rlDrawLogoScreen(void) +{ + 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 rlUnloadLogoScreen(void) +{ + // TODO: Unload LOGO screen variables here! +} + +// Logo Screen should finish? +int rlFinishLogoScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/light_my_ritual/screens/screen_title.c b/games/light_my_ritual/screens/screen_title.c new file mode 100644 index 00000000..c1ecaf12 --- /dev/null +++ b/games/light_my_ritual/screens/screen_title.c @@ -0,0 +1,105 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Title Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Title screen global variables +static int framesCounter; +static int finishScreen; + +static Texture2D background; +static Texture2D title; +static float titleAlpha = 0.0f; + +static Sound fxStart; + +//---------------------------------------------------------------------------------- +// Title Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Title Screen Initialization logic +void InitTitleScreen(void) +{ + // Initialize TITLE screen variables here! + framesCounter = 0; + finishScreen = 0; + + background = LoadTexture("resources/textures/back_title.png"); + title = LoadTexture("resources/textures/title.png"); + + fxStart = LoadSound("resources/audio/start.wav"); +} + +// Title Screen Update logic +void UpdateTitleScreen(void) +{ + // Update TITLE screen variables here! + framesCounter++; + + titleAlpha += 0.005f; + + if (titleAlpha >= 1.0f) titleAlpha = 1.0f; + + // Press enter to change to ATTIC screen + if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) + { + PlaySound(fxStart); + finishScreen = 1; + } +} + +// Title Screen Draw logic +void DrawTitleScreen(void) +{ + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), (Color){ 26, 26, 26, 255 }); + + DrawTexture(background, GetScreenWidth()/2 - background.width/2, 0, WHITE); + DrawTexture(title, GetScreenWidth()/2 - title.width/2, 30, Fade(WHITE, titleAlpha)); + + DrawText("(c) Developed by Ramon Santamaria (@raysan5)", 20, GetScreenHeight() - 40, 20, LIGHTGRAY); + + if ((framesCounter > 180) && ((framesCounter/40)%2)) DrawTextEx(font, "PRESS ENTER to START LIGHTING", (Vector2){ 230, 450 }, font.size, -2, WHITE); +} + +// Title Screen Unload logic +void UnloadTitleScreen(void) +{ + // Unload TITLE screen variables here! + UnloadTexture(background); + UnloadTexture(title); + + UnloadSound(fxStart); +} + +// Title Screen should finish? +int FinishTitleScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/light_my_ritual/screens/screens.h b/games/light_my_ritual/screens/screens.h new file mode 100644 index 00000000..8fee5274 --- /dev/null +++ b/games/light_my_ritual/screens/screens.h @@ -0,0 +1,78 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Screens Functions Declarations (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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_RL = 0, TITLE, GAMEPLAY } GameScreen; + +//---------------------------------------------------------------------------------- +// Global Variables Definition +//---------------------------------------------------------------------------------- +GameScreen currentScreen; +SpriteFont font; + +Color *lightsMap; +int lightsMapWidth, lightsMapHeight; + +#ifdef __cplusplus +extern "C" { // Prevents name mangling of functions +#endif + +//---------------------------------------------------------------------------------- +// raylib Logo Screen Functions Declaration +//---------------------------------------------------------------------------------- +void rlInitLogoScreen(void); +void rlUpdateLogoScreen(void); +void rlDrawLogoScreen(void); +void rlUnloadLogoScreen(void); +int rlFinishLogoScreen(void); + +//---------------------------------------------------------------------------------- +// Title Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitTitleScreen(void); +void UpdateTitleScreen(void); +void DrawTitleScreen(void); +void UnloadTitleScreen(void); +int FinishTitleScreen(void); + +//---------------------------------------------------------------------------------- +// Gameplay Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitGameplayScreen(void); +void UpdateGameplayScreen(void); +void DrawGameplayScreen(void); +void UnloadGameplayScreen(void); +int FinishGameplayScreen(void); + +#ifdef __cplusplus +} +#endif + +#endif // SCREENS_H \ No newline at end of file -- cgit v1.2.3 From 4fae37bb88962816328a6b4e0f23bedb084b0604 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 7 Feb 2016 11:08:31 +0100 Subject: Removed floppy game, available as sample --- games/floppy/floppy.c | 213 ---------------------------------- games/floppy/resources/background.png | Bin 228930 -> 0 bytes games/floppy/resources/coin.wav | Bin 37396 -> 0 bytes games/floppy/resources/floppy.png | Bin 2030 -> 0 bytes games/floppy/resources/jump.wav | Bin 14540 -> 0 bytes games/floppy/resources/tubes.png | Bin 19623 -> 0 bytes 6 files changed, 213 deletions(-) delete mode 100644 games/floppy/floppy.c delete mode 100644 games/floppy/resources/background.png delete mode 100644 games/floppy/resources/coin.wav delete mode 100644 games/floppy/resources/floppy.png delete mode 100644 games/floppy/resources/jump.wav delete mode 100644 games/floppy/resources/tubes.png (limited to 'games') diff --git a/games/floppy/floppy.c b/games/floppy/floppy.c deleted file mode 100644 index 0c0cb5f2..00000000 --- a/games/floppy/floppy.c +++ /dev/null @@ -1,213 +0,0 @@ -/******************************************************************************************* -* -* raylib game - Floppy Bird -* -* This game has been created using raylib 1.1 (www.raylib.com) -* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -********************************************************************************************/ - -#include "raylib.h" - -#define MAX_TUBES 100 - -int main() -{ - // Initialization - //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; - - InitWindow(screenWidth, screenHeight, "Floppy Bird"); - - InitAudioDevice(); // Initialize audio device - - Sound coin = LoadSound("resources/coin.wav"); - Sound jump = LoadSound("resources/jump.wav"); - - Texture2D background = LoadTexture("resources/background.png"); - Texture2D tubes = LoadTexture("resources/tubes.png"); - Texture2D floppy = LoadTexture("resources/floppy.png"); - - Vector2 floppyPos = { 80, screenHeight/2 - floppy.height/2 }; - - Vector2 tubesPos[MAX_TUBES]; - int tubesSpeedX = 2; - - for (int i = 0; i < MAX_TUBES; i++) - { - tubesPos[i].x = 400 + 280*i; - tubesPos[i].y = -GetRandomValue(0, 120); - } - - Rectangle tubesRecs[MAX_TUBES*2]; - bool tubesActive[MAX_TUBES]; - - for (int i = 0; i < MAX_TUBES*2; i += 2) - { - tubesRecs[i].x = tubesPos[i/2].x; - tubesRecs[i].y = tubesPos[i/2].y; - tubesRecs[i].width = tubes.width; - tubesRecs[i].height = 255; - - tubesRecs[i+1].x = tubesPos[i/2].x; - tubesRecs[i+1].y = 600 + tubesPos[i/2].y - 255; - tubesRecs[i+1].width = tubes.width; - tubesRecs[i+1].height = 255; - - tubesActive[i/2] = true; - } - - int backScroll = 0; - - int score = 0; - int hiscore = 0; - - bool gameover = false; - bool superfx = false; - - SetTargetFPS(60); - //--------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - - // Background scroll logic - backScroll--; - if (backScroll <= -800) backScroll = 0; - - // Player movement logic - if (!gameover) - { - if (IsKeyDown(KEY_SPACE)) floppyPos.y -= 3; - else floppyPos.y += 1; - - if (IsKeyPressed(KEY_SPACE)) PlaySound(jump); - } - - // Tubes moving logic - for (int i = 0; i < MAX_TUBES; i++) tubesPos[i].x -= tubesSpeedX; - - for (int i = 0; i < MAX_TUBES*2; i += 2) - { - tubesRecs[i].x = tubesPos[i/2].x; - tubesRecs[i+1].x = tubesPos[i/2].x; - } - - // Check collisions player-tubes - for (int i = 0; i < MAX_TUBES*2; i++) - { - if (CheckCollisionCircleRec((Vector2){ floppyPos.x + floppy.width/2, floppyPos.y + floppy.height/2 }, floppy.width/2, tubesRecs[i])) - { - gameover = true; - } - else if ((tubesPos[i/2].x < floppyPos.x) && tubesActive[i/2] && !gameover) - { - score += 100; - tubesActive[i/2] = false; - PlaySound(coin); - - superfx = true; - - if (score > hiscore) hiscore = score; - } - } - - // Gameover logic for reset - if (gameover && IsKeyPressed(KEY_ENTER)) - { - for (int i = 0; i < MAX_TUBES; i++) - { - tubesPos[i].x = 400 + 280*i; - tubesPos[i].y = -GetRandomValue(0, 120); - } - - for (int i = 0; i < MAX_TUBES*2; i += 2) - { - tubesRecs[i].x = tubesPos[i/2].x; - tubesRecs[i].y = tubesPos[i/2].y; - - tubesRecs[i+1].x = tubesPos[i/2].x; - tubesRecs[i+1].y = 600 + tubesPos[i/2].y - 255; - - tubesActive[i/2] = true; - } - - floppyPos.x = 80; - floppyPos.y = screenHeight/2 - floppy.height/2; - - gameover = false; - score = 0; - } - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - // Draw scrolling background - DrawTexture(background, backScroll, 0, WHITE); - DrawTexture(background, screenWidth + backScroll, 0, WHITE); - - // Draw moving tubes - for (int i = 0; i < MAX_TUBES; i++) - { - if (tubesPos[i].x <= 800) DrawTextureEx(tubes, tubesPos[i], 0, 1.0, WHITE); - - // Draw collision recs - //DrawRectangleLines(tubesRecs[i*2].x, tubesRecs[i*2].y, tubesRecs[i*2].width, tubesRecs[i*2].height, RED); - //DrawRectangleLines(tubesRecs[i*2 + 1].x, tubesRecs[i*2 + 1].y, tubesRecs[i*2 + 1].width, tubesRecs[i*2 + 1].height, RED); - } - - // Draw scores - DrawText(FormatText("%04i", score), 20, 20, 40, PINK); - DrawText(FormatText("HI-SCORE: %04i", hiscore), 20, 70, 20, VIOLET); - - // Draw player or game over messages - if (!gameover) - { - DrawTextureEx(floppy, floppyPos, 0, 1.0, WHITE); - - // Draw collision circle - //DrawCircleLines(floppyPos.x + floppy.width/2, floppyPos.y + floppy.height/2, floppy.width/2, RED); - } - else - { - DrawText("GAME OVER", 100, 180, 100, MAROON); - DrawText("PRESS ENTER to RETRY!", 280, 280, 20, RED); - } - - // Draw screen light flash when passing through a tube - if (superfx) - { - DrawRectangle(0, 0, screenWidth, screenHeight, GOLD); - superfx = false; - } - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(background); // Texture unloading - UnloadTexture(tubes); // Texture unloading - UnloadTexture(floppy); // Texture unloading - - UnloadSound(coin); // Unload sound data - UnloadSound(jump); // Unload sound data - - CloseAudioDevice(); // Close audio device - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -} \ No newline at end of file diff --git a/games/floppy/resources/background.png b/games/floppy/resources/background.png deleted file mode 100644 index eab9d865..00000000 Binary files a/games/floppy/resources/background.png and /dev/null differ diff --git a/games/floppy/resources/coin.wav b/games/floppy/resources/coin.wav deleted file mode 100644 index d3b6e93c..00000000 Binary files a/games/floppy/resources/coin.wav and /dev/null differ diff --git a/games/floppy/resources/floppy.png b/games/floppy/resources/floppy.png deleted file mode 100644 index 7c851086..00000000 Binary files a/games/floppy/resources/floppy.png and /dev/null differ diff --git a/games/floppy/resources/jump.wav b/games/floppy/resources/jump.wav deleted file mode 100644 index 1f68d336..00000000 Binary files a/games/floppy/resources/jump.wav and /dev/null differ diff --git a/games/floppy/resources/tubes.png b/games/floppy/resources/tubes.png deleted file mode 100644 index a3ca8e7e..00000000 Binary files a/games/floppy/resources/tubes.png and /dev/null differ -- cgit v1.2.3 From 4a3509f06d60e2761aa048378fe979e11a5a1667 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 7 Feb 2016 11:09:12 +0100 Subject: Added game sources: Skully Escape This game was developed for King GameJam 2015 --- games/skully_escape/makefile | 254 ++++++++++++ games/skully_escape/monster.c | 54 +++ games/skully_escape/monster.h | 73 ++++ games/skully_escape/player.c | 281 +++++++++++++ games/skully_escape/player.h | 51 +++ .../resources/audio/come_play_with_me.ogg | Bin 0 -> 2310768 bytes games/skully_escape/resources/audio/door.ogg | Bin 0 -> 32434 bytes games/skully_escape/resources/audio/scream.ogg | Bin 0 -> 19696 bytes games/skully_escape/resources/textures/alagard.png | Bin 0 -> 36659 bytes .../resources/textures/background_aisle01.png | Bin 0 -> 670481 bytes .../resources/textures/background_aisle02.png | Bin 0 -> 507254 bytes .../resources/textures/background_armory.png | Bin 0 -> 252006 bytes .../resources/textures/background_attic.png | Bin 0 -> 286704 bytes .../resources/textures/background_bathroom.png | Bin 0 -> 254709 bytes .../resources/textures/background_kitchen.png | Bin 0 -> 310161 bytes .../resources/textures/background_livingroom.png | Bin 0 -> 319096 bytes games/skully_escape/resources/textures/doors.png | Bin 0 -> 82485 bytes .../resources/textures/monster_arc.png | Bin 0 -> 49342 bytes .../resources/textures/monster_blazon01.png | Bin 0 -> 47467 bytes .../resources/textures/monster_blazon02.png | Bin 0 -> 47085 bytes .../resources/textures/monster_blazon03.png | Bin 0 -> 52593 bytes .../resources/textures/monster_candle.png | Bin 0 -> 70445 bytes .../resources/textures/monster_chair_left.png | Bin 0 -> 42529 bytes .../resources/textures/monster_chair_right.png | Bin 0 -> 46303 bytes .../resources/textures/monster_closet.png | Bin 0 -> 93494 bytes .../resources/textures/monster_lamp_left.png | Bin 0 -> 80413 bytes .../resources/textures/monster_lamp_right.png | Bin 0 -> 148299 bytes .../resources/textures/monster_mirror.png | Bin 0 -> 67383 bytes .../resources/textures/monster_phone.png | Bin 0 -> 51545 bytes .../resources/textures/monster_picture.png | Bin 0 -> 96506 bytes .../resources/textures/monster_window.png | Bin 0 -> 175595 bytes games/skully_escape/resources/textures/skully.png | Bin 0 -> 138765 bytes .../resources/textures/skully_icon.png | Bin 0 -> 3165 bytes .../resources/textures/skully_logo.png | Bin 0 -> 19137 bytes games/skully_escape/resources/textures/title.png | Bin 0 -> 120338 bytes games/skully_escape/screens/screen_aisle01.c | 409 +++++++++++++++++++ games/skully_escape/screens/screen_aisle02.c | 444 +++++++++++++++++++++ games/skully_escape/screens/screen_armory.c | 404 +++++++++++++++++++ games/skully_escape/screens/screen_attic.c | 332 +++++++++++++++ games/skully_escape/screens/screen_bathroom.c | 383 ++++++++++++++++++ games/skully_escape/screens/screen_ending.c | 90 +++++ games/skully_escape/screens/screen_kitchen.c | 403 +++++++++++++++++++ games/skully_escape/screens/screen_livingroom.c | 403 +++++++++++++++++++ games/skully_escape/screens/screen_logo.c | 108 +++++ games/skully_escape/screens/screen_logo_raylib.c | 201 ++++++++++ games/skully_escape/screens/screen_title.c | 92 +++++ games/skully_escape/screens/screens.h | 164 ++++++++ games/skully_escape/skully_escape.c | 403 +++++++++++++++++++ 48 files changed, 4549 insertions(+) create mode 100644 games/skully_escape/makefile create mode 100644 games/skully_escape/monster.c create mode 100644 games/skully_escape/monster.h create mode 100644 games/skully_escape/player.c create mode 100644 games/skully_escape/player.h create mode 100644 games/skully_escape/resources/audio/come_play_with_me.ogg create mode 100644 games/skully_escape/resources/audio/door.ogg create mode 100644 games/skully_escape/resources/audio/scream.ogg create mode 100644 games/skully_escape/resources/textures/alagard.png create mode 100644 games/skully_escape/resources/textures/background_aisle01.png create mode 100644 games/skully_escape/resources/textures/background_aisle02.png create mode 100644 games/skully_escape/resources/textures/background_armory.png create mode 100644 games/skully_escape/resources/textures/background_attic.png create mode 100644 games/skully_escape/resources/textures/background_bathroom.png create mode 100644 games/skully_escape/resources/textures/background_kitchen.png create mode 100644 games/skully_escape/resources/textures/background_livingroom.png create mode 100644 games/skully_escape/resources/textures/doors.png create mode 100644 games/skully_escape/resources/textures/monster_arc.png create mode 100644 games/skully_escape/resources/textures/monster_blazon01.png create mode 100644 games/skully_escape/resources/textures/monster_blazon02.png create mode 100644 games/skully_escape/resources/textures/monster_blazon03.png create mode 100644 games/skully_escape/resources/textures/monster_candle.png create mode 100644 games/skully_escape/resources/textures/monster_chair_left.png create mode 100644 games/skully_escape/resources/textures/monster_chair_right.png create mode 100644 games/skully_escape/resources/textures/monster_closet.png create mode 100644 games/skully_escape/resources/textures/monster_lamp_left.png create mode 100644 games/skully_escape/resources/textures/monster_lamp_right.png create mode 100644 games/skully_escape/resources/textures/monster_mirror.png create mode 100644 games/skully_escape/resources/textures/monster_phone.png create mode 100644 games/skully_escape/resources/textures/monster_picture.png create mode 100644 games/skully_escape/resources/textures/monster_window.png create mode 100644 games/skully_escape/resources/textures/skully.png create mode 100644 games/skully_escape/resources/textures/skully_icon.png create mode 100644 games/skully_escape/resources/textures/skully_logo.png create mode 100644 games/skully_escape/resources/textures/title.png create mode 100644 games/skully_escape/screens/screen_aisle01.c create mode 100644 games/skully_escape/screens/screen_aisle02.c create mode 100644 games/skully_escape/screens/screen_armory.c create mode 100644 games/skully_escape/screens/screen_attic.c create mode 100644 games/skully_escape/screens/screen_bathroom.c create mode 100644 games/skully_escape/screens/screen_ending.c create mode 100644 games/skully_escape/screens/screen_kitchen.c create mode 100644 games/skully_escape/screens/screen_livingroom.c create mode 100644 games/skully_escape/screens/screen_logo.c create mode 100644 games/skully_escape/screens/screen_logo_raylib.c create mode 100644 games/skully_escape/screens/screen_title.c create mode 100644 games/skully_escape/screens/screens.h create mode 100644 games/skully_escape/skully_escape.c (limited to 'games') diff --git a/games/skully_escape/makefile b/games/skully_escape/makefile new file mode 100644 index 00000000..0a343037 --- /dev/null +++ b/games/skully_escape/makefile @@ -0,0 +1,254 @@ +#************************************************************************************************** +# +# raylib - Advance Game +# +# makefile to compile advance game +# +# Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +# +# 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. +# +#************************************************************************************************** + +# define raylib platform if not defined (by default, compile for RPI) +# Other possible platform: PLATFORM_DESKTOP +PLATFORM ?= PLATFORM_DESKTOP + +# determine PLATFORM_OS in case PLATFORM_DESKTOP selected +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + # No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows + ifeq ($(OS),Windows_NT) + PLATFORM_OS=WINDOWS + LIBPATH=win32 + else + UNAMEOS:=$(shell uname) + ifeq ($(UNAMEOS),Linux) + PLATFORM_OS=LINUX + LIBPATH=linux + else + ifeq ($(UNAMEOS),Darwin) + PLATFORM_OS=OSX + LIBPATH=osx + endif + endif + endif +endif + +# define compiler: gcc for C program, define as g++ for C++ +ifeq ($(PLATFORM),PLATFORM_WEB) + # define emscripten compiler + CC = emcc +else +ifeq ($(PLATFORM_OS),OSX) + # define llvm compiler for mac + CC = clang +else + # define default gcc compiler + CC = gcc +endif +endif + +# define compiler flags: +# -O2 defines optimization level +# -Wall turns on most, but not all, compiler warnings +# -std=c99 use standard C from 1999 revision +ifeq ($(PLATFORM),PLATFORM_RPI) + CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline +else + CFLAGS = -O2 -Wall -std=c99 +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 --preload-file resources -s ALLOW_MEMORY_GROWTH=1 + #-s ASSERTIONS=1 --preload-file resources + #-s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing + #-s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB) +endif + +# define any directories containing required header files +ifeq ($(PLATFORM),PLATFORM_RPI) + INCLUDES = -I. -I../../src -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads +else + INCLUDES = -I. -IC:/raylib/raylib/src -IC:/raylib/raylib/src +# external libraries headers +# GLFW3 + INCLUDES += -I../../external/glfw3/include +# GLEW + INCLUDES += -I../../external/glew/include +# OpenAL Soft + INCLUDES += -I../../external/openal_soft/include +endif + +# define library paths containing required libs +ifeq ($(PLATFORM),PLATFORM_RPI) + LFLAGS = -L. -L../../src -L/opt/vc/lib +else + LFLAGS = -L. -LC:/raylib/raylib/src -L../../../src + # external libraries to link with + # GLFW3 + LFLAGS += -L../../external/glfw3/lib/$(LIBPATH) + ifneq ($(PLATFORM_OS),OSX) + # OpenAL Soft + LFLAGS += -L../../external/openal_soft/lib/$(LIBPATH) + # GLEW + LFLAGS += -L../../external/glew/lib/$(LIBPATH) + endif +endif + +# define any libraries to link into executable +# if you want to link libraries (libname.so or libname.a), use the -lname +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),LINUX) + # libraries for Debian GNU/Linux desktop compiling + # requires the following packages: + # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev + LIBS = -lraylib -lglfw -lGLEW -lGL -lopenal + endif + ifeq ($(PLATFORM_OS),OSX) + # libraries for OS X 10.9 desktop compiling + # requires the following packages: + # libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev + LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAl -framework Cocoa + else + # libraries for Windows desktop compiling + # NOTE: GLFW3 and OpenAL Soft libraries should be installed + LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32 + endif +endif +ifeq ($(PLATFORM),PLATFORM_RPI) + # libraries for Raspberry Pi compiling + # NOTE: OpenAL Soft library should be installed (libopenal1 package) + LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + LIBS = C:/raylib/raylib/src/libraylib.bc +endif + +# define additional parameters and flags for windows +ifeq ($(PLATFORM_OS),WINDOWS) + # resources file contains windows exe icon + # -Wl,--subsystem,windows hides the console window + WINFLAGS = C:/raylib/raylib/src/resources + #-Wl,--subsystem,windows +endif + +ifeq ($(PLATFORM),PLATFORM_WEB) + EXT = .html +endif + +# define all screen object files required +SCREENS = \ + screens/screen_logo.o \ + screens/screen_logo_raylib.o \ + screens/screen_title.o \ + screens/screen_attic.o \ + screens/screen_aisle01.o \ + screens/screen_aisle02.o \ + screens/screen_armory.o \ + screens/screen_livingroom.o \ + screens/screen_kitchen.o \ + screens/screen_bathroom.o \ + screens/screen_ending.o \ + player.o \ + monster.o \ + +# typing 'make' will invoke the first target entry in the file, +# in this case, the 'default' target entry is advance_game +default: skully_escape + +# compile template - advance_game +skully_escape: skully_escape.c $(SCREENS) + $(CC) -o $@$(EXT) $< $(SCREENS) $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) + +# compile screen LOGO +screens/screen_logo.o: screens/screen_logo.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LOGO raylib +screens/screen_logo_raylib.o: screens/screen_logo_raylib.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen TITLE +screens/screen_title.o: screens/screen_title.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen ATTIC +screens/screen_attic.o: screens/screen_attic.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen AISLE01 +screens/screen_aisle01.o: screens/screen_aisle01.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen AISLE02 +screens/screen_aisle02.o: screens/screen_aisle02.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen BATHROOM +screens/screen_bathroom.o: screens/screen_bathroom.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LIVINGROOM +screens/screen_livingroom.o: screens/screen_livingroom.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen KITCHEN +screens/screen_kitchen.o: screens/screen_kitchen.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen ARMORY +screens/screen_armory.o: screens/screen_armory.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen ENDING +screens/screen_ending.o: screens/screen_ending.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LOGO +player.o: player.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# compile screen LOGO +monster.o: monster.c + $(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM) + +# clean everything +clean: +ifeq ($(PLATFORM),PLATFORM_DESKTOP) + ifeq ($(PLATFORM_OS),OSX) + find . -type f -perm +ugo+x -delete + rm -f *.o + else + ifeq ($(PLATFORM_OS),LINUX) + find . -type f -executable -delete + rm -f *.o + else + del *.o *.exe + endif + endif +endif +ifeq ($(PLATFORM),PLATFORM_RPI) + find . -type f -executable -delete + rm -f *.o +endif +ifeq ($(PLATFORM),PLATFORM_WEB) + del *.o *.html *.js +endif + @echo Cleaning done + +# instead of defining every module one by one, we can define a pattern +# this pattern below will automatically compile every module defined on $(OBJS) +#%.exe : %.c +# $(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) diff --git a/games/skully_escape/monster.c b/games/skully_escape/monster.c new file mode 100644 index 00000000..643d0a73 --- /dev/null +++ b/games/skully_escape/monster.c @@ -0,0 +1,54 @@ +/*********************************************************************************** +* +* KING GAME JAM - GRAY TEAM +* +* +* +* +* 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) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +************************************************************************************/ + +#include "raylib.h" +#include "monster.h" + +void UpdateMonster(Monster *monster) +{ + if (!monster->active) + { + if (CheckCollisionPointRec(GetMousePosition(), monster->bounds)) monster->selected = true; + else monster->selected = false; + } + else if (monster->spooky) + { + monster->framesCounter++; + monster->currentSeq = 0; + + if (monster->framesCounter > 7) + { + monster->currentFrame++; + monster->framesCounter = 0; + + if (monster->currentFrame > monster->numFrames - 1) monster->currentFrame = 1; + } + } + + monster->frameRec.x = monster->currentFrame*monster->texture.width/monster->numFrames; + monster->frameRec.y = monster->currentSeq*monster->texture.height; +} + +void DrawMonster(Monster monster, int scroll) +{ + Vector2 scrollPos = { monster.position.x - scroll, monster.position.y }; + + if (monster.selected) DrawTextureRec(monster.texture, monster.frameRec, scrollPos, RED); + else DrawTextureRec(monster.texture, monster.frameRec, scrollPos, WHITE); +} + +void UnloadMonster(Monster monster) +{ + UnloadTexture(monster.texture); +} \ No newline at end of file diff --git a/games/skully_escape/monster.h b/games/skully_escape/monster.h new file mode 100644 index 00000000..e7e01856 --- /dev/null +++ b/games/skully_escape/monster.h @@ -0,0 +1,73 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Screens Functions Declarations (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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 MONSTER_H +#define MONSTER_H + +#define MONSTER_ANIM_FRAMES 7 +#define MONSTER_ANIM_SEQ 2 + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//--------------------------------------------------------------------------------- +typedef struct Monster { + Vector2 position; + Texture2D texture; + Rectangle bounds; + Rectangle frameRec; + Color color; + int framesCounter; + int currentFrame; + int currentSeq; + int numFrames; + bool active; + bool selected; + bool spooky; +} Monster; + +//---------------------------------------------------------------------------------- +// Global Variables Definition +//---------------------------------------------------------------------------------- + + + +#ifdef __cplusplus +extern "C" { // Prevents name mangling of functions +#endif + +//---------------------------------------------------------------------------------- +// Monster Functions Declaration +//---------------------------------------------------------------------------------- + +void UpdateMonster(Monster *monster); +void DrawMonster(Monster monster, int scroll); +void UnloadMonster(Monster monster); + + +#ifdef __cplusplus +} +#endif + +#endif // SCREENS_H \ No newline at end of file diff --git a/games/skully_escape/player.c b/games/skully_escape/player.c new file mode 100644 index 00000000..11006f65 --- /dev/null +++ b/games/skully_escape/player.c @@ -0,0 +1,281 @@ +/*********************************************************************************** +* +* KING GAME JAM - GRAY TEAM +* +* +* +* +* 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) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +************************************************************************************/ + +#include "raylib.h" +#include "player.h" + +#define PLAYER_ANIM_FRAMES 4 +#define PLAYER_ANIM_SEQ 6 + +//---------------------------------------------------------------------------------- +// Module Variables Definition +//---------------------------------------------------------------------------------- + +// Player mouse moving variables +static bool movingAnim; +static int moveDirection; +static int nextMovePoint; + +// Mouse pointer variables +static Vector2 pointerPosition; +static bool pointerAnim; +static float pointerAlpha; + +static int framesCounter; +static bool outControl = false; + +static int animTimer = 0; + +static Texture2D texLife; + +static void DrawLifes(void); + +// player initialitaction definition +void InitPlayer(void) +{ + // NOTE: Some player variables are only initialized once + player.texture = LoadTexture("resources/textures/skully.png"); + player.position = (Vector2){ 350, 400 }; + player.numLifes = 4; + + ResetPlayer(); + + framesCounter = 0; + + texLife = LoadTexture("resources/textures/skully_icon.png"); +} + +// player update definition +void UpdatePlayer(void) +{ + if (!outControl) + { + if ((IsKeyDown(KEY_LEFT)) || (IsKeyDown(KEY_RIGHT))) + { + moveDirection = -1; + movingAnim = false; + } + + if ((IsKeyDown(KEY_RIGHT)) || (moveDirection == 0)) + { + player.currentSeq = WALK_RIGHT; + framesCounter++; + + if (framesCounter > 15) + { + player.currentFrame++; + framesCounter = 0; + + if (player.currentFrame > PLAYER_ANIM_FRAMES - 1) player.currentFrame = 0; + } + + player.position.x += 4; + } + else if ((IsKeyDown(KEY_LEFT)) || (moveDirection == 1)) + { + player.currentSeq = WALK_LEFT; + framesCounter++; + + if (framesCounter > 15) + { + player.currentFrame++; + framesCounter = 0; + + if (player.currentFrame > PLAYER_ANIM_FRAMES - 1) player.currentFrame = 0; + } + + player.position.x -= 4; + } + else player.currentFrame = 0; + } + else + { + framesCounter++; + animTimer++; + + if (framesCounter > 10) + { + player.currentFrame++; + framesCounter = 0; + + if (player.currentFrame > PLAYER_ANIM_FRAMES - 1) player.currentFrame = 0; + + // We can adjust animation playing time depending on sequence + switch (player.currentSeq) + { + case SCARE_RIGHT: + { + if (animTimer > 180) + { + animTimer = 0; + outControl = false; + player.currentSeq = WALK_LEFT; + } + } break; + case SCARE_LEFT: + { + if (animTimer > 240) + { + animTimer = 0; + outControl = false; + player.currentSeq = WALK_RIGHT; + } + } break; + case SEARCH: + case FIND_KEY: + { + if (animTimer > 240) + { + animTimer = 0; + outControl = false; + player.currentSeq = WALK_RIGHT; + } + } break; + } + } + } + + if (player.position.x < 30) player.position.x = 30; + else if (player.position.x > (GetScreenWidth() - 200)) player.position.x = GetScreenWidth() - 200; + + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + pointerPosition = GetMousePosition(); + pointerAnim = true; + pointerAlpha = 1.0f; + + nextMovePoint = (int)pointerPosition.x; + movingAnim = true; + } + + if (movingAnim) + { + if (nextMovePoint > (player.position.x + (player.frameRec.width/2) + 5)) moveDirection = 0; // Move Left + else if (nextMovePoint < (player.position.x + (player.frameRec.width/2) - 5)) moveDirection = 1; // Move Right + else + { + moveDirection = -1; + movingAnim = 0; + } + } + + player.frameRec.x = player.currentFrame*player.texture.width/PLAYER_ANIM_FRAMES; + player.frameRec.y = (player.currentSeq - 1)*player.texture.height/PLAYER_ANIM_SEQ; + + // Update player bounds + player.bounds = (Rectangle){ player.position.x + 50, player.position.y - 60, 100, 300 }; + + // Mouse pointer alpha animation + if (pointerAnim) + { + pointerAlpha -= 0.1f; + + if (pointerAlpha <= 0.0f) + { + pointerAlpha = 0.0f; + pointerAnim = false; + } + } +} +// +void DrawPlayer(void) +{ + DrawTextureRec(player.texture, player.frameRec, player.position, WHITE); + + // Draw mouse pointer on click + if (pointerAnim) DrawCircleV(pointerPosition, 20, Fade(RED, pointerAlpha)); + + DrawLifes(); +} + +void UnloadPlayer(void) +{ + UnloadTexture(player.texture); + UnloadTexture(texLife); +} + +void ResetPlayer(void) +{ + // Reset player variables + player.frameRec = (Rectangle){ 0, 0, player.texture.width/PLAYER_ANIM_FRAMES, player.texture.height/PLAYER_ANIM_SEQ }; + player.currentFrame = 0; + player.currentSeq = WALK_RIGHT; + + player.key = false; + player.dead = false; + + // Reset player position + if (player.position.x < 400) player.position.x = GetScreenWidth() - 350; + if (player.position.x > (GetScreenWidth() - 400)) player.position.x = 350; + + // Reset moving variables + movingAnim = false; + moveDirection = -1; + nextMovePoint = 0; + framesCounter = 0; + outControl = false; + animTimer = 0; + + // Reset pointer + pointerAlpha = 0.0f; + pointerAnim = false; +} + +void ScarePlayer(void) +{ + player.currentFrame = 0; + + if (moveDirection == 0) player.currentSeq = SCARE_RIGHT; + else if (moveDirection == 1) player.currentSeq = SCARE_LEFT; + else player.currentSeq = SCARE_RIGHT; + + player.numLifes--; + + if (player.numLifes <= 0) player.dead = true; + + outControl = true; +} + +void SearchKeyPlayer(void) +{ + moveDirection = -1; + movingAnim = 0; + + player.currentFrame = 0; + player.currentSeq = SEARCH; + + outControl = true; +} + +void FindKeyPlayer(void) +{ + player.currentFrame = 0; + player.currentSeq = FIND_KEY; + player.key = true; + + outControl = true; +} + +static void DrawLifes(void) +{ + if (player.numLifes != 0) + { + Vector2 position = { 20, GetScreenHeight() - texLife.height - 20 }; + + for(int i = 0; i < player.numLifes; i++) + { + DrawTexture(texLife, position.x + i*texLife.width, position.y, Fade(RAYWHITE, 0.7f)); + } + } +} \ No newline at end of file diff --git a/games/skully_escape/player.h b/games/skully_escape/player.h new file mode 100644 index 00000000..7d59bdde --- /dev/null +++ b/games/skully_escape/player.h @@ -0,0 +1,51 @@ +#ifndef PLAYER_H +#define PLAYER_H + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef enum { NONE, WALK_RIGHT, WALK_LEFT, SCARE_RIGHT, SCARE_LEFT, SEARCH, FIND_KEY } PlayerSequence; + +typedef struct Player { + Vector2 position; + Rectangle bounds; + Texture2D texture; + Color color; + + // Animation variables + Rectangle frameRec; + int currentFrame; + int currentSeq; + + bool key; + int numLifes; + bool dead; +} Player; + +//---------------------------------------------------------------------------------- +// Global Variables Definition +//---------------------------------------------------------------------------------- +Player player; + +#ifdef __cplusplus +extern "C" { // Prevents name mangling of functions +#endif + +//---------------------------------------------------------------------------------- +// Logo Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitPlayer(void); +void UpdatePlayer(void); +void DrawPlayer(void); +void UnloadPlayer(void); +void ResetPlayer(void); + +void ScarePlayer(void); +void SearchKeyPlayer(void); +void FindKeyPlayer(void); + +#ifdef __cplusplus +} +#endif + +#endif // SCREENS_H \ No newline at end of file diff --git a/games/skully_escape/resources/audio/come_play_with_me.ogg b/games/skully_escape/resources/audio/come_play_with_me.ogg new file mode 100644 index 00000000..425498b8 Binary files /dev/null and b/games/skully_escape/resources/audio/come_play_with_me.ogg differ diff --git a/games/skully_escape/resources/audio/door.ogg b/games/skully_escape/resources/audio/door.ogg new file mode 100644 index 00000000..a1d1cd1b Binary files /dev/null and b/games/skully_escape/resources/audio/door.ogg differ diff --git a/games/skully_escape/resources/audio/scream.ogg b/games/skully_escape/resources/audio/scream.ogg new file mode 100644 index 00000000..41524027 Binary files /dev/null and b/games/skully_escape/resources/audio/scream.ogg differ diff --git a/games/skully_escape/resources/textures/alagard.png b/games/skully_escape/resources/textures/alagard.png new file mode 100644 index 00000000..c5cc54dc Binary files /dev/null and b/games/skully_escape/resources/textures/alagard.png differ diff --git a/games/skully_escape/resources/textures/background_aisle01.png b/games/skully_escape/resources/textures/background_aisle01.png new file mode 100644 index 00000000..482056f8 Binary files /dev/null and b/games/skully_escape/resources/textures/background_aisle01.png differ diff --git a/games/skully_escape/resources/textures/background_aisle02.png b/games/skully_escape/resources/textures/background_aisle02.png new file mode 100644 index 00000000..fced627f Binary files /dev/null and b/games/skully_escape/resources/textures/background_aisle02.png differ diff --git a/games/skully_escape/resources/textures/background_armory.png b/games/skully_escape/resources/textures/background_armory.png new file mode 100644 index 00000000..1a93807f Binary files /dev/null and b/games/skully_escape/resources/textures/background_armory.png differ diff --git a/games/skully_escape/resources/textures/background_attic.png b/games/skully_escape/resources/textures/background_attic.png new file mode 100644 index 00000000..446e09a7 Binary files /dev/null and b/games/skully_escape/resources/textures/background_attic.png differ diff --git a/games/skully_escape/resources/textures/background_bathroom.png b/games/skully_escape/resources/textures/background_bathroom.png new file mode 100644 index 00000000..55061d1f Binary files /dev/null and b/games/skully_escape/resources/textures/background_bathroom.png differ diff --git a/games/skully_escape/resources/textures/background_kitchen.png b/games/skully_escape/resources/textures/background_kitchen.png new file mode 100644 index 00000000..5c74c74e Binary files /dev/null and b/games/skully_escape/resources/textures/background_kitchen.png differ diff --git a/games/skully_escape/resources/textures/background_livingroom.png b/games/skully_escape/resources/textures/background_livingroom.png new file mode 100644 index 00000000..f91a11f9 Binary files /dev/null and b/games/skully_escape/resources/textures/background_livingroom.png differ diff --git a/games/skully_escape/resources/textures/doors.png b/games/skully_escape/resources/textures/doors.png new file mode 100644 index 00000000..f5a75d05 Binary files /dev/null and b/games/skully_escape/resources/textures/doors.png differ diff --git a/games/skully_escape/resources/textures/monster_arc.png b/games/skully_escape/resources/textures/monster_arc.png new file mode 100644 index 00000000..ae3e346d Binary files /dev/null and b/games/skully_escape/resources/textures/monster_arc.png differ diff --git a/games/skully_escape/resources/textures/monster_blazon01.png b/games/skully_escape/resources/textures/monster_blazon01.png new file mode 100644 index 00000000..2d2a409c Binary files /dev/null and b/games/skully_escape/resources/textures/monster_blazon01.png differ diff --git a/games/skully_escape/resources/textures/monster_blazon02.png b/games/skully_escape/resources/textures/monster_blazon02.png new file mode 100644 index 00000000..8cea9361 Binary files /dev/null and b/games/skully_escape/resources/textures/monster_blazon02.png differ diff --git a/games/skully_escape/resources/textures/monster_blazon03.png b/games/skully_escape/resources/textures/monster_blazon03.png new file mode 100644 index 00000000..cc4665a1 Binary files /dev/null and b/games/skully_escape/resources/textures/monster_blazon03.png differ diff --git a/games/skully_escape/resources/textures/monster_candle.png b/games/skully_escape/resources/textures/monster_candle.png new file mode 100644 index 00000000..9feef00d Binary files /dev/null and b/games/skully_escape/resources/textures/monster_candle.png differ diff --git a/games/skully_escape/resources/textures/monster_chair_left.png b/games/skully_escape/resources/textures/monster_chair_left.png new file mode 100644 index 00000000..b3ac070f Binary files /dev/null and b/games/skully_escape/resources/textures/monster_chair_left.png differ diff --git a/games/skully_escape/resources/textures/monster_chair_right.png b/games/skully_escape/resources/textures/monster_chair_right.png new file mode 100644 index 00000000..d29cc021 Binary files /dev/null and b/games/skully_escape/resources/textures/monster_chair_right.png differ diff --git a/games/skully_escape/resources/textures/monster_closet.png b/games/skully_escape/resources/textures/monster_closet.png new file mode 100644 index 00000000..7c0c8f27 Binary files /dev/null and b/games/skully_escape/resources/textures/monster_closet.png differ diff --git a/games/skully_escape/resources/textures/monster_lamp_left.png b/games/skully_escape/resources/textures/monster_lamp_left.png new file mode 100644 index 00000000..3b31b77f Binary files /dev/null and b/games/skully_escape/resources/textures/monster_lamp_left.png differ diff --git a/games/skully_escape/resources/textures/monster_lamp_right.png b/games/skully_escape/resources/textures/monster_lamp_right.png new file mode 100644 index 00000000..26491866 Binary files /dev/null and b/games/skully_escape/resources/textures/monster_lamp_right.png differ diff --git a/games/skully_escape/resources/textures/monster_mirror.png b/games/skully_escape/resources/textures/monster_mirror.png new file mode 100644 index 00000000..2e994309 Binary files /dev/null and b/games/skully_escape/resources/textures/monster_mirror.png differ diff --git a/games/skully_escape/resources/textures/monster_phone.png b/games/skully_escape/resources/textures/monster_phone.png new file mode 100644 index 00000000..a4862ef7 Binary files /dev/null and b/games/skully_escape/resources/textures/monster_phone.png differ diff --git a/games/skully_escape/resources/textures/monster_picture.png b/games/skully_escape/resources/textures/monster_picture.png new file mode 100644 index 00000000..29549895 Binary files /dev/null and b/games/skully_escape/resources/textures/monster_picture.png differ diff --git a/games/skully_escape/resources/textures/monster_window.png b/games/skully_escape/resources/textures/monster_window.png new file mode 100644 index 00000000..47d70a79 Binary files /dev/null and b/games/skully_escape/resources/textures/monster_window.png differ diff --git a/games/skully_escape/resources/textures/skully.png b/games/skully_escape/resources/textures/skully.png new file mode 100644 index 00000000..9ce6cd58 Binary files /dev/null and b/games/skully_escape/resources/textures/skully.png differ diff --git a/games/skully_escape/resources/textures/skully_icon.png b/games/skully_escape/resources/textures/skully_icon.png new file mode 100644 index 00000000..91a0bc2a Binary files /dev/null and b/games/skully_escape/resources/textures/skully_icon.png differ diff --git a/games/skully_escape/resources/textures/skully_logo.png b/games/skully_escape/resources/textures/skully_logo.png new file mode 100644 index 00000000..93e8bfe2 Binary files /dev/null and b/games/skully_escape/resources/textures/skully_logo.png differ diff --git a/games/skully_escape/resources/textures/title.png b/games/skully_escape/resources/textures/title.png new file mode 100644 index 00000000..20e08c88 Binary files /dev/null and b/games/skully_escape/resources/textures/title.png differ diff --git a/games/skully_escape/screens/screen_aisle01.c b/games/skully_escape/screens/screen_aisle01.c new file mode 100644 index 00000000..17d25058 --- /dev/null +++ b/games/skully_escape/screens/screen_aisle01.c @@ -0,0 +1,409 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" +#include "../player.h" +#include "../monster.h" + +#include + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Gameplay screen global variables +static int framesCounter; +static int finishScreen; + +static Texture2D background; + +// Declare doors +static Door doorRight; +static Door doorCenter; +static Door doorLeft; + +// Decalre monsters +static Monster lamp; +static Monster picture; + +static bool monsterHover = false; +static int monsterCheck = -1; // Identify checking monster + +static const char message[256] = "WHO IS THERE???\nANYBODY IN THE ROOM???"; +static int msgPosX = 100; + +static int msgState = 0; // 0-writting, 1-wait, 2-choose +static int lettersCounter = 0; +static char msgBuffer[256] = { '\0' }; +static int msgCounter = 0; + +static bool searching = false; + +static int scroll = 0; + +//---------------------------------------------------------------------------------- +// Gameplay Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Gameplay Screen Initialization logic +void InitAisle01Screen(void) +{ + ResetPlayer(); + + // Reset Screen variables + monsterHover = false; + monsterCheck = -1; + msgState = 0; + msgCounter = 0; + lettersCounter = 0; + for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; + + framesCounter = 0; + finishScreen = 0; + + background = LoadTexture("resources/textures/background_aisle01.png"); + + scroll = player.position.x - 200; + + // Initialize doors + doorLeft.position = (Vector2) { -30, 135 }; + doorLeft.facing = 0; + doorLeft.locked = true; + doorLeft.frameRec =(Rectangle) {((doors.width/3)*doorLeft.facing), doors.height/2, doors.width/3, doors.height/2}; + doorLeft.bound = (Rectangle) { doorLeft.position.x, doorLeft.position.y, doors.width/3, doors.height/2}; + doorLeft.selected = false; + + doorCenter.position = (Vector2) { 1115, 104 }; + doorCenter.facing = 1; + doorCenter.locked = true; + doorCenter.frameRec =(Rectangle) {((doors.width/3)*doorCenter.facing), doors.height/2, doors.width/3, doors.height/2}; + doorCenter.bound = (Rectangle) { doorCenter.position.x, doorCenter.position.y, doors.width/3, doors.height/2}; + doorCenter.selected = false; + + doorRight.position = (Vector2) { 1710, 140 }; + doorRight.facing = 2; + doorRight.locked = true; + doorRight.frameRec =(Rectangle) {((doors.width/3)*doorRight.facing), doors.height/2, doors.width/3, doors.height/2}; + doorRight.bound = (Rectangle) { doorRight.position.x, doorRight.position.y, doors.width/3, doors.height/2}; + + // Monster init: lamp + lamp.position = (Vector2){ 187, 256 }; + lamp.texture = LoadTexture("resources/textures/monster_lamp_left.png"); + lamp.currentFrame = 0; + lamp.framesCounter = 0; + lamp.numFrames = 4; + lamp.bounds = (Rectangle){ lamp.position.x + 20, lamp.position.y, 90, 380 }; + lamp.frameRec = (Rectangle) { 0, 0, lamp.texture.width/lamp.numFrames, lamp.texture.height }; + lamp.selected = false; + lamp.active = false; + lamp.spooky = true; + + // Monster init: arc + picture.position = (Vector2){ 637, 178 }; + picture.texture = LoadTexture("resources/textures/monster_picture.png"); + picture.currentFrame = 0; + picture.framesCounter = 0; + picture.numFrames = 4; + picture.bounds = (Rectangle){ picture.position.x + 44, picture.position.y, 174, 256 }; + picture.frameRec = (Rectangle) { 0, 0, picture.texture.width/picture.numFrames, picture.texture.height }; + picture.selected = false; + picture.active = false; + picture.spooky = false; +} + +// Gameplay Screen Update logic +void UpdateAisle01Screen(void) +{ + // Update doors bounds + doorLeft.bound.x = doorLeft.position.x - scroll; + doorCenter.bound.x = doorCenter.position.x - scroll; + doorRight.bound.x = doorRight.position.x - scroll; + + if (player.key) + { + // Door: left + if ((CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || + (CheckCollisionRecs(player.bounds, doorLeft.bound))) doorLeft.selected = true; + else doorLeft.selected = false; + + if ((doorLeft.selected) && (CheckCollisionRecs(player.bounds, doorLeft.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorLeft.locked) + { + doorLeft.frameRec.y = 0; + doorLeft.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 1; + } + } + + // Door: center + if ((CheckCollisionPointRec(GetMousePosition(), doorCenter.bound)) || + (CheckCollisionRecs(player.bounds, doorCenter.bound))) doorCenter.selected = true; + else doorCenter.selected = false; + + if ((doorCenter.selected) && (CheckCollisionRecs(player.bounds, doorCenter.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorCenter.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorCenter.locked) + { + doorCenter.frameRec.y = 0; + doorCenter.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 2; + } + } + + // Door: right + if ((CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || + (CheckCollisionRecs(player.bounds, doorRight.bound))) doorRight.selected = true; + else doorRight.selected = false; + + if ((doorRight.selected) && (CheckCollisionRecs(player.bounds, doorRight.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorRight.locked) + { + doorRight.frameRec.y = 0; + doorRight.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 3; + } + } + } + + if (msgState > 2) + { + UpdatePlayer(); + + // Monsters logic + UpdateMonster(&lamp); + UpdateMonster(&picture); + } + + // Update monster bounds + lamp.bounds.x = lamp.position.x + 20 - scroll; + picture.bounds.x = picture.position.x + 44 - scroll; + + // Check player hover monsters to interact + if (((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active) || + ((CheckCollisionRecs(player.bounds, picture.bounds)) && !picture.active)) monsterHover = true; + else monsterHover = false; + + // Monters logic: lamp + if ((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active) + { + lamp.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), lamp.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 1; + } + } + else lamp.selected = false; + + // Monters logic: picture + if ((CheckCollisionRecs(player.bounds, picture.bounds)) && !picture.active) + { + picture.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), picture.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 2; + } + } + else picture.selected = false; + + if (searching) + { + framesCounter++; + + if (framesCounter > 180) + { + if (monsterCheck == 1) + { + if (lamp.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + lamp.active = true; + lamp.selected = false; + } + else if (monsterCheck == 2) + { + if (picture.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + picture.active = true; + picture.selected = false; + } + + searching = false; + framesCounter = 0; + } + } + + // Text animation + framesCounter++; + + if ((framesCounter%2) == 0) lettersCounter++; + + if (msgState == 0) + { + if (lettersCounter <= (int)strlen(message)) strncpy(msgBuffer, message, lettersCounter); + else + { + for (int i = 0; i < (int)strlen(msgBuffer); i++) msgBuffer[i] = '\0'; + + lettersCounter = 0; + msgState = 1; + } + + if (IsKeyPressed(KEY_ENTER)) msgState = 1; + } + else if (msgState == 1) + { + msgCounter++; + + if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) + { + msgState = 2; + msgCounter = 0; + } + } + else if (msgState == 2) + { + msgCounter++; + + if (msgCounter > 180) msgState = 3; + } + else msgCounter++; + + if (player.position.x > 200) + { + scroll = player.position.x - 200; + + if (scroll > 620) scroll = 620; + } +} + +// Gameplay Screen Draw logic +void DrawAisle01Screen(void) +{ + DrawTexture(background, -scroll, 0, WHITE); + + // Draw monsters + DrawMonster(lamp, scroll); + DrawMonster(picture, scroll); + + // Draw door + Vector2 doorScrollPos = { doorCenter.position.x - scroll, doorCenter.position.y }; + if (doorCenter.selected) DrawTextureRec(doors, doorCenter.frameRec, doorScrollPos, GREEN); + else DrawTextureRec(doors, doorCenter.frameRec, doorScrollPos, WHITE); + + doorScrollPos = (Vector2){ doorLeft.position.x - scroll, doorLeft.position.y }; + if (doorLeft.selected) DrawTextureRec(doors, doorLeft.frameRec, doorScrollPos, GREEN); + else DrawTextureRec(doors, doorLeft.frameRec, doorScrollPos, WHITE); + + doorScrollPos = (Vector2){ doorRight.position.x - scroll, doorRight.position.y }; + if (doorRight.selected) DrawTextureRec(doors, doorRight.frameRec, doorScrollPos, GREEN); + else DrawTextureRec(doors, doorRight.frameRec, doorScrollPos, WHITE); + + // Draw messsages + if (msgState < 2) DrawRectangle(0, 40, GetScreenWidth(), 200, Fade(LIGHTGRAY, 0.5f)); + else if (msgState == 2) DrawRectangle(0, 80, GetScreenWidth(), 100, Fade(LIGHTGRAY, 0.5f)); + + if (msgState == 0) + { + DrawTextEx(font, msgBuffer, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + } + else if (msgState == 1) + { + DrawTextEx(font, message, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + + if ((msgCounter/30)%2) DrawText("PRESS ENTER or CLICK", GetScreenWidth() - 280, 200, 20, BLACK); + } + else if (msgState == 2) + { + if ((msgCounter/30)%2) + { + DrawTextEx(font, "CHOOSE WISELY!", (Vector2){ 300, 95 }, font.size*2, 2, WHITE); + + DrawRectangleRec(lamp.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(picture.bounds, Fade(RED, 0.6f)); + } + } + else + { + if ((monsterHover) && ((msgCounter/30)%2)) + { + DrawRectangle(0, 0, GetScreenWidth(), 50, Fade(LIGHTGRAY, 0.5f)); + DrawText("PRESS SPACE or CLICK to INTERACT", 420, 15, 20, BLACK); + } + } + + DrawPlayer(); // NOTE: Also draws mouse pointer! +} + +// Gameplay Screen Unload logic +void UnloadAisle01Screen(void) +{ + // TODO: Unload GAMEPLAY screen variables here! + UnloadTexture(background); + + UnloadMonster(lamp); + UnloadMonster(picture); +} + +// Gameplay Screen should finish? +int FinishAisle01Screen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/skully_escape/screens/screen_aisle02.c b/games/skully_escape/screens/screen_aisle02.c new file mode 100644 index 00000000..6186a1fc --- /dev/null +++ b/games/skully_escape/screens/screen_aisle02.c @@ -0,0 +1,444 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" +#include "../player.h" +#include "../monster.h" + +#include + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Gameplay screen global variables +static int framesCounter; +static int finishScreen; + +static Texture2D background; + +// Declare doors +static Door doorLeft; + +// Decalre monsters +static Monster lamp; +static Monster chair; +static Monster picture; +static Monster arc; + +static bool monsterHover = false; +static int monsterCheck = -1; // Identify checking monster + +static const char message[256] = "HAS LEGS BUT CAN NOT WALK...\nSEARCH FOR IT TO OPEN THE DOOR!"; +static int msgPosX = 100; + +static int msgState = 0; // 0-writting, 1-wait, 2-choose +static int lettersCounter = 0; +static char msgBuffer[256] = { '\0' }; +static int msgCounter = 0; + +static bool searching = false; + +static int scroll = 0; + +//---------------------------------------------------------------------------------- +// Gameplay Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Gameplay Screen Initialization logic +void InitAisle02Screen(void) +{ + ResetPlayer(); + + // Reset Screen variables + monsterHover = false; + monsterCheck = -1; + msgState = 0; + msgCounter = 0; + lettersCounter = 0; + for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; + + framesCounter = 0; + finishScreen = 0; + + background = LoadTexture("resources/textures/background_aisle02.png"); + + scroll = player.position.x - 200; + + // Initialize doors + doorLeft.position = (Vector2) { -10, 136 }; + doorLeft.facing = 0; + doorLeft.locked = true; + doorLeft.frameRec =(Rectangle) {((doors.width/3)*doorLeft.facing), doors.height/2, doors.width/3, doors.height/2}; + doorLeft.bound = (Rectangle) { doorLeft.position.x, doorLeft.position.y, doors.width/3, doors.height/2}; + doorLeft.selected = false; + + // Monster init: lamp + lamp.position = (Vector2){ 1520, 300 }; + lamp.texture = LoadTexture("resources/textures/monster_lamp_right.png"); + lamp.currentFrame = 0; + lamp.framesCounter = 0; + lamp.numFrames = 4; + lamp.bounds = (Rectangle){ lamp.position.x + 200, lamp.position.y, 90, 380 }; + lamp.frameRec = (Rectangle) { 0, 0, lamp.texture.width/lamp.numFrames, lamp.texture.height }; + lamp.selected = false; + lamp.active = false; + lamp.spooky = true; + + // Monster init: chair + chair.position = (Vector2){ 1400, 404 }; + chair.texture = LoadTexture("resources/textures/monster_chair_right.png"); + chair.currentFrame = 0; + chair.framesCounter = 0; + chair.numFrames = 4; + chair.bounds = (Rectangle){ chair.position.x + 50, chair.position.y + 30, 120, 190 }; + chair.frameRec = (Rectangle) { 0, 0, chair.texture.width/chair.numFrames, chair.texture.height }; + chair.selected = false; + chair.active = false; + chair.spooky = false; + + // Monster init: picture + picture.position = (Vector2){ 837, 162 }; + picture.texture = LoadTexture("resources/textures/monster_picture.png"); + picture.currentFrame = 0; + picture.framesCounter = 0; + picture.numFrames = 4; + picture.bounds = (Rectangle){ picture.position.x + 44, picture.position.y, 174, 264 }; + picture.frameRec = (Rectangle) { 0, 0, picture.texture.width/picture.numFrames, picture.texture.height }; + picture.selected = false; + picture.active = false; + picture.spooky = true; + + // Monster init: arc + arc.position = (Vector2){ 388, 423 }; + arc.texture = LoadTexture("resources/textures/monster_arc.png"); + arc.currentFrame = 0; + arc.framesCounter = 0; + arc.numFrames = 4; + arc.bounds = (Rectangle){ arc.position.x + 44, arc.position.y + 70, 220, 120 }; + arc.frameRec = (Rectangle) { 0, 0, arc.texture.width/arc.numFrames, arc.texture.height }; + arc.selected = false; + arc.active = false; + arc.spooky = true; +} + +// Gameplay Screen Update logic +void UpdateAisle02Screen(void) +{ + // Update doors bounds + doorLeft.bound.x = doorLeft.position.x - scroll; + + if (player.key) + { + // Door: left + if ((CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || + (CheckCollisionRecs(player.bounds, doorLeft.bound))) doorLeft.selected = true; + else doorLeft.selected = false; + + if ((doorLeft.selected) && (CheckCollisionRecs(player.bounds, doorLeft.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorLeft.locked) + { + doorLeft.frameRec.y = 0; + doorLeft.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 1; + } + } + } + + if (msgState > 2) + { + UpdatePlayer(); + + // Monsters logic + UpdateMonster(&lamp); + UpdateMonster(&chair); + UpdateMonster(&picture); + UpdateMonster(&arc); + } + + // Update monster bounds + lamp.bounds.x = lamp.position.x + 200 - scroll; + chair.bounds.x = chair.position.x + 50 - scroll; + picture.bounds.x = picture.position.x + 44 - scroll; + arc.bounds.x = arc.position.x + 44 - scroll; + + // Check player hover monsters to interact + if (((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active) || + ((CheckCollisionRecs(player.bounds, chair.bounds)) && !chair.active) || + ((CheckCollisionRecs(player.bounds, picture.bounds)) && !picture.active) || + ((CheckCollisionRecs(player.bounds, arc.bounds)) && !arc.active)) monsterHover = true; + else monsterHover = false; + + + // Monters logic: lamp + if ((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active) + { + lamp.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), lamp.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 1; + } + } + else lamp.selected = false; + + // Monters logic: chair + if ((CheckCollisionRecs(player.bounds, chair.bounds)) && !chair.active) + { + chair.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), chair.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 2; + } + } + else chair.selected = false; + + // Monters logic: picture + if ((CheckCollisionRecs(player.bounds, picture.bounds)) && !picture.active) + { + picture.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), picture.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 3; + } + } + else picture.selected = false; + + // Monters logic: arc + if ((CheckCollisionRecs(player.bounds, arc.bounds)) && !arc.active) + { + arc.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), arc.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 4; + } + } + else arc.selected = false; + + if (searching) + { + framesCounter++; + + if (framesCounter > 180) + { + if (monsterCheck == 1) + { + if (lamp.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + lamp.active = true; + lamp.selected = false; + } + else if (monsterCheck == 2) + { + if (chair.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + chair.active = true; + chair.selected = false; + } + else if (monsterCheck == 3) + { + if (picture.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + picture.active = true; + picture.selected = false; + } + else if (monsterCheck == 4) + { + if (arc.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + arc.active = true; + arc.selected = false; + } + + searching = false; + framesCounter = 0; + } + } + + // Text animation + framesCounter++; + + if ((framesCounter%2) == 0) lettersCounter++; + + if (msgState == 0) + { + if (lettersCounter <= (int)strlen(message)) strncpy(msgBuffer, message, lettersCounter); + else + { + for (int i = 0; i < (int)strlen(msgBuffer); i++) msgBuffer[i] = '\0'; + + lettersCounter = 0; + msgState = 1; + } + + if (IsKeyPressed(KEY_ENTER)) msgState = 1; + } + else if (msgState == 1) + { + msgCounter++; + + if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) + { + msgState = 2; + msgCounter = 0; + } + } + else if (msgState == 2) + { + msgCounter++; + + if (msgCounter > 180) msgState = 3; + } + else msgCounter++; + + if (player.position.x > 200) + { + scroll = player.position.x - 200; + + if (scroll > 620) scroll = 620; + } +} + +// Gameplay Screen Draw logic +void DrawAisle02Screen(void) +{ + DrawTexture(background, -scroll, 0, WHITE); + + // Draw monsters + DrawMonster(lamp, scroll); + DrawMonster(arc, scroll); + DrawMonster(picture, scroll); + DrawMonster(chair, scroll); + + // Draw door + Vector2 doorScrollPos = { doorLeft.position.x - scroll, doorLeft.position.y }; + + if (doorLeft.selected) DrawTextureRec(doors, doorLeft.frameRec, doorScrollPos, GREEN); + else DrawTextureRec(doors, doorLeft.frameRec, doorScrollPos, WHITE); + + // Draw messsages + if (msgState < 2) DrawRectangle(0, 40, GetScreenWidth(), 200, Fade(LIGHTGRAY, 0.5f)); + else if (msgState == 2) DrawRectangle(0, 80, GetScreenWidth(), 100, Fade(LIGHTGRAY, 0.5f)); + + if (msgState == 0) + { + DrawTextEx(font, msgBuffer, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + } + else if (msgState == 1) + { + DrawTextEx(font, message, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + + if ((msgCounter/30)%2) DrawText("PRESS ENTER or CLICK", GetScreenWidth() - 280, 200, 20, BLACK); + } + else if (msgState == 2) + { + if ((msgCounter/30)%2) + { + DrawTextEx(font, "CHOOSE WISELY!", (Vector2){ 300, 95 }, font.size*2, 2, WHITE); + + DrawRectangleRec(lamp.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(arc.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(chair.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(picture.bounds, Fade(RED, 0.6f)); + } + } + else + { + if ((monsterHover) && ((msgCounter/30)%2)) + { + DrawRectangle(0, 0, GetScreenWidth(), 50, Fade(LIGHTGRAY, 0.5f)); + DrawText("PRESS SPACE or CLICK to INTERACT", 420, 15, 20, BLACK); + } + } + + DrawPlayer(); // NOTE: Also draws mouse pointer! +} + +// Gameplay Screen Unload logic +void UnloadAisle02Screen(void) +{ + // TODO: Unload GAMEPLAY screen variables here! + UnloadTexture(background); + + UnloadMonster(lamp); + UnloadMonster(chair); + UnloadMonster(picture); + UnloadMonster(arc); +} + +// Gameplay Screen should finish? +int FinishAisle02Screen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/skully_escape/screens/screen_armory.c b/games/skully_escape/screens/screen_armory.c new file mode 100644 index 00000000..622299f0 --- /dev/null +++ b/games/skully_escape/screens/screen_armory.c @@ -0,0 +1,404 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" +#include "../player.h" +#include "../monster.h" + +#include + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Gameplay screen global variables +static int framesCounter; +static int finishScreen; + +static Texture2D background; + +// Declare doors +static Door doorLeft; +static Door doorRight; + +// Decalre monsters +static Monster blazon01; +static Monster blazon02; +static Monster blazon03; + +static bool monsterHover = false; +static int monsterCheck = -1; // Identify checking monster + +static const char message[256] = "NO MORE TIPS...\nFOLLOW YOUR INSTINCT!"; +static int msgPosX = 100; + +static int msgState = 0; // 0-writting, 1-wait, 2-choose +static int lettersCounter = 0; +static char msgBuffer[256] = { '\0' }; +static int msgCounter = 0; + +static bool searching = false; + +//---------------------------------------------------------------------------------- +// Gameplay Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Gameplay Screen Initialization logic +void InitArmoryScreen(void) +{ + ResetPlayer(); + + // Reset Screen variables + monsterHover = false; + monsterCheck = -1; + msgState = 0; + msgCounter = 0; + lettersCounter = 0; + for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; + + framesCounter = 0; + finishScreen = 0; + + background = LoadTexture("resources/textures/background_armory.png"); + + // Initialize doors + doorLeft.position = (Vector2) { -50, 145 }; + doorLeft.facing = 0; + doorLeft.locked = true; + doorLeft.frameRec =(Rectangle) {((doors.width/3)*doorLeft.facing), doors.height/2, doors.width/3, doors.height/2}; + doorLeft.bound = (Rectangle) { doorLeft.position.x, doorLeft.position.y, doors.width/3, doors.height/2}; + doorLeft.selected = false; + + doorRight.position = (Vector2) { 1074, 140 }; + doorRight.facing = 2; + doorRight.locked = true; + doorRight.frameRec =(Rectangle) {((doors.width/3)*doorRight.facing), doors.height/2, doors.width/3, doors.height/2}; + doorRight.bound = (Rectangle) { doorRight.position.x, doorRight.position.y, doors.width/3, doors.height/2}; + doorRight.selected = false; + + // Monster init: blazon01 + blazon01.position = (Vector2){ 300, 260 }; + blazon01.texture = LoadTexture("resources/textures/monster_blazon01.png"); + blazon01.currentFrame = 0; + blazon01.framesCounter = 0; + blazon01.numFrames = 4; + blazon01.bounds = (Rectangle){ blazon01.position.x, blazon01.position.y + 20, 160, 230 }; + blazon01.frameRec = (Rectangle) { 0, 0, blazon01.texture.width/blazon01.numFrames, blazon01.texture.height }; + blazon01.selected = false; + blazon01.active = false; + blazon01.spooky = true; + + // Monster init: blazon02 + blazon02.position = (Vector2){ 550, 260 }; + blazon02.texture = LoadTexture("resources/textures/monster_blazon02.png"); + blazon02.currentFrame = 0; + blazon02.framesCounter = 0; + blazon02.numFrames = 4; + blazon02.bounds = (Rectangle){ blazon02.position.x, blazon02.position.y + 20, 160, 230 }; + blazon02.frameRec = (Rectangle) { 0, 0, blazon02.texture.width/blazon02.numFrames, blazon02.texture.height }; + blazon02.selected = false; + blazon02.active = false; + blazon02.spooky = true; + + // Monster init: blazon03 + blazon03.position = (Vector2){ 800, 260 }; + blazon03.texture = LoadTexture("resources/textures/monster_blazon03.png"); + blazon03.currentFrame = 0; + blazon03.framesCounter = 0; + blazon03.numFrames = 4; + blazon03.bounds = (Rectangle){ blazon03.position.x, blazon03.position.y + 20, 160, 230 }; + blazon03.frameRec = (Rectangle) { 0, 0, blazon03.texture.width/blazon03.numFrames, blazon03.texture.height }; + blazon03.selected = false; + blazon03.active = false; + blazon03.spooky = false; +} + +// Gameplay Screen Update logic +void UpdateArmoryScreen(void) +{ + if (player.key) + { + // Door: left + if ((CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || + (CheckCollisionRecs(player.bounds, doorLeft.bound))) doorLeft.selected = true; + else doorLeft.selected = false; + + if ((doorLeft.selected) && (CheckCollisionRecs(player.bounds, doorLeft.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorLeft.locked) + { + doorLeft.frameRec.y = 0; + doorLeft.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 1; + } + } + + // Door: right + if ((CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || + (CheckCollisionRecs(player.bounds, doorRight.bound))) doorRight.selected = true; + else doorRight.selected = false; + + if ((doorRight.selected) && (CheckCollisionRecs(player.bounds, doorRight.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorRight.locked) + { + doorRight.frameRec.y = 0; + doorRight.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 2; + } + } + } + + if (msgState > 2) + { + UpdatePlayer(); + + // Monsters logic + UpdateMonster(&blazon01); + UpdateMonster(&blazon02); + UpdateMonster(&blazon03); + } + + // Check player hover monsters to interact + if (((CheckCollisionRecs(player.bounds, blazon01.bounds)) && !blazon01.active) || + ((CheckCollisionRecs(player.bounds, blazon02.bounds)) && !blazon02.active) || + ((CheckCollisionRecs(player.bounds, blazon03.bounds)) && !blazon03.active)) monsterHover = true; + else monsterHover = false; + + // Monters logic: blazon01 + if ((CheckCollisionRecs(player.bounds, blazon01.bounds)) && !blazon01.active) + { + blazon01.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), blazon01.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 1; + } + } + else blazon01.selected = false; + + // Monters logic: blazon02 + if ((CheckCollisionRecs(player.bounds, blazon02.bounds)) && !blazon02.active) + { + blazon02.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), blazon02.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 2; + } + } + else blazon02.selected = false; + + // Monters logic: blazon03 + if ((CheckCollisionRecs(player.bounds, blazon03.bounds)) && !blazon03.active) + { + blazon03.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), blazon03.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 3; + } + } + else blazon03.selected = false; + + if (searching) + { + framesCounter++; + + if (framesCounter > 180) + { + if (monsterCheck == 1) + { + if (blazon01.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + blazon01.active = true; + blazon01.selected = false; + } + else if (monsterCheck == 2) + { + if (blazon02.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + blazon02.active = true; + blazon02.selected = false; + } + else if (monsterCheck == 3) + { + if (blazon03.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + blazon03.active = true; + blazon03.selected = false; + } + + searching = false; + framesCounter = 0; + } + } + + // Text animation + framesCounter++; + + if ((framesCounter%2) == 0) lettersCounter++; + + if (msgState == 0) + { + if (lettersCounter <= (int)strlen(message)) strncpy(msgBuffer, message, lettersCounter); + else + { + for (int i = 0; i < (int)strlen(msgBuffer); i++) msgBuffer[i] = '\0'; + + lettersCounter = 0; + msgState = 1; + } + + if (IsKeyPressed(KEY_ENTER)) msgState = 1; + } + else if (msgState == 1) + { + msgCounter++; + + if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) + { + msgState = 2; + msgCounter = 0; + } + } + else if (msgState == 2) + { + msgCounter++; + + if (msgCounter > 180) msgState = 3; + } + else msgCounter++; +} + +// Gameplay Screen Draw logic +void DrawArmoryScreen(void) +{ + DrawTexture(background, 0, 0, WHITE); + + // Draw monsters + DrawMonster(blazon01, 0); + DrawMonster(blazon02, 0); + DrawMonster(blazon03, 0); + + // Draw door + if (doorLeft.selected) DrawTextureRec(doors, doorLeft.frameRec, doorLeft.position, GREEN); + else DrawTextureRec(doors, doorLeft.frameRec, doorLeft.position, WHITE); + + if (doorRight.selected) DrawTextureRec(doors, doorRight.frameRec, doorRight.position, GREEN); + else DrawTextureRec(doors, doorRight.frameRec, doorRight.position, WHITE); + + // Draw messsages + if (msgState < 2) DrawRectangle(0, 40, GetScreenWidth(), 200, Fade(LIGHTGRAY, 0.5f)); + else if (msgState == 2) DrawRectangle(0, 80, GetScreenWidth(), 100, Fade(LIGHTGRAY, 0.5f)); + + if (msgState == 0) + { + DrawTextEx(font, msgBuffer, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + } + else if (msgState == 1) + { + DrawTextEx(font, message, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + + if ((msgCounter/30)%2) DrawText("PRESS ENTER or CLICK", GetScreenWidth() - 280, 200, 20, BLACK); + } + else if (msgState == 2) + { + if ((msgCounter/30)%2) + { + DrawTextEx(font, "CHOOSE WISELY!", (Vector2){ 300, 95 }, font.size*2, 2, WHITE); + + DrawRectangleRec(blazon01.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(blazon02.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(blazon03.bounds, Fade(RED, 0.6f)); + } + } + else + { + if ((monsterHover) && ((msgCounter/30)%2)) + { + DrawRectangle(0, 0, GetScreenWidth(), 50, Fade(LIGHTGRAY, 0.5f)); + DrawText("PRESS SPACE or CLICK to INTERACT", 420, 15, 20, BLACK); + } + } + + DrawPlayer(); // NOTE: Also draws mouse pointer! +} + +// Gameplay Screen Unload logic +void UnloadArmoryScreen(void) +{ + // TODO: Unload GAMEPLAY screen variables here! + UnloadTexture(background); + + UnloadMonster(blazon01); + UnloadMonster(blazon02); + UnloadMonster(blazon03); +} + +// Gameplay Screen should finish? +int FinishArmoryScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/skully_escape/screens/screen_attic.c b/games/skully_escape/screens/screen_attic.c new file mode 100644 index 00000000..a8bc0a6b --- /dev/null +++ b/games/skully_escape/screens/screen_attic.c @@ -0,0 +1,332 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" +#include "../player.h" +#include "../monster.h" + +#include + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Gameplay screen global variables +static int framesCounter; +static int finishScreen; + +static Texture2D background; + +// Declare doors +static Door doorRight; + +// Decalre monsters +static Monster lamp; +static Monster arc; + +static bool monsterHover; +static int monsterCheck; // Identify checking monster + +static const char message[256] = "YOUR PARENTS ARE GONE! TIME TO ESCAPE!\nTHE DOOR IS LOCKED... TURN ON THE LIGHTS! ;)"; +static int msgPosX = 100; + +static int msgState = 0; // 0-writting, 1-wait, 2-choose +static int lettersCounter = 0; +static char msgBuffer[256] = { '\0' }; +static int msgCounter = 0; + +static bool searching = false; + +//---------------------------------------------------------------------------------- +// Gameplay Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Gameplay Screen Initialization logic +void InitAtticScreen(void) +{ + ResetPlayer(); + + // Reset Screen variables + monsterHover = false; + monsterCheck = -1; + msgState = 0; + msgCounter = 0; + lettersCounter = 0; + for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; + + framesCounter = 0; + finishScreen = 0; + + background = LoadTexture("resources/textures/background_attic.png"); + + // Initialize doors + doorRight.position = (Vector2) { 1074, 140 }; + doorRight.facing = 2; + doorRight.locked = true; + doorRight.frameRec =(Rectangle) {((doors.width/3)*doorRight.facing), doors.height/2, doors.width/3, doors.height/2}; + doorRight.bound = (Rectangle) { doorRight.position.x, doorRight.position.y, doors.width/3, doors.height/2}; + doorRight.selected = false; + + // Monster init: lamp + lamp.position = (Vector2){ 50, 316 }; + lamp.texture = LoadTexture("resources/textures/monster_lamp_left.png"); + lamp.currentFrame = 0; + lamp.framesCounter = 0; + lamp.numFrames = 4; + lamp.bounds = (Rectangle){ lamp.position.x + 20, lamp.position.y, 90, 380 }; + lamp.frameRec = (Rectangle) { 0, 0, lamp.texture.width/lamp.numFrames, lamp.texture.height }; + lamp.selected = false; + lamp.active = false; + lamp.spooky = false; + + // Monster init: arc + arc.position = (Vector2){ 760, 430 }; + arc.texture = LoadTexture("resources/textures/monster_arc.png"); + arc.currentFrame = 0; + arc.framesCounter = 0; + arc.numFrames = 4; + arc.bounds = (Rectangle){ arc.position.x + 44, arc.position.y + 70, 220, 120 }; + arc.frameRec = (Rectangle) { 0, 0, arc.texture.width/arc.numFrames, arc.texture.height }; + arc.selected = false; + arc.active = false; + arc.spooky = true; +} + +// Gameplay Screen Update logic +void UpdateAtticScreen(void) +{ + if (player.key) + { + // Door: right + if ((CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || + (CheckCollisionRecs(player.bounds, doorRight.bound))) doorRight.selected = true; + else doorRight.selected = false; + + if ((doorRight.selected) && (CheckCollisionRecs(player.bounds, doorRight.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorRight.locked) + { + doorRight.frameRec.y = 0; + doorRight.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 1; + } + } + } + + if (msgState > 2) + { + UpdatePlayer(); + + // Monsters logic + UpdateMonster(&lamp); + UpdateMonster(&arc); + } + + // Check player hover monsters to interact + if (((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active) || + ((CheckCollisionRecs(player.bounds, arc.bounds)) && !arc.active)) monsterHover = true; + else monsterHover = false; + + // Monters logic: lamp + if ((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active) + { + lamp.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), lamp.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 1; + } + } + else lamp.selected = false; + + // Monters logic: arc + if ((CheckCollisionRecs(player.bounds, arc.bounds)) && !arc.active) + { + arc.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), arc.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 2; + } + } + else arc.selected = false; + + if (searching) + { + framesCounter++; + + if (framesCounter > 180) + { + if (monsterCheck == 1) + { + if (lamp.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + lamp.active = true; + lamp.selected = false; + } + else if (monsterCheck == 2) + { + if (arc.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + arc.active = true; + arc.selected = false; + } + + searching = false; + framesCounter = 0; + } + } + + // Text animation + framesCounter++; + + if ((framesCounter%2) == 0) lettersCounter++; + + if (msgState == 0) + { + if (lettersCounter <= (int)strlen(message)) strncpy(msgBuffer, message, lettersCounter); + else + { + for (int i = 0; i < (int)strlen(msgBuffer); i++) msgBuffer[i] = '\0'; + + lettersCounter = 0; + msgState = 1; + } + + if (IsKeyPressed(KEY_ENTER)) msgState = 1; + } + else if (msgState == 1) + { + msgCounter++; + + if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) + { + msgState = 2; + msgCounter = 0; + } + } + else if (msgState == 2) + { + msgCounter++; + + if (msgCounter > 180) msgState = 3; + } + else msgCounter++; + + if (IsKeyPressed('M')) + { + finishScreen = 1; + } +} + +// Gameplay Screen Draw logic +void DrawAtticScreen(void) +{ + DrawTexture(background, 0, 0, WHITE); + + // Draw monsters + DrawMonster(lamp, 0); + DrawMonster(arc, 0); + + // Draw door + if (doorRight.selected) DrawTextureRec(doors, doorRight.frameRec, doorRight.position, GREEN); + else DrawTextureRec(doors, doorRight.frameRec, doorRight.position, WHITE); + + // Draw messsages + if (msgState < 2) DrawRectangle(0, 40, GetScreenWidth(), 200, Fade(LIGHTGRAY, 0.5f)); + else if (msgState == 2) DrawRectangle(0, 80, GetScreenWidth(), 100, Fade(LIGHTGRAY, 0.5f)); + + if (msgState == 0) + { + DrawTextEx(font, msgBuffer, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + } + else if (msgState == 1) + { + DrawTextEx(font, message, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + + if ((msgCounter/30)%2) DrawText("PRESS ENTER or CLICK", GetScreenWidth() - 280, 200, 20, BLACK); + } + else if (msgState == 2) + { + if ((msgCounter/30)%2) + { + DrawTextEx(font, "CHOOSE WISELY!", (Vector2){ 300, 95 }, font.size*2, 2, WHITE); + + DrawRectangleRec(lamp.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(arc.bounds, Fade(RED, 0.6f)); + } + } + else + { + if ((monsterHover) && ((msgCounter/30)%2)) + { + DrawRectangle(0, 0, GetScreenWidth(), 50, Fade(LIGHTGRAY, 0.5f)); + DrawText("PRESS SPACE or CLICK to INTERACT", 420, 15, 20, BLACK); + } + } + + DrawPlayer(); // NOTE: Also draws mouse pointer! +} + +// Gameplay Screen Unload logic +void UnloadAtticScreen(void) +{ + // TODO: Unload GAMEPLAY screen variables here! + UnloadTexture(background); + + UnloadMonster(lamp); + UnloadMonster(arc); +} + +// Gameplay Screen should finish? +int FinishAtticScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/skully_escape/screens/screen_bathroom.c b/games/skully_escape/screens/screen_bathroom.c new file mode 100644 index 00000000..176967a7 --- /dev/null +++ b/games/skully_escape/screens/screen_bathroom.c @@ -0,0 +1,383 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" +#include "../player.h" +#include "../monster.h" + +#include + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Gameplay screen global variables +static int framesCounter; +static int finishScreen; + +static Texture2D background; + +// Declare doors +static Door doorRight; + +// Decalre monst +static Monster lamp; +static Monster chair; +static Monster mirror; + +static bool monsterHover = false; +static int monsterCheck = -1; // Identify checking monster + +static const char message[256] = "TRICK OR TREAT! WHO IS THE MOST BEAUTIFUL\nSKELETON IN THE WORLD?"; +static int msgPosX = 100; + +static int msgState = 0; // 0-writting, 1-wait, 2-choose +static int lettersCounter = 0; +static char msgBuffer[256] = { '\0' }; +static int msgCounter = 0; + +static bool searching = false; + +//---------------------------------------------------------------------------------- +// Gameplay Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Gameplay Screen Initialization logic +void InitBathroomScreen(void) +{ + ResetPlayer(); + + // Reset Screen variables + monsterHover = false; + monsterCheck = -1; + msgState = 0; + msgCounter = 0; + lettersCounter = 0; + for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; + + framesCounter = 0; + finishScreen = 0; + + background = LoadTexture("resources/textures/background_bathroom.png"); + + // Reset Screen variables + monsterHover = false; + monsterCheck = -1; + msgState = 0; + msgCounter = 0; + lettersCounter = 0; + for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; + + // Initialize doors + doorRight.position = (Vector2) { 1070, 135 }; + doorRight.facing = 2; + doorRight.locked = true; + doorRight.frameRec =(Rectangle) {((doors.width/3)*doorRight.facing), doors.height/2, doors.width/3, doors.height/2}; + doorRight.bound = (Rectangle) { doorRight.position.x, doorRight.position.y, doors.width/3, doors.height/2}; + doorRight.selected = false; + + // Monster init: lamp + lamp.position = (Vector2){ 35, 334 }; + lamp.texture = LoadTexture("resources/textures/monster_lamp_left.png"); + lamp.currentFrame = 0; + lamp.framesCounter = 0; + lamp.numFrames = 4; + lamp.bounds = (Rectangle){ lamp.position.x + 20, lamp.position.y + 0, 90, 380}; + lamp.frameRec = (Rectangle) { 0, 0, lamp.texture.width/lamp.numFrames, lamp.texture.height }; + lamp.selected = false; + lamp.active = false; + lamp.spooky = true; + + // Monster init: mirror + mirror.position = (Vector2){ 300, 200 }; + mirror.texture = LoadTexture("resources/textures/monster_mirror.png"); + mirror.currentFrame = 0; + mirror.framesCounter = 0; + mirror.numFrames = 4; + mirror.bounds = (Rectangle){ mirror.position.x + 40, mirror.position.y + 20, 190, 200 }; + mirror.frameRec = (Rectangle) { 0, 0, mirror.texture.width/mirror.numFrames, mirror.texture.height }; + mirror.selected = false; + mirror.active = false; + mirror.spooky = false; + + // Monster init: chair + chair.position = (Vector2){ 760, 430 }; + chair.texture = LoadTexture("resources/textures/monster_chair_right.png"); + chair.currentFrame = 0; + chair.framesCounter = 0; + chair.numFrames = 4; + chair.bounds = (Rectangle){ chair.position.x + 30, chair.position.y + 30, 120, 190 }; + chair.frameRec = (Rectangle) { 0, 0, chair.texture.width/chair.numFrames, chair.texture.height }; + chair.selected = false; + chair.active = false; + chair.spooky = true; +} + +// Gameplay Screen Update logic +void UpdateBathroomScreen(void) +{ + if (player.key) + { + // Door: right + if ((CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || + (CheckCollisionRecs(player.bounds, doorRight.bound))) doorRight.selected = true; + else doorRight.selected = false; + + if ((doorRight.selected) && (CheckCollisionRecs(player.bounds, doorRight.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorRight.locked) + { + doorRight.frameRec.y = 0; + doorRight.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 1; + } + } + } + + if (msgState > 2) + { + UpdatePlayer(); + + // Monsters logic + UpdateMonster(&lamp); + UpdateMonster(&mirror); + UpdateMonster(&chair); + } + + // Check player hover monsters to interact + if (((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active) || + ((CheckCollisionRecs(player.bounds, mirror.bounds)) && !mirror.active) || + ((CheckCollisionRecs(player.bounds, chair.bounds)) && !chair.active)) monsterHover = true; + else monsterHover = false; + + + // Monters logic: lamp + if ((CheckCollisionRecs(player.bounds, lamp.bounds)) && !lamp.active) + { + lamp.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), lamp.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 1; + } + } + else lamp.selected = false; + + // Monters logic: mirror + if ((CheckCollisionRecs(player.bounds, mirror.bounds)) && !mirror.active) + { + mirror.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), mirror.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 2; + } + } + else mirror.selected = false; + + // Monters logic: chair + if ((CheckCollisionRecs(player.bounds, chair.bounds)) && !chair.active) + { + chair.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), chair.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 3; + } + } + else chair.selected = false; + + if (searching) + { + framesCounter++; + + if (framesCounter > 180) + { + if (monsterCheck == 1) + { + if (lamp.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + lamp.active = true; + lamp.selected = false; + } + else if (monsterCheck == 2) + { + if (mirror.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + mirror.active = true; + mirror.selected = false; + } + else if (monsterCheck == 3) + { + if (chair.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + chair.active = true; + chair.selected = false; + } + + searching = false; + framesCounter = 0; + } + } + + // Text animation + framesCounter++; + + if ((framesCounter%2) == 0) lettersCounter++; + + if (msgState == 0) + { + if (lettersCounter <= (int)strlen(message)) strncpy(msgBuffer, message, lettersCounter); + else + { + for (int i = 0; i < (int)strlen(msgBuffer); i++) msgBuffer[i] = '\0'; + + lettersCounter = 0; + msgState = 1; + } + + if (IsKeyPressed(KEY_ENTER)) msgState = 1; + } + else if (msgState == 1) + { + msgCounter++; + + if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) + { + msgState = 2; + msgCounter = 0; + } + } + else if (msgState == 2) + { + msgCounter++; + + if (msgCounter > 180) msgState = 3; + } + else msgCounter++; +} + +// Gameplay Screen Draw logic +void DrawBathroomScreen(void) +{ + DrawTexture(background, 0, 0, WHITE); + + // Draw monsters + DrawMonster(lamp, 0); + DrawMonster(mirror, 0); + DrawMonster(chair, 0); + + // Draw door + if (doorRight.selected) DrawTextureRec(doors, doorRight.frameRec, doorRight.position, GREEN); + else DrawTextureRec(doors, doorRight.frameRec, doorRight.position, WHITE); + + // Draw messsages + if (msgState < 2) DrawRectangle(0, 40, GetScreenWidth(), 200, Fade(LIGHTGRAY, 0.5f)); + else if (msgState == 2) DrawRectangle(0, 80, GetScreenWidth(), 100, Fade(LIGHTGRAY, 0.5f)); + + if (msgState == 0) + { + DrawTextEx(font, msgBuffer, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + } + else if (msgState == 1) + { + DrawTextEx(font, message, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + + if ((msgCounter/30)%2) DrawText("PRESS ENTER or CLICK", GetScreenWidth() - 280, 200, 20, BLACK); + } + else if (msgState == 2) + { + if ((msgCounter/30)%2) + { + DrawTextEx(font, "CHOOSE WISELY!", (Vector2){ 300, 95 }, font.size*2, 2, WHITE); + + DrawRectangleRec(lamp.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(mirror.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(chair.bounds, Fade(RED, 0.6f)); + } + } + else + { + if ((monsterHover) && ((msgCounter/30)%2)) + { + DrawRectangle(0, 0, GetScreenWidth(), 50, Fade(LIGHTGRAY, 0.5f)); + DrawText("PRESS SPACE or CLICK to INTERACT", 420, 15, 20, BLACK); + } + } + + DrawPlayer(); // NOTE: Also draws mouse pointer! +} + +// Gameplay Screen Unload logic +void UnloadBathroomScreen(void) +{ + // TODO: Unload GAMEPLAY screen variables here! + UnloadTexture(background); + + UnloadMonster(lamp); + UnloadMonster(chair); + UnloadMonster(mirror); +} + +// Gameplay Screen should finish? +int FinishBathroomScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/skully_escape/screens/screen_ending.c b/games/skully_escape/screens/screen_ending.c new file mode 100644 index 00000000..120d9071 --- /dev/null +++ b/games/skully_escape/screens/screen_ending.c @@ -0,0 +1,90 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Ending Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Ending screen global variables +static int framesCounter; +static int finishScreen; + +static float alpha = 0.0f; + +//---------------------------------------------------------------------------------- +// Ending Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Ending Screen Initialization logic +void InitEndingScreen(void) +{ + // TODO: Initialize ENDING screen variables here! + framesCounter = 0; + finishScreen = 0; + alpha = 0.0f; +} + +// Ending Screen Update logic +void UpdateEndingScreen(void) +{ + // TODO: Update ENDING screen variables here! + framesCounter++; + + alpha += 0.005f; + + if (alpha >= 1.0f) alpha = 1.0f; + + // Press enter to change to ATTIC screen + if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) + { + finishScreen = 1; + } +} + +// Ending Screen Draw logic +void DrawEndingScreen(void) +{ + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), DARKGRAY); + + DrawTextEx(font, "CONGRATULATIONS!", (Vector2){ 50, 160 }, font.size*3, 2, Fade(WHITE, alpha)); + DrawTextEx(font, "SKULLY ESCAPED!", (Vector2){ 100, 300 }, font.size*3, 2, Fade(WHITE, alpha)); + + if ((framesCounter > 180) && ((framesCounter/40)%2)) DrawText("PRESS ENTER or CLICK", 380, 545, 40, BLACK); +} + +// Ending Screen Unload logic +void UnloadEndingScreen(void) +{ + // TODO: Unload ENDING screen variables here! +} + +// Ending Screen should finish? +int FinishEndingScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/skully_escape/screens/screen_kitchen.c b/games/skully_escape/screens/screen_kitchen.c new file mode 100644 index 00000000..a6b8924d --- /dev/null +++ b/games/skully_escape/screens/screen_kitchen.c @@ -0,0 +1,403 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" +#include "../player.h" +#include "../monster.h" + +#include + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Gameplay screen global variables +static int framesCounter; +static int finishScreen; + +static Texture2D background; + +// Declare doors +static Door doorLeft; +static Door doorRight; + +// Decalre monsters +static Monster closet; +static Monster chair; +static Monster window; + +static bool monsterHover = false; +static int monsterCheck = -1; // Identify checking monster + +static const char message[256] = "QUITE BORING AROUND...\nANY BETTER ENTERTAINING?"; +static int msgPosX = 100; + +static int msgState = 0; // 0-writting, 1-wait, 2-choose +static int lettersCounter = 0; +static char msgBuffer[256] = { '\0' }; +static int msgCounter = 0; + +static bool searching = false; + +//---------------------------------------------------------------------------------- +// Gameplay Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Gameplay Screen Initialization logic +void InitKitchenScreen(void) +{ + ResetPlayer(); + + // Reset Screen variables + monsterHover = false; + monsterCheck = -1; + msgState = 0; + msgCounter = 0; + lettersCounter = 0; + for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; + + framesCounter = 0; + finishScreen = 0; + + background = LoadTexture("resources/textures/background_kitchen.png"); + + // Initialize doors + doorLeft.position = (Vector2) { -45, 136 }; + doorLeft.facing = 0; + doorLeft.locked = true; + doorLeft.frameRec =(Rectangle) {((doors.width/3)*doorLeft.facing), doors.height/2, doors.width/3, doors.height/2}; + doorLeft.bound = (Rectangle) { doorLeft.position.x, doorLeft.position.y, doors.width/3, doors.height/2}; + doorLeft.selected = false; + + doorRight.position = (Vector2) { 1090, 148 }; + doorRight.facing = 2; + doorRight.locked = true; + doorRight.frameRec =(Rectangle) {((doors.width/3)*doorRight.facing), doors.height/2, doors.width/3, doors.height/2}; + doorRight.bound = (Rectangle) { doorRight.position.x, doorRight.position.y, doors.width/3, doors.height/2}; + doorRight.selected = false; + + // Monster init: lamp + closet.position = (Vector2){ 280, 260 }; + closet.texture = LoadTexture("resources/textures/monster_closet.png"); + closet.currentFrame = 0; + closet.framesCounter = 0; + closet.numFrames = 4; + closet.bounds = (Rectangle){ closet.position.x + 100, closet.position.y+25, 272,348 }; + closet.frameRec = (Rectangle) { 0, 0, closet.texture.width/closet.numFrames, closet.texture.height }; + closet.selected = false; + closet.active = false; + closet.spooky = true; + + // Monster init: chair + chair.position = (Vector2){ 230, 410 }; + chair.texture = LoadTexture("resources/textures/monster_chair_left.png"); + chair.currentFrame = 0; + chair.framesCounter = 0; + chair.numFrames = 4; + chair.bounds = (Rectangle){ chair.position.x + 30, chair.position.y + 60, 100, 160 }; + chair.frameRec = (Rectangle) { 0, 0, chair.texture.width/chair.numFrames, chair.texture.height }; + chair.selected = false; + chair.active = false; + chair.spooky = true; + + // Monster init: window + window.position = (Vector2){ 715, 88 }; + window.texture = LoadTexture("resources/textures/monster_window.png"); + window.currentFrame = 0; + window.framesCounter = 0; + window.numFrames = 4; + window.bounds = (Rectangle){ window.position.x + 100, window.position.y + 10, 200, 370 }; + window.frameRec = (Rectangle) { 0, 0, window.texture.width/window.numFrames, window.texture.height }; + window.selected = false; + window.active = false; + window.spooky = false; +} + +// Gameplay Screen Update logic +void UpdateKitchenScreen(void) +{ + if (player.key) + { + // Door: left + if ((CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || + (CheckCollisionRecs(player.bounds, doorLeft.bound))) doorLeft.selected = true; + else doorLeft.selected = false; + + if ((doorLeft.selected) && (CheckCollisionRecs(player.bounds, doorLeft.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorLeft.locked) + { + doorLeft.frameRec.y = 0; + doorLeft.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 1; + } + } + + // Door: right + if ((CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || + (CheckCollisionRecs(player.bounds, doorRight.bound))) doorRight.selected = true; + else doorRight.selected = false; + + if ((doorRight.selected) && (CheckCollisionRecs(player.bounds, doorRight.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorRight.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorRight.locked) + { + doorRight.frameRec.y = 0; + doorRight.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 2; + } + } + } + + if (msgState > 2) + { + UpdatePlayer(); + + // Monsters logic + UpdateMonster(&closet); + UpdateMonster(&chair); + UpdateMonster(&window); + } + + // Check player hover monsters to interact + if (((CheckCollisionRecs(player.bounds, closet.bounds)) && !closet.active) || + ((CheckCollisionRecs(player.bounds, window.bounds)) && !window.active)) monsterHover = true; + else monsterHover = false; + + // Monters logic: closet + if ((CheckCollisionRecs(player.bounds, closet.bounds)) && !closet.active) + { + closet.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), closet.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 1; + } + } + else closet.selected = false; + + // Monters logic: chair + if ((CheckCollisionRecs(player.bounds, chair.bounds)) && !chair.active) + { + chair.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), chair.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 2; + } + } + else chair.selected = false; + + // Monters logic: window + if ((CheckCollisionRecs(player.bounds, window.bounds)) && !window.active) + { + window.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), window.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 3; + } + } + else window.selected = false; + + if (searching) + { + framesCounter++; + + if (framesCounter > 180) + { + if (monsterCheck == 1) + { + if (closet.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + closet.active = true; + closet.selected = false; + } + else if (monsterCheck == 2) + { + if (chair.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + chair.active = true; + chair.selected = false; + } + else if (monsterCheck == 3) + { + if (window.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + window.active = true; + window.selected = false; + } + + searching = false; + framesCounter = 0; + } + } + + // Text animation + framesCounter++; + + if ((framesCounter%2) == 0) lettersCounter++; + + if (msgState == 0) + { + if (lettersCounter <= (int)strlen(message)) strncpy(msgBuffer, message, lettersCounter); + else + { + for (int i = 0; i < (int)strlen(msgBuffer); i++) msgBuffer[i] = '\0'; + + lettersCounter = 0; + msgState = 1; + } + + if (IsKeyPressed(KEY_ENTER)) msgState = 1; + } + else if (msgState == 1) + { + msgCounter++; + + if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) + { + msgState = 2; + msgCounter = 0; + } + } + else if (msgState == 2) + { + msgCounter++; + + if (msgCounter > 180) msgState = 3; + } + else msgCounter++; +} + +// Gameplay Screen Draw logic +void DrawKitchenScreen(void) +{ + DrawTexture(background, 0, 0, WHITE); + + // Draw monsters + DrawMonster(closet, 0); + DrawMonster(chair, 0); + DrawMonster(window, 0); + + // Draw door + if (doorRight.selected) DrawTextureRec(doors, doorRight.frameRec, doorRight.position, GREEN); + else DrawTextureRec(doors, doorRight.frameRec, doorRight.position, WHITE); + + if (doorLeft.selected) DrawTextureRec(doors, doorLeft.frameRec, doorLeft.position, GREEN); + else DrawTextureRec(doors, doorLeft.frameRec, doorLeft.position, WHITE); + + // Draw messsages + if (msgState < 2) DrawRectangle(0, 40, GetScreenWidth(), 200, Fade(LIGHTGRAY, 0.5f)); + else if (msgState == 2) DrawRectangle(0, 80, GetScreenWidth(), 100, Fade(LIGHTGRAY, 0.5f)); + + if (msgState == 0) + { + DrawTextEx(font, msgBuffer, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + } + else if (msgState == 1) + { + DrawTextEx(font, message, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + + if ((msgCounter/30)%2) DrawText("PRESS ENTER or CLICK", GetScreenWidth() - 280, 200, 20, BLACK); + } + else if (msgState == 2) + { + if ((msgCounter/30)%2) + { + DrawTextEx(font, "CHOOSE WISELY!", (Vector2){ 300, 95 }, font.size*2, 2, WHITE); + + DrawRectangleRec(closet.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(window.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(chair.bounds, Fade(RED, 0.6f)); + } + } + else + { + if ((monsterHover) && ((msgCounter/30)%2)) + { + DrawRectangle(0, 0, GetScreenWidth(), 50, Fade(LIGHTGRAY, 0.5f)); + DrawText("PRESS SPACE or CLICK to INTERACT", 420, 15, 20, BLACK); + } + } + + DrawPlayer(); // NOTE: Also draws mouse pointer! +} + +// Gameplay Screen Unload logic +void UnloadKitchenScreen(void) +{ + // TODO: Unload GAMEPLAY screen variables here! + UnloadTexture(background); + + UnloadMonster(closet); + UnloadMonster(chair); + UnloadMonster(window); +} + +// Gameplay Screen should finish? +int FinishKitchenScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/skully_escape/screens/screen_livingroom.c b/games/skully_escape/screens/screen_livingroom.c new file mode 100644 index 00000000..b2b09d9a --- /dev/null +++ b/games/skully_escape/screens/screen_livingroom.c @@ -0,0 +1,403 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Gameplay Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" +#include "../player.h" +#include "../monster.h" + +#include + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Gameplay screen global variables +static int framesCounter; +static int finishScreen; + +static Texture2D background; + +// Declare doors +static Door doorCenter; +static Door doorLeft; + +// Decalre monsters +static Monster candle; +static Monster picture; +static Monster phone; + +static bool monsterHover = false; +static int monsterCheck = -1; // Identify checking monster + +static const char message[256] = "WHEN WIND BLOWS, IT KNOWS THE DIRECTION\nLET IT GUIDE YOU!"; +static int msgPosX = 100; + +static int msgState = 0; // 0-writting, 1-wait, 2-choose +static int lettersCounter = 0; +static char msgBuffer[256] = { '\0' }; +static int msgCounter = 0; + +static bool searching = false; + +//---------------------------------------------------------------------------------- +// Gameplay Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Gameplay Screen Initialization logic +void InitLivingroomScreen(void) +{ + ResetPlayer(); + + // Reset Screen variables + monsterHover = false; + monsterCheck = -1; + msgState = 0; + msgCounter = 0; + lettersCounter = 0; + for (int i = 0; i < 256; i++) msgBuffer[i] = '\0'; + + framesCounter = 0; + finishScreen = 0; + + background = LoadTexture("resources/textures/background_livingroom.png"); + + // Initialize doors + doorLeft.position = (Vector2) { -45, 140}; + doorLeft.facing = 0; + doorLeft.locked = true; + doorLeft.frameRec =(Rectangle) {((doors.width/3)*doorLeft.facing), doors.height/2, doors.width/3, doors.height/2}; + doorLeft.bound = (Rectangle) { doorLeft.position.x, doorLeft.position.y, doors.width/3, doors.height/2}; + doorLeft.selected = false; + + doorCenter.position = (Vector2) { 830, 108 }; + doorCenter.facing = 1; + doorCenter.locked = true; + doorCenter.frameRec =(Rectangle) {((doors.width/3)*doorCenter.facing), doors.height/2, doors.width/3, doors.height/2}; + doorCenter.bound = (Rectangle) { doorCenter.position.x, doorCenter.position.y, doors.width/3, doors.height/2}; + doorCenter.selected = false; + + // Monster init: lamp + candle.position = (Vector2){ 154, 256 }; + candle.texture = LoadTexture("resources/textures/monster_candle.png"); + candle.currentFrame = 0; + candle.framesCounter = 0; + candle.numFrames = 4; + candle.bounds = (Rectangle){ candle.position.x + 90, candle.position.y + 30, 185, 340 }; + candle.frameRec = (Rectangle) { 0, 0, candle.texture.width/candle.numFrames, candle.texture.height }; + candle.selected = false; + candle.active = false; + candle.spooky = false; + + // Monster init: arc + picture.position = (Vector2){ 504, 164 }; + picture.texture = LoadTexture("resources/textures/monster_picture.png"); + picture.currentFrame = 0; + picture.framesCounter = 0; + picture.numFrames = 4; + picture.bounds = (Rectangle){ picture.position.x + 44, picture.position.y, 174, 264 }; + picture.frameRec = (Rectangle) { 0, 0, picture.texture.width/picture.numFrames, picture.texture.height }; + picture.selected = false; + picture.active = false; + picture.spooky = true; + + // Monster init: phone + phone.position = (Vector2){ 1054, 404 }; + phone.texture = LoadTexture("resources/textures/monster_phone.png"); + phone.currentFrame = 0; + phone.framesCounter = 0; + phone.numFrames = 4; + phone.bounds = (Rectangle){ phone.position.x + 64, phone.position.y +120, 100, 160 }; + phone.frameRec = (Rectangle) { 0, 0, phone.texture.width/phone.numFrames, phone.texture.height }; + phone.selected = false; + phone.active = false; + phone.spooky = true; +} + +// Gameplay Screen Update logic +void UpdateLivingroomScreen(void) +{ + if (player.key) + { + // Door: left + if ((CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || + (CheckCollisionRecs(player.bounds, doorLeft.bound))) doorLeft.selected = true; + else doorLeft.selected = false; + + if ((doorLeft.selected) && (CheckCollisionRecs(player.bounds, doorLeft.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorLeft.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorLeft.locked) + { + doorLeft.frameRec.y = 0; + doorLeft.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 1; + } + } + + // Door: center + if ((CheckCollisionPointRec(GetMousePosition(), doorCenter.bound)) || + (CheckCollisionRecs(player.bounds, doorCenter.bound))) doorCenter.selected = true; + else doorCenter.selected = false; + + if ((doorCenter.selected) && (CheckCollisionRecs(player.bounds, doorCenter.bound))) + { + if (((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && CheckCollisionPointRec(GetMousePosition(), doorCenter.bound)) || (IsKeyPressed(KEY_SPACE))) + { + if (doorCenter.locked) + { + doorCenter.frameRec.y = 0; + doorCenter.locked = false; + PlaySound(sndDoor); + } + else finishScreen = 2; + } + } + } + + if (msgState > 2) + { + UpdatePlayer(); + + // Monsters logic + UpdateMonster(&candle); + UpdateMonster(&picture); + UpdateMonster(&phone); + } + + // Check player hover monsters to interact + if (((CheckCollisionRecs(player.bounds, candle.bounds)) && !candle.active) || + ((CheckCollisionRecs(player.bounds, picture.bounds)) && !picture.active) || + ((CheckCollisionRecs(player.bounds, phone.bounds)) && !phone.active)) monsterHover = true; + else monsterHover = false; + + // Monters logic: candle + if ((CheckCollisionRecs(player.bounds, candle.bounds)) && !candle.active) + { + candle.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), candle.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 1; + } + } + else candle.selected = false; + + // Monters logic: picture + if ((CheckCollisionRecs(player.bounds, picture.bounds)) && !picture.active) + { + picture.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), picture.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 2; + } + } + else picture.selected = false; + + // Monters logic: phone + if ((CheckCollisionRecs(player.bounds, phone.bounds)) && !phone.active) + { + phone.selected = true; + + if ((IsKeyPressed(KEY_SPACE)) || + ((IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) && (CheckCollisionPointRec(GetMousePosition(), phone.bounds)))) + { + SearchKeyPlayer(); + searching = true; + framesCounter = 0; + + monsterCheck = 3; + } + } + else phone.selected = false; + + if (searching) + { + framesCounter++; + + if (framesCounter > 180) + { + if (monsterCheck == 1) + { + if (candle.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + candle.active = true; + candle.selected = false; + } + else if (monsterCheck == 2) + { + if (picture.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + picture.active = true; + picture.selected = false; + } + else if (monsterCheck == 3) + { + if (phone.spooky) + { + ScarePlayer(); + PlaySound(sndScream); + } + else FindKeyPlayer(); + + phone.active = true; + phone.selected = false; + } + + searching = false; + framesCounter = 0; + } + } + + // Text animation + framesCounter++; + + if ((framesCounter%2) == 0) lettersCounter++; + + if (msgState == 0) + { + if (lettersCounter <= (int)strlen(message)) strncpy(msgBuffer, message, lettersCounter); + else + { + for (int i = 0; i < (int)strlen(msgBuffer); i++) msgBuffer[i] = '\0'; + + lettersCounter = 0; + msgState = 1; + } + + if (IsKeyPressed(KEY_ENTER)) msgState = 1; + } + else if (msgState == 1) + { + msgCounter++; + + if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) + { + msgState = 2; + msgCounter = 0; + } + } + else if (msgState == 2) + { + msgCounter++; + + if (msgCounter > 180) msgState = 3; + } + else msgCounter++; +} + +// Gameplay Screen Draw logic +void DrawLivingroomScreen(void) +{ + DrawTexture(background, 0, 0, WHITE); + + // Draw monsters + DrawMonster(picture, 0); + DrawMonster(candle, 0); + DrawMonster(phone, 0); + + // Draw door + if (doorCenter.selected) DrawTextureRec(doors, doorCenter.frameRec, doorCenter.position, GREEN); + else DrawTextureRec(doors, doorCenter.frameRec, doorCenter.position, WHITE); + if (doorLeft.selected) DrawTextureRec(doors, doorLeft.frameRec, doorLeft.position, GREEN); + else DrawTextureRec(doors, doorLeft.frameRec, doorLeft.position, WHITE); + + // Draw messsages + if (msgState < 2) DrawRectangle(0, 40, GetScreenWidth(), 200, Fade(LIGHTGRAY, 0.5f)); + else if (msgState == 2) DrawRectangle(0, 80, GetScreenWidth(), 100, Fade(LIGHTGRAY, 0.5f)); + + if (msgState == 0) + { + DrawTextEx(font, msgBuffer, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + } + else if (msgState == 1) + { + DrawTextEx(font, message, (Vector2){ msgPosX, 80 }, font.size, 2, WHITE); + + if ((msgCounter/30)%2) DrawText("PRESS ENTER or CLICK", GetScreenWidth() - 280, 200, 20, BLACK); + } + else if (msgState == 2) + { + if ((msgCounter/30)%2) + { + DrawTextEx(font, "CHOOSE WISELY!", (Vector2){ 300, 95 }, font.size*2, 2, WHITE); + + DrawRectangleRec(candle.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(phone.bounds, Fade(RED, 0.6f)); + DrawRectangleRec(picture.bounds, Fade(RED, 0.6f)); + } + } + else + { + if ((monsterHover) && ((msgCounter/30)%2)) + { + DrawRectangle(0, 0, GetScreenWidth(), 50, Fade(LIGHTGRAY, 0.5f)); + DrawText("PRESS SPACE or CLICK to INTERACT", 420, 15, 20, BLACK); + } + } + + DrawPlayer(); // NOTE: Also draws mouse pointer! +} + +// Gameplay Screen Unload logic +void UnloadLivingroomScreen(void) +{ + // TODO: Unload GAMEPLAY screen variables here! + UnloadTexture(background); + + UnloadMonster(candle); + UnloadMonster(picture); + UnloadMonster(phone); +} + +// Gameplay Screen should finish? +int FinishLivingroomScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/skully_escape/screens/screen_logo.c b/games/skully_escape/screens/screen_logo.c new file mode 100644 index 00000000..f07f5f54 --- /dev/null +++ b/games/skully_escape/screens/screen_logo.c @@ -0,0 +1,108 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Logo Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Logo screen global variables +static int framesCounter = 0; +static int finishScreen; + +static Texture2D logo; +static float logoAlpha = 0; + +static int state = 0; + +//---------------------------------------------------------------------------------- +// Logo Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Logo Screen Initialization logic +void InitLogoScreen(void) +{ + // Initialize LOGO screen variables here! + finishScreen = 0; + + logo = LoadTexture("resources/textures/skully_logo.png"); +} + +// Logo Screen Update logic +void UpdateLogoScreen(void) +{ + // Update LOGO screen variables here! + if (state == 0) + { + logoAlpha += 0.04f; + + if (logoAlpha >= 1.0f) state = 1; + } + else if (state == 1) + { + framesCounter++; + + if (framesCounter > 180) state = 2; + } + else if (state == 2) + { + logoAlpha -= 0.04f; + + if (logoAlpha <= 0.0f) + { + framesCounter = 0; + state = 3; + } + } + else if (state == 3) + { + finishScreen = 1; + } +} + +// Logo Screen Draw logic +void DrawLogoScreen(void) +{ + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), RAYWHITE); + + DrawTexture(logo, GetScreenWidth()/2 - logo.width/2, 130, Fade(WHITE, logoAlpha)); + + DrawText("GRAY TEAM", 340, 450, 100, Fade(DARKGRAY, logoAlpha)); +} + +// Logo Screen Unload logic +void UnloadLogoScreen(void) +{ + // Unload LOGO screen variables here! + UnloadTexture(logo); +} + +// Logo Screen should finish? +int FinishLogoScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/skully_escape/screens/screen_logo_raylib.c b/games/skully_escape/screens/screen_logo_raylib.c new file mode 100644 index 00000000..e5efe843 --- /dev/null +++ b/games/skully_escape/screens/screen_logo_raylib.c @@ -0,0 +1,201 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Logo Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +#define LOGO_RECS_SIDE 16 + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Logo screen global variables +static int framesCounter = 0; +static int finishScreen; + +static int logoPositionX; +static int logoPositionY; + +static int lettersCount = 0; + +static int topSideRecWidth = LOGO_RECS_SIDE; +static int leftSideRecHeight = LOGO_RECS_SIDE; + +static int bottomSideRecWidth = LOGO_RECS_SIDE; +static int rightSideRecHeight = LOGO_RECS_SIDE; + +static char raylib[8]; // 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 Initialization logic +void rlInitLogoScreen(void) +{ + // TODO: Initialize LOGO screen variables here! + finishScreen = 0; + + logoPositionX = GetScreenWidth()/2 - 128; + logoPositionY = GetScreenHeight()/2 - 128; + + for (int i = 0; i < 8; i++) raylib[i] = '\0'; +} + +// Logo Screen Update logic +void rlUpdateLogoScreen(void) +{ + // Update LOGO screen variables here! + if (state == 0) // State 0: Small box blinking + { + 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 rlDrawLogoScreen(void) +{ + 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 rlUnloadLogoScreen(void) +{ + // TODO: Unload LOGO screen variables here! +} + +// Logo Screen should finish? +int rlFinishLogoScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/skully_escape/screens/screen_title.c b/games/skully_escape/screens/screen_title.c new file mode 100644 index 00000000..837b5112 --- /dev/null +++ b/games/skully_escape/screens/screen_title.c @@ -0,0 +1,92 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Title Screen Functions Definitions (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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" + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- + +// Title screen global variables +static int framesCounter; +static int finishScreen; + +static Texture2D title; +static float titleAlpha = 0.0f; + +//---------------------------------------------------------------------------------- +// Title Screen Functions Definition +//---------------------------------------------------------------------------------- + +// Title Screen Initialization logic +void InitTitleScreen(void) +{ + // Initialize TITLE screen variables here! + framesCounter = 0; + finishScreen = 0; + + title = LoadTexture("resources/textures/title.png"); +} + +// Title Screen Update logic +void UpdateTitleScreen(void) +{ + // Update TITLE screen variables here! + framesCounter++; + + titleAlpha += 0.005f; + + if (titleAlpha >= 1.0f) titleAlpha = 1.0f; + + // Press enter to change to ATTIC screen + if ((IsKeyPressed(KEY_ENTER)) || (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))) + { + finishScreen = 1; + } +} + +// Title Screen Draw logic +void DrawTitleScreen(void) +{ + //DrawText("TITLE SCREEN", 100, 100, 140, Fade(BLACK, titleAlpha)); + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), DARKGRAY); + DrawTexture(title, GetScreenWidth()/2 - title.width/2, 20, Fade(WHITE, titleAlpha)); + + if ((framesCounter > 180) && ((framesCounter/40)%2)) DrawText("PRESS ENTER to START", 380, 545, 40, BLACK); +} + +// Title Screen Unload logic +void UnloadTitleScreen(void) +{ + // Unload TITLE screen variables here! + UnloadTexture(title); +} + +// Title Screen should finish? +int FinishTitleScreen(void) +{ + return finishScreen; +} \ No newline at end of file diff --git a/games/skully_escape/screens/screens.h b/games/skully_escape/screens/screens.h new file mode 100644 index 00000000..790df9ff --- /dev/null +++ b/games/skully_escape/screens/screens.h @@ -0,0 +1,164 @@ +/********************************************************************************************** +* +* raylib - Advance Game template +* +* Screens Functions Declarations (Init, Update, Draw, Unload) +* +* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +* 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 + +#define PLAYER_ANIM_FRAMES 7 +#define PLAYER_ANIM_SEQ 2 + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +typedef enum GameScreen { LOGO = 0, LOGO_RL, TITLE, ATTIC, AISLE01, AISLE02, BATHROOM, LIVINGROOM, KITCHEN, ARMORY, ENDING } GameScreen; + +typedef struct Door { + Vector2 position; + int facing; + bool locked; + bool selected; + Rectangle frameRec; + Rectangle bound; +} Door; + +//---------------------------------------------------------------------------------- +// Global Variables Definition +//---------------------------------------------------------------------------------- +GameScreen currentScreen; +SpriteFont font; + +Texture2D doors; +Sound sndDoor; +Sound sndScream; + + +#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); + +//---------------------------------------------------------------------------------- +// raylib Logo Screen Functions Declaration +//---------------------------------------------------------------------------------- +void rlInitLogoScreen(void); +void rlUpdateLogoScreen(void); +void rlDrawLogoScreen(void); +void rlUnloadLogoScreen(void); +int rlFinishLogoScreen(void); + +//---------------------------------------------------------------------------------- +// Title Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitTitleScreen(void); +void UpdateTitleScreen(void); +void DrawTitleScreen(void); +void UnloadTitleScreen(void); +int FinishTitleScreen(void); + +//---------------------------------------------------------------------------------- +// Attic Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitAtticScreen(void); +void UpdateAtticScreen(void); +void DrawAtticScreen(void); +void UnloadAtticScreen(void); +int FinishAtticScreen(void); + +//---------------------------------------------------------------------------------- +// Aisle01 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitAisle01Screen(void); +void UpdateAisle01Screen(void); +void DrawAisle01Screen(void); +void UnloadAisle01Screen(void); +int FinishAisle01Screen(void); + +//---------------------------------------------------------------------------------- +// Aisle02 Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitAisle02Screen(void); +void UpdateAisle02Screen(void); +void DrawAisle02Screen(void); +void UnloadAisle02Screen(void); +int FinishAisle02Screen(void); + +//---------------------------------------------------------------------------------- +// Bathroom Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitBathroomScreen(void); +void UpdateBathroomScreen(void); +void DrawBathroomScreen(void); +void UnloadBathroomScreen(void); +int FinishBathroomScreen(void); + +//---------------------------------------------------------------------------------- +// Livingroom Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitLivingroomScreen(void); +void UpdateLivingroomScreen(void); +void DrawLivingroomScreen(void); +void UnloadLivingroomScreen(void); +int FinishLivingroomScreen(void); + +//---------------------------------------------------------------------------------- +// Kitchen Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitKitchenScreen(void); +void UpdateKitchenScreen(void); +void DrawKitchenScreen(void); +void UnloadKitchenScreen(void); +int FinishKitchenScreen(void); + +//---------------------------------------------------------------------------------- +// Armory Screen Functions Declaration +//---------------------------------------------------------------------------------- +void InitArmoryScreen(void); +void UpdateArmoryScreen(void); +void DrawArmoryScreen(void); +void UnloadArmoryScreen(void); +int FinishArmoryScreen(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 \ No newline at end of file diff --git a/games/skully_escape/skully_escape.c b/games/skully_escape/skully_escape.c new file mode 100644 index 00000000..22cc04e4 --- /dev/null +++ b/games/skully_escape/skully_escape.c @@ -0,0 +1,403 @@ +/******************************************************************************************* +* +* SKULLY ESCAPE [KING GAME JAM 2015] +* +* 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) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* +********************************************************************************************/ + +#include "raylib.h" +#include "screens/screens.h" // NOTE: Defines global variable: currentScreen + +#include "player.h" + +#if defined(PLATFORM_WEB) + #include +#endif + +//---------------------------------------------------------------------------------- +// Global Variables Definition (local to this module) +//---------------------------------------------------------------------------------- +const int screenWidth = 1280; +const int screenHeight = 720; + +// Required variables to manage screen transitions (fade-in, fade-out) +float transAlpha = 0; +bool onTransition = false; +bool transFadeOut = false; +int transFromScreen = -1; +int transToScreen = -1; + +static int framesCounter = 0; + +//---------------------------------------------------------------------------------- +// Local Functions Declaration +//---------------------------------------------------------------------------------- +void TransitionToScreen(int screen); +void ChangeToScreen(int screen); // No transition effect +void UpdateTransition(void); +void DrawTransition(void); + +void UpdateDrawFrame(void); // Update and Draw one frame + +//---------------------------------------------------------------------------------- +// Main entry point +//---------------------------------------------------------------------------------- +int main(void) +{ + // Initialization + //--------------------------------------------------------- + const char windowTitle[30] = "SKULLY ESCAPE [KING GAMEJAM]"; + + InitWindow(screenWidth, screenHeight, windowTitle); + + // Global data loading (assets that must be available in all screens, i.e. fonts) + InitAudioDevice(); + + PlayMusicStream("resources/audio/come_play_with_me.ogg"); + + font = LoadSpriteFont("resources/textures/alagard.png"); + doors = LoadTexture("resources/textures/doors.png"); + sndDoor = LoadSound("resources/audio/door.ogg"); + sndScream = LoadSound("resources/audio/scream.ogg"); + + InitPlayer(); + + // Setup and Init first screen + currentScreen = LOGO; + InitLogoScreen(); + +#if defined(PLATFORM_WEB) + emscripten_set_main_loop(UpdateDrawFrame, 0, 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 all global loaded data (i.e. fonts) here! + UnloadPlayer(); + UnloadSpriteFont(font); + UnloadTexture(doors); + UnloadSound(sndDoor); + UnloadSound(sndScream); + + CloseAudioDevice(); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +void TransitionToScreen(int screen) +{ + onTransition = true; + transFromScreen = currentScreen; + transToScreen = screen; +} + +void ChangeToScreen(int screen) +{ + switch (currentScreen) + { + case LOGO: UnloadLogoScreen(); break; + case LOGO_RL: rlUnloadLogoScreen(); break; + case TITLE: UnloadTitleScreen(); break; + case ATTIC: UnloadAtticScreen(); break; + case AISLE01: UnloadAisle01Screen();break; + case AISLE02: UnloadAisle02Screen();break; + case ARMORY: UnloadArmoryScreen();break; + case LIVINGROOM: UnloadLivingroomScreen();break; + case KITCHEN: UnloadKitchenScreen(); break; + case BATHROOM: UnloadBathroomScreen(); break; + case ENDING: UnloadEndingScreen(); break; + default: break; + } + + switch (screen) + { + case LOGO: InitLogoScreen(); break; + case LOGO_RL: rlInitLogoScreen(); break; + case TITLE: InitTitleScreen(); break; + case ATTIC: InitAtticScreen(); break; + case AISLE01: InitAisle01Screen();break; + case AISLE02: InitAisle02Screen();break; + case ARMORY: InitArmoryScreen();break; + case LIVINGROOM: InitLivingroomScreen();break; + case KITCHEN: InitKitchenScreen(); break; + case BATHROOM: InitBathroomScreen(); break; + case ENDING: InitEndingScreen(); break; + default: break; + } + + currentScreen = screen; +} + +void UpdateTransition(void) +{ + if (!transFadeOut) + { + transAlpha += 0.05f; + + if (transAlpha >= 1.0) + { + transAlpha = 1.0; + + switch (transFromScreen) + { + case LOGO: UnloadLogoScreen(); break; + case LOGO_RL: rlUnloadLogoScreen(); break; + case TITLE: UnloadTitleScreen(); break; + case ATTIC: UnloadAtticScreen(); break; + case AISLE01: UnloadAisle01Screen();break; + case AISLE02: UnloadAisle02Screen();break; + case ARMORY: UnloadArmoryScreen();break; + case LIVINGROOM: UnloadLivingroomScreen();break; + case KITCHEN: UnloadKitchenScreen(); break; + case BATHROOM: UnloadBathroomScreen(); break; + case ENDING: UnloadEndingScreen(); break; + default: break; + } + + switch (transToScreen) + { + case LOGO: + { + InitLogoScreen(); + currentScreen = LOGO; + } break; + case LOGO_RL: + { + rlInitLogoScreen(); + currentScreen = LOGO_RL; + } break; + case TITLE: + { + InitTitleScreen(); + currentScreen = TITLE; + } break; + case ATTIC: + { + InitAtticScreen(); + currentScreen = ATTIC; + } break; + case AISLE01: + { + InitAisle01Screen(); + currentScreen = AISLE01; + } break; + case AISLE02: + { + InitAisle02Screen(); + currentScreen = AISLE02; + } break; + case BATHROOM: + { + InitBathroomScreen(); + currentScreen = BATHROOM; + } break; + case LIVINGROOM: + { + InitLivingroomScreen(); + currentScreen = LIVINGROOM; + } break; + case KITCHEN: + { + InitKitchenScreen(); + currentScreen = KITCHEN; + } break; + case ARMORY: + { + InitArmoryScreen(); + currentScreen = ARMORY; + } break; + case ENDING: + { + InitEndingScreen(); + currentScreen = ENDING; + } break; + default: break; + } + + transFadeOut = true; + } + } + else // Transition fade out logic + { + transAlpha -= 0.05f; + + if (transAlpha <= 0) + { + transAlpha = 0; + transFadeOut = false; + onTransition = false; + transFromScreen = -1; + transToScreen = -1; + } + } +} + +void DrawTransition(void) +{ + DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(BLACK, transAlpha)); +} + +// Update and draw game frame +void UpdateDrawFrame(void) +{ + // Update + //---------------------------------------------------------------------------------- + if (!onTransition) + { + if (player.dead) + { + framesCounter++; + + if (framesCounter > 80) + { + framesCounter = 0; + player.dead = false; + player.numLifes = 4; + + TransitionToScreen(TITLE); + } + } + + switch(currentScreen) + { + case LOGO: + { + UpdateLogoScreen(); + + if (FinishLogoScreen()) ChangeToScreen(LOGO_RL); + + } break; + case LOGO_RL: + { + rlUpdateLogoScreen(); + + if (rlFinishLogoScreen()) TransitionToScreen(TITLE); + + } break; + case TITLE: + { + UpdateTitleScreen(); + + if (FinishTitleScreen() == 1) TransitionToScreen(ATTIC); + + } break; + case ATTIC: + { + UpdateAtticScreen(); + + if (FinishAtticScreen() == 1) TransitionToScreen(AISLE01); + + } break; + case AISLE01: + { + UpdateAisle01Screen(); + + if (FinishAisle01Screen() == 1) TransitionToScreen(BATHROOM); + else if(FinishAisle01Screen() == 2) TransitionToScreen(KITCHEN); + else if(FinishAisle01Screen() == 3) TransitionToScreen(LIVINGROOM); + + } break; + case BATHROOM: + { + UpdateBathroomScreen(); + + if (FinishBathroomScreen() == 1) TransitionToScreen(AISLE01); + + } break; + case LIVINGROOM: + { + UpdateLivingroomScreen(); + + if (FinishLivingroomScreen() == 1) TransitionToScreen(AISLE01); + else if(FinishLivingroomScreen() == 2)TransitionToScreen(AISLE02); + + } break; + case AISLE02: + { + UpdateAisle02Screen(); + + if (FinishAisle02Screen() == 1) TransitionToScreen(KITCHEN); + + } break; + case KITCHEN: + { + UpdateKitchenScreen(); + + if (FinishKitchenScreen() == 1) TransitionToScreen(ARMORY); + else if(FinishKitchenScreen() == 2)TransitionToScreen(AISLE02); + + } break; + case ARMORY: + { + UpdateArmoryScreen(); + + if(FinishArmoryScreen() == 1) TransitionToScreen(ENDING); + else if(FinishArmoryScreen() == 2) TransitionToScreen(KITCHEN); + + } break; + case ENDING: + { + UpdateEndingScreen(); + + if (FinishEndingScreen()) TransitionToScreen(TITLE); + + } break; + default: break; + } + } + else + { + // Update transition (fade-in, fade-out) + UpdateTransition(); + } + + UpdateMusicStream(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + switch(currentScreen) + { + case LOGO: DrawLogoScreen(); break; + case LOGO_RL: rlDrawLogoScreen(); break; + case TITLE: DrawTitleScreen(); break; + case ATTIC: DrawAtticScreen(); break; + case AISLE01: DrawAisle01Screen();break; + case AISLE02: DrawAisle02Screen();break; + case BATHROOM: DrawBathroomScreen();break; + case LIVINGROOM: DrawLivingroomScreen();break; + case KITCHEN: DrawKitchenScreen();break; + case ARMORY: DrawArmoryScreen();break; + case ENDING: DrawEndingScreen(); break; + default: break; + } + + if (onTransition) DrawTransition(); + + //DrawFPS(10, 10); + + EndDrawing(); + //---------------------------------------------------------------------------------- +} + -- cgit v1.2.3 From 4ad375a3783472b8629387d45fb90619115c973a Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sun, 7 Feb 2016 11:23:12 +0100 Subject: Code review Most of this code was developed by students, it requires some additional review to be used for teaching. --- games/samples/asteroids.c | 125 ++++---- games/samples/asteroids_survival.c | 72 ++--- games/samples/floppy.c | 12 +- games/samples/gold_fever.c | 69 ++-- games/samples/pang.c | 630 +++++++++++++++++-------------------- games/samples/space_invaders.c | 19 +- games/samples/tetris.c | 23 +- 7 files changed, 427 insertions(+), 523 deletions(-) (limited to 'games') diff --git a/games/samples/asteroids.c b/games/samples/asteroids.c index 676b0154..53ebbd8e 100644 --- a/games/samples/asteroids.c +++ b/games/samples/asteroids.c @@ -22,13 +22,14 @@ //---------------------------------------------------------------------------------- // Some Defines //---------------------------------------------------------------------------------- -#define MAX_SPEED 6 +#define PLAYER_BASE_SIZE 20.0f +#define PLAYER_SPEED 6.0f +#define PLAYER_MAX_SHOOTS 10 + #define METEORS_SPEED 2 -#define NUM_SHOOTS 10 -#define NUM_BIG_METEORS 4 -#define NUM_MEDIUM_METEORS 8 -#define NUM_SMALL_METEORS 16 -#define SHIP_BASE_SIZE 20.0f +#define MAX_BIG_METEORS 4 +#define MAX_MEDIUM_METEORS 8 +#define MAX_SMALL_METEORS 16 //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -53,29 +54,13 @@ typedef struct Shoot { Color color; } Shoot; -typedef struct BigMeteor { - Vector2 position; - Vector2 speed; - float radius; - bool active; - Color color; -} BigMeteor; - -typedef struct MediumMeteor { +typedef struct Meteor { Vector2 position; Vector2 speed; float radius; bool active; Color color; -} MediumMeteor; - -typedef struct SmallMeteor { - Vector2 position; - Vector2 speed; - float radius; - bool active; - Color color; -} SmallMeteor; +} Meteor; //------------------------------------------------------------------------------------ // Global Variables Declaration @@ -92,10 +77,10 @@ static bool victory; static float shipHeight; static Player player; -static Shoot shoot[NUM_SHOOTS]; -static BigMeteor bigMeteor[NUM_BIG_METEORS]; -static MediumMeteor mediumMeteor[NUM_MEDIUM_METEORS]; -static SmallMeteor smallMeteor[NUM_SMALL_METEORS]; +static Shoot shoot[PLAYER_MAX_SHOOTS]; +static Meteor bigMeteor[MAX_BIG_METEORS]; +static Meteor mediumMeteor[MAX_MEDIUM_METEORS]; +static Meteor smallMeteor[MAX_SMALL_METEORS]; static int countMediumMeteors; static int countSmallMeteors; @@ -169,7 +154,7 @@ void InitGame(void) victory = false; pause = false; - shipHeight = (SHIP_BASE_SIZE/2)/tanf(20*DEG2RAD); + shipHeight = (PLAYER_BASE_SIZE/2)/tanf(20*DEG2RAD); // Initialization player player.position = (Vector2){screenWidth/2, screenHeight/2 - shipHeight/2}; @@ -181,10 +166,8 @@ void InitGame(void) meteorsDestroyed = 0; - //InitShoot(&shoot); - // Initialization shoot - for (int i = 0; i < NUM_SHOOTS; i++) + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) { shoot[i].position = (Vector2){0, 0}; shoot[i].speed = (Vector2){0, 0}; @@ -194,7 +177,7 @@ void InitGame(void) shoot[i].color = WHITE; } - for (int i = 0; i < NUM_BIG_METEORS; i++) + for (int i = 0; i < MAX_BIG_METEORS; i++) { posx = GetRandomValue(0, screenWidth); @@ -236,7 +219,7 @@ void InitGame(void) bigMeteor[i].color = BLUE; } - for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + for (int i = 0; i < MAX_MEDIUM_METEORS; i++) { mediumMeteor[i].position = (Vector2){-100, -100}; mediumMeteor[i].speed = (Vector2){0,0}; @@ -245,7 +228,7 @@ void InitGame(void) mediumMeteor[i].color = BLUE; } - for (int i = 0; i < NUM_SMALL_METEORS; i++) + for (int i = 0; i < MAX_SMALL_METEORS; i++) { smallMeteor[i].position = (Vector2){-100, -100}; smallMeteor[i].speed = (Vector2){0,0}; @@ -274,8 +257,8 @@ void UpdateGame(void) if (IsKeyDown(KEY_RIGHT)) player.rotation += 5; // Speed - player.speed.x = sin(player.rotation*DEG2RAD)*MAX_SPEED; - player.speed.y = cos(player.rotation*DEG2RAD)*MAX_SPEED; + player.speed.x = sin(player.rotation*DEG2RAD)*PLAYER_SPEED; + player.speed.y = cos(player.rotation*DEG2RAD)*PLAYER_SPEED; // Controller if (IsKeyDown(KEY_UP)) @@ -306,14 +289,14 @@ void UpdateGame(void) // Activation of shoot if (IsKeyPressed(KEY_SPACE)) { - for (int i = 0; i < NUM_SHOOTS; i++) + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) { if (!shoot[i].active) { shoot[i].position = (Vector2){ player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight) }; shoot[i].active = true; - shoot[i].speed.x = 1.5*sin(player.rotation*DEG2RAD)*MAX_SPEED; - shoot[i].speed.y = 1.5*cos(player.rotation*DEG2RAD)*MAX_SPEED; + shoot[i].speed.x = 1.5*sin(player.rotation*DEG2RAD)*PLAYER_SPEED; + shoot[i].speed.y = 1.5*cos(player.rotation*DEG2RAD)*PLAYER_SPEED; shoot[i].rotation = player.rotation; break; } @@ -321,13 +304,13 @@ void UpdateGame(void) } // Shoot life timer - for (int i = 0; i < NUM_SHOOTS; i++) + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) { if (shoot[i].active) shoot[i].lifeSpawn++; } // Shot logic - for (int i = 0; i < NUM_SHOOTS; i++) + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) { if (shoot[i].active) { @@ -371,23 +354,23 @@ void UpdateGame(void) // Collision Player to meteors player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12}; - for (int a = 0; a < NUM_BIG_METEORS; a++) + for (int a = 0; a < MAX_BIG_METEORS; a++) { if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, bigMeteor[a].position, bigMeteor[a].radius) && bigMeteor[a].active) gameOver = true; } - for (int a = 0; a < NUM_MEDIUM_METEORS; a++) + for (int a = 0; a < MAX_MEDIUM_METEORS; a++) { if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, mediumMeteor[a].position, mediumMeteor[a].radius) && mediumMeteor[a].active) gameOver = true; } - for (int a = 0; a < NUM_SMALL_METEORS; a++) + for (int a = 0; a < MAX_SMALL_METEORS; a++) { if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, smallMeteor[a].position, smallMeteor[a].radius) && smallMeteor[a].active) gameOver = true; } // Meteor logic - for (int i = 0; i < NUM_BIG_METEORS; i++) + for (int i = 0; i < MAX_BIG_METEORS; i++) { if (bigMeteor[i].active) { @@ -403,7 +386,7 @@ void UpdateGame(void) } } - for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + for (int i = 0; i < MAX_MEDIUM_METEORS; i++) { if (mediumMeteor[i].active) { @@ -419,7 +402,7 @@ void UpdateGame(void) } } - for (int i = 0; i < NUM_SMALL_METEORS; i++) + for (int i = 0; i < MAX_SMALL_METEORS; i++) { if (smallMeteor[i].active) { @@ -436,11 +419,11 @@ void UpdateGame(void) } // Collision behaviour - for (int i = 0; i < NUM_SHOOTS; i++) + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) { if ((shoot[i].active)) { - for (int a = 0; a < NUM_BIG_METEORS; a++) + for (int a = 0; a < MAX_BIG_METEORS; a++) { if (bigMeteor[a].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, bigMeteor[a].position, bigMeteor[a].radius)) { @@ -466,13 +449,13 @@ void UpdateGame(void) } //bigMeteor[a].position = (Vector2){-100, -100}; bigMeteor[a].color = RED; - a = NUM_BIG_METEORS; + a = MAX_BIG_METEORS; } } } if ((shoot[i].active)) { - for (int b = 0; b < NUM_MEDIUM_METEORS; b++) + for (int b = 0; b < MAX_MEDIUM_METEORS; b++) { if (mediumMeteor[b].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, mediumMeteor[b].position, mediumMeteor[b].radius)) { @@ -498,13 +481,13 @@ void UpdateGame(void) } //mediumMeteor[b].position = (Vector2){-100, -100}; mediumMeteor[b].color = GREEN; - b = NUM_MEDIUM_METEORS; + b = MAX_MEDIUM_METEORS; } } } if ((shoot[i].active)) { - for (int c = 0; c < NUM_SMALL_METEORS; c++) + for (int c = 0; c < MAX_SMALL_METEORS; c++) { if (smallMeteor[c].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, smallMeteor[c].position, smallMeteor[c].radius)) { @@ -514,14 +497,14 @@ void UpdateGame(void) meteorsDestroyed++; smallMeteor[c].color = YELLOW; // smallMeteor[c].position = (Vector2){-100, -100}; - c = NUM_SMALL_METEORS; + c = MAX_SMALL_METEORS; } } } } } - if (meteorsDestroyed == NUM_BIG_METEORS + NUM_MEDIUM_METEORS + NUM_SMALL_METEORS) victory = true; + if (meteorsDestroyed == MAX_BIG_METEORS + MAX_MEDIUM_METEORS + MAX_SMALL_METEORS) victory = true; } else { @@ -538,39 +521,39 @@ void DrawGame(void) { BeginDrawing(); - ClearBackground(DARKGRAY); + ClearBackground(RAYWHITE); if (!gameOver) { // Draw spaceship Vector2 v1 = { player.position.x + sinf(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cosf(player.rotation*DEG2RAD)*(shipHeight) }; - Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; - Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; - DrawTriangleLines(v1, v2, v3, player.color); + Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) }; + Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) }; + DrawTriangle(v1, v2, v3, MAROON); // Draw meteors - for (int i = 0; i < NUM_BIG_METEORS; i++) + for (int i = 0; i < MAX_BIG_METEORS; i++) { - if (bigMeteor[i].active) DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, bigMeteor[i].color); - else DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, Fade(bigMeteor[i].color, 0.25f)); + if (bigMeteor[i].active) DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, DARKGRAY); + else DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, Fade(LIGHTGRAY, 0.3f)); } - for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + for (int i = 0; i < MAX_MEDIUM_METEORS; i++) { - if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, mediumMeteor[i].color); - else DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(mediumMeteor[i].color, 0.25f)); + if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, GRAY); + else DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(LIGHTGRAY, 0.3f)); } - for (int i = 0; i < NUM_SMALL_METEORS; i++) + for (int i = 0; i < MAX_SMALL_METEORS; i++) { - if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, smallMeteor[i].color); - else DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(smallMeteor[i].color, 0.25f)); + if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, GRAY); + else DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(LIGHTGRAY, 0.3f)); } // Draw shoot - for (int i = 0; i < NUM_SHOOTS; i++) + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) { - if (shoot[i].active) DrawCircleV(shoot[i].position, shoot[i].radius, shoot[i].color); + if (shoot[i].active) DrawCircleV(shoot[i].position, shoot[i].radius, BLACK); } if (victory) DrawText("VICTORY", screenWidth/2 - MeasureText("VICTORY", 20)/2, screenHeight/2, 20, LIGHTGRAY); diff --git a/games/samples/asteroids_survival.c b/games/samples/asteroids_survival.c index e2be9366..aa21112d 100644 --- a/games/samples/asteroids_survival.c +++ b/games/samples/asteroids_survival.c @@ -22,13 +22,13 @@ //---------------------------------------------------------------------------------- // Some Defines //---------------------------------------------------------------------------------- -#define MAX_SPEED 6 +#define PLAYER_BASE_SIZE 20.0f +#define PLAYER_SPEED 6.0f +#define PLAYER_MAX_SHOOTS 10 + #define METEORS_SPEED 2 -#define NUM_SHOOTS 10 -#define NUM_BIG_METEORS 4 -#define NUM_MEDIUM_METEORS 8 -#define NUM_SMALL_METEORS 16 -#define SHIP_BASE_SIZE 20.0f +#define MAX_MEDIUM_METEORS 8 +#define MAX_SMALL_METEORS 16 //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -43,22 +43,13 @@ typedef struct Player { Color color; } Player; -typedef struct MediumMeteor { - Vector2 position; - Vector2 speed; - float radius; - bool active; - Color color; -} MediumMeteor; - -typedef struct SmallMeteor { +typedef struct Meteor { Vector2 position; Vector2 speed; float radius; bool active; Color color; -} SmallMeteor; - +} Meteor; //------------------------------------------------------------------------------------ // Global Variables Declaration @@ -74,8 +65,8 @@ static bool pause; static float shipHeight; static Player player; -static MediumMeteor mediumMeteor[NUM_MEDIUM_METEORS]; -static SmallMeteor smallMeteor[NUM_SMALL_METEORS]; +static Meteor mediumMeteor[MAX_MEDIUM_METEORS]; +static Meteor smallMeteor[MAX_SMALL_METEORS]; //------------------------------------------------------------------------------------ // Module Functions Declaration (local) @@ -86,8 +77,6 @@ static void DrawGame(void); // Draw game (one frame) static void UnloadGame(void); // Unload game static void UpdateDrawFrame(void); // Update and Draw (one frame) -static void DrawSpaceship(Vector2 position, float rotation, Color color); - //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ @@ -146,7 +135,7 @@ void InitGame(void) framesCounter = 0; - shipHeight = (SHIP_BASE_SIZE/2)/tanf(20*DEG2RAD); + shipHeight = (PLAYER_BASE_SIZE/2)/tanf(20*DEG2RAD); // Initialization player player.position = (Vector2){screenWidth/2, screenHeight/2 - shipHeight/2}; @@ -156,7 +145,7 @@ void InitGame(void) player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12}; player.color = LIGHTGRAY; - for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + for (int i = 0; i < MAX_MEDIUM_METEORS; i++) { posx = GetRandomValue(0, screenWidth); @@ -196,7 +185,7 @@ void InitGame(void) mediumMeteor[i].color = GREEN; } - for (int i = 0; i < NUM_SMALL_METEORS; i++) + for (int i = 0; i < MAX_SMALL_METEORS; i++) { posx = GetRandomValue(0, screenWidth); @@ -255,8 +244,8 @@ void UpdateGame(void) if (IsKeyDown(KEY_RIGHT)) player.rotation += 5; // Speed - player.speed.x = sin(player.rotation*DEG2RAD)*MAX_SPEED; - player.speed.y = cos(player.rotation*DEG2RAD)*MAX_SPEED; + player.speed.x = sin(player.rotation*DEG2RAD)*PLAYER_SPEED; + player.speed.y = cos(player.rotation*DEG2RAD)*PLAYER_SPEED; // Controller if (IsKeyDown(KEY_UP)) @@ -287,19 +276,19 @@ void UpdateGame(void) // Collision Player to meteors player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12}; - for (int a = 0; a < NUM_MEDIUM_METEORS; a++) + for (int a = 0; a < MAX_MEDIUM_METEORS; a++) { if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, mediumMeteor[a].position, mediumMeteor[a].radius) && mediumMeteor[a].active) gameOver = true; } - for (int a = 0; a < NUM_SMALL_METEORS; a++) + for (int a = 0; a < MAX_SMALL_METEORS; a++) { if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, smallMeteor[a].position, smallMeteor[a].radius) && smallMeteor[a].active) gameOver = true; } // Meteor logic - for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + for (int i = 0; i < MAX_MEDIUM_METEORS; i++) { if (mediumMeteor[i].active) { @@ -315,7 +304,7 @@ void UpdateGame(void) } } - for (int i = 0; i < NUM_SMALL_METEORS; i++) + for (int i = 0; i < MAX_SMALL_METEORS; i++) { if (smallMeteor[i].active) { @@ -347,31 +336,30 @@ void DrawGame(void) { BeginDrawing(); - ClearBackground(DARKGRAY); + ClearBackground(RAYWHITE); if (!gameOver) { // Draw spaceship Vector2 v1 = { player.position.x + sinf(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cosf(player.rotation*DEG2RAD)*(shipHeight) }; - Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; - Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; - - DrawTriangleLines(v1, v2, v3, player.color); + Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) }; + Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) }; + DrawTriangle(v1, v2, v3, MAROON); // Draw meteor - for (int i = 0;i < NUM_MEDIUM_METEORS; i++) + for (int i = 0;i < MAX_MEDIUM_METEORS; i++) { - if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, mediumMeteor[i].color); - else DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(mediumMeteor[i].color, 0.25f)); + if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, GRAY); + else DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(LIGHTGRAY, 0.3f)); } - for (int i = 0;i < NUM_SMALL_METEORS; i++) + for (int i = 0;i < MAX_SMALL_METEORS; i++) { - if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, smallMeteor[i].color); - else DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(smallMeteor[i].color, 0.25f)); + if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, DARKGRAY); + else DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(LIGHTGRAY, 0.3f)); } - DrawText(FormatText("SURVIVAL TIME: %.02f", (float)framesCounter/60), 10, 10, 20, WHITE); + DrawText(FormatText("TIME: %.02f", (float)framesCounter/60), 10, 10, 20, BLACK); if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); } diff --git a/games/samples/floppy.c b/games/samples/floppy.c index d66f5bbe..f48ea235 100644 --- a/games/samples/floppy.c +++ b/games/samples/floppy.c @@ -206,24 +206,24 @@ void DrawGame(void) if (!gameOver) { - DrawCircle(floppy.position.x, floppy.position.y, floppy.radius, BLUE); + DrawCircle(floppy.position.x, floppy.position.y, floppy.radius, DARKGRAY); // Draw tubes for (int i = 0; i < MAX_TUBES; i++) { - DrawRectangle(tubes[i*2].rec.x, tubes[i*2].rec.y, tubes[i*2].rec.width, tubes[i*2].rec.height, RED); - DrawRectangle(tubes[i*2 + 1].rec.x, tubes[i*2 + 1].rec.y, tubes[i*2 + 1].rec.width, tubes[i*2 + 1].rec.height, RED); + DrawRectangle(tubes[i*2].rec.x, tubes[i*2].rec.y, tubes[i*2].rec.width, tubes[i*2].rec.height, GRAY); + DrawRectangle(tubes[i*2 + 1].rec.x, tubes[i*2 + 1].rec.y, tubes[i*2 + 1].rec.width, tubes[i*2 + 1].rec.height, GRAY); } // Draw flashing fx (one frame only) if (superfx) { - DrawRectangle(0, 0, screenWidth, screenHeight, GOLD); + DrawRectangle(0, 0, screenWidth, screenHeight, WHITE); superfx = false; } - DrawText(FormatText("%04i", score), 20, 20, 40, PINK); - DrawText(FormatText("HI-SCORE: %04i", hiScore), 20, 70, 20, VIOLET); + DrawText(FormatText("%04i", score), 20, 20, 40, GRAY); + DrawText(FormatText("HI-SCORE: %04i", hiScore), 20, 70, 20, LIGHTGRAY); if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); } diff --git a/games/samples/gold_fever.c b/games/samples/gold_fever.c index d4c0d99f..5a435027 100644 --- a/games/samples/gold_fever.c +++ b/games/samples/gold_fever.c @@ -22,19 +22,16 @@ //---------------------------------------------------------------------------------- typedef struct Player { Vector2 position; - int radius; Vector2 speed; - Color color; + int radius; } Player; typedef struct Enemy { Vector2 position; + Vector2 speed; int radius; int radiusBounds; - Vector2 speed; - bool moveRight; - Color colorBounds; - Color color; + bool moveRight; // RAY: o__O } Enemy; typedef struct Points { @@ -42,15 +39,14 @@ typedef struct Points { int radius; int value; bool active; - Color color; } Points; -typedef struct Exit { +typedef struct Home { Rectangle rec; bool active; bool save; Color color; -} Exit; +} Home; //------------------------------------------------------------------------------------ // Global Variables Declaration @@ -67,7 +63,7 @@ static int hiScore = 0; static Player player; static Enemy enemy; static Points points; -static Exit exit; +static Home home; static bool follow; //------------------------------------------------------------------------------------ @@ -136,30 +132,25 @@ void InitGame(void) player.position = (Vector2){50, 50}; player.radius = 20; player.speed = (Vector2){5, 5}; - player.color = DARKGRAY; enemy.position = (Vector2){screenWidth - 50, screenHeight/2}; enemy.radius = 20; enemy.radiusBounds = 150; enemy.speed = (Vector2){3, 3}; enemy.moveRight = true; - enemy.color = MAROON; - enemy.colorBounds = RED; follow = false; points.radius = 10; points.position = (Vector2){GetRandomValue(points.radius, screenWidth - points.radius), GetRandomValue(points.radius, screenHeight - points.radius)}; points.value = 100; points.active = true; - points.color = GOLD; - - exit.rec.width = 50; - exit.rec.height = 50; - exit.rec.x = GetRandomValue(0, screenWidth - exit.rec.width); - exit.rec.y = GetRandomValue(0, screenHeight - exit.rec.height); - exit.active = false; - exit.save = false; - exit.color = PINK; + + home.rec.width = 50; + home.rec.height = 50; + home.rec.x = GetRandomValue(0, screenWidth - home.rec.width); + home.rec.y = GetRandomValue(0, screenHeight - home.rec.height); + home.active = false; + home.save = false; } // Update game (one frame) @@ -184,7 +175,7 @@ void UpdateGame(void) if (player.position.y + player.radius >= screenHeight) player.position.y = screenHeight - player.radius; //IA Enemy - if ( (follow || CheckCollisionCircles(player.position, player.radius, enemy.position, enemy.radiusBounds)) && !exit.save) + if ( (follow || CheckCollisionCircles(player.position, player.radius, enemy.position, enemy.radiusBounds)) && !home.save) { if (player.position.x > enemy.position.x) enemy.position.x += enemy.speed.x; if (player.position.x < enemy.position.x) enemy.position.x -= enemy.speed.x; @@ -212,17 +203,17 @@ void UpdateGame(void) { follow = true; points.active = false; - exit.active = true; + home.active = true; } - if (CheckCollisionCircles(player.position, player.radius, enemy.position, enemy.radius) && !exit.save) + if (CheckCollisionCircles(player.position, player.radius, enemy.position, enemy.radius) && !home.save) { gameOver = true; if (hiScore < score) hiScore = score; } - if (CheckCollisionCircleRec(player.position, player.radius, exit.rec)) + if (CheckCollisionCircleRec(player.position, player.radius, home.rec)) { follow = false; @@ -235,9 +226,9 @@ void UpdateGame(void) points.position = (Vector2){GetRandomValue(points.radius, screenWidth - points.radius), GetRandomValue(points.radius, screenHeight - points.radius)}; } - exit.save = true; + home.save = true; } - else exit.save = false; + else home.save = false; } } else @@ -259,18 +250,22 @@ void DrawGame(void) if (!gameOver) { - if (follow) ClearBackground(RED); - - DrawCircleLines(enemy.position.x, enemy.position.y, enemy.radiusBounds, enemy.colorBounds); - DrawCircleV(enemy.position, enemy.radius, enemy.color); + if (follow) + { + DrawRectangle(0, 0, screenWidth, screenHeight, RED); + DrawRectangle(10, 10, screenWidth - 20, screenHeight - 20, RAYWHITE); + } - DrawCircleV(player.position, player.radius, player.color); - DrawCircleV(points.position, points.radius, points.color); + DrawRectangleLines(home.rec.x, home.rec.y, home.rec.width, home.rec.height, BLUE); + + DrawCircleLines(enemy.position.x, enemy.position.y, enemy.radiusBounds, RED); + DrawCircleV(enemy.position, enemy.radius, MAROON); - if (exit.active) DrawRectangleRec(exit.rec, exit.color); + DrawCircleV(player.position, player.radius, GRAY); + if (points.active) DrawCircleV(points.position, points.radius, GOLD); - DrawText(FormatText("SCORE: %04i", score), 10, 10, 20, GRAY); - DrawText(FormatText("HI-SCORE: %04i", hiScore), 300, 10, 20, GRAY); + DrawText(FormatText("SCORE: %04i", score), 20, 15, 20, GRAY); + DrawText(FormatText("HI-SCORE: %04i", hiScore), 300, 15, 20, GRAY); if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); } diff --git a/games/samples/pang.c b/games/samples/pang.c index e7b2bb86..fe1c3005 100644 --- a/games/samples/pang.c +++ b/games/samples/pang.c @@ -2,7 +2,7 @@ * * raylib - sample game: pang * -* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria +* Sample game developed by Ian Eito and Albert Martos and Ramon Santamaria * * This game has been created using raylib v1.3 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) @@ -22,13 +22,12 @@ //---------------------------------------------------------------------------------- // Some Defines //---------------------------------------------------------------------------------- -#define MAX_SPEED 5 -#define METEORS_SPEED 2 -#define NUM_SHOOTS 1 -#define NUM_BIG_METEORS 2 -#define NUM_MEDIUM_METEORS 4 -#define NUM_SMALL_METEORS 8 -#define SHIP_BASE_SIZE 20.0f +#define PLAYER_BASE_SIZE 20.0f +#define PLAYER_SPEED 5.0f +#define PLAYER_MAX_SHOOTS 1 + +#define MAX_BIG_BALLS 2 +#define BALLS_SPEED 2.0f //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -37,9 +36,8 @@ typedef struct Player { Vector2 position; Vector2 speed; - float rotation; Vector3 collider; - Color color; + float rotation; } Player; typedef struct Shoot { @@ -49,41 +47,19 @@ typedef struct Shoot { float rotation; int lifeSpawn; bool active; - Color color; } Shoot; -typedef struct BigMeteor { - Vector2 position; - Vector2 speed; - float radius; - int points; - bool active; - Color color; -} BigMeteor; - -typedef struct MediumMeteor { +typedef struct Ball { Vector2 position; Vector2 speed; float radius; int points; bool active; - Color color; -} MediumMeteor; - -typedef struct SmallMeteor { - Vector2 position; - Vector2 speed; - float radius; - int points; - bool active; - Color color; -} SmallMeteor; +} Ball; typedef struct Points { - char letter; Vector2 position; int value; - Color color; float alpha; } Points; @@ -99,18 +75,18 @@ static bool pause; static int score; static Player player; -static Shoot shoot[NUM_SHOOTS]; -static BigMeteor bigMeteor[NUM_BIG_METEORS]; -static MediumMeteor mediumMeteor[NUM_MEDIUM_METEORS]; -static SmallMeteor smallMeteor[NUM_SMALL_METEORS]; +static Shoot shoot[PLAYER_MAX_SHOOTS]; +static Ball bigBalls[MAX_BIG_BALLS]; +static Ball mediumBalls[MAX_BIG_BALLS*2]; +static Ball smallBalls[MAX_BIG_BALLS*4]; static Points points[5]; // NOTE: Defined triangle is isosceles with common angles of 70 degrees. static float shipHeight; static float gravity; -static int countMediumMeteors; -static int countSmallMeteors; +static int countmediumBallss; +static int countsmallBallss; static int meteorsDestroyed; static Vector2 linePosition; @@ -127,9 +103,6 @@ static void DrawGame(void); // Draw game (one frame) static void UnloadGame(void); // Unload game static void UpdateDrawFrame(void); // Update and Draw (one frame) -static void InitShoot(Shoot shoot); -static void DrawSpaceship(Vector2 position, float rotation, Color color); - //------------------------------------------------------------------------------------ // Program main entry point //------------------------------------------------------------------------------------ @@ -193,69 +166,64 @@ static void InitGame(void) gravity = 0.25f; linePosition = (Vector2){ 0.0f , 0.0f }; - shipHeight = (SHIP_BASE_SIZE/2)/tanf(20*DEG2RAD); + shipHeight = (PLAYER_BASE_SIZE/2)/tanf(20*DEG2RAD); // Initialization player player.position = (Vector2){ screenWidth/2, screenHeight }; - player.speed = (Vector2){ MAX_SPEED, MAX_SPEED }; + player.speed = (Vector2){ PLAYER_SPEED, PLAYER_SPEED }; player.rotation = 0; player.collider = (Vector3){ player.position.x, player.position.y - shipHeight/2.0f, 12.0f }; - player.color = LIGHTGRAY; meteorsDestroyed = 0; // Initialize shoots - for (int i = 0; i < NUM_SHOOTS; i++) + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) { shoot[i].position = (Vector2){ 0, 0 }; shoot[i].speed = (Vector2){ 0, 0 }; shoot[i].radius = 2; shoot[i].active = false; shoot[i].lifeSpawn = 0; - shoot[i].color = WHITE; } // Initialize big meteors - for (int i = 0; i < NUM_BIG_METEORS; i++) + for (int i = 0; i < MAX_BIG_BALLS; i++) { - bigMeteor[i].radius = 40.0f; - posx = GetRandomValue(0 + bigMeteor[i].radius, screenWidth - bigMeteor[i].radius); - posy = GetRandomValue(0 + bigMeteor[i].radius, screenHeight/2); + bigBalls[i].radius = 40.0f; + posx = GetRandomValue(0 + bigBalls[i].radius, screenWidth - bigBalls[i].radius); + posy = GetRandomValue(0 + bigBalls[i].radius, screenHeight/2); - bigMeteor[i].position = (Vector2){ posx, posy }; + bigBalls[i].position = (Vector2){ posx, posy }; while ((velx == 0) || (vely == 0)) { - velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); - vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED); + velx = GetRandomValue(-BALLS_SPEED, BALLS_SPEED); + vely = GetRandomValue(-BALLS_SPEED, BALLS_SPEED); } - bigMeteor[i].speed = (Vector2){ velx, vely }; - bigMeteor[i].points = 200; - bigMeteor[i].active = true; - bigMeteor[i].color = BLUE; + bigBalls[i].speed = (Vector2){ velx, vely }; + bigBalls[i].points = 200; + bigBalls[i].active = true; } // Initialize medium meteors - for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + for (int i = 0; i < MAX_BIG_BALLS*2; i++) { - mediumMeteor[i].position = (Vector2){-100, -100}; - mediumMeteor[i].speed = (Vector2){0,0}; - mediumMeteor[i].radius = 20.0f; - mediumMeteor[i].points = 100; - mediumMeteor[i].active = false; - mediumMeteor[i].color = BLUE; + mediumBalls[i].position = (Vector2){-100, -100}; + mediumBalls[i].speed = (Vector2){0,0}; + mediumBalls[i].radius = 20.0f; + mediumBalls[i].points = 100; + mediumBalls[i].active = false; } // Initialize small meteors - for (int i = 0; i < NUM_SMALL_METEORS; i++) + for (int i = 0; i < MAX_BIG_BALLS*4; i++) { - smallMeteor[i].position = (Vector2){ -100, -100 }; - smallMeteor[i].speed = (Vector2){ 0, 0 }; - smallMeteor[i].radius = 10.0f; - smallMeteor[i].points = 50; - smallMeteor[i].active = false; - smallMeteor[i].color = BLUE; + smallBalls[i].position = (Vector2){ -100, -100 }; + smallBalls[i].speed = (Vector2){ 0, 0 }; + smallBalls[i].radius = 10.0f; + smallBalls[i].points = 50; + smallBalls[i].active = false; } // Initialize animated points @@ -266,333 +234,297 @@ static void InitGame(void) points[i].alpha = 0.0f; } - countMediumMeteors = 0; - countSmallMeteors = 0; + countmediumBallss = 0; + countsmallBallss = 0; } // Update game (one frame) void UpdateGame(void) { - if (!gameOver) + if (!gameOver && !victory) { if (IsKeyPressed('P')) pause = !pause; if (!pause) { - if (awake) - { - // Player logic - if (IsKeyDown(KEY_LEFT)) player.position.x -= player.speed.x; - if (IsKeyDown(KEY_RIGHT)) player.position.x += player.speed.x; + // Player logic + if (IsKeyDown(KEY_LEFT)) player.position.x -= player.speed.x; + if (IsKeyDown(KEY_RIGHT)) player.position.x += player.speed.x; - // Wall behaviour for player - if (player.position.x + SHIP_BASE_SIZE/2 > screenWidth) player.position.x = screenWidth - SHIP_BASE_SIZE/2; - else if (player.position.x - SHIP_BASE_SIZE/2 < 0) player.position.x = 0 + SHIP_BASE_SIZE/2; + // Player vs wall collision logic + if (player.position.x + PLAYER_BASE_SIZE/2 > screenWidth) player.position.x = screenWidth - PLAYER_BASE_SIZE/2; + else if (player.position.x - PLAYER_BASE_SIZE/2 < 0) player.position.x = 0 + PLAYER_BASE_SIZE/2; - // Activation of shoot - if (IsKeyPressed(KEY_SPACE)) + // Player shot logic + if (IsKeyPressed(KEY_SPACE)) + { + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) { - for (int i = 0; i < NUM_SHOOTS; i++) + if (!shoot[i].active) { - if (!shoot[i].active) - { - shoot[i].position = (Vector2){ player.position.x, player.position.y - shipHeight }; - linePosition = (Vector2){ player.position.x, player.position.y}; - shoot[i].active = true; - shoot[i].speed.y = MAX_SPEED; - break; - } + shoot[i].position = (Vector2){ player.position.x, player.position.y - shipHeight }; + shoot[i].speed.y = PLAYER_SPEED; + shoot[i].active = true; + + linePosition = (Vector2){ player.position.x, player.position.y}; + + break; } } + } - // Shoot life timer - for (int i = 0; i < NUM_SHOOTS; i++) - { - if (shoot[i].active) shoot[i].lifeSpawn++; - } + // Shoot life timer + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) + { + if (shoot[i].active) shoot[i].lifeSpawn++; + } - // Shot logic - for (int i = 0; i < NUM_SHOOTS; i++) + // Shot logic + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) + { + if (shoot[i].active) { - if (shoot[i].active) - { - // Movement - shoot[i].position.y -= shoot[i].speed.y; + shoot[i].position.y -= shoot[i].speed.y; - // Wall behaviour for shoot - if (shoot[i].position.x > screenWidth + shoot[i].radius) - { - shoot[i].active = false; - shoot[i].lifeSpawn = 0; - } - else if (shoot[i].position.x < 0 - shoot[i].radius) - { - shoot[i].active = false; - shoot[i].lifeSpawn = 0; - } - - if (shoot[i].position.y > screenHeight + shoot[i].radius) - { - shoot[i].active = false; - shoot[i].lifeSpawn = 0; - } - else if (shoot[i].position.y < 0 - shoot[i].radius) - { - shoot[i].active = false; - shoot[i].lifeSpawn = 0; - } + // Shot vs walls collision logic + if ((shoot[i].position.x > screenWidth + shoot[i].radius) || (shoot[i].position.x < 0 - shoot[i].radius) || + (shoot[i].position.y > screenHeight + shoot[i].radius) || (shoot[i].position.y < 0 - shoot[i].radius)) + { + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + } - // Life of shoot - if (shoot[i].lifeSpawn >= 120) - { - shoot[i].position = (Vector2){0, 0}; - shoot[i].speed = (Vector2){0, 0}; - shoot[i].lifeSpawn = 0; - shoot[i].active = false; - } + // Player shot life spawn + if (shoot[i].lifeSpawn >= 120) + { + shoot[i].position = (Vector2){ 0.0f, 0.0f }; + shoot[i].speed = (Vector2){ 0.0f, 0.0f }; + shoot[i].lifeSpawn = 0; + shoot[i].active = false; } } + } - // Player collision with meteors - player.collider = (Vector3){player.position.x, player.position.y - shipHeight/2, 12}; + // Player vs meteors collision logic + player.collider = (Vector3){player.position.x, player.position.y - shipHeight/2, 12}; - for (int i = 0; i < NUM_BIG_METEORS; i++) + for (int i = 0; i < MAX_BIG_BALLS; i++) + { + if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, bigBalls[i].position, bigBalls[i].radius) && bigBalls[i].active) { - if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, bigMeteor[i].position, bigMeteor[i].radius) && bigMeteor[i].active) - { - gameOver = true; - } + gameOver = true; } + } - for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + for (int i = 0; i < MAX_BIG_BALLS*2; i++) + { + if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, mediumBalls[i].position, mediumBalls[i].radius) && mediumBalls[i].active) { - if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, mediumMeteor[i].position, mediumMeteor[i].radius) && mediumMeteor[i].active) - { - gameOver = true; - } + gameOver = true; } + } - for (int i = 0; i < NUM_SMALL_METEORS; i++) + for (int i = 0; i < MAX_BIG_BALLS*4; i++) + { + if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, smallBalls[i].position, smallBalls[i].radius) && smallBalls[i].active) { - if (CheckCollisionCircles((Vector2){ player.collider.x, player.collider.y }, player.collider.z, smallMeteor[i].position, smallMeteor[i].radius) && smallMeteor[i].active) - { - gameOver = true; - } + gameOver = true; } + } - // Meteor logic - for (int i = 0; i < NUM_BIG_METEORS; i++) + // Meteors logic (big) + for (int i = 0; i < MAX_BIG_BALLS; i++) + { + if (bigBalls[i].active) { - if (bigMeteor[i].active) - { - // movement - bigMeteor[i].position.x += bigMeteor[i].speed.x; - bigMeteor[i].position.y += bigMeteor[i].speed.y; - - // wall behaviour - if (((bigMeteor[i].position.x + bigMeteor[i].radius) >= screenWidth) || ((bigMeteor[i].position.x - bigMeteor[i].radius) <= 0)) bigMeteor[i].speed.x *= -1; - if ((bigMeteor[i].position.y - bigMeteor[i].radius) <= 0) bigMeteor[i].speed.y *= -1.5; - - if ((bigMeteor[i].position.y + bigMeteor[i].radius) >= screenHeight) - { - bigMeteor[i].speed.y *= -1; - bigMeteor[i].position.y = screenHeight - bigMeteor[i].radius; - } + // Meteor movement logic + bigBalls[i].position.x += bigBalls[i].speed.x; + bigBalls[i].position.y += bigBalls[i].speed.y; - bigMeteor[i].speed.y += gravity; + // Meteor vs wall collision logic + if (((bigBalls[i].position.x + bigBalls[i].radius) >= screenWidth) || ((bigBalls[i].position.x - bigBalls[i].radius) <= 0)) bigBalls[i].speed.x *= -1; + if ((bigBalls[i].position.y - bigBalls[i].radius) <= 0) bigBalls[i].speed.y *= -1.5; + + if ((bigBalls[i].position.y + bigBalls[i].radius) >= screenHeight) + { + bigBalls[i].speed.y *= -1; + bigBalls[i].position.y = screenHeight - bigBalls[i].radius; } + + bigBalls[i].speed.y += gravity; } + } - for (int i = 0; i < NUM_MEDIUM_METEORS; i++) + // Meteors logic (medium) + for (int i = 0; i < MAX_BIG_BALLS*2; i++) + { + if (mediumBalls[i].active) { - if (mediumMeteor[i].active) + // Meteor movement logic + mediumBalls[i].position.x += mediumBalls[i].speed.x; + mediumBalls[i].position.y += mediumBalls[i].speed.y; + + // Meteor vs wall collision logic + if (mediumBalls[i].position.x + mediumBalls[i].radius >= screenWidth || mediumBalls[i].position.x - mediumBalls[i].radius <= 0) mediumBalls[i].speed.x *= -1; + if (mediumBalls[i].position.y - mediumBalls[i].radius <= 0) mediumBalls[i].speed.y *= -1; + if (mediumBalls[i].position.y + mediumBalls[i].radius >= screenHeight) { - // Movement logic - mediumMeteor[i].position.x += mediumMeteor[i].speed.x; - mediumMeteor[i].position.y += mediumMeteor[i].speed.y; - - // Wall behaviour - if (mediumMeteor[i].position.x + mediumMeteor[i].radius >= screenWidth || mediumMeteor[i].position.x - mediumMeteor[i].radius <= 0) mediumMeteor[i].speed.x *= -1; - if (mediumMeteor[i].position.y - mediumMeteor[i].radius <= 0) mediumMeteor[i].speed.y *= -1; - if (mediumMeteor[i].position.y + mediumMeteor[i].radius >= screenHeight) - { - mediumMeteor[i].speed.y *= -1; - mediumMeteor[i].position.y = screenHeight - mediumMeteor[i].radius; - } - - mediumMeteor[i].speed.y += gravity + 0.12f; + mediumBalls[i].speed.y *= -1; + mediumBalls[i].position.y = screenHeight - mediumBalls[i].radius; } + + mediumBalls[i].speed.y += gravity + 0.12f; } + } - for (int i = 0; i < NUM_SMALL_METEORS; i++) + // Meteors logic (small) + for (int i = 0; i < MAX_BIG_BALLS*4; i++) + { + if (smallBalls[i].active) { - if (smallMeteor[i].active) + // Meteor movement logic + smallBalls[i].position.x += smallBalls[i].speed.x; + smallBalls[i].position.y += smallBalls[i].speed.y; + + // Meteor vs wall collision logic + if (smallBalls[i].position.x + smallBalls[i].radius >= screenWidth || smallBalls[i].position.x - smallBalls[i].radius <= 0) smallBalls[i].speed.x *= -1; + if (smallBalls[i].position.y - smallBalls[i].radius <= 0) smallBalls[i].speed.y *= -1; + if (smallBalls[i].position.y + smallBalls[i].radius >= screenHeight) { - // movement - smallMeteor[i].position.x += smallMeteor[i].speed.x; - smallMeteor[i].position.y += smallMeteor[i].speed.y; - - // wall behaviour - if (smallMeteor[i].position.x + smallMeteor[i].radius >= screenWidth || smallMeteor[i].position.x - smallMeteor[i].radius <= 0) smallMeteor[i].speed.x *= -1; - if (smallMeteor[i].position.y - smallMeteor[i].radius <= 0) smallMeteor[i].speed.y *= -1; - if (smallMeteor[i].position.y + smallMeteor[i].radius >= screenHeight) - { - smallMeteor[i].speed.y *= -1; - smallMeteor[i].position.y = screenHeight - smallMeteor[i].radius; - } - - smallMeteor[i].speed.y += gravity + 0.25f; + smallBalls[i].speed.y *= -1; + smallBalls[i].position.y = screenHeight - smallBalls[i].radius; } + + smallBalls[i].speed.y += gravity + 0.25f; } + } - // Collision behaviour - for (int i = 0; i < NUM_SHOOTS; i++) + // Player-shot vs meteors logic + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) + { + if ((shoot[i].active)) { - if ((shoot[i].active)) + for (int a = 0; a < MAX_BIG_BALLS; a++) { - for (int a = 0; a < NUM_BIG_METEORS; a++) + if (bigBalls[a].active && (bigBalls[a].position.x - bigBalls[a].radius <= linePosition.x && bigBalls[a].position.x + bigBalls[a].radius >= linePosition.x) + && (bigBalls[a].position.y + bigBalls[a].radius >= shoot[i].position.y)) { - if (bigMeteor[a].active && (bigMeteor[a].position.x - bigMeteor[a].radius <= linePosition.x && bigMeteor[a].position.x + bigMeteor[a].radius >= linePosition.x) - && (bigMeteor[a].position.y + bigMeteor[a].radius >= shoot[i].position.y)) - { - shoot[i].active = false; - shoot[i].lifeSpawn = 0; - bigMeteor[a].active = false; - meteorsDestroyed++; - score += bigMeteor[a].points; + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + bigBalls[a].active = false; + meteorsDestroyed++; + score += bigBalls[a].points; - for (int z = 0; z < 5; z++) + for (int z = 0; z < 5; z++) + { + if (points[z].alpha == 0.0f) { - if (points[z].alpha == 0.0f) - { - points[z].position = bigMeteor[a].position; - points[z].value = bigMeteor[a].points; - points[z].color = RED; - points[z].alpha = 1.0f; - z = 5; - } + points[z].position = bigBalls[a].position; + points[z].value = bigBalls[a].points; + points[z].alpha = 1.0f; + z = 5; } + } - for (int j = 0; j < 2; j ++) + for (int j = 0; j < 2; j ++) + { + if ((countmediumBallss%2) == 0) + { + mediumBalls[countmediumBallss].position = (Vector2){bigBalls[a].position.x, bigBalls[a].position.y}; + mediumBalls[countmediumBallss].speed = (Vector2){ -1*BALLS_SPEED, BALLS_SPEED }; + } + else { - if ((countMediumMeteors%2) == 0) - { - mediumMeteor[countMediumMeteors].position = (Vector2){bigMeteor[a].position.x, bigMeteor[a].position.y}; - mediumMeteor[countMediumMeteors].speed = (Vector2){METEORS_SPEED*-1, METEORS_SPEED}; - } - else - { - mediumMeteor[countMediumMeteors].position = (Vector2){bigMeteor[a].position.x, bigMeteor[a].position.y}; - mediumMeteor[countMediumMeteors].speed = (Vector2){METEORS_SPEED, METEORS_SPEED}; - } - - mediumMeteor[countMediumMeteors].active = true; - countMediumMeteors ++; + mediumBalls[countmediumBallss].position = (Vector2){bigBalls[a].position.x, bigBalls[a].position.y}; + mediumBalls[countmediumBallss].speed = (Vector2){ BALLS_SPEED, BALLS_SPEED }; } - bigMeteor[a].color = RED; - a = NUM_BIG_METEORS; + mediumBalls[countmediumBallss].active = true; + countmediumBallss ++; } + + a = MAX_BIG_BALLS; } } + } - if ((shoot[i].active)) + if ((shoot[i].active)) + { + for (int b = 0; b < MAX_BIG_BALLS*2; b++) { - for (int b = 0; b < NUM_MEDIUM_METEORS; b++) + if (mediumBalls[b].active && (mediumBalls[b].position.x - mediumBalls[b].radius <= linePosition.x && mediumBalls[b].position.x + mediumBalls[b].radius >= linePosition.x) + && (mediumBalls[b].position.y + mediumBalls[b].radius >= shoot[i].position.y)) { - if (mediumMeteor[b].active && (mediumMeteor[b].position.x - mediumMeteor[b].radius <= linePosition.x && mediumMeteor[b].position.x + mediumMeteor[b].radius >= linePosition.x) - && (mediumMeteor[b].position.y + mediumMeteor[b].radius >= shoot[i].position.y)) - { - shoot[i].active = false; - shoot[i].lifeSpawn = 0; - mediumMeteor[b].active = false; - meteorsDestroyed++; - score += mediumMeteor[b].points; + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + mediumBalls[b].active = false; + meteorsDestroyed++; + score += mediumBalls[b].points; - for (int z = 0; z < 5; z++) + for (int z = 0; z < 5; z++) + { + if (points[z].alpha == 0.0f) { - if (points[z].alpha == 0.0f) - { - points[z].position = mediumMeteor[b].position; - points[z].value = mediumMeteor[b].points; - points[z].color = GREEN; - points[z].alpha = 1.0f; - z = 5; - } + points[z].position = mediumBalls[b].position; + points[z].value = mediumBalls[b].points; + points[z].alpha = 1.0f; + z = 5; } + } - for (int j = 0; j < 2; j ++) + for (int j = 0; j < 2; j ++) + { + if (countsmallBallss%2 == 0) { - if (countSmallMeteors%2 == 0) - { - smallMeteor[countSmallMeteors].position = (Vector2){mediumMeteor[b].position.x, mediumMeteor[b].position.y}; - smallMeteor[countSmallMeteors].speed = (Vector2){METEORS_SPEED*-1, METEORS_SPEED*-1}; - } - else - { - smallMeteor[countSmallMeteors].position = (Vector2){mediumMeteor[b].position.x, mediumMeteor[b].position.y}; - smallMeteor[countSmallMeteors].speed = (Vector2){METEORS_SPEED, METEORS_SPEED*-1}; - } - - smallMeteor[countSmallMeteors].active = true; - countSmallMeteors ++; + smallBalls[countsmallBallss].position = (Vector2){mediumBalls[b].position.x, mediumBalls[b].position.y}; + smallBalls[countsmallBallss].speed = (Vector2){ BALLS_SPEED*-1, BALLS_SPEED*-1}; } - mediumMeteor[b].color = GREEN; - b = NUM_MEDIUM_METEORS; + else + { + smallBalls[countsmallBallss].position = (Vector2){mediumBalls[b].position.x, mediumBalls[b].position.y}; + smallBalls[countsmallBallss].speed = (Vector2){ BALLS_SPEED, BALLS_SPEED*-1}; + } + + smallBalls[countsmallBallss].active = true; + countsmallBallss ++; } + + b = MAX_BIG_BALLS*2; } } + } - if ((shoot[i].active)) + if ((shoot[i].active)) + { + for (int c = 0; c < MAX_BIG_BALLS*4; c++) { - for (int c = 0; c < NUM_SMALL_METEORS; c++) + if (smallBalls[c].active && (smallBalls[c].position.x - smallBalls[c].radius <= linePosition.x && smallBalls[c].position.x + smallBalls[c].radius >= linePosition.x) + && (smallBalls[c].position.y + smallBalls[c].radius >= shoot[i].position.y)) { - if (smallMeteor[c].active && (smallMeteor[c].position.x - smallMeteor[c].radius <= linePosition.x && smallMeteor[c].position.x + smallMeteor[c].radius >= linePosition.x) - && (smallMeteor[c].position.y + smallMeteor[c].radius >= shoot[i].position.y)) + shoot[i].active = false; + shoot[i].lifeSpawn = 0; + smallBalls[c].active = false; + meteorsDestroyed++; + score += smallBalls[c].points; + + for (int z = 0; z < 5; z++) { - shoot[i].active = false; - shoot[i].lifeSpawn = 0; - smallMeteor[c].active = false; - meteorsDestroyed++; - smallMeteor[c].color = YELLOW; - score += smallMeteor[c].points; - - for (int z = 0; z < 5; z++) + if (points[z].alpha == 0.0f) { - if (points[z].alpha == 0.0f) - { - points[z].position = smallMeteor[c].position; - points[z].value = smallMeteor[c].points; - points[z].color = YELLOW; - points[z].alpha = 1.0f; - z = 5; - } + points[z].position = smallBalls[c].position; + points[z].value = smallBalls[c].points; + points[z].alpha = 1.0f; + z = 5; } - - c = NUM_SMALL_METEORS; } - } - } - } - for (int z = 0; z < 5; z++) - { - if (points[z].alpha > 0.0f) - { - points[z].position.y -= 2; - points[z].alpha -= 0.02f; + c = MAX_BIG_BALLS*4; + } } - - if (points[z].alpha < 0.0f) points[z].alpha = 0.0f; } - - if (meteorsDestroyed == (NUM_BIG_METEORS + NUM_MEDIUM_METEORS + NUM_SMALL_METEORS)) victory = true; - } - else - { - framesCounter++; - if (framesCounter%180 == 0) awake = false; } + + if (meteorsDestroyed == (MAX_BIG_BALLS + MAX_BIG_BALLS*2 + MAX_BIG_BALLS*4)) victory = true; } } else @@ -603,6 +535,18 @@ void UpdateGame(void) gameOver = false; } } + + // Points move-up and fade logic + for (int z = 0; z < 5; z++) + { + if (points[z].alpha > 0.0f) + { + points[z].position.y -= 2; + points[z].alpha -= 0.02f; + } + + if (points[z].alpha < 0.0f) points[z].alpha = 0.0f; + } } // Draw game (one frame) @@ -610,66 +554,60 @@ void DrawGame(void) { BeginDrawing(); - ClearBackground(DARKGRAY); + ClearBackground(RAYWHITE); if (!gameOver) { // Draw player Vector2 v1 = { player.position.x + sinf(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cosf(player.rotation*DEG2RAD)*(shipHeight) }; - Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; - Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(SHIP_BASE_SIZE/2) }; - DrawTriangleLines(v1, v2, v3, player.color); + Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) }; + Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) }; + DrawTriangle(v1, v2, v3, MAROON); - // Draw meteor - for (int i = 0;i < NUM_BIG_METEORS; i++) + // Draw meteors (big) + for (int i = 0;i < MAX_BIG_BALLS; i++) { - if (bigMeteor[i].active) DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, bigMeteor[i].color); - else - { - DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, Fade(bigMeteor[i].color, 0.25f)); - //DrawText(FormatText("%i", bigMeteor[i].points), bigMeteor[i].position.x - MeasureText("200", 20)/2, bigMeteor[i].position.y - 10, 20, Fade(WHITE, 0.25f)); - } + if (bigBalls[i].active) DrawCircleV(bigBalls[i].position, bigBalls[i].radius, DARKGRAY); + else DrawCircleV(bigBalls[i].position, bigBalls[i].radius, Fade(LIGHTGRAY, 0.3f)); } - for (int i = 0;i < NUM_MEDIUM_METEORS; i++) + // Draw meteors (medium) + for (int i = 0;i < MAX_BIG_BALLS*2; i++) { - if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, mediumMeteor[i].color); - else - { - DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(mediumMeteor[i].color, 0.25f)); - //DrawText(FormatText("%i", mediumMeteor[i].points), mediumMeteor[i].position.x - MeasureText("100", 20)/2, mediumMeteor[i].position.y - 10, 20, Fade(WHITE, 0.25f)); - } + if (mediumBalls[i].active) DrawCircleV(mediumBalls[i].position, mediumBalls[i].radius, GRAY); + else DrawCircleV(mediumBalls[i].position, mediumBalls[i].radius, Fade(LIGHTGRAY, 0.3f)); } - for (int i = 0;i < NUM_SMALL_METEORS; i++) + // Draw meteors (small) + for (int i = 0;i < MAX_BIG_BALLS*4; i++) { - if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, smallMeteor[i].color); - else - { - DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(smallMeteor[i].color, 0.25f)); - //DrawText(FormatText("%i", smallMeteor[i].points), smallMeteor[i].position.x - MeasureText("50", 10)/2, smallMeteor[i].position.y - 5, 10, Fade(WHITE, 0.25f)); - } + if (smallBalls[i].active) DrawCircleV(smallBalls[i].position, smallBalls[i].radius, GRAY); + else DrawCircleV(smallBalls[i].position, smallBalls[i].radius, Fade(LIGHTGRAY, 0.3f)); } // Draw shoot - - for (int i = 0; i < NUM_SHOOTS; i++) + for (int i = 0; i < PLAYER_MAX_SHOOTS; i++) { if (shoot[i].active) DrawLine(linePosition.x, linePosition.y, shoot[i].position.x, shoot[i].position.y, RED); } + // Draw score points for (int z = 0; z < 5; z++) { if (points[z].alpha > 0.0f) { - DrawText(FormatText("+%i", points[z].value), points[z].position.x, points[z].position.y, 20, Fade(points[z].color, points[z].alpha)); + DrawText(FormatText("+%02i", points[z].value), points[z].position.x, points[z].position.y, 20, Fade(BLUE, points[z].alpha)); } } - // Draw Text + // Draw score (UI) DrawText(FormatText("SCORE: %i", score), 10, 10, 20, LIGHTGRAY); - if (victory) DrawText("VICTORY", screenWidth/2 - MeasureText("VICTORY", 40)/2, screenHeight/2 - 40, 40, LIGHTGRAY); + if (victory) + { + DrawText("YOU WIN!", screenWidth/2 - MeasureText("YOU WIN!", 60)/2, 100, 60, LIGHTGRAY); + DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, LIGHTGRAY); + } if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, LIGHTGRAY); } diff --git a/games/samples/space_invaders.c b/games/samples/space_invaders.c index 9f380628..c2dd0c61 100644 --- a/games/samples/space_invaders.c +++ b/games/samples/space_invaders.c @@ -29,7 +29,7 @@ //---------------------------------------------------------------------------------- // Types and Structures Definition //---------------------------------------------------------------------------------- -typedef enum { FIRST = 0, SECOND, THIRD } enemyWave; +typedef enum { FIRST = 0, SECOND, THIRD } EnemyWave; typedef struct Player{ Rectangle rec; @@ -66,7 +66,7 @@ static bool victory; static Player player; static Enemy enemy[NUM_MAX_ENEMIES]; static Shoot shoot[NUM_SHOOTS]; -static enemyWave wave; +static EnemyWave wave; static int shootRate; static float alpha; @@ -149,8 +149,8 @@ void InitGame(void) // Initialize player player.rec.x = 20; player.rec.y = 50; - player.rec.width = 10; - player.rec.height = 10; + player.rec.width = 20; + player.rec.height = 20; player.speed.x = 5; player.speed.y = 5; player.color = BLACK; @@ -165,7 +165,7 @@ void InitGame(void) enemy[i].speed.x = 5; enemy[i].speed.y = 5; enemy[i].active = true; - enemy[i].color = DARKGRAY; + enemy[i].color = GRAY; } // Initialize shoots @@ -178,7 +178,7 @@ void InitGame(void) shoot[i].speed.x = 7; shoot[i].speed.y = 0; shoot[i].active = false; - shoot[i].color = WHITE; + shoot[i].color = MAROON; } } @@ -325,10 +325,9 @@ void UpdateGame(void) { if (enemy[j].active) { - if (CheckCollisionRecs(shoot[i].rec, enemy[j].rec)) + if (CheckCollisionRecs(shoot[i].rec, enemy[j].rec)) { shoot[i].active = false; - enemy[j].active = false; enemy[j].rec.x = GetRandomValue(screenWidth, screenWidth + 1000); enemy[j].rec.y = GetRandomValue(0, screenHeight - enemy[j].rec.height); shootRate = 0; @@ -362,7 +361,7 @@ void DrawGame(void) { BeginDrawing(); - ClearBackground(LIGHTGRAY); + ClearBackground(RAYWHITE); if (!gameOver) { @@ -382,7 +381,7 @@ void DrawGame(void) if (shoot[i].active) DrawRectangleRec(shoot[i].rec, shoot[i].color); } - DrawText(FormatText("%04i", score), 20, 20, 40, DARKGRAY); + DrawText(FormatText("%04i", score), 20, 20, 40, GRAY); if (victory) DrawText("YOU WIN", screenWidth/2 - MeasureText("YOU WIN", 40)/2, screenHeight/2 - 40, 40, BLACK); diff --git a/games/samples/tetris.c b/games/samples/tetris.c index 8d550f3d..62400201 100644 --- a/games/samples/tetris.c +++ b/games/samples/tetris.c @@ -25,7 +25,7 @@ //---------------------------------------------------------------------------------- // Some Defines //---------------------------------------------------------------------------------- -#define SQUARE_SIZE 30 +#define SQUARE_SIZE 20 #define GRID_HORIZONTAL_SIZE 12 #define GRID_VERTICAL_SIZE 20 @@ -45,7 +45,7 @@ typedef enum GridSquare { EMPTY, MOVING, FULL, BLOCK, FADING } GridSquare; // Global Variables Declaration //------------------------------------------------------------------------------------ static int screenWidth = 800; -static int screenHeight = 620; +static int screenHeight = 450; static bool gameOver = false; static bool pause = false; @@ -289,6 +289,8 @@ void UpdateGame(void) DeleteCompleteLines(); fadeLineCounter = 0; lineToDelete = false; + + lines++; } } } @@ -314,10 +316,10 @@ void DrawGame(void) { // Draw gameplay area Vector2 offset; - offset.x = screenWidth/2 - (GRID_HORIZONTAL_SIZE*SQUARE_SIZE/2); + offset.x = screenWidth/2 - (GRID_HORIZONTAL_SIZE*SQUARE_SIZE/2) - 50; offset.y = screenHeight/2 - ((GRID_VERTICAL_SIZE - 1)*SQUARE_SIZE/2) + SQUARE_SIZE*2; - offset.y -= 60; // NOTE: Harcoded position! + offset.y -= 50; // NOTE: Harcoded position! int controller = offset.x; @@ -360,13 +362,9 @@ void DrawGame(void) offset.y += SQUARE_SIZE; } - // Draw incoming piece - //offset.x = screenWidth/2 - (4*SQUARE_SIZE/2); - //offset.y = (screenHeight/2 - ((GRID_VERTICAL_SIZE - 1)*SQUARE_SIZE/2)) - (3*SQUARE_SIZE); - - // NOTE: Harcoded positions for the demo! - offset.x = 850; - offset.y = 75; + // Draw incoming piece (hardcoded) + offset.x = 500; + offset.y = 45; int controler = offset.x; @@ -393,6 +391,9 @@ void DrawGame(void) offset.y += SQUARE_SIZE; } + DrawText("INCOMING:", offset.x, offset.y - 100, 10, GRAY); + DrawText(FormatText("LINES: %04i", lines), offset.x, offset.y + 20, 10, GRAY); + if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); } else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); -- cgit v1.2.3