2017-01-22 17:31:56 +03:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
2019-05-21 23:36:52 +03:00
|
|
|
* WAVE COLLECTOR [GLOBAL GAME JAM 2017]
|
2017-01-22 17:31:56 +03:00
|
|
|
*
|
|
|
|
* The ultimate wave particles collector is here!
|
|
|
|
* You must follow the wave and collect all the particles
|
|
|
|
* The level is actually the wave and the wave is the level!
|
|
|
|
* Be fast! Be smart! Be the best wave collector!
|
|
|
|
*
|
2017-03-12 14:37:43 +03:00
|
|
|
* This game has been created using raylib v1.7 (www.raylib.com)
|
2017-01-22 17:31:56 +03:00
|
|
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
|
|
|
*
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
#include "raylib.h"
|
|
|
|
#include "screens/screens.h" // NOTE: Defines global variable: currentScreen
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2017-05-10 20:39:52 +03:00
|
|
|
#include <stdio.h> // Required for: printf()
|
|
|
|
#include <string.h> // Required for: strcpy()
|
|
|
|
|
2017-01-22 17:31:56 +03:00
|
|
|
#if defined(PLATFORM_WEB)
|
|
|
|
#include <emscripten/emscripten.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Global Variables Definition (local to this module)
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
const int screenWidth = 1280;
|
|
|
|
const int screenHeight = 720;
|
|
|
|
|
|
|
|
// Required variables to manage screen transitions (fade-in, fade-out)
|
2017-01-24 14:14:15 +03:00
|
|
|
static float transAlpha = 0.0f;
|
|
|
|
static bool onTransition = false;
|
|
|
|
static bool transFadeOut = false;
|
|
|
|
static int transFromScreen = -1;
|
|
|
|
static int transToScreen = -1;
|
|
|
|
|
|
|
|
// NOTE: Some global variables that require to be visible for all screens,
|
|
|
|
// are defined in screens.h (i.e. currentScreen)
|
2017-01-22 17:31:56 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Local Functions Declaration
|
|
|
|
//----------------------------------------------------------------------------------
|
2017-04-04 01:21:52 +03:00
|
|
|
static void ChangeToScreen(int screen); // No transition effect
|
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
static void TransitionToScreen(int screen);
|
|
|
|
static void UpdateTransition(void);
|
|
|
|
static void DrawTransition(void);
|
2017-01-22 17:31:56 +03:00
|
|
|
|
2017-04-04 01:21:52 +03:00
|
|
|
static void UpdateDrawFrame(void); // Update and Draw one frame
|
2017-01-22 17:31:56 +03:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Main entry point
|
|
|
|
//----------------------------------------------------------------------------------
|
2017-11-25 22:27:53 +03:00
|
|
|
int main(int argc, char *argv[])
|
2017-01-22 17:31:56 +03:00
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//---------------------------------------------------------
|
2017-10-22 12:48:41 +03:00
|
|
|
#if defined(PLATFORM_DESKTOP)
|
2017-05-10 20:39:52 +03:00
|
|
|
// TODO: Support for dropped files on the exe
|
|
|
|
|
|
|
|
// Support command line argument for custom music file
|
2017-01-22 17:31:56 +03:00
|
|
|
if (argc > 1)
|
|
|
|
{
|
2017-05-10 20:39:52 +03:00
|
|
|
// Just supporting an input argument parameter!!! o__O
|
|
|
|
|
2017-04-04 01:21:52 +03:00
|
|
|
if ((IsFileExtension(argv[1], ".ogg")) ||
|
|
|
|
(IsFileExtension(argv[1], ".wav")))
|
2017-01-22 17:31:56 +03:00
|
|
|
{
|
2017-05-10 20:39:52 +03:00
|
|
|
if (sampleFilename != NULL) free(sampleFilename);
|
|
|
|
|
|
|
|
sampleFilename = (char *)malloc(256);
|
2017-01-22 17:31:56 +03:00
|
|
|
strcpy(sampleFilename, argv[1]);
|
2017-05-10 20:39:52 +03:00
|
|
|
|
|
|
|
printf("Custom audio file: %s", sampleFilename);
|
2017-01-22 17:31:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2017-05-10 20:39:52 +03:00
|
|
|
|
2018-03-16 23:31:10 +03:00
|
|
|
#ifndef PLATFORM_ANDROID
|
2017-01-22 17:31:56 +03:00
|
|
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
2017-10-22 12:48:41 +03:00
|
|
|
#endif
|
2018-03-16 23:31:10 +03:00
|
|
|
// Note windowTitle is unused on Android
|
2019-05-21 23:36:52 +03:00
|
|
|
InitWindow(screenWidth, screenHeight, "WAVE COLLECTOR [GGJ17]");
|
2017-01-22 17:31:56 +03:00
|
|
|
|
|
|
|
// Global data loading (assets that must be available in all screens, i.e. fonts)
|
|
|
|
InitAudioDevice();
|
|
|
|
|
2018-05-04 17:59:48 +03:00
|
|
|
font = LoadFont("resources/font.fnt");
|
2017-01-22 17:31:56 +03:00
|
|
|
music = LoadMusicStream("resources/audio/wave.ogg");
|
|
|
|
|
|
|
|
SetMusicVolume(music, 1.0f);
|
|
|
|
|
|
|
|
// Setup and Init first screen
|
|
|
|
currentScreen = LOGO;
|
|
|
|
InitLogoScreen();
|
|
|
|
//InitTitleScreen();
|
|
|
|
//InitGameplayScreen();
|
|
|
|
//InitEndingScreen();
|
|
|
|
|
|
|
|
#if defined(PLATFORM_WEB)
|
|
|
|
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
|
|
|
#else
|
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Main game loop
|
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
|
|
{
|
|
|
|
UpdateDrawFrame();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// De-Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
switch (currentScreen)
|
|
|
|
{
|
|
|
|
case LOGO: UnloadLogoScreen(); break;
|
|
|
|
case TITLE: UnloadTitleScreen(); break;
|
|
|
|
case GAMEPLAY: UnloadGameplayScreen(); break;
|
|
|
|
case ENDING: UnloadEndingScreen(); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unload all global loaded data (i.e. fonts) here!
|
2018-05-04 17:59:48 +03:00
|
|
|
UnloadFont(font);
|
2017-01-22 17:31:56 +03:00
|
|
|
UnloadMusicStream(music);
|
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
CloseAudioDevice(); // Close audio context
|
2017-01-22 17:31:56 +03:00
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
CloseWindow(); // Close window and OpenGL context
|
2017-01-22 17:31:56 +03:00
|
|
|
//--------------------------------------------------------------------------------------
|
2018-03-16 23:31:10 +03:00
|
|
|
|
2017-01-22 17:31:56 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// Module specific Functions Definition
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Change to next screen, no transition
|
2017-04-04 01:21:52 +03:00
|
|
|
static void ChangeToScreen(int screen)
|
2017-01-22 17:31:56 +03:00
|
|
|
{
|
2017-01-24 14:14:15 +03:00
|
|
|
// Unload current screen
|
2017-01-22 17:31:56 +03:00
|
|
|
switch (currentScreen)
|
|
|
|
{
|
|
|
|
case LOGO: UnloadLogoScreen(); break;
|
|
|
|
case TITLE: UnloadTitleScreen(); break;
|
|
|
|
case GAMEPLAY: UnloadGameplayScreen(); break;
|
|
|
|
case ENDING: UnloadEndingScreen(); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
// Init next screen
|
2017-01-22 17:31:56 +03:00
|
|
|
switch (screen)
|
|
|
|
{
|
|
|
|
case LOGO: InitLogoScreen(); break;
|
|
|
|
case TITLE: InitTitleScreen(); break;
|
|
|
|
case GAMEPLAY: InitGameplayScreen(); break;
|
|
|
|
case ENDING: InitEndingScreen(); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentScreen = screen;
|
|
|
|
}
|
|
|
|
|
2017-04-04 01:21:52 +03:00
|
|
|
// Define transition to next screen
|
|
|
|
static void TransitionToScreen(int screen)
|
|
|
|
{
|
|
|
|
onTransition = true;
|
|
|
|
transFadeOut = false;
|
|
|
|
transFromScreen = currentScreen;
|
|
|
|
transToScreen = screen;
|
|
|
|
transAlpha = 0.0f;
|
|
|
|
}
|
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
// Update transition effect
|
2017-04-04 01:21:52 +03:00
|
|
|
static void UpdateTransition(void)
|
2017-01-22 17:31:56 +03:00
|
|
|
{
|
|
|
|
if (!transFadeOut)
|
|
|
|
{
|
|
|
|
transAlpha += 0.05f;
|
2017-01-24 14:14:15 +03:00
|
|
|
|
2017-01-25 02:44:04 +03:00
|
|
|
// NOTE: Due to float internal representation, condition jumps on 1.0f instead of 1.05f
|
|
|
|
// For that reason we compare against 1.01f, to avoid last frame loading stop
|
2017-04-04 01:21:52 +03:00
|
|
|
if ((int)transAlpha >= 1)
|
2017-01-22 17:31:56 +03:00
|
|
|
{
|
2017-01-24 14:14:15 +03:00
|
|
|
transAlpha = 1.0f;
|
2017-01-22 17:31:56 +03:00
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
// Unload current screen
|
2017-01-22 17:31:56 +03:00
|
|
|
switch (transFromScreen)
|
|
|
|
{
|
|
|
|
case LOGO: UnloadLogoScreen(); break;
|
|
|
|
case TITLE: UnloadTitleScreen(); break;
|
|
|
|
case GAMEPLAY: UnloadGameplayScreen(); break;
|
|
|
|
case ENDING: UnloadEndingScreen(); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
// Load next screen
|
2017-01-22 17:31:56 +03:00
|
|
|
switch (transToScreen)
|
|
|
|
{
|
2017-01-24 14:14:15 +03:00
|
|
|
case LOGO: InitLogoScreen(); break;
|
|
|
|
case TITLE: InitTitleScreen(); break;
|
|
|
|
case GAMEPLAY: InitGameplayScreen(); break;
|
|
|
|
case ENDING: InitEndingScreen(); break;
|
2017-01-22 17:31:56 +03:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
currentScreen = transToScreen;
|
|
|
|
|
|
|
|
// Activate fade out effect to next loaded screen
|
2017-01-22 17:31:56 +03:00
|
|
|
transFadeOut = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Transition fade out logic
|
|
|
|
{
|
|
|
|
transAlpha -= 0.05f;
|
|
|
|
|
2017-04-04 01:21:52 +03:00
|
|
|
if ((int)transAlpha <= 0)
|
2017-01-22 17:31:56 +03:00
|
|
|
{
|
2017-01-24 14:14:15 +03:00
|
|
|
transAlpha = 0.0f;
|
2017-01-22 17:31:56 +03:00
|
|
|
transFadeOut = false;
|
|
|
|
onTransition = false;
|
|
|
|
transFromScreen = -1;
|
|
|
|
transToScreen = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
// Draw transition effect (full-screen rectangle)
|
2017-04-04 01:21:52 +03:00
|
|
|
static void DrawTransition(void)
|
2017-01-22 17:31:56 +03:00
|
|
|
{
|
|
|
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, transAlpha));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update and draw game frame
|
2017-04-04 01:21:52 +03:00
|
|
|
static void UpdateDrawFrame(void)
|
2017-01-22 17:31:56 +03:00
|
|
|
{
|
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
if (!onTransition)
|
|
|
|
{
|
|
|
|
switch(currentScreen)
|
|
|
|
{
|
|
|
|
case LOGO:
|
|
|
|
{
|
|
|
|
UpdateLogoScreen();
|
|
|
|
|
|
|
|
if (FinishLogoScreen()) TransitionToScreen(TITLE);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TITLE:
|
|
|
|
{
|
|
|
|
UpdateTitleScreen();
|
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
if (FinishTitleScreen() == 1) TransitionToScreen(GAMEPLAY);
|
2017-01-22 17:31:56 +03:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case GAMEPLAY:
|
2017-05-10 20:39:52 +03:00
|
|
|
{
|
2017-01-22 17:31:56 +03:00
|
|
|
UpdateGameplayScreen();
|
|
|
|
|
|
|
|
if (FinishGameplayScreen() == 1) TransitionToScreen(ENDING);
|
|
|
|
//else if (FinishGameplayScreen() == 2) TransitionToScreen(TITLE);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ENDING:
|
|
|
|
{
|
|
|
|
UpdateEndingScreen();
|
|
|
|
|
|
|
|
if (FinishEndingScreen() == 1) TransitionToScreen(TITLE);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 14:14:15 +03:00
|
|
|
else UpdateTransition(); // Update transition (fade-in, fade-out)
|
2017-01-22 17:31:56 +03:00
|
|
|
|
2017-01-25 02:44:04 +03:00
|
|
|
// TODO: Review! It breaks the game... issues with audio buffering...
|
2017-01-22 17:31:56 +03:00
|
|
|
if (currentScreen != ENDING) UpdateMusicStream(music);
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
BeginDrawing();
|
|
|
|
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
|
|
|
|
switch(currentScreen)
|
|
|
|
{
|
|
|
|
case LOGO: DrawLogoScreen(); break;
|
|
|
|
case TITLE: DrawTitleScreen(); break;
|
|
|
|
case GAMEPLAY: DrawGameplayScreen(); break;
|
|
|
|
case ENDING: DrawEndingScreen(); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2017-01-24 14:14:15 +03:00
|
|
|
// Draw full screen rectangle in front of everything
|
2017-01-22 17:31:56 +03:00
|
|
|
if (onTransition) DrawTransition();
|
|
|
|
|
|
|
|
EndDrawing();
|
|
|
|
//----------------------------------------------------------------------------------
|
2017-11-25 22:27:53 +03:00
|
|
|
}
|