merge with parent
This commit is contained in:
parent
e624973200
commit
e27e431818
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -59,4 +59,6 @@ xcschememanagement.plist
|
||||||
.DS_Store
|
.DS_Store
|
||||||
._.*
|
._.*
|
||||||
xcuserdata/
|
xcuserdata/
|
||||||
DerivedData/
|
DerivedData/
|
||||||
|
*.dll
|
||||||
|
src/libraylib.a
|
||||||
152
README.md
152
README.md
|
|
@ -34,7 +34,7 @@ I've coded quite a lot in C# and XNA and I really love it (in fact, my students
|
||||||
so, I decided to use C# language notation and XNA naming conventions. That way, students can jump from
|
so, I decided to use C# language notation and XNA naming conventions. That way, students can jump from
|
||||||
raylib to XNA, MonoGame or similar libs extremely easily.
|
raylib to XNA, MonoGame or similar libs extremely easily.
|
||||||
|
|
||||||
raylib started as a weekend project and after three months of hard work, first version was published.
|
raylib started as a weekend project and after three months of hard work, raylib 1.0 was published on November 2013.
|
||||||
|
|
||||||
Enjoy it.
|
Enjoy it.
|
||||||
|
|
||||||
|
|
@ -99,14 +99,37 @@ Most of the examples have been completely rewritten and +10 new examples have be
|
||||||
|
|
||||||
Lots of code changes and lot of testing have concluded in this amazing new raylib 1.3.
|
Lots of code changes and lot of testing have concluded in this amazing new raylib 1.3.
|
||||||
|
|
||||||
|
notes on raylib 1.4
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
On February 2016, after 4 months of raylib 1.3 release, it comes raylib 1.4.
|
||||||
|
|
||||||
|
Lots of parts of the library have been reviewed to better accomodate to shaders systems and multiple new features have been added.
|
||||||
|
|
||||||
|
SpriteFonts system has been improved, adding support for AngelCode fonts (.fnt) and TTF fonts (using stb_truetype).
|
||||||
|
|
||||||
|
Finally, raycast system for 3D picking is working, including some ray collision-detection functions.
|
||||||
|
|
||||||
|
A set of Image manipulation functions have been added to crop, resize, colorize, dither and even draw image-to-image or text-to-image.
|
||||||
|
|
||||||
|
Two new functions added for persistent data storage.
|
||||||
|
|
||||||
|
New [physac](https://github.com/raysan5/raylib/blob/develop/src/physac.h) physics module!
|
||||||
|
|
||||||
|
Complete LUA scripting support to allow raylib usage from LUA and LUA scripts support within raylib.
|
||||||
|
|
||||||
|
Up to 8 new examples have been added to show the new raylib features.
|
||||||
|
|
||||||
|
Lots of code changes and lot of testing have concluded in this amazing new raylib 1.4.
|
||||||
|
|
||||||
features
|
features
|
||||||
--------
|
--------
|
||||||
|
|
||||||
* Written in plain C code (C99)
|
* Written in plain C code (C99)
|
||||||
* Uses C# PascalCase/camelCase notation
|
* Uses C# PascalCase/camelCase notation
|
||||||
* Hardware accelerated with OpenGL (1.1, 3.3 or ES2)
|
* Hardware accelerated with OpenGL (1.1, 3.3 or ES2)
|
||||||
* Unique OpenGL abstraction layer: [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.c)
|
* Unique OpenGL abstraction layer (usable as standalone module): [rlgl](https://github.com/raysan5/raylib/blob/master/src/rlgl.c)
|
||||||
* Powerful fonts module with SpriteFonts support
|
* Powerful fonts module with multiple SpriteFonts formats support (XNA bitmap fonts, AngelCode fonts, TTF)
|
||||||
* Outstanding texture formats support, including compressed formats
|
* Outstanding texture formats support, including compressed formats
|
||||||
* Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps
|
* Basic 3d support for Shapes, Models, Billboards, Heightmaps and Cubicmaps
|
||||||
* Powerful math module for Vector and Matrix operations: [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.c)
|
* Powerful math module for Vector and Matrix operations: [raymath](https://github.com/raysan5/raylib/blob/master/src/raymath.c)
|
||||||
|
|
@ -145,126 +168,12 @@ Since raylib v1.1, you can download a Windows Installer package for easy install
|
||||||
building source (generate libraylib.a)
|
building source (generate libraylib.a)
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
|
|
||||||
**Building raylib sources on desktop platforms:**
|
Check raylib wiki page: [Building source](https://github.com/raysan5/raylib/wiki/Building-source)
|
||||||
|
|
||||||
_Step 1:_ Using MinGW make tool, just navigate from command line to `raylib/src/` folder and type:
|
|
||||||
|
|
||||||
mingw32-make PLATFORM=PLATFORM_DESKTOP
|
|
||||||
|
|
||||||
NOTE: By default raylib compiles using OpenGL 1.1 to maximize compatibility; to use OpenGL 3.3 just type:
|
|
||||||
|
|
||||||
mingw32-make PLATFORM=PLATFORM_DESKTOP GRAPHICS=GRAPHICS_API_OPENGL_33
|
|
||||||
|
|
||||||
**Building raylib sources on Raspberry Pi:**
|
|
||||||
|
|
||||||
_Step 1._ Make sure you have installed in your Raspberry Pi OpenAL Soft library for audio:
|
|
||||||
|
|
||||||
sudo apt-get install openal1
|
|
||||||
|
|
||||||
_Step 2._ Navigate from command line to `raylib/src/` folder and type:
|
|
||||||
|
|
||||||
make
|
|
||||||
|
|
||||||
**Building raylib sources for Android:**
|
|
||||||
|
|
||||||
_Step 1._ Make sure you have installed Android SDK, Android NDK and Apache Ant tools:
|
|
||||||
|
|
||||||
> Download and decompress on C: [Android SDK r23](http://dl.google.com/android/android-sdk_r23.0.2-windows.zip)
|
|
||||||
|
|
||||||
> Download and decompress on C: [Android NDK r10b](http://dl.google.com/android/ndk/android-ndk32-r10b-windows-x86.zip)
|
|
||||||
|
|
||||||
> Download and decompress on C: [Apache Ant 1.9.4](http://ftp.cixug.es/apache//ant/binaries/apache-ant-1.9.4-bin.zip)
|
|
||||||
|
|
||||||
_Step 2._ Create the following environment variables with the correct paths:
|
|
||||||
|
|
||||||
ANDROID_SDK_TOOLS = C:\android-sdk\platform-tools
|
|
||||||
ANDROID_NDK_ROOT = C:\android-ndk-r10b
|
|
||||||
ANT_HOME = C:\apache-ant-1.9.4
|
|
||||||
|
|
||||||
_Step 3._ Navigate from command line to folder `raylib/template_android/` and type:
|
|
||||||
|
|
||||||
%ANDROID_NDK_ROOT%\ndk-build
|
|
||||||
|
|
||||||
NOTE: libraylib.a will be generated in folder `raylib/src_android/obj/local/armeabi/`, it must be copied
|
|
||||||
to Android project; if using `raylib/template_android` project, copy it to `raylib/template_android/jni/libs/`.
|
|
||||||
|
|
||||||
**Building raylib sources for Web (HTML5)**
|
|
||||||
|
|
||||||
_Step 1._ Make sure you have installed emscripten SDK:
|
|
||||||
|
|
||||||
> Download latest version from [here](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). I recommend downloading the [Portable Emscripten SDK for Windows](https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-1.25.0-portable-64bit.zip) and decompress it in `C:\emsdk-1.25.0` folder. After that, follow the portable version installation instructions.
|
|
||||||
|
|
||||||
_Step 2._ Open `raylib/src/makefile` on Notepad++ and run the script named `raylib_makefile_emscripten`
|
|
||||||
|
|
||||||
building examples
|
building examples
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
**Building raylib examples on desktop platforms:**
|
Check raylib wiki page: [Building examples](https://github.com/raysan5/raylib/wiki/Building-examples)
|
||||||
|
|
||||||
_Step 1:_ Using MinGW make tool, just navigate from command line to `raylib/examples/` folder and type:
|
|
||||||
|
|
||||||
mingw32-make PLATFORM=PLATFORM_DESKTOP
|
|
||||||
|
|
||||||
NOTE: Make sure the following libs (and their headers) are placed on their respectibe MinGW folders:
|
|
||||||
|
|
||||||
libglfw3.a - GLFW3 (static version)
|
|
||||||
libglew32.a - GLEW, OpenGL extension loading, only required if using OpenGL 3.3+ or ES2
|
|
||||||
libopenal32.a - OpenAL Soft, audio device management
|
|
||||||
|
|
||||||
**Building raylib examples on Raspberry Pi:**
|
|
||||||
|
|
||||||
_Step 1._ Make sure you have installed in your Raspberry Pi OpenAL Soft library for audio:
|
|
||||||
|
|
||||||
sudo apt-get install openal1
|
|
||||||
|
|
||||||
_Step 2._ Navigate from command line to `raylib/examples/` folder and type:
|
|
||||||
|
|
||||||
make
|
|
||||||
|
|
||||||
**Building raylib examples for HTML5 (emscripten):**
|
|
||||||
|
|
||||||
_Step 1._ Make sure you have installed emscripten SDK:
|
|
||||||
|
|
||||||
> Download latest version from [here](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html). I recommend downloading the [Portable Emscripten SDK for Windows](https://s3.amazonaws.com/mozilla-games/emscripten/releases/emsdk-1.25.0-portable-64bit.zip) and decompress it in `C:\emsdk-1.25.0` folder. After that, follow the portable version installation instructions.
|
|
||||||
|
|
||||||
_Step 2._ Open `raylib/examples/makefile` on Notepad++ and run the script named `raylib_makefile_emscripten`
|
|
||||||
|
|
||||||
NOTE: At this moment, raylib examples are not ready to directly compile for HTML5, code needs to be reorganized due to the way web browsers work. To see how code should be refactored to fit compilation for web, check [core_basic_window_web.c](https://github.com/raysan5/raylib/blob/master/examples/core_basic_window_web.c) example.
|
|
||||||
|
|
||||||
**Building raylib project for Android (using template):**
|
|
||||||
|
|
||||||
_Step 1._ Make sure you have installed Android SDK, Android NDK and Apache Ant tools:
|
|
||||||
|
|
||||||
> Download and decompress on C: [Android SDK r23] (http://dl.google.com/android/android-sdk_r23.0.2-windows.zip)
|
|
||||||
|
|
||||||
> Download and decompress on C: [Android NDK r10b] (http://dl.google.com/android/ndk/android-ndk32-r10b-windows-x86.zip)
|
|
||||||
|
|
||||||
> Download and decompress on C: [Apache Ant 1.9.4] (http://ftp.cixug.es/apache//ant/binaries/apache-ant-1.9.4-bin.zip)
|
|
||||||
|
|
||||||
_Step 2._ Create the following environment variables with the correct paths:
|
|
||||||
|
|
||||||
ANDROID_SDK_TOOLS = C:\android-sdk\platform-tools
|
|
||||||
ANDROID_NDK_ROOT = C:\android-ndk-r10b
|
|
||||||
ANT_HOME = C:\apache-ant-1.9.4
|
|
||||||
|
|
||||||
_Step 3._ To compile project, navigate from command line to folder `raylib/template_android/` and type:
|
|
||||||
|
|
||||||
%ANDROID_NDK_ROOT%\ndk-build
|
|
||||||
|
|
||||||
_Step 4._ To generate APK, navigate to folder `raylib/template_android/` and type:
|
|
||||||
|
|
||||||
%ANT_HOME%\bin\ant debug
|
|
||||||
|
|
||||||
_Step 5:_ To install APK into connected device (previously intalled drivers and activated USB debug mode on device):
|
|
||||||
|
|
||||||
%ANT_HOME%\bin\ant installd
|
|
||||||
|
|
||||||
_Step 6:_ To view log output from device:
|
|
||||||
|
|
||||||
%ANDROID_SDK_TOOLS%\adb logcat -c
|
|
||||||
%ANDROID_SDK_TOOLS%\adb -d logcat raylib:V *:S
|
|
||||||
|
|
||||||
**If you have any doubt, [just let me know][raysan5].**
|
|
||||||
|
|
||||||
contact
|
contact
|
||||||
-------
|
-------
|
||||||
|
|
@ -292,6 +201,9 @@ The following people have contributed in some way to make raylib project a reali
|
||||||
- Daniel Moreno for testing and using raylib on a real product ([Koala Seasons](http://www.koalaseasons.com))
|
- Daniel Moreno for testing and using raylib on a real product ([Koala Seasons](http://www.koalaseasons.com))
|
||||||
- Daniel Gomez for testing and using raylib on a real product ([Koala Seasons](http://www.koalaseasons.com))
|
- Daniel Gomez for testing and using raylib on a real product ([Koala Seasons](http://www.koalaseasons.com))
|
||||||
- Sergio Martinez for helping on raygui development and tools development.
|
- Sergio Martinez for helping on raygui development and tools development.
|
||||||
|
- Victor Fisac for developing physics raylib module (physac) and implementing light shaders and raycast system... and multiple tools and games.
|
||||||
|
- Albert Martos for helping on raygui and porting examples and game-templates to Android and HTML5.
|
||||||
|
- Ian Eito for helping on raygui and porting examples and game-templates to Android and HTML5.
|
||||||
|
|
||||||
|
|
||||||
[raysan5]: mailto:raysan@raysanweb.com "Ramon Santamaria - Ray San"
|
[raysan5]: mailto:raysan5@gmail.com "Ramon Santamaria - Ray San"
|
||||||
|
|
|
||||||
13
ROADMAP.md
13
ROADMAP.md
|
|
@ -8,14 +8,17 @@ Around the source code there are multiple TODO points with pending revisions/bug
|
||||||
|
|
||||||
raylib v1.4
|
raylib v1.4
|
||||||
|
|
||||||
- TTF fonts support (using stb_truetype)
|
[DONE] TTF fonts support (using stb_truetype)
|
||||||
- Raycast system for 3D picking (including collisions detection)
|
[DONE] Raycast system for 3D picking (including collisions detection)
|
||||||
|
[DONE] Floyd-Steinberg dithering on 16bit image format conversion
|
||||||
|
[DONE] Basic image manipulation functions (crop, resize, draw...)
|
||||||
|
[DONE] Storage load/save data functionality
|
||||||
|
[DONE] Physics module
|
||||||
|
[IN PROGRESS] LUA scripting support (wrapper to lua lib)
|
||||||
- Remove GLEW dependency (use another solution... glad?)
|
- Remove GLEW dependency (use another solution... glad?)
|
||||||
- Floyd-Steinberg dithering on 16bit image format conversion
|
|
||||||
- Basic image manipulation functions (crop, resize, draw...)
|
|
||||||
- Basic image procedural generation (spot, gradient, noise...)
|
- Basic image procedural generation (spot, gradient, noise...)
|
||||||
- Basic GPU stats sytem (memory, draws, time...)
|
- Basic GPU stats sytem (memory, draws, time...)
|
||||||
- LUA scripting support (wrapper to lua lib)
|
|
||||||
|
|
||||||
Check [GITHUB ISSUES][issues] for further details on implementation status for this features!
|
Check [GITHUB ISSUES][issues] for further details on implementation status for this features!
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ int main()
|
||||||
PlayMusicStream("resources/audio/guitar_noodling.ogg"); // Play music stream
|
PlayMusicStream("resources/audio/guitar_noodling.ogg"); // Play music stream
|
||||||
|
|
||||||
int framesCounter = 0;
|
int framesCounter = 0;
|
||||||
float timePlayed = 0;
|
float timePlayed = 0.0f;
|
||||||
//float volume = 1.0;
|
//float volume = 1.0;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,8 @@ int main()
|
||||||
|
|
||||||
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
|
Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file
|
||||||
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
|
Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
// Generates some random columns
|
// Generates some random columns
|
||||||
float heights[MAX_COLUMNS];
|
float heights[MAX_COLUMNS];
|
||||||
|
|
@ -37,7 +37,7 @@ int main()
|
||||||
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
|
colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 };
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector3 playerPosition = { 4, 2, 4 }; // Define player position
|
Vector3 playerPosition = { 4.0f, 2.0f, 4.0f }; // Define player position
|
||||||
|
|
||||||
SetCameraMode(CAMERA_FIRST_PERSON); // Set a first person camera mode
|
SetCameraMode(CAMERA_FIRST_PERSON); // Set a first person camera mode
|
||||||
|
|
||||||
|
|
@ -60,16 +60,16 @@ int main()
|
||||||
|
|
||||||
Begin3dMode(camera);
|
Begin3dMode(camera);
|
||||||
|
|
||||||
DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 32, 32 }, LIGHTGRAY); // Draw ground
|
DrawPlane((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector2){ 32.0f, 32.0f }, LIGHTGRAY); // Draw ground
|
||||||
DrawCube((Vector3){ -16, 2.5, 0 }, 1, 5, 32, BLUE); // Draw a blue wall
|
DrawCube((Vector3){ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall
|
||||||
DrawCube((Vector3){ 16, 2.5, 0 }, 1, 5, 32, LIME); // Draw a green wall
|
DrawCube((Vector3){ 16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, LIME); // Draw a green wall
|
||||||
DrawCube((Vector3){ 0, 2.5, 16 }, 32, 5, 1, GOLD); // Draw a yellow wall
|
DrawCube((Vector3){ 0.0f, 2.5f, 16.0f }, 32.0f, 5.0f, 1.0f, GOLD); // Draw a yellow wall
|
||||||
|
|
||||||
// Draw some cubes around
|
// Draw some cubes around
|
||||||
for (int i = 0; i < MAX_COLUMNS; i++)
|
for (int i = 0; i < MAX_COLUMNS; i++)
|
||||||
{
|
{
|
||||||
DrawCube(positions[i], 2, heights[i], 2, colors[i]);
|
DrawCube(positions[i], 2.0f, heights[i], 2.0f, colors[i]);
|
||||||
DrawCubeWires(positions[i], 2, heights[i], 2, MAROON);
|
DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON);
|
||||||
}
|
}
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,12 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera;
|
||||||
|
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f };
|
||||||
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0, 0.0, 0.0 };
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
SetCameraMode(CAMERA_FREE); // Set a free camera mode
|
SetCameraMode(CAMERA_FREE); // Set a free camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
||||||
|
|
@ -48,10 +51,10 @@ int main()
|
||||||
|
|
||||||
Begin3dMode(camera);
|
Begin3dMode(camera);
|
||||||
|
|
||||||
DrawCube(cubePosition, 2, 2, 2, RED);
|
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||||
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
|
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||||
|
|
||||||
DrawGrid(10.0, 1.0);
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,14 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera;
|
||||||
|
camera.position = (Vector3){ 0.0f, 10.0f, 10.0f };
|
||||||
|
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
|
||||||
|
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0, 0.0, 0.0 };
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
//SetTargetFPS(60); // Set our game to run at 60 frames-per-second, but not now...
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
|
@ -40,14 +43,14 @@ int main()
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
|
|
||||||
ClearBackground(WHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
Begin3dMode(camera);
|
Begin3dMode(camera);
|
||||||
|
|
||||||
DrawCube(cubePosition, 2, 2, 2, RED);
|
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||||
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
|
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||||
|
|
||||||
DrawGrid(10.0, 1.0);
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,15 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
Vector3 cubePosition = { 0.0, 1.0, 0.0 };
|
Vector3 cubePosition = { 0.0f, 1.0f, 0.0f };
|
||||||
|
Vector3 cubeSize = { 2.0f, 2.0f, 2.0f };
|
||||||
|
|
||||||
Ray ray; // Picking line ray
|
Ray ray; // Picking line ray
|
||||||
|
|
||||||
|
bool collision = false;
|
||||||
|
|
||||||
SetCameraMode(CAMERA_FREE); // Set a free camera mode
|
SetCameraMode(CAMERA_FREE); // Set a free camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
||||||
|
|
||||||
|
|
@ -45,7 +48,10 @@ int main()
|
||||||
// NOTE: This function is NOT WORKING properly!
|
// NOTE: This function is NOT WORKING properly!
|
||||||
ray = GetMouseRay(GetMousePosition(), camera);
|
ray = GetMouseRay(GetMousePosition(), camera);
|
||||||
|
|
||||||
// TODO: Check collision between ray and box
|
// Check collision between ray and box
|
||||||
|
collision = CheckCollisionRayBox(ray,
|
||||||
|
(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 },
|
||||||
|
(Vector3){ cubePosition.x + cubeSize.x/2, cubePosition.y + cubeSize.y/2, cubePosition.z + cubeSize.z/2 });
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -57,16 +63,18 @@ int main()
|
||||||
|
|
||||||
Begin3dMode(camera);
|
Begin3dMode(camera);
|
||||||
|
|
||||||
DrawCube(cubePosition, 2, 2, 2, GRAY);
|
DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY);
|
||||||
DrawCubeWires(cubePosition, 2, 2, 2, DARKGRAY);
|
DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY);
|
||||||
|
|
||||||
DrawGrid(10.0, 1.0);
|
|
||||||
|
|
||||||
DrawRay(ray, MAROON);
|
DrawRay(ray, MAROON);
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
DrawText("Try selecting the box with mouse!", 240, 10, 20, GRAY);
|
DrawText("Try selecting the box with mouse!", 240, 10, 20, GRAY);
|
||||||
|
|
||||||
|
if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN);
|
||||||
|
|
||||||
DrawFPS(10, 10);
|
DrawFPS(10, 10);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ int main()
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ int main()
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad input");
|
||||||
|
|
||||||
Vector2 ballPosition = { screenWidth/2, screenHeight/2 };
|
Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 };
|
||||||
Vector2 gamepadMovement = { 0, 0 };
|
Vector2 gamepadMovement = { 0.0f, 0.0f };
|
||||||
|
|
||||||
SetTargetFPS(60); // Set target frames-per-second
|
SetTargetFPS(60); // Set target frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -43,8 +43,8 @@ int main()
|
||||||
|
|
||||||
if (IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_A))
|
if (IsGamepadButtonPressed(GAMEPAD_PLAYER1, GAMEPAD_BUTTON_A))
|
||||||
{
|
{
|
||||||
ballPosition.x = screenWidth/2;
|
ballPosition.x = (float)screenWidth/2;
|
||||||
ballPosition.y = screenHeight/2;
|
ballPosition.y = (float)screenHeight/2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ int main()
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - keyboard input");
|
||||||
|
|
||||||
Vector2 ballPosition = { screenWidth/2, screenHeight/2 };
|
Vector2 ballPosition = { (float)screenWidth/2, (float)screenHeight/2 };
|
||||||
|
|
||||||
SetTargetFPS(60); // Set target frames-per-second
|
SetTargetFPS(60); // Set target frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -30,10 +30,10 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8;
|
if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8f;
|
||||||
if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8;
|
if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8f;
|
||||||
if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8;
|
if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8f;
|
||||||
if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8;
|
if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8f;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,9 @@ int main()
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - mouse input");
|
||||||
|
|
||||||
int mouseX, mouseY;
|
Vector2 ballPosition = { -100.0f, -100.0f };
|
||||||
Vector2 ballPosition = { -100.0, -100.0 };
|
|
||||||
|
SetTargetFPS(60);
|
||||||
//---------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
|
@ -31,11 +32,7 @@ int main()
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||||
{
|
{
|
||||||
mouseX = GetMouseX();
|
ballPosition = GetMousePosition();
|
||||||
mouseY = GetMouseY();
|
|
||||||
|
|
||||||
ballPosition.x = (float)mouseX;
|
|
||||||
ballPosition.y = (float)mouseY;
|
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ int main()
|
||||||
|
|
||||||
int framesCounter = 0; // Variable used to count frames
|
int framesCounter = 0; // Variable used to count frames
|
||||||
|
|
||||||
int randValue = GetRandomValue(-8,5); // Get a random integer number between -8 and 5 (both included)
|
int randValue = GetRandomValue(-8, 5); // Get a random integer number between -8 and 5 (both included)
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -37,7 +37,7 @@ int main()
|
||||||
// Every two seconds (120 frames) a new random value is generated
|
// Every two seconds (120 frames) a new random value is generated
|
||||||
if (((framesCounter/120)%2) == 1)
|
if (((framesCounter/120)%2) == 1)
|
||||||
{
|
{
|
||||||
randValue = GetRandomValue(-8,5);
|
randValue = GetRandomValue(-8, 5);
|
||||||
framesCounter = 0;
|
framesCounter = 0;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
85
examples/core_storage_values.c
Normal file
85
examples/core_storage_values.c
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - Storage save/load values
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.4 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
// NOTE: Storage positions must start with 0, directly related to file memory layout
|
||||||
|
typedef enum { STORAGE_SCORE = 0, STORAGE_HISCORE } StorageData;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - storage save/load values");
|
||||||
|
|
||||||
|
int score = 0;
|
||||||
|
int hiscore = 0;
|
||||||
|
|
||||||
|
int framesCounter = 0;
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
if (IsKeyPressed(KEY_R))
|
||||||
|
{
|
||||||
|
score = GetRandomValue(1000, 2000);
|
||||||
|
hiscore = GetRandomValue(2000, 4000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_ENTER))
|
||||||
|
{
|
||||||
|
StorageSaveValue(STORAGE_SCORE, score);
|
||||||
|
StorageSaveValue(STORAGE_HISCORE, hiscore);
|
||||||
|
}
|
||||||
|
else if (IsKeyPressed(KEY_SPACE))
|
||||||
|
{
|
||||||
|
// NOTE: If requested position could not be found, value 0 is returned
|
||||||
|
score = StorageLoadValue(STORAGE_SCORE);
|
||||||
|
hiscore = StorageLoadValue(STORAGE_HISCORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
framesCounter++;
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
DrawText(FormatText("SCORE: %i", score), 280, 130, 40, MAROON);
|
||||||
|
DrawText(FormatText("HI-SCORE: %i", hiscore), 210, 200, 50, BLACK);
|
||||||
|
|
||||||
|
DrawText(FormatText("frames: %i", framesCounter), 10, 10, 20, LIME);
|
||||||
|
|
||||||
|
DrawText("Press R to generate random numbers", 220, 40, 20, LIGHTGRAY);
|
||||||
|
DrawText("Press ENTER to SAVE values", 250, 310, 20, LIGHTGRAY);
|
||||||
|
DrawText("Press SPACE to LOAD values", 252, 350, 20, LIGHTGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
examples/core_storage_values.png
Normal file
BIN
examples/core_storage_values.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 16 KiB |
77
examples/core_world_screen.c
Normal file
77
examples/core_world_screen.c
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [core] example - World to screen
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free");
|
||||||
|
|
||||||
|
// Define the camera to look into our 3d world
|
||||||
|
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
|
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
|
||||||
|
|
||||||
|
Vector2 cubeScreenPosition;
|
||||||
|
|
||||||
|
SetCameraMode(CAMERA_FREE); // Set a free camera mode
|
||||||
|
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
||||||
|
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
|
||||||
|
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
UpdateCamera(&camera); // Update internal camera and our camera
|
||||||
|
|
||||||
|
// Calculate cube screen space position (with a little offset to be in top)
|
||||||
|
cubeScreenPosition = WorldToScreen((Vector3){cubePosition.x, cubePosition.y + 2.5f, cubePosition.z}, camera);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
Begin3dMode(camera);
|
||||||
|
|
||||||
|
DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED);
|
||||||
|
DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON);
|
||||||
|
|
||||||
|
DrawGrid(10, 1.0f);
|
||||||
|
|
||||||
|
End3dMode();
|
||||||
|
|
||||||
|
DrawText("Enemy: 100 / 100", cubeScreenPosition.x - MeasureText("Enemy: 100 / 100", 20) / 2, cubeScreenPosition.y, 20, BLACK);
|
||||||
|
DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20)) / 2, 25, 20, GRAY);
|
||||||
|
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
examples/lighting_blinn_phong.png
Normal file
BIN
examples/lighting_blinn_phong.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
|
|
@ -113,8 +113,10 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
ifeq ($(PLATFORM_OS),LINUX)
|
ifeq ($(PLATFORM_OS),LINUX)
|
||||||
# libraries for Debian GNU/Linux desktop compiling
|
# libraries for Debian GNU/Linux desktop compiling
|
||||||
# requires the following packages:
|
# requires the following packages:
|
||||||
# libopenal-dev libglew-dev libegl1-mesa-dev
|
# libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
|
||||||
LIBS = -lraylib -lglfw3 -lGLEW -lGL -lopenal -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor -lm -pthread
|
LIBS = -lraylib -lglfw3 -lGLEW -lGL -lopenal -lm -pthread
|
||||||
|
# on XWindow could require also below libraries, just uncomment
|
||||||
|
#LIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||||
else
|
else
|
||||||
ifeq ($(PLATFORM_OS),OSX)
|
ifeq ($(PLATFORM_OS),OSX)
|
||||||
# libraries for OS X 10.9 desktop compiling
|
# libraries for OS X 10.9 desktop compiling
|
||||||
|
|
@ -134,6 +136,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal
|
LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
|
# just adjust the correct path to libraylib.bc
|
||||||
LIBS = ../src/libraylib.bc
|
LIBS = ../src/libraylib.bc
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 5.0, 4.0, 5.0 }, { 0.0, 2.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera = {{ 5.0f, 4.0f, 5.0f }, { 0.0f, 2.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
|
Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard
|
||||||
Vector3 billPosition = { 0.0, 2.0, 0.0 }; // Position where draw billboard
|
Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard
|
||||||
|
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
||||||
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
||||||
|
|
@ -48,10 +48,10 @@ int main()
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
Begin3dMode(camera);
|
Begin3dMode(camera);
|
||||||
|
|
||||||
DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
|
DrawBillboard(camera, bill, billPosition, 2.0f, WHITE);
|
||||||
|
|
||||||
DrawGrid(10.0, 1.0); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,16 +21,16 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
Vector3 playerPosition = { 0, 1, 2 };
|
Vector3 playerPosition = { 0.0f, 1.0f, 2.0f };
|
||||||
Vector3 playerSize = { 1, 2, 1 };
|
Vector3 playerSize = { 1.0f, 2.0f, 1.0f };
|
||||||
Color playerColor = GREEN;
|
Color playerColor = GREEN;
|
||||||
|
|
||||||
Vector3 enemyBoxPos = { -4, 1, 0 };
|
Vector3 enemyBoxPos = { -4.0f, 1.0f, 0.0f };
|
||||||
Vector3 enemyBoxSize = { 2, 2, 2 };
|
Vector3 enemyBoxSize = { 2.0f, 2.0f, 2.0f };
|
||||||
|
|
||||||
Vector3 enemySpherePos = { 4, 0, 0 };
|
Vector3 enemySpherePos = { 4.0f, 0.0f, 0.0f };
|
||||||
float enemySphereSize = 1.5f;
|
float enemySphereSize = 1.5f;
|
||||||
|
|
||||||
bool collision = false;
|
bool collision = false;
|
||||||
|
|
@ -98,7 +98,7 @@ int main()
|
||||||
// Draw player
|
// Draw player
|
||||||
DrawCubeV(playerPosition, playerSize, playerColor);
|
DrawCubeV(playerPosition, playerSize, playerColor);
|
||||||
|
|
||||||
DrawGrid(10.0, 1.0); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 16.0, 14.0, 16.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
|
Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM)
|
||||||
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
|
Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM)
|
||||||
|
|
@ -31,7 +31,7 @@ int main()
|
||||||
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
|
Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture
|
||||||
SetModelTexture(&map, texture); // Bind texture to map model
|
SetModelTexture(&map, texture); // Bind texture to map model
|
||||||
|
|
||||||
Vector3 mapPosition = { -16, 0.0, -8 }; // Set model position
|
Vector3 mapPosition = { -16.0f, 0.0f, -8.0f }; // Set model position
|
||||||
|
|
||||||
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
|
UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -42,21 +42,21 @@ int main()
|
||||||
|
|
||||||
Begin3dMode(camera);
|
Begin3dMode(camera);
|
||||||
|
|
||||||
DrawCube((Vector3){-4, 0, 2}, 2, 5, 2, RED);
|
DrawCube((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, RED);
|
||||||
DrawCubeWires((Vector3){-4, 0, 2}, 2, 5, 2, GOLD);
|
DrawCubeWires((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, GOLD);
|
||||||
DrawCubeWires((Vector3){-4, 0, -2}, 3, 6, 2, MAROON);
|
DrawCubeWires((Vector3){-4.0f, 0.0f, -2.0f}, 3.0f, 6.0f, 2.0f, MAROON);
|
||||||
|
|
||||||
DrawSphere((Vector3){-1, 0, -2}, 1, GREEN);
|
DrawSphere((Vector3){-1.0f, 0.0f, -2.0f}, 1.0f, GREEN);
|
||||||
DrawSphereWires((Vector3){1, 0, 2}, 2, 16, 16, LIME);
|
DrawSphereWires((Vector3){1.0f, 0.0f, 2.0f}, 2.0f, 16, 16, LIME);
|
||||||
|
|
||||||
DrawCylinder((Vector3){4, 0, -2}, 1, 2, 3, 4, SKYBLUE);
|
DrawCylinder((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, SKYBLUE);
|
||||||
DrawCylinderWires((Vector3){4, 0, -2}, 1, 2, 3, 4, DARKBLUE);
|
DrawCylinderWires((Vector3){4.0f, 0.0f, -2.0f}, 1.0f, 2.0f, 3.0f, 4, DARKBLUE);
|
||||||
DrawCylinderWires((Vector3){4.5, -1, 2}, 1, 1, 2, 6, BROWN);
|
DrawCylinderWires((Vector3){4.5f, -1.0f, 2.0f}, 1.0f, 1.0f, 2.0f, 6, BROWN);
|
||||||
|
|
||||||
DrawCylinder((Vector3){1, 0, -4}, 0, 1.5, 3, 8, GOLD);
|
DrawCylinder((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, GOLD);
|
||||||
DrawCylinderWires((Vector3){1, 0, -4}, 0, 1.5, 3, 8, PINK);
|
DrawCylinderWires((Vector3){1.0f, 0.0f, -4.0f}, 0.0f, 1.5f, 3.0f, 8, PINK);
|
||||||
|
|
||||||
DrawGrid(10.0, 1.0); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,13 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing");
|
||||||
|
|
||||||
// Define our custom camera to look into our 3d world
|
// Define our custom camera to look into our 3d world
|
||||||
Camera camera = {{ 24.0, 18.0, 24.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera = {{ 24.0f, 18.0f, 24.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
|
Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
|
||||||
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
|
Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM)
|
||||||
Model map = LoadHeightmap(image, 32); // Load heightmap model
|
Model map = LoadHeightmap(image, 32); // Load heightmap model
|
||||||
SetModelTexture(&map, texture); // Bind texture to model
|
SetModelTexture(&map, texture); // Bind texture to model
|
||||||
Vector3 mapPosition = { -16, 0.0, -16 }; // Set model position (depends on model scaling!)
|
Vector3 mapPosition = { -16.0f, 0.0f, -16.0f }; // Set model position (depends on model scaling!)
|
||||||
|
|
||||||
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,12 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading");
|
InitWindow(screenWidth, screenHeight, "raylib [models] example - obj model loading");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
|
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
|
||||||
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
|
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
|
||||||
SetModelTexture(&dwarf, texture); // Bind texture to model
|
SetModelTexture(&dwarf, texture); // Bind texture to model
|
||||||
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
@ -49,7 +49,7 @@ int main()
|
||||||
|
|
||||||
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
||||||
|
|
||||||
DrawGrid(10.0, 1.0); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
DrawGizmo(position); // Draw gizmo
|
DrawGizmo(position); // Draw gizmo
|
||||||
|
|
||||||
|
|
|
||||||
144
examples/physics_basic_rigidbody.c
Normal file
144
examples/physics_basic_rigidbody.c
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [physac] physics example - Basic rigidbody
|
||||||
|
*
|
||||||
|
* Welcome to raylib!
|
||||||
|
*
|
||||||
|
* To test examples, just press F6 and execute raylib_compile_execute script
|
||||||
|
* Note that compiled executable is placed in the same folder as .c file
|
||||||
|
*
|
||||||
|
* You can find all basic examples on C:\raylib\raylib\examples folder or
|
||||||
|
* raylib official webpage: www.raylib.com
|
||||||
|
*
|
||||||
|
* Enjoy using raylib. :)
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define OBJECT_SIZE 50
|
||||||
|
#define PLAYER_INDEX 0
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [physics] example - basic rigidbody");
|
||||||
|
SetTargetFPS(60); // Enable v-sync
|
||||||
|
InitPhysics(); // Initialize internal physics values (max rigidbodies/colliders available: 1024)
|
||||||
|
|
||||||
|
// Physics initialization
|
||||||
|
Physics worldPhysics = {true, false, (Vector2){0, -9.81f}};
|
||||||
|
|
||||||
|
// Set internal physics settings
|
||||||
|
SetPhysics(worldPhysics);
|
||||||
|
|
||||||
|
// Object initialization
|
||||||
|
Transform player = (Transform){(Vector2){(screenWidth - OBJECT_SIZE) / 2, (screenHeight - OBJECT_SIZE) / 2}, 0.0f, (Vector2){OBJECT_SIZE, OBJECT_SIZE}};
|
||||||
|
AddCollider(PLAYER_INDEX, (Collider){true, RectangleCollider, (Rectangle){player.position.x, player.position.y, player.scale.x, player.scale.y}, 0});
|
||||||
|
AddRigidbody(PLAYER_INDEX, (Rigidbody){true, 1.0f, (Vector2){0, 0}, (Vector2){0, 0}, false, false, true, 0.5f, 1.0f});
|
||||||
|
|
||||||
|
// Floor initialization
|
||||||
|
// NOTE: floor doesn't need a rigidbody because it's a static physic object, just a collider to collide with other dynamic colliders (with rigidbody)
|
||||||
|
Transform floor = (Transform){(Vector2){0, screenHeight * 0.8f}, 0.0f, (Vector2){screenWidth, screenHeight * 0.2f}};
|
||||||
|
AddCollider(PLAYER_INDEX + 1, (Collider){true, RectangleCollider, (Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, 0});
|
||||||
|
|
||||||
|
// Object properties initialization
|
||||||
|
float moveSpeed = 6.0f;
|
||||||
|
float jumpForce = 4.5f;
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Update object physics
|
||||||
|
// NOTE: all physics detections and reactions are calculated in ApplyPhysics() function (You will live happier :D)
|
||||||
|
ApplyPhysics(PLAYER_INDEX, &player.position);
|
||||||
|
|
||||||
|
// Check jump button input
|
||||||
|
if(IsKeyDown(KEY_SPACE) && GetRigidbody(PLAYER_INDEX).isGrounded)
|
||||||
|
{
|
||||||
|
// Reset object Y velocity to avoid double jumping cases but keep the same X velocity that it already has
|
||||||
|
SetRigidbodyVelocity(PLAYER_INDEX, (Vector2){GetRigidbody(PLAYER_INDEX).velocity.x, 0});
|
||||||
|
|
||||||
|
// Add jumping force in Y axis
|
||||||
|
AddRigidbodyForce(PLAYER_INDEX, (Vector2){0, jumpForce});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check movement buttons input
|
||||||
|
if(IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D))
|
||||||
|
{
|
||||||
|
// Set rigidbody velocity in X based on moveSpeed value and apply the same Y velocity that it already has
|
||||||
|
SetRigidbodyVelocity(PLAYER_INDEX, (Vector2){moveSpeed, GetRigidbody(PLAYER_INDEX).velocity.y});
|
||||||
|
}
|
||||||
|
else if(IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A))
|
||||||
|
{
|
||||||
|
// Set rigidbody velocity in X based on moveSpeed negative value and apply the same Y velocity that it already has
|
||||||
|
SetRigidbodyVelocity(PLAYER_INDEX, (Vector2){-moveSpeed, GetRigidbody(PLAYER_INDEX).velocity.y});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check debug mode toggle button input
|
||||||
|
if(IsKeyPressed(KEY_P))
|
||||||
|
{
|
||||||
|
// Update program physics value
|
||||||
|
worldPhysics.debug = !worldPhysics.debug;
|
||||||
|
|
||||||
|
// Update internal physics value
|
||||||
|
SetPhysics(worldPhysics);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
// Draw information
|
||||||
|
DrawText("Use LEFT / RIGHT to MOVE and SPACE to JUMP", (screenWidth - MeasureText("Use LEFT / RIGHT to MOVE and SPACE to JUMP", 20)) / 2, screenHeight * 0.20f, 20, LIGHTGRAY);
|
||||||
|
DrawText("Use P to switch DEBUG MODE", (screenWidth - MeasureText("Use P to switch DEBUG MODE", 20)) / 2, screenHeight * 0.3f, 20, LIGHTGRAY);
|
||||||
|
|
||||||
|
// Check if debug mode is enabled
|
||||||
|
if(worldPhysics.debug)
|
||||||
|
{
|
||||||
|
// Draw every internal physics stored collider if it is active
|
||||||
|
for(int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
if(GetCollider(i).enabled)
|
||||||
|
{
|
||||||
|
DrawRectangleLines(GetCollider(i).bounds.x, GetCollider(i).bounds.y, GetCollider(i).bounds.width, GetCollider(i).bounds.height, GREEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Draw player
|
||||||
|
DrawRectangleRec((Rectangle){player.position.x, player.position.y, player.scale.x, player.scale.y}, GRAY);
|
||||||
|
|
||||||
|
// Draw floor
|
||||||
|
DrawRectangleRec((Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
examples/physics_basic_rigidbody.png
Normal file
BIN
examples/physics_basic_rigidbody.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
141
examples/physics_rigidbody_force.c
Normal file
141
examples/physics_rigidbody_force.c
Normal file
|
|
@ -0,0 +1,141 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [physac] physics example - Rigidbody forces
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define MAX_OBJECTS 5
|
||||||
|
#define OBJECTS_OFFSET 150
|
||||||
|
|
||||||
|
#define FORCE_INTENSITY 250.0f // Customize by user
|
||||||
|
#define FORCE_RADIUS 100 // Customize by user
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
int screenWidth = 800;
|
||||||
|
int screenHeight = 450;
|
||||||
|
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [physics] example - rigidbodies forces");
|
||||||
|
SetTargetFPS(60); // Enable v-sync
|
||||||
|
InitPhysics(); // Initialize internal physics values (max rigidbodies/colliders available: 1024)
|
||||||
|
|
||||||
|
// Physics initialization
|
||||||
|
Physics worldPhysics = {true, false, (Vector2){0, -9.81f}};
|
||||||
|
|
||||||
|
// Set internal physics settings
|
||||||
|
SetPhysics(worldPhysics);
|
||||||
|
|
||||||
|
// Objects initialization
|
||||||
|
Transform objects[MAX_OBJECTS];
|
||||||
|
for(int i = 0; i < MAX_OBJECTS; i++)
|
||||||
|
{
|
||||||
|
objects[i] = (Transform){(Vector2){75 + OBJECTS_OFFSET * i, (screenHeight - 50) / 2}, 0.0f, (Vector2){50, 50}};
|
||||||
|
AddCollider(i, (Collider){true, RectangleCollider, (Rectangle){objects[i].position.x, objects[i].position.y, objects[i].scale.x, objects[i].scale.y}, 0});
|
||||||
|
AddRigidbody(i, (Rigidbody){true, 1.0f, (Vector2){0, 0}, (Vector2){0, 0}, false, false, true, 0.5f, 0.5f});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Floor initialization
|
||||||
|
// NOTE: floor doesn't need a rigidbody because it's a static physic object, just a collider to collide with other dynamic colliders (with rigidbody)
|
||||||
|
Transform floor = (Transform){(Vector2){0, screenHeight * 0.8f}, 0.0f, (Vector2){screenWidth, screenHeight * 0.2f}};
|
||||||
|
AddCollider(MAX_OBJECTS, (Collider){true, RectangleCollider, (Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, 0});
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Update object physics
|
||||||
|
// NOTE: all physics detections and reactions are calculated in ApplyPhysics() function (You will live happier :D)
|
||||||
|
for(int i = 0; i < MAX_OBJECTS; i++)
|
||||||
|
{
|
||||||
|
ApplyPhysics(i, &objects[i].position);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check foce button input
|
||||||
|
if(IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||||
|
{
|
||||||
|
AddForceAtPosition(GetMousePosition(), FORCE_INTENSITY, FORCE_RADIUS);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check debug mode toggle button input
|
||||||
|
if(IsKeyPressed(KEY_P))
|
||||||
|
{
|
||||||
|
// Update program physics value
|
||||||
|
worldPhysics.debug = !worldPhysics.debug;
|
||||||
|
|
||||||
|
// Update internal physics value
|
||||||
|
SetPhysics(worldPhysics);
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
// Check if debug mode is enabled
|
||||||
|
if(worldPhysics.debug)
|
||||||
|
{
|
||||||
|
// Draw every internal physics stored collider if it is active (floor included)
|
||||||
|
for(int i = 0; i < MAX_OBJECTS + 1; i++)
|
||||||
|
{
|
||||||
|
if(GetCollider(i).enabled)
|
||||||
|
{
|
||||||
|
// Draw collider bounds
|
||||||
|
DrawRectangleLines(GetCollider(i).bounds.x, GetCollider(i).bounds.y, GetCollider(i).bounds.width, GetCollider(i).bounds.height, GREEN);
|
||||||
|
|
||||||
|
// Check if current collider is not floor
|
||||||
|
if(i < MAX_OBJECTS)
|
||||||
|
{
|
||||||
|
// Draw lines between mouse position and objects if they are in force range
|
||||||
|
if(CheckCollisionPointCircle(GetMousePosition(), (Vector2){GetCollider(i).bounds.x + GetCollider(i).bounds.width / 2, GetCollider(i).bounds.y + GetCollider(i).bounds.height / 2}, FORCE_RADIUS))
|
||||||
|
{
|
||||||
|
DrawLineV(GetMousePosition(), (Vector2){GetCollider(i).bounds.x + GetCollider(i).bounds.width / 2, GetCollider(i).bounds.y + GetCollider(i).bounds.height / 2}, RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw radius circle
|
||||||
|
DrawCircleLines(GetMousePosition().x, GetMousePosition().y, FORCE_RADIUS, RED);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Draw objects
|
||||||
|
for(int i = 0; i < MAX_OBJECTS; i++)
|
||||||
|
{
|
||||||
|
DrawRectangleRec((Rectangle){objects[i].position.x, objects[i].position.y, objects[i].scale.x, objects[i].scale.y}, GRAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw floor
|
||||||
|
DrawRectangleRec((Rectangle){floor.position.x, floor.position.y, floor.scale.x, floor.scale.y}, BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Draw help messages
|
||||||
|
DrawText("Use LEFT MOUSE BUTTON to create a force in mouse position", (screenWidth - MeasureText("Use LEFT MOUSE BUTTON to create a force in mouse position", 20)) / 2, screenHeight * 0.20f, 20, LIGHTGRAY);
|
||||||
|
DrawText("Use P to switch DEBUG MODE", (screenWidth - MeasureText("Use P to switch DEBUG MODE", 20)) / 2, screenHeight * 0.3f, 20, LIGHTGRAY);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
examples/physics_rigidbody_force.png
Normal file
BIN
examples/physics_rigidbody_force.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
6433
examples/resources/model/shapes.obj
Normal file
6433
examples/resources/model/shapes.obj
Normal file
File diff suppressed because it is too large
Load Diff
|
|
@ -6,8 +6,7 @@ in vec3 vertexNormal;
|
||||||
|
|
||||||
out vec2 fragTexCoord;
|
out vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 mvpMatrix;
|
||||||
uniform mat4 modelviewMatrix;
|
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
@ -15,5 +14,5 @@ void main()
|
||||||
{
|
{
|
||||||
fragTexCoord = vertexTexCoord;
|
fragTexCoord = vertexTexCoord;
|
||||||
|
|
||||||
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
|
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,16 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
|
vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
|
||||||
|
|
||||||
// Convert to grayscale using NTSC conversion weights
|
// Convert to grayscale using NTSC conversion weights
|
||||||
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
|
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
|
||||||
|
|
||||||
fragColor = vec4(gray, gray, gray, tintColor.a);
|
fragColor = vec4(gray, gray, gray, fragTintColor.a);
|
||||||
}
|
}
|
||||||
76
examples/resources/shaders/phong.fs
Normal file
76
examples/resources/shaders/phong.fs
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
#version 330
|
||||||
|
|
||||||
|
// Vertex shader input data
|
||||||
|
in vec2 fragTexCoord;
|
||||||
|
in vec3 fragNormal;
|
||||||
|
|
||||||
|
// Diffuse data
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
|
// Light attributes
|
||||||
|
uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0.0);
|
||||||
|
uniform vec3 light_diffuseColor = vec3(1.0, 0.5, 0.0);
|
||||||
|
uniform vec3 light_specularColor = vec3(0.0, 1.0, 0.0);
|
||||||
|
uniform float light_intensity = 1.0;
|
||||||
|
uniform float light_specIntensity = 1.0;
|
||||||
|
|
||||||
|
// Material attributes
|
||||||
|
uniform vec3 mat_ambientColor = vec3(1.0, 1.0, 1.0);
|
||||||
|
uniform vec3 mat_specularColor = vec3(1.0, 1.0, 1.0);
|
||||||
|
uniform float mat_glossiness = 50.0;
|
||||||
|
|
||||||
|
// World attributes
|
||||||
|
uniform vec3 lightPos;
|
||||||
|
uniform vec3 cameraPos;
|
||||||
|
|
||||||
|
// Fragment shader output data
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
vec3 AmbientLighting()
|
||||||
|
{
|
||||||
|
return (mat_ambientColor*light_ambientColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 DiffuseLighting(in vec3 N, in vec3 L)
|
||||||
|
{
|
||||||
|
// Lambertian reflection calculation
|
||||||
|
float diffuse = clamp(dot(N, L), 0, 1);
|
||||||
|
|
||||||
|
return (fragTintColor.xyz*light_diffuseColor*light_intensity*diffuse);
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V)
|
||||||
|
{
|
||||||
|
float specular = 0.0;
|
||||||
|
|
||||||
|
// Calculate specular reflection only if the surface is oriented to the light source
|
||||||
|
if (dot(N, L) > 0)
|
||||||
|
{
|
||||||
|
// Calculate half vector
|
||||||
|
vec3 H = normalize(L + V);
|
||||||
|
|
||||||
|
// Calculate specular intensity
|
||||||
|
specular = pow(dot(N, H), 3 + mat_glossiness);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (mat_specularColor*light_specularColor*light_specIntensity*specular);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Normalize input vectors
|
||||||
|
vec3 L = normalize(lightPos);
|
||||||
|
vec3 V = normalize(cameraPos);
|
||||||
|
vec3 N = normalize(fragNormal);
|
||||||
|
|
||||||
|
vec3 ambient = AmbientLighting();
|
||||||
|
vec3 diffuse = DiffuseLighting(N, L);
|
||||||
|
vec3 specular = SpecularLighting(N, L, V);
|
||||||
|
|
||||||
|
// Get base color from texture
|
||||||
|
vec4 textureColor = texture(texture0, fragTexCoord);
|
||||||
|
vec3 finalColor = textureColor.rgb;
|
||||||
|
|
||||||
|
fragColor = vec4(finalColor * (ambient + diffuse + specular), textureColor.a);
|
||||||
|
}
|
||||||
27
examples/resources/shaders/phong.vs
Normal file
27
examples/resources/shaders/phong.vs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
#version 330
|
||||||
|
|
||||||
|
// Vertex input data
|
||||||
|
in vec3 vertexPosition;
|
||||||
|
in vec2 vertexTexCoord;
|
||||||
|
in vec3 vertexNormal;
|
||||||
|
|
||||||
|
// Projection and model data
|
||||||
|
uniform mat4 mvpMatrix;
|
||||||
|
uniform mat4 modelMatrix;
|
||||||
|
|
||||||
|
// Attributes to fragment shader
|
||||||
|
out vec2 fragTexCoord;
|
||||||
|
out vec3 fragNormal;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Send texture coord to fragment shader
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
|
||||||
|
// Calculate view vector normal from model
|
||||||
|
mat3 normalMatrix = transpose(inverse(mat3(modelMatrix)));
|
||||||
|
fragNormal = normalize(normalMatrix*vertexNormal);
|
||||||
|
|
||||||
|
// Calculate final vertex position
|
||||||
|
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
|
|
@ -4,16 +4,15 @@ attribute vec3 vertexPosition;
|
||||||
attribute vec2 vertexTexCoord;
|
attribute vec2 vertexTexCoord;
|
||||||
attribute vec4 vertexColor;
|
attribute vec4 vertexColor;
|
||||||
|
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 mvpMatrix;
|
||||||
uniform mat4 modelviewMatrix;
|
|
||||||
|
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
varying vec4 fragColor;
|
varying vec4 fragTintColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
fragTexCoord = vertexTexCoord;
|
fragTexCoord = vertexTexCoord;
|
||||||
fragColor = vertexColor;
|
fragTintColor = vertexColor;
|
||||||
|
|
||||||
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
|
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||||
}
|
}
|
||||||
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
varying vec4 fragColor;
|
varying vec4 fragTintColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 base = texture2D(texture0, fragTexCoord)*fragColor;
|
vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
|
||||||
|
|
||||||
// Convert to grayscale using NTSC conversion weights
|
// Convert to grayscale using NTSC conversion weights
|
||||||
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
|
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,17 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
const float renderWidth = 800; // HARDCODED for example!
|
const float renderWidth = 800.0; // HARDCODED for example!
|
||||||
const float renderHeight = 480; // Use uniforms instead...
|
const float renderHeight = 480.0; // Use uniforms instead...
|
||||||
|
|
||||||
float radius = 250.0;
|
float radius = 250.0;
|
||||||
float angle = 0.8;
|
float angle = 0.8;
|
||||||
|
|
||||||
uniform vec2 center = vec2(200, 200);
|
uniform vec2 center = vec2(200.0, 200.0);
|
||||||
|
|
||||||
void main (void)
|
void main (void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
152
examples/shaders_basic_lighting.c
Normal file
152
examples/shaders_basic_lighting.c
Normal file
|
|
@ -0,0 +1,152 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* raylib [shaders] example - Basic lighting: Blinn-Phong
|
||||||
|
*
|
||||||
|
* This example has been created using raylib 1.3 (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
|
||||||
|
#define SHININESS_SPEED 1.0f
|
||||||
|
#define LIGHT_SPEED 0.25f
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 800;
|
||||||
|
const int screenHeight = 450;
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_MSAA_4X_HINT);
|
||||||
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - basic lighting");
|
||||||
|
|
||||||
|
// Camera initialization
|
||||||
|
Camera camera = {{ 8.0f, 8.0f, 8.0f }, { 0.0f, 3.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
|
// Model initialization
|
||||||
|
Vector3 position = { 0.0f, 0.0f, 0.0f };
|
||||||
|
Model model = LoadModel("resources/model/dwarf.obj");
|
||||||
|
Shader shader = LoadShader("resources/shaders/phong.vs", "resources/shaders/phong.fs");
|
||||||
|
SetModelShader(&model, shader);
|
||||||
|
|
||||||
|
// Shader locations initialization
|
||||||
|
int lIntensityLoc = GetShaderLocation(shader, "light_intensity");
|
||||||
|
int lAmbientLoc = GetShaderLocation(shader, "light_ambientColor");
|
||||||
|
int lDiffuseLoc = GetShaderLocation(shader, "light_diffuseColor");
|
||||||
|
int lSpecularLoc = GetShaderLocation(shader, "light_specularColor");
|
||||||
|
int lSpecIntensityLoc = GetShaderLocation(shader, "light_specIntensity");
|
||||||
|
|
||||||
|
int mAmbientLoc = GetShaderLocation(shader, "mat_ambientColor");
|
||||||
|
int mSpecularLoc = GetShaderLocation(shader, "mat_specularColor");
|
||||||
|
int mGlossLoc = GetShaderLocation(shader, "mat_glossiness");
|
||||||
|
|
||||||
|
// Camera and light vectors shader locations
|
||||||
|
int cameraLoc = GetShaderLocation(shader, "cameraPos");
|
||||||
|
int lightLoc = GetShaderLocation(shader, "lightPos");
|
||||||
|
|
||||||
|
// Light and material definitions
|
||||||
|
Light light;
|
||||||
|
Material matBlinn;
|
||||||
|
|
||||||
|
// Light initialization
|
||||||
|
light.position = (Vector3){ 4.0f, 2.0f, 0.0f };
|
||||||
|
light.direction = (Vector3){ 5.0f, 1.0f, 1.0f };
|
||||||
|
light.intensity = 1.0f;
|
||||||
|
light.diffuse = WHITE;
|
||||||
|
light.ambient = (Color){ 150, 75, 0, 255 };
|
||||||
|
light.specular = WHITE;
|
||||||
|
light.specIntensity = 1.0f;
|
||||||
|
|
||||||
|
// Material initialization
|
||||||
|
matBlinn.diffuse = WHITE;
|
||||||
|
matBlinn.ambient = (Color){ 50, 50, 50, 255 };
|
||||||
|
matBlinn.specular = WHITE;
|
||||||
|
matBlinn.glossiness = 50.0f;
|
||||||
|
|
||||||
|
// Setup camera
|
||||||
|
SetCameraMode(CAMERA_FREE); // Set camera mode
|
||||||
|
SetCameraPosition(camera.position); // Set internal camera position to match our camera position
|
||||||
|
SetCameraTarget(camera.target); // Set internal camera target to match our camera target
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
UpdateCamera(&camera); // Update camera position
|
||||||
|
|
||||||
|
// Glossiness input control
|
||||||
|
if(IsKeyDown(KEY_UP)) matBlinn.glossiness += SHININESS_SPEED;
|
||||||
|
else if(IsKeyDown(KEY_DOWN))
|
||||||
|
{
|
||||||
|
matBlinn.glossiness -= SHININESS_SPEED;
|
||||||
|
if( matBlinn.glossiness < 0) matBlinn.glossiness = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Light X movement
|
||||||
|
if (IsKeyDown(KEY_D)) light.position.x += LIGHT_SPEED;
|
||||||
|
else if(IsKeyDown(KEY_A)) light.position.x -= LIGHT_SPEED;
|
||||||
|
|
||||||
|
// Light Y movement
|
||||||
|
if (IsKeyDown(KEY_LEFT_SHIFT)) light.position.y += LIGHT_SPEED;
|
||||||
|
else if (IsKeyDown(KEY_LEFT_CONTROL)) light.position.y -= LIGHT_SPEED;
|
||||||
|
|
||||||
|
// Light Z movement
|
||||||
|
if (IsKeyDown(KEY_S)) light.position.z += LIGHT_SPEED;
|
||||||
|
else if (IsKeyDown(KEY_W)) light.position.z -= LIGHT_SPEED;
|
||||||
|
|
||||||
|
// Send light values to shader
|
||||||
|
SetShaderValue(shader, lIntensityLoc, &light.intensity, 1);
|
||||||
|
SetShaderValue(shader, lAmbientLoc, ColorToFloat(light.ambient), 3);
|
||||||
|
SetShaderValue(shader, lDiffuseLoc, ColorToFloat(light.diffuse), 3);
|
||||||
|
SetShaderValue(shader, lSpecularLoc, ColorToFloat(light.specular), 3);
|
||||||
|
SetShaderValue(shader, lSpecIntensityLoc, &light.specIntensity, 1);
|
||||||
|
|
||||||
|
// Send material values to shader
|
||||||
|
SetShaderValue(shader, mAmbientLoc, ColorToFloat(matBlinn.ambient), 3);
|
||||||
|
SetShaderValue(shader, mSpecularLoc, ColorToFloat(matBlinn.specular), 3);
|
||||||
|
SetShaderValue(shader, mGlossLoc, &matBlinn.glossiness, 1);
|
||||||
|
|
||||||
|
// Send camera and light transform values to shader
|
||||||
|
SetShaderValue(shader, cameraLoc, VectorToFloat(camera.position), 3);
|
||||||
|
SetShaderValue(shader, lightLoc, VectorToFloat(light.position), 3);
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
Begin3dMode(camera);
|
||||||
|
|
||||||
|
DrawModel(model, position, 4.0f, matBlinn.diffuse);
|
||||||
|
DrawSphere(light.position, 0.5f, GOLD);
|
||||||
|
|
||||||
|
DrawGrid(20, 1.0f);
|
||||||
|
|
||||||
|
End3dMode();
|
||||||
|
|
||||||
|
DrawFPS(10, 10); // Draw FPS
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
UnloadShader(shader);
|
||||||
|
UnloadModel(model);
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -30,13 +30,13 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - custom uniform variable");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
|
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
|
||||||
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
|
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
|
||||||
SetModelTexture(&dwarf, texture); // Bind texture to model
|
SetModelTexture(&dwarf, texture); // Bind texture to model
|
||||||
|
|
||||||
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
Shader shader = LoadShader("resources/shaders/base.vs",
|
Shader shader = LoadShader("resources/shaders/base.vs",
|
||||||
"resources/shaders/swirl.fs"); // Load postpro shader
|
"resources/shaders/swirl.fs"); // Load postpro shader
|
||||||
|
|
@ -45,7 +45,7 @@ int main()
|
||||||
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
// NOTE: If uniform variable could not be found in the shader, function returns -1
|
||||||
int swirlCenterLoc = GetShaderLocation(shader, "center");
|
int swirlCenterLoc = GetShaderLocation(shader, "center");
|
||||||
|
|
||||||
float swirlCenter[2] = { screenWidth/2, screenHeight/2 };
|
float swirlCenter[2] = { (float)screenWidth/2, (float)screenHeight/2 };
|
||||||
|
|
||||||
SetPostproShader(shader); // Set fullscreen postprocessing shader
|
SetPostproShader(shader); // Set fullscreen postprocessing shader
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ int main()
|
||||||
|
|
||||||
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
||||||
|
|
||||||
DrawGrid(10.0, 1.0); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
|
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
|
||||||
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
|
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
|
||||||
|
|
@ -40,7 +40,7 @@ int main()
|
||||||
SetModelShader(&dwarf, shader); // Set shader effect to 3d model
|
SetModelShader(&dwarf, shader); // Set shader effect to 3d model
|
||||||
SetModelTexture(&dwarf, texture); // Bind texture to model
|
SetModelTexture(&dwarf, texture); // Bind texture to model
|
||||||
|
|
||||||
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
// Setup orbital camera
|
// Setup orbital camera
|
||||||
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode
|
||||||
|
|
@ -68,7 +68,7 @@ int main()
|
||||||
|
|
||||||
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
||||||
|
|
||||||
DrawGrid(10.0, 1.0); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,13 @@ int main()
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader");
|
InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader");
|
||||||
|
|
||||||
// Define the camera to look into our 3d world
|
// Define the camera to look into our 3d world
|
||||||
Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }};
|
Camera camera = {{ 3.0f, 3.0f, 3.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }};
|
||||||
|
|
||||||
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
|
Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model
|
||||||
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
|
Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture
|
||||||
SetModelTexture(&dwarf, texture); // Bind texture to model
|
SetModelTexture(&dwarf, texture); // Bind texture to model
|
||||||
|
|
||||||
Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position
|
Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position
|
||||||
|
|
||||||
Shader shader = LoadShader("resources/shaders/base.vs",
|
Shader shader = LoadShader("resources/shaders/base.vs",
|
||||||
"resources/shaders/bloom.fs"); // Load postpro shader
|
"resources/shaders/bloom.fs"); // Load postpro shader
|
||||||
|
|
@ -69,7 +69,7 @@ int main()
|
||||||
|
|
||||||
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture
|
||||||
|
|
||||||
DrawGrid(10.0, 1.0); // Draw a grid
|
DrawGrid(10, 1.0f); // Draw a grid
|
||||||
|
|
||||||
End3dMode();
|
End3dMode();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ int main()
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing");
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - basic shapes drawing");
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ int main()
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette");
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib color palette");
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ int main()
|
||||||
int screenHeight = 450;
|
int screenHeight = 450;
|
||||||
|
|
||||||
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes");
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - raylib logo using shapes");
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Main game loop
|
// Main game loop
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,7 @@ int main()
|
||||||
char raylib[8] = " \0"; // raylib text array, max 8 letters
|
char raylib[8] = " \0"; // raylib text array, max 8 letters
|
||||||
|
|
||||||
int state = 0; // Tracking animation states (State Machine)
|
int state = 0; // Tracking animation states (State Machine)
|
||||||
|
float alpha = 1.0f; // Useful for fading
|
||||||
float alpha = 1.0; // Useful for fading
|
|
||||||
|
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,7 @@ int main()
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
DrawTexture(texture, screenWidth/2 - texture.width/2,
|
DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);
|
||||||
screenHeight/2 - texture.height/2, WHITE);
|
|
||||||
|
|
||||||
DrawText("this IS a texture!", 360, 370, 10, GRAY);
|
DrawText("this IS a texture!", 360, 370, 10, GRAY);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,12 +41,12 @@ int main()
|
||||||
mouseTail[i].position = (Vector2){ 0, 0 };
|
mouseTail[i].position = (Vector2){ 0, 0 };
|
||||||
mouseTail[i].color = (Color){ GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 };
|
mouseTail[i].color = (Color){ GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 };
|
||||||
mouseTail[i].alpha = 1.0f;
|
mouseTail[i].alpha = 1.0f;
|
||||||
mouseTail[i].size = (float)GetRandomValue(1, 30)/20;
|
mouseTail[i].size = (float)GetRandomValue(1, 30)/20.0f;
|
||||||
mouseTail[i].rotation = GetRandomValue(0, 360);
|
mouseTail[i].rotation = GetRandomValue(0, 360);
|
||||||
mouseTail[i].active = false;
|
mouseTail[i].active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
float gravity = 3;
|
float gravity = 3.0f;
|
||||||
|
|
||||||
Texture2D smoke = LoadTexture("resources/smoke.png");
|
Texture2D smoke = LoadTexture("resources/smoke.png");
|
||||||
|
|
||||||
|
|
@ -85,7 +85,7 @@ int main()
|
||||||
|
|
||||||
if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false;
|
if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false;
|
||||||
|
|
||||||
mouseTail[i].rotation += 5;
|
mouseTail[i].rotation += 5.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ int main()
|
||||||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||||
Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading
|
Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading
|
||||||
|
|
||||||
Vector2 position = { 350, 240 };
|
Vector2 position = { 350.0f, 240.0f };
|
||||||
Rectangle frameRec = { 0, 0, guybrush.width/7, guybrush.height };
|
Rectangle frameRec = { 0, 0, guybrush.width/7, guybrush.height };
|
||||||
int currentFrame = 0;
|
int currentFrame = 0;
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,6 @@
|
||||||
*
|
*
|
||||||
* raylib game - Floppy Bird
|
* raylib game - Floppy Bird
|
||||||
*
|
*
|
||||||
* Welcome to raylib!
|
|
||||||
*
|
|
||||||
* To test examples, just press F6 and execute raylib_compile_execute script
|
|
||||||
* Note that compiled executable is placed in the same folder as .c file
|
|
||||||
*
|
|
||||||
* You can find all basic examples on C:\raylib\raylib\examples folder or
|
|
||||||
* raylib official webpage: www.raylib.com
|
|
||||||
*
|
|
||||||
* Enjoy using raylib. :)
|
|
||||||
*
|
|
||||||
* This game has been created using raylib 1.1 (www.raylib.com)
|
* This game has been created using raylib 1.1 (www.raylib.com)
|
||||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
*
|
*
|
||||||
|
|
@ -86,10 +76,21 @@ int main()
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
backScroll--;
|
|
||||||
|
|
||||||
|
// Background scroll logic
|
||||||
|
backScroll--;
|
||||||
if (backScroll <= -800) backScroll = 0;
|
if (backScroll <= -800) backScroll = 0;
|
||||||
|
|
||||||
|
// Player movement logic
|
||||||
|
if (!gameover)
|
||||||
|
{
|
||||||
|
if (IsKeyDown(KEY_SPACE)) floppyPos.y -= 3;
|
||||||
|
else floppyPos.y += 1;
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_SPACE)) PlaySound(jump);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tubes moving logic
|
||||||
for (int i = 0; i < MAX_TUBES; i++) tubesPos[i].x -= tubesSpeedX;
|
for (int i = 0; i < MAX_TUBES; i++) tubesPos[i].x -= tubesSpeedX;
|
||||||
|
|
||||||
for (int i = 0; i < MAX_TUBES*2; i += 2)
|
for (int i = 0; i < MAX_TUBES*2; i += 2)
|
||||||
|
|
@ -98,12 +99,7 @@ int main()
|
||||||
tubesRecs[i+1].x = tubesPos[i/2].x;
|
tubesRecs[i+1].x = tubesPos[i/2].x;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsKeyDown(KEY_SPACE) && !gameover) floppyPos.y -= 3;
|
// Check collisions player-tubes
|
||||||
else floppyPos.y += 1;
|
|
||||||
|
|
||||||
if (IsKeyPressed(KEY_SPACE) && !gameover) PlaySound(jump);
|
|
||||||
|
|
||||||
// Check Collisions
|
|
||||||
for (int i = 0; i < MAX_TUBES*2; i++)
|
for (int i = 0; i < MAX_TUBES*2; i++)
|
||||||
{
|
{
|
||||||
if (CheckCollisionCircleRec((Vector2){ floppyPos.x + floppy.width/2, floppyPos.y + floppy.height/2 }, floppy.width/2, tubesRecs[i]))
|
if (CheckCollisionCircleRec((Vector2){ floppyPos.x + floppy.width/2, floppyPos.y + floppy.height/2 }, floppy.width/2, tubesRecs[i]))
|
||||||
|
|
@ -122,6 +118,7 @@ int main()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gameover logic for reset
|
||||||
if (gameover && IsKeyPressed(KEY_ENTER))
|
if (gameover && IsKeyPressed(KEY_ENTER))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < MAX_TUBES; i++)
|
for (int i = 0; i < MAX_TUBES; i++)
|
||||||
|
|
@ -147,7 +144,6 @@ int main()
|
||||||
gameover = false;
|
gameover = false;
|
||||||
score = 0;
|
score = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Draw
|
// Draw
|
||||||
|
|
@ -156,32 +152,39 @@ int main()
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
// Draw scrolling background
|
||||||
DrawTexture(background, backScroll, 0, WHITE);
|
DrawTexture(background, backScroll, 0, WHITE);
|
||||||
DrawTexture(background, screenWidth + backScroll, 0, WHITE);
|
DrawTexture(background, screenWidth + backScroll, 0, WHITE);
|
||||||
|
|
||||||
if (!gameover)
|
// Draw moving tubes
|
||||||
{
|
|
||||||
DrawTextureEx(floppy, floppyPos, 0, 1.0, WHITE);
|
|
||||||
//DrawCircleLines(floppyPos.x + floppy.width/2, floppyPos.y + floppy.height/2, floppy.width/2, RED);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_TUBES; i++)
|
for (int i = 0; i < MAX_TUBES; i++)
|
||||||
{
|
{
|
||||||
if (tubesPos[i].x <= 800) DrawTextureEx(tubes, tubesPos[i], 0, 1.0, WHITE);
|
if (tubesPos[i].x <= 800) DrawTextureEx(tubes, tubesPos[i], 0, 1.0, WHITE);
|
||||||
|
|
||||||
|
// Draw collision recs
|
||||||
//DrawRectangleLines(tubesRecs[i*2].x, tubesRecs[i*2].y, tubesRecs[i*2].width, tubesRecs[i*2].height, RED);
|
//DrawRectangleLines(tubesRecs[i*2].x, tubesRecs[i*2].y, tubesRecs[i*2].width, tubesRecs[i*2].height, RED);
|
||||||
//DrawRectangleLines(tubesRecs[i*2 + 1].x, tubesRecs[i*2 + 1].y, tubesRecs[i*2 + 1].width, tubesRecs[i*2 + 1].height, RED);
|
//DrawRectangleLines(tubesRecs[i*2 + 1].x, tubesRecs[i*2 + 1].y, tubesRecs[i*2 + 1].width, tubesRecs[i*2 + 1].height, RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw scores
|
||||||
DrawText(FormatText("%04i", score), 20, 20, 40, PINK);
|
DrawText(FormatText("%04i", score), 20, 20, 40, PINK);
|
||||||
DrawText(FormatText("HI-SCORE: %04i", hiscore), 20, 70, 20, VIOLET);
|
DrawText(FormatText("HI-SCORE: %04i", hiscore), 20, 70, 20, VIOLET);
|
||||||
|
|
||||||
if (gameover)
|
// Draw player or game over messages
|
||||||
|
if (!gameover)
|
||||||
|
{
|
||||||
|
DrawTextureEx(floppy, floppyPos, 0, 1.0, WHITE);
|
||||||
|
|
||||||
|
// Draw collision circle
|
||||||
|
//DrawCircleLines(floppyPos.x + floppy.width/2, floppyPos.y + floppy.height/2, floppy.width/2, RED);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
DrawText("GAME OVER", 100, 180, 100, MAROON);
|
DrawText("GAME OVER", 100, 180, 100, MAROON);
|
||||||
DrawText("PRESS ENTER to RETRY!", 280, 280, 20, RED);
|
DrawText("PRESS ENTER to RETRY!", 280, 280, 20, RED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw screen light flash when passing through a tube
|
||||||
if (superfx)
|
if (superfx)
|
||||||
{
|
{
|
||||||
DrawRectangle(0, 0, screenWidth, screenHeight, GOLD);
|
DrawRectangle(0, 0, screenWidth, screenHeight, GOLD);
|
||||||
|
|
|
||||||
358
games/just_do/just_do.c
Normal file
358
games/just_do/just_do.c
Normal file
|
|
@ -0,0 +1,358 @@
|
||||||
|
/*******************************************************************************************
|
||||||
|
*
|
||||||
|
* JUST DO - Global Game Jam 2015 Videogame
|
||||||
|
* Experimental puzzle game that lets the user try to find a logic solution to
|
||||||
|
* different shape-color-based situations.
|
||||||
|
*
|
||||||
|
* Developed by: Ramon Santamaria (Ray San)
|
||||||
|
*
|
||||||
|
* This game has been created using raylib (www.raylib.com)
|
||||||
|
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||||
|
*
|
||||||
|
* raylib - Copyright (c) 2015 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
|
*
|
||||||
|
********************************************************************************************/
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "screens/screens.h" // NOTE: Defines currentScreen
|
||||||
|
|
||||||
|
#if defined(PLATFORM_WEB)
|
||||||
|
#include <emscripten/emscripten.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Global Variables Definition (local to this module)
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
const int screenWidth = 1280; // Moved to screens.h
|
||||||
|
const int screenHeight = 720; // Moved to screens.h
|
||||||
|
|
||||||
|
// Required variables to manage screen transitions (fade-in, fade-out)
|
||||||
|
float transAlpha = 0;
|
||||||
|
bool onTransition = false;
|
||||||
|
bool transFadeOut = false;
|
||||||
|
int transFromScreen = -1;
|
||||||
|
int transToScreen = -1;
|
||||||
|
int framesCounter = 0;
|
||||||
|
|
||||||
|
//static Sound levelWin;
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Local Functions Declaration
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
void TransitionToScreen(int screen);
|
||||||
|
void UpdateTransition(void);
|
||||||
|
void DrawTransition(void);
|
||||||
|
|
||||||
|
void UpdateDrawFrame(void); // Update and Draw one frame
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Main entry point
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
// Initialization
|
||||||
|
//---------------------------------------------------------
|
||||||
|
const char windowTitle[30] = "JUST DO";
|
||||||
|
|
||||||
|
//SetupFlags(FLAG_FULLSCREEN_MODE);
|
||||||
|
InitWindow(screenWidth, screenHeight, windowTitle);
|
||||||
|
|
||||||
|
// TODO: Load global data here (assets that must be available in all screens, i.e. fonts)
|
||||||
|
InitAudioDevice();
|
||||||
|
|
||||||
|
levelWin = LoadSound("resources/win.wav");
|
||||||
|
|
||||||
|
// Setup and Init first screen
|
||||||
|
currentScreen = LOGO;
|
||||||
|
InitLogoScreen();
|
||||||
|
|
||||||
|
#if defined(PLATFORM_WEB)
|
||||||
|
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||||
|
#else
|
||||||
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Main game loop
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
|
||||||
|
if (IsKeyPressed(KEY_SPACE)) PlaySound(levelWin);
|
||||||
|
|
||||||
|
UpdateDrawFrame();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// De-Initialization
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// TODO: Unload all global loaded data (i.e. fonts) here!
|
||||||
|
UnloadSound(levelWin);
|
||||||
|
|
||||||
|
CloseAudioDevice();
|
||||||
|
|
||||||
|
CloseWindow(); // Close window and OpenGL context
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
// Local Functions Definition
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
void TransitionToScreen(int screen)
|
||||||
|
{
|
||||||
|
onTransition = true;
|
||||||
|
transFromScreen = currentScreen;
|
||||||
|
transToScreen = screen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateTransition(void)
|
||||||
|
{
|
||||||
|
if (!transFadeOut)
|
||||||
|
{
|
||||||
|
transAlpha += 0.02f;
|
||||||
|
|
||||||
|
if (transAlpha >= 1.0)
|
||||||
|
{
|
||||||
|
transAlpha = 1.0;
|
||||||
|
currentScreen = transToScreen;
|
||||||
|
transFadeOut = true;
|
||||||
|
framesCounter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // Transition fade out logic
|
||||||
|
{
|
||||||
|
transAlpha -= 0.02f;
|
||||||
|
|
||||||
|
if (transAlpha <= 0)
|
||||||
|
{
|
||||||
|
transAlpha = 0;
|
||||||
|
transFadeOut = false;
|
||||||
|
onTransition = false;
|
||||||
|
transFromScreen = -1;
|
||||||
|
transToScreen = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DrawTransition(void)
|
||||||
|
{
|
||||||
|
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(RAYWHITE, transAlpha));
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpdateDrawFrame(void)
|
||||||
|
{
|
||||||
|
// Update
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
if (!onTransition)
|
||||||
|
{
|
||||||
|
if (IsKeyPressed('0'))
|
||||||
|
{
|
||||||
|
TransitionToScreen(LEVEL00);
|
||||||
|
InitLevel00Screen();
|
||||||
|
}
|
||||||
|
else if (IsKeyPressed('1'))
|
||||||
|
{
|
||||||
|
TransitionToScreen(LEVEL01);
|
||||||
|
InitLevel01Screen();
|
||||||
|
}
|
||||||
|
else if (IsKeyPressed('2'))
|
||||||
|
{
|
||||||
|
TransitionToScreen(LEVEL02);
|
||||||
|
InitLevel02Screen();
|
||||||
|
}
|
||||||
|
else if (IsKeyPressed('3'))
|
||||||
|
{
|
||||||
|
TransitionToScreen(LEVEL03);
|
||||||
|
InitLevel03Screen();
|
||||||
|
}
|
||||||
|
else if (IsKeyPressed('4'))
|
||||||
|
{
|
||||||
|
TransitionToScreen(LEVEL04);
|
||||||
|
InitLevel04Screen();
|
||||||
|
}
|
||||||
|
else if (IsKeyPressed('5'))
|
||||||
|
{
|
||||||
|
TransitionToScreen(LEVEL05);
|
||||||
|
InitLevel05Screen();
|
||||||
|
}
|
||||||
|
else if (IsKeyPressed('6'))
|
||||||
|
{
|
||||||
|
TransitionToScreen(LEVEL06);
|
||||||
|
InitLevel06Screen();
|
||||||
|
}
|
||||||
|
else if (IsKeyPressed('7'))
|
||||||
|
{
|
||||||
|
TransitionToScreen(LEVEL07);
|
||||||
|
InitLevel07Screen();
|
||||||
|
}
|
||||||
|
else if (IsKeyPressed('8'))
|
||||||
|
{
|
||||||
|
TransitionToScreen(LEVEL08);
|
||||||
|
InitLevel08Screen();
|
||||||
|
}
|
||||||
|
else if (IsKeyPressed('9'))
|
||||||
|
{
|
||||||
|
TransitionToScreen(LEVEL09);
|
||||||
|
InitLevel08Screen();
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(currentScreen)
|
||||||
|
{
|
||||||
|
case LOGO:
|
||||||
|
{
|
||||||
|
UpdateLogoScreen();
|
||||||
|
|
||||||
|
if (FinishLogoScreen())
|
||||||
|
{
|
||||||
|
UnloadLogoScreen();
|
||||||
|
TransitionToScreen(LEVEL00);
|
||||||
|
InitLevel00Screen();
|
||||||
|
|
||||||
|
PlayMusicStream("resources/ambient.ogg");
|
||||||
|
SetMusicVolume(0.6f);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case LEVEL00:
|
||||||
|
{
|
||||||
|
UpdateLevel00Screen();
|
||||||
|
|
||||||
|
if (FinishLevel00Screen())
|
||||||
|
{
|
||||||
|
UnloadLevel00Screen();
|
||||||
|
TransitionToScreen(LEVEL01);
|
||||||
|
InitLevel01Screen();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case LEVEL01:
|
||||||
|
{
|
||||||
|
UpdateLevel01Screen();
|
||||||
|
|
||||||
|
if (FinishLevel01Screen())
|
||||||
|
{
|
||||||
|
UnloadLevel01Screen();
|
||||||
|
TransitionToScreen(LEVEL02);
|
||||||
|
InitLevel02Screen();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case LEVEL02:
|
||||||
|
{
|
||||||
|
UpdateLevel02Screen();
|
||||||
|
|
||||||
|
if (FinishLevel02Screen())
|
||||||
|
{
|
||||||
|
UnloadLevel02Screen();
|
||||||
|
TransitionToScreen(LEVEL03);
|
||||||
|
InitLevel03Screen();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case LEVEL03:
|
||||||
|
{
|
||||||
|
UpdateLevel03Screen();
|
||||||
|
|
||||||
|
if (FinishLevel03Screen())
|
||||||
|
{
|
||||||
|
UnloadLevel03Screen();
|
||||||
|
TransitionToScreen(LEVEL04);
|
||||||
|
InitLevel04Screen();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case LEVEL04:
|
||||||
|
{
|
||||||
|
UpdateLevel04Screen();
|
||||||
|
|
||||||
|
if (FinishLevel04Screen())
|
||||||
|
{
|
||||||
|
UnloadLevel04Screen();
|
||||||
|
TransitionToScreen(LEVEL05);
|
||||||
|
InitLevel05Screen();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case LEVEL05:
|
||||||
|
{
|
||||||
|
UpdateLevel05Screen();
|
||||||
|
|
||||||
|
if (FinishLevel05Screen())
|
||||||
|
{
|
||||||
|
UnloadLevel05Screen();
|
||||||
|
TransitionToScreen(LEVEL06);
|
||||||
|
InitLevel06Screen();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case LEVEL06:
|
||||||
|
{
|
||||||
|
UpdateLevel06Screen();
|
||||||
|
|
||||||
|
if (FinishLevel06Screen())
|
||||||
|
{
|
||||||
|
UnloadLevel06Screen();
|
||||||
|
TransitionToScreen(LEVEL07);
|
||||||
|
InitLevel07Screen();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case LEVEL07:
|
||||||
|
{
|
||||||
|
UpdateLevel07Screen();
|
||||||
|
|
||||||
|
if (FinishLevel07Screen())
|
||||||
|
{
|
||||||
|
UnloadLevel07Screen();
|
||||||
|
TransitionToScreen(LEVEL08);
|
||||||
|
InitLevel08Screen();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case LEVEL08:
|
||||||
|
{
|
||||||
|
UpdateLevel08Screen();
|
||||||
|
|
||||||
|
if (FinishLevel08Screen())
|
||||||
|
{
|
||||||
|
UnloadLevel08Screen();
|
||||||
|
TransitionToScreen(LEVEL09);
|
||||||
|
InitLevel09Screen();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case LEVEL09:
|
||||||
|
{
|
||||||
|
UpdateLevel09Screen();
|
||||||
|
|
||||||
|
if (FinishLevel09Screen())
|
||||||
|
{
|
||||||
|
UnloadLevel09Screen();
|
||||||
|
TransitionToScreen(LEVEL00);
|
||||||
|
InitLevel00Screen();
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else UpdateTransition(); // Update transition (fade-in, fade-out)
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
switch(currentScreen)
|
||||||
|
{
|
||||||
|
case LOGO: DrawLogoScreen(); break;
|
||||||
|
case LEVEL00: DrawLevel00Screen(); break;
|
||||||
|
case LEVEL01: DrawLevel01Screen(); break;
|
||||||
|
case LEVEL02: DrawLevel02Screen(); break;
|
||||||
|
case LEVEL03: DrawLevel03Screen(); break;
|
||||||
|
case LEVEL04: DrawLevel04Screen(); break;
|
||||||
|
case LEVEL05: DrawLevel05Screen(); break;
|
||||||
|
case LEVEL06: DrawLevel06Screen(); break;
|
||||||
|
case LEVEL07: DrawLevel07Screen(); break;
|
||||||
|
case LEVEL08: DrawLevel08Screen(); break;
|
||||||
|
case LEVEL09: DrawLevel09Screen(); break;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onTransition) DrawTransition();
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
246
games/just_do/makefile
Normal file
246
games/just_do/makefile
Normal file
|
|
@ -0,0 +1,246 @@
|
||||||
|
#**************************************************************************************************
|
||||||
|
#
|
||||||
|
# raylib - Advance Game
|
||||||
|
#
|
||||||
|
# makefile to compile advance game for desktop platforms, Raspberry Pi and HTML5 (emscripten)
|
||||||
|
#
|
||||||
|
# Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||||
|
#
|
||||||
|
# This software is provided "as-is", without any express or implied warranty. In no event
|
||||||
|
# will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
#
|
||||||
|
# Permission is granted to anyone to use this software for any purpose, including commercial
|
||||||
|
# applications, and to alter it and redistribute it freely, subject to the following restrictions:
|
||||||
|
#
|
||||||
|
# 1. The origin of this software must not be misrepresented; you must not claim that you
|
||||||
|
# wrote the original software. If you use this software in a product, an acknowledgment
|
||||||
|
# in the product documentation would be appreciated but is not required.
|
||||||
|
#
|
||||||
|
# 2. Altered source versions must be plainly marked as such, and must not be misrepresented
|
||||||
|
# as being the original software.
|
||||||
|
#
|
||||||
|
# 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
#
|
||||||
|
#**************************************************************************************************
|
||||||
|
|
||||||
|
# define raylib platform to compile for
|
||||||
|
# possible platforms: PLATFORM_DESKTOP PLATFORM_RPI PLATFORM_WEB
|
||||||
|
# WARNING: To compile to HTML5, code must be redesigned to use emscripten.h and emscripten_set_main_loop()
|
||||||
|
PLATFORM ?= PLATFORM_DESKTOP
|
||||||
|
|
||||||
|
# determine PLATFORM_OS in case PLATFORM_DESKTOP selected
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
|
# No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
PLATFORM_OS=WINDOWS
|
||||||
|
LIBPATH=win32
|
||||||
|
else
|
||||||
|
UNAMEOS:=$(shell uname)
|
||||||
|
ifeq ($(UNAMEOS),Linux)
|
||||||
|
PLATFORM_OS=LINUX
|
||||||
|
LIBPATH=linux
|
||||||
|
else
|
||||||
|
ifeq ($(UNAMEOS),Darwin)
|
||||||
|
PLATFORM_OS=OSX
|
||||||
|
LIBPATH=osx
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
# define compiler: gcc for C program, define as g++ for C++
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
|
# define emscripten compiler
|
||||||
|
CC = emcc
|
||||||
|
else
|
||||||
|
ifeq ($(PLATFORM_OS),OSX)
|
||||||
|
# define llvm compiler for mac
|
||||||
|
CC = clang
|
||||||
|
else
|
||||||
|
# define default gcc compiler
|
||||||
|
CC = gcc
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
# define compiler flags:
|
||||||
|
# -O2 defines optimization level
|
||||||
|
# -Wall turns on most, but not all, compiler warnings
|
||||||
|
# -std=c99 use standard C from 1999 revision
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
CFLAGS = -O2 -Wall -std=gnu99 -fgnu89-inline
|
||||||
|
else
|
||||||
|
CFLAGS = -O2 -Wall -std=c99
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
|
CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3
|
||||||
|
#-s ASSERTIONS=1 --preload-file resources
|
||||||
|
#-s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing
|
||||||
|
#-s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
|
||||||
|
endif
|
||||||
|
|
||||||
|
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||||
|
|
||||||
|
# define any directories containing required header files
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
INCLUDES = -I. -I../../src -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
|
||||||
|
else
|
||||||
|
INCLUDES = -I. -I../../src -I../../../src
|
||||||
|
# external libraries headers
|
||||||
|
# GLFW3
|
||||||
|
INCLUDES += -I../../external/glfw3/include
|
||||||
|
# GLEW
|
||||||
|
INCLUDES += -I../../external/glew/include
|
||||||
|
# OpenAL Soft
|
||||||
|
INCLUDES += -I../../external/openal_soft/include
|
||||||
|
endif
|
||||||
|
|
||||||
|
# define library paths containing required libs
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
LFLAGS = -L. -L../../src -L/opt/vc/lib
|
||||||
|
else
|
||||||
|
LFLAGS = -L. -L../../src -L../../../src
|
||||||
|
# external libraries to link with
|
||||||
|
# GLFW3
|
||||||
|
LFLAGS += -L../../external/glfw3/lib/$(LIBPATH)
|
||||||
|
ifneq ($(PLATFORM_OS),OSX)
|
||||||
|
# OpenAL Soft
|
||||||
|
LFLAGS += -L../../external/openal_soft/lib/$(LIBPATH)
|
||||||
|
# GLEW
|
||||||
|
LFLAGS += -L../../external/glew/lib/$(LIBPATH)
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
# define any libraries to link into executable
|
||||||
|
# if you want to link libraries (libname.so or libname.a), use the -lname
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
|
ifeq ($(PLATFORM_OS),LINUX)
|
||||||
|
# libraries for Debian GNU/Linux desktop compiling
|
||||||
|
# requires the following packages:
|
||||||
|
# libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
|
||||||
|
LIBS = -lraylib -lglfw -lGLEW -lGL -lopenal
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM_OS),OSX)
|
||||||
|
# libraries for OS X 10.9 desktop compiling
|
||||||
|
# requires the following packages:
|
||||||
|
# libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
|
||||||
|
LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAl -framework Cocoa
|
||||||
|
else
|
||||||
|
# libraries for Windows desktop compiling
|
||||||
|
# NOTE: GLFW3 and OpenAL Soft libraries should be installed
|
||||||
|
LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
# libraries for Raspberry Pi compiling
|
||||||
|
# NOTE: OpenAL Soft library should be installed (libopenal1 package)
|
||||||
|
LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
|
LIBS = ../../src/libraylib.bc
|
||||||
|
endif
|
||||||
|
|
||||||
|
# define additional parameters and flags for windows
|
||||||
|
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
|
# resources file contains windows exe icon
|
||||||
|
# -Wl,--subsystem,windows hides the console window
|
||||||
|
WINFLAGS = ../../src/resources -Wl,--subsystem,windows
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
|
EXT = .html
|
||||||
|
endif
|
||||||
|
|
||||||
|
# define all screen object files required
|
||||||
|
SCREENS = \
|
||||||
|
screens/screen_logo.o \
|
||||||
|
screens/screen_level00.o \
|
||||||
|
screens/screen_level01.o \
|
||||||
|
screens/screen_level02.o \
|
||||||
|
screens/screen_level03.o \
|
||||||
|
screens/screen_level04.o \
|
||||||
|
screens/screen_level05.o \
|
||||||
|
screens/screen_level06.o \
|
||||||
|
screens/screen_level07.o \
|
||||||
|
screens/screen_level08.o \
|
||||||
|
screens/screen_level09.o \
|
||||||
|
|
||||||
|
# typing 'make' will invoke the first target entry in the file,
|
||||||
|
# in this case, the 'default' target entry is just_do
|
||||||
|
default: just_do
|
||||||
|
|
||||||
|
# compile just_do
|
||||||
|
just_do: just_do.c $(SCREENS)
|
||||||
|
$(CC) -o $@$(EXT) $< $(SCREENS) $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
|
# compile screen LOGO
|
||||||
|
screens/screen_logo.o: screens/screen_logo.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile screen LEVEL00
|
||||||
|
screens/screen_level00.o: screens/screen_level00.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile screen LEVEL01
|
||||||
|
screens/screen_level01.o: screens/screen_level01.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile screen LEVEL02
|
||||||
|
screens/screen_level02.o: screens/screen_level02.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile screen LEVEL03
|
||||||
|
screens/screen_level03.o: screens/screen_level03.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile screen LEVEL04
|
||||||
|
screens/screen_level04.o: screens/screen_level04.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile screen LEVEL05
|
||||||
|
screens/screen_level05.o: screens/screen_level05.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile screen LEVEL06
|
||||||
|
screens/screen_level06.o: screens/screen_level06.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile screen LEVEL07
|
||||||
|
screens/screen_level07.o: screens/screen_level07.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile screen LEVEL08
|
||||||
|
screens/screen_level08.o: screens/screen_level08.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# compile screen LEVEL09
|
||||||
|
screens/screen_level09.o: screens/screen_level09.c
|
||||||
|
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
|
||||||
|
|
||||||
|
# clean everything
|
||||||
|
clean:
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
|
ifeq ($(PLATFORM_OS),OSX)
|
||||||
|
find . -type f -perm +ugo+x -delete
|
||||||
|
rm -f *.o
|
||||||
|
else
|
||||||
|
ifeq ($(PLATFORM_OS),LINUX)
|
||||||
|
find . -type f -executable -delete
|
||||||
|
rm -f *.o
|
||||||
|
else
|
||||||
|
del *.o *.exe
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
|
find . -type f -executable -delete
|
||||||
|
rm -f *.o
|
||||||
|
endif
|
||||||
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
|
del *.o *.html *.js
|
||||||
|
endif
|
||||||
|
@echo Cleaning done
|
||||||
|
|
||||||
|
# instead of defining every module one by one, we can define a pattern
|
||||||
|
# this pattern below will automatically compile every module defined on $(OBJS)
|
||||||
|
#%.exe : %.c
|
||||||
|
# $(CC) -o $@ $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM)
|
||||||
BIN
games/just_do/resources/ambient.ogg
Normal file
BIN
games/just_do/resources/ambient.ogg
Normal file
Binary file not shown.
BIN
games/just_do/resources/win.wav
Normal file
BIN
games/just_do/resources/win.wav
Normal file
Binary file not shown.
167
games/just_do/screens/screen_level00.c
Normal file
167
games/just_do/screens/screen_level00.c
Normal 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);
|
||||||
|
}
|
||||||
163
games/just_do/screens/screen_level01.c
Normal file
163
games/just_do/screens/screen_level01.c
Normal 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;
|
||||||
|
}
|
||||||
170
games/just_do/screens/screen_level02.c
Normal file
170
games/just_do/screens/screen_level02.c
Normal 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;
|
||||||
|
}
|
||||||
134
games/just_do/screens/screen_level03.c
Normal file
134
games/just_do/screens/screen_level03.c
Normal 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;
|
||||||
|
}
|
||||||
147
games/just_do/screens/screen_level04.c
Normal file
147
games/just_do/screens/screen_level04.c
Normal 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;
|
||||||
|
}
|
||||||
185
games/just_do/screens/screen_level05.c
Normal file
185
games/just_do/screens/screen_level05.c
Normal 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));
|
||||||
|
}
|
||||||
156
games/just_do/screens/screen_level06.c
Normal file
156
games/just_do/screens/screen_level06.c
Normal 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;
|
||||||
|
}
|
||||||
178
games/just_do/screens/screen_level07.c
Normal file
178
games/just_do/screens/screen_level07.c
Normal 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));
|
||||||
|
}
|
||||||
157
games/just_do/screens/screen_level08.c
Normal file
157
games/just_do/screens/screen_level08.c
Normal 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;
|
||||||
|
}
|
||||||
199
games/just_do/screens/screen_level09.c
Normal file
199
games/just_do/screens/screen_level09.c
Normal 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));
|
||||||
|
}
|
||||||
153
games/just_do/screens/screen_level10.c
Normal file
153
games/just_do/screens/screen_level10.c
Normal 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;
|
||||||
|
}
|
||||||
227
games/just_do/screens/screen_logo.c
Normal file
227
games/just_do/screens/screen_logo.c
Normal 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;
|
||||||
|
}
|
||||||
150
games/just_do/screens/screens.h
Normal file
150
games/just_do/screens/screens.h
Normal 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
|
||||||
|
|
@ -6,8 +6,7 @@ in vec3 vertexNormal;
|
||||||
|
|
||||||
out vec2 fragTexCoord;
|
out vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 mvpMatrix;
|
||||||
uniform mat4 modelviewMatrix;
|
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
@ -15,5 +14,5 @@ void main()
|
||||||
{
|
{
|
||||||
fragTexCoord = vertexTexCoord;
|
fragTexCoord = vertexTexCoord;
|
||||||
|
|
||||||
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
|
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
@ -18,23 +18,23 @@ void main()
|
||||||
{
|
{
|
||||||
for (int j = -3; j < 3; j++)
|
for (int j = -3; j < 3; j++)
|
||||||
{
|
{
|
||||||
sum += texture2D(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25;
|
sum += texture(texture0, fragTexCoord + vec2(j, i)*0.004) * 0.25;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texture2D(texture0, fragTexCoord).r < 0.3)
|
if (texture(texture0, fragTexCoord).r < 0.3)
|
||||||
{
|
{
|
||||||
tc = sum*sum*0.012 + texture2D(texture0, fragTexCoord);
|
tc = sum*sum*0.012 + texture(texture0, fragTexCoord);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (texture2D(texture0, fragTexCoord).r < 0.5)
|
if (texture(texture0, fragTexCoord).r < 0.5)
|
||||||
{
|
{
|
||||||
tc = sum*sum*0.009 + texture2D(texture0, fragTexCoord);
|
tc = sum*sum*0.009 + texture(texture0, fragTexCoord);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tc = sum*sum*0.0075 + texture2D(texture0, fragTexCoord);
|
tc = sum*sum*0.0075 + texture(texture0, fragTexCoord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,24 +5,24 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
const float renderWidth = 1280;
|
const float renderWidth = 1280.0;
|
||||||
const float renderHeight = 720;
|
const float renderHeight = 720.0;
|
||||||
|
|
||||||
float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
|
float offset[3] = float[](0.0, 1.3846153846, 3.2307692308);
|
||||||
float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
|
float weight[3] = float[](0.2270270270, 0.3162162162, 0.0702702703);
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 tc = texture2D(texture0, fragTexCoord).rgb*weight[0];
|
vec3 tc = texture(texture0, fragTexCoord).rgb*weight[0];
|
||||||
|
|
||||||
for (int i = 1; i < 3; i++)
|
for (int i = 1; i < 3; i++)
|
||||||
{
|
{
|
||||||
tc += texture2D(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
|
tc += texture(texture0, fragTexCoord + vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
|
||||||
tc += texture2D(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
|
tc += texture(texture0, fragTexCoord - vec2(offset[i])/renderWidth, 0.0).rgb*weight[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
fragColor = vec4(tc, 1.0);
|
fragColor = vec4(tc, 1.0);
|
||||||
|
|
|
||||||
|
|
@ -5,20 +5,20 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
float hatchOffsetY = 5.0f;
|
float hatchOffsetY = 5.0;
|
||||||
float lumThreshold01 = 0.9f;
|
float lumThreshold01 = 0.9;
|
||||||
float lumThreshold02 = 0.7f;
|
float lumThreshold02 = 0.7;
|
||||||
float lumThreshold03 = 0.5f;
|
float lumThreshold03 = 0.5;
|
||||||
float lumThreshold04 = 0.3f;
|
float lumThreshold04 = 0.3;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 tc = vec3(1.0, 1.0, 1.0);
|
vec3 tc = vec3(1.0, 1.0, 1.0);
|
||||||
float lum = length(texture2D(texture0, fragTexCoord).rgb);
|
float lum = length(texture(texture0, fragTexCoord).rgb);
|
||||||
|
|
||||||
if (lum < lumThreshold01)
|
if (lum < lumThreshold01)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,14 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
const float renderWidth = 1280;
|
const float renderWidth = 1280.0;
|
||||||
const float renderHeight = 720;
|
const float renderHeight = 720.0;
|
||||||
|
|
||||||
float stitchingSize = 6.0f;
|
float stitchingSize = 6.0;
|
||||||
|
|
||||||
uniform int invert = 0;
|
uniform int invert = 0;
|
||||||
|
|
||||||
|
|
@ -35,11 +35,11 @@ vec4 PostFX(sampler2D tex, vec2 uv)
|
||||||
if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y)))))
|
if ((remX == remY) || (((int(cPos.x) - int(blPos.x)) == (int(blPos.y) - int(cPos.y)))))
|
||||||
{
|
{
|
||||||
if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0);
|
if (invert == 1) c = vec4(0.2, 0.15, 0.05, 1.0);
|
||||||
else c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
else c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (invert == 1) c = texture2D(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
if (invert == 1) c = texture(tex, tlPos * vec2(1.0/renderWidth, 1.0/renderHeight)) * 1.4;
|
||||||
else c = vec4(0.0, 0.0, 0.0, 1.0);
|
else c = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,27 +5,27 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 color = texture2D(texture0, fragTexCoord);
|
vec4 color = texture(texture0, fragTexCoord);
|
||||||
|
|
||||||
color += texture2D(texture0, fragTexCoord + 0.001);
|
color += texture(texture0, fragTexCoord + 0.001);
|
||||||
color += texture2D(texture0, fragTexCoord + 0.003);
|
color += texture(texture0, fragTexCoord + 0.003);
|
||||||
color += texture2D(texture0, fragTexCoord + 0.005);
|
color += texture(texture0, fragTexCoord + 0.005);
|
||||||
color += texture2D(texture0, fragTexCoord + 0.007);
|
color += texture(texture0, fragTexCoord + 0.007);
|
||||||
color += texture2D(texture0, fragTexCoord + 0.009);
|
color += texture(texture0, fragTexCoord + 0.009);
|
||||||
color += texture2D(texture0, fragTexCoord + 0.011);
|
color += texture(texture0, fragTexCoord + 0.011);
|
||||||
|
|
||||||
color += texture2D(texture0, fragTexCoord - 0.001);
|
color += texture(texture0, fragTexCoord - 0.001);
|
||||||
color += texture2D(texture0, fragTexCoord - 0.003);
|
color += texture(texture0, fragTexCoord - 0.003);
|
||||||
color += texture2D(texture0, fragTexCoord - 0.005);
|
color += texture(texture0, fragTexCoord - 0.005);
|
||||||
color += texture2D(texture0, fragTexCoord - 0.007);
|
color += texture(texture0, fragTexCoord - 0.007);
|
||||||
color += texture2D(texture0, fragTexCoord - 0.009);
|
color += texture(texture0, fragTexCoord - 0.009);
|
||||||
color += texture2D(texture0, fragTexCoord - 0.011);
|
color += texture(texture0, fragTexCoord - 0.011);
|
||||||
|
|
||||||
color.rgb = vec3((color.r + color.g + color.b)/3.0);
|
color.rgb = vec3((color.r + color.g + color.b)/3.0);
|
||||||
color = color/9.5;
|
color = color/9.5;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ const float PI = 3.1415926535;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
float aperture = 178.0f;
|
float aperture = 178.0;
|
||||||
float apertureHalf = 0.5 * aperture * (PI / 180.0);
|
float apertureHalf = 0.5 * aperture * (PI / 180.0);
|
||||||
float maxFactor = sin(apertureHalf);
|
float maxFactor = sin(apertureHalf);
|
||||||
|
|
||||||
|
|
@ -36,5 +36,5 @@ void main()
|
||||||
uv = fragTexCoord.xy;
|
uv = fragTexCoord.xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
fragColor = texture2D(texture0, uv);
|
fragColor = texture(texture0, uv);
|
||||||
}
|
}
|
||||||
|
|
@ -5,16 +5,16 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
|
vec4 base = texture(texture0, fragTexCoord)*fragTintColor;
|
||||||
|
|
||||||
// Convert to grayscale using NTSC conversion weights
|
// Convert to grayscale using NTSC conversion weights
|
||||||
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
|
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
|
||||||
|
|
||||||
fragColor = vec4(gray, gray, gray, tintColor.a);
|
fragColor = vec4(gray, gray, gray, fragTintColor.a);
|
||||||
}
|
}
|
||||||
76
shaders/gl330/phong.fs
Normal file
76
shaders/gl330/phong.fs
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
#version 330
|
||||||
|
|
||||||
|
// Vertex shader input data
|
||||||
|
in vec2 fragTexCoord;
|
||||||
|
in vec3 fragNormal;
|
||||||
|
|
||||||
|
// Diffuse data
|
||||||
|
uniform sampler2D texture0;
|
||||||
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
|
// Light attributes
|
||||||
|
uniform vec3 light_ambientColor = vec3(0.6, 0.3, 0);
|
||||||
|
uniform vec3 light_diffuseColor = vec3(1, 0.5, 0);
|
||||||
|
uniform vec3 light_specularColor = vec3(0, 1, 0);
|
||||||
|
uniform float light_intensity = 1;
|
||||||
|
uniform float light_specIntensity = 1;
|
||||||
|
|
||||||
|
// Material attributes
|
||||||
|
uniform vec3 mat_ambientColor = vec3(1, 1, 1);
|
||||||
|
uniform vec3 mat_specularColor = vec3(1, 1, 1);
|
||||||
|
uniform float mat_glossiness = 50;
|
||||||
|
|
||||||
|
// World attributes
|
||||||
|
uniform vec3 lightPos;
|
||||||
|
uniform vec3 cameraPos;
|
||||||
|
|
||||||
|
// Fragment shader output data
|
||||||
|
out vec4 fragColor;
|
||||||
|
|
||||||
|
vec3 AmbientLighting()
|
||||||
|
{
|
||||||
|
return mat_ambientColor * light_ambientColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 DiffuseLighting(in vec3 N, in vec3 L)
|
||||||
|
{
|
||||||
|
// Lambertian reflection calculation
|
||||||
|
float diffuse = clamp(dot(N, L), 0, 1);
|
||||||
|
|
||||||
|
return tintColor.xyz * light_diffuseColor * light_intensity * diffuse;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec3 SpecularLighting(in vec3 N, in vec3 L, in vec3 V)
|
||||||
|
{
|
||||||
|
float specular = 0;
|
||||||
|
|
||||||
|
// Calculate specular reflection only if the surface is oriented to the light source
|
||||||
|
if(dot(N, L) > 0)
|
||||||
|
{
|
||||||
|
// Calculate half vector
|
||||||
|
vec3 H = normalize(L + V);
|
||||||
|
|
||||||
|
// Calculate specular intensity
|
||||||
|
specular = pow(dot(N, H), 3 + mat_glossiness);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mat_specularColor * light_specularColor * light_specIntensity * specular;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Normalize input vectors
|
||||||
|
vec3 L = normalize(lightPos);
|
||||||
|
vec3 V = normalize(cameraPos);
|
||||||
|
vec3 N = normalize(fragNormal);
|
||||||
|
|
||||||
|
vec3 ambient = AmbientLighting();
|
||||||
|
vec3 diffuse = DiffuseLighting(N, L);
|
||||||
|
vec3 specular = SpecularLighting(N, L, V);
|
||||||
|
|
||||||
|
// Get base color from texture
|
||||||
|
vec4 textureColor = texture(texture0, fragTexCoord);
|
||||||
|
vec3 finalColor = textureColor.rgb;
|
||||||
|
|
||||||
|
fragColor = vec4(finalColor * (ambient + diffuse + specular), textureColor.a);
|
||||||
|
}
|
||||||
27
shaders/gl330/phong.vs
Normal file
27
shaders/gl330/phong.vs
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
#version 330
|
||||||
|
|
||||||
|
// Vertex input data
|
||||||
|
in vec3 vertexPosition;
|
||||||
|
in vec2 vertexTexCoord;
|
||||||
|
in vec3 vertexNormal;
|
||||||
|
|
||||||
|
// Projection and model data
|
||||||
|
uniform mat4 mvpMatrix;
|
||||||
|
uniform mat4 modelMatrix;
|
||||||
|
|
||||||
|
// Attributes to fragment shader
|
||||||
|
out vec2 fragTexCoord;
|
||||||
|
out vec3 fragNormal;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
// Send texture coord to fragment shader
|
||||||
|
fragTexCoord = vertexTexCoord;
|
||||||
|
|
||||||
|
// Calculate view vector normal from model
|
||||||
|
mat3 normalMatrix = transpose(inverse(mat3(modelMatrix)));
|
||||||
|
fragNormal = normalize(normalMatrix*vertexNormal);
|
||||||
|
|
||||||
|
// Calculate final vertex position
|
||||||
|
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||||
|
}
|
||||||
|
|
@ -5,15 +5,15 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
const float renderWidth = 1280;
|
const float renderWidth = 1280.0;
|
||||||
const float renderHeight = 720;
|
const float renderHeight = 720.0;
|
||||||
|
|
||||||
uniform float pixelWidth = 5.0f;
|
uniform float pixelWidth = 5.0;
|
||||||
uniform float pixelHeight = 5.0f;
|
uniform float pixelHeight = 5.0;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
@ -22,7 +22,7 @@ void main()
|
||||||
|
|
||||||
vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy));
|
vec2 coord = vec2(dx*floor(fragTexCoord.x/dx), dy*floor(fragTexCoord.y/dy));
|
||||||
|
|
||||||
vec3 tc = texture2D(texture0, coord).rgb;
|
vec3 tc = texture(texture0, coord).rgb;
|
||||||
|
|
||||||
fragColor = vec4(tc, 1.0);
|
fragColor = vec4(tc, 1.0);
|
||||||
}
|
}
|
||||||
|
|
@ -5,16 +5,16 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
float gamma = 0.6f;
|
float gamma = 0.6;
|
||||||
float numColors = 8.0f;
|
float numColors = 8.0;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 color = texture2D(texture0, fragTexCoord.xy).rgb;
|
vec3 color = texture(texture0, fragTexCoord.xy).rgb;
|
||||||
|
|
||||||
color = pow(color, vec3(gamma, gamma, gamma));
|
color = pow(color, vec3(gamma, gamma, gamma));
|
||||||
color = color*numColors;
|
color = color*numColors;
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 color = texture2D(texture0, fragTexCoord).rgb;
|
vec3 color = texture(texture0, fragTexCoord).rgb;
|
||||||
vec3 colors[3];
|
vec3 colors[3];
|
||||||
colors[0] = vec3(0.0, 0.0, 1.0);
|
colors[0] = vec3(0.0, 0.0, 1.0);
|
||||||
colors[1] = vec3(1.0, 1.0, 0.0);
|
colors[1] = vec3(1.0, 1.0, 0.0);
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
float offset = 0;
|
float offset = 0.0;
|
||||||
float frequency = 720/3.0;
|
float frequency = 720.0/3.0;
|
||||||
|
|
||||||
uniform float time;
|
uniform float time;
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@ void main (void)
|
||||||
float tval = 0; //time
|
float tval = 0; //time
|
||||||
vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval));
|
vec2 uv = 0.5 + (fragTexCoord - 0.5)*(0.9 + 0.01*sin(0.5*tval));
|
||||||
|
|
||||||
vec4 color = texture2D(texture0, fragTexCoord);
|
vec4 color = texture(texture0, fragTexCoord);
|
||||||
|
|
||||||
color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0);
|
color = clamp(color*0.5 + 0.5*color*color*1.2, 0.0, 1.0);
|
||||||
color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y);
|
color *= 0.5 + 0.5*16.0*uv.x*uv.y*(1.0 - uv.x)*(1.0 - uv.y);
|
||||||
|
|
@ -35,7 +35,7 @@ void main (void)
|
||||||
float globalPos = (fragTexCoord.y + offset) * frequency;
|
float globalPos = (fragTexCoord.y + offset) * frequency;
|
||||||
float wavePos = cos((fract(globalPos) - 0.5)*3.14);
|
float wavePos = cos((fract(globalPos) - 0.5)*3.14);
|
||||||
|
|
||||||
vec4 color = texture2D(texture0, fragTexCoord);
|
vec4 color = texture(texture0, fragTexCoord);
|
||||||
|
|
||||||
fragColor = mix(vec4(0, 0.3, 0, 0), color, wavePos);
|
fragColor = mix(vec4(0.0, 0.3, 0.0, 0.0), color, wavePos);
|
||||||
}
|
}
|
||||||
|
|
@ -5,17 +5,17 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
const float renderWidth = 1280;
|
const float renderWidth = 1280.0;
|
||||||
const float renderHeight = 720;
|
const float renderHeight = 720.0;
|
||||||
|
|
||||||
float radius = 250.0;
|
float radius = 250.0;
|
||||||
float angle = 0.8;
|
float angle = 0.8;
|
||||||
|
|
||||||
uniform vec2 center = vec2(200, 200);
|
uniform vec2 center = vec2(200.0, 200.0);
|
||||||
|
|
||||||
void main (void)
|
void main (void)
|
||||||
{
|
{
|
||||||
|
|
@ -35,7 +35,7 @@ void main (void)
|
||||||
}
|
}
|
||||||
|
|
||||||
tc += center;
|
tc += center;
|
||||||
vec3 color = texture2D(texture0, tc/texSize).rgb;
|
vec3 color = texture(texture0, tc/texSize).rgb;
|
||||||
|
|
||||||
fragColor = vec4(color, 1.0);;
|
fragColor = vec4(color, 1.0);;
|
||||||
}
|
}
|
||||||
|
|
@ -5,15 +5,15 @@ in vec2 fragTexCoord;
|
||||||
out vec4 fragColor;
|
out vec4 fragColor;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 texelColor = texture2D(texture0, fragTexCoord);
|
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||||
|
|
||||||
// NOTE: Implement here your fragment shader code
|
// NOTE: Implement here your fragment shader code
|
||||||
|
|
||||||
fragColor = texelColor*tintColor;
|
fragColor = texelColor*fragTintColor;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,7 @@ attribute vec3 vertexNormal;
|
||||||
|
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform mat4 projectionMatrix;
|
uniform mat4 mvpMatrix;
|
||||||
uniform mat4 modelviewMatrix;
|
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
@ -17,5 +16,5 @@ void main()
|
||||||
|
|
||||||
fragTexCoord = vertexTexCoord;
|
fragTexCoord = vertexTexCoord;
|
||||||
|
|
||||||
gl_Position = projectionMatrix*modelviewMatrix*vec4(vertexPosition, 1.0);
|
gl_Position = mvpMatrix*vec4(vertexPosition, 1.0);
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ precision mediump float;
|
||||||
|
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,16 +5,16 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 base = texture2D(texture0, fragTexCoord)*tintColor;
|
vec4 base = texture2D(texture0, fragTexCoord)*fragTintColor;
|
||||||
|
|
||||||
// Convert to grayscale using NTSC conversion weights
|
// Convert to grayscale using NTSC conversion weights
|
||||||
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
|
float gray = dot(base.rgb, vec3(0.299, 0.587, 0.114));
|
||||||
|
|
||||||
gl_FragColor = vec4(gray, gray, gray, tintColor.a);
|
gl_FragColor = vec4(gray, gray, gray, fragTintColor.a);
|
||||||
}
|
}
|
||||||
|
|
@ -5,7 +5,7 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ precision mediump float;
|
||||||
varying vec2 fragTexCoord;
|
varying vec2 fragTexCoord;
|
||||||
|
|
||||||
uniform sampler2D texture0;
|
uniform sampler2D texture0;
|
||||||
uniform vec4 tintColor;
|
uniform vec4 fragTintColor;
|
||||||
|
|
||||||
// NOTE: Add here your custom variables
|
// NOTE: Add here your custom variables
|
||||||
|
|
||||||
|
|
@ -15,5 +15,5 @@ void main()
|
||||||
|
|
||||||
// NOTE: Implement here your fragment shader code
|
// NOTE: Implement here your fragment shader code
|
||||||
|
|
||||||
gl_FragColor = texelColor*tintColor;
|
gl_FragColor = texelColor*fragTintColor;
|
||||||
}
|
}
|
||||||
|
|
@ -92,7 +92,7 @@ typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Global Variables Definition
|
// Global Variables Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
bool musicEnabled = false;
|
static bool musicEnabled = false;
|
||||||
static Music currentMusic; // Current music loaded
|
static Music currentMusic; // Current music loaded
|
||||||
// NOTE: Only one music file playing at a time
|
// NOTE: Only one music file playing at a time
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -317,7 +317,7 @@ static void ProcessCamera(Camera *camera, Vector3 *playerPosition)
|
||||||
camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_SCROLL_SENSITIVITY/cameraTargetDistance;
|
camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_SCROLL_SENSITIVITY/cameraTargetDistance;
|
||||||
camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_SCROLL_SENSITIVITY/cameraTargetDistance;
|
camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_SCROLL_SENSITIVITY/cameraTargetDistance;
|
||||||
|
|
||||||
if (camera->target.y < 0) camera->target.y = -0.001;
|
// if (camera->target.y < 0) camera->target.y = -0.001;
|
||||||
}
|
}
|
||||||
else if ((camera->position.y > camera->target.y) && (camera->target.y < 0) && (mouseWheelMove > 0))
|
else if ((camera->position.y > camera->target.y) && (camera->target.y < 0) && (mouseWheelMove > 0))
|
||||||
{
|
{
|
||||||
|
|
@ -337,7 +337,7 @@ static void ProcessCamera(Camera *camera, Vector3 *playerPosition)
|
||||||
camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_SCROLL_SENSITIVITY/cameraTargetDistance;
|
camera->target.y += mouseWheelMove*(camera->target.y - camera->position.y)*CAMERA_SCROLL_SENSITIVITY/cameraTargetDistance;
|
||||||
camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_SCROLL_SENSITIVITY/cameraTargetDistance;
|
camera->target.z += mouseWheelMove*(camera->target.z - camera->position.z)*CAMERA_SCROLL_SENSITIVITY/cameraTargetDistance;
|
||||||
|
|
||||||
if (camera->target.y > 0) camera->target.y = 0.001;
|
// if (camera->target.y > 0) camera->target.y = 0.001;
|
||||||
}
|
}
|
||||||
else if ((camera->position.y < camera->target.y) && (camera->target.y > 0) && (mouseWheelMove > 0))
|
else if ((camera->position.y < camera->target.y) && (camera->target.y > 0) && (mouseWheelMove > 0))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
514
src/core.c
514
src/core.c
|
|
@ -66,7 +66,7 @@
|
||||||
#include <jni.h> // Java native interface
|
#include <jni.h> // Java native interface
|
||||||
#include <android/sensor.h> // Android sensors functions
|
#include <android/sensor.h> // Android sensors functions
|
||||||
#include <android/window.h> // Defines AWINDOW_FLAG_FULLSCREEN and others
|
#include <android/window.h> // Defines AWINDOW_FLAG_FULLSCREEN and others
|
||||||
//#include <android_native_app_glue.h> // Defines basic app state struct and manages activity
|
#include <android_native_app_glue.h> // Defines basic app state struct and manages activity
|
||||||
|
|
||||||
#include <EGL/egl.h> // Khronos EGL library - Native platform display device control functions
|
#include <EGL/egl.h> // Khronos EGL library - Native platform display device control functions
|
||||||
#include <GLES2/gl2.h> // Khronos OpenGL ES 2.0 library
|
#include <GLES2/gl2.h> // Khronos OpenGL ES 2.0 library
|
||||||
|
|
@ -103,7 +103,6 @@
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#define MAX_TOUCH_POINTS 256
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
|
|
@ -121,7 +120,10 @@ static struct android_app *app; // Android activity
|
||||||
static struct android_poll_source *source; // Android events polling source
|
static struct android_poll_source *source; // Android events polling source
|
||||||
static int ident, events;
|
static int ident, events;
|
||||||
static bool windowReady = false; // Used to detect display initialization
|
static bool windowReady = false; // Used to detect display initialization
|
||||||
|
static bool appEnabled = true; // Used to detec if app is active
|
||||||
|
static bool contextRebindRequired = false; // Used to know context rebind required
|
||||||
|
static int previousButtonState[128] = { 1 }; // Required to check if button pressed/released once
|
||||||
|
static int currentButtonState[128] = { 1 }; // Required to check if button pressed/released once
|
||||||
#elif defined(PLATFORM_RPI)
|
#elif defined(PLATFORM_RPI)
|
||||||
static EGL_DISPMANX_WINDOW_T nativeWindow; // Native window (graphic device)
|
static EGL_DISPMANX_WINDOW_T nativeWindow; // Native window (graphic device)
|
||||||
|
|
||||||
|
|
@ -149,6 +151,7 @@ static int gamepadStream = -1; // Gamepad device file descripto
|
||||||
static EGLDisplay display; // Native display device (physical screen connection)
|
static EGLDisplay display; // Native display device (physical screen connection)
|
||||||
static EGLSurface surface; // Surface to draw on, framebuffers (connected to context)
|
static EGLSurface surface; // Surface to draw on, framebuffers (connected to context)
|
||||||
static EGLContext context; // Graphic context, mode in which drawing can be done
|
static EGLContext context; // Graphic context, mode in which drawing can be done
|
||||||
|
static EGLConfig config; // Graphic config
|
||||||
static uint64_t baseTime; // Base time measure for hi-res timer
|
static uint64_t baseTime; // Base time measure for hi-res timer
|
||||||
static bool windowShouldClose = false; // Flag to set window for closing
|
static bool windowShouldClose = false; // Flag to set window for closing
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -254,10 +257,12 @@ static void TakeScreenshot(void);
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
static void AndroidCommandCallback(struct android_app *app, int32_t cmd); // Process Android activity lifecycle commands
|
static void AndroidCommandCallback(struct android_app *app, int32_t cmd); // Process Android activity lifecycle commands
|
||||||
|
static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event); // Process Android inputs
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_WEB)
|
#if defined(PLATFORM_WEB)
|
||||||
static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *e, void *userData);
|
static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *e, void *userData);
|
||||||
|
static EM_BOOL EmscriptenInputCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -267,7 +272,7 @@ static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const Emscripte
|
||||||
// Initialize Window and Graphics Context (OpenGL)
|
// Initialize Window and Graphics Context (OpenGL)
|
||||||
void InitWindow(int width, int height, const char *title)
|
void InitWindow(int width, int height, const char *title)
|
||||||
{
|
{
|
||||||
TraceLog(INFO, "Initializing raylib (v1.3.0)");
|
TraceLog(INFO, "Initializing raylib (v1.4.0)");
|
||||||
|
|
||||||
// Store window title (could be useful...)
|
// Store window title (could be useful...)
|
||||||
windowTitle = title;
|
windowTitle = title;
|
||||||
|
|
@ -293,13 +298,19 @@ void InitWindow(int width, int height, const char *title)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_WEB)
|
#if defined(PLATFORM_WEB)
|
||||||
InitGesturesSystem();
|
|
||||||
|
|
||||||
emscripten_set_fullscreenchange_callback(0, 0, 1, EmscriptenFullscreenChangeCallback);
|
emscripten_set_fullscreenchange_callback(0, 0, 1, EmscriptenFullscreenChangeCallback);
|
||||||
|
|
||||||
|
// NOTE: Some code examples
|
||||||
|
//emscripten_set_touchstart_callback(0, NULL, 1, Emscripten_HandleTouch);
|
||||||
|
//emscripten_set_touchend_callback("#canvas", data, 0, Emscripten_HandleTouch);
|
||||||
|
emscripten_set_touchstart_callback("#canvas", NULL, 1, EmscriptenInputCallback);
|
||||||
|
emscripten_set_touchend_callback("#canvas", NULL, 1, EmscriptenInputCallback);
|
||||||
|
emscripten_set_touchmove_callback("#canvas", NULL, 1, EmscriptenInputCallback);
|
||||||
|
emscripten_set_touchcancel_callback("#canvas", NULL, 1, EmscriptenInputCallback);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
mousePosition.x = screenWidth/2;
|
mousePosition.x = (float)screenWidth/2.0f;
|
||||||
mousePosition.y = screenHeight/2;
|
mousePosition.y = (float)screenHeight/2.0f;
|
||||||
|
|
||||||
// raylib logo appearing animation (if enabled)
|
// raylib logo appearing animation (if enabled)
|
||||||
if (showLogo)
|
if (showLogo)
|
||||||
|
|
@ -313,7 +324,7 @@ void InitWindow(int width, int height, const char *title)
|
||||||
// Android activity initialization
|
// Android activity initialization
|
||||||
void InitWindow(int width, int height, struct android_app *state)
|
void InitWindow(int width, int height, struct android_app *state)
|
||||||
{
|
{
|
||||||
TraceLog(INFO, "Initializing raylib (v1.3.0)");
|
TraceLog(INFO, "Initializing raylib (v1.4.0)");
|
||||||
|
|
||||||
app_dummy();
|
app_dummy();
|
||||||
|
|
||||||
|
|
@ -350,26 +361,30 @@ void InitWindow(int width, int height, struct android_app *state)
|
||||||
|
|
||||||
//state->userData = &engine;
|
//state->userData = &engine;
|
||||||
app->onAppCmd = AndroidCommandCallback;
|
app->onAppCmd = AndroidCommandCallback;
|
||||||
|
app->onInputEvent = AndroidInputCallback;
|
||||||
|
|
||||||
//InitGesturesSystem(app); // NOTE: Must be called by user
|
|
||||||
|
|
||||||
InitAssetManager(app->activity->assetManager);
|
InitAssetManager(app->activity->assetManager);
|
||||||
|
|
||||||
InitGesturesSystem(app);
|
|
||||||
|
|
||||||
TraceLog(INFO, "Android app initialized successfully");
|
TraceLog(INFO, "Android app initialized successfully");
|
||||||
|
|
||||||
|
// Init button states values (default up)
|
||||||
|
for(int i = 0; i < 128; i++)
|
||||||
|
{
|
||||||
|
currentButtonState[i] = 1;
|
||||||
|
previousButtonState[i] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for window to be initialized (display and context)
|
||||||
while (!windowReady)
|
while (!windowReady)
|
||||||
{
|
{
|
||||||
// Wait for window to be initialized (display and context)
|
|
||||||
// Process events loop
|
// Process events loop
|
||||||
while ((ident = ALooper_pollAll(0, NULL, &events,(void**)&source)) >= 0)
|
while ((ident = ALooper_pollAll(0, NULL, &events,(void**)&source)) >= 0)
|
||||||
{
|
{
|
||||||
// Process this event
|
// Process this event
|
||||||
if (source != NULL) source->process(app, source);
|
if (source != NULL) source->process(app, source);
|
||||||
|
|
||||||
// Check if we are exiting
|
// NOTE: Never close window, native activity is controlled by the system!
|
||||||
if (app->destroyRequested != 0) windowShouldClose = true;
|
//if (app->destroyRequested != 0) windowShouldClose = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -504,12 +519,23 @@ void BeginDrawing(void)
|
||||||
|
|
||||||
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
|
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
|
||||||
|
|
||||||
rlMultMatrixf(GetMatrixVector(downscaleView)); // If downscale required, apply it here
|
rlMultMatrixf(MatrixToFloat(downscaleView)); // If downscale required, apply it here
|
||||||
|
|
||||||
//rlTranslatef(0.375, 0.375, 0); // HACK to have 2D pixel-perfect drawing on OpenGL 1.1
|
//rlTranslatef(0.375, 0.375, 0); // HACK to have 2D pixel-perfect drawing on OpenGL 1.1
|
||||||
// NOTE: Not required with OpenGL 3.3+
|
// NOTE: Not required with OpenGL 3.3+
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup drawing canvas with extended parameters
|
||||||
|
void BeginDrawingEx(int blendMode, Shader shader, Matrix transform)
|
||||||
|
{
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
SetBlendMode(blendMode);
|
||||||
|
SetPostproShader(shader);
|
||||||
|
|
||||||
|
rlMultMatrixf(MatrixToFloat(transform));
|
||||||
|
}
|
||||||
|
|
||||||
// End canvas drawing and Swap Buffers (Double Buffering)
|
// End canvas drawing and Swap Buffers (Double Buffering)
|
||||||
void EndDrawing(void)
|
void EndDrawing(void)
|
||||||
{
|
{
|
||||||
|
|
@ -551,7 +577,7 @@ void Begin3dMode(Camera camera)
|
||||||
|
|
||||||
// Setup perspective projection
|
// Setup perspective projection
|
||||||
float aspect = (float)screenWidth/(float)screenHeight;
|
float aspect = (float)screenWidth/(float)screenHeight;
|
||||||
double top = 0.1f*tan(45.0f*PI / 360.0f);
|
double top = 0.1f*tan(45.0f*PI/360.0f);
|
||||||
double right = top*aspect;
|
double right = top*aspect;
|
||||||
|
|
||||||
// NOTE: zNear and zFar values are important when computing depth buffer values
|
// NOTE: zNear and zFar values are important when computing depth buffer values
|
||||||
|
|
@ -561,8 +587,8 @@ void Begin3dMode(Camera camera)
|
||||||
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
|
rlLoadIdentity(); // Reset current matrix (MODELVIEW)
|
||||||
|
|
||||||
// Setup Camera view
|
// Setup Camera view
|
||||||
Matrix view = MatrixLookAt(camera.position, camera.target, camera.up);
|
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
||||||
rlMultMatrixf(GetMatrixVector(view)); // Multiply MODELVIEW matrix by view matrix (camera)
|
rlMultMatrixf(MatrixToFloat(matView)); // Multiply MODELVIEW matrix by view matrix (camera)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ends 3D mode and returns to default 2D orthographic mode
|
// Ends 3D mode and returns to default 2D orthographic mode
|
||||||
|
|
@ -582,7 +608,7 @@ void End3dMode(void)
|
||||||
// Set target FPS for the game
|
// Set target FPS for the game
|
||||||
void SetTargetFPS(int fps)
|
void SetTargetFPS(int fps)
|
||||||
{
|
{
|
||||||
targetTime = 1 / (double)fps;
|
targetTime = 1.0/(double)fps;
|
||||||
|
|
||||||
TraceLog(INFO, "Target time per frame: %02.03f milliseconds", (float)targetTime*1000);
|
TraceLog(INFO, "Target time per frame: %02.03f milliseconds", (float)targetTime*1000);
|
||||||
}
|
}
|
||||||
|
|
@ -599,11 +625,24 @@ float GetFrameTime(void)
|
||||||
// As we are operate quite a lot with frameTime,
|
// As we are operate quite a lot with frameTime,
|
||||||
// it could be no stable, so we round it before passing it around
|
// it could be no stable, so we round it before passing it around
|
||||||
// NOTE: There are still problems with high framerates (>500fps)
|
// NOTE: There are still problems with high framerates (>500fps)
|
||||||
double roundedFrameTime = round(frameTime*10000)/10000;
|
double roundedFrameTime = round(frameTime*10000)/10000.0;
|
||||||
|
|
||||||
return (float)roundedFrameTime; // Time in seconds to run a frame
|
return (float)roundedFrameTime; // Time in seconds to run a frame
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Converts Color to float array and normalizes
|
||||||
|
float *ColorToFloat(Color color)
|
||||||
|
{
|
||||||
|
static float buffer[4];
|
||||||
|
|
||||||
|
buffer[0] = (float)color.r/255;
|
||||||
|
buffer[1] = (float)color.g/255;
|
||||||
|
buffer[2] = (float)color.b/255;
|
||||||
|
buffer[3] = (float)color.a/255;
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
// Returns a Color struct from hexadecimal value
|
// Returns a Color struct from hexadecimal value
|
||||||
Color GetColor(int hexValue)
|
Color GetColor(int hexValue)
|
||||||
{
|
{
|
||||||
|
|
@ -691,46 +730,161 @@ void ClearDroppedFiles(void)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: Gives the ray trace from mouse position
|
// Storage save integer value (to defined position)
|
||||||
|
// NOTE: Storage positions is directly related to file memory layout (4 bytes each integer)
|
||||||
|
void StorageSaveValue(int position, int value)
|
||||||
|
{
|
||||||
|
FILE *storageFile = NULL;
|
||||||
|
|
||||||
|
// Try open existing file to append data
|
||||||
|
storageFile = fopen("storage.data", "rb+");
|
||||||
|
|
||||||
|
// If file doesn't exist, create a new storage data file
|
||||||
|
if (!storageFile) storageFile = fopen("storage.data", "wb");
|
||||||
|
|
||||||
|
if (!storageFile) TraceLog(WARNING, "Storage data file could not be created");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Get file size
|
||||||
|
fseek(storageFile, 0, SEEK_END);
|
||||||
|
int fileSize = ftell(storageFile); // Size in bytes
|
||||||
|
fseek(storageFile, 0, SEEK_SET);
|
||||||
|
|
||||||
|
if (fileSize < (position*4)) TraceLog(WARNING, "Storage position could not be found");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fseek(storageFile, (position*4), SEEK_SET);
|
||||||
|
fwrite(&value, 1, 4, storageFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(storageFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Storage load integer value (from defined position)
|
||||||
|
// NOTE: If requested position could not be found, value 0 is returned
|
||||||
|
int StorageLoadValue(int position)
|
||||||
|
{
|
||||||
|
int value = 0;
|
||||||
|
|
||||||
|
// Try open existing file to append data
|
||||||
|
FILE *storageFile = fopen("storage.data", "rb");
|
||||||
|
|
||||||
|
if (!storageFile) TraceLog(WARNING, "Storage data file could not be found");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Get file size
|
||||||
|
fseek(storageFile, 0, SEEK_END);
|
||||||
|
int fileSize = ftell(storageFile); // Size in bytes
|
||||||
|
rewind(storageFile);
|
||||||
|
|
||||||
|
if (fileSize < (position*4)) TraceLog(WARNING, "Storage position could not be found");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
fseek(storageFile, (position*4), SEEK_SET);
|
||||||
|
fread(&value, 1, 4, storageFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(storageFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a ray trace from mouse position
|
||||||
|
//http://www.songho.ca/opengl/gl_transform.html
|
||||||
|
//http://www.songho.ca/opengl/gl_matrix.html
|
||||||
|
//http://www.sjbaker.org/steve/omniv/matrices_can_be_your_friends.html
|
||||||
|
//https://www.opengl.org/archives/resources/faq/technical/transformations.htm
|
||||||
Ray GetMouseRay(Vector2 mousePosition, Camera camera)
|
Ray GetMouseRay(Vector2 mousePosition, Camera camera)
|
||||||
{
|
{
|
||||||
|
// Tutorial used: https://mkonrad.net/2014/08/07/simple-opengl-object-picking-in-3d.html
|
||||||
|
// Similar to http://antongerdelan.net, the problem is maybe in MatrixPerspective vs MatrixFrustum
|
||||||
|
// or matrix order (transpose it or not... that's the question)
|
||||||
|
|
||||||
Ray ray;
|
Ray ray;
|
||||||
|
|
||||||
Matrix proj = MatrixIdentity();
|
// Calculate normalized device coordinates
|
||||||
Matrix view = MatrixLookAt(camera.position, camera.target, camera.up);
|
// NOTE: y value is negative
|
||||||
|
float x = (2.0f*mousePosition.x)/(float)GetScreenWidth() - 1.0f;
|
||||||
// Calculate projection matrix for the camera
|
float y = 1.0f - (2.0f*mousePosition.y)/(float)GetScreenHeight();
|
||||||
float aspect = (float)GetScreenWidth()/(float)GetScreenHeight();
|
float z = 1.0f;
|
||||||
double top = 0.1f*tanf(45.0f*PI/360.0f);
|
|
||||||
double right = top*aspect;
|
// Store values in a vector
|
||||||
|
Vector3 deviceCoords = {x, y, z};
|
||||||
// NOTE: zNear and zFar values are important for depth
|
|
||||||
proj = MatrixFrustum(-right, right, -top, top, 0.01f, 1000.0f);
|
// Device debug message
|
||||||
MatrixTranspose(&proj);
|
TraceLog(INFO, "device(%f, %f, %f)", deviceCoords.x, deviceCoords.y, deviceCoords.z);
|
||||||
|
|
||||||
// NOTE: Our screen origin is top-left instead of bottom-left: transform required!
|
// Calculate projection matrix (from perspective instead of frustum
|
||||||
float invertedMouseY = (float)GetScreenHeight() - mousePosition.y;
|
Matrix matProj = MatrixPerspective(45.0f, (float)((float)GetScreenWidth() / (float)GetScreenHeight()), 0.01f, 1000.0f);
|
||||||
|
|
||||||
// NOTE: Do I really need to get z value from depth buffer?
|
// Calculate view matrix from camera look at
|
||||||
//float z;
|
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
||||||
//glReadPixels(mousePosition.x, mousePosition.y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
|
|
||||||
//http://www.bfilipek.com/2012/06/select-mouse-opengl.html
|
// Do I need to transpose it? It seems that yes...
|
||||||
|
// NOTE: matrix order is maybe incorrect... In OpenGL to get world position from
|
||||||
Vector3 nearPoint = { mousePosition.x, invertedMouseY, 0.0f };
|
// camera view it just needs to get inverted, but here we need to transpose it too.
|
||||||
Vector3 farPoint = { mousePosition.x, invertedMouseY, 1.0f };
|
// For example, if you get view matrix, transpose and inverted and you transform it
|
||||||
|
// to a vector, you will get its 3d world position coordinates (camera.position).
|
||||||
nearPoint = rlglUnproject(nearPoint, proj, view);
|
// If you don't transpose, final position will be wrong.
|
||||||
farPoint = rlglUnproject(farPoint, proj, view); // TODO: it seems it doesn't work...
|
MatrixTranspose(&matView);
|
||||||
|
|
||||||
|
// Calculate unproject matrix (multiply projection matrix and view matrix) and invert it
|
||||||
|
Matrix matProjView = MatrixMultiply(matProj, matView);
|
||||||
|
MatrixInvert(&matProjView);
|
||||||
|
|
||||||
|
// Calculate far and near points
|
||||||
|
Quaternion near = { deviceCoords.x, deviceCoords.y, 0, 1};
|
||||||
|
Quaternion far = { deviceCoords.x, deviceCoords.y, 1, 1};
|
||||||
|
|
||||||
|
// Multiply points by unproject matrix
|
||||||
|
QuaternionTransform(&near, matProjView);
|
||||||
|
QuaternionTransform(&far, matProjView);
|
||||||
|
|
||||||
|
// Calculate normalized world points in vectors
|
||||||
|
Vector3 nearPoint = {near.x / near.w, near.y / near.w, near.z / near.w};
|
||||||
|
Vector3 farPoint = {far.x / far.w, far.y / far.w, far.z / far.w};
|
||||||
|
|
||||||
|
// Calculate normalized direction vector
|
||||||
Vector3 direction = VectorSubtract(farPoint, nearPoint);
|
Vector3 direction = VectorSubtract(farPoint, nearPoint);
|
||||||
VectorNormalize(&direction);
|
VectorNormalize(&direction);
|
||||||
|
|
||||||
ray.position = nearPoint;
|
// Apply calculated vectors to ray
|
||||||
|
ray.position = camera.position;
|
||||||
ray.direction = direction;
|
ray.direction = direction;
|
||||||
|
|
||||||
return ray;
|
return ray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns the screen space position from a 3d world space position
|
||||||
|
Vector2 WorldToScreen(Vector3 position, Camera camera)
|
||||||
|
{
|
||||||
|
// Calculate projection matrix (from perspective instead of frustum
|
||||||
|
Matrix matProj = MatrixPerspective(45.0f, (float)((float)GetScreenWidth() / (float)GetScreenHeight()), 0.01f, 1000.0f);
|
||||||
|
|
||||||
|
// Calculate view matrix from camera look at (and transpose it)
|
||||||
|
Matrix matView = MatrixLookAt(camera.position, camera.target, camera.up);
|
||||||
|
MatrixTranspose(&matView);
|
||||||
|
|
||||||
|
// Convert world position vector to quaternion
|
||||||
|
Quaternion worldPos = { position.x, position.y, position.z, 1.0f };
|
||||||
|
|
||||||
|
// Transform world position to view
|
||||||
|
QuaternionTransform(&worldPos, matView);
|
||||||
|
|
||||||
|
// Transform result to projection (clip space position)
|
||||||
|
QuaternionTransform(&worldPos, matProj);
|
||||||
|
|
||||||
|
// Calculate normalized device coordinates (inverted y)
|
||||||
|
Vector3 ndcPos = { worldPos.x / worldPos.w, -worldPos.y / worldPos.w, worldPos.z / worldPos.z };
|
||||||
|
|
||||||
|
// Calculate 2d screen position vector
|
||||||
|
Vector2 screenPosition = { (ndcPos.x + 1.0f)/2.0f*(float)GetScreenWidth(), (ndcPos.y + 1.0f)/2.0f*(float)GetScreenHeight() };
|
||||||
|
|
||||||
|
return screenPosition;
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Definition - Input (Keyboard, Mouse, Gamepad) Functions
|
// Module Functions Definition - Input (Keyboard, Mouse, Gamepad) Functions
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -1023,6 +1177,35 @@ Vector2 GetTouchPosition(void)
|
||||||
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detect if a button has been pressed once
|
||||||
|
bool IsButtonPressed(int button)
|
||||||
|
{
|
||||||
|
bool pressed = false;
|
||||||
|
|
||||||
|
if ((currentButtonState[button] != previousButtonState[button]) && (currentButtonState[button] == 0)) pressed = true;
|
||||||
|
else pressed = false;
|
||||||
|
|
||||||
|
return pressed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect if a button is being pressed (button held down)
|
||||||
|
bool IsButtonDown(int button)
|
||||||
|
{
|
||||||
|
if (currentButtonState[button] == 0) return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect if a button has been released once
|
||||||
|
bool IsButtonReleased(int button)
|
||||||
|
{
|
||||||
|
bool released = false;
|
||||||
|
|
||||||
|
if ((currentButtonState[button] != previousButtonState[button]) && (currentButtonState[button] == 1)) released = true;
|
||||||
|
else released = false;
|
||||||
|
|
||||||
|
return released;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -1097,7 +1280,7 @@ static void InitDisplay(int width, int height)
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
{
|
{
|
||||||
// At this point we need to manage render size vs screen size
|
// At this point we need to manage render size vs screen size
|
||||||
// NOTE: This function use and modify global module variables: screenWidth/screenHeight and renderWidth/renderHeight and downscaleView
|
// NOTE: This function uses and modifies global module variables: screenWidth/screenHeight and renderWidth/renderHeight and downscaleView
|
||||||
SetupFramebufferSize(displayWidth, displayHeight);
|
SetupFramebufferSize(displayWidth, displayHeight);
|
||||||
|
|
||||||
window = glfwCreateWindow(renderWidth, renderHeight, windowTitle, glfwGetPrimaryMonitor(), NULL);
|
window = glfwCreateWindow(renderWidth, renderHeight, windowTitle, glfwGetPrimaryMonitor(), NULL);
|
||||||
|
|
@ -1212,7 +1395,6 @@ static void InitDisplay(int width, int height)
|
||||||
};
|
};
|
||||||
|
|
||||||
EGLint numConfigs;
|
EGLint numConfigs;
|
||||||
EGLConfig config;
|
|
||||||
|
|
||||||
// Get an EGL display connection
|
// Get an EGL display connection
|
||||||
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
|
||||||
|
|
@ -1446,30 +1628,62 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
|
||||||
|
|
||||||
if (app->window != NULL)
|
if (app->window != NULL)
|
||||||
{
|
{
|
||||||
// Init device display (monitor, LCD, ...)
|
if (contextRebindRequired)
|
||||||
InitDisplay(screenWidth, screenHeight);
|
|
||||||
|
|
||||||
// Init OpenGL graphics
|
|
||||||
InitGraphics();
|
|
||||||
|
|
||||||
// Load default font for convenience
|
|
||||||
// NOTE: External function (defined in module: text)
|
|
||||||
LoadDefaultFont();
|
|
||||||
|
|
||||||
// Init hi-res timer
|
|
||||||
InitTimer();
|
|
||||||
|
|
||||||
// raylib logo appearing animation (if enabled)
|
|
||||||
if (showLogo)
|
|
||||||
{
|
{
|
||||||
SetTargetFPS(60);
|
// Reset screen scaling to full display size
|
||||||
LogoAnimation();
|
EGLint displayFormat;
|
||||||
|
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &displayFormat);
|
||||||
|
ANativeWindow_setBuffersGeometry(app->window, renderWidth, renderHeight, displayFormat);
|
||||||
|
|
||||||
|
// Recreate display surface and re-attach OpenGL context
|
||||||
|
surface = eglCreateWindowSurface(display, config, app->window, NULL);
|
||||||
|
eglMakeCurrent(display, surface, surface, context);
|
||||||
|
|
||||||
|
contextRebindRequired = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Init device display (monitor, LCD, ...)
|
||||||
|
InitDisplay(screenWidth, screenHeight);
|
||||||
|
|
||||||
|
// Init OpenGL graphics
|
||||||
|
InitGraphics();
|
||||||
|
|
||||||
|
// Load default font for convenience
|
||||||
|
// NOTE: External function (defined in module: text)
|
||||||
|
LoadDefaultFont();
|
||||||
|
|
||||||
|
// TODO: GPU assets reload in case of lost focus (lost context)
|
||||||
|
// NOTE: This problem has been solved just unbinding and rebinding context from display
|
||||||
|
/*
|
||||||
|
if (assetsReloadRequired)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < assetsCount; i++)
|
||||||
|
{
|
||||||
|
// TODO: Unload old asset if required
|
||||||
|
|
||||||
|
// Load texture again to pointed texture
|
||||||
|
(*textureAsset + i) = LoadTexture(assetPath[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Init hi-res timer
|
||||||
|
InitTimer();
|
||||||
|
|
||||||
|
// raylib logo appearing animation (if enabled)
|
||||||
|
if (showLogo)
|
||||||
|
{
|
||||||
|
SetTargetFPS(60); // Not required on Android
|
||||||
|
LogoAnimation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case APP_CMD_GAINED_FOCUS:
|
case APP_CMD_GAINED_FOCUS:
|
||||||
{
|
{
|
||||||
TraceLog(INFO, "APP_CMD_GAINED_FOCUS");
|
TraceLog(INFO, "APP_CMD_GAINED_FOCUS");
|
||||||
|
appEnabled = true;
|
||||||
//ResumeMusicStream();
|
//ResumeMusicStream();
|
||||||
} break;
|
} break;
|
||||||
case APP_CMD_PAUSE:
|
case APP_CMD_PAUSE:
|
||||||
|
|
@ -1480,11 +1694,18 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
|
||||||
{
|
{
|
||||||
//DrawFrame();
|
//DrawFrame();
|
||||||
TraceLog(INFO, "APP_CMD_LOST_FOCUS");
|
TraceLog(INFO, "APP_CMD_LOST_FOCUS");
|
||||||
|
appEnabled = false;
|
||||||
//PauseMusicStream();
|
//PauseMusicStream();
|
||||||
} break;
|
} break;
|
||||||
case APP_CMD_TERM_WINDOW:
|
case APP_CMD_TERM_WINDOW:
|
||||||
{
|
{
|
||||||
// TODO: Do display destruction here? -> Yes but only display, don't free buffers!
|
// Dettach OpenGL context and destroy display surface
|
||||||
|
// NOTE 1: Detaching context before destroying display surface avoids losing our resources (textures, shaders, VBOs...)
|
||||||
|
// NOTE 2: In some cases (too many context loaded), OS could unload context automatically... :(
|
||||||
|
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
|
||||||
|
eglDestroySurface(display, surface);
|
||||||
|
|
||||||
|
contextRebindRequired = true;
|
||||||
|
|
||||||
TraceLog(INFO, "APP_CMD_TERM_WINDOW");
|
TraceLog(INFO, "APP_CMD_TERM_WINDOW");
|
||||||
} break;
|
} break;
|
||||||
|
|
@ -1515,6 +1736,71 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd)
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Android: Get input events
|
||||||
|
static int32_t AndroidInputCallback(struct android_app *app, AInputEvent *event)
|
||||||
|
{
|
||||||
|
//http://developer.android.com/ndk/reference/index.html
|
||||||
|
|
||||||
|
int type = AInputEvent_getType(event);
|
||||||
|
|
||||||
|
if (type == AINPUT_EVENT_TYPE_MOTION)
|
||||||
|
{
|
||||||
|
touchPosition.x = AMotionEvent_getX(event, 0);
|
||||||
|
touchPosition.y = AMotionEvent_getY(event, 0);
|
||||||
|
}
|
||||||
|
else if (type == AINPUT_EVENT_TYPE_KEY)
|
||||||
|
{
|
||||||
|
int32_t keycode = AKeyEvent_getKeyCode(event);
|
||||||
|
//int32_t AKeyEvent_getMetaState(event);
|
||||||
|
|
||||||
|
// Save current button and its state
|
||||||
|
currentButtonState[keycode] = AKeyEvent_getAction(event); // Down = 0, Up = 1
|
||||||
|
|
||||||
|
if (keycode == AKEYCODE_POWER)
|
||||||
|
{
|
||||||
|
// Let the OS handle input to avoid app stuck. Behaviour: CMD_PAUSE -> CMD_SAVE_STATE -> CMD_STOP -> CMD_CONFIG_CHANGED -> CMD_LOST_FOCUS
|
||||||
|
// Resuming Behaviour: CMD_START -> CMD_RESUME -> CMD_CONFIG_CHANGED -> CMD_CONFIG_CHANGED -> CMD_GAINED_FOCUS
|
||||||
|
// It seems like locking mobile, screen size (CMD_CONFIG_CHANGED) is affected.
|
||||||
|
// NOTE: AndroidManifest.xml must have <activity android:configChanges="orientation|keyboardHidden|screenSize" >
|
||||||
|
// Before that change, activity was calling CMD_TERM_WINDOW and CMD_DESTROY when locking mobile, so that was not a normal behaviour
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else if ((keycode == AKEYCODE_BACK) || (keycode == AKEYCODE_MENU))
|
||||||
|
{
|
||||||
|
// Eat BACK_BUTTON and AKEYCODE_MENU, just do nothing... and don't let to be handled by OS!
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if ((keycode == AKEYCODE_VOLUME_UP) || (keycode == AKEYCODE_VOLUME_DOWN))
|
||||||
|
{
|
||||||
|
// Set default OS behaviour
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t action = AMotionEvent_getAction(event);
|
||||||
|
unsigned int flags = action & AMOTION_EVENT_ACTION_MASK;
|
||||||
|
|
||||||
|
GestureEvent gestureEvent;
|
||||||
|
|
||||||
|
// Register touch actions
|
||||||
|
if (flags == AMOTION_EVENT_ACTION_DOWN) gestureEvent.touchAction = TOUCH_DOWN;
|
||||||
|
else if (flags == AMOTION_EVENT_ACTION_UP) gestureEvent.touchAction = TOUCH_UP;
|
||||||
|
else if (flags == AMOTION_EVENT_ACTION_MOVE) gestureEvent.touchAction = TOUCH_MOVE;
|
||||||
|
|
||||||
|
// Register touch points count
|
||||||
|
gestureEvent.pointCount = AMotionEvent_getPointerCount(event);
|
||||||
|
|
||||||
|
// Register touch points position
|
||||||
|
// NOTE: Only two points registered
|
||||||
|
gestureEvent.position[0] = (Vector2){ AMotionEvent_getX(event, 0), AMotionEvent_getY(event, 0) };
|
||||||
|
gestureEvent.position[1] = (Vector2){ AMotionEvent_getX(event, 1), AMotionEvent_getY(event, 1) };
|
||||||
|
|
||||||
|
// Gesture data is sent to gestures system for processing
|
||||||
|
ProcessGestureEvent(gestureEvent);
|
||||||
|
|
||||||
|
return 0; // return 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI)
|
||||||
|
|
@ -1557,7 +1843,7 @@ static void InitTimer(void)
|
||||||
previousTime = GetTime(); // Get time as double
|
previousTime = GetTime(); // Get time as double
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current time measure since InitTimer()
|
// Get current time measure (in seconds) since InitTimer()
|
||||||
static double GetTime(void)
|
static double GetTime(void)
|
||||||
{
|
{
|
||||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_WEB)
|
||||||
|
|
@ -1565,7 +1851,7 @@ static double GetTime(void)
|
||||||
#elif defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
#elif defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
uint64_t time = ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec;
|
uint64_t time = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec;
|
||||||
|
|
||||||
return (double)(time - baseTime)*1e-9;
|
return (double)(time - baseTime)*1e-9;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -1604,9 +1890,8 @@ static bool GetMouseButtonStatus(int button)
|
||||||
static void PollInputEvents(void)
|
static void PollInputEvents(void)
|
||||||
{
|
{
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_WEB)
|
||||||
// Touch events reading (requires gestures module)
|
|
||||||
touchPosition = GetRawTouchPosition();
|
// TODO: Remove this requirement...
|
||||||
|
|
||||||
UpdateGestures();
|
UpdateGestures();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -1636,23 +1921,21 @@ static void PollInputEvents(void)
|
||||||
glfwPollEvents(); // Register keyboard/mouse events... and window events!
|
glfwPollEvents(); // Register keyboard/mouse events... and window events!
|
||||||
#elif defined(PLATFORM_ANDROID)
|
#elif defined(PLATFORM_ANDROID)
|
||||||
|
|
||||||
// TODO: Check virtual keyboard (?)
|
// Register previous keys states
|
||||||
|
for (int i = 0; i < 128; i++) previousButtonState[i] = currentButtonState[i];
|
||||||
|
|
||||||
// Poll Events (registered events)
|
// Poll Events (registered events)
|
||||||
// TODO: Enable/disable activityMinimized to block activity if minimized
|
// NOTE: Activity is paused if not enabled (appEnabled)
|
||||||
//while ((ident = ALooper_pollAll(activityMinimized ? 0 : -1, NULL, &events,(void**)&source)) >= 0)
|
while ((ident = ALooper_pollAll(appEnabled ? 0 : -1, NULL, &events,(void**)&source)) >= 0)
|
||||||
while ((ident = ALooper_pollAll(0, NULL, &events, (void**)&source)) >= 0)
|
|
||||||
{
|
{
|
||||||
// Process this event
|
// Process this event
|
||||||
if (source != NULL) source->process(app, source);
|
if (source != NULL) source->process(app, source);
|
||||||
|
|
||||||
// Check if we are exiting
|
// NOTE: Never close window, native activity is controlled by the system!
|
||||||
if (app->destroyRequested != 0)
|
if (app->destroyRequested != 0)
|
||||||
{
|
{
|
||||||
// NOTE: Never close window, native activity is controlled by the system!
|
|
||||||
//TraceLog(INFO, "Closing Window...");
|
//TraceLog(INFO, "Closing Window...");
|
||||||
//windowShouldClose = true;
|
//windowShouldClose = true;
|
||||||
|
|
||||||
//ANativeActivity_finish(app->activity);
|
//ANativeActivity_finish(app->activity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1680,7 +1963,7 @@ static void PollInputEvents(void)
|
||||||
|
|
||||||
int key = keysBuffer[i];
|
int key = keysBuffer[i];
|
||||||
|
|
||||||
if (keyboardMode == 2)
|
if (keyboardMode == 2) // scancodes
|
||||||
{
|
{
|
||||||
// NOTE: If (key == 0x1b), depending on next key, it could be a special keymap code!
|
// NOTE: If (key == 0x1b), depending on next key, it could be a special keymap code!
|
||||||
// Up -> 1b 5b 41 / Left -> 1b 5b 44 / Right -> 1b 5b 43 / Down -> 1b 5b 42
|
// Up -> 1b 5b 41 / Left -> 1b 5b 44 / Right -> 1b 5b 43 / Down -> 1b 5b 42
|
||||||
|
|
@ -1715,9 +1998,13 @@ static void PollInputEvents(void)
|
||||||
// Detect ESC to stop program
|
// Detect ESC to stop program
|
||||||
if ((key == 0x1b) && (numKeysBuffer == 1)) windowShouldClose = true;
|
if ((key == 0x1b) && (numKeysBuffer == 1)) windowShouldClose = true;
|
||||||
}
|
}
|
||||||
else if (keyboardMode == 1)
|
else if (keyboardMode == 1) // keycodes (K_MEDIUMRAW mode)
|
||||||
{
|
{
|
||||||
TraceLog(DEBUG, "Pressed key (keycode): 0x%02x", key);
|
TraceLog(DEBUG, "Pressed key (keycode): 0x%02x", key);
|
||||||
|
|
||||||
|
// NOTE: Each key is 7-bits (high bit in the byte is 0 for down, 1 for up)
|
||||||
|
|
||||||
|
// TODO: Review (or rewrite) this code... not clear... replace by events!
|
||||||
|
|
||||||
int asciiKey = -1;
|
int asciiKey = -1;
|
||||||
|
|
||||||
|
|
@ -2026,6 +2313,59 @@ static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const Emscripte
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Web: Get input events
|
||||||
|
static EM_BOOL EmscriptenInputCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
for (int i = 0; i < touchEvent->numTouches; i++)
|
||||||
|
{
|
||||||
|
long x, y, id;
|
||||||
|
|
||||||
|
if (!touchEvent->touches[i].isChanged) continue;
|
||||||
|
|
||||||
|
id = touchEvent->touches[i].identifier;
|
||||||
|
x = touchEvent->touches[i].canvasX;
|
||||||
|
y = touchEvent->touches[i].canvasY;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s, numTouches: %d %s%s%s%s\n", emscripten_event_type_to_string(eventType), event->numTouches,
|
||||||
|
event->ctrlKey ? " CTRL" : "", event->shiftKey ? " SHIFT" : "", event->altKey ? " ALT" : "", event->metaKey ? " META" : "");
|
||||||
|
|
||||||
|
for(int i = 0; i < event->numTouches; ++i)
|
||||||
|
{
|
||||||
|
const EmscriptenTouchPoint *t = &event->touches[i];
|
||||||
|
|
||||||
|
printf(" %ld: screen: (%ld,%ld), client: (%ld,%ld), page: (%ld,%ld), isChanged: %d, onTarget: %d, canvas: (%ld, %ld)\n",
|
||||||
|
t->identifier, t->screenX, t->screenY, t->clientX, t->clientY, t->pageX, t->pageY, t->isChanged, t->onTarget, t->canvasX, t->canvasY);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
GestureEvent gestureEvent;
|
||||||
|
|
||||||
|
// Register touch actions
|
||||||
|
if (eventType == EMSCRIPTEN_EVENT_TOUCHSTART) gestureEvent.touchAction = TOUCH_DOWN;
|
||||||
|
else if (eventType == EMSCRIPTEN_EVENT_TOUCHEND) gestureEvent.touchAction = TOUCH_UP;
|
||||||
|
else if (eventType == EMSCRIPTEN_EVENT_TOUCHMOVE) gestureEvent.touchAction = TOUCH_MOVE;
|
||||||
|
|
||||||
|
// Register touch points count
|
||||||
|
gestureEvent.pointCount = touchEvent->numTouches;
|
||||||
|
|
||||||
|
// Register touch points position
|
||||||
|
// NOTE: Only two points registered
|
||||||
|
// TODO: Touch data should be scaled accordingly!
|
||||||
|
//gestureEvent.position[0] = (Vector2){ touchEvent->touches[0].canvasX, touchEvent->touches[0].canvasY };
|
||||||
|
//gestureEvent.position[1] = (Vector2){ touchEvent->touches[1].canvasX, touchEvent->touches[1].canvasY };
|
||||||
|
gestureEvent.position[0] = (Vector2){ touchEvent->touches[0].targetX, touchEvent->touches[0].targetY };
|
||||||
|
gestureEvent.position[1] = (Vector2){ touchEvent->touches[1].targetX, touchEvent->touches[1].targetY };
|
||||||
|
|
||||||
|
touchPosition = gestureEvent.position[0];
|
||||||
|
|
||||||
|
// Gesture data is sent to gestures system for processing
|
||||||
|
ProcessGestureEvent(gestureEvent); // Process obtained gestures data
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Plays raylib logo appearing animation
|
// Plays raylib logo appearing animation
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user