JUST DO - Global Game Jam 2015

This commit is contained in:
Ray
2015-01-25 14:46:11 +01:00
parent e9ea3f50bf
commit f5048742aa
17 changed files with 2790 additions and 0 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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 <math.h>
//----------------------------------------------------------------------------------
// 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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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));
}

View File

@ -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;
}

View File

@ -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));
}

View File

@ -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;
}

View File

@ -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));
}

View File

@ -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;
}

View File

@ -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 <string.h>
//----------------------------------------------------------------------------------
// 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;
}

View File

@ -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