diff --git a/games/just_do_GGJ2015/src/just_do.c b/games/just_do_GGJ2015/src/just_do.c new file mode 100644 index 000000000..beac9e149 --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/makefile b/games/just_do_GGJ2015/src/makefile new file mode 100644 index 000000000..32bee4dc1 --- /dev/null +++ b/games/just_do_GGJ2015/src/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 = -O2 -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 new file mode 100644 index 000000000..af7f836ed Binary files /dev/null and b/games/just_do_GGJ2015/src/resources/ambient.ogg differ diff --git a/games/just_do_GGJ2015/src/resources/win.wav b/games/just_do_GGJ2015/src/resources/win.wav new file mode 100644 index 000000000..72520f993 Binary files /dev/null and b/games/just_do_GGJ2015/src/resources/win.wav differ diff --git a/games/just_do_GGJ2015/src/screens/screen_level00.c b/games/just_do_GGJ2015/src/screens/screen_level00.c new file mode 100644 index 000000000..99f298492 --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screen_level01.c b/games/just_do_GGJ2015/src/screens/screen_level01.c new file mode 100644 index 000000000..cedcb2e0c --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screen_level02.c b/games/just_do_GGJ2015/src/screens/screen_level02.c new file mode 100644 index 000000000..ccfa355e8 --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screen_level03.c b/games/just_do_GGJ2015/src/screens/screen_level03.c new file mode 100644 index 000000000..e87324149 --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screen_level04.c b/games/just_do_GGJ2015/src/screens/screen_level04.c new file mode 100644 index 000000000..c4e4e2c00 --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screen_level05.c b/games/just_do_GGJ2015/src/screens/screen_level05.c new file mode 100644 index 000000000..f2e4d852a --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screen_level06.c b/games/just_do_GGJ2015/src/screens/screen_level06.c new file mode 100644 index 000000000..b5881db41 --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screen_level07.c b/games/just_do_GGJ2015/src/screens/screen_level07.c new file mode 100644 index 000000000..d305b0255 --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screen_level08.c b/games/just_do_GGJ2015/src/screens/screen_level08.c new file mode 100644 index 000000000..4cb0443be --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screen_level09.c b/games/just_do_GGJ2015/src/screens/screen_level09.c new file mode 100644 index 000000000..d20f4bfb2 --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screen_level10.c b/games/just_do_GGJ2015/src/screens/screen_level10.c new file mode 100644 index 000000000..338060068 --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screen_logo.c b/games/just_do_GGJ2015/src/screens/screen_logo.c new file mode 100644 index 000000000..9639602de --- /dev/null +++ b/games/just_do_GGJ2015/src/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_GGJ2015/src/screens/screens.h b/games/just_do_GGJ2015/src/screens/screens.h new file mode 100644 index 000000000..7fa594053 --- /dev/null +++ b/games/just_do_GGJ2015/src/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