Corrected some issues

Now works in WEB!
This commit is contained in:
Ray 2017-05-10 19:39:52 +02:00
parent 93e2fd8ea1
commit 76062247f8
4 changed files with 46 additions and 46 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 977 B

View File

@ -26,6 +26,8 @@
#include "raylib.h" #include "raylib.h"
#include "screens.h" #include "screens.h"
#include <stdio.h>
#include <stdlib.h> // Required for: malloc(), free() #include <stdlib.h> // Required for: malloc(), free()
#include <math.h> // Required for: sqrtf(), asinf() #include <math.h> // Required for: sqrtf(), asinf()
@ -79,7 +81,7 @@ static Rectangle waveRec;
// Samples variables // Samples variables
static Sample *samples; // Game samples static Sample *samples; // Game samples
static int totalSamples = 0; // Total game samples (proportional to waveData num samples) static int totalSamples; // Total game samples (proportional to waveData num samples)
static int collectedSamples; // Samples collected by player static int collectedSamples; // Samples collected by player
static int currentSample; // Last sample to go through player collect area static int currentSample; // Last sample to go through player collect area
static float samplesSpeed; // All samples move at the same speed static float samplesSpeed; // All samples move at the same speed
@ -91,7 +93,6 @@ static Texture2D texPlayer;
static Texture2D texSampleSmall; static Texture2D texSampleSmall;
static Texture2D texSampleMid; static Texture2D texSampleMid;
static Texture2D texSampleBig; static Texture2D texSampleBig;
static Texture2D texLine;
static RenderTexture2D waveTarget; static RenderTexture2D waveTarget;
@ -103,7 +104,7 @@ static Sound fxPause; // Pause sound
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Module Functions Declaration (local) // Module Functions Declaration (local)
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
static void DrawSamples(Sample *samples, int sampleCount, int playedSamples, Rectangle bounds, Color color); static void DrawSamplesMap(Sample *samples, int sampleCount, int playedSamples, Rectangle bounds, Color color);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Gameplay Screen Functions Definition // Gameplay Screen Functions Definition
@ -123,7 +124,6 @@ void InitGameplayScreen(void)
texSampleSmall = LoadTexture("resources/textures/sample_small.png"); texSampleSmall = LoadTexture("resources/textures/sample_small.png");
texSampleMid = LoadTexture("resources/textures/sample_mid.png"); texSampleMid = LoadTexture("resources/textures/sample_mid.png");
texSampleBig = LoadTexture("resources/textures/sample_big.png"); texSampleBig = LoadTexture("resources/textures/sample_big.png");
texLine = LoadTexture("resources/textures/line.png");
waveRec = (Rectangle){ 32, 32, 1280 - 64, 105 }; waveRec = (Rectangle){ 32, 32, 1280 - 64, 105 };
waveTarget = LoadRenderTexture(waveRec.width, waveRec.height); waveTarget = LoadRenderTexture(waveRec.width, waveRec.height);
@ -200,11 +200,16 @@ void InitGameplayScreen(void)
samples[i].active = true; samples[i].active = true;
samples[i].collected = false; samples[i].collected = false;
samples[i].color = RED; samples[i].color = RED;
samples[i].renderable = false;
} }
samplesSpeed = MAX_SAMPLES_SPEED; samplesSpeed = MAX_SAMPLES_SPEED;
currentSample = 0; currentSample = 0;
//FILE *samplesFile = fopen("resources/samples.data", "wb");
//fwrite(samples, totalSamples*sizeof(Sample), 1, samplesFile);
//fclose(samplesFile);
// We already saved the samples we needed for the game, we can free waveData // We already saved the samples we needed for the game, we can free waveData
free(waveData); free(waveData);
@ -329,7 +334,6 @@ void UpdateGameplayScreen(void)
// Check ending conditions // Check ending conditions
if (currentSample >= totalSamples - 1) if (currentSample >= totalSamples - 1)
{ {
StopMusicStream(music);
endingStatus = 1; // Win endingStatus = 1; // Win
finishScreen = 1; finishScreen = 1;
} }
@ -337,7 +341,6 @@ void UpdateGameplayScreen(void)
if (synchro <= 0.0f) if (synchro <= 0.0f)
{ {
synchro = 0.0f; synchro = 0.0f;
StopMusicStream(music);
endingStatus = 2; // Loose endingStatus = 2; // Loose
finishScreen = 1; finishScreen = 1;
} }
@ -365,33 +368,20 @@ void DrawGameplayScreen(void)
if (i < (currentSample + 1)) col = Fade(DARKGRAY, 0.5f); if (i < (currentSample + 1)) col = Fade(DARKGRAY, 0.5f);
else col = WHITE; else col = WHITE;
//DrawCircleV(samples[i].position, samples[i].radius, col);
if (!samples[i].collected) if (!samples[i].collected)
{ {
if (combo > 50) DrawTexture(texSampleSmall, samples[i].position.x - texSampleSmall.width/2, samples[i].position.y - texSampleSmall.height/2, col); //DrawCircleV(samples[i].position, samples[i].radius, col);
else if (combo > 25) DrawTexture(texSampleMid, samples[i].position.x - texSampleMid.width/2, samples[i].position.y - texSampleMid.height/2, col);
else DrawTexture(texSampleBig, samples[i].position.x - texSampleSmall.width/2, samples[i].position.y - texSampleBig.height/2, col); if (combo > 30) DrawTexture(texSampleSmall, samples[i].position.x - texSampleSmall.width/2, samples[i].position.y - texSampleSmall.height/2, col);
else if (combo > 15) DrawTexture(texSampleMid, samples[i].position.x - texSampleMid.width/2, samples[i].position.y - texSampleMid.height/2, col);
else DrawTexture(texSampleBig, samples[i].position.x - texSampleBig.width/2, samples[i].position.y - texSampleBig.height/2, col);
} }
if (i < (currentSample + 1)) col = Fade(GRAY, 0.3f); if (i < (currentSample + 1)) col = Fade(GRAY, 0.3f);
else col = Fade(WHITE, 0.5f); else col = Fade(RED, 0.5f);
// Draw line between samples // Draw line between samples
//DrawLine(samples[i].position.x, samples[i].position.y, samples[i + 1].position.x, samples[i + 1].position.y, col); DrawLineEx(samples[i].position, samples[i + 1].position, 3.0f, col);
float dx = samples[i + 1].position.x - samples[i].position.x;
float dy = samples[i + 1].position.y - samples[i].position.y;
float d = sqrtf(dx*dx + dy*dy);
float angle = asinf(dy/d);
// Draw lines using textures
//DrawTextureEx(texLine, (Vector2){ samples[i].position.x - 2, samples[i].position.y - 2 }, -RAD2DEG*angle, d/SAMPLES_SPACING, col);
// Draw lines using textures - IMPROVED
// TODO: Further improving to draw lines properly
DrawTexturePro(texLine, (Rectangle){ 0, 0, texLine.width, texLine.height },
(Rectangle){ samples[i].position.x, samples[i].position.y, (float)texLine.width*d/SAMPLES_SPACING, texLine.height },
(Vector2){ 0, (float)texLine.height/2 }, -RAD2DEG*angle, col);
} }
} }
@ -432,7 +422,7 @@ void DrawGameplayScreen(void)
// Draw wave // Draw wave
// NOTE: Old drawing method, replaced by rendertarget // NOTE: Old drawing method, replaced by rendertarget
//DrawSamples(samples, totalSamples, currentSample, waveRec, MAROON); //DrawSamplesMap(samples, totalSamples, currentSample, waveRec, MAROON);
//DrawRectangle(waveRec.x + (int)currentSample*1240/totalSamples, waveRec.y, 2, 99, DARKGRAY); //DrawRectangle(waveRec.x + (int)currentSample*1240/totalSamples, waveRec.y, 2, 99, DARKGRAY);
//DrawRectangleLines(20, 20, 1240, 140, DARKGRAY); //DrawRectangleLines(20, 20, 1240, 140, DARKGRAY);
//DrawRectangle(20, 150, (float)currentSample/totalSamples*1240, 10, GRAY); //DrawRectangle(20, 150, (float)currentSample/totalSamples*1240, 10, GRAY);
@ -440,7 +430,7 @@ void DrawGameplayScreen(void)
// Draw wave using render target // Draw wave using render target
ClearBackground(BLANK); ClearBackground(BLANK);
BeginTextureMode(waveTarget); BeginTextureMode(waveTarget);
DrawSamples(samples, totalSamples, currentSample, (Rectangle){ 0, 0, waveTarget.texture.width, waveTarget.texture.height }, MAROON); DrawSamplesMap(samples, totalSamples, currentSample, (Rectangle){ 0, 0, waveTarget.texture.width, waveTarget.texture.height }, MAROON);
EndTextureMode(); EndTextureMode();
// TODO: Apply antialiasing shader // TODO: Apply antialiasing shader
@ -451,13 +441,14 @@ void DrawGameplayScreen(void)
// Gameplay Screen Unload logic // Gameplay Screen Unload logic
void UnloadGameplayScreen(void) void UnloadGameplayScreen(void)
{ {
StopMusicStream(music);
// Unload textures // Unload textures
UnloadTexture(texBackground); UnloadTexture(texBackground);
UnloadTexture(texPlayer); UnloadTexture(texPlayer);
UnloadTexture(texSampleSmall); UnloadTexture(texSampleSmall);
UnloadTexture(texSampleMid); UnloadTexture(texSampleMid);
UnloadTexture(texSampleBig); UnloadTexture(texSampleBig);
UnloadTexture(texLine);
UnloadRenderTexture(waveTarget); UnloadRenderTexture(waveTarget);
@ -466,7 +457,7 @@ void UnloadGameplayScreen(void)
UnloadSound(fxSampleOff); UnloadSound(fxSampleOff);
UnloadSound(fxPause); UnloadSound(fxPause);
free(samples); // Unload game samples (crashes game) free(samples); // Unload game samples
} }
// Gameplay Screen should finish? // Gameplay Screen should finish?
@ -483,7 +474,7 @@ int FinishGameplayScreen(void)
// NOTE: For proper visualization, MSAA x4 is recommended, alternatively // NOTE: For proper visualization, MSAA x4 is recommended, alternatively
// it should be rendered to a bigger texture and then scaled down with // it should be rendered to a bigger texture and then scaled down with
// bilinear/trilinear texture filtering // bilinear/trilinear texture filtering
static void DrawSamples(Sample *samples, int sampleCount, int playedSamples, Rectangle bounds, Color color) static void DrawSamplesMap(Sample *samples, int sampleCount, int playedSamples, Rectangle bounds, Color color)
{ {
// NOTE: We just pick a sample to draw every increment // NOTE: We just pick a sample to draw every increment
float sampleIncrementX = (float)bounds.width/sampleCount; float sampleIncrementX = (float)bounds.width/sampleCount;

View File

@ -38,7 +38,8 @@ GameScreen currentScreen;
SpriteFont font; SpriteFont font;
Music music; Music music;
int endingStatus; // 1 - Win, 2 - Lose int endingStatus; // 1 - Win, 2 - Lose
//char *sampleFilename;
char *sampleFilename; // Required for custom music file
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { // Prevents name mangling of functions extern "C" { // Prevents name mangling of functions

View File

@ -19,6 +19,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> // Required for: printf()
#include <string.h> // Required for: strcpy()
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h> #include <emscripten/emscripten.h>
#endif #endif
@ -57,20 +60,27 @@ int main(int argc, char *argv[])
{ {
// Initialization // Initialization
//--------------------------------------------------------- //---------------------------------------------------------
/*
#if !defined(PLATFORM_WEB) #if !defined(PLATFORM_WEB)
// TODO: Add support for dropped files on the exe // TODO: Support for dropped files on the exe
sampleFilename = (char *)malloc(256);
// Support command line argument for custom music file
if (argc > 1) if (argc > 1)
{ {
// Just supporting an input argument parameter!!! o__O
if ((IsFileExtension(argv[1], ".ogg")) || if ((IsFileExtension(argv[1], ".ogg")) ||
(IsFileExtension(argv[1], ".wav"))) (IsFileExtension(argv[1], ".wav")))
{ {
if (sampleFilename != NULL) free(sampleFilename);
sampleFilename = (char *)malloc(256);
strcpy(sampleFilename, argv[1]); strcpy(sampleFilename, argv[1]);
printf("Custom audio file: %s", sampleFilename);
} }
} }
#endif #endif
*/
SetConfigFlags(FLAG_MSAA_4X_HINT); SetConfigFlags(FLAG_MSAA_4X_HINT);
InitWindow(screenWidth, screenHeight, "GGJ17 - WAVE COLLECTOR"); InitWindow(screenWidth, screenHeight, "GGJ17 - WAVE COLLECTOR");
@ -104,8 +114,6 @@ int main(int argc, char *argv[])
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
StopMusicStream(music);
switch (currentScreen) switch (currentScreen)
{ {
case LOGO: UnloadLogoScreen(); break; case LOGO: UnloadLogoScreen(); break;