Merge remote-tracking branch 'origin/master'
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
blank_issues_enabled: false
|
||||
10
.github/ISSUE_TEMPLATE/new-issue-template.md
vendored
|
|
@ -7,6 +7,16 @@ assignees: ''
|
|||
|
||||
---
|
||||
|
||||
**WARNING: Please, read this note carefully before submitting a new issue:**
|
||||
|
||||
It is important to realise that **this is NOT A SUPPORT FORUM**, this is for reproducible BUGS with raylib ONLY.
|
||||
|
||||
There are lots of generous and helpful people ready to help you out on [raylib Discord forum](https://discord.gg/VkzNHUE) or [raylib reddit](https://www.reddit.com/r/raylib/).
|
||||
|
||||
Remember that asking for support questions here actively takes developer time away from improving raylib.
|
||||
|
||||
---
|
||||
|
||||
Please, before submitting a new issue verify and check:
|
||||
|
||||
- [ ] I tested it on latest raylib version from master branch
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ before_install:
|
|||
if [[ "$ARCH" == *-android ]]; then
|
||||
export DONT_TEST=1;
|
||||
export RAYLIB_PACKAGE_SUFFIX="-Android-arm64";
|
||||
wget https://dl.google.com/android/repository/android-ndk-r17-linux-x86_64.zip;
|
||||
wget https://dl.google.com/android/repository/android-ndk-r21-linux-x86_64.zip;
|
||||
unzip -qq android-ndk*.zip;
|
||||
if [[ "$ARCH" == arm64-* ]]; then
|
||||
export RAYLIB_PACKAGE_SUFFIX="-Android-arm64";
|
||||
|
|
@ -70,15 +70,14 @@ before_install:
|
|||
TOOLCHAIN_ARCH=arm;
|
||||
PREFIX=arm-linux-androideabi-;
|
||||
fi;
|
||||
android-ndk*/build/tools/make_standalone_toolchain.py --arch $TOOLCHAIN_ARCH --api 21 --install-dir /tmp/android-toolchain;
|
||||
export PATH=/tmp/android-toolchain/bin:$PATH;
|
||||
export PATH=/android-ndk*/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH;
|
||||
export CC=${PREFIX}clang;
|
||||
export CXX=${PREFIX}clang++;
|
||||
export CMAKE_ARCH_ARGS='-DPLATFORM=Android';
|
||||
elif [ "$ARCH" == "html5" ]; then
|
||||
export DONT_TEST=1;
|
||||
export RAYLIB_PACKAGE_SUFFIX="-html5";
|
||||
docker run --privileged=true -dit --name emscripten -v $(pwd):/src trzeci/emscripten:sdk-incoming-64bit bash;
|
||||
docker run --privileged=true -dit --name emscripten -v $(pwd):/src trzeci/emscripten:sdk-latest bash;
|
||||
export CMAKE_ARCH_ARGS='-DPLATFORM=Web -DCMAKE_TOOLCHAIN_FILE=../cmake/emscripten.cmake';
|
||||
RUNNER='docker exec -it emscripten cmake -E chdir build';
|
||||
else
|
||||
|
|
@ -134,7 +133,7 @@ script:
|
|||
- $RUNNER cmake $CMAKE_ARCH_ARGS
|
||||
-DMACOS_FATLIB=ON
|
||||
-DSTATIC=$STATIC -DSHARED=$SHARED
|
||||
-DBUILD_EXAMPLES=ON -DBUILD_GAMES=ON
|
||||
-DBUILD_EXAMPLES=ON
|
||||
-DUSE_EXTERNAL_GLFW=$USE_EXTERNAL_GLFW
|
||||
-DUSE_WAYLAND=$WAYLAND
|
||||
-DINCLUDE_EVERYTHING=ON
|
||||
|
|
|
|||
20
BINDINGS.md
|
|
@ -34,9 +34,10 @@ Some people ported raylib to other languages in form of bindings or wrappers to
|
|||
| raylib-mruby | mruby | https://github.com/lihaochen910/raylib-mruby |
|
||||
| raylib-py | Python | https://github.com/overdev/raylib-py |
|
||||
| raylib-python-cffi | Python | https://github.com/electronstudio/raylib-python-cffi |
|
||||
| jaylib | Java | https://github.com/electronstudio/jaylib/ |
|
||||
| raylib-java | Java | https://github.com/XoanaIO/raylib-java |
|
||||
| node-raylib | Node.js | https://github.com/RobLoach/node-raylib |
|
||||
| QuickJS-raylib | QuickJS | https://github.com/sntg-p/QuickJS-raylib |
|
||||
| QuickJS-raylib | [QuickJS](https://bellard.org/quickjs/) | https://github.com/sntg-p/QuickJS-raylib |
|
||||
| raylib-js | JavaScript | https://github.com/RobLoach/raylib-js |
|
||||
| raylib-chaiscript | ChaiScript | https://github.com/RobLoach/raylib-chaiscript |
|
||||
| raylib-squirrel | Squirrel | https://github.com/RobLoach/raylib-squirrel |
|
||||
|
|
@ -45,26 +46,27 @@ Some people ported raylib to other languages in form of bindings or wrappers to
|
|||
| raylib-php-ffi | PHP | https://github.com/oraoto/raylib-php-ffi |
|
||||
| raylib-phpcpp | PHP | https://github.com/oraoto/raylib-phpcpp |
|
||||
| raylib-factor | Factor | https://github.com/Silverbeard00/raylib-factor |
|
||||
| raylib-haxe | Haxe | https://github.com/ibilon/raylib-haxe |
|
||||
| ringraylib | Ring | https://github.com/ringpackages/ringraylib |
|
||||
| raylib-haxe | [Haxe](https://haxe.org/) | https://github.com/ibilon/raylib-haxe |
|
||||
| ringraylib | [Ring](http://ring-lang.sourceforge.net/) | https://github.com/ringpackages/ringraylib |
|
||||
| cl-raylib | Common Lisp | https://github.com/longlene/cl-raylib |
|
||||
| raylib-scm | Chicken Scheme | https://github.com/yashrk/raylib-scm |
|
||||
| raylib-chibi | Chibi-Scheme | https://github.com/VincentToups/raylib-chibi |
|
||||
| Euraylib | Euphoria | https://github.com/gAndy50/Euraylib |
|
||||
| raylib-wren | Wren | https://github.com/TSnake41/raylib-wren |
|
||||
| raylib-odin | Odin | https://github.com/kevinw/raylib-odin |
|
||||
| raylib-zig | Zig | https://github.com/G3bE/raylib-zig |
|
||||
| ray.zig | Zig | https://github.com/BitPuffin/zig-raylib-experiments |
|
||||
| raylib-wren | [Wren](http://wren.io/) | https://github.com/TSnake41/raylib-wren |
|
||||
| raylib-odin | [Odin](https://odin-lang.org/) | https://github.com/kevinw/raylib-odin |
|
||||
| raylib-zig | [Zig](https://ziglang.org/) | https://github.com/G3bE/raylib-zig |
|
||||
| ray.zig | [Zig](https://ziglang.org/) | https://github.com/BitPuffin/zig-raylib-experiments |
|
||||
| raylib-Ada | Ada | https://github.com/mimo/raylib-Ada |
|
||||
| jaylib | Janet | https://github.com/janet-lang/jaylib |
|
||||
| jaylib | [Janet](https://janet-lang.org/) | https://github.com/janet-lang/jaylib |
|
||||
| raykit | Kit | https://github.com/Gamerfiend/raykit |
|
||||
| vraylib | V | https://github.com/MajorHard/vraylib |
|
||||
| vraylib | [V](https://vlang.io/) | https://github.com/MajorHard/vraylib |
|
||||
| ray.mod | BlitzMax | https://github.com/bmx-ng/ray.mod |
|
||||
| raylib-mosaic | Mosaic | https://github.com/pluckyporcupine/raylib-mosaic |
|
||||
| raylib-xdpw | XD Pascal | https://github.com/vtereshkov/raylib-xdpw |
|
||||
| raylib-carp | Carp | https://github.com/pluckyporcupine/raylib-carp |
|
||||
| raylib-fb | FreeBasic | https://github.com/IchMagBier/raylib-fb |
|
||||
| raylib-ats2 | ATS2 | https://github.com/mephistopheles-8/raylib-ats2 |
|
||||
| raylib-beef | [Beef](https://www.beeflang.org/) | https://github.com/M0n7y5/raylib-beef |
|
||||
| raylib.cbl | COBOL | *[code examples](https://github.com/Martinfx/Cobol/tree/master/OpenCobol/Games/raylib)* |
|
||||
|
||||
Missing some language? Check the [bindings not yet in this list](https://gist.github.com/raysan5/5764cc5b885183f523fce47f098f3d9b#bindings-not-yet-in-the-official-list) or create a new binding! :)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
|||
|
||||
# Config options
|
||||
option(BUILD_EXAMPLES "Build the examples." ON)
|
||||
option(BUILD_GAMES "Build the example games." ON)
|
||||
option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF)
|
||||
option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF)
|
||||
option(ENABLE_MSAN "Enable MemorySanitizer (MSan) for debugging (not recommended to run with ASAN)" OFF)
|
||||
|
|
@ -45,8 +44,4 @@ if (${BUILD_EXAMPLES})
|
|||
add_subdirectory(examples)
|
||||
endif()
|
||||
|
||||
if (${BUILD_GAMES})
|
||||
add_subdirectory(games)
|
||||
endif()
|
||||
|
||||
enable_testing()
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ Ready to learn? Jump to [code examples!](http://www.raylib.com/examples.html)
|
|||
|
||||
[](https://github.com/raysan5/raylib/graphs/contributors)
|
||||
[](https://github.com/raysan5/raylib/releases)
|
||||
[](https://github.com/raysan5/raylib/commits/master)
|
||||
[](https://github.com/raysan5/raylib/commits/master)
|
||||
[](LICENSE)
|
||||
|
||||
[](https://discord.gg/VkzNHUE)
|
||||
|
|
|
|||
|
|
@ -26,5 +26,7 @@ The following people has contributed with a generous donation to the raylib proj
|
|||
- Benjamin Stigsen ([@BenStigsen](https://github.com/BenStigsen))
|
||||
- Rahul Nair ([@rahulunair](https://github.com/rahulunair))
|
||||
- Snowminx ([@Gamerfiend](https://github.com/Gamerfiend))
|
||||
|
||||
- Dani Martin ([@danimartin82](https://github.com/danimartin82))
|
||||
- Tommi Sinivuo ([@TommiSinivuo](https://github.com/TommiSinivuo))
|
||||
- Joakim Wennergren ([@joakimwennergren](https://github.com/joakimwennergren))
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ before_build:
|
|||
- cd build
|
||||
|
||||
build_script:
|
||||
- cmake -G %GENERATOR% -DCMAKE_BUILD_TYPE=Release -DSTATIC=ON -DSHARED=ON -DBUILD_EXAMPLES=%examples% -DBUILD_GAMES=%examples% -DINCLUDE_EVERYTHING=ON ..
|
||||
- cmake -G %GENERATOR% -DCMAKE_BUILD_TYPE=Release -DSTATIC=ON -DSHARED=ON -DBUILD_EXAMPLES=%examples% -DINCLUDE_EVERYTHING=ON ..
|
||||
- cmake --build . --target install
|
||||
|
||||
after_build:
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ if(${PLATFORM} MATCHES "Android")
|
|||
list(REMOVE_ITEM example_sources ${CMAKE_CURRENT_SOURCE_DIR}/shaders/shaders_basic_lighting.c)
|
||||
|
||||
elseif(${PLATFORM} MATCHES "Web")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s ASYNCIFY")
|
||||
# Since WASM is used, ALLOW_MEMORY_GROWTH has no extra overheads
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s ALLOW_MEMORY_GROWTH=1 --no-heap-copy")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --shell-file ${CMAKE_SOURCE_DIR}/src/shell.html")
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ generate_android_manifest:
|
|||
# Generate storekey for APK signing: $(PROJECT_NAME).keystore
|
||||
# NOTE: Configure here your Distinguished Names (-dname) if required!
|
||||
generate_apk_keystore:
|
||||
if not exist $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore $(JAVA_HOME)/bin/keytool -genkeypair -validity 1000 -dname "CN=$(APP_COMPANY_NAME),O=Android,C=ES" -keystore $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore -storepass $(APP_KEYSTORE_PASS) -keypass $(APP_KEYSTORE_PASS) -alias $(PROJECT_NAME)Key -keyalg RSA
|
||||
if not exist $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore $(JAVA_HOME)/bin/keytool -genkeypair -validity 10000 -dname "CN=$(APP_COMPANY_NAME),O=Android,C=ES" -keystore $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore -storepass $(APP_KEYSTORE_PASS) -keypass $(APP_KEYSTORE_PASS) -alias $(PROJECT_NAME)Key -keyalg RSA
|
||||
|
||||
# Config project package and resource using AndroidManifest.xml and res/values/strings.xml
|
||||
# NOTE: Generates resources file: src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/R.java
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ Examples showing raylib misc functionality that does not fit in other categories
|
|||
|----|----------|--------|:----------:|:---:|
|
||||
| 113 | [raudio_standalone](others/raudio_standalone.c) | | ray | |
|
||||
| 114 | [rlgl_standalone](others/rlgl_standalone.c) | | ray | |
|
||||
| 115 | [easings_testbed](others/easings_testbed.c) | | ray | |
|
||||
| 115 | [easings_testbed](others/easings_testbed.c) | | [Juan Miguel López](https://github.com/flashback-fx) | |
|
||||
|
||||
As always contributions are welcome, feel free to send new examples! Here it is an [examples template](examples_template.c) to start with!
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2015-2017 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2015-2020 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* 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.
|
||||
|
|
@ -56,7 +56,7 @@
|
|||
#if defined(RAYMATH_IMPLEMENTATION)
|
||||
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
|
||||
#define RMDEF __declspec(dllexport) extern inline // We are building raylib as a Win32 shared library (.dll).
|
||||
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
||||
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
|
||||
#define RMDEF __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
|
||||
#else
|
||||
#define RMDEF extern inline // Provide external definition
|
||||
|
|
@ -113,7 +113,7 @@
|
|||
float y;
|
||||
float z;
|
||||
} Vector3;
|
||||
|
||||
|
||||
// Quaternion type
|
||||
typedef struct Quaternion {
|
||||
float x;
|
||||
|
|
@ -135,7 +135,7 @@
|
|||
typedef struct float3 { float v[3]; } float3;
|
||||
typedef struct float16 { float v[16]; } float16;
|
||||
|
||||
#include <math.h> // Required for: sinf(), cosf(), tan(), fabs()
|
||||
#include <math.h> // Required for: sinf(), cosf(), sqrtf(), tan(), fabs()
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Utils math
|
||||
|
|
@ -148,7 +148,7 @@ RMDEF float Clamp(float value, float min, float max)
|
|||
return res > max ? max : res;
|
||||
}
|
||||
|
||||
// Calculate linear interpolation between two vectors
|
||||
// Calculate linear interpolation between two floats
|
||||
RMDEF float Lerp(float start, float end, float amount)
|
||||
{
|
||||
return start + amount*(end - start);
|
||||
|
|
@ -179,6 +179,13 @@ RMDEF Vector2 Vector2Add(Vector2 v1, Vector2 v2)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Add vector and float value
|
||||
RMDEF Vector2 Vector2AddValue(Vector2 v, float add)
|
||||
{
|
||||
Vector2 result = { v.x + add, v.y + add };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Subtract two vectors (v1 - v2)
|
||||
RMDEF Vector2 Vector2Subtract(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
|
|
@ -186,6 +193,13 @@ RMDEF Vector2 Vector2Subtract(Vector2 v1, Vector2 v2)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Subtract vector by float value
|
||||
RMDEF Vector2 Vector2SubtractValue(Vector2 v, float sub)
|
||||
{
|
||||
Vector2 result = { v.x - sub, v.y - sub };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calculate vector length
|
||||
RMDEF float Vector2Length(Vector2 v)
|
||||
{
|
||||
|
|
@ -223,10 +237,10 @@ RMDEF Vector2 Vector2Scale(Vector2 v, float scale)
|
|||
}
|
||||
|
||||
// Multiply vector by vector
|
||||
RMDEF Vector2 Vector2MultiplyV(Vector2 v1, Vector2 v2)
|
||||
RMDEF Vector2 Vector2Multiply(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
Vector2 result = { v1.x*v2.x, v1.y*v2.y };
|
||||
return result;
|
||||
Vector2 result = { v1.x*v2.x, v1.y*v2.y };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Negate vector
|
||||
|
|
@ -236,24 +250,17 @@ RMDEF Vector2 Vector2Negate(Vector2 v)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Divide vector by a float value
|
||||
RMDEF Vector2 Vector2Divide(Vector2 v, float div)
|
||||
{
|
||||
Vector2 result = { v.x/div, v.y/div };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Divide vector by vector
|
||||
RMDEF Vector2 Vector2DivideV(Vector2 v1, Vector2 v2)
|
||||
RMDEF Vector2 Vector2Divide(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
Vector2 result = { v1.x/v2.x, v1.y/v2.y };
|
||||
return result;
|
||||
Vector2 result = { v1.x/v2.x, v1.y/v2.y };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Normalize provided vector
|
||||
RMDEF Vector2 Vector2Normalize(Vector2 v)
|
||||
{
|
||||
Vector2 result = Vector2Divide(v, Vector2Length(v));
|
||||
Vector2 result = Vector2Scale(v, 1/Vector2Length(v));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -268,6 +275,14 @@ RMDEF Vector2 Vector2Lerp(Vector2 v1, Vector2 v2, float amount)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Rotate Vector by float in Degrees.
|
||||
RMDEF Vector2 Vector2Rotate(Vector2 v, float degs)
|
||||
{
|
||||
float rads = degs*DEG2RAD;
|
||||
Vector2 result = {v.x * cosf(rads) - v.y * sinf(rads) , v.x * sinf(rads) + v.y * cosf(rads) };
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition - Vector3 math
|
||||
//----------------------------------------------------------------------------------
|
||||
|
|
@ -293,6 +308,13 @@ RMDEF Vector3 Vector3Add(Vector3 v1, Vector3 v2)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Add vector and float value
|
||||
RMDEF Vector3 Vector3AddValue(Vector3 v, float add)
|
||||
{
|
||||
Vector3 result = { v.x + add, v.y + add, v.z + add };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Subtract two vectors
|
||||
RMDEF Vector3 Vector3Subtract(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
|
|
@ -300,15 +322,22 @@ RMDEF Vector3 Vector3Subtract(Vector3 v1, Vector3 v2)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Subtract vector by float value
|
||||
RMDEF Vector3 Vector3SubtractValue(Vector3 v, float sub)
|
||||
{
|
||||
Vector3 result = { v.x - sub, v.y - sub, v.z - sub };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Multiply vector by scalar
|
||||
RMDEF Vector3 Vector3Multiply(Vector3 v, float scalar)
|
||||
RMDEF Vector3 Vector3Scale(Vector3 v, float scalar)
|
||||
{
|
||||
Vector3 result = { v.x*scalar, v.y*scalar, v.z*scalar };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Multiply vector by vector
|
||||
RMDEF Vector3 Vector3MultiplyV(Vector3 v1, Vector3 v2)
|
||||
RMDEF Vector3 Vector3Multiply(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
Vector3 result = { v1.x*v2.x, v1.y*v2.y, v1.z*v2.z };
|
||||
return result;
|
||||
|
|
@ -371,13 +400,6 @@ RMDEF float Vector3Distance(Vector3 v1, Vector3 v2)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Scale provided vector
|
||||
RMDEF Vector3 Vector3Scale(Vector3 v, float scale)
|
||||
{
|
||||
Vector3 result = { v.x*scale, v.y*scale, v.z*scale };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Negate provided vector (invert direction)
|
||||
RMDEF Vector3 Vector3Negate(Vector3 v)
|
||||
{
|
||||
|
|
@ -385,18 +407,11 @@ RMDEF Vector3 Vector3Negate(Vector3 v)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Divide vector by a float value
|
||||
RMDEF Vector3 Vector3Divide(Vector3 v, float div)
|
||||
{
|
||||
Vector3 result = { v.x / div, v.y / div, v.z / div };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Divide vector by vector
|
||||
RMDEF Vector3 Vector3DivideV(Vector3 v1, Vector3 v2)
|
||||
RMDEF Vector3 Vector3Divide(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
Vector3 result = { v1.x/v2.x, v1.y/v2.y, v1.z/v2.z };
|
||||
return result;
|
||||
Vector3 result = { v1.x/v2.x, v1.y/v2.y, v1.z/v2.z };
|
||||
return result;
|
||||
}
|
||||
|
||||
// Normalize provided vector
|
||||
|
|
@ -440,7 +455,7 @@ RMDEF Vector3 Vector3Transform(Vector3 v, Matrix mat)
|
|||
result.z = mat.m2*x + mat.m6*y + mat.m10*z + mat.m14;
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
// Transform a vector by quaternion rotation
|
||||
RMDEF Vector3 Vector3RotateByQuaternion(Vector3 v, Quaternion q)
|
||||
|
|
@ -553,20 +568,18 @@ RMDEF float3 Vector3ToFloatV(Vector3 v)
|
|||
// Compute matrix determinant
|
||||
RMDEF float MatrixDeterminant(Matrix mat)
|
||||
{
|
||||
float result = { 0 };
|
||||
|
||||
// Cache the matrix values (speed optimization)
|
||||
float a00 = mat.m0, a01 = mat.m1, a02 = mat.m2, a03 = mat.m3;
|
||||
float a10 = mat.m4, a11 = mat.m5, a12 = mat.m6, a13 = mat.m7;
|
||||
float a20 = mat.m8, a21 = mat.m9, a22 = mat.m10, a23 = mat.m11;
|
||||
float a30 = mat.m12, a31 = mat.m13, a32 = mat.m14, a33 = mat.m15;
|
||||
|
||||
result = a30*a21*a12*a03 - a20*a31*a12*a03 - a30*a11*a22*a03 + a10*a31*a22*a03 +
|
||||
a20*a11*a32*a03 - a10*a21*a32*a03 - a30*a21*a02*a13 + a20*a31*a02*a13 +
|
||||
a30*a01*a22*a13 - a00*a31*a22*a13 - a20*a01*a32*a13 + a00*a21*a32*a13 +
|
||||
a30*a11*a02*a23 - a10*a31*a02*a23 - a30*a01*a12*a23 + a00*a31*a12*a23 +
|
||||
a10*a01*a32*a23 - a00*a11*a32*a23 - a20*a11*a02*a33 + a10*a21*a02*a33 +
|
||||
a20*a01*a12*a33 - a00*a21*a12*a33 - a10*a01*a22*a33 + a00*a11*a22*a33;
|
||||
float result = a30*a21*a12*a03 - a20*a31*a12*a03 - a30*a11*a22*a03 + a10*a31*a22*a03 +
|
||||
a20*a11*a32*a03 - a10*a21*a32*a03 - a30*a21*a02*a13 + a20*a31*a02*a13 +
|
||||
a30*a01*a22*a13 - a00*a31*a22*a13 - a20*a01*a32*a13 + a00*a21*a32*a13 +
|
||||
a30*a11*a02*a23 - a10*a31*a02*a23 - a30*a01*a12*a23 + a00*a31*a12*a23 +
|
||||
a10*a01*a32*a23 - a00*a11*a32*a23 - a20*a11*a02*a33 + a10*a21*a02*a33 +
|
||||
a20*a01*a12*a33 - a00*a21*a12*a33 - a10*a01*a22*a33 + a00*a11*a22*a33;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -794,6 +807,33 @@ RMDEF Matrix MatrixRotate(Vector3 axis, float angle)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Returns xyz-rotation matrix (angles in radians)
|
||||
RMDEF Matrix MatrixRotateXYZ(Vector3 ang)
|
||||
{
|
||||
Matrix result = MatrixIdentity();
|
||||
|
||||
float cosz = cosf(-ang.z);
|
||||
float sinz = sinf(-ang.z);
|
||||
float cosy = cosf(-ang.y);
|
||||
float siny = sinf(-ang.y);
|
||||
float cosx = cosf(-ang.x);
|
||||
float sinx = sinf(-ang.x);
|
||||
|
||||
result.m0 = cosz * cosy;
|
||||
result.m4 = (cosz * siny * sinx) - (sinz * cosx);
|
||||
result.m8 = (cosz * siny * cosx) + (sinz * sinx);
|
||||
|
||||
result.m1 = sinz * cosy;
|
||||
result.m5 = (sinz * siny * sinx) + (cosz * cosx);
|
||||
result.m9 = (sinz * siny * cosx) - (cosz * sinx);
|
||||
|
||||
result.m2 = -siny;
|
||||
result.m6 = cosy * sinx;
|
||||
result.m10= cosy * cosx;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns x-rotation matrix (angle in radians)
|
||||
RMDEF Matrix MatrixRotateX(float angle)
|
||||
{
|
||||
|
|
@ -1014,6 +1054,34 @@ RMDEF float16 MatrixToFloatV(Matrix mat)
|
|||
// Module Functions Definition - Quaternion math
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Add two quaternions
|
||||
RMDEF Quaternion QuaternionAdd(Quaternion q1, Quaternion q2)
|
||||
{
|
||||
Quaternion result = {q1.x + q2.x, q1.y + q2.y, q1.z + q2.z, q1.w + q2.w};
|
||||
return result;
|
||||
}
|
||||
|
||||
// Add quaternion and float value
|
||||
RMDEF Quaternion QuaternionAddValue(Quaternion q, float add)
|
||||
{
|
||||
Quaternion result = {q.x + add, q.y + add, q.z + add, q.w + add};
|
||||
return result;
|
||||
}
|
||||
|
||||
// Subtract two quaternions
|
||||
RMDEF Quaternion QuaternionSubtract(Quaternion q1, Quaternion q2)
|
||||
{
|
||||
Quaternion result = {q1.x - q2.x, q1.y - q2.y, q1.z - q2.z, q1.w - q2.w};
|
||||
return result;
|
||||
}
|
||||
|
||||
// Subtract quaternion and float value
|
||||
RMDEF Quaternion QuaternionSubtractValue(Quaternion q, float sub)
|
||||
{
|
||||
Quaternion result = {q.x - sub, q.y - sub, q.z - sub, q.w - sub};
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns identity quaternion
|
||||
RMDEF Quaternion QuaternionIdentity(void)
|
||||
{
|
||||
|
|
@ -1082,6 +1150,28 @@ RMDEF Quaternion QuaternionMultiply(Quaternion q1, Quaternion q2)
|
|||
return result;
|
||||
}
|
||||
|
||||
// Scale quaternion by float value
|
||||
RMDEF Quaternion QuaternionScale(Quaternion q, float mul)
|
||||
{
|
||||
Quaternion result = { 0 };
|
||||
|
||||
float qax = q.x, qay = q.y, qaz = q.z, qaw = q.w;
|
||||
|
||||
result.x = qax * mul + qaw * mul + qay * mul - qaz * mul;
|
||||
result.y = qay * mul + qaw * mul + qaz * mul - qax * mul;
|
||||
result.z = qaz * mul + qaw * mul + qax * mul - qay * mul;
|
||||
result.w = qaw * mul - qax * mul - qay * mul - qaz * mul;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Divide two quaternions
|
||||
RMDEF Quaternion QuaternionDivide(Quaternion q1, Quaternion q2)
|
||||
{
|
||||
Quaternion result = {q1.x / q2.x, q1.y / q2.y, q1.z / q2.z, q1.w / q2.w};
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calculate linear interpolation between two quaternions
|
||||
RMDEF Quaternion QuaternionLerp(Quaternion q1, Quaternion q2, float amount)
|
||||
{
|
||||
|
|
@ -1115,8 +1205,8 @@ RMDEF Quaternion QuaternionSlerp(Quaternion q1, Quaternion q2, float amount)
|
|||
else if (cosHalfTheta > 0.95f) result = QuaternionNlerp(q1, q2, amount);
|
||||
else
|
||||
{
|
||||
float halfTheta = (float) acos(cosHalfTheta);
|
||||
float sinHalfTheta = (float) sqrt(1.0f - cosHalfTheta*cosHalfTheta);
|
||||
float halfTheta = acosf(cosHalfTheta);
|
||||
float sinHalfTheta = sqrtf(1.0f - cosHalfTheta*cosHalfTheta);
|
||||
|
||||
if (fabs(sinHalfTheta) < 0.001f)
|
||||
{
|
||||
|
|
@ -1159,7 +1249,7 @@ RMDEF Quaternion QuaternionFromVector3ToVector3(Vector3 from, Vector3 to)
|
|||
// Above lines are equivalent to:
|
||||
//Quaternion result = QuaternionNlerp(q, QuaternionIdentity(), 0.5f);
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Returns a quaternion for a given rotation matrix
|
||||
|
|
@ -1171,7 +1261,7 @@ RMDEF Quaternion QuaternionFromMatrix(Matrix mat)
|
|||
|
||||
if (trace > 0.0f)
|
||||
{
|
||||
float s = (float)sqrt(trace + 1)*2.0f;
|
||||
float s = sqrtf(trace + 1)*2.0f;
|
||||
float invS = 1.0f/s;
|
||||
|
||||
result.w = s*0.25f;
|
||||
|
|
@ -1195,7 +1285,7 @@ RMDEF Quaternion QuaternionFromMatrix(Matrix mat)
|
|||
}
|
||||
else if (m11 > m22)
|
||||
{
|
||||
float s = (float)sqrt(1.0f + m11 - m00 - m22)*2.0f;
|
||||
float s = sqrtf(1.0f + m11 - m00 - m22)*2.0f;
|
||||
float invS = 1.0f/s;
|
||||
|
||||
result.w = (mat.m8 - mat.m2)*invS;
|
||||
|
|
@ -1205,7 +1295,7 @@ RMDEF Quaternion QuaternionFromMatrix(Matrix mat)
|
|||
}
|
||||
else
|
||||
{
|
||||
float s = (float)sqrt(1.0f + m22 - m00 - m11)*2.0f;
|
||||
float s = sqrtf(1.0f + m22 - m00 - m11)*2.0f;
|
||||
float invS = 1.0f/s;
|
||||
|
||||
result.w = (mat.m1 - mat.m4)*invS;
|
||||
|
|
@ -1295,10 +1385,8 @@ RMDEF void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle
|
|||
if (fabs(q.w) > 1.0f) q = QuaternionNormalize(q);
|
||||
|
||||
Vector3 resAxis = { 0.0f, 0.0f, 0.0f };
|
||||
float resAngle = 0.0f;
|
||||
|
||||
resAngle = 2.0f*(float)acos(q.w);
|
||||
float den = (float)sqrt(1.0f - q.w*q.w);
|
||||
float resAngle = 2.0f*acosf(q.w);
|
||||
float den = sqrtf(1.0f - q.w*q.w);
|
||||
|
||||
if (den > 0.0001f)
|
||||
{
|
||||
|
|
@ -1320,21 +1408,21 @@ RMDEF void QuaternionToAxisAngle(Quaternion q, Vector3 *outAxis, float *outAngle
|
|||
// Returns he quaternion equivalent to Euler angles
|
||||
RMDEF Quaternion QuaternionFromEuler(float roll, float pitch, float yaw)
|
||||
{
|
||||
Quaternion q = { 0 };
|
||||
Quaternion q = { 0 };
|
||||
|
||||
float x0 = cosf(roll*0.5f);
|
||||
float x1 = sinf(roll*0.5f);
|
||||
float y0 = cosf(pitch*0.5f);
|
||||
float y1 = sinf(pitch*0.5f);
|
||||
float z0 = cosf(yaw*0.5f);
|
||||
float z1 = sinf(yaw*0.5f);
|
||||
float x0 = cosf(roll*0.5f);
|
||||
float x1 = sinf(roll*0.5f);
|
||||
float y0 = cosf(pitch*0.5f);
|
||||
float y1 = sinf(pitch*0.5f);
|
||||
float z0 = cosf(yaw*0.5f);
|
||||
float z1 = sinf(yaw*0.5f);
|
||||
|
||||
q.x = x1*y0*z0 - x0*y1*z1;
|
||||
q.y = x0*y1*z0 + x1*y0*z1;
|
||||
q.z = x0*y0*z1 - x1*y1*z0;
|
||||
q.w = x0*y0*z0 + x1*y1*z1;
|
||||
q.x = x1*y0*z0 - x0*y1*z1;
|
||||
q.y = x0*y1*z0 + x1*y0*z1;
|
||||
q.z = x0*y0*z1 - x1*y1*z0;
|
||||
q.w = x0*y0*z0 + x1*y1*z1;
|
||||
|
||||
return q;
|
||||
return q;
|
||||
}
|
||||
|
||||
// Return the Euler angles equivalent to quaternion (roll, pitch, yaw)
|
||||
|
|
@ -1343,21 +1431,21 @@ RMDEF Vector3 QuaternionToEuler(Quaternion q)
|
|||
{
|
||||
Vector3 result = { 0 };
|
||||
|
||||
// roll (x-axis rotation)
|
||||
float x0 = 2.0f*(q.w*q.x + q.y*q.z);
|
||||
float x1 = 1.0f - 2.0f*(q.x*q.x + q.y*q.y);
|
||||
result.x = atan2f(x0, x1)*RAD2DEG;
|
||||
// roll (x-axis rotation)
|
||||
float x0 = 2.0f*(q.w*q.x + q.y*q.z);
|
||||
float x1 = 1.0f - 2.0f*(q.x*q.x + q.y*q.y);
|
||||
result.x = atan2f(x0, x1)*RAD2DEG;
|
||||
|
||||
// pitch (y-axis rotation)
|
||||
float y0 = 2.0f*(q.w*q.y - q.z*q.x);
|
||||
y0 = y0 > 1.0f ? 1.0f : y0;
|
||||
y0 = y0 < -1.0f ? -1.0f : y0;
|
||||
result.y = asinf(y0)*RAD2DEG;
|
||||
// pitch (y-axis rotation)
|
||||
float y0 = 2.0f*(q.w*q.y - q.z*q.x);
|
||||
y0 = y0 > 1.0f ? 1.0f : y0;
|
||||
y0 = y0 < -1.0f ? -1.0f : y0;
|
||||
result.y = asinf(y0)*RAD2DEG;
|
||||
|
||||
// yaw (z-axis rotation)
|
||||
float z0 = 2.0f*(q.w*q.z + q.x*q.y);
|
||||
float z1 = 1.0f - 2.0f*(q.y*q.y + q.z*q.z);
|
||||
result.z = atan2f(z0, z1)*RAD2DEG;
|
||||
// yaw (z-axis rotation)
|
||||
float z0 = 2.0f*(q.w*q.z + q.x*q.y);
|
||||
float z1 = 1.0f - 2.0f*(q.y*q.y + q.z*q.z);
|
||||
result.z = atan2f(z0, z1)*RAD2DEG;
|
||||
|
||||
return result;
|
||||
}
|
||||
1466
examples/models/raymath.h
Normal file
1466
examples/shaders/raymath.h
Normal file
|
|
@ -245,7 +245,7 @@ void ResetStar(Star *s)
|
|||
|
||||
} while (!(fabs(s->vel.x) + fabs(s->vel.y) > 1));
|
||||
|
||||
s->pos = Vector2Add(s->pos, Vector2MultiplyV(s->vel, (Vector2){ 8, 8 }));
|
||||
s->pos = Vector2Add(s->pos, Vector2Multiply(s->vel, (Vector2){ 8, 8 }));
|
||||
}
|
||||
|
||||
void UpdateStar(Star *s)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ int main(void)
|
|||
Font font = LoadFont("resources/custom_jupiter_crash.png");
|
||||
|
||||
// Draw over image using custom font
|
||||
ImageDrawTextEx(&parrots, (Vector2){ 300, 230 }, font, "PARROTS & CAT", font.baseSize, -2, WHITE);
|
||||
ImageDrawTextEx(&parrots, font, "PARROTS & CAT", (Vector2){ 300, 230 }, font.baseSize, -2, WHITE);
|
||||
|
||||
UnloadFont(font); // Unload custom spritefont (already drawn used on image)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ int main(void)
|
|||
Font font = LoadFontEx("resources/KAISG.ttf", 64, 0, 0);
|
||||
|
||||
// Draw over image using custom font
|
||||
ImageDrawTextEx(&parrots, (Vector2){ 20.0f, 20.0f }, font, "[Parrots font drawing]", (float)font.baseSize, 0.0f, RED);
|
||||
ImageDrawTextEx(&parrots, font, "[Parrots font drawing]", (Vector2){ 20.0f, 20.0f }, (float)font.baseSize, 0.0f, RED);
|
||||
|
||||
Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM)
|
||||
UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
# Setup the project and settings
|
||||
project(games)
|
||||
|
||||
# Get the source toegher
|
||||
file(GLOB sources *.c)
|
||||
|
||||
set(OUTPUT_EXT)
|
||||
|
||||
if(${PLATFORM} MATCHES "Web")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Os -s USE_GLFW=3 -s ASSERTIONS=1 -s WASM=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --shell-file ${CMAKE_SOURCE_DIR}/src/shell.html")
|
||||
set(OUTPUT_EXT ".html")
|
||||
|
||||
# Remove the -rdynamic flag because otherwise emscripten
|
||||
# does not generate HTML+JS+WASM files, only a non-working
|
||||
# and fat HTML
|
||||
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
|
||||
endif()
|
||||
|
||||
if (NOT TARGET raylib)
|
||||
find_package(raylib 2.0 REQUIRED)
|
||||
endif()
|
||||
|
||||
# Do each game
|
||||
foreach(game_source ${sources})
|
||||
# Create the basename for the game
|
||||
get_filename_component(game_name ${game_source} NAME)
|
||||
string(REPLACE ".c" "${OUTPUT_EXT}" game_name ${game_name})
|
||||
|
||||
# Setup the game
|
||||
add_executable(${game_name} ${game_source})
|
||||
|
||||
# Link the libraries
|
||||
target_link_libraries(${game_name} raylib)
|
||||
endforeach()
|
||||
|
||||
# Do the games with subdirectories
|
||||
add_subdirectory(drturtle)
|
||||
add_subdirectory(just_do)
|
||||
add_subdirectory(koala_seasons)
|
||||
add_subdirectory(light_my_ritual)
|
||||
add_subdirectory(skully_escape)
|
||||
add_subdirectory(wave_collector)
|
||||
398
games/Makefile
|
|
@ -1,398 +0,0 @@
|
|||
#**************************************************************************************************
|
||||
#
|
||||
# raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5
|
||||
#
|
||||
# Copyright (c) 2013-2020 Ramon Santamaria (@raysan5)
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#**************************************************************************************************
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
# Define required raylib variables
|
||||
PROJECT_NAME ?= raylib_examples
|
||||
RAYLIB_VERSION ?= 3.0.0
|
||||
RAYLIB_API_VERSION ?= 3
|
||||
RAYLIB_PATH ?= ..
|
||||
|
||||
# Define default options
|
||||
|
||||
# One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
PLATFORM ?= PLATFORM_DESKTOP
|
||||
|
||||
# Locations of your newly installed library and associated headers. See ../src/Makefile
|
||||
# On Linux, if you have installed raylib but cannot compile the examples, check that
|
||||
# the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations.
|
||||
# To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED.
|
||||
# To enable compile-time linking to a special version of libraylib.so, change these variables here.
|
||||
# To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below.
|
||||
# If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime,
|
||||
# the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH.
|
||||
# RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths.
|
||||
DESTDIR ?= /usr/local
|
||||
RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib
|
||||
# RAYLIB_H_INSTALL_PATH locates the installed raylib header and associated source files.
|
||||
RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include
|
||||
|
||||
# Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
|
||||
RAYLIB_LIBTYPE ?= STATIC
|
||||
|
||||
# Build mode for project: DEBUG or RELEASE
|
||||
BUILD_MODE ?= RELEASE
|
||||
|
||||
# Use external GLFW library instead of rglfw module
|
||||
# TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3
|
||||
USE_EXTERNAL_GLFW ?= FALSE
|
||||
|
||||
# Use Wayland display server protocol on Linux desktop
|
||||
# by default it uses X11 windowing system
|
||||
USE_WAYLAND_DISPLAY ?= FALSE
|
||||
|
||||
# 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
|
||||
else
|
||||
UNAMEOS=$(shell uname)
|
||||
ifeq ($(UNAMEOS),Linux)
|
||||
PLATFORM_OS=LINUX
|
||||
endif
|
||||
ifeq ($(UNAMEOS),FreeBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),OpenBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),NetBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),DragonFly)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),Darwin)
|
||||
PLATFORM_OS=OSX
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
UNAMEOS=$(shell uname)
|
||||
ifeq ($(UNAMEOS),Linux)
|
||||
PLATFORM_OS=LINUX
|
||||
endif
|
||||
endif
|
||||
|
||||
# RAYLIB_PATH adjustment for different platforms.
|
||||
# If using GNU make, we can get the full path to the top of the tree. Windows? BSD?
|
||||
# Required for ldconfig or other tools that do not perform path expansion.
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
RAYLIB_PREFIX ?= ..
|
||||
RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX))
|
||||
endif
|
||||
endif
|
||||
# Default path for raylib on Raspberry Pi, if installed in different path, update it!
|
||||
# This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki.
|
||||
# TODO: update install: target in src/Makefile for RPI, consider relation to LINUX.
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
RAYLIB_PATH ?= /home/pi/raylib
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# Emscripten required variables
|
||||
EMSDK_PATH ?= C:/emsdk
|
||||
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/fastcomp/emscripten
|
||||
CLANG_PATH = $(EMSDK_PATH)/fastcomp/bin
|
||||
PYTHON_PATH = $(EMSDK_PATH)/python/2.7.13.1_64bit/python-2.7.13.amd64
|
||||
NODE_PATH = $(EMSDK_PATH)/node/12.9.1_64bit/bin
|
||||
export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH);C:\raylib\MinGW\bin:$$(PATH)
|
||||
endif
|
||||
|
||||
# Define raylib release directory for compiled library.
|
||||
# RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version
|
||||
RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src
|
||||
|
||||
# EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries
|
||||
# into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH
|
||||
# so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux
|
||||
# without formal installation from ../src/Makefile. It aids portability and is useful if you have
|
||||
# multiple versions of raylib, have raylib installed to a non-standard location, or want to
|
||||
# bundle libraylib.so with your game. Change it to your liking.
|
||||
# NOTE: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH,
|
||||
# The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH,
|
||||
# Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
|
||||
# To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute.
|
||||
# To see which libraries a built example is linking to, ldd core/core_basic_window;
|
||||
# Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing.
|
||||
EXAMPLE_RUNTIME_PATH ?= $(RAYLIB_RELEASE_PATH)
|
||||
|
||||
# Define default C compiler: gcc
|
||||
# NOTE: define g++ compiler if using C++
|
||||
CC = gcc
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
# OSX default compiler
|
||||
CC = clang
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# FreeBSD, OpenBSD, NetBSD, DragonFly default compiler
|
||||
CC = clang
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
ifeq ($(USE_RPI_CROSS_COMPILER),TRUE)
|
||||
# Define RPI cross-compiler
|
||||
#CC = armv6j-hardfloat-linux-gnueabi-gcc
|
||||
CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# HTML5 emscripten compiler
|
||||
# WARNING: To compile to HTML5, code must be redesigned
|
||||
# to use emscripten.h and emscripten_set_main_loop()
|
||||
CC = emcc
|
||||
endif
|
||||
|
||||
# Define default make program: Mingw32-make
|
||||
MAKE = mingw32-make
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
MAKE = make
|
||||
endif
|
||||
endif
|
||||
|
||||
# Define compiler flags:
|
||||
# -O1 defines optimization level
|
||||
# -g include debug information on compilation
|
||||
# -s strip unnecessary data from build
|
||||
# -Wall turns on most, but not all, compiler warnings
|
||||
# -std=c99 defines C language mode (standard C from 1999 revision)
|
||||
# -std=gnu99 defines C language mode (GNU C from 1999 revision)
|
||||
# -Wno-missing-braces ignore invalid warning (GCC bug 53119)
|
||||
# -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
|
||||
CFLAGS += -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces
|
||||
|
||||
ifeq ($(BUILD_MODE),DEBUG)
|
||||
CFLAGS += -g
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
CFLAGS += -s ASSERTIONS=1 --profiling
|
||||
endif
|
||||
else
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
CFLAGS += -Os
|
||||
else
|
||||
CFLAGS += -s -O1
|
||||
endif
|
||||
endif
|
||||
|
||||
# Additional flags for compiler (if desired)
|
||||
#CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
# resource file contains windows executable icon and properties
|
||||
# -Wl,--subsystem,windows hides the console window
|
||||
CFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data
|
||||
ifeq ($(BUILD_MODE), RELEASE)
|
||||
CFLAGS += -Wl,--subsystem,windows
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
ifeq ($(RAYLIB_LIBTYPE),STATIC)
|
||||
CFLAGS += -D_DEFAULT_SOURCE
|
||||
endif
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
# Explicitly enable runtime link to libraylib.so
|
||||
CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
CFLAGS += -std=gnu99
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# -Os # size optimization
|
||||
# -O2 # optimization level 2, if used, also set --memory-init-file 0
|
||||
# -s USE_GLFW=3 # Use glfw3 library (context/input management)
|
||||
# -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing -> WARNING: Audio buffers could FAIL!
|
||||
# -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
|
||||
# -s USE_PTHREADS=1 # multithreading support
|
||||
# -s WASM=0 # disable Web Assembly, emitted by default
|
||||
# -s EMTERPRETIFY=1 # enable emscripten code interpreter (very slow)
|
||||
# -s EMTERPRETIFY_ASYNC=1 # support synchronous loops by emterpreter
|
||||
# -s FORCE_FILESYSTEM=1 # force filesystem to load/save files data
|
||||
# -s ASSERTIONS=1 # enable runtime checks for common memory allocation errors (-O1 and above turn it off)
|
||||
# --profiling # include information for code profiling
|
||||
# --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
|
||||
# --preload-file resources # specify a resources folder for data compilation
|
||||
CFLAGS += -s USE_GLFW=3
|
||||
|
||||
# Define a custom shell .html and output extension
|
||||
CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
|
||||
EXT = .html
|
||||
endif
|
||||
|
||||
# Define include paths for required headers
|
||||
# NOTE: Several external required libraries (stb and others)
|
||||
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
|
||||
|
||||
# Define additional directories containing required header files
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
# RPI required libraries
|
||||
INCLUDE_PATHS += -I/opt/vc/include
|
||||
INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux
|
||||
INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Consider -L$(RAYLIB_H_INSTALL_PATH)
|
||||
INCLUDE_PATHS += -I/usr/local/include
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Reset everything.
|
||||
# Precedence: immediately local, installed version, raysan5 provided libs -I$(RAYLIB_H_INSTALL_PATH) -I$(RAYLIB_PATH)/release/include
|
||||
INCLUDE_PATHS = -I$(RAYLIB_H_INSTALL_PATH) -isystem. -isystem$(RAYLIB_PATH)/src -isystem$(RAYLIB_PATH)/release/include -isystem$(RAYLIB_PATH)/src/external
|
||||
endif
|
||||
endif
|
||||
|
||||
# Define library paths containing required libs.
|
||||
LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Consider -L$(RAYLIB_INSTALL_PATH)
|
||||
LDFLAGS += -L. -Lsrc -L/usr/local/lib
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Reset everything.
|
||||
# Precedence: immediately local, installed version, raysan5 provided libs
|
||||
LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
LDFLAGS += -L/opt/vc/lib
|
||||
endif
|
||||
|
||||
# Define any libraries required on linking
|
||||
# if you want to link libraries (libname.so or libname.a), use the -lname
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
# Libraries for Windows desktop compilation
|
||||
# NOTE: WinMM library required to set high-res timer resolution
|
||||
LDLIBS = -lraylib -lopengl32 -lgdi32 -lwinmm
|
||||
# Required for physac examples
|
||||
LDLIBS += -static -lpthread
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Libraries for Debian GNU/Linux desktop compiling
|
||||
# NOTE: Required packages: libegl1-mesa-dev
|
||||
LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
|
||||
|
||||
# On X11 requires also below libraries
|
||||
LDLIBS += -lX11
|
||||
# NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
|
||||
#LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||
|
||||
# On Wayland windowing system, additional libraries requires
|
||||
ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
|
||||
LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
|
||||
endif
|
||||
# Explicit link to libc
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
LDLIBS += -lc
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
# Libraries for OSX 10.9 desktop compiling
|
||||
# NOTE: Required packages: libopenal-dev libegl1-mesa-dev
|
||||
LDLIBS = -lraylib -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling
|
||||
# NOTE: Required packages: mesa-libs
|
||||
LDLIBS = -lraylib -lGL -lpthread -lm
|
||||
|
||||
# On XWindow requires also below libraries
|
||||
LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||
endif
|
||||
ifeq ($(USE_EXTERNAL_GLFW),TRUE)
|
||||
# NOTE: It could require additional packages installed: libglfw3-dev
|
||||
LDLIBS += -lglfw
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
# Libraries for Raspberry Pi compiling
|
||||
# NOTE: Required packages: libasound2-dev (ALSA)
|
||||
LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# Libraries for web (HTML5) compiling
|
||||
LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc
|
||||
endif
|
||||
|
||||
# Define all source files required
|
||||
SAMPLES = \
|
||||
arkanoid \
|
||||
asteroids \
|
||||
asteroids_survival \
|
||||
floppy \
|
||||
gold_fever \
|
||||
gorilas \
|
||||
missile_commander \
|
||||
pang \
|
||||
snake \
|
||||
space_invaders \
|
||||
tetris \
|
||||
|
||||
# typing 'make' will invoke the default target entry
|
||||
all: $(SAMPLES)
|
||||
|
||||
# Generic compilation pattern
|
||||
# NOTE: Examples must be ready for Android compilation!
|
||||
%: %.c
|
||||
ifeq ($(PLATFORM),PLATFORM_ANDROID)
|
||||
$(MAKE) -f Makefile.Android PROJECT_NAME=$@ PROJECT_SOURCE_FILES=$<
|
||||
else
|
||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||
endif
|
||||
|
||||
# Clean everything
|
||||
clean:
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
del *.o *.exe /s
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable|x-pie-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -fv
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
find . -type f -perm +ugo+x -delete
|
||||
rm -f *.o
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
find . -type f -executable -delete
|
||||
rm -fv *.o
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
del *.o *.html *.js
|
||||
endif
|
||||
@echo Cleaning done
|
||||
|
||||
|
|
@ -1,300 +0,0 @@
|
|||
#**************************************************************************************************
|
||||
#
|
||||
# raylib makefile for Android project (APK building)
|
||||
#
|
||||
# Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
#
|
||||
# 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 required raylib variables
|
||||
PLATFORM ?= PLATFORM_ANDROID
|
||||
RAYLIB_PATH ?= ..\..
|
||||
|
||||
# Define Android architecture (armeabi-v7a, arm64-v8a, x86, x86-64) and API version
|
||||
ANDROID_ARCH ?= ARM
|
||||
ANDROID_API_VERSION = 21
|
||||
ifeq ($(ANDROID_ARCH),ARM)
|
||||
ANDROID_ARCH_NAME = armeabi-v7a
|
||||
endif
|
||||
ifeq ($(ANDROID_ARCH),ARM64)
|
||||
ANDROID_ARCH_NAME = arm64-v8a
|
||||
endif
|
||||
|
||||
# Required path variables
|
||||
# NOTE: JAVA_HOME must be set to JDK
|
||||
JAVA_HOME ?= C:/JavaJDK
|
||||
ANDROID_HOME = C:/android-sdk
|
||||
ANDROID_TOOLCHAIN = C:/android_toolchain_$(ANDROID_ARCH)_API$(ANDROID_API_VERSION)
|
||||
ANDROID_BUILD_TOOLS = $(ANDROID_HOME)/build-tools/28.0.1
|
||||
ANDROID_PLATFORM_TOOLS = $(ANDROID_HOME)/platform-tools
|
||||
|
||||
# Android project configuration variables
|
||||
PROJECT_NAME ?= raylib_game
|
||||
PROJECT_LIBRARY_NAME ?= main
|
||||
PROJECT_BUILD_PATH ?= android.$(PROJECT_NAME)
|
||||
PROJECT_RESOURCES_PATH ?= resources
|
||||
PROJECT_SOURCE_FILES ?= raylib_game.c
|
||||
|
||||
# Some source files are placed in directories, when compiling to some
|
||||
# output directory other than source, that directory must pre-exist.
|
||||
# Here we get a list of required folders that need to be created on
|
||||
# code output folder $(PROJECT_BUILD_PATH)\obj to avoid GCC errors.
|
||||
PROJECT_SOURCE_DIRS = $(sort $(dir $(PROJECT_SOURCE_FILES)))
|
||||
|
||||
# Android app configuration variables
|
||||
APP_LABEL_NAME ?= rGame
|
||||
APP_COMPANY_NAME ?= raylib
|
||||
APP_PRODUCT_NAME ?= rgame
|
||||
APP_VERSION_CODE ?= 1
|
||||
APP_VERSION_NAME ?= 1.0
|
||||
APP_ICON_LDPI ?= $(RAYLIB_PATH)\logo\raylib_36x36.png
|
||||
APP_ICON_MDPI ?= $(RAYLIB_PATH)\logo\raylib_48x48.png
|
||||
APP_ICON_HDPI ?= $(RAYLIB_PATH)\logo\raylib_72x72.png
|
||||
APP_SCREEN_ORIENTATION ?= landscape
|
||||
APP_KEYSTORE_PASS ?= raylib
|
||||
|
||||
# Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
|
||||
RAYLIB_LIBTYPE ?= STATIC
|
||||
|
||||
# Library path for libraylib.a/libraylib.so
|
||||
RAYLIB_LIB_PATH = $(RAYLIB_PATH)\src
|
||||
|
||||
# Shared libs must be added to APK if required
|
||||
# NOTE: Generated NativeLoader.java automatically load those libraries
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
PROJECT_SHARED_LIBS = lib/$(ANDROID_ARCH_NAME)/libraylib.so
|
||||
endif
|
||||
|
||||
# Compiler and archiver
|
||||
# NOTE: GCC is being deprecated in Android NDK r16
|
||||
ifeq ($(ANDROID_ARCH),ARM)
|
||||
CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-clang
|
||||
AR = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-ar
|
||||
endif
|
||||
ifeq ($(ANDROID_ARCH),ARM64)
|
||||
CC = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-clang
|
||||
AR = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-ar
|
||||
endif
|
||||
|
||||
# Compiler flags for arquitecture
|
||||
ifeq ($(ANDROID_ARCH),ARM)
|
||||
CFLAGS = -std=c99 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
|
||||
endif
|
||||
ifeq ($(ANDROID_ARCH),ARM64)
|
||||
CFLAGS = -std=c99 -target aarch64 -mfix-cortex-a53-835769
|
||||
endif
|
||||
# Compilation functions attributes options
|
||||
CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC
|
||||
# Compiler options for the linker
|
||||
CFLAGS += -Wall -Wa,--noexecstack -Wformat -Werror=format-security -no-canonical-prefixes
|
||||
# Preprocessor macro definitions
|
||||
CFLAGS += -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=$(ANDROID_API_VERSION)
|
||||
|
||||
# Paths containing required header files
|
||||
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external/android/native_app_glue
|
||||
|
||||
# Linker options
|
||||
LDFLAGS = -Wl,-soname,lib$(PROJECT_LIBRARY_NAME).so -Wl,--exclude-libs,libatomic.a
|
||||
LDFLAGS += -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings
|
||||
# Force linking of library module to define symbol
|
||||
LDFLAGS += -u ANativeActivity_onCreate
|
||||
# Library paths containing required libs
|
||||
LDFLAGS += -L. -L$(PROJECT_BUILD_PATH)/obj -L$(PROJECT_BUILD_PATH)/lib/$(ANDROID_ARCH_NAME) -L$(ANDROID_TOOLCHAIN)\sysroot\usr\lib
|
||||
|
||||
# Define any libraries to link into executable
|
||||
# if you want to link libraries (libname.so or libname.a), use the -lname
|
||||
LDLIBS = -lm -lc -lraylib -llog -landroid -lEGL -lGLESv2 -lOpenSLES -ldl
|
||||
|
||||
# Generate target objects list from PROJECT_SOURCE_FILES
|
||||
OBJS = $(patsubst %.c, $(PROJECT_BUILD_PATH)/obj/%.o, $(PROJECT_SOURCE_FILES))
|
||||
|
||||
# Android APK building process... some steps required...
|
||||
# NOTE: typing 'make' will invoke the default target entry called 'all',
|
||||
all: create_temp_project_dirs \
|
||||
copy_project_required_libs \
|
||||
copy_project_resources \
|
||||
generate_loader_script \
|
||||
generate_android_manifest \
|
||||
generate_apk_keystore \
|
||||
config_project_package \
|
||||
compile_project_code \
|
||||
compile_project_class \
|
||||
compile_project_class_dex \
|
||||
create_project_apk_package \
|
||||
sign_project_apk_package \
|
||||
zipalign_project_apk_package
|
||||
|
||||
# Create required temp directories for APK building
|
||||
create_temp_project_dirs:
|
||||
if not exist $(PROJECT_BUILD_PATH) mkdir $(PROJECT_BUILD_PATH)
|
||||
if not exist $(PROJECT_BUILD_PATH)\obj mkdir $(PROJECT_BUILD_PATH)\obj
|
||||
if not exist $(PROJECT_BUILD_PATH)\src mkdir $(PROJECT_BUILD_PATH)\src
|
||||
if not exist $(PROJECT_BUILD_PATH)\src\com mkdir $(PROJECT_BUILD_PATH)\src\com
|
||||
if not exist $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME) mkdir $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME)
|
||||
if not exist $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME)\$(APP_PRODUCT_NAME) mkdir $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME)\$(APP_PRODUCT_NAME)
|
||||
if not exist $(PROJECT_BUILD_PATH)\lib mkdir $(PROJECT_BUILD_PATH)\lib
|
||||
if not exist $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME) mkdir $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME)
|
||||
if not exist $(PROJECT_BUILD_PATH)\bin mkdir $(PROJECT_BUILD_PATH)\bin
|
||||
if not exist $(PROJECT_BUILD_PATH)\res mkdir $(PROJECT_BUILD_PATH)\res
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\drawable-ldpi mkdir $(PROJECT_BUILD_PATH)\res\drawable-ldpi
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\drawable-mdpi mkdir $(PROJECT_BUILD_PATH)\res\drawable-mdpi
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\drawable-hdpi mkdir $(PROJECT_BUILD_PATH)\res\drawable-hdpi
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\values mkdir $(PROJECT_BUILD_PATH)\res\values
|
||||
if not exist $(PROJECT_BUILD_PATH)\assets mkdir $(PROJECT_BUILD_PATH)\assets
|
||||
if not exist $(PROJECT_BUILD_PATH)\assets\$(PROJECT_RESOURCES_PATH) mkdir $(PROJECT_BUILD_PATH)\assets\$(PROJECT_RESOURCES_PATH)
|
||||
if not exist $(PROJECT_BUILD_PATH)\obj\screens mkdir $(PROJECT_BUILD_PATH)\obj\screens
|
||||
$(foreach dir, $(PROJECT_SOURCE_DIRS), $(call create_dir, $(dir)))
|
||||
|
||||
define create_dir
|
||||
if not exist $(PROJECT_BUILD_PATH)\obj\$(1) mkdir $(PROJECT_BUILD_PATH)\obj\$(1)
|
||||
endef
|
||||
|
||||
# Copy required shared libs for integration into APK
|
||||
# NOTE: If using shared libs they are loaded by generated NativeLoader.java
|
||||
copy_project_required_libs:
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
copy /Y $(RAYLIB_LIB_PATH)\libraylib.so $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME)\libraylib.so
|
||||
endif
|
||||
ifeq ($(RAYLIB_LIBTYPE),STATIC)
|
||||
copy /Y $(RAYLIB_LIB_PATH)\libraylib.a $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME)\libraylib.a
|
||||
endif
|
||||
|
||||
# Copy project required resources: strings.xml, icon.png, assets
|
||||
# NOTE: Required strings.xml is generated and game resources are copied to assets folder
|
||||
# TODO: Review xcopy usage, it can not be found in some systems!
|
||||
copy_project_resources:
|
||||
copy $(APP_ICON_LDPI) $(PROJECT_BUILD_PATH)\res\drawable-ldpi\icon.png /Y
|
||||
copy $(APP_ICON_MDPI) $(PROJECT_BUILD_PATH)\res\drawable-mdpi\icon.png /Y
|
||||
copy $(APP_ICON_HDPI) $(PROJECT_BUILD_PATH)\res\drawable-hdpi\icon.png /Y
|
||||
@echo ^<?xml version="1.0" encoding="utf-8"^?^> > $(PROJECT_BUILD_PATH)/res/values/strings.xml
|
||||
@echo ^<resources^>^<string name="app_name"^>$(APP_LABEL_NAME)^</string^>^</resources^> >> $(PROJECT_BUILD_PATH)/res/values/strings.xml
|
||||
if exist $(PROJECT_RESOURCES_PATH) C:\Windows\System32\xcopy $(PROJECT_RESOURCES_PATH) $(PROJECT_BUILD_PATH)\assets\$(PROJECT_RESOURCES_PATH) /Y /E /F
|
||||
|
||||
# Generate NativeLoader.java to load required shared libraries
|
||||
# NOTE: Probably not the bet way to generate this file... but it works.
|
||||
generate_loader_script:
|
||||
@echo package com.$(APP_COMPANY_NAME).$(APP_PRODUCT_NAME); > $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo. >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo public class NativeLoader extends android.app.NativeActivity { >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo static { >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
@echo System.loadLibrary("raylib"); >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
endif
|
||||
@echo System.loadLibrary("$(PROJECT_LIBRARY_NAME)"); >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo } >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo } >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
|
||||
# Generate AndroidManifest.xml with all the required options
|
||||
# NOTE: Probably not the bet way to generate this file... but it works.
|
||||
generate_android_manifest:
|
||||
@echo ^<?xml version="1.0" encoding="utf-8"^?^> > $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<manifest xmlns:android="http://schemas.android.com/apk/res/android" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo package="com.$(APP_COMPANY_NAME).$(APP_PRODUCT_NAME)" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:versionCode="$(APP_VERSION_CODE)" android:versionName="$(APP_VERSION_NAME)" ^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<uses-sdk android:minSdkVersion="$(ANDROID_API_VERSION)" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<uses-feature android:glEsVersion="0x00020000" android:required="true" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<application android:allowBackup="false" android:label="@string/app_name" android:icon="@drawable/icon" ^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<activity android:name="com.$(APP_COMPANY_NAME).$(APP_PRODUCT_NAME).NativeLoader" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:configChanges="orientation|keyboardHidden|screenSize" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:screenOrientation="$(APP_SCREEN_ORIENTATION)" android:launchMode="singleTask" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:clearTaskOnLaunch="true"^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<meta-data android:name="android.app.lib_name" android:value="$(PROJECT_LIBRARY_NAME)" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<intent-filter^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<action android:name="android.intent.action.MAIN" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<category android:name="android.intent.category.LAUNCHER" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</intent-filter^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</activity^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</application^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</manifest^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
|
||||
# Generate storekey for APK signing: $(PROJECT_NAME).keystore
|
||||
# NOTE: Configure here your Distinguished Names (-dname) if required!
|
||||
generate_apk_keystore:
|
||||
if not exist $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore $(JAVA_HOME)/bin/keytool -genkeypair -validity 1000 -dname "CN=$(APP_COMPANY_NAME),O=Android,C=ES" -keystore $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore -storepass $(APP_KEYSTORE_PASS) -keypass $(APP_KEYSTORE_PASS) -alias $(PROJECT_NAME)Key -keyalg RSA
|
||||
|
||||
# Config project package and resource using AndroidManifest.xml and res/values/strings.xml
|
||||
# NOTE: Generates resources file: src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/R.java
|
||||
config_project_package:
|
||||
$(ANDROID_BUILD_TOOLS)/aapt package -f -m -S $(PROJECT_BUILD_PATH)/res -J $(PROJECT_BUILD_PATH)/src -M $(PROJECT_BUILD_PATH)/AndroidManifest.xml -I $(ANDROID_HOME)/platforms/android-$(ANDROID_API_VERSION)/android.jar
|
||||
|
||||
# Compile native_app_glue code as static library: obj/libnative_app_glue.a
|
||||
compile_native_app_glue:
|
||||
$(CC) -c $(RAYLIB_PATH)/src/external/android/native_app_glue/android_native_app_glue.c -o $(PROJECT_BUILD_PATH)/obj/native_app_glue.o $(CFLAGS)
|
||||
$(AR) rcs $(PROJECT_BUILD_PATH)/obj/libnative_app_glue.a $(PROJECT_BUILD_PATH)/obj/native_app_glue.o
|
||||
|
||||
# Compile project code into a shared library: lib/lib$(PROJECT_LIBRARY_NAME).so
|
||||
compile_project_code: $(OBJS)
|
||||
$(CC) -o $(PROJECT_BUILD_PATH)/lib/$(ANDROID_ARCH_NAME)/lib$(PROJECT_LIBRARY_NAME).so $(OBJS) -shared $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
# Compile all .c files required into object (.o) files
|
||||
# NOTE: Those files will be linked into a shared library
|
||||
$(PROJECT_BUILD_PATH)/obj/%.o:%.c
|
||||
$(CC) -c $^ -o $@ $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot
|
||||
|
||||
# Compile project .java code into .class (Java bytecode)
|
||||
compile_project_class:
|
||||
$(JAVA_HOME)/bin/javac -verbose -source 1.7 -target 1.7 -d $(PROJECT_BUILD_PATH)/obj -bootclasspath $(JAVA_HOME)/jre/lib/rt.jar -classpath $(ANDROID_HOME)/platforms/android-$(ANDROID_API_VERSION)/android.jar;$(PROJECT_BUILD_PATH)/obj -sourcepath $(PROJECT_BUILD_PATH)/src $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/R.java $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
|
||||
# Compile .class files into Dalvik executable bytecode (.dex)
|
||||
# NOTE: Since Android 5.0, Dalvik interpreter (JIT) has been replaced by ART (AOT)
|
||||
compile_project_class_dex:
|
||||
$(ANDROID_BUILD_TOOLS)/dx --verbose --dex --output=$(PROJECT_BUILD_PATH)/bin/classes.dex $(PROJECT_BUILD_PATH)/obj
|
||||
|
||||
# Create Android APK package: bin/$(PROJECT_NAME).unsigned.apk
|
||||
# NOTE: Requires compiled classes.dex and lib$(PROJECT_LIBRARY_NAME).so
|
||||
# NOTE: Use -A resources to define additional directory in which to find raw asset files
|
||||
create_project_apk_package:
|
||||
$(ANDROID_BUILD_TOOLS)/aapt package -f -M $(PROJECT_BUILD_PATH)/AndroidManifest.xml -S $(PROJECT_BUILD_PATH)/res -A $(PROJECT_BUILD_PATH)/assets -I $(ANDROID_HOME)/platforms/android-$(ANDROID_API_VERSION)/android.jar -F $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).unsigned.apk $(PROJECT_BUILD_PATH)/bin
|
||||
cd $(PROJECT_BUILD_PATH) && $(ANDROID_BUILD_TOOLS)/aapt add bin/$(PROJECT_NAME).unsigned.apk lib/$(ANDROID_ARCH_NAME)/lib$(PROJECT_LIBRARY_NAME).so $(PROJECT_SHARED_LIBS)
|
||||
|
||||
# Create signed APK package using generated Key: bin/$(PROJECT_NAME).signed.apk
|
||||
sign_project_apk_package:
|
||||
$(JAVA_HOME)/bin/jarsigner -keystore $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore -storepass $(APP_KEYSTORE_PASS) -keypass $(APP_KEYSTORE_PASS) -signedjar $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).signed.apk $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).unsigned.apk $(PROJECT_NAME)Key
|
||||
|
||||
# Create zip-aligned APK package: $(PROJECT_NAME).apk
|
||||
zipalign_project_apk_package:
|
||||
$(ANDROID_BUILD_TOOLS)/zipalign -f 4 $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).signed.apk $(PROJECT_NAME).apk
|
||||
|
||||
# Install $(PROJECT_NAME).apk to default emulator/device
|
||||
# NOTE: Use -e (emulator) or -d (device) parameters if required
|
||||
install:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb install --abi $(ANDROID_ARCH_NAME) -rds $(PROJECT_NAME).apk
|
||||
|
||||
# Check supported ABI for the device (armeabi-v7a, arm64-v8a, x86, x86_64)
|
||||
check_device_abi:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb shell getprop ro.product.cpu.abi
|
||||
|
||||
# Monitorize output log coming from device, only raylib tag
|
||||
logcat:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat -c
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat raylib:V *:S
|
||||
|
||||
# Install and monitorize $(PROJECT_NAME).apk to default emulator/device
|
||||
deploy:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb install -r $(PROJECT_NAME).apk
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat -c
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat raylib:V *:S
|
||||
|
||||
#$(ANDROID_PLATFORM_TOOLS)/adb logcat *:W
|
||||
|
||||
# Clean everything
|
||||
clean:
|
||||
del $(PROJECT_BUILD_PATH)\* /f /s /q
|
||||
rmdir $(PROJECT_BUILD_PATH) /s /q
|
||||
@echo Cleaning done
|
||||
323
games/arkanoid.c
|
|
@ -1,323 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib - sample game: arkanoid
|
||||
*
|
||||
* Sample game Marc Palau and Ramon Santamaria
|
||||
*
|
||||
* This game has been created using raylib v1.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"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Some Defines
|
||||
//----------------------------------------------------------------------------------
|
||||
#define PLAYER_MAX_LIFE 5
|
||||
#define LINES_OF_BRICKS 5
|
||||
#define BRICKS_PER_LINE 20
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
typedef enum GameScreen { LOGO, TITLE, GAMEPLAY, ENDING } GameScreen;
|
||||
|
||||
typedef struct Player {
|
||||
Vector2 position;
|
||||
Vector2 size;
|
||||
int life;
|
||||
} Player;
|
||||
|
||||
typedef struct Ball {
|
||||
Vector2 position;
|
||||
Vector2 speed;
|
||||
int radius;
|
||||
bool active;
|
||||
} Ball;
|
||||
|
||||
typedef struct Brick {
|
||||
Vector2 position;
|
||||
bool active;
|
||||
} Brick;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Global Variables Declaration
|
||||
//------------------------------------------------------------------------------------
|
||||
static const int screenWidth = 800;
|
||||
static const int screenHeight = 450;
|
||||
|
||||
static bool gameOver = false;
|
||||
static bool pause = false;
|
||||
|
||||
static Player player = { 0 };
|
||||
static Ball ball = { 0 };
|
||||
static Brick brick[LINES_OF_BRICKS][BRICKS_PER_LINE] = { 0 };
|
||||
static Vector2 brickSize = { 0 };
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Declaration (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
static void InitGame(void); // Initialize game
|
||||
static void UpdateGame(void); // Update game (one frame)
|
||||
static void DrawGame(void); // Draw game (one frame)
|
||||
static void UnloadGame(void); // Unload game
|
||||
static void UpdateDrawFrame(void); // Update and Draw (one frame)
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
// Initialization (Note windowTitle is unused on Android)
|
||||
//---------------------------------------------------------
|
||||
InitWindow(screenWidth, screenHeight, "sample game: arkanoid");
|
||||
|
||||
InitGame();
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||
#else
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update and Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateDrawFrame();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
#endif
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadGame(); // Unload loaded data (textures, sounds, models...)
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Definitions (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
// Initialize game variables
|
||||
void InitGame(void)
|
||||
{
|
||||
brickSize = (Vector2){ GetScreenWidth()/BRICKS_PER_LINE, 40 };
|
||||
|
||||
// Initialize player
|
||||
player.position = (Vector2){ screenWidth/2, screenHeight*7/8 };
|
||||
player.size = (Vector2){ screenWidth/10, 20 };
|
||||
player.life = PLAYER_MAX_LIFE;
|
||||
|
||||
// Initialize ball
|
||||
ball.position = (Vector2){ screenWidth/2, screenHeight*7/8 - 30 };
|
||||
ball.speed = (Vector2){ 0, 0 };
|
||||
ball.radius = 7;
|
||||
ball.active = false;
|
||||
|
||||
// Initialize bricks
|
||||
int initialDownPosition = 50;
|
||||
|
||||
for (int i = 0; i < LINES_OF_BRICKS; i++)
|
||||
{
|
||||
for (int j = 0; j < BRICKS_PER_LINE; j++)
|
||||
{
|
||||
brick[i][j].position = (Vector2){ j*brickSize.x + brickSize.x/2, i*brickSize.y + initialDownPosition };
|
||||
brick[i][j].active = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update game (one frame)
|
||||
void UpdateGame(void)
|
||||
{
|
||||
if (!gameOver)
|
||||
{
|
||||
if (IsKeyPressed('P')) pause = !pause;
|
||||
|
||||
if (!pause)
|
||||
{
|
||||
// Player movement logic
|
||||
if (IsKeyDown(KEY_LEFT)) player.position.x -= 5;
|
||||
if ((player.position.x - player.size.x/2) <= 0) player.position.x = player.size.x/2;
|
||||
if (IsKeyDown(KEY_RIGHT)) player.position.x += 5;
|
||||
if ((player.position.x + player.size.x/2) >= screenWidth) player.position.x = screenWidth - player.size.x/2;
|
||||
|
||||
// Ball launching logic
|
||||
if (!ball.active)
|
||||
{
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
ball.active = true;
|
||||
ball.speed = (Vector2){ 0, -5 };
|
||||
}
|
||||
}
|
||||
|
||||
// Ball movement logic
|
||||
if (ball.active)
|
||||
{
|
||||
ball.position.x += ball.speed.x;
|
||||
ball.position.y += ball.speed.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
ball.position = (Vector2){ player.position.x, screenHeight*7/8 - 30 };
|
||||
}
|
||||
|
||||
// Collision logic: ball vs walls
|
||||
if (((ball.position.x + ball.radius) >= screenWidth) || ((ball.position.x - ball.radius) <= 0)) ball.speed.x *= -1;
|
||||
if ((ball.position.y - ball.radius) <= 0) ball.speed.y *= -1;
|
||||
if ((ball.position.y + ball.radius) >= screenHeight)
|
||||
{
|
||||
ball.speed = (Vector2){ 0, 0 };
|
||||
ball.active = false;
|
||||
|
||||
player.life--;
|
||||
}
|
||||
|
||||
// Collision logic: ball vs player
|
||||
if (CheckCollisionCircleRec(ball.position, ball.radius,
|
||||
(Rectangle){ player.position.x - player.size.x/2, player.position.y - player.size.y/2, player.size.x, player.size.y}))
|
||||
{
|
||||
if (ball.speed.y > 0)
|
||||
{
|
||||
ball.speed.y *= -1;
|
||||
ball.speed.x = (ball.position.x - player.position.x)/(player.size.x/2)*5;
|
||||
}
|
||||
}
|
||||
|
||||
// Collision logic: ball vs bricks
|
||||
for (int i = 0; i < LINES_OF_BRICKS; i++)
|
||||
{
|
||||
for (int j = 0; j < BRICKS_PER_LINE; j++)
|
||||
{
|
||||
if (brick[i][j].active)
|
||||
{
|
||||
// Hit below
|
||||
if (((ball.position.y - ball.radius) <= (brick[i][j].position.y + brickSize.y/2)) &&
|
||||
((ball.position.y - ball.radius) > (brick[i][j].position.y + brickSize.y/2 + ball.speed.y)) &&
|
||||
((fabs(ball.position.x - brick[i][j].position.x)) < (brickSize.x/2 + ball.radius*2/3)) && (ball.speed.y < 0))
|
||||
{
|
||||
brick[i][j].active = false;
|
||||
ball.speed.y *= -1;
|
||||
}
|
||||
// Hit above
|
||||
else if (((ball.position.y + ball.radius) >= (brick[i][j].position.y - brickSize.y/2)) &&
|
||||
((ball.position.y + ball.radius) < (brick[i][j].position.y - brickSize.y/2 + ball.speed.y)) &&
|
||||
((fabs(ball.position.x - brick[i][j].position.x)) < (brickSize.x/2 + ball.radius*2/3)) && (ball.speed.y > 0))
|
||||
{
|
||||
brick[i][j].active = false;
|
||||
ball.speed.y *= -1;
|
||||
}
|
||||
// Hit left
|
||||
else if (((ball.position.x + ball.radius) >= (brick[i][j].position.x - brickSize.x/2)) &&
|
||||
((ball.position.x + ball.radius) < (brick[i][j].position.x - brickSize.x/2 + ball.speed.x)) &&
|
||||
((fabs(ball.position.y - brick[i][j].position.y)) < (brickSize.y/2 + ball.radius*2/3)) && (ball.speed.x > 0))
|
||||
{
|
||||
brick[i][j].active = false;
|
||||
ball.speed.x *= -1;
|
||||
}
|
||||
// Hit right
|
||||
else if (((ball.position.x - ball.radius) <= (brick[i][j].position.x + brickSize.x/2)) &&
|
||||
((ball.position.x - ball.radius) > (brick[i][j].position.x + brickSize.x/2 + ball.speed.x)) &&
|
||||
((fabs(ball.position.y - brick[i][j].position.y)) < (brickSize.y/2 + ball.radius*2/3)) && (ball.speed.x < 0))
|
||||
{
|
||||
brick[i][j].active = false;
|
||||
ball.speed.x *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Game over logic
|
||||
if (player.life <= 0) gameOver = true;
|
||||
else
|
||||
{
|
||||
gameOver = true;
|
||||
|
||||
for (int i = 0; i < LINES_OF_BRICKS; i++)
|
||||
{
|
||||
for (int j = 0; j < BRICKS_PER_LINE; j++)
|
||||
{
|
||||
if (brick[i][j].active) gameOver = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
InitGame();
|
||||
gameOver = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw game (one frame)
|
||||
void DrawGame(void)
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
if (!gameOver)
|
||||
{
|
||||
// Draw player bar
|
||||
DrawRectangle(player.position.x - player.size.x/2, player.position.y - player.size.y/2, player.size.x, player.size.y, BLACK);
|
||||
|
||||
// Draw player lives
|
||||
for (int i = 0; i < player.life; i++) DrawRectangle(20 + 40*i, screenHeight - 30, 35, 10, LIGHTGRAY);
|
||||
|
||||
// Draw ball
|
||||
DrawCircleV(ball.position, ball.radius, MAROON);
|
||||
|
||||
// Draw bricks
|
||||
for (int i = 0; i < LINES_OF_BRICKS; i++)
|
||||
{
|
||||
for (int j = 0; j < BRICKS_PER_LINE; j++)
|
||||
{
|
||||
if (brick[i][j].active)
|
||||
{
|
||||
if ((i + j) % 2 == 0) DrawRectangle(brick[i][j].position.x - brickSize.x/2, brick[i][j].position.y - brickSize.y/2, brickSize.x, brickSize.y, GRAY);
|
||||
else DrawRectangle(brick[i][j].position.x - brickSize.x/2, brick[i][j].position.y - brickSize.y/2, brickSize.x, brickSize.y, DARKGRAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
|
||||
}
|
||||
else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// Unload game variables
|
||||
void UnloadGame(void)
|
||||
{
|
||||
// TODO: Unload all dynamic loaded data (textures, sounds, models...)
|
||||
}
|
||||
|
||||
// Update and Draw (one frame)
|
||||
void UpdateDrawFrame(void)
|
||||
{
|
||||
UpdateGame();
|
||||
DrawGame();
|
||||
}
|
||||
|
|
@ -1,565 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib - sample game: asteroids
|
||||
*
|
||||
* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria
|
||||
*
|
||||
* This game has been created using raylib v1.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"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Some Defines
|
||||
//----------------------------------------------------------------------------------
|
||||
#define PLAYER_BASE_SIZE 20.0f
|
||||
#define PLAYER_SPEED 6.0f
|
||||
#define PLAYER_MAX_SHOOTS 10
|
||||
|
||||
#define METEORS_SPEED 2
|
||||
#define MAX_BIG_METEORS 4
|
||||
#define MAX_MEDIUM_METEORS 8
|
||||
#define MAX_SMALL_METEORS 16
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
typedef struct Player {
|
||||
Vector2 position;
|
||||
Vector2 speed;
|
||||
float acceleration;
|
||||
float rotation;
|
||||
Vector3 collider;
|
||||
Color color;
|
||||
} Player;
|
||||
|
||||
typedef struct Shoot {
|
||||
Vector2 position;
|
||||
Vector2 speed;
|
||||
float radius;
|
||||
float rotation;
|
||||
int lifeSpawn;
|
||||
bool active;
|
||||
Color color;
|
||||
} Shoot;
|
||||
|
||||
typedef struct Meteor {
|
||||
Vector2 position;
|
||||
Vector2 speed;
|
||||
float radius;
|
||||
bool active;
|
||||
Color color;
|
||||
} Meteor;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Global Variables Declaration
|
||||
//------------------------------------------------------------------------------------
|
||||
static const int screenWidth = 800;
|
||||
static const int screenHeight = 450;
|
||||
|
||||
static bool gameOver = false;
|
||||
static bool pause = false;
|
||||
static bool victory = false;
|
||||
|
||||
// NOTE: Defined triangle is isosceles with common angles of 70 degrees.
|
||||
static float shipHeight = 0.0f;
|
||||
|
||||
static Player player = { 0 };
|
||||
static Shoot shoot[PLAYER_MAX_SHOOTS] = { 0 };
|
||||
static Meteor bigMeteor[MAX_BIG_METEORS] = { 0 };
|
||||
static Meteor mediumMeteor[MAX_MEDIUM_METEORS] = { 0 };
|
||||
static Meteor smallMeteor[MAX_SMALL_METEORS] = { 0 };
|
||||
|
||||
static int midMeteorsCount = 0;
|
||||
static int smallMeteorsCount = 0;
|
||||
static int destroyedMeteorsCount = 0;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Declaration (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
static void InitGame(void); // Initialize game
|
||||
static void UpdateGame(void); // Update game (one frame)
|
||||
static void DrawGame(void); // Draw game (one frame)
|
||||
static void UnloadGame(void); // Unload game
|
||||
static void UpdateDrawFrame(void); // Update and Draw (one frame)
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
// Initialization (Note windowTitle is unused on Android)
|
||||
//---------------------------------------------------------
|
||||
InitWindow(screenWidth, screenHeight, "sample game: asteroids");
|
||||
|
||||
InitGame();
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||
#else
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update and Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateDrawFrame();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
#endif
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadGame(); // Unload loaded data (textures, sounds, models...)
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Definitions (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
// Initialize game variables
|
||||
void InitGame(void)
|
||||
{
|
||||
int posx, posy;
|
||||
int velx, vely;
|
||||
bool correctRange = false;
|
||||
victory = false;
|
||||
pause = false;
|
||||
|
||||
shipHeight = (PLAYER_BASE_SIZE/2)/tanf(20*DEG2RAD);
|
||||
|
||||
// Initialization player
|
||||
player.position = (Vector2){screenWidth/2, screenHeight/2 - shipHeight/2};
|
||||
player.speed = (Vector2){0, 0};
|
||||
player.acceleration = 0;
|
||||
player.rotation = 0;
|
||||
player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12};
|
||||
player.color = LIGHTGRAY;
|
||||
|
||||
destroyedMeteorsCount = 0;
|
||||
|
||||
// Initialization shoot
|
||||
for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
|
||||
{
|
||||
shoot[i].position = (Vector2){0, 0};
|
||||
shoot[i].speed = (Vector2){0, 0};
|
||||
shoot[i].radius = 2;
|
||||
shoot[i].active = false;
|
||||
shoot[i].lifeSpawn = 0;
|
||||
shoot[i].color = WHITE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_BIG_METEORS; i++)
|
||||
{
|
||||
posx = GetRandomValue(0, screenWidth);
|
||||
|
||||
while(!correctRange)
|
||||
{
|
||||
if (posx > screenWidth/2 - 150 && posx < screenWidth/2 + 150) posx = GetRandomValue(0, screenWidth);
|
||||
else correctRange = true;
|
||||
}
|
||||
|
||||
correctRange = false;
|
||||
|
||||
posy = GetRandomValue(0, screenHeight);
|
||||
|
||||
while(!correctRange)
|
||||
{
|
||||
if (posy > screenHeight/2 - 150 && posy < screenHeight/2 + 150) posy = GetRandomValue(0, screenHeight);
|
||||
else correctRange = true;
|
||||
}
|
||||
|
||||
bigMeteor[i].position = (Vector2){posx, posy};
|
||||
|
||||
correctRange = false;
|
||||
velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
|
||||
while(!correctRange)
|
||||
{
|
||||
if (velx == 0 && vely == 0)
|
||||
{
|
||||
velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
}
|
||||
else correctRange = true;
|
||||
}
|
||||
|
||||
bigMeteor[i].speed = (Vector2){velx, vely};
|
||||
bigMeteor[i].radius = 40;
|
||||
bigMeteor[i].active = true;
|
||||
bigMeteor[i].color = BLUE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_MEDIUM_METEORS; i++)
|
||||
{
|
||||
mediumMeteor[i].position = (Vector2){-100, -100};
|
||||
mediumMeteor[i].speed = (Vector2){0,0};
|
||||
mediumMeteor[i].radius = 20;
|
||||
mediumMeteor[i].active = false;
|
||||
mediumMeteor[i].color = BLUE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_SMALL_METEORS; i++)
|
||||
{
|
||||
smallMeteor[i].position = (Vector2){-100, -100};
|
||||
smallMeteor[i].speed = (Vector2){0,0};
|
||||
smallMeteor[i].radius = 10;
|
||||
smallMeteor[i].active = false;
|
||||
smallMeteor[i].color = BLUE;
|
||||
}
|
||||
|
||||
midMeteorsCount = 0;
|
||||
smallMeteorsCount = 0;
|
||||
}
|
||||
|
||||
// Update game (one frame)
|
||||
void UpdateGame(void)
|
||||
{
|
||||
if (!gameOver)
|
||||
{
|
||||
if (IsKeyPressed('P')) pause = !pause;
|
||||
|
||||
if (!pause)
|
||||
{
|
||||
// Player logic: rotation
|
||||
if (IsKeyDown(KEY_LEFT)) player.rotation -= 5;
|
||||
if (IsKeyDown(KEY_RIGHT)) player.rotation += 5;
|
||||
|
||||
// Player logic: speed
|
||||
player.speed.x = sin(player.rotation*DEG2RAD)*PLAYER_SPEED;
|
||||
player.speed.y = cos(player.rotation*DEG2RAD)*PLAYER_SPEED;
|
||||
|
||||
// Player logic: acceleration
|
||||
if (IsKeyDown(KEY_UP))
|
||||
{
|
||||
if (player.acceleration < 1) player.acceleration += 0.04f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.acceleration > 0) player.acceleration -= 0.02f;
|
||||
else if (player.acceleration < 0) player.acceleration = 0;
|
||||
}
|
||||
if (IsKeyDown(KEY_DOWN))
|
||||
{
|
||||
if (player.acceleration > 0) player.acceleration -= 0.04f;
|
||||
else if (player.acceleration < 0) player.acceleration = 0;
|
||||
}
|
||||
|
||||
// Player logic: movement
|
||||
player.position.x += (player.speed.x*player.acceleration);
|
||||
player.position.y -= (player.speed.y*player.acceleration);
|
||||
|
||||
// Collision logic: player vs walls
|
||||
if (player.position.x > screenWidth + shipHeight) player.position.x = -(shipHeight);
|
||||
else if (player.position.x < -(shipHeight)) player.position.x = screenWidth + shipHeight;
|
||||
if (player.position.y > (screenHeight + shipHeight)) player.position.y = -(shipHeight);
|
||||
else if (player.position.y < -(shipHeight)) player.position.y = screenHeight + shipHeight;
|
||||
|
||||
// Player shoot logic
|
||||
if (IsKeyPressed(KEY_SPACE))
|
||||
{
|
||||
for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
|
||||
{
|
||||
if (!shoot[i].active)
|
||||
{
|
||||
shoot[i].position = (Vector2){ player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight) };
|
||||
shoot[i].active = true;
|
||||
shoot[i].speed.x = 1.5*sin(player.rotation*DEG2RAD)*PLAYER_SPEED;
|
||||
shoot[i].speed.y = 1.5*cos(player.rotation*DEG2RAD)*PLAYER_SPEED;
|
||||
shoot[i].rotation = player.rotation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shoot life timer
|
||||
for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
|
||||
{
|
||||
if (shoot[i].active) shoot[i].lifeSpawn++;
|
||||
}
|
||||
|
||||
// Shot logic
|
||||
for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
|
||||
{
|
||||
if (shoot[i].active)
|
||||
{
|
||||
// Movement
|
||||
shoot[i].position.x += shoot[i].speed.x;
|
||||
shoot[i].position.y -= shoot[i].speed.y;
|
||||
|
||||
// Collision logic: shoot vs walls
|
||||
if (shoot[i].position.x > screenWidth + shoot[i].radius)
|
||||
{
|
||||
shoot[i].active = false;
|
||||
shoot[i].lifeSpawn = 0;
|
||||
}
|
||||
else if (shoot[i].position.x < 0 - shoot[i].radius)
|
||||
{
|
||||
shoot[i].active = false;
|
||||
shoot[i].lifeSpawn = 0;
|
||||
}
|
||||
if (shoot[i].position.y > screenHeight + shoot[i].radius)
|
||||
{
|
||||
shoot[i].active = false;
|
||||
shoot[i].lifeSpawn = 0;
|
||||
}
|
||||
else if (shoot[i].position.y < 0 - shoot[i].radius)
|
||||
{
|
||||
shoot[i].active = false;
|
||||
shoot[i].lifeSpawn = 0;
|
||||
}
|
||||
|
||||
// Life of shoot
|
||||
if (shoot[i].lifeSpawn >= 60)
|
||||
{
|
||||
shoot[i].position = (Vector2){0, 0};
|
||||
shoot[i].speed = (Vector2){0, 0};
|
||||
shoot[i].lifeSpawn = 0;
|
||||
shoot[i].active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Collision logic: player vs meteors
|
||||
player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12};
|
||||
|
||||
for (int a = 0; a < MAX_BIG_METEORS; a++)
|
||||
{
|
||||
if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, bigMeteor[a].position, bigMeteor[a].radius) && bigMeteor[a].active) gameOver = true;
|
||||
}
|
||||
|
||||
for (int a = 0; a < MAX_MEDIUM_METEORS; a++)
|
||||
{
|
||||
if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, mediumMeteor[a].position, mediumMeteor[a].radius) && mediumMeteor[a].active) gameOver = true;
|
||||
}
|
||||
|
||||
for (int a = 0; a < MAX_SMALL_METEORS; a++)
|
||||
{
|
||||
if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, smallMeteor[a].position, smallMeteor[a].radius) && smallMeteor[a].active) gameOver = true;
|
||||
}
|
||||
|
||||
// Meteors logic: big meteors
|
||||
for (int i = 0; i < MAX_BIG_METEORS; i++)
|
||||
{
|
||||
if (bigMeteor[i].active)
|
||||
{
|
||||
// Movement
|
||||
bigMeteor[i].position.x += bigMeteor[i].speed.x;
|
||||
bigMeteor[i].position.y += bigMeteor[i].speed.y;
|
||||
|
||||
// Collision logic: meteor vs wall
|
||||
if (bigMeteor[i].position.x > screenWidth + bigMeteor[i].radius) bigMeteor[i].position.x = -(bigMeteor[i].radius);
|
||||
else if (bigMeteor[i].position.x < 0 - bigMeteor[i].radius) bigMeteor[i].position.x = screenWidth + bigMeteor[i].radius;
|
||||
if (bigMeteor[i].position.y > screenHeight + bigMeteor[i].radius) bigMeteor[i].position.y = -(bigMeteor[i].radius);
|
||||
else if (bigMeteor[i].position.y < 0 - bigMeteor[i].radius) bigMeteor[i].position.y = screenHeight + bigMeteor[i].radius;
|
||||
}
|
||||
}
|
||||
|
||||
// Meteors logic: medium meteors
|
||||
for (int i = 0; i < MAX_MEDIUM_METEORS; i++)
|
||||
{
|
||||
if (mediumMeteor[i].active)
|
||||
{
|
||||
// Movement
|
||||
mediumMeteor[i].position.x += mediumMeteor[i].speed.x;
|
||||
mediumMeteor[i].position.y += mediumMeteor[i].speed.y;
|
||||
|
||||
// Collision logic: meteor vs wall
|
||||
if (mediumMeteor[i].position.x > screenWidth + mediumMeteor[i].radius) mediumMeteor[i].position.x = -(mediumMeteor[i].radius);
|
||||
else if (mediumMeteor[i].position.x < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.x = screenWidth + mediumMeteor[i].radius;
|
||||
if (mediumMeteor[i].position.y > screenHeight + mediumMeteor[i].radius) mediumMeteor[i].position.y = -(mediumMeteor[i].radius);
|
||||
else if (mediumMeteor[i].position.y < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.y = screenHeight + mediumMeteor[i].radius;
|
||||
}
|
||||
}
|
||||
|
||||
// Meteors logic: small meteors
|
||||
for (int i = 0; i < MAX_SMALL_METEORS; i++)
|
||||
{
|
||||
if (smallMeteor[i].active)
|
||||
{
|
||||
// Movement
|
||||
smallMeteor[i].position.x += smallMeteor[i].speed.x;
|
||||
smallMeteor[i].position.y += smallMeteor[i].speed.y;
|
||||
|
||||
// Collision logic: meteor vs wall
|
||||
if (smallMeteor[i].position.x > screenWidth + smallMeteor[i].radius) smallMeteor[i].position.x = -(smallMeteor[i].radius);
|
||||
else if (smallMeteor[i].position.x < 0 - smallMeteor[i].radius) smallMeteor[i].position.x = screenWidth + smallMeteor[i].radius;
|
||||
if (smallMeteor[i].position.y > screenHeight + smallMeteor[i].radius) smallMeteor[i].position.y = -(smallMeteor[i].radius);
|
||||
else if (smallMeteor[i].position.y < 0 - smallMeteor[i].radius) smallMeteor[i].position.y = screenHeight + smallMeteor[i].radius;
|
||||
}
|
||||
}
|
||||
|
||||
// Collision logic: player-shoots vs meteors
|
||||
for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
|
||||
{
|
||||
if ((shoot[i].active))
|
||||
{
|
||||
for (int a = 0; a < MAX_BIG_METEORS; a++)
|
||||
{
|
||||
if (bigMeteor[a].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, bigMeteor[a].position, bigMeteor[a].radius))
|
||||
{
|
||||
shoot[i].active = false;
|
||||
shoot[i].lifeSpawn = 0;
|
||||
bigMeteor[a].active = false;
|
||||
destroyedMeteorsCount++;
|
||||
|
||||
for (int j = 0; j < 2; j ++)
|
||||
{
|
||||
if (midMeteorsCount%2 == 0)
|
||||
{
|
||||
mediumMeteor[midMeteorsCount].position = (Vector2){bigMeteor[a].position.x, bigMeteor[a].position.y};
|
||||
mediumMeteor[midMeteorsCount].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1};
|
||||
}
|
||||
else
|
||||
{
|
||||
mediumMeteor[midMeteorsCount].position = (Vector2){bigMeteor[a].position.x, bigMeteor[a].position.y};
|
||||
mediumMeteor[midMeteorsCount].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED};
|
||||
}
|
||||
|
||||
mediumMeteor[midMeteorsCount].active = true;
|
||||
midMeteorsCount ++;
|
||||
}
|
||||
//bigMeteor[a].position = (Vector2){-100, -100};
|
||||
bigMeteor[a].color = RED;
|
||||
a = MAX_BIG_METEORS;
|
||||
}
|
||||
}
|
||||
|
||||
for (int b = 0; b < MAX_MEDIUM_METEORS; b++)
|
||||
{
|
||||
if (mediumMeteor[b].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, mediumMeteor[b].position, mediumMeteor[b].radius))
|
||||
{
|
||||
shoot[i].active = false;
|
||||
shoot[i].lifeSpawn = 0;
|
||||
mediumMeteor[b].active = false;
|
||||
destroyedMeteorsCount++;
|
||||
|
||||
for (int j = 0; j < 2; j ++)
|
||||
{
|
||||
if (smallMeteorsCount%2 == 0)
|
||||
{
|
||||
smallMeteor[smallMeteorsCount].position = (Vector2){mediumMeteor[b].position.x, mediumMeteor[b].position.y};
|
||||
smallMeteor[smallMeteorsCount].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED*-1};
|
||||
}
|
||||
else
|
||||
{
|
||||
smallMeteor[smallMeteorsCount].position = (Vector2){mediumMeteor[b].position.x, mediumMeteor[b].position.y};
|
||||
smallMeteor[smallMeteorsCount].speed = (Vector2){cos(shoot[i].rotation*DEG2RAD)*METEORS_SPEED, sin(shoot[i].rotation*DEG2RAD)*METEORS_SPEED};
|
||||
}
|
||||
|
||||
smallMeteor[smallMeteorsCount].active = true;
|
||||
smallMeteorsCount ++;
|
||||
}
|
||||
//mediumMeteor[b].position = (Vector2){-100, -100};
|
||||
mediumMeteor[b].color = GREEN;
|
||||
b = MAX_MEDIUM_METEORS;
|
||||
}
|
||||
}
|
||||
|
||||
for (int c = 0; c < MAX_SMALL_METEORS; c++)
|
||||
{
|
||||
if (smallMeteor[c].active && CheckCollisionCircles(shoot[i].position, shoot[i].radius, smallMeteor[c].position, smallMeteor[c].radius))
|
||||
{
|
||||
shoot[i].active = false;
|
||||
shoot[i].lifeSpawn = 0;
|
||||
smallMeteor[c].active = false;
|
||||
destroyedMeteorsCount++;
|
||||
smallMeteor[c].color = YELLOW;
|
||||
// smallMeteor[c].position = (Vector2){-100, -100};
|
||||
c = MAX_SMALL_METEORS;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (destroyedMeteorsCount == MAX_BIG_METEORS + MAX_MEDIUM_METEORS + MAX_SMALL_METEORS) victory = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
InitGame();
|
||||
gameOver = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw game (one frame)
|
||||
void DrawGame(void)
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
if (!gameOver)
|
||||
{
|
||||
// Draw spaceship
|
||||
Vector2 v1 = { player.position.x + sinf(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cosf(player.rotation*DEG2RAD)*(shipHeight) };
|
||||
Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) };
|
||||
Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) };
|
||||
DrawTriangle(v1, v2, v3, MAROON);
|
||||
|
||||
// Draw meteors
|
||||
for (int i = 0; i < MAX_BIG_METEORS; i++)
|
||||
{
|
||||
if (bigMeteor[i].active) DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, DARKGRAY);
|
||||
else DrawCircleV(bigMeteor[i].position, bigMeteor[i].radius, Fade(LIGHTGRAY, 0.3f));
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_MEDIUM_METEORS; i++)
|
||||
{
|
||||
if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, GRAY);
|
||||
else DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(LIGHTGRAY, 0.3f));
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_SMALL_METEORS; i++)
|
||||
{
|
||||
if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, GRAY);
|
||||
else DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(LIGHTGRAY, 0.3f));
|
||||
}
|
||||
|
||||
// Draw shoot
|
||||
for (int i = 0; i < PLAYER_MAX_SHOOTS; i++)
|
||||
{
|
||||
if (shoot[i].active) DrawCircleV(shoot[i].position, shoot[i].radius, BLACK);
|
||||
}
|
||||
|
||||
if (victory) DrawText("VICTORY", screenWidth/2 - MeasureText("VICTORY", 20)/2, screenHeight/2, 20, LIGHTGRAY);
|
||||
|
||||
if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
|
||||
}
|
||||
else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// Unload game variables
|
||||
void UnloadGame(void)
|
||||
{
|
||||
// TODO: Unload all dynamic loaded data (textures, sounds, models...)
|
||||
}
|
||||
|
||||
// Update and Draw (one frame)
|
||||
void UpdateDrawFrame(void)
|
||||
{
|
||||
UpdateGame();
|
||||
DrawGame();
|
||||
}
|
||||
|
|
@ -1,375 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib - sample game: asteroids survival
|
||||
*
|
||||
* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria
|
||||
*
|
||||
* This game has been created using raylib v1.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"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Some Defines
|
||||
//----------------------------------------------------------------------------------
|
||||
#define PLAYER_BASE_SIZE 20.0f
|
||||
#define PLAYER_SPEED 6.0f
|
||||
#define PLAYER_MAX_SHOOTS 10
|
||||
|
||||
#define METEORS_SPEED 2
|
||||
#define MAX_MEDIUM_METEORS 8
|
||||
#define MAX_SMALL_METEORS 16
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
typedef struct Player {
|
||||
Vector2 position;
|
||||
Vector2 speed;
|
||||
float acceleration;
|
||||
float rotation;
|
||||
Vector3 collider;
|
||||
Color color;
|
||||
} Player;
|
||||
|
||||
typedef struct Meteor {
|
||||
Vector2 position;
|
||||
Vector2 speed;
|
||||
float radius;
|
||||
bool active;
|
||||
Color color;
|
||||
} Meteor;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Global Variables Declaration
|
||||
//------------------------------------------------------------------------------------
|
||||
static const int screenWidth = 800;
|
||||
static const int screenHeight = 450;
|
||||
|
||||
static int framesCounter = 0;
|
||||
static bool gameOver = false;
|
||||
static bool pause = false;
|
||||
|
||||
// NOTE: Defined triangle is isosceles with common angles of 70 degrees.
|
||||
static float shipHeight = 0.0f;
|
||||
|
||||
static Player player = { 0 };
|
||||
static Meteor mediumMeteor[MAX_MEDIUM_METEORS] = { 0 };
|
||||
static Meteor smallMeteor[MAX_SMALL_METEORS] = { 0 };
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Declaration (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
static void InitGame(void); // Initialize game
|
||||
static void UpdateGame(void); // Update game (one frame)
|
||||
static void DrawGame(void); // Draw game (one frame)
|
||||
static void UnloadGame(void); // Unload game
|
||||
static void UpdateDrawFrame(void); // Update and Draw (one frame)
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
// Initialization (Note windowTitle is unused on Android)
|
||||
//---------------------------------------------------------
|
||||
InitWindow(screenWidth, screenHeight, "sample game: asteroids survival");
|
||||
|
||||
InitGame();
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||
#else
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update and Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateDrawFrame();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
#endif
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadGame(); // Unload loaded data (textures, sounds, models...)
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Definitions (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
// Initialize game variables
|
||||
void InitGame(void)
|
||||
{
|
||||
int posx, posy;
|
||||
int velx, vely;
|
||||
bool correctRange = false;
|
||||
|
||||
pause = false;
|
||||
|
||||
framesCounter = 0;
|
||||
|
||||
shipHeight = (PLAYER_BASE_SIZE/2)/tanf(20*DEG2RAD);
|
||||
|
||||
// Initialization player
|
||||
player.position = (Vector2){screenWidth/2, screenHeight/2 - shipHeight/2};
|
||||
player.speed = (Vector2){0, 0};
|
||||
player.acceleration = 0;
|
||||
player.rotation = 0;
|
||||
player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12};
|
||||
player.color = LIGHTGRAY;
|
||||
|
||||
for (int i = 0; i < MAX_MEDIUM_METEORS; i++)
|
||||
{
|
||||
posx = GetRandomValue(0, screenWidth);
|
||||
|
||||
while(!correctRange)
|
||||
{
|
||||
if (posx > screenWidth/2 - 150 && posx < screenWidth/2 + 150) posx = GetRandomValue(0, screenWidth);
|
||||
else correctRange = true;
|
||||
}
|
||||
|
||||
correctRange = false;
|
||||
|
||||
posy = GetRandomValue(0, screenHeight);
|
||||
|
||||
while(!correctRange)
|
||||
{
|
||||
if (posy > screenHeight/2 - 150 && posy < screenHeight/2 + 150) posy = GetRandomValue(0, screenHeight);
|
||||
else correctRange = true;
|
||||
}
|
||||
|
||||
correctRange = false;
|
||||
velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
|
||||
while(!correctRange)
|
||||
{
|
||||
if (velx == 0 && vely == 0)
|
||||
{
|
||||
velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
}
|
||||
else correctRange = true;
|
||||
}
|
||||
mediumMeteor[i].position = (Vector2){posx, posy};
|
||||
mediumMeteor[i].speed = (Vector2){velx, vely};
|
||||
mediumMeteor[i].radius = 20;
|
||||
mediumMeteor[i].active = true;
|
||||
mediumMeteor[i].color = GREEN;
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_SMALL_METEORS; i++)
|
||||
{
|
||||
posx = GetRandomValue(0, screenWidth);
|
||||
|
||||
while(!correctRange)
|
||||
{
|
||||
if (posx > screenWidth/2 - 150 && posx < screenWidth/2 + 150) posx = GetRandomValue(0, screenWidth);
|
||||
else correctRange = true;
|
||||
}
|
||||
|
||||
correctRange = false;
|
||||
|
||||
posy = GetRandomValue(0, screenHeight);
|
||||
|
||||
while(!correctRange)
|
||||
{
|
||||
if (posy > screenHeight/2 - 150 && posy < screenHeight/2 + 150) posy = GetRandomValue(0, screenHeight);
|
||||
else correctRange = true;
|
||||
}
|
||||
|
||||
correctRange = false;
|
||||
velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
|
||||
while(!correctRange)
|
||||
{
|
||||
if (velx == 0 && vely == 0)
|
||||
{
|
||||
velx = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
vely = GetRandomValue(-METEORS_SPEED, METEORS_SPEED);
|
||||
}
|
||||
else correctRange = true;
|
||||
}
|
||||
smallMeteor[i].position = (Vector2){posx, posy};
|
||||
smallMeteor[i].speed = (Vector2){velx, vely};
|
||||
smallMeteor[i].radius = 10;
|
||||
smallMeteor[i].active = true;
|
||||
smallMeteor[i].color = YELLOW;
|
||||
}
|
||||
}
|
||||
|
||||
// Update game (one frame)
|
||||
void UpdateGame(void)
|
||||
{
|
||||
if (!gameOver)
|
||||
{
|
||||
if (IsKeyPressed('P')) pause = !pause;
|
||||
|
||||
if (!pause)
|
||||
{
|
||||
framesCounter++;
|
||||
|
||||
// Player logic
|
||||
|
||||
// Rotation
|
||||
if (IsKeyDown(KEY_LEFT)) player.rotation -= 5;
|
||||
if (IsKeyDown(KEY_RIGHT)) player.rotation += 5;
|
||||
|
||||
// Speed
|
||||
player.speed.x = sin(player.rotation*DEG2RAD)*PLAYER_SPEED;
|
||||
player.speed.y = cos(player.rotation*DEG2RAD)*PLAYER_SPEED;
|
||||
|
||||
// Controller
|
||||
if (IsKeyDown(KEY_UP))
|
||||
{
|
||||
if (player.acceleration < 1) player.acceleration += 0.04f;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.acceleration > 0) player.acceleration -= 0.02f;
|
||||
else if (player.acceleration < 0) player.acceleration = 0;
|
||||
}
|
||||
if (IsKeyDown(KEY_DOWN))
|
||||
{
|
||||
if (player.acceleration > 0) player.acceleration -= 0.04f;
|
||||
else if (player.acceleration < 0) player.acceleration = 0;
|
||||
}
|
||||
|
||||
// Movement
|
||||
player.position.x += (player.speed.x*player.acceleration);
|
||||
player.position.y -= (player.speed.y*player.acceleration);
|
||||
|
||||
// Wall behaviour for player
|
||||
if (player.position.x > screenWidth + shipHeight) player.position.x = -(shipHeight);
|
||||
else if (player.position.x < -(shipHeight)) player.position.x = screenWidth + shipHeight;
|
||||
if (player.position.y > (screenHeight + shipHeight)) player.position.y = -(shipHeight);
|
||||
else if (player.position.y < -(shipHeight)) player.position.y = screenHeight + shipHeight;
|
||||
|
||||
// Collision Player to meteors
|
||||
player.collider = (Vector3){player.position.x + sin(player.rotation*DEG2RAD)*(shipHeight/2.5f), player.position.y - cos(player.rotation*DEG2RAD)*(shipHeight/2.5f), 12};
|
||||
|
||||
for (int a = 0; a < MAX_MEDIUM_METEORS; a++)
|
||||
{
|
||||
if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, mediumMeteor[a].position, mediumMeteor[a].radius) && mediumMeteor[a].active) gameOver = true;
|
||||
}
|
||||
|
||||
for (int a = 0; a < MAX_SMALL_METEORS; a++)
|
||||
{
|
||||
if (CheckCollisionCircles((Vector2){player.collider.x, player.collider.y}, player.collider.z, smallMeteor[a].position, smallMeteor[a].radius) && smallMeteor[a].active) gameOver = true;
|
||||
}
|
||||
|
||||
// Meteor logic
|
||||
|
||||
for (int i = 0; i < MAX_MEDIUM_METEORS; i++)
|
||||
{
|
||||
if (mediumMeteor[i].active)
|
||||
{
|
||||
// movement
|
||||
mediumMeteor[i].position.x += mediumMeteor[i].speed.x;
|
||||
mediumMeteor[i].position.y += mediumMeteor[i].speed.y;
|
||||
|
||||
// wall behaviour
|
||||
if (mediumMeteor[i].position.x > screenWidth + mediumMeteor[i].radius) mediumMeteor[i].position.x = -(mediumMeteor[i].radius);
|
||||
else if (mediumMeteor[i].position.x < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.x = screenWidth + mediumMeteor[i].radius;
|
||||
if (mediumMeteor[i].position.y > screenHeight + mediumMeteor[i].radius) mediumMeteor[i].position.y = -(mediumMeteor[i].radius);
|
||||
else if (mediumMeteor[i].position.y < 0 - mediumMeteor[i].radius) mediumMeteor[i].position.y = screenHeight + mediumMeteor[i].radius;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_SMALL_METEORS; i++)
|
||||
{
|
||||
if (smallMeteor[i].active)
|
||||
{
|
||||
// movement
|
||||
smallMeteor[i].position.x += smallMeteor[i].speed.x;
|
||||
smallMeteor[i].position.y += smallMeteor[i].speed.y;
|
||||
|
||||
// wall behaviour
|
||||
if (smallMeteor[i].position.x > screenWidth + smallMeteor[i].radius) smallMeteor[i].position.x = -(smallMeteor[i].radius);
|
||||
else if (smallMeteor[i].position.x < 0 - smallMeteor[i].radius) smallMeteor[i].position.x = screenWidth + smallMeteor[i].radius;
|
||||
if (smallMeteor[i].position.y > screenHeight + smallMeteor[i].radius) smallMeteor[i].position.y = -(smallMeteor[i].radius);
|
||||
else if (smallMeteor[i].position.y < 0 - smallMeteor[i].radius) smallMeteor[i].position.y = screenHeight + smallMeteor[i].radius;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
InitGame();
|
||||
gameOver = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw game (one frame)
|
||||
void DrawGame(void)
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
if (!gameOver)
|
||||
{
|
||||
// Draw spaceship
|
||||
Vector2 v1 = { player.position.x + sinf(player.rotation*DEG2RAD)*(shipHeight), player.position.y - cosf(player.rotation*DEG2RAD)*(shipHeight) };
|
||||
Vector2 v2 = { player.position.x - cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y - sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) };
|
||||
Vector2 v3 = { player.position.x + cosf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2), player.position.y + sinf(player.rotation*DEG2RAD)*(PLAYER_BASE_SIZE/2) };
|
||||
DrawTriangle(v1, v2, v3, MAROON);
|
||||
|
||||
// Draw meteor
|
||||
for (int i = 0;i < MAX_MEDIUM_METEORS; i++)
|
||||
{
|
||||
if (mediumMeteor[i].active) DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, GRAY);
|
||||
else DrawCircleV(mediumMeteor[i].position, mediumMeteor[i].radius, Fade(LIGHTGRAY, 0.3f));
|
||||
}
|
||||
|
||||
for (int i = 0;i < MAX_SMALL_METEORS; i++)
|
||||
{
|
||||
if (smallMeteor[i].active) DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, DARKGRAY);
|
||||
else DrawCircleV(smallMeteor[i].position, smallMeteor[i].radius, Fade(LIGHTGRAY, 0.3f));
|
||||
}
|
||||
|
||||
DrawText(TextFormat("TIME: %.02f", (float)framesCounter/60), 10, 10, 20, BLACK);
|
||||
|
||||
if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
|
||||
}
|
||||
else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// Unload game variables
|
||||
void UnloadGame(void)
|
||||
{
|
||||
// TODO: Unload all dynamic loaded data (textures, sounds, models...)
|
||||
}
|
||||
|
||||
// Update and Draw (one frame)
|
||||
void UpdateDrawFrame(void)
|
||||
{
|
||||
UpdateGame();
|
||||
DrawGame();
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
This game sources are licensed under an unmodified zlib/libpng license,
|
||||
which is an OSI-certified, BSD-like license:
|
||||
|
||||
Copyright (c) 2013-2019 Ramon Santamaria (@raysan5)
|
||||
|
||||
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.
|
||||
|
|
@ -1,406 +0,0 @@
|
|||
#**************************************************************************************************
|
||||
#
|
||||
# raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5
|
||||
#
|
||||
# Copyright (c) 2013-2020 Ramon Santamaria (@raysan5)
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#**************************************************************************************************
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
# Define required raylib variables
|
||||
PROJECT_NAME ?= roomba
|
||||
RAYLIB_VERSION ?= 3.0.0
|
||||
RAYLIB_API_VERSION ?= 3
|
||||
RAYLIB_PATH ?= C:\GitHub\raylib
|
||||
|
||||
# Define default options
|
||||
|
||||
# One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
PLATFORM ?= PLATFORM_DESKTOP
|
||||
|
||||
# Locations of your newly installed library and associated headers. See ../src/Makefile
|
||||
# On Linux, if you have installed raylib but cannot compile the examples, check that
|
||||
# the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations.
|
||||
# To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED.
|
||||
# To enable compile-time linking to a special version of libraylib.so, change these variables here.
|
||||
# To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below.
|
||||
# If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime,
|
||||
# the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH.
|
||||
# RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths.
|
||||
DESTDIR ?= /usr/local
|
||||
RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib
|
||||
# RAYLIB_H_INSTALL_PATH locates the installed raylib header and associated source files.
|
||||
RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include
|
||||
|
||||
# Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
|
||||
RAYLIB_LIBTYPE ?= STATIC
|
||||
|
||||
# Build mode for project: DEBUG or RELEASE
|
||||
BUILD_MODE ?= RELEASE
|
||||
|
||||
# Use external GLFW library instead of rglfw module
|
||||
# TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3
|
||||
USE_EXTERNAL_GLFW ?= FALSE
|
||||
|
||||
# Use Wayland display server protocol on Linux desktop
|
||||
# by default it uses X11 windowing system
|
||||
USE_WAYLAND_DISPLAY ?= FALSE
|
||||
|
||||
# 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
|
||||
else
|
||||
UNAMEOS=$(shell uname)
|
||||
ifeq ($(UNAMEOS),Linux)
|
||||
PLATFORM_OS=LINUX
|
||||
endif
|
||||
ifeq ($(UNAMEOS),FreeBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),OpenBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),NetBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),DragonFly)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),Darwin)
|
||||
PLATFORM_OS=OSX
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
UNAMEOS=$(shell uname)
|
||||
ifeq ($(UNAMEOS),Linux)
|
||||
PLATFORM_OS=LINUX
|
||||
endif
|
||||
endif
|
||||
|
||||
# RAYLIB_PATH adjustment for different platforms.
|
||||
# If using GNU make, we can get the full path to the top of the tree. Windows? BSD?
|
||||
# Required for ldconfig or other tools that do not perform path expansion.
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
RAYLIB_PREFIX ?= ..
|
||||
RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX))
|
||||
endif
|
||||
endif
|
||||
# Default path for raylib on Raspberry Pi, if installed in different path, update it!
|
||||
# This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki.
|
||||
# TODO: update install: target in src/Makefile for RPI, consider relation to LINUX.
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
RAYLIB_PATH ?= /home/pi/raylib
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# Emscripten required variables
|
||||
EMSDK_PATH ?= C:/emsdk
|
||||
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/fastcomp/emscripten
|
||||
CLANG_PATH = $(EMSDK_PATH)/fastcomp/bin
|
||||
PYTHON_PATH = $(EMSDK_PATH)/python/2.7.13.1_64bit/python-2.7.13.amd64
|
||||
NODE_PATH = $(EMSDK_PATH)/node/12.9.1_64bit/bin
|
||||
export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH);C:\raylib\MinGW\bin:$$(PATH)
|
||||
endif
|
||||
|
||||
# Define raylib release directory for compiled library.
|
||||
# RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version
|
||||
RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src
|
||||
|
||||
# EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries
|
||||
# into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH
|
||||
# so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux
|
||||
# without formal installation from ../src/Makefile. It aids portability and is useful if you have
|
||||
# multiple versions of raylib, have raylib installed to a non-standard location, or want to
|
||||
# bundle libraylib.so with your game. Change it to your liking.
|
||||
# NOTE: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH,
|
||||
# The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH,
|
||||
# Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
|
||||
# To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute.
|
||||
# To see which libraries a built example is linking to, ldd core/core_basic_window;
|
||||
# Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing.
|
||||
EXAMPLE_RUNTIME_PATH ?= $(RAYLIB_RELEASE_PATH)
|
||||
|
||||
# Define default C compiler: gcc
|
||||
# NOTE: define g++ compiler if using C++
|
||||
CC = gcc
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
# OSX default compiler
|
||||
CC = clang
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# FreeBSD, OpenBSD, NetBSD, DragonFly default compiler
|
||||
CC = clang
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
ifeq ($(USE_RPI_CROSS_COMPILER),TRUE)
|
||||
# Define RPI cross-compiler
|
||||
#CC = armv6j-hardfloat-linux-gnueabi-gcc
|
||||
CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# HTML5 emscripten compiler
|
||||
# WARNING: To compile to HTML5, code must be redesigned
|
||||
# to use emscripten.h and emscripten_set_main_loop()
|
||||
CC = emcc
|
||||
endif
|
||||
|
||||
# Define default make program: Mingw32-make
|
||||
MAKE = mingw32-make
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
MAKE = make
|
||||
endif
|
||||
endif
|
||||
|
||||
# Define compiler flags:
|
||||
# -O1 defines optimization level
|
||||
# -g include debug information on compilation
|
||||
# -s strip unnecessary data from build
|
||||
# -Wall turns on most, but not all, compiler warnings
|
||||
# -std=c99 defines C language mode (standard C from 1999 revision)
|
||||
# -std=gnu99 defines C language mode (GNU C from 1999 revision)
|
||||
# -Wno-missing-braces ignore invalid warning (GCC bug 53119)
|
||||
# -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
|
||||
CFLAGS += -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces
|
||||
|
||||
ifeq ($(BUILD_MODE),DEBUG)
|
||||
CFLAGS += -g
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
CFLAGS += -s ASSERTIONS=1 --profiling
|
||||
endif
|
||||
else
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
CFLAGS += -Os
|
||||
else
|
||||
CFLAGS += -s -O1
|
||||
endif
|
||||
endif
|
||||
|
||||
# Additional flags for compiler (if desired)
|
||||
#CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
ifeq ($(RAYLIB_LIBTYPE),STATIC)
|
||||
CFLAGS += -D_DEFAULT_SOURCE
|
||||
endif
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
# Explicitly enable runtime link to libraylib.so
|
||||
CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
CFLAGS += -std=gnu99
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# -Os # size optimization
|
||||
# -O2 # optimization level 2, if used, also set --memory-init-file 0
|
||||
# -s USE_GLFW=3 # Use glfw3 library (context/input management)
|
||||
# -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing -> WARNING: Audio buffers could FAIL!
|
||||
# -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
|
||||
# -s USE_PTHREADS=1 # multithreading support
|
||||
# -s WASM=0 # disable Web Assembly, emitted by default
|
||||
# -s EMTERPRETIFY=1 # enable emscripten code interpreter (very slow)
|
||||
# -s EMTERPRETIFY_ASYNC=1 # support synchronous loops by emterpreter
|
||||
# -s FORCE_FILESYSTEM=1 # force filesystem to load/save files data
|
||||
# -s ASSERTIONS=1 # enable runtime checks for common memory allocation errors (-O1 and above turn it off)
|
||||
# --profiling # include information for code profiling
|
||||
# --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
|
||||
# --preload-file resources # specify a resources folder for data compilation
|
||||
CFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=16777216 --preload-file resources
|
||||
|
||||
# Define a custom shell .html and output extension
|
||||
CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
|
||||
EXT = .html
|
||||
endif
|
||||
|
||||
# Define include paths for required headers
|
||||
# NOTE: Several external required libraries (stb and others)
|
||||
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
|
||||
|
||||
# Define additional directories containing required header files
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
# RPI required libraries
|
||||
INCLUDE_PATHS += -I/opt/vc/include
|
||||
INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux
|
||||
INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Consider -L$(RAYLIB_H_INSTALL_PATH)
|
||||
INCLUDE_PATHS += -I/usr/local/include
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Reset everything.
|
||||
# Precedence: immediately local, installed version, raysan5 provided libs -I$(RAYLIB_H_INSTALL_PATH) -I$(RAYLIB_PATH)/release/include
|
||||
INCLUDE_PATHS = -I$(RAYLIB_H_INSTALL_PATH) -isystem. -isystem$(RAYLIB_PATH)/src -isystem$(RAYLIB_PATH)/release/include -isystem$(RAYLIB_PATH)/src/external
|
||||
endif
|
||||
endif
|
||||
|
||||
# Define library paths containing required libs.
|
||||
LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
# resource file contains windows executable icon and properties
|
||||
LDFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data
|
||||
# -Wl,--subsystem,windows hides the console window
|
||||
ifeq ($(BUILD_MODE), RELEASE)
|
||||
LDFLAGS += -Wl,--subsystem,windows
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Consider -L$(RAYLIB_INSTALL_PATH)
|
||||
LDFLAGS += -L. -Lsrc -L/usr/local/lib
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Reset everything.
|
||||
# Precedence: immediately local, installed version, raysan5 provided libs
|
||||
LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
LDFLAGS += -L/opt/vc/lib
|
||||
endif
|
||||
|
||||
# Define any libraries required on linking
|
||||
# if you want to link libraries (libname.so or libname.a), use the -lname
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
# Libraries for Windows desktop compilation
|
||||
# NOTE: WinMM library required to set high-res timer resolution
|
||||
LDLIBS = -lraylib -lopengl32 -lgdi32 -lwinmm
|
||||
# Required for physac examples
|
||||
LDLIBS += -static -lpthread
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Libraries for Debian GNU/Linux desktop compiling
|
||||
# NOTE: Required packages: libegl1-mesa-dev
|
||||
LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
|
||||
|
||||
# On X11 requires also below libraries
|
||||
LDLIBS += -lX11
|
||||
# NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
|
||||
#LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||
|
||||
# On Wayland windowing system, additional libraries requires
|
||||
ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
|
||||
LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
|
||||
endif
|
||||
# Explicit link to libc
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
LDLIBS += -lc
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
# Libraries for OSX 10.9 desktop compiling
|
||||
# NOTE: Required packages: libopenal-dev libegl1-mesa-dev
|
||||
LDLIBS = -lraylib -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling
|
||||
# NOTE: Required packages: mesa-libs
|
||||
LDLIBS = -lraylib -lGL -lpthread -lm
|
||||
|
||||
# On XWindow requires also below libraries
|
||||
LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||
endif
|
||||
ifeq ($(USE_EXTERNAL_GLFW),TRUE)
|
||||
# NOTE: It could require additional packages installed: libglfw3-dev
|
||||
LDLIBS += -lglfw
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
# Libraries for Raspberry Pi compiling
|
||||
# NOTE: Required packages: libasound2-dev (ALSA)
|
||||
LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# Libraries for web (HTML5) compiling
|
||||
LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc
|
||||
endif
|
||||
|
||||
# Define all source files required
|
||||
PROJECT_SOURCE_FILES ?= \
|
||||
roomba.c \
|
||||
screens/screen_logo.c \
|
||||
screens/screen_title.c \
|
||||
screens/screen_gameplay.c \
|
||||
screens/screen_ending.c
|
||||
|
||||
# Define all object files from source files
|
||||
OBJS = $(patsubst %.c, %.o, $(PROJECT_SOURCE_FILES))
|
||||
|
||||
# For Android platform we call a custom Makefile.Android
|
||||
ifeq ($(PLATFORM),PLATFORM_ANDROID)
|
||||
MAKEFILE_PARAMS = -f Makefile.Android
|
||||
export PROJECT_NAME
|
||||
export PROJECT_SOURCE_FILES
|
||||
else
|
||||
MAKEFILE_PARAMS = $(PROJECT_NAME)
|
||||
endif
|
||||
|
||||
# Default target entry
|
||||
# NOTE: We call this Makefile target or Makefile.Android target
|
||||
all:
|
||||
$(MAKE) $(MAKEFILE_PARAMS)
|
||||
|
||||
# Project target defined by PROJECT_NAME
|
||||
$(PROJECT_NAME): $(OBJS)
|
||||
$(CC) -o $(PROJECT_NAME)$(EXT) $(OBJS) $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||
|
||||
# Compile source files
|
||||
# NOTE: This pattern will compile every module defined on $(OBJS)
|
||||
%.o: %.c
|
||||
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
|
||||
|
||||
# Clean everything
|
||||
clean:
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
del *.o *.exe /s
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable|x-pie-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -fv
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
find . -type f -perm +ugo+x -delete
|
||||
rm -f *.o
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
find . -type f -executable -delete
|
||||
rm -fv *.o
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
del *.o *.html *.js
|
||||
endif
|
||||
@echo Cleaning done
|
||||
|
||||
|
|
@ -1,300 +0,0 @@
|
|||
#**************************************************************************************************
|
||||
#
|
||||
# raylib makefile for Android project (APK building)
|
||||
#
|
||||
# Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
#
|
||||
# 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 required raylib variables
|
||||
PLATFORM ?= PLATFORM_ANDROID
|
||||
RAYLIB_PATH ?= ..\..
|
||||
|
||||
# Define Android architecture (armeabi-v7a, arm64-v8a, x86, x86-64) and API version
|
||||
ANDROID_ARCH ?= ARM
|
||||
ANDROID_API_VERSION = 21
|
||||
ifeq ($(ANDROID_ARCH),ARM)
|
||||
ANDROID_ARCH_NAME = armeabi-v7a
|
||||
endif
|
||||
ifeq ($(ANDROID_ARCH),ARM64)
|
||||
ANDROID_ARCH_NAME = arm64-v8a
|
||||
endif
|
||||
|
||||
# Required path variables
|
||||
# NOTE: JAVA_HOME must be set to JDK
|
||||
JAVA_HOME ?= C:/JavaJDK
|
||||
ANDROID_HOME = C:/android-sdk
|
||||
ANDROID_TOOLCHAIN = C:/android_toolchain_$(ANDROID_ARCH)_API$(ANDROID_API_VERSION)
|
||||
ANDROID_BUILD_TOOLS = $(ANDROID_HOME)/build-tools/28.0.1
|
||||
ANDROID_PLATFORM_TOOLS = $(ANDROID_HOME)/platform-tools
|
||||
|
||||
# Android project configuration variables
|
||||
PROJECT_NAME ?= raylib_game
|
||||
PROJECT_LIBRARY_NAME ?= main
|
||||
PROJECT_BUILD_PATH ?= android.$(PROJECT_NAME)
|
||||
PROJECT_RESOURCES_PATH ?= resources
|
||||
PROJECT_SOURCE_FILES ?= raylib_game.c
|
||||
|
||||
# Some source files are placed in directories, when compiling to some
|
||||
# output directory other than source, that directory must pre-exist.
|
||||
# Here we get a list of required folders that need to be created on
|
||||
# code output folder $(PROJECT_BUILD_PATH)\obj to avoid GCC errors.
|
||||
PROJECT_SOURCE_DIRS = $(sort $(dir $(PROJECT_SOURCE_FILES)))
|
||||
|
||||
# Android app configuration variables
|
||||
APP_LABEL_NAME ?= rGame
|
||||
APP_COMPANY_NAME ?= raylib
|
||||
APP_PRODUCT_NAME ?= rgame
|
||||
APP_VERSION_CODE ?= 1
|
||||
APP_VERSION_NAME ?= 1.0
|
||||
APP_ICON_LDPI ?= $(RAYLIB_PATH)\logo\raylib_36x36.png
|
||||
APP_ICON_MDPI ?= $(RAYLIB_PATH)\logo\raylib_48x48.png
|
||||
APP_ICON_HDPI ?= $(RAYLIB_PATH)\logo\raylib_72x72.png
|
||||
APP_SCREEN_ORIENTATION ?= landscape
|
||||
APP_KEYSTORE_PASS ?= raylib
|
||||
|
||||
# Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
|
||||
RAYLIB_LIBTYPE ?= STATIC
|
||||
|
||||
# Library path for libraylib.a/libraylib.so
|
||||
RAYLIB_LIB_PATH = $(RAYLIB_PATH)\src
|
||||
|
||||
# Shared libs must be added to APK if required
|
||||
# NOTE: Generated NativeLoader.java automatically load those libraries
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
PROJECT_SHARED_LIBS = lib/$(ANDROID_ARCH_NAME)/libraylib.so
|
||||
endif
|
||||
|
||||
# Compiler and archiver
|
||||
# NOTE: GCC is being deprecated in Android NDK r16
|
||||
ifeq ($(ANDROID_ARCH),ARM)
|
||||
CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-clang
|
||||
AR = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-ar
|
||||
endif
|
||||
ifeq ($(ANDROID_ARCH),ARM64)
|
||||
CC = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-clang
|
||||
AR = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-ar
|
||||
endif
|
||||
|
||||
# Compiler flags for arquitecture
|
||||
ifeq ($(ANDROID_ARCH),ARM)
|
||||
CFLAGS = -std=c99 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
|
||||
endif
|
||||
ifeq ($(ANDROID_ARCH),ARM64)
|
||||
CFLAGS = -std=c99 -target aarch64 -mfix-cortex-a53-835769
|
||||
endif
|
||||
# Compilation functions attributes options
|
||||
CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC
|
||||
# Compiler options for the linker
|
||||
CFLAGS += -Wall -Wa,--noexecstack -Wformat -Werror=format-security -no-canonical-prefixes
|
||||
# Preprocessor macro definitions
|
||||
CFLAGS += -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=$(ANDROID_API_VERSION)
|
||||
|
||||
# Paths containing required header files
|
||||
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external/android/native_app_glue
|
||||
|
||||
# Linker options
|
||||
LDFLAGS = -Wl,-soname,lib$(PROJECT_LIBRARY_NAME).so -Wl,--exclude-libs,libatomic.a
|
||||
LDFLAGS += -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings
|
||||
# Force linking of library module to define symbol
|
||||
LDFLAGS += -u ANativeActivity_onCreate
|
||||
# Library paths containing required libs
|
||||
LDFLAGS += -L. -L$(PROJECT_BUILD_PATH)/obj -L$(PROJECT_BUILD_PATH)/lib/$(ANDROID_ARCH_NAME) -L$(ANDROID_TOOLCHAIN)\sysroot\usr\lib
|
||||
|
||||
# Define any libraries to link into executable
|
||||
# if you want to link libraries (libname.so or libname.a), use the -lname
|
||||
LDLIBS = -lm -lc -lraylib -llog -landroid -lEGL -lGLESv2 -lOpenSLES -ldl
|
||||
|
||||
# Generate target objects list from PROJECT_SOURCE_FILES
|
||||
OBJS = $(patsubst %.c, $(PROJECT_BUILD_PATH)/obj/%.o, $(PROJECT_SOURCE_FILES))
|
||||
|
||||
# Android APK building process... some steps required...
|
||||
# NOTE: typing 'make' will invoke the default target entry called 'all',
|
||||
all: create_temp_project_dirs \
|
||||
copy_project_required_libs \
|
||||
copy_project_resources \
|
||||
generate_loader_script \
|
||||
generate_android_manifest \
|
||||
generate_apk_keystore \
|
||||
config_project_package \
|
||||
compile_project_code \
|
||||
compile_project_class \
|
||||
compile_project_class_dex \
|
||||
create_project_apk_package \
|
||||
sign_project_apk_package \
|
||||
zipalign_project_apk_package
|
||||
|
||||
# Create required temp directories for APK building
|
||||
create_temp_project_dirs:
|
||||
if not exist $(PROJECT_BUILD_PATH) mkdir $(PROJECT_BUILD_PATH)
|
||||
if not exist $(PROJECT_BUILD_PATH)\obj mkdir $(PROJECT_BUILD_PATH)\obj
|
||||
if not exist $(PROJECT_BUILD_PATH)\src mkdir $(PROJECT_BUILD_PATH)\src
|
||||
if not exist $(PROJECT_BUILD_PATH)\src\com mkdir $(PROJECT_BUILD_PATH)\src\com
|
||||
if not exist $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME) mkdir $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME)
|
||||
if not exist $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME)\$(APP_PRODUCT_NAME) mkdir $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME)\$(APP_PRODUCT_NAME)
|
||||
if not exist $(PROJECT_BUILD_PATH)\lib mkdir $(PROJECT_BUILD_PATH)\lib
|
||||
if not exist $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME) mkdir $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME)
|
||||
if not exist $(PROJECT_BUILD_PATH)\bin mkdir $(PROJECT_BUILD_PATH)\bin
|
||||
if not exist $(PROJECT_BUILD_PATH)\res mkdir $(PROJECT_BUILD_PATH)\res
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\drawable-ldpi mkdir $(PROJECT_BUILD_PATH)\res\drawable-ldpi
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\drawable-mdpi mkdir $(PROJECT_BUILD_PATH)\res\drawable-mdpi
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\drawable-hdpi mkdir $(PROJECT_BUILD_PATH)\res\drawable-hdpi
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\values mkdir $(PROJECT_BUILD_PATH)\res\values
|
||||
if not exist $(PROJECT_BUILD_PATH)\assets mkdir $(PROJECT_BUILD_PATH)\assets
|
||||
if not exist $(PROJECT_BUILD_PATH)\assets\$(PROJECT_RESOURCES_PATH) mkdir $(PROJECT_BUILD_PATH)\assets\$(PROJECT_RESOURCES_PATH)
|
||||
if not exist $(PROJECT_BUILD_PATH)\obj\screens mkdir $(PROJECT_BUILD_PATH)\obj\screens
|
||||
$(foreach dir, $(PROJECT_SOURCE_DIRS), $(call create_dir, $(dir)))
|
||||
|
||||
define create_dir
|
||||
if not exist $(PROJECT_BUILD_PATH)\obj\$(1) mkdir $(PROJECT_BUILD_PATH)\obj\$(1)
|
||||
endef
|
||||
|
||||
# Copy required shared libs for integration into APK
|
||||
# NOTE: If using shared libs they are loaded by generated NativeLoader.java
|
||||
copy_project_required_libs:
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
copy /Y $(RAYLIB_LIB_PATH)\libraylib.so $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME)\libraylib.so
|
||||
endif
|
||||
ifeq ($(RAYLIB_LIBTYPE),STATIC)
|
||||
copy /Y $(RAYLIB_LIB_PATH)\libraylib.a $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME)\libraylib.a
|
||||
endif
|
||||
|
||||
# Copy project required resources: strings.xml, icon.png, assets
|
||||
# NOTE: Required strings.xml is generated and game resources are copied to assets folder
|
||||
# TODO: Review xcopy usage, it can not be found in some systems!
|
||||
copy_project_resources:
|
||||
copy $(APP_ICON_LDPI) $(PROJECT_BUILD_PATH)\res\drawable-ldpi\icon.png /Y
|
||||
copy $(APP_ICON_MDPI) $(PROJECT_BUILD_PATH)\res\drawable-mdpi\icon.png /Y
|
||||
copy $(APP_ICON_HDPI) $(PROJECT_BUILD_PATH)\res\drawable-hdpi\icon.png /Y
|
||||
@echo ^<?xml version="1.0" encoding="utf-8"^?^> > $(PROJECT_BUILD_PATH)/res/values/strings.xml
|
||||
@echo ^<resources^>^<string name="app_name"^>$(APP_LABEL_NAME)^</string^>^</resources^> >> $(PROJECT_BUILD_PATH)/res/values/strings.xml
|
||||
if exist $(PROJECT_RESOURCES_PATH) C:\Windows\System32\xcopy $(PROJECT_RESOURCES_PATH) $(PROJECT_BUILD_PATH)\assets\$(PROJECT_RESOURCES_PATH) /Y /E /F
|
||||
|
||||
# Generate NativeLoader.java to load required shared libraries
|
||||
# NOTE: Probably not the bet way to generate this file... but it works.
|
||||
generate_loader_script:
|
||||
@echo package com.$(APP_COMPANY_NAME).$(APP_PRODUCT_NAME); > $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo. >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo public class NativeLoader extends android.app.NativeActivity { >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo static { >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
@echo System.loadLibrary("raylib"); >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
endif
|
||||
@echo System.loadLibrary("$(PROJECT_LIBRARY_NAME)"); >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo } >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo } >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
|
||||
# Generate AndroidManifest.xml with all the required options
|
||||
# NOTE: Probably not the bet way to generate this file... but it works.
|
||||
generate_android_manifest:
|
||||
@echo ^<?xml version="1.0" encoding="utf-8"^?^> > $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<manifest xmlns:android="http://schemas.android.com/apk/res/android" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo package="com.$(APP_COMPANY_NAME).$(APP_PRODUCT_NAME)" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:versionCode="$(APP_VERSION_CODE)" android:versionName="$(APP_VERSION_NAME)" ^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<uses-sdk android:minSdkVersion="$(ANDROID_API_VERSION)" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<uses-feature android:glEsVersion="0x00020000" android:required="true" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<application android:allowBackup="false" android:label="@string/app_name" android:icon="@drawable/icon" ^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<activity android:name="com.$(APP_COMPANY_NAME).$(APP_PRODUCT_NAME).NativeLoader" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:configChanges="orientation|keyboardHidden|screenSize" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:screenOrientation="$(APP_SCREEN_ORIENTATION)" android:launchMode="singleTask" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:clearTaskOnLaunch="true"^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<meta-data android:name="android.app.lib_name" android:value="$(PROJECT_LIBRARY_NAME)" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<intent-filter^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<action android:name="android.intent.action.MAIN" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<category android:name="android.intent.category.LAUNCHER" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</intent-filter^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</activity^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</application^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</manifest^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
|
||||
# Generate storekey for APK signing: $(PROJECT_NAME).keystore
|
||||
# NOTE: Configure here your Distinguished Names (-dname) if required!
|
||||
generate_apk_keystore:
|
||||
if not exist $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore $(JAVA_HOME)/bin/keytool -genkeypair -validity 1000 -dname "CN=$(APP_COMPANY_NAME),O=Android,C=ES" -keystore $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore -storepass $(APP_KEYSTORE_PASS) -keypass $(APP_KEYSTORE_PASS) -alias $(PROJECT_NAME)Key -keyalg RSA
|
||||
|
||||
# Config project package and resource using AndroidManifest.xml and res/values/strings.xml
|
||||
# NOTE: Generates resources file: src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/R.java
|
||||
config_project_package:
|
||||
$(ANDROID_BUILD_TOOLS)/aapt package -f -m -S $(PROJECT_BUILD_PATH)/res -J $(PROJECT_BUILD_PATH)/src -M $(PROJECT_BUILD_PATH)/AndroidManifest.xml -I $(ANDROID_HOME)/platforms/android-$(ANDROID_API_VERSION)/android.jar
|
||||
|
||||
# Compile native_app_glue code as static library: obj/libnative_app_glue.a
|
||||
compile_native_app_glue:
|
||||
$(CC) -c $(RAYLIB_PATH)/src/external/android/native_app_glue/android_native_app_glue.c -o $(PROJECT_BUILD_PATH)/obj/native_app_glue.o $(CFLAGS)
|
||||
$(AR) rcs $(PROJECT_BUILD_PATH)/obj/libnative_app_glue.a $(PROJECT_BUILD_PATH)/obj/native_app_glue.o
|
||||
|
||||
# Compile project code into a shared library: lib/lib$(PROJECT_LIBRARY_NAME).so
|
||||
compile_project_code: $(OBJS)
|
||||
$(CC) -o $(PROJECT_BUILD_PATH)/lib/$(ANDROID_ARCH_NAME)/lib$(PROJECT_LIBRARY_NAME).so $(OBJS) -shared $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
# Compile all .c files required into object (.o) files
|
||||
# NOTE: Those files will be linked into a shared library
|
||||
$(PROJECT_BUILD_PATH)/obj/%.o:%.c
|
||||
$(CC) -c $^ -o $@ $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot
|
||||
|
||||
# Compile project .java code into .class (Java bytecode)
|
||||
compile_project_class:
|
||||
$(JAVA_HOME)/bin/javac -verbose -source 1.7 -target 1.7 -d $(PROJECT_BUILD_PATH)/obj -bootclasspath $(JAVA_HOME)/jre/lib/rt.jar -classpath $(ANDROID_HOME)/platforms/android-$(ANDROID_API_VERSION)/android.jar;$(PROJECT_BUILD_PATH)/obj -sourcepath $(PROJECT_BUILD_PATH)/src $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/R.java $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
|
||||
# Compile .class files into Dalvik executable bytecode (.dex)
|
||||
# NOTE: Since Android 5.0, Dalvik interpreter (JIT) has been replaced by ART (AOT)
|
||||
compile_project_class_dex:
|
||||
$(ANDROID_BUILD_TOOLS)/dx --verbose --dex --output=$(PROJECT_BUILD_PATH)/bin/classes.dex $(PROJECT_BUILD_PATH)/obj
|
||||
|
||||
# Create Android APK package: bin/$(PROJECT_NAME).unsigned.apk
|
||||
# NOTE: Requires compiled classes.dex and lib$(PROJECT_LIBRARY_NAME).so
|
||||
# NOTE: Use -A resources to define additional directory in which to find raw asset files
|
||||
create_project_apk_package:
|
||||
$(ANDROID_BUILD_TOOLS)/aapt package -f -M $(PROJECT_BUILD_PATH)/AndroidManifest.xml -S $(PROJECT_BUILD_PATH)/res -A $(PROJECT_BUILD_PATH)/assets -I $(ANDROID_HOME)/platforms/android-$(ANDROID_API_VERSION)/android.jar -F $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).unsigned.apk $(PROJECT_BUILD_PATH)/bin
|
||||
cd $(PROJECT_BUILD_PATH) && $(ANDROID_BUILD_TOOLS)/aapt add bin/$(PROJECT_NAME).unsigned.apk lib/$(ANDROID_ARCH_NAME)/lib$(PROJECT_LIBRARY_NAME).so $(PROJECT_SHARED_LIBS)
|
||||
|
||||
# Create signed APK package using generated Key: bin/$(PROJECT_NAME).signed.apk
|
||||
sign_project_apk_package:
|
||||
$(JAVA_HOME)/bin/jarsigner -keystore $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore -storepass $(APP_KEYSTORE_PASS) -keypass $(APP_KEYSTORE_PASS) -signedjar $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).signed.apk $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).unsigned.apk $(PROJECT_NAME)Key
|
||||
|
||||
# Create zip-aligned APK package: $(PROJECT_NAME).apk
|
||||
zipalign_project_apk_package:
|
||||
$(ANDROID_BUILD_TOOLS)/zipalign -f 4 $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).signed.apk $(PROJECT_NAME).apk
|
||||
|
||||
# Install $(PROJECT_NAME).apk to default emulator/device
|
||||
# NOTE: Use -e (emulator) or -d (device) parameters if required
|
||||
install:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb install --abi $(ANDROID_ARCH_NAME) -rds $(PROJECT_NAME).apk
|
||||
|
||||
# Check supported ABI for the device (armeabi-v7a, arm64-v8a, x86, x86_64)
|
||||
check_device_abi:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb shell getprop ro.product.cpu.abi
|
||||
|
||||
# Monitorize output log coming from device, only raylib tag
|
||||
logcat:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat -c
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat raylib:V *:S
|
||||
|
||||
# Install and monitorize $(PROJECT_NAME).apk to default emulator/device
|
||||
deploy:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb install -r $(PROJECT_NAME).apk
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat -c
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat raylib:V *:S
|
||||
|
||||
#$(ANDROID_PLATFORM_TOOLS)/adb logcat *:W
|
||||
|
||||
# Clean everything
|
||||
clean:
|
||||
del $(PROJECT_BUILD_PATH)\* /f /s /q
|
||||
rmdir $(PROJECT_BUILD_PATH) /s /q
|
||||
@echo Cleaning done
|
||||
|
Before Width: | Height: | Size: 2.2 KiB |
|
|
@ -1,16 +0,0 @@
|
|||
1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,0,0,1,1,1,1,1,1,1,1,
|
||||
1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,1,0,0,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
0,0,1,1,1,1,2,2,2,1,1,1,0,0,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
0,0,1,1,1,1,2,2,2,1,1,1,0,0,1,1,1,2,2,2,1,1,1,1,0,0,1,1,1,1,0,0,
|
||||
0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,0,0,1,1,1,1,0,0,
|
||||
0,0,1,1,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,2,1,1,1,0,0,0,0,0,0,0,0,
|
||||
1,1,1,1,2,2,2,2,2,2,2,2,0,0,1,1,1,2,2,2,1,1,1,1,0,0,0,0,0,0,0,0,
|
||||
1,1,1,1,2,2,2,2,2,2,2,2,0,0,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,1,2,2,2,2,2,2,1,1,
|
||||
0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,2,2,2,2,2,2,1,1,
|
||||
0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,1,1,
|
||||
0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,1,1,
|
||||
0,0,0,0,0,0,0,0,0,0,2,2,2,0,0,0,0,1,1,0,0,1,2,2,2,2,2,2,2,2,0,0
|
||||
|
Before Width: | Height: | Size: 883 B |
|
Before Width: | Height: | Size: 4.8 KiB |
|
|
@ -1,34 +0,0 @@
|
|||
.furniture
|
||||
.state: 0-Block, 1-Alpha, 2-Breakable
|
||||
.f setId cellX cellY state counter
|
||||
.puff and sits
|
||||
f 3 0 4 0 0
|
||||
f 3 13 0 0 0
|
||||
f 3 22 0 0 0
|
||||
f 3 21 11 0 0
|
||||
f 2 19 15 0 0
|
||||
f 2 30 5 0 0
|
||||
f 4 12 4 0 0
|
||||
.wood pieces
|
||||
f 26 3 0 0 0
|
||||
f 27 4 10 0 0
|
||||
f 27 24 7 0 0
|
||||
f 17 30 15 0 0
|
||||
.kitchen
|
||||
f 11 0 15 0 0
|
||||
f 13 0 12 0 0
|
||||
.sofa and bed (alpha)
|
||||
f 14 4 7 1 0
|
||||
f 10 24 11 1 0
|
||||
.glass and tables (alpha)
|
||||
f 9 17 4 1 0
|
||||
f 16 6 4 1 0
|
||||
f 16 10 15 1 0
|
||||
f 15 22 15 1 0
|
||||
.plants (breakable)
|
||||
f 6 0 6 2 1800
|
||||
f 6 12 10 2 1800
|
||||
f 7 17 0 2 1200
|
||||
f 7 15 15 2 1200
|
||||
f 8 13 15 2 2000
|
||||
f 8 24 5 2 2000
|
||||
|
Before Width: | Height: | Size: 96 KiB |
|
|
@ -1,37 +0,0 @@
|
|||
.tileset
|
||||
.first line
|
||||
f 0 0 0 2 2
|
||||
f 1 2 0 2 2
|
||||
f 2 4 0 2 2
|
||||
f 3 6 0 2 2
|
||||
f 4 8 0 2 2
|
||||
f 5 10 0 2 2
|
||||
f 6 12 0 2 2
|
||||
f 7 14 0 2 2
|
||||
f 8 16 0 2 2
|
||||
f 9 18 0 5 6
|
||||
f 10 23 0 6 6
|
||||
.second line
|
||||
f 11 0 2 10 2
|
||||
f 12 10 2 7 3
|
||||
.third line
|
||||
f 13 0 4 2 3
|
||||
f 14 2 4 8 3
|
||||
f 15 10 5 2 2
|
||||
f 16 12 5 3 2
|
||||
f 17 15 5 2 2
|
||||
.cups
|
||||
f 18 17 6 1 1
|
||||
f 19 18 6 1 1
|
||||
f 20 19 6 1 1
|
||||
f 21 20 6 1 1
|
||||
f 22 21 6 1 1
|
||||
f 23 22 6 1 1
|
||||
f 24 23 6 1 1
|
||||
f 25 24 6 1 1
|
||||
.four line
|
||||
f 26 0 7 10 2
|
||||
f 27 10 7 8 2
|
||||
f 28 18 7 3 2
|
||||
f 29 21 7 3 2
|
||||
f 30 24 7 2 2
|
||||
|
Before Width: | Height: | Size: 93 KiB |
|
Before Width: | Height: | Size: 3.9 KiB |
|
|
@ -1,139 +0,0 @@
|
|||
info face="Starcatcher" size=-64 bold=0 italic=0 charset="ANSI" unicode=0 stretchH=100 smooth=1 aa=1 padding=4,4,4,4 spacing=1,1 outline=0
|
||||
common lineHeight=63 base=50 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
|
||||
page id=0 file="star.png"
|
||||
chars count=135
|
||||
char id=32 x=416 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=33 x=347 y=360 width=17 height=71 xoffset=-4 yoffset=-4 xadvance=9 page=0 chnl=15
|
||||
char id=35 x=183 y=0 width=48 height=71 xoffset=-4 yoffset=-4 xadvance=40 page=0 chnl=15
|
||||
char id=36 x=328 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=37 x=67 y=0 width=62 height=71 xoffset=-4 yoffset=-4 xadvance=55 page=0 chnl=15
|
||||
char id=38 x=488 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=39 x=266 y=360 width=21 height=71 xoffset=-4 yoffset=-4 xadvance=13 page=0 chnl=15
|
||||
char id=40 x=471 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=41 x=387 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=42 x=415 y=0 width=42 height=71 xoffset=-4 yoffset=-4 xadvance=34 page=0 chnl=15
|
||||
char id=43 x=403 y=216 width=31 height=71 xoffset=-4 yoffset=-4 xadvance=23 page=0 chnl=15
|
||||
char id=44 x=309 y=360 width=18 height=71 xoffset=-4 yoffset=-4 xadvance=10 page=0 chnl=15
|
||||
char id=45 x=82 y=360 width=26 height=71 xoffset=-4 yoffset=-4 xadvance=18 page=0 chnl=15
|
||||
char id=46 x=365 y=360 width=16 height=71 xoffset=-4 yoffset=-4 xadvance=7 page=0 chnl=15
|
||||
char id=47 x=155 y=288 width=29 height=71 xoffset=-4 yoffset=-4 xadvance=21 page=0 chnl=15
|
||||
char id=48 x=38 y=144 width=36 height=71 xoffset=-4 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=49 x=188 y=360 width=25 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=50 x=339 y=216 width=31 height=71 xoffset=-4 yoffset=-4 xadvance=23 page=0 chnl=15
|
||||
char id=51 x=0 y=288 width=30 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=52 x=35 y=216 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=53 x=105 y=216 width=33 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=54 x=207 y=216 width=32 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=55 x=433 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=56 x=468 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=57 x=0 y=216 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=58 x=399 y=360 width=16 height=71 xoffset=-4 yoffset=-4 xadvance=7 page=0 chnl=15
|
||||
char id=59 x=328 y=360 width=18 height=71 xoffset=-4 yoffset=-4 xadvance=10 page=0 chnl=15
|
||||
char id=60 x=185 y=144 width=35 height=71 xoffset=-4 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=61 x=371 y=216 width=31 height=71 xoffset=-4 yoffset=-4 xadvance=23 page=0 chnl=15
|
||||
char id=62 x=221 y=144 width=35 height=71 xoffset=-4 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=63 x=398 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=25 page=0 chnl=15
|
||||
char id=64 x=130 y=0 width=52 height=71 xoffset=-4 yoffset=-4 xadvance=44 page=0 chnl=15
|
||||
char id=65 x=445 y=72 width=37 height=71 xoffset=-4 yoffset=-4 xadvance=29 page=0 chnl=15
|
||||
char id=66 x=209 y=72 width=40 height=71 xoffset=-4 yoffset=-4 xadvance=32 page=0 chnl=15
|
||||
char id=67 x=173 y=216 width=33 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=68 x=250 y=72 width=39 height=71 xoffset=-4 yoffset=-4 xadvance=31 page=0 chnl=15
|
||||
char id=69 x=306 y=216 width=32 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=70 x=149 y=144 width=35 height=71 xoffset=-4 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=71 x=112 y=144 width=36 height=71 xoffset=-4 yoffset=-4 xadvance=28 page=0 chnl=15
|
||||
char id=72 x=458 y=0 width=42 height=71 xoffset=-4 yoffset=-4 xadvance=34 page=0 chnl=15
|
||||
char id=73 x=288 y=360 width=20 height=71 xoffset=-4 yoffset=-4 xadvance=12 page=0 chnl=15
|
||||
char id=74 x=257 y=144 width=35 height=71 xoffset=-4 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=75 x=0 y=144 width=37 height=71 xoffset=-4 yoffset=-4 xadvance=29 page=0 chnl=15
|
||||
char id=76 x=139 y=216 width=33 height=71 xoffset=-4 yoffset=-4 xadvance=25 page=0 chnl=15
|
||||
char id=77 x=85 y=72 width=41 height=71 xoffset=-4 yoffset=-4 xadvance=33 page=0 chnl=15
|
||||
char id=78 x=371 y=0 width=43 height=71 xoffset=-4 yoffset=-4 xadvance=35 page=0 chnl=15
|
||||
char id=79 x=168 y=72 width=40 height=71 xoffset=-4 yoffset=-4 xadvance=31 page=0 chnl=15
|
||||
char id=80 x=75 y=144 width=36 height=71 xoffset=-4 yoffset=-4 xadvance=28 page=0 chnl=15
|
||||
char id=81 x=280 y=0 width=45 height=71 xoffset=-4 yoffset=-4 xadvance=37 page=0 chnl=15
|
||||
char id=82 x=369 y=72 width=37 height=71 xoffset=-4 yoffset=-4 xadvance=29 page=0 chnl=15
|
||||
char id=83 x=70 y=216 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=84 x=43 y=72 width=41 height=71 xoffset=-4 yoffset=-4 xadvance=33 page=0 chnl=15
|
||||
char id=85 x=0 y=72 width=42 height=71 xoffset=-4 yoffset=-4 xadvance=34 page=0 chnl=15
|
||||
char id=86 x=326 y=0 width=44 height=71 xoffset=-4 yoffset=-4 xadvance=36 page=0 chnl=15
|
||||
char id=87 x=232 y=0 width=47 height=71 xoffset=-4 yoffset=-4 xadvance=39 page=0 chnl=15
|
||||
char id=88 x=127 y=72 width=40 height=71 xoffset=-4 yoffset=-4 xadvance=33 page=0 chnl=15
|
||||
char id=89 x=290 y=72 width=39 height=71 xoffset=-4 yoffset=-4 xadvance=31 page=0 chnl=15
|
||||
char id=90 x=330 y=72 width=38 height=71 xoffset=-4 yoffset=-4 xadvance=30 page=0 chnl=15
|
||||
char id=91 x=499 y=288 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=92 x=109 y=360 width=26 height=71 xoffset=-4 yoffset=-4 xadvance=18 page=0 chnl=15
|
||||
char id=93 x=499 y=216 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=97 x=302 y=288 width=28 height=71 xoffset=-4 yoffset=-4 xadvance=20 page=0 chnl=15
|
||||
char id=98 x=415 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=99 x=136 y=360 width=25 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=100 x=124 y=288 width=30 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=101 x=162 y=360 width=25 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=102 x=443 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=103 x=0 y=360 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=104 x=240 y=216 width=32 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=105 x=382 y=360 width=16 height=71 xoffset=-4 yoffset=-4 xadvance=8 page=0 chnl=15
|
||||
char id=106 x=359 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=18 page=0 chnl=15
|
||||
char id=107 x=483 y=72 width=28 height=71 xoffset=-4 yoffset=-4 xadvance=20 page=0 chnl=15
|
||||
char id=108 x=55 y=360 width=26 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=109 x=435 y=216 width=31 height=71 xoffset=-4 yoffset=-4 xadvance=23 page=0 chnl=15
|
||||
char id=110 x=273 y=216 width=32 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=111 x=31 y=288 width=30 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=112 x=331 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=113 x=363 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=114 x=273 y=288 width=28 height=71 xoffset=-4 yoffset=-4 xadvance=20 page=0 chnl=15
|
||||
char id=115 x=28 y=360 width=26 height=71 xoffset=-4 yoffset=-4 xadvance=18 page=0 chnl=15
|
||||
char id=116 x=62 y=288 width=30 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=117 x=93 y=288 width=30 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=118 x=467 y=216 width=31 height=71 xoffset=-4 yoffset=-4 xadvance=23 page=0 chnl=15
|
||||
char id=119 x=293 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=120 x=185 y=288 width=29 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=121 x=215 y=288 width=28 height=71 xoffset=-4 yoffset=-4 xadvance=20 page=0 chnl=15
|
||||
char id=122 x=244 y=288 width=28 height=71 xoffset=-4 yoffset=-4 xadvance=20 page=0 chnl=15
|
||||
char id=123 x=428 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=124 x=440 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=125 x=452 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=126 x=0 y=0 width=66 height=71 xoffset=-4 yoffset=-4 xadvance=58 page=0 chnl=15
|
||||
char id=162 x=464 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=163 x=407 y=72 width=37 height=71 xoffset=-4 yoffset=-4 xadvance=29 page=0 chnl=15
|
||||
char id=167 x=476 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=171 x=214 y=360 width=25 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=187 x=240 y=360 width=25 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=191 x=500 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=192 x=0 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=193 x=12 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=194 x=24 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=196 x=36 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=199 x=48 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=200 x=60 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=201 x=72 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=202 x=84 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=203 x=96 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=206 x=108 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=207 x=120 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=209 x=132 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=211 x=144 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=212 x=156 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=214 x=168 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=217 x=180 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=218 x=192 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=219 x=204 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=220 x=216 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=223 x=228 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=224 x=240 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=225 x=252 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=226 x=264 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=228 x=276 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=231 x=288 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=232 x=300 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=233 x=312 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=234 x=324 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=235 x=336 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=238 x=348 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=239 x=360 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=243 x=372 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=244 x=384 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=246 x=396 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=249 x=408 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=250 x=420 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=251 x=432 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=252 x=444 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
|
Before Width: | Height: | Size: 80 KiB |
|
|
@ -1,139 +0,0 @@
|
|||
info face="Starcatcher" size=-64 bold=0 italic=0 charset="ANSI" unicode=0 stretchH=100 smooth=1 aa=1 padding=4,4,4,4 spacing=1,1 outline=0
|
||||
common lineHeight=63 base=50 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
|
||||
page id=0 file="star2.png"
|
||||
chars count=135
|
||||
char id=32 x=416 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=33 x=347 y=360 width=17 height=71 xoffset=-4 yoffset=-4 xadvance=9 page=0 chnl=15
|
||||
char id=35 x=183 y=0 width=48 height=71 xoffset=-4 yoffset=-4 xadvance=40 page=0 chnl=15
|
||||
char id=36 x=328 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=37 x=67 y=0 width=62 height=71 xoffset=-4 yoffset=-4 xadvance=55 page=0 chnl=15
|
||||
char id=38 x=488 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=39 x=266 y=360 width=21 height=71 xoffset=-4 yoffset=-4 xadvance=13 page=0 chnl=15
|
||||
char id=40 x=471 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=41 x=387 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=42 x=415 y=0 width=42 height=71 xoffset=-4 yoffset=-4 xadvance=34 page=0 chnl=15
|
||||
char id=43 x=403 y=216 width=31 height=71 xoffset=-4 yoffset=-4 xadvance=23 page=0 chnl=15
|
||||
char id=44 x=309 y=360 width=18 height=71 xoffset=-4 yoffset=-4 xadvance=10 page=0 chnl=15
|
||||
char id=45 x=82 y=360 width=26 height=71 xoffset=-4 yoffset=-4 xadvance=18 page=0 chnl=15
|
||||
char id=46 x=365 y=360 width=16 height=71 xoffset=-4 yoffset=-4 xadvance=7 page=0 chnl=15
|
||||
char id=47 x=155 y=288 width=29 height=71 xoffset=-4 yoffset=-4 xadvance=21 page=0 chnl=15
|
||||
char id=48 x=38 y=144 width=36 height=71 xoffset=-4 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=49 x=188 y=360 width=25 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=50 x=339 y=216 width=31 height=71 xoffset=-4 yoffset=-4 xadvance=23 page=0 chnl=15
|
||||
char id=51 x=0 y=288 width=30 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=52 x=35 y=216 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=53 x=105 y=216 width=33 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=54 x=207 y=216 width=32 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=55 x=433 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=56 x=468 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=57 x=0 y=216 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=58 x=399 y=360 width=16 height=71 xoffset=-4 yoffset=-4 xadvance=7 page=0 chnl=15
|
||||
char id=59 x=328 y=360 width=18 height=71 xoffset=-4 yoffset=-4 xadvance=10 page=0 chnl=15
|
||||
char id=60 x=185 y=144 width=35 height=71 xoffset=-4 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=61 x=371 y=216 width=31 height=71 xoffset=-4 yoffset=-4 xadvance=23 page=0 chnl=15
|
||||
char id=62 x=221 y=144 width=35 height=71 xoffset=-4 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=63 x=398 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=25 page=0 chnl=15
|
||||
char id=64 x=130 y=0 width=52 height=71 xoffset=-4 yoffset=-4 xadvance=44 page=0 chnl=15
|
||||
char id=65 x=445 y=72 width=37 height=71 xoffset=-4 yoffset=-4 xadvance=29 page=0 chnl=15
|
||||
char id=66 x=209 y=72 width=40 height=71 xoffset=-4 yoffset=-4 xadvance=32 page=0 chnl=15
|
||||
char id=67 x=173 y=216 width=33 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=68 x=250 y=72 width=39 height=71 xoffset=-4 yoffset=-4 xadvance=31 page=0 chnl=15
|
||||
char id=69 x=306 y=216 width=32 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=70 x=149 y=144 width=35 height=71 xoffset=-4 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=71 x=112 y=144 width=36 height=71 xoffset=-4 yoffset=-4 xadvance=28 page=0 chnl=15
|
||||
char id=72 x=458 y=0 width=42 height=71 xoffset=-4 yoffset=-4 xadvance=34 page=0 chnl=15
|
||||
char id=73 x=288 y=360 width=20 height=71 xoffset=-4 yoffset=-4 xadvance=12 page=0 chnl=15
|
||||
char id=74 x=257 y=144 width=35 height=71 xoffset=-4 yoffset=-4 xadvance=27 page=0 chnl=15
|
||||
char id=75 x=0 y=144 width=37 height=71 xoffset=-4 yoffset=-4 xadvance=29 page=0 chnl=15
|
||||
char id=76 x=139 y=216 width=33 height=71 xoffset=-4 yoffset=-4 xadvance=25 page=0 chnl=15
|
||||
char id=77 x=85 y=72 width=41 height=71 xoffset=-4 yoffset=-4 xadvance=33 page=0 chnl=15
|
||||
char id=78 x=371 y=0 width=43 height=71 xoffset=-4 yoffset=-4 xadvance=35 page=0 chnl=15
|
||||
char id=79 x=168 y=72 width=40 height=71 xoffset=-4 yoffset=-4 xadvance=31 page=0 chnl=15
|
||||
char id=80 x=75 y=144 width=36 height=71 xoffset=-4 yoffset=-4 xadvance=28 page=0 chnl=15
|
||||
char id=81 x=280 y=0 width=45 height=71 xoffset=-4 yoffset=-4 xadvance=37 page=0 chnl=15
|
||||
char id=82 x=369 y=72 width=37 height=71 xoffset=-4 yoffset=-4 xadvance=29 page=0 chnl=15
|
||||
char id=83 x=70 y=216 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=84 x=43 y=72 width=41 height=71 xoffset=-4 yoffset=-4 xadvance=33 page=0 chnl=15
|
||||
char id=85 x=0 y=72 width=42 height=71 xoffset=-4 yoffset=-4 xadvance=34 page=0 chnl=15
|
||||
char id=86 x=326 y=0 width=44 height=71 xoffset=-4 yoffset=-4 xadvance=36 page=0 chnl=15
|
||||
char id=87 x=232 y=0 width=47 height=71 xoffset=-4 yoffset=-4 xadvance=39 page=0 chnl=15
|
||||
char id=88 x=127 y=72 width=40 height=71 xoffset=-4 yoffset=-4 xadvance=33 page=0 chnl=15
|
||||
char id=89 x=290 y=72 width=39 height=71 xoffset=-4 yoffset=-4 xadvance=31 page=0 chnl=15
|
||||
char id=90 x=330 y=72 width=38 height=71 xoffset=-4 yoffset=-4 xadvance=30 page=0 chnl=15
|
||||
char id=91 x=499 y=288 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=92 x=109 y=360 width=26 height=71 xoffset=-4 yoffset=-4 xadvance=18 page=0 chnl=15
|
||||
char id=93 x=499 y=216 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=97 x=302 y=288 width=28 height=71 xoffset=-4 yoffset=-4 xadvance=20 page=0 chnl=15
|
||||
char id=98 x=415 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=99 x=136 y=360 width=25 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=100 x=124 y=288 width=30 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=101 x=162 y=360 width=25 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=102 x=443 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=103 x=0 y=360 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=104 x=240 y=216 width=32 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=105 x=382 y=360 width=16 height=71 xoffset=-4 yoffset=-4 xadvance=8 page=0 chnl=15
|
||||
char id=106 x=359 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=18 page=0 chnl=15
|
||||
char id=107 x=483 y=72 width=28 height=71 xoffset=-4 yoffset=-4 xadvance=20 page=0 chnl=15
|
||||
char id=108 x=55 y=360 width=26 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=109 x=435 y=216 width=31 height=71 xoffset=-4 yoffset=-4 xadvance=23 page=0 chnl=15
|
||||
char id=110 x=273 y=216 width=32 height=71 xoffset=-4 yoffset=-4 xadvance=24 page=0 chnl=15
|
||||
char id=111 x=31 y=288 width=30 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=112 x=331 y=288 width=27 height=71 xoffset=-4 yoffset=-4 xadvance=19 page=0 chnl=15
|
||||
char id=113 x=363 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=114 x=273 y=288 width=28 height=71 xoffset=-4 yoffset=-4 xadvance=20 page=0 chnl=15
|
||||
char id=115 x=28 y=360 width=26 height=71 xoffset=-4 yoffset=-4 xadvance=18 page=0 chnl=15
|
||||
char id=116 x=62 y=288 width=30 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=117 x=93 y=288 width=30 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=118 x=467 y=216 width=31 height=71 xoffset=-4 yoffset=-4 xadvance=23 page=0 chnl=15
|
||||
char id=119 x=293 y=144 width=34 height=71 xoffset=-4 yoffset=-4 xadvance=26 page=0 chnl=15
|
||||
char id=120 x=185 y=288 width=29 height=71 xoffset=-4 yoffset=-4 xadvance=22 page=0 chnl=15
|
||||
char id=121 x=215 y=288 width=28 height=71 xoffset=-4 yoffset=-4 xadvance=20 page=0 chnl=15
|
||||
char id=122 x=244 y=288 width=28 height=71 xoffset=-4 yoffset=-4 xadvance=20 page=0 chnl=15
|
||||
char id=123 x=428 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=124 x=440 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=125 x=452 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=126 x=0 y=0 width=66 height=71 xoffset=-4 yoffset=-4 xadvance=58 page=0 chnl=15
|
||||
char id=162 x=464 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=163 x=407 y=72 width=37 height=71 xoffset=-4 yoffset=-4 xadvance=29 page=0 chnl=15
|
||||
char id=167 x=476 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=171 x=214 y=360 width=25 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=187 x=240 y=360 width=25 height=71 xoffset=-4 yoffset=-4 xadvance=17 page=0 chnl=15
|
||||
char id=191 x=500 y=360 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=192 x=0 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=193 x=12 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=194 x=24 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=196 x=36 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=199 x=48 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=200 x=60 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=201 x=72 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=202 x=84 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=203 x=96 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=206 x=108 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=207 x=120 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=209 x=132 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=211 x=144 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=212 x=156 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=214 x=168 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=217 x=180 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=218 x=192 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=219 x=204 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=220 x=216 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=223 x=228 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=224 x=240 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=225 x=252 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=226 x=264 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=228 x=276 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=231 x=288 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=232 x=300 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=233 x=312 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=234 x=324 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=235 x=336 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=238 x=348 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=239 x=360 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=243 x=372 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=244 x=384 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=246 x=396 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=249 x=408 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=250 x=420 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=251 x=432 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
char id=252 x=444 y=432 width=11 height=71 xoffset=-5 yoffset=-4 xadvance=1 page=0 chnl=15
|
||||
|
Before Width: | Height: | Size: 71 KiB |
|
Before Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 98 KiB |
|
|
@ -1,291 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* CAT VS ROOMBA [GLOBAL GAME JAM 2019]
|
||||
*
|
||||
* Ah! Home, sweet home! Time for some automatic cleaning...
|
||||
* if the worst enemy of Roomba allows it... be careful with Cat!
|
||||
*
|
||||
* This game has been created using raylib 2.0 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
* Copyright (c) 2019 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#include "raylib.h"
|
||||
#include "screens/screens.h" // NOTE: Defines global variable: currentScreen
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
GameScreen currentScreen = 0;
|
||||
Font font = { 0 };
|
||||
Font font2 = { 0 };
|
||||
Music music = { 0 };
|
||||
Sound fxCoin = { 0 };
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition (local to this module)
|
||||
//----------------------------------------------------------------------------------
|
||||
const int screenWidth = 1280;
|
||||
#if defined(TILE_VIEWER_MODE)
|
||||
const int screenHeight = 1080;
|
||||
#else
|
||||
const int screenHeight = 720;
|
||||
#endif
|
||||
|
||||
// Required variables to manage screen transitions (fade-in, fade-out)
|
||||
static float transAlpha = 0.0f;
|
||||
static bool onTransition = false;
|
||||
static bool transFadeOut = false;
|
||||
static int transFromScreen = -1;
|
||||
static int transToScreen = -1;
|
||||
|
||||
// NOTE: Some global variables that require to be visible for all screens,
|
||||
// are defined in screens.h (i.e. currentScreen)
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Local Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
static void ChangeToScreen(int screen); // No transition effect
|
||||
|
||||
static void TransitionToScreen(int screen);
|
||||
static void UpdateTransition(void);
|
||||
static void DrawTransition(void);
|
||||
|
||||
static void UpdateDrawFrame(void); // Update and Draw one frame
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Main entry point
|
||||
//----------------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
// Initialization (Note windowTitle is unused on Android)
|
||||
//---------------------------------------------------------
|
||||
InitWindow(screenWidth, screenHeight, "CAT VS ROOMBA [GGJ19]");
|
||||
|
||||
// Global data loading (assets that must be available in all screens, i.e. fonts)
|
||||
InitAudioDevice();
|
||||
|
||||
font = LoadFont("resources/star.fnt");
|
||||
font2 = LoadFont("resources/star2.fnt");
|
||||
music = LoadMusicStream("resources/cat_mouse.mod");
|
||||
fxCoin = LoadSound("resources/coin.wav");
|
||||
|
||||
SetMusicVolume(music, 1.0f);
|
||||
PlayMusicStream(music);
|
||||
|
||||
// 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
|
||||
{
|
||||
UpdateDrawFrame();
|
||||
}
|
||||
#endif
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Unload current screen data before closing
|
||||
switch (currentScreen)
|
||||
{
|
||||
case LOGO: UnloadLogoScreen(); break;
|
||||
case TITLE: UnloadTitleScreen(); break;
|
||||
case GAMEPLAY: UnloadGameplayScreen(); break;
|
||||
case ENDING: UnloadEndingScreen(); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Unload all global loaded data (i.e. fonts) here!
|
||||
UnloadFont(font);
|
||||
UnloadFont(font2);
|
||||
UnloadMusicStream(music);
|
||||
UnloadSound(fxCoin);
|
||||
|
||||
CloseAudioDevice(); // Close audio context
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module specific Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Change to next screen, no transition
|
||||
static void ChangeToScreen(int screen)
|
||||
{
|
||||
// Unload current screen
|
||||
switch (currentScreen)
|
||||
{
|
||||
case LOGO: UnloadLogoScreen(); break;
|
||||
case TITLE: UnloadTitleScreen(); break;
|
||||
case GAMEPLAY: UnloadGameplayScreen(); break;
|
||||
case ENDING: UnloadEndingScreen(); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Init next screen
|
||||
switch (screen)
|
||||
{
|
||||
case LOGO: InitLogoScreen(); break;
|
||||
case TITLE: InitTitleScreen(); break;
|
||||
case GAMEPLAY: InitGameplayScreen(); break;
|
||||
case ENDING: InitEndingScreen(); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
currentScreen = screen;
|
||||
}
|
||||
|
||||
// Define transition to next screen
|
||||
static void TransitionToScreen(int screen)
|
||||
{
|
||||
onTransition = true;
|
||||
transFadeOut = false;
|
||||
transFromScreen = currentScreen;
|
||||
transToScreen = screen;
|
||||
transAlpha = 0.0f;
|
||||
}
|
||||
|
||||
// Update transition effect
|
||||
static void UpdateTransition(void)
|
||||
{
|
||||
if (!transFadeOut)
|
||||
{
|
||||
transAlpha += 0.02f;
|
||||
|
||||
// NOTE: Due to float internal representation, condition jumps on 1.0f instead of 1.05f
|
||||
// For that reason we compare against 1.01f, to avoid last frame loading stop
|
||||
if (transAlpha > 1.01f)
|
||||
{
|
||||
transAlpha = 1.0f;
|
||||
|
||||
// Unload current screen
|
||||
switch (transFromScreen)
|
||||
{
|
||||
case LOGO: UnloadLogoScreen(); break;
|
||||
case TITLE: UnloadTitleScreen(); break;
|
||||
case GAMEPLAY: UnloadGameplayScreen(); break;
|
||||
case ENDING: UnloadEndingScreen(); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Load next screen
|
||||
switch (transToScreen)
|
||||
{
|
||||
case LOGO: InitLogoScreen(); break;
|
||||
case TITLE: InitTitleScreen(); break;
|
||||
case GAMEPLAY: InitGameplayScreen(); break;
|
||||
case ENDING: InitEndingScreen(); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
currentScreen = transToScreen;
|
||||
|
||||
// Activate fade out effect to next loaded screen
|
||||
transFadeOut = true;
|
||||
}
|
||||
}
|
||||
else // Transition fade out logic
|
||||
{
|
||||
transAlpha -= 0.02f;
|
||||
|
||||
if (transAlpha < -0.01f)
|
||||
{
|
||||
transAlpha = 0.0f;
|
||||
transFadeOut = false;
|
||||
onTransition = false;
|
||||
transFromScreen = -1;
|
||||
transToScreen = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw transition effect (full-screen rectangle)
|
||||
static void DrawTransition(void)
|
||||
{
|
||||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), Fade(BLACK, transAlpha));
|
||||
}
|
||||
|
||||
// Update and draw game frame
|
||||
static void UpdateDrawFrame(void)
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateMusicStream(music); // NOTE: Music keeps playing between screens
|
||||
|
||||
if (!onTransition)
|
||||
{
|
||||
switch(currentScreen)
|
||||
{
|
||||
case LOGO:
|
||||
{
|
||||
UpdateLogoScreen();
|
||||
|
||||
if (FinishLogoScreen()) TransitionToScreen(TITLE);
|
||||
|
||||
} break;
|
||||
case TITLE:
|
||||
{
|
||||
UpdateTitleScreen();
|
||||
|
||||
if (FinishTitleScreen() == 1) TransitionToScreen(OPTIONS);
|
||||
else if (FinishTitleScreen() == 2) TransitionToScreen(GAMEPLAY);
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
UpdateGameplayScreen();
|
||||
|
||||
if (FinishGameplayScreen() == 1) TransitionToScreen(ENDING);
|
||||
//else if (FinishGameplayScreen() == 2) TransitionToScreen(TITLE);
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
UpdateEndingScreen();
|
||||
|
||||
if (FinishEndingScreen() == 1) TransitionToScreen(TITLE);
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else UpdateTransition(); // Update transition (fade-in, fade-out)
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
switch(currentScreen)
|
||||
{
|
||||
case LOGO: DrawLogoScreen(); break;
|
||||
case TITLE: DrawTitleScreen(); break;
|
||||
case GAMEPLAY: DrawGameplayScreen(); break;
|
||||
case ENDING: DrawEndingScreen(); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Draw full screen rectangle in front of everything
|
||||
if (onTransition) DrawTransition();
|
||||
|
||||
//DrawFPS(10, 10);
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib - Advance Game template
|
||||
*
|
||||
* Ending Screen Functions Definitions (Init, Update, Draw, Unload)
|
||||
*
|
||||
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* 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)
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Ending screen global variables
|
||||
static int framesCounter;
|
||||
static int finishScreen;
|
||||
|
||||
static int scrollPositionX;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Ending Screen Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Ending Screen Initialization logic
|
||||
void InitEndingScreen(void)
|
||||
{
|
||||
// TODO: Initialize ENDING screen variables here!
|
||||
framesCounter = 0;
|
||||
finishScreen = 0;
|
||||
|
||||
PlayMusicStream(music);
|
||||
}
|
||||
|
||||
// Ending Screen Update logic
|
||||
void UpdateEndingScreen(void)
|
||||
{
|
||||
framesCounter++;
|
||||
|
||||
scrollPositionX -= 5;
|
||||
if (scrollPositionX < -GetScreenWidth()) scrollPositionX = 0;
|
||||
|
||||
// Press enter or tap to return to TITLE screen
|
||||
if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
|
||||
{
|
||||
finishScreen = 1;
|
||||
PlaySound(fxCoin);
|
||||
}
|
||||
}
|
||||
|
||||
// Ending Screen Draw logic
|
||||
void DrawEndingScreen(void)
|
||||
{
|
||||
for (int i = 0; i < 64*2*2; i++)
|
||||
{
|
||||
DrawRectangle(64*i + scrollPositionX, 0, 64, GetScreenHeight(), (i%2 == 0)? GetColor(0xf3726dff) : GetColor(0xffcf6bff));
|
||||
}
|
||||
|
||||
if (result == 0) DrawTextEx(font2, "YOU LOOSE...", (Vector2){ 350, 200 }, font2.baseSize*2, 2, WHITE);
|
||||
else if (result == 1) DrawTextEx(font, "YOU WIN!!!", (Vector2){ 380, 200 }, font.baseSize*2, 2, WHITE);
|
||||
|
||||
// Draw score
|
||||
DrawTextEx(font, FormatText("FINAL SCORE: %i", score), (Vector2){ 400, 360 }, font2.baseSize, 2, WHITE);
|
||||
|
||||
if ((framesCounter/30)%2) DrawTextEx(font2, "PRESS ENTER to TITLE", (Vector2){ 340, 550 }, font2.baseSize, 2, WHITE);
|
||||
}
|
||||
|
||||
// Ending Screen Unload logic
|
||||
void UnloadEndingScreen(void)
|
||||
{
|
||||
// TODO: Unload ENDING screen variables here!
|
||||
}
|
||||
|
||||
// Ending Screen should finish?
|
||||
int FinishEndingScreen(void)
|
||||
{
|
||||
return finishScreen;
|
||||
}
|
||||
|
|
@ -1,652 +0,0 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib - Advance Game template
|
||||
*
|
||||
* Gameplay Screen Functions Definitions (Init, Update, Draw, Unload)
|
||||
*
|
||||
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* 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 "raymath.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define TILE_REQUIRED_CLEAN_TIME 2 // Frames it takes to clean a dirt level
|
||||
#define TILE_SCORE_BY_CLEANED_LEVEL 100 // Score by cleanied dirt level
|
||||
#define TILE_REQUIRED_CLEAN_AREA 28*28 // Required are for actually cleaning tile
|
||||
|
||||
#define TILE_SIZE 36 // Tile size, it should match texture
|
||||
#define MAX_TILES_X 32
|
||||
#define MAX_TILES_Y 17
|
||||
|
||||
#define CAT_TARGET_RADIUS 3 // Target proximity radius
|
||||
#define CAT_DIRT_CELL_RADIUS 2 // Cells around cat for dirt spreading
|
||||
|
||||
#define TIME_LIMIT_SECONDS 180 // Time to complete the level in seconds
|
||||
|
||||
#define MAX_SCORE_POPUPS 60 // Maximum simultaneous score pop-ups!
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module types
|
||||
//----------------------------------------------------------------------------------
|
||||
// One dirt tile type
|
||||
typedef struct {
|
||||
Vector2 position; // Relative to top-left corner
|
||||
int level; // Dirtiness: 0-Clean, 1-2-3-Dirt levels
|
||||
int state; // Current dirtiness state
|
||||
int counter; // Frames counter for cleaning
|
||||
//int time; // Time it takes to make it clean --> Depends on level
|
||||
//int score; // It depends on the dirt level
|
||||
bool cleaned; // If it was cleaned (not clean by default)
|
||||
} Dirtile;
|
||||
|
||||
// Score poping-up type
|
||||
typedef struct {
|
||||
Vector2 position;
|
||||
int value;
|
||||
float alpha;
|
||||
bool enabled;
|
||||
} ScorePopup;
|
||||
|
||||
// Furniture tile set
|
||||
typedef struct {
|
||||
int id; // Furniture tile id
|
||||
int posX; // Position X on tileset
|
||||
int posY; // Position Y on tileset
|
||||
int width; // Furniture piece width
|
||||
int height; // Furniture piece height
|
||||
} FurSet;
|
||||
|
||||
// Furniture type
|
||||
typedef struct {
|
||||
int furId; // Tileset id
|
||||
int cellX; // Cell position X
|
||||
int cellY; // Cell position Y
|
||||
int state; // 0-Block, 1-Alpha, 2-Breakable
|
||||
int counter; // Counter in case of break
|
||||
} Furniture;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition (local to this module)
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Gameplay screen global variables
|
||||
static int framesCounter;
|
||||
static int timeLevelSeconds;
|
||||
static bool levelFinished;
|
||||
static int finishScreen;
|
||||
|
||||
const Vector2 roomOffset = { 70, 70 };
|
||||
|
||||
static Texture2D roomba;
|
||||
static Texture2D cat;
|
||||
static Texture2D dirtiles;
|
||||
static Texture2D furniture;
|
||||
|
||||
#if defined(TILE_VIEWER_MODE)
|
||||
static Texture2D tracemap;
|
||||
static Texture2D fursetid;
|
||||
#endif
|
||||
|
||||
static Music catch;
|
||||
|
||||
static Sound fxCat[2];
|
||||
static Sound fxRoomba[3];
|
||||
|
||||
static Vector2 roombaPosition = { 100, 100 };
|
||||
static Vector2 roombaSpeed = { 4, 4 };
|
||||
static int roombaTilePosX = 0, roombaTilePosY = 0;
|
||||
|
||||
static Vector2 catPosition = { 0, 0 };
|
||||
static Vector2 catTargetPosition = { 0, 0 };
|
||||
static Vector2 catSpeed = { 3, 3 };
|
||||
static int catTilePosX = 0, catTilePosY = 0;
|
||||
static bool catShouldMove = false;
|
||||
|
||||
static Vector2 mousePosition = { 0, 0 };
|
||||
static int mouseTileX = -1, mouseTileY = -1;
|
||||
|
||||
static Dirtile tiles[MAX_TILES_X*MAX_TILES_Y] = { 0 };
|
||||
|
||||
static ScorePopup popup[MAX_SCORE_POPUPS] = { 0 };
|
||||
|
||||
static FurSet furset[32] = { -1 };
|
||||
static Furniture furmap[40] = { -1 };
|
||||
static int furnitureCount = 0;
|
||||
|
||||
// Furniture collisions map
|
||||
// 0-block, 1-normal, 2-alpha, 3-breakable
|
||||
static int furcolmap[MAX_TILES_X*MAX_TILES_Y] = {
|
||||
1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,3,3,1,1,1,0,0,1,1,1,1,1,1,1,1,
|
||||
1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,3,3,1,1,1,0,0,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
0,0,1,1,1,1,2,2,2,1,1,1,0,0,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
0,0,1,1,1,1,2,2,2,1,1,1,0,0,1,1,1,2,2,2,1,1,1,1,3,3,1,1,1,1,0,0,
|
||||
3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,1,1,1,3,3,1,1,1,1,0,0,
|
||||
3,3,1,1,2,2,2,2,2,2,2,2,1,1,1,1,2,2,2,2,2,1,1,1,0,0,0,0,0,0,0,0,
|
||||
1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,1,2,2,2,1,1,1,1,0,0,0,0,0,0,0,0,
|
||||
1,1,1,1,2,2,2,2,2,2,2,2,1,1,1,1,1,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,0,0,0,0,0,0,0,0,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
|
||||
1,1,1,1,0,0,0,0,0,0,0,0,3,3,1,1,1,1,1,1,1,0,0,1,2,2,2,2,2,2,1,1,
|
||||
0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,2,2,2,2,2,2,1,1,
|
||||
0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,1,1,
|
||||
0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,1,1,
|
||||
0,0,0,0,0,0,0,0,0,0,2,2,2,3,3,3,3,1,1,0,0,1,2,2,2,2,2,2,2,2,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,2,2,2,3,3,3,3,1,1,0,0,1,2,2,2,2,2,2,2,2,0,0 };
|
||||
|
||||
static bool showObjective = false;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
static float GetTileCleanPercent(void);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Gameplay Screen Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Gameplay Screen Initialization logic
|
||||
void InitGameplayScreen(void)
|
||||
{
|
||||
// Initialize GAMEPLAY screen variables here!
|
||||
framesCounter = 0;
|
||||
finishScreen = 0;
|
||||
timeLevelSeconds = TIME_LIMIT_SECONDS;
|
||||
levelFinished = false;
|
||||
|
||||
roomba = LoadTexture("resources/roomba.png");
|
||||
cat = LoadTexture("resources/cat.png");
|
||||
dirtiles = LoadTexture("resources/dirtiles.png");
|
||||
furniture = LoadTexture("resources/furniture.png");
|
||||
|
||||
#if defined(TILE_VIEWER_MODE)
|
||||
tracemap = LoadTexture("resources/tracemap.png");
|
||||
fursetid = LoadTexture("resources/fursetid.png");
|
||||
#endif
|
||||
|
||||
int furCount = 0;
|
||||
FILE *fursetFile = fopen("resources/furset.txt", "rt");
|
||||
|
||||
if (fursetFile != NULL)
|
||||
{
|
||||
char buffer[512] = { 0 };
|
||||
|
||||
while (!feof(fursetFile))
|
||||
{
|
||||
fgets(buffer, 512, fursetFile);
|
||||
|
||||
switch (buffer[0])
|
||||
{
|
||||
case 'f':
|
||||
{
|
||||
sscanf(buffer, "f %i %i %i %i %i",
|
||||
&furset[furCount].id,
|
||||
&furset[furCount].posX,
|
||||
&furset[furCount].posY,
|
||||
&furset[furCount].width,
|
||||
&furset[furCount].height);
|
||||
furCount++;
|
||||
} break;
|
||||
case '.': // This is a comment
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fursetFile);
|
||||
}
|
||||
|
||||
// Position and size come in cell form, not pixels
|
||||
for (int i = 0; i < furCount; i++)
|
||||
{
|
||||
furset[i].posX *= TILE_SIZE;
|
||||
furset[i].posY *= TILE_SIZE;
|
||||
furset[i].width *= TILE_SIZE;
|
||||
furset[i].height *= TILE_SIZE;
|
||||
}
|
||||
|
||||
printf("Furniture SET elements read: %i\n", furCount);
|
||||
|
||||
// Init furniture elements
|
||||
FILE *furnitureFile = fopen("resources/furmap.txt", "rt");
|
||||
|
||||
if (furnitureFile != NULL)
|
||||
{
|
||||
char buffer[512] = { 0 };
|
||||
|
||||
while (!feof(furnitureFile))
|
||||
{
|
||||
fgets(buffer, 512, furnitureFile);
|
||||
|
||||
switch (buffer[0])
|
||||
{
|
||||
case 'f':
|
||||
{
|
||||
sscanf(buffer, "f %i %i %i %i %i",
|
||||
&furmap[furnitureCount].furId,
|
||||
&furmap[furnitureCount].cellX,
|
||||
&furmap[furnitureCount].cellY,
|
||||
&furmap[furnitureCount].state,
|
||||
&furmap[furnitureCount].counter);
|
||||
furnitureCount++;
|
||||
} break;
|
||||
case '.': // This is a comment
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(furnitureFile);
|
||||
}
|
||||
|
||||
printf("Furniture MAP elements read: %i\n", furnitureCount);
|
||||
|
||||
// Init dirt tiles
|
||||
for (int y = 0; y < MAX_TILES_Y; y++)
|
||||
{
|
||||
for (int x = 0; x < MAX_TILES_X; x++)
|
||||
{
|
||||
tiles[y*MAX_TILES_X + x].position = (Vector2){ roomOffset.x + TILE_SIZE*x, roomOffset.y + TILE_SIZE*y };
|
||||
|
||||
if ((furcolmap[y*MAX_TILES_X + x] != 0) &&
|
||||
(furcolmap[y*MAX_TILES_X + x] != 3))
|
||||
{
|
||||
// TODO: Level of dirtiness depends on difficulty level
|
||||
// Adjust probability of every tile dirt level
|
||||
int dirt = GetRandomValue(0, 100);
|
||||
|
||||
if (dirt < 50) tiles[y*MAX_TILES_X + x].level = 0; // 50% probability
|
||||
else if (dirt < 70) tiles[y*MAX_TILES_X + x].level = 1; // 20% probability
|
||||
else if (dirt < 90) tiles[y*MAX_TILES_X + x].level = 2; // 10% probability
|
||||
else if (dirt < 100) tiles[y*MAX_TILES_X + x].level = 3; // 10% probability
|
||||
}
|
||||
else tiles[y*MAX_TILES_X + x].level = 0;
|
||||
|
||||
tiles[y*MAX_TILES_X + x].state = tiles[y*MAX_TILES_X + x].level;
|
||||
tiles[y*MAX_TILES_X + x].counter = (tiles[y*MAX_TILES_X + x].level == 0)? 0 : TILE_REQUIRED_CLEAN_TIME;
|
||||
tiles[y*MAX_TILES_X + x].cleaned = (tiles[y*MAX_TILES_X + x].level == 0)? true : false;
|
||||
}
|
||||
}
|
||||
|
||||
// Init score popups
|
||||
for (int i = 0; i < MAX_SCORE_POPUPS; i++)
|
||||
{
|
||||
popup[i].position = (Vector2){ 0, 0 };
|
||||
popup[i].value = TILE_SCORE_BY_CLEANED_LEVEL;
|
||||
popup[i].enabled = false;
|
||||
popup[i].alpha = 1.0f;
|
||||
}
|
||||
|
||||
// Init cat position
|
||||
catPosition = (Vector2){ 30*TILE_SIZE + roomOffset.x, TILE_SIZE + roomOffset.y };
|
||||
catTargetPosition = catPosition;
|
||||
|
||||
showObjective = true;
|
||||
|
||||
// Load music and sounds
|
||||
fxCat[0] = LoadSound("resources/fxcat01.wav");
|
||||
fxCat[1] = LoadSound("resources/fxcat02.wav");
|
||||
fxRoomba[0] = LoadSound("resources/fxrobot01.wav");
|
||||
fxRoomba[1] = LoadSound("resources/fxrobot02.wav");
|
||||
fxRoomba[2] = LoadSound("resources/fxrobot03.wav");
|
||||
|
||||
catch = LoadMusicStream("resources/catch22.mod");
|
||||
|
||||
StopMusicStream(music);
|
||||
SetMusicVolume(catch, 0.6f);
|
||||
PlayMusicStream(catch);
|
||||
|
||||
result = 0; // Global variable: screens.h
|
||||
}
|
||||
|
||||
// Gameplay Screen Update logic
|
||||
void UpdateGameplayScreen(void)
|
||||
{
|
||||
UpdateMusicStream(catch);
|
||||
|
||||
if (showObjective)
|
||||
{
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
showObjective = false;
|
||||
PlaySound(fxCoin);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
framesCounter++;
|
||||
|
||||
if (framesCounter == 60)
|
||||
{
|
||||
timeLevelSeconds--;
|
||||
|
||||
if (timeLevelSeconds == 0)
|
||||
{
|
||||
levelFinished = true;
|
||||
finishScreen = 1;
|
||||
PlaySound(fxCoin);
|
||||
|
||||
if (GetTileCleanPercent() >= 80) result = 1;
|
||||
}
|
||||
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
mousePosition = GetMousePosition();
|
||||
mouseTileX = (int)floorf((mousePosition.x - roomOffset.x)/TILE_SIZE);
|
||||
mouseTileY = (int)floorf((mousePosition.y - roomOffset.y)/TILE_SIZE);
|
||||
|
||||
// Roomba movement logic
|
||||
Vector2 prevPosition = roombaPosition;
|
||||
|
||||
if (IsKeyDown(KEY_D)) roombaPosition.x += roombaSpeed.x;
|
||||
else if (IsKeyDown(KEY_A)) roombaPosition.x -= roombaSpeed.x;
|
||||
if (IsKeyDown(KEY_W)) roombaPosition.y -= roombaSpeed.y;
|
||||
else if (IsKeyDown(KEY_S)) roombaPosition.y += roombaSpeed.y;
|
||||
|
||||
// Verify current player position is valid or reset
|
||||
roombaTilePosX = (int)(floorf(roombaPosition.x - roomOffset.x)/TILE_SIZE);
|
||||
roombaTilePosY = (int)(floorf(roombaPosition.y - roomOffset.y)/TILE_SIZE);
|
||||
if ((roombaPosition.x - roomba.width/2 < roomOffset.x) ||
|
||||
((roombaPosition.x + roomba.width/2) >= (roomOffset.x + MAX_TILES_X*TILE_SIZE)) ||
|
||||
(roombaPosition.y - roomba.height/2 < roomOffset.y) ||
|
||||
((roombaPosition.y + roomba.height/2) >= (roomOffset.y + MAX_TILES_Y*TILE_SIZE)) ||
|
||||
(furcolmap[roombaTilePosY*MAX_TILES_X + roombaTilePosX] == 0) ||
|
||||
(furcolmap[roombaTilePosY*MAX_TILES_X + roombaTilePosX] == 3)) roombaPosition = prevPosition;
|
||||
|
||||
// Dyson movement logic
|
||||
// if (IsKeyDown(KEY_RIGHT)) dysonPosition.x += dysonSpeed.x;
|
||||
// else if (IsKeyDown(KEY_LEFT)) dysonPosition.x -= dysonSpeed.x;
|
||||
// if (IsKeyDown(KEY_UP)) dysonPosition.y -= dysonSpeed.y;
|
||||
// else if (IsKeyDown(KEY_DOWN)) dysonPosition.y += dysonSpeed.y;
|
||||
|
||||
// Check collision area between Roomba and dirt tiles to verify it's beeing cleaned
|
||||
// TODO: OPTIMIZATION: Check only Roomba surrounding tiles
|
||||
for (int y = 0; y < MAX_TILES_Y; y++)
|
||||
{
|
||||
for (int x = 0; x < MAX_TILES_X; x++)
|
||||
{
|
||||
// Check if tile requires cleaning
|
||||
if (tiles[y*MAX_TILES_X + x].state > 0)
|
||||
{
|
||||
// TODO: Get better collision area measure, considering round roomba
|
||||
Rectangle cleanRec = GetCollisionRec((Rectangle){ tiles[y*MAX_TILES_X + x].position.x, tiles[y*MAX_TILES_X + x].position.y, 36, 36 },
|
||||
(Rectangle){ roombaPosition.x - roomba.width/2, roombaPosition.y - roomba.height/2, roomba.width, roomba.height });
|
||||
|
||||
// Check Roomba is covering at least half of the tile
|
||||
if ((cleanRec.width*cleanRec.height) > TILE_REQUIRED_CLEAN_AREA)
|
||||
{
|
||||
// Start cleaning tile
|
||||
tiles[y*MAX_TILES_X + x].counter--;
|
||||
|
||||
if (tiles[y*MAX_TILES_X + x].counter < 0)
|
||||
{
|
||||
tiles[y*MAX_TILES_X + x].state--;
|
||||
|
||||
if (tiles[y*MAX_TILES_X + x].state == 0)
|
||||
{
|
||||
tiles[y*MAX_TILES_X + x].counter = 0;
|
||||
score += tiles[y*MAX_TILES_X + x].level*TILE_SCORE_BY_CLEANED_LEVEL;
|
||||
|
||||
// Show scoring popup, enable first ready!
|
||||
for (int i = 0; i < MAX_SCORE_POPUPS; i++)
|
||||
{
|
||||
if (!popup[i].enabled)
|
||||
{
|
||||
popup[i].position = tiles[y*MAX_TILES_X + x].position;
|
||||
popup[i].value = TILE_SCORE_BY_CLEANED_LEVEL*tiles[y*MAX_TILES_X + x].level;
|
||||
popup[i].enabled = true;
|
||||
popup[i].alpha = 1.0f;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else tiles[y*MAX_TILES_X + x].counter = TILE_REQUIRED_CLEAN_TIME;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update enabled popups!
|
||||
for (int i = 0; i < MAX_SCORE_POPUPS; i++)
|
||||
{
|
||||
if (popup[i].enabled)
|
||||
{
|
||||
popup[i].position.y -= 2;
|
||||
popup[i].alpha -= 0.015f;
|
||||
|
||||
if (popup[i].alpha < 0.0f) popup[i].enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Cat movement logic
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
// Check for a valid cell to move on
|
||||
if ((mousePosition.x > roomOffset.x) && (mousePosition.x < (roomOffset.x + MAX_TILES_X*TILE_SIZE)) &&
|
||||
(mousePosition.y > roomOffset.y) && (mousePosition.y < (roomOffset.y + MAX_TILES_Y*TILE_SIZE)) &&
|
||||
furcolmap[mouseTileY*MAX_TILES_X + mouseTileX] != 0)
|
||||
{
|
||||
catTargetPosition = GetMousePosition();
|
||||
catShouldMove = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) PlaySound(fxCat[GetRandomValue(0,1)]);
|
||||
if (IsKeyPressed(KEY_SPACE)) PlaySound(fxRoomba[GetRandomValue(0,2)]);
|
||||
|
||||
// Check if cat should move
|
||||
if (catShouldMove)
|
||||
{
|
||||
if (CheckCollisionPointCircle(catPosition, catTargetPosition, CAT_TARGET_RADIUS))
|
||||
{
|
||||
catShouldMove = false;
|
||||
|
||||
// Spread dirt all around selected cell!
|
||||
// NOTE: We consider cat drawing offset
|
||||
catTilePosX = (int)floorf((catPosition.x - cat.width/2 - roomOffset.x)/TILE_SIZE) + 1;
|
||||
catTilePosY = (int)floorf((catPosition.y - cat.height/2 - 10 - roomOffset.y)/TILE_SIZE) + 1;
|
||||
|
||||
// Check if tile includes a dirt element
|
||||
if (furcolmap[mouseTileY*MAX_TILES_X + mouseTileX] == 3)
|
||||
{
|
||||
for (int y = (catTilePosY - CAT_DIRT_CELL_RADIUS); y < (catTilePosY + CAT_DIRT_CELL_RADIUS + 1); y++)
|
||||
{
|
||||
for (int x = (catTilePosX - CAT_DIRT_CELL_RADIUS); x < (catTilePosX + CAT_DIRT_CELL_RADIUS + 1); x++)
|
||||
{
|
||||
if (((y >= 0) && (y < MAX_TILES_Y) && (x >= 0) && (x < MAX_TILES_X)) &&
|
||||
(tiles[y*MAX_TILES_X + x].state == 0) &&
|
||||
(furcolmap[y*MAX_TILES_X + x] != 0) &&
|
||||
(furcolmap[y*MAX_TILES_X + x] != 3))
|
||||
{
|
||||
int dirt = GetRandomValue(0, 100);
|
||||
|
||||
if (dirt < 50) tiles[y*MAX_TILES_X + x].level = 0; // 50% probability
|
||||
else if (dirt < 70) tiles[y*MAX_TILES_X + x].level = 1; // 20% probability
|
||||
else if (dirt < 90) tiles[y*MAX_TILES_X + x].level = 2; // 10% probability
|
||||
else if (dirt < 100) tiles[y*MAX_TILES_X + x].level = 3; // 10% probability
|
||||
|
||||
tiles[y*MAX_TILES_X + x].state = tiles[y*MAX_TILES_X + x].level;
|
||||
tiles[y*MAX_TILES_X + x].counter = (tiles[y*MAX_TILES_X + x].level == 0)? 0 : TILE_REQUIRED_CLEAN_TIME;
|
||||
tiles[y*MAX_TILES_X + x].cleaned = (tiles[y*MAX_TILES_X + x].level == 0)? true : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Vector2 dir = Vector2Subtract(catTargetPosition, catPosition);
|
||||
Vector2 dirnorm = Vector2Normalize(dir);
|
||||
|
||||
catPosition.x += catSpeed.x*dirnorm.x;
|
||||
catPosition.y += catSpeed.y*dirnorm.y;
|
||||
}
|
||||
}
|
||||
|
||||
if (levelFinished)
|
||||
{
|
||||
// TODO: Check level finished
|
||||
}
|
||||
}
|
||||
|
||||
// Gameplay Screen Draw logic
|
||||
void DrawGameplayScreen(void)
|
||||
{
|
||||
DrawRectangle(0, 0, GetScreenWidth(), GetScreenHeight(), GetColor(0x57374cff));
|
||||
|
||||
// Draw tiles
|
||||
for (int y = 0; y < MAX_TILES_Y; y++)
|
||||
{
|
||||
for (int x = 0; x < MAX_TILES_X; x++)
|
||||
{
|
||||
// Draw dirty tiles
|
||||
DrawTextureRec(dirtiles, (Rectangle){ tiles[y*MAX_TILES_X + x].state*TILE_SIZE, 0, TILE_SIZE, TILE_SIZE },
|
||||
(Vector2){ roomOffset.x + TILE_SIZE*x, roomOffset.y + TILE_SIZE*y }, WHITE);
|
||||
|
||||
// TODO: Draw possible walls
|
||||
}
|
||||
}
|
||||
|
||||
// Draw starting point for roomba and cat
|
||||
DrawTextureRec(furniture, (Rectangle){ furset[30].posX, furset[30].posY, furset[30].width, furset[30].height }, roomOffset, WHITE);
|
||||
DrawTextureRec(furniture, (Rectangle){ furset[29].posX, furset[29].posY, furset[29].width, furset[29].height }, (Vector2){ roomOffset.x + 29*36, roomOffset.y }, WHITE);
|
||||
|
||||
DrawTexture(roomba, roombaPosition.x - roomba.width/2, roombaPosition.y - roomba.height/2, WHITE);
|
||||
DrawTexture(cat, catPosition.x - cat.width/2, catPosition.y - cat.height/2 - 10, WHITE);
|
||||
|
||||
float furAlpha = 1.0f;
|
||||
|
||||
// Draw home objects
|
||||
for (int i = 0; i < furnitureCount; i++)
|
||||
{
|
||||
if (CheckCollisionCircleRec((Vector2){ roombaPosition.x - roomba.width/2, roombaPosition.y - roomba.height/2 }, roomba.width,
|
||||
(Rectangle){ roomOffset.x + furmap[i].cellX*TILE_SIZE, roomOffset.y + furmap[i].cellY*TILE_SIZE,
|
||||
furset[furmap[i].furId].width, furset[furmap[i].furId].height}) && (furmap[i].state == 1))
|
||||
{
|
||||
DrawTextureRec(furniture, (Rectangle){ furset[furmap[i].furId].posX, furset[furmap[i].furId].posY, furset[furmap[i].furId].width, furset[furmap[i].furId].height },
|
||||
(Vector2){ roomOffset.x + furmap[i].cellX*TILE_SIZE, roomOffset.y + furmap[i].cellY*TILE_SIZE }, Fade(WHITE, 0.5f));
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTextureRec(furniture, (Rectangle){ furset[furmap[i].furId].posX, furset[furmap[i].furId].posY, furset[furmap[i].furId].width, furset[furmap[i].furId].height },
|
||||
(Vector2){ roomOffset.x + furmap[i].cellX*TILE_SIZE, roomOffset.y + furmap[i].cellY*TILE_SIZE }, Fade(WHITE, furAlpha));
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(TILE_VIEWER_MODE)
|
||||
DrawTexture(tracemap, roomOffset.x, roomOffset.y, Fade(WHITE, 0.5f));
|
||||
DrawTexture(fursetid, 0, 720, WHITE);
|
||||
#endif
|
||||
|
||||
// TODO: If an object has been used by cat, draw it in gray
|
||||
// Maybe add a tempo bar for reusing?
|
||||
|
||||
// Draw UI
|
||||
DrawTextEx(font2, "SCORE:", (Vector2){ 80, 10 }, font2.baseSize, 2, WHITE);
|
||||
DrawTextEx(font, FormatText("%i", score), (Vector2){ 260, 10 }, font.baseSize, 2, WHITE);
|
||||
DrawTextEx(font2, "CLEAN:", (Vector2){ 500, 10 }, font2.baseSize, 2, WHITE);
|
||||
DrawTextEx(font, FormatText("%.2f%%", GetTileCleanPercent()), (Vector2){ 690, 10 }, font.baseSize, 2, WHITE);
|
||||
DrawTextEx(font2, "TIME:", (Vector2){ 950, 10 }, font2.baseSize, 2, WHITE);
|
||||
DrawTextEx(font, FormatText("%i:%02is", timeLevelSeconds/60, timeLevelSeconds%60), (Vector2){ 1100, 10 }, font.baseSize, 2, WHITE);
|
||||
|
||||
// Debug information
|
||||
//DrawText(FormatText("CatTilePos: [ %i, %i ]", catTilePosX, catTilePosY), roomOffset.x, 690, 20, RAYWHITE);
|
||||
//DrawText(FormatText("MousePos: [ %i, %i ]", mouseTileX, mouseTileY), 400, 690, 20, RED);
|
||||
//DrawText(FormatText("RoombaPos: [ %i, %i ]", roombaTilePosX, roombaTilePosY), 600, 690, 20, GREEN);
|
||||
|
||||
if ((mouseTileY >= 0) && (mouseTileY < MAX_TILES_Y) && (mouseTileX >= 0) && (mouseTileX < MAX_TILES_X))
|
||||
{
|
||||
DrawRectangleLinesEx((Rectangle){ tiles[mouseTileY*MAX_TILES_X + mouseTileX].position.x,
|
||||
tiles[mouseTileY*MAX_TILES_X + mouseTileX].position.y, TILE_SIZE, TILE_SIZE }, 2, RED);
|
||||
}
|
||||
|
||||
// Draw enabled popups!
|
||||
for (int i = 0; i < MAX_SCORE_POPUPS; i++)
|
||||
{
|
||||
if (popup[i].enabled) DrawText(FormatText("+%i", popup[i].value), popup[i].position.x, popup[i].position.y, 20, Fade(RED, popup[i].alpha));
|
||||
}
|
||||
|
||||
// Show objective
|
||||
if (showObjective)
|
||||
{
|
||||
DrawRectangle(0, 150, GetScreenWidth(), GetScreenHeight() - 300, Fade(DARKGRAY, 0.7f));
|
||||
DrawTextEx(font2, "OBJECTIVE:", (Vector2){ 500, 240 }, font2.baseSize, 2, WHITE);
|
||||
DrawTextEx(font, "CLEAN 80% OF THE ROOM", (Vector2){ 300, 320 }, font.baseSize, 2, WHITE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Gameplay Screen Unload logic
|
||||
void UnloadGameplayScreen(void)
|
||||
{
|
||||
// Unload GAMEPLAY screen variables here!
|
||||
UnloadTexture(roomba);
|
||||
UnloadTexture(cat);
|
||||
UnloadTexture(dirtiles);
|
||||
UnloadTexture(furniture);
|
||||
|
||||
UnloadSound(fxCat[0]);
|
||||
UnloadSound(fxCat[1]);
|
||||
UnloadSound(fxRoomba[0]);
|
||||
UnloadSound(fxRoomba[1]);
|
||||
UnloadSound(fxRoomba[2]);
|
||||
|
||||
StopMusicStream(catch);
|
||||
UnloadMusicStream(catch);
|
||||
}
|
||||
|
||||
// Gameplay Screen should finish?
|
||||
int FinishGameplayScreen(void)
|
||||
{
|
||||
return finishScreen;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Check how much cleaning we have done
|
||||
static float GetTileCleanPercent(void)
|
||||
{
|
||||
float value = 0;
|
||||
|
||||
int tileLevelsToClean = 0;
|
||||
int tileLevelsCleaned = 0;
|
||||
|
||||
for (int y = 0; y < MAX_TILES_Y; y++)
|
||||
{
|
||||
for (int x = 0; x < MAX_TILES_X; x++)
|
||||
{
|
||||
if (tiles[y*MAX_TILES_X + x].level > 0)
|
||||
{
|
||||
tileLevelsToClean += tiles[y*MAX_TILES_X + x].level;
|
||||
tileLevelsCleaned += tiles[y*MAX_TILES_X + x].state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
value = ((float)(tileLevelsToClean - tileLevelsCleaned)/tileLevelsToClean)*100.0f;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
@ -1,211 +0,0 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib - Advance Game template
|
||||
*
|
||||
* Logo Screen Functions Definitions (Init, Update, Draw, Unload)
|
||||
*
|
||||
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* 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 LOGO_RECS_SIDE 16
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition (local to this module)
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Logo screen global variables
|
||||
static int framesCounter = 0;
|
||||
static int finishScreen = 0;
|
||||
|
||||
static int logoPositionX = 0;
|
||||
static int logoPositionY = 0;
|
||||
|
||||
static int lettersCount = 0;
|
||||
|
||||
static int topSideRecWidth = 0;
|
||||
static int leftSideRecHeight = 0;
|
||||
|
||||
static int bottomSideRecWidth = 0;
|
||||
static int rightSideRecHeight = 0;
|
||||
|
||||
static char raylib[8] = { 0 }; // raylib text array, max 8 letters
|
||||
static int state = 0; // Tracking animation states (State Machine)
|
||||
static float alpha = 1.0f; // Useful for fading
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Logo Screen Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Logo Screen Initialization logic
|
||||
void InitLogoScreen(void)
|
||||
{
|
||||
// Initialize LOGO screen variables here!
|
||||
finishScreen = 0;
|
||||
framesCounter = 0;
|
||||
lettersCount = 0;
|
||||
|
||||
logoPositionX = GetScreenWidth()/2 - 128;
|
||||
logoPositionY = GetScreenHeight()/2 - 128;
|
||||
|
||||
topSideRecWidth = LOGO_RECS_SIDE;
|
||||
leftSideRecHeight = LOGO_RECS_SIDE;
|
||||
bottomSideRecWidth = LOGO_RECS_SIDE;
|
||||
rightSideRecHeight = LOGO_RECS_SIDE;
|
||||
|
||||
for (int i = 0; i < 8; i++) raylib[i] = '\0';
|
||||
|
||||
state = 0;
|
||||
alpha = 1.0f;
|
||||
}
|
||||
|
||||
// Logo Screen Update logic
|
||||
void UpdateLogoScreen(void)
|
||||
{
|
||||
// Update LOGO screen variables here!
|
||||
if (state == 0) // State 0: Small box blinking
|
||||
{
|
||||
framesCounter++;
|
||||
|
||||
if (framesCounter == 80)
|
||||
{
|
||||
state = 1;
|
||||
framesCounter = 0; // Reset counter... will be used later...
|
||||
}
|
||||
}
|
||||
else if (state == 1) // State 1: Top and left bars growing
|
||||
{
|
||||
topSideRecWidth += 8;
|
||||
leftSideRecHeight += 8;
|
||||
|
||||
if (topSideRecWidth == 256) state = 2;
|
||||
}
|
||||
else if (state == 2) // State 2: Bottom and right bars growing
|
||||
{
|
||||
bottomSideRecWidth += 8;
|
||||
rightSideRecHeight += 8;
|
||||
|
||||
if (bottomSideRecWidth == 256) state = 3;
|
||||
}
|
||||
else if (state == 3) // State 3: Letters appearing (one by one)
|
||||
{
|
||||
framesCounter++;
|
||||
|
||||
if (framesCounter/10) // Every 12 frames, one more letter!
|
||||
{
|
||||
lettersCount++;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
switch (lettersCount)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
// When all letters have appeared...
|
||||
if (lettersCount >= 10)
|
||||
{
|
||||
state = 4;
|
||||
framesCounter = 0;
|
||||
}
|
||||
}
|
||||
else if (state == 4)
|
||||
{
|
||||
framesCounter++;
|
||||
|
||||
if (framesCounter > 100)
|
||||
{
|
||||
alpha -= 0.02f;
|
||||
|
||||
if (alpha <= 0.0f)
|
||||
{
|
||||
alpha = 0.0f;
|
||||
finishScreen = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Logo Screen Draw logic
|
||||
void DrawLogoScreen(void)
|
||||
{
|
||||
if (state == 0)
|
||||
{
|
||||
if ((framesCounter/10)%2) DrawRectangle(logoPositionX, logoPositionY, 16, 16, BLACK);
|
||||
}
|
||||
else if (state == 1)
|
||||
{
|
||||
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
|
||||
DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
|
||||
}
|
||||
else if (state == 2)
|
||||
{
|
||||
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, BLACK);
|
||||
DrawRectangle(logoPositionX, logoPositionY, 16, leftSideRecHeight, BLACK);
|
||||
|
||||
DrawRectangle(logoPositionX + 240, logoPositionY, 16, rightSideRecHeight, BLACK);
|
||||
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, BLACK);
|
||||
}
|
||||
else if (state == 3)
|
||||
{
|
||||
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
|
||||
DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
|
||||
|
||||
DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
|
||||
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
|
||||
|
||||
DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
|
||||
|
||||
DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48, 50, Fade(BLACK, alpha));
|
||||
}
|
||||
else if (state == 4)
|
||||
{
|
||||
DrawRectangle(logoPositionX, logoPositionY, topSideRecWidth, 16, Fade(BLACK, alpha));
|
||||
DrawRectangle(logoPositionX, logoPositionY + 16, 16, leftSideRecHeight - 32, Fade(BLACK, alpha));
|
||||
|
||||
DrawRectangle(logoPositionX + 240, logoPositionY + 16, 16, rightSideRecHeight - 32, Fade(BLACK, alpha));
|
||||
DrawRectangle(logoPositionX, logoPositionY + 240, bottomSideRecWidth, 16, Fade(BLACK, alpha));
|
||||
|
||||
DrawRectangle(GetScreenWidth()/2 - 112, GetScreenHeight()/2 - 112, 224, 224, Fade(RAYWHITE, alpha));
|
||||
|
||||
DrawText(raylib, GetScreenWidth()/2 - 44, GetScreenHeight()/2 + 48, 50, Fade(BLACK, alpha));
|
||||
|
||||
if (framesCounter > 20) DrawText("powered by", logoPositionX, logoPositionY - 27, 20, Fade(DARKGRAY, alpha));
|
||||
}
|
||||
}
|
||||
|
||||
// Logo Screen Unload logic
|
||||
void UnloadLogoScreen(void)
|
||||
{
|
||||
// Unload LOGO screen variables here!
|
||||
}
|
||||
|
||||
// Logo Screen should finish?
|
||||
int FinishLogoScreen(void)
|
||||
{
|
||||
return finishScreen;
|
||||
}
|
||||
|
|
@ -1,154 +0,0 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib - Advance Game template
|
||||
*
|
||||
* Title Screen Functions Definitions (Init, Update, Draw, Unload)
|
||||
*
|
||||
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* 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)
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Title screen global variables
|
||||
static int framesCounter;
|
||||
static int finishScreen;
|
||||
static int state;
|
||||
|
||||
static int scrollPositionX;
|
||||
|
||||
static int catPosX;
|
||||
static int roombaPosX;
|
||||
|
||||
static float vsAlpha;
|
||||
static float vsScale;
|
||||
|
||||
static Texture2D cat;
|
||||
static Texture2D vs;
|
||||
static Texture2D roomba;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Title Screen Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Title Screen Initialization logic
|
||||
void InitTitleScreen(void)
|
||||
{
|
||||
// TODO: Initialize TITLE screen variables here!
|
||||
framesCounter = 0;
|
||||
finishScreen = 0;
|
||||
|
||||
cat = LoadTexture("resources/title_cat.png");
|
||||
vs = LoadTexture("resources/title_vs.png");
|
||||
roomba = LoadTexture("resources/title_roomba.png");
|
||||
|
||||
state = 0;
|
||||
catPosX = 1760;
|
||||
roombaPosX = -700;
|
||||
scrollPositionX = 0;
|
||||
|
||||
vsAlpha = 0.0f;
|
||||
vsScale = 10.0f;
|
||||
|
||||
PlayMusicStream(music);
|
||||
}
|
||||
|
||||
// Title Screen Update logic
|
||||
void UpdateTitleScreen(void)
|
||||
{
|
||||
scrollPositionX -= 5;
|
||||
if (scrollPositionX < -GetScreenWidth()) scrollPositionX = 0;
|
||||
|
||||
if (state == 0)
|
||||
{
|
||||
catPosX -= 4;
|
||||
roombaPosX += 3;
|
||||
|
||||
if (catPosX < (GetScreenWidth()/2 - cat.width/2)) catPosX = (GetScreenWidth()/2 - cat.width/2);
|
||||
if (roombaPosX > (GetScreenWidth()/2 - roomba.width/2)) roombaPosX = (GetScreenWidth()/2 - roomba.width/2);
|
||||
|
||||
if ((catPosX == (GetScreenWidth()/2 - cat.width/2)) && (roombaPosX == (GetScreenWidth()/2 - roomba.width/2)))
|
||||
{
|
||||
state = 1;
|
||||
framesCounter = 0;
|
||||
}
|
||||
}
|
||||
else if (state == 1)
|
||||
{
|
||||
framesCounter++;
|
||||
|
||||
vsScale -= 0.1f;
|
||||
vsAlpha += 0.01f;
|
||||
|
||||
if (vsScale < 1.0f) vsScale = 1.0f;
|
||||
if (vsAlpha > 1.0f) vsAlpha = 1.0f;
|
||||
|
||||
if (framesCounter > 160)
|
||||
{
|
||||
state = 2;
|
||||
framesCounter = 0;
|
||||
}
|
||||
}
|
||||
else if (state == 2) framesCounter++;
|
||||
|
||||
// Press enter or tap to change to GAMEPLAY screen
|
||||
if (IsKeyPressed(KEY_ENTER) || IsGestureDetected(GESTURE_TAP))
|
||||
{
|
||||
//finishScreen = 1; // OPTIONS
|
||||
finishScreen = 2; // GAMEPLAY
|
||||
PlaySound(fxCoin);
|
||||
}
|
||||
}
|
||||
|
||||
// Title Screen Draw logic
|
||||
void DrawTitleScreen(void)
|
||||
{
|
||||
for (int i = 0; i < 64*2*2; i++)
|
||||
{
|
||||
DrawRectangle(64*i + scrollPositionX, 0, 64, GetScreenHeight(), (i%2 == 0)? GetColor(0xf3726dff) : GetColor(0xffcf6bff));
|
||||
}
|
||||
|
||||
DrawTexture(cat, catPosX, 80, WHITE);
|
||||
DrawTexture(roomba, roombaPosX, 320, WHITE);
|
||||
|
||||
if (state > 0)
|
||||
{
|
||||
DrawTexturePro(vs, (Rectangle){ 0, 0, vs.width, vs.height }, (Rectangle){ GetScreenWidth()/2, 300, vs.width*vsScale, vs.height*vsScale }, (Vector2){ vs.width/2*vsScale, vs.height/2*vsScale }, 0.0f, Fade(WHITE, vsAlpha));
|
||||
}
|
||||
|
||||
if ((state == 2) && ((framesCounter/30)%2)) DrawTextEx(font2, "PRESS ENTER to START", (Vector2){ 340, 550 }, font2.baseSize, 2, WHITE);
|
||||
}
|
||||
|
||||
// Title Screen Unload logic
|
||||
void UnloadTitleScreen(void)
|
||||
{
|
||||
UnloadTexture(cat);
|
||||
UnloadTexture(vs);
|
||||
UnloadTexture(roomba);
|
||||
}
|
||||
|
||||
// Title Screen should finish?
|
||||
int FinishTitleScreen(void)
|
||||
{
|
||||
return finishScreen;
|
||||
}
|
||||
|
|
@ -1,92 +0,0 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib - Advance Game template
|
||||
*
|
||||
* Screens Functions Declarations (Init, Update, Draw, Unload)
|
||||
*
|
||||
* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* 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
|
||||
|
||||
//#define TILE_VIEWER_MODE
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
typedef enum GameScreen { LOGO = 0, TITLE, OPTIONS, GAMEPLAY, ENDING } GameScreen;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
extern GameScreen currentScreen;
|
||||
extern Font font;
|
||||
extern Font font2;
|
||||
extern Music music;
|
||||
extern Sound fxCoin;
|
||||
|
||||
int score;
|
||||
int result; // 0-Loose, 1-Win
|
||||
|
||||
#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);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Title Screen Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
void InitTitleScreen(void);
|
||||
void UpdateTitleScreen(void);
|
||||
void DrawTitleScreen(void);
|
||||
void UnloadTitleScreen(void);
|
||||
int FinishTitleScreen(void);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Gameplay Screen Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
void InitGameplayScreen(void);
|
||||
void UpdateGameplayScreen(void);
|
||||
void DrawGameplayScreen(void);
|
||||
void UnloadGameplayScreen(void);
|
||||
int FinishGameplayScreen(void);
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Ending Screen Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
void InitEndingScreen(void);
|
||||
void UpdateEndingScreen(void);
|
||||
void DrawEndingScreen(void);
|
||||
void UnloadEndingScreen(void);
|
||||
int FinishEndingScreen(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SCREENS_H
|
||||
|
|
@ -1,126 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib game - Dr. Turtle & Mr. Gamera
|
||||
*
|
||||
* 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)
|
||||
* 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_ENEMIES 10
|
||||
|
||||
typedef enum { TITLE, GAMEPLAY, ENDING } GameScreen;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 1280;
|
||||
const int screenHeight = 720;
|
||||
|
||||
// Init window
|
||||
InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA");
|
||||
|
||||
// Define current screen
|
||||
GameScreen currentScreen = TITLE;
|
||||
|
||||
SetTargetFPS(60); // Setup game frames per second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Game screens management
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Press enter to change to gameplay screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
}
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Press enter to change to ending screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = ENDING;
|
||||
}
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Press enter to change to title screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = TITLE;
|
||||
}
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Draw title screen
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, GREEN);
|
||||
DrawText("TITLE SCREEN", 20, 20, 40, DARKGREEN);
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Draw gameplay screen
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, RED);
|
||||
DrawText("GAMEPLAY SCREEN", 20, 20, 40, MAROON);
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Draw ending screen
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, BLUE);
|
||||
DrawText("ENDING SCREEN", 20, 20, 40, DARKBLUE);
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib game - Dr. Turtle & Mr. Gamera
|
||||
*
|
||||
* 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)
|
||||
* 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_ENEMIES 10
|
||||
|
||||
typedef enum { TITLE, GAMEPLAY, ENDING } GameScreen;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 1280;
|
||||
const int screenHeight = 720;
|
||||
|
||||
// Init window
|
||||
InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA");
|
||||
|
||||
// Load game resources: textures
|
||||
Texture2D sky = LoadTexture("resources/sky.png");
|
||||
Texture2D mountains = LoadTexture("resources/mountains.png");
|
||||
Texture2D sea = LoadTexture("resources/sea.png");
|
||||
|
||||
// Define scrolling variables
|
||||
int backScrolling = 0;
|
||||
int seaScrolling = 0;
|
||||
|
||||
// Define current screen
|
||||
GameScreen currentScreen = TITLE;
|
||||
|
||||
SetTargetFPS(60); // Setup game frames per second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Game screens management
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Sea scrolling
|
||||
seaScrolling -= 2;
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Press enter to change to gameplay screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
}
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Background scrolling logic
|
||||
backScrolling--;
|
||||
if (backScrolling <= -screenWidth) backScrolling = 0;
|
||||
|
||||
// Sea scrolling logic
|
||||
seaScrolling -= 8;
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Press enter to change to ending screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = ENDING;
|
||||
}
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Press enter to change to title screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = TITLE;
|
||||
}
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Draw background (common to all screens)
|
||||
DrawTexture(sky, 0, 0, WHITE);
|
||||
|
||||
DrawTexture(mountains, backScrolling, 0, WHITE);
|
||||
DrawTexture(mountains, screenWidth + backScrolling, 0, WHITE);
|
||||
|
||||
DrawTexture(sea, seaScrolling, 0, BLUE);
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, BLUE);
|
||||
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Draw title screen
|
||||
DrawText("PRESS ENTER", 450, 420, 40, BLACK);
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Draw gameplay screen
|
||||
DrawText("GAMEPLAY SCREEN", 20, 20, 40, MAROON);
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Draw ending screen
|
||||
|
||||
// Draw a transparent black rectangle that covers all screen
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, Fade(BLACK, 0.4f));
|
||||
|
||||
DrawText("ENDING SCREEN", 20, 20, 40, DARKBLUE);
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Unload textures
|
||||
UnloadTexture(sky);
|
||||
UnloadTexture(mountains);
|
||||
UnloadTexture(sea);
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,212 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib game - Dr. Turtle & Mr. Gamera
|
||||
*
|
||||
* 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)
|
||||
* 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_ENEMIES 10
|
||||
|
||||
typedef enum { TITLE, GAMEPLAY, ENDING } GameScreen;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 1280;
|
||||
const int screenHeight = 720;
|
||||
|
||||
// Init window
|
||||
InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA");
|
||||
|
||||
// Load game resources: textures
|
||||
Texture2D sky = LoadTexture("resources/sky.png");
|
||||
Texture2D mountains = LoadTexture("resources/mountains.png");
|
||||
Texture2D sea = LoadTexture("resources/sea.png");
|
||||
Texture2D title = LoadTexture("resources/title.png");
|
||||
Texture2D turtle = LoadTexture("resources/turtle.png");
|
||||
Texture2D gamera = LoadTexture("resources/gamera.png");
|
||||
|
||||
// Define scrolling variables
|
||||
int backScrolling = 0;
|
||||
int seaScrolling = 0;
|
||||
|
||||
// Define current screen
|
||||
GameScreen currentScreen = TITLE;
|
||||
|
||||
// Define player variables
|
||||
int playerRail = 1;
|
||||
Rectangle playerBounds = { 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
bool gameraMode = false;
|
||||
|
||||
// Define additional game variables
|
||||
int framesCounter = 0;
|
||||
|
||||
SetTargetFPS(60); // Setup game frames per second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
framesCounter++;
|
||||
|
||||
// Game screens management
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Sea scrolling
|
||||
seaScrolling -= 2;
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Press enter to change to gameplay screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Background scrolling logic
|
||||
backScrolling--;
|
||||
if (backScrolling <= -screenWidth) backScrolling = 0;
|
||||
|
||||
// Sea scrolling logic
|
||||
seaScrolling -= 8;
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Player movement logic
|
||||
if (IsKeyPressed(KEY_DOWN)) playerRail++;
|
||||
else if (IsKeyPressed(KEY_UP)) playerRail--;
|
||||
|
||||
// Check player not out of rails
|
||||
if (playerRail > 4) playerRail = 4;
|
||||
else if (playerRail < 0) playerRail = 0;
|
||||
|
||||
// Update player bounds
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
|
||||
if (IsKeyPressed(KEY_SPACE)) gameraMode = !gameraMode;
|
||||
if (IsKeyPressed(KEY_ENTER)) currentScreen = ENDING;
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Press enter to play again
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
|
||||
// Reset player
|
||||
playerRail = 1;
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
|
||||
gameraMode = false;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Draw background (common to all screens)
|
||||
DrawTexture(sky, 0, 0, WHITE);
|
||||
|
||||
DrawTexture(mountains, backScrolling, 0, WHITE);
|
||||
DrawTexture(mountains, screenWidth + backScrolling, 0, WHITE);
|
||||
|
||||
if (!gameraMode)
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, BLUE);
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, BLUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, RED);
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, RED);
|
||||
}
|
||||
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Draw title
|
||||
//DrawTexture(title, screenWidth/2 - title.width/2, screenHeight/2 - title.height/2 - 80, WHITE);
|
||||
DrawRectangle(380, 140, 500, 300, GRAY);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawText("PRESS ENTER", 480, 480, 40, BLACK);
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Draw player
|
||||
//if (!gameraMode) DrawTexture(turtle, playerBounds.x - 14, playerBounds.y - 14, WHITE);
|
||||
//else DrawTexture(gamera, playerBounds.x - 64, playerBounds.y - 64, WHITE);
|
||||
|
||||
// Draw player bounding box
|
||||
if (!gameraMode) DrawRectangleRec(playerBounds, GREEN);
|
||||
else DrawRectangleRec(playerBounds, ORANGE);
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Draw a transparent black rectangle that covers all screen
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, Fade(BLACK, 0.4f));
|
||||
|
||||
DrawText("GAME OVER", 300, 200, 100, MAROON);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawText("PRESS ENTER to REPLAY", 400, 420, 30, LIGHTGRAY);
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Unload textures
|
||||
UnloadTexture(sky);
|
||||
UnloadTexture(mountains);
|
||||
UnloadTexture(sea);
|
||||
UnloadTexture(title);
|
||||
UnloadTexture(turtle);
|
||||
UnloadTexture(gamera);
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,393 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib game - Dr. Turtle & Mr. Gamera
|
||||
*
|
||||
* 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)
|
||||
* 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_ENEMIES 10
|
||||
|
||||
typedef enum { TITLE, GAMEPLAY, ENDING } GameScreen;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 1280;
|
||||
const int screenHeight = 720;
|
||||
|
||||
// Init window
|
||||
InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA");
|
||||
|
||||
// Load game resources: textures
|
||||
Texture2D sky = LoadTexture("resources/sky.png");
|
||||
Texture2D mountains = LoadTexture("resources/mountains.png");
|
||||
Texture2D sea = LoadTexture("resources/sea.png");
|
||||
Texture2D title = LoadTexture("resources/title.png");
|
||||
Texture2D turtle = LoadTexture("resources/turtle.png");
|
||||
Texture2D gamera = LoadTexture("resources/gamera.png");
|
||||
Texture2D shark = LoadTexture("resources/shark.png");
|
||||
Texture2D orca = LoadTexture("resources/orca.png");
|
||||
Texture2D swhale = LoadTexture("resources/swhale.png");
|
||||
Texture2D fish = LoadTexture("resources/fish.png");
|
||||
|
||||
// Define scrolling variables
|
||||
int backScrolling = 0;
|
||||
int seaScrolling = 0;
|
||||
|
||||
// Define current screen
|
||||
GameScreen currentScreen = TITLE;
|
||||
|
||||
// Define player variables
|
||||
int playerRail = 1;
|
||||
Rectangle playerBounds = { 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
bool gameraMode = false;
|
||||
|
||||
// Define enemies variables
|
||||
Rectangle enemyBounds[MAX_ENEMIES];
|
||||
int enemyRail[MAX_ENEMIES];
|
||||
int enemyType[MAX_ENEMIES];
|
||||
bool enemyActive[MAX_ENEMIES];
|
||||
float enemySpeed = 10;
|
||||
|
||||
// Init enemies variables
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
// Define enemy type (all same probability)
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
|
||||
// Define enemy rail
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Define enemy bounding box
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
|
||||
// Define additional game variables
|
||||
int foodBar = 0;
|
||||
int framesCounter = 0;
|
||||
|
||||
SetTargetFPS(60); // Setup game frames per second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
framesCounter++;
|
||||
|
||||
// Game screens management
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Sea scrolling
|
||||
seaScrolling -= 2;
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Press enter to change to gameplay screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Background scrolling logic
|
||||
backScrolling--;
|
||||
if (backScrolling <= -screenWidth) backScrolling = 0;
|
||||
|
||||
// Sea scrolling logic
|
||||
seaScrolling -= (enemySpeed - 2);
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Player movement logic
|
||||
if (IsKeyPressed(KEY_DOWN)) playerRail++;
|
||||
else if (IsKeyPressed(KEY_UP)) playerRail--;
|
||||
|
||||
// Check player not out of rails
|
||||
if (playerRail > 4) playerRail = 4;
|
||||
else if (playerRail < 0) playerRail = 0;
|
||||
|
||||
// Update player bounds
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
|
||||
// Enemies activation logic (every 40 frames)
|
||||
if (framesCounter > 40)
|
||||
{
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i] == false)
|
||||
{
|
||||
enemyActive[i] = true;
|
||||
i = MAX_ENEMIES;
|
||||
}
|
||||
}
|
||||
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
// Enemies logic
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
enemyBounds[i].x -= enemySpeed;
|
||||
}
|
||||
|
||||
// Check enemies out of screen
|
||||
if (enemyBounds[i].x <= 0 - 128)
|
||||
{
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Enemies speed increase every frame
|
||||
if (!gameraMode) enemySpeed += 0.005;
|
||||
|
||||
// Check collision player vs enemies
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
if (CheckCollisionRecs(playerBounds, enemyBounds[i]))
|
||||
{
|
||||
if (enemyType[i] < 3) // Bad enemies
|
||||
{
|
||||
if (gameraMode)
|
||||
{
|
||||
foodBar += 15;
|
||||
|
||||
// After enemy deactivation, reset enemy parameters to be reused
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Player die logic
|
||||
currentScreen = ENDING;
|
||||
framesCounter = 0;
|
||||
}
|
||||
}
|
||||
else // Sweet fish
|
||||
{
|
||||
enemyActive[i] = false;
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
|
||||
if (!gameraMode) foodBar += 80;
|
||||
else foodBar += 25;
|
||||
|
||||
if (foodBar == 400)
|
||||
{
|
||||
gameraMode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gamera mode logic
|
||||
if (gameraMode)
|
||||
{
|
||||
foodBar--;
|
||||
|
||||
if (foodBar <= 0)
|
||||
{
|
||||
gameraMode = false;
|
||||
enemySpeed -= 2;
|
||||
if (enemySpeed < 10) enemySpeed = 10;
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Press enter to play again
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
|
||||
// Reset player
|
||||
playerRail = 1;
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
gameraMode = false;
|
||||
|
||||
// Reset enemies data
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
|
||||
enemySpeed = 10;
|
||||
|
||||
// Reset game variables
|
||||
foodBar = 0;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Draw background (common to all screens)
|
||||
DrawTexture(sky, 0, 0, WHITE);
|
||||
|
||||
DrawTexture(mountains, backScrolling, 0, WHITE);
|
||||
DrawTexture(mountains, screenWidth + backScrolling, 0, WHITE);
|
||||
|
||||
if (!gameraMode)
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, BLUE);
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, BLUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, RED);
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, RED);
|
||||
}
|
||||
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Draw title
|
||||
DrawTexture(title, screenWidth/2 - title.width/2, screenHeight/2 - title.height/2 - 80, WHITE);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawText("PRESS ENTER", 480, 480, 40, BLACK);
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Draw water lines
|
||||
for (int i = 0; i < 5; i++) DrawRectangle(0, i*120 + 120, screenWidth, 110, Fade(SKYBLUE, 0.1f));
|
||||
|
||||
// Draw player
|
||||
if (!gameraMode) DrawTexture(turtle, playerBounds.x - 14, playerBounds.y - 14, WHITE);
|
||||
else DrawTexture(gamera, playerBounds.x - 64, playerBounds.y - 64, WHITE);
|
||||
|
||||
// Draw player bounding box
|
||||
//if (!gameraMode) DrawRectangleRec(playerBounds, Fade(GREEN, 0.4f));
|
||||
//else DrawRectangleRec(playerBounds, Fade(ORANGE, 0.4f));
|
||||
|
||||
// Draw enemies
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
// Draw enemies
|
||||
/*
|
||||
switch(enemyType[i])
|
||||
{
|
||||
case 0: DrawTexture(shark, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 1: DrawTexture(orca, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 2: DrawTexture(swhale, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 3: DrawTexture(fish, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
default: break;
|
||||
}
|
||||
*/
|
||||
|
||||
// Draw enemies bounding boxes
|
||||
switch(enemyType[i])
|
||||
{
|
||||
case 0: DrawRectangleRec(enemyBounds[i], RED); break;
|
||||
case 1: DrawRectangleRec(enemyBounds[i], RED); break;
|
||||
case 2: DrawRectangleRec(enemyBounds[i], RED); break;
|
||||
case 3: DrawRectangleRec(enemyBounds[i], GREEN); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw gameplay interface
|
||||
|
||||
// Draw food bar
|
||||
DrawRectangle(20, 20, 400, 40, Fade(GRAY, 0.4f));
|
||||
DrawRectangle(20, 20, foodBar, 40, ORANGE);
|
||||
DrawRectangleLines(20, 20, 400, 40, BLACK);
|
||||
|
||||
if (gameraMode)
|
||||
{
|
||||
DrawText("GAMERA MODE", 60, 22, 40, GRAY);
|
||||
}
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Draw a transparent black rectangle that covers all screen
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, Fade(BLACK, 0.4f));
|
||||
|
||||
DrawText("GAME OVER", 300, 200, 100, MAROON);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawText("PRESS ENTER to REPLAY", 400, 420, 30, LIGHTGRAY);
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Unload textures
|
||||
UnloadTexture(sky);
|
||||
UnloadTexture(mountains);
|
||||
UnloadTexture(sea);
|
||||
UnloadTexture(title);
|
||||
UnloadTexture(turtle);
|
||||
UnloadTexture(gamera);
|
||||
UnloadTexture(shark);
|
||||
UnloadTexture(orca);
|
||||
UnloadTexture(swhale);
|
||||
UnloadTexture(fish);
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,447 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib game - Dr. Turtle & Mr. Gamera
|
||||
*
|
||||
* 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)
|
||||
* 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_ENEMIES 10
|
||||
|
||||
typedef enum { TITLE, GAMEPLAY, ENDING } GameScreen;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 1280;
|
||||
const int screenHeight = 720;
|
||||
|
||||
// Init window
|
||||
InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA");
|
||||
|
||||
// Load game resources: textures
|
||||
Texture2D sky = LoadTexture("resources/sky.png");
|
||||
Texture2D mountains = LoadTexture("resources/mountains.png");
|
||||
Texture2D sea = LoadTexture("resources/sea.png");
|
||||
Texture2D title = LoadTexture("resources/title.png");
|
||||
Texture2D turtle = LoadTexture("resources/turtle.png");
|
||||
Texture2D gamera = LoadTexture("resources/gamera.png");
|
||||
Texture2D shark = LoadTexture("resources/shark.png");
|
||||
Texture2D orca = LoadTexture("resources/orca.png");
|
||||
Texture2D swhale = LoadTexture("resources/swhale.png");
|
||||
Texture2D fish = LoadTexture("resources/fish.png");
|
||||
Texture2D gframe = LoadTexture("resources/gframe.png");
|
||||
|
||||
// Load game resources: fonts
|
||||
Font font = LoadFont("resources/komika.png");
|
||||
|
||||
// Define scrolling variables
|
||||
int backScrolling = 0;
|
||||
int seaScrolling = 0;
|
||||
|
||||
// Define current screen
|
||||
GameScreen currentScreen = TITLE;
|
||||
|
||||
// Define player variables
|
||||
int playerRail = 1;
|
||||
Rectangle playerBounds = { 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
bool gameraMode = false;
|
||||
|
||||
// Define enemies variables
|
||||
Rectangle enemyBounds[MAX_ENEMIES];
|
||||
int enemyRail[MAX_ENEMIES];
|
||||
int enemyType[MAX_ENEMIES];
|
||||
bool enemyActive[MAX_ENEMIES];
|
||||
float enemySpeed = 10;
|
||||
|
||||
// Init enemies variables
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
// Define enemy type (all same probability)
|
||||
//enemyType[i] = GetRandomValue(0, 3);
|
||||
|
||||
// Probability system for enemies type
|
||||
int enemyProb = GetRandomValue(0, 100);
|
||||
|
||||
if (enemyProb < 30) enemyType[i] = 0;
|
||||
else if (enemyProb < 60) enemyType[i] = 1;
|
||||
else if (enemyProb < 90) enemyType[i] = 2;
|
||||
else enemyType[i] = 3;
|
||||
|
||||
// Define enemy rail
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
|
||||
// Define additional game variables
|
||||
int score = 0;
|
||||
float distance = 0.0f;
|
||||
int hiscore = 0;
|
||||
float hidistance = 0.0f;
|
||||
int foodBar = 0;
|
||||
int framesCounter = 0;
|
||||
|
||||
SetTargetFPS(60); // Setup game frames per second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
framesCounter++;
|
||||
|
||||
// Game screens management
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Sea scrolling
|
||||
seaScrolling -= 2;
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Press enter to change to gameplay screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Background scrolling logic
|
||||
backScrolling--;
|
||||
if (backScrolling <= -screenWidth) backScrolling = 0;
|
||||
|
||||
// Sea scrolling logic
|
||||
seaScrolling -= (enemySpeed - 2);
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Player movement logic
|
||||
if (IsKeyPressed(KEY_DOWN)) playerRail++;
|
||||
else if (IsKeyPressed(KEY_UP)) playerRail--;
|
||||
|
||||
// Check player not out of rails
|
||||
if (playerRail > 4) playerRail = 4;
|
||||
else if (playerRail < 0) playerRail = 0;
|
||||
|
||||
// Update player bounds
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
|
||||
// Enemies activation logic (every 40 frames)
|
||||
if (framesCounter > 40)
|
||||
{
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i] == false)
|
||||
{
|
||||
enemyActive[i] = true;
|
||||
i = MAX_ENEMIES;
|
||||
}
|
||||
}
|
||||
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
// Enemies logic
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
enemyBounds[i].x -= enemySpeed;
|
||||
}
|
||||
|
||||
// Check enemies out of screen
|
||||
if (enemyBounds[i].x <= 0 - 128)
|
||||
{
|
||||
enemyActive[i] = false;
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
}
|
||||
}
|
||||
|
||||
if (!gameraMode) enemySpeed += 0.005;
|
||||
|
||||
// Check collision player vs enemies
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
if (CheckCollisionRecs(playerBounds, enemyBounds[i]))
|
||||
{
|
||||
if (enemyType[i] < 3) // Bad enemies
|
||||
{
|
||||
if (gameraMode)
|
||||
{
|
||||
if (enemyType[i] == 0) score += 50;
|
||||
else if (enemyType[i] == 1) score += 150;
|
||||
else if (enemyType[i] == 2) score += 300;
|
||||
|
||||
foodBar += 15;
|
||||
|
||||
enemyActive[i] = false;
|
||||
|
||||
// After enemy deactivation, reset enemy parameters to be reused
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
}
|
||||
else
|
||||
{
|
||||
// Player die logic
|
||||
currentScreen = ENDING;
|
||||
framesCounter = 0;
|
||||
|
||||
// Save hiscore and hidistance for next game
|
||||
if (score > hiscore) hiscore = score;
|
||||
if (distance > hidistance) hidistance = distance;
|
||||
}
|
||||
}
|
||||
else // Sweet fish
|
||||
{
|
||||
enemyActive[i] = false;
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
|
||||
if (!gameraMode) foodBar += 80;
|
||||
else foodBar += 25;
|
||||
|
||||
score += 10;
|
||||
|
||||
if (foodBar == 400)
|
||||
{
|
||||
gameraMode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gamera mode logic
|
||||
if (gameraMode)
|
||||
{
|
||||
foodBar--;
|
||||
|
||||
if (foodBar <= 0)
|
||||
{
|
||||
gameraMode = false;
|
||||
enemySpeed -= 2;
|
||||
if (enemySpeed < 10) enemySpeed = 10;
|
||||
}
|
||||
}
|
||||
|
||||
// Update distance counter
|
||||
distance += 0.5f;
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Press enter to play again
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
|
||||
// Reset player
|
||||
playerRail = 1;
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
gameraMode = false;
|
||||
|
||||
// Reset enemies data
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
int enemyProb = GetRandomValue(0, 100);
|
||||
|
||||
if (enemyProb < 30) enemyType[i] = 0;
|
||||
else if (enemyProb < 60) enemyType[i] = 1;
|
||||
else if (enemyProb < 90) enemyType[i] = 2;
|
||||
else enemyType[i] = 3;
|
||||
|
||||
//enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
|
||||
enemySpeed = 10;
|
||||
|
||||
// Reset game variables
|
||||
score = 0;
|
||||
distance = 0.0;
|
||||
foodBar = 0;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Draw background (common to all screens)
|
||||
DrawTexture(sky, 0, 0, WHITE);
|
||||
|
||||
DrawTexture(mountains, backScrolling, 0, WHITE);
|
||||
DrawTexture(mountains, screenWidth + backScrolling, 0, WHITE);
|
||||
|
||||
if (!gameraMode)
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, (Color){ 16, 189, 227, 255});
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 16, 189, 227, 255});
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, (Color){ 255, 113, 66, 255});
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 255, 113, 66, 255});
|
||||
}
|
||||
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Draw title
|
||||
DrawTexture(title, screenWidth/2 - title.width/2, screenHeight/2 - title.height/2 - 80, WHITE);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER", (Vector2){ screenWidth/2 - 150, 480 }, font.baseSize, 0, WHITE);
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Draw water lines
|
||||
for (int i = 0; i < 5; i++) DrawRectangle(0, i*120 + 120, screenWidth, 110, Fade(SKYBLUE, 0.1f));
|
||||
|
||||
// Draw player
|
||||
if (!gameraMode) DrawTexture(turtle, playerBounds.x - 14, playerBounds.y - 14, WHITE);
|
||||
else DrawTexture(gamera, playerBounds.x - 64, playerBounds.y - 64, WHITE);
|
||||
|
||||
// Draw player bounding box
|
||||
//if (!gameraMode) DrawRectangleRec(playerBounds, Fade(GREEN, 0.4f));
|
||||
//else DrawRectangleRec(playerBounds, Fade(ORANGE, 0.4f));
|
||||
|
||||
// Draw enemies
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
// Draw enemies
|
||||
switch(enemyType[i])
|
||||
{
|
||||
case 0: DrawTexture(shark, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 1: DrawTexture(orca, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 2: DrawTexture(swhale, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 3: DrawTexture(fish, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Draw enemies bounding boxes
|
||||
/*
|
||||
switch(enemyType[i])
|
||||
{
|
||||
case 0: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 1: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 2: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 3: DrawRectangleRec(enemyBounds[i], Fade(GREEN, 0.5f)); break;
|
||||
default: break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// Draw gameplay interface
|
||||
DrawRectangle(20, 20, 400, 40, Fade(GRAY, 0.4f));
|
||||
DrawRectangle(20, 20, foodBar, 40, ORANGE);
|
||||
DrawRectangleLines(20, 20, 400, 40, BLACK);
|
||||
|
||||
DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ screenWidth - 300, 20 }, font.baseSize, -2, ORANGE);
|
||||
DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 550, 20 }, font.baseSize, -2, ORANGE);
|
||||
|
||||
if (gameraMode)
|
||||
{
|
||||
DrawText("GAMERA MODE", 60, 22, 40, GRAY);
|
||||
DrawTexture(gframe, 0, 0, Fade(WHITE, 0.5f));
|
||||
}
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Draw a transparent black rectangle that covers all screen
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, Fade(BLACK, 0.4f));
|
||||
|
||||
DrawTextEx(font, "GAME OVER", (Vector2){ 300, 160 }, font.baseSize*3, -2, MAROON);
|
||||
|
||||
DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ 680, 350 }, font.baseSize, -2, GOLD);
|
||||
DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 290, 350 }, font.baseSize, -2, GOLD);
|
||||
DrawTextEx(font, FormatText("HISCORE: %04i", hiscore), (Vector2){ 665, 400 }, font.baseSize, -2, ORANGE);
|
||||
DrawTextEx(font, FormatText("HIDISTANCE: %04i", (int)hidistance), (Vector2){ 270, 400 }, font.baseSize, -2, ORANGE);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER to REPLAY", (Vector2){ screenWidth/2 - 250, 520 }, font.baseSize, -2, LIGHTGRAY);
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Unload textures
|
||||
UnloadTexture(sky);
|
||||
UnloadTexture(mountains);
|
||||
UnloadTexture(sea);
|
||||
UnloadTexture(gframe);
|
||||
UnloadTexture(title);
|
||||
UnloadTexture(turtle);
|
||||
UnloadTexture(shark);
|
||||
UnloadTexture(orca);
|
||||
UnloadTexture(swhale);
|
||||
UnloadTexture(fish);
|
||||
UnloadTexture(gamera);
|
||||
|
||||
// Unload font texture
|
||||
UnloadFont(font);
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,471 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib game - Dr. Turtle & Mr. Gamera
|
||||
*
|
||||
* 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.6 (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_ENEMIES 10
|
||||
|
||||
typedef enum { TITLE, GAMEPLAY, ENDING } GameScreen;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 1280;
|
||||
const int screenHeight = 720;
|
||||
|
||||
// Init window
|
||||
InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA");
|
||||
|
||||
// Initialize audio device
|
||||
InitAudioDevice();
|
||||
|
||||
// Load game resources: textures
|
||||
Texture2D sky = LoadTexture("resources/sky.png");
|
||||
Texture2D mountains = LoadTexture("resources/mountains.png");
|
||||
Texture2D sea = LoadTexture("resources/sea.png");
|
||||
Texture2D title = LoadTexture("resources/title.png");
|
||||
Texture2D turtle = LoadTexture("resources/turtle.png");
|
||||
Texture2D shark = LoadTexture("resources/shark.png");
|
||||
Texture2D orca = LoadTexture("resources/orca.png");
|
||||
Texture2D swhale = LoadTexture("resources/swhale.png");
|
||||
Texture2D fish = LoadTexture("resources/fish.png");
|
||||
Texture2D gamera = LoadTexture("resources/gamera.png");
|
||||
Texture2D gframe = LoadTexture("resources/gframe.png");
|
||||
|
||||
// Load game resources: fonts
|
||||
Font font = LoadFont("resources/komika.png");
|
||||
|
||||
// Load game resources: sounds
|
||||
Sound eat = LoadSound("resources/eat.wav");
|
||||
Sound die = LoadSound("resources/die.wav");
|
||||
Sound growl = LoadSound("resources/gamera.wav");
|
||||
|
||||
// Load music stream and start playing music
|
||||
Music music = LoadMusicStream("resources/speeding.ogg");
|
||||
PlayMusicStream(music);
|
||||
|
||||
// Define scrolling variables
|
||||
int backScrolling = 0;
|
||||
int seaScrolling = 0;
|
||||
|
||||
// Define current screen
|
||||
GameScreen currentScreen = TITLE;
|
||||
|
||||
// Define player variables
|
||||
int playerRail = 1;
|
||||
Rectangle playerBounds = { 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
bool gameraMode = false;
|
||||
|
||||
// Define enemies variables
|
||||
Rectangle enemyBounds[MAX_ENEMIES];
|
||||
int enemyRail[MAX_ENEMIES];
|
||||
int enemyType[MAX_ENEMIES];
|
||||
bool enemyActive[MAX_ENEMIES];
|
||||
float enemySpeed = 10;
|
||||
|
||||
// Init enemies variables
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
// Define enemy type (all same probability)
|
||||
//enemyType[i] = GetRandomValue(0, 3);
|
||||
|
||||
// Probability system for enemies type
|
||||
int enemyProb = GetRandomValue(0, 100);
|
||||
|
||||
if (enemyProb < 30) enemyType[i] = 0;
|
||||
else if (enemyProb < 60) enemyType[i] = 1;
|
||||
else if (enemyProb < 90) enemyType[i] = 2;
|
||||
else enemyType[i] = 3;
|
||||
|
||||
// Define enemy rail
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
|
||||
// Define additional game variables
|
||||
int score = 0;
|
||||
float distance = 0.0f;
|
||||
int hiscore = 0;
|
||||
float hidistance = 0.0f;
|
||||
int foodBar = 0;
|
||||
int framesCounter = 0;
|
||||
|
||||
SetTargetFPS(60); // Setup game frames per second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateMusicStream(music); // Refill music stream buffers (if required)
|
||||
|
||||
framesCounter++;
|
||||
|
||||
// Game screens management
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Sea scrolling
|
||||
seaScrolling -= 2;
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Press enter to change to gameplay screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Background scrolling logic
|
||||
backScrolling--;
|
||||
if (backScrolling <= -screenWidth) backScrolling = 0;
|
||||
|
||||
// Sea scrolling logic
|
||||
seaScrolling -= (enemySpeed - 2);
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Player movement logic
|
||||
if (IsKeyPressed(KEY_DOWN)) playerRail++;
|
||||
else if (IsKeyPressed(KEY_UP)) playerRail--;
|
||||
|
||||
// Check player not out of rails
|
||||
if (playerRail > 4) playerRail = 4;
|
||||
else if (playerRail < 0) playerRail = 0;
|
||||
|
||||
// Update player bounds
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
|
||||
// Enemies activation logic (every 40 frames)
|
||||
if (framesCounter > 40)
|
||||
{
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i] == false)
|
||||
{
|
||||
enemyActive[i] = true;
|
||||
i = MAX_ENEMIES;
|
||||
}
|
||||
}
|
||||
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
// Enemies logic
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
enemyBounds[i].x -= enemySpeed;
|
||||
}
|
||||
|
||||
// Check enemies out of screen
|
||||
if (enemyBounds[i].x <= 0 - 128)
|
||||
{
|
||||
enemyActive[i] = false;
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
}
|
||||
}
|
||||
|
||||
if (!gameraMode) enemySpeed += 0.005;
|
||||
|
||||
// Check collision player vs enemies
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
if (CheckCollisionRecs(playerBounds, enemyBounds[i]))
|
||||
{
|
||||
if (enemyType[i] < 3) // Bad enemies
|
||||
{
|
||||
if (gameraMode)
|
||||
{
|
||||
if (enemyType[i] == 0) score += 50;
|
||||
else if (enemyType[i] == 1) score += 150;
|
||||
else if (enemyType[i] == 2) score += 300;
|
||||
|
||||
foodBar += 15;
|
||||
|
||||
enemyActive[i] = false;
|
||||
|
||||
// After enemy deactivation, reset enemy parameters to be reused
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
|
||||
PlaySound(eat);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Player die logic
|
||||
PlaySound(die);
|
||||
|
||||
currentScreen = ENDING;
|
||||
framesCounter = 0;
|
||||
|
||||
// Save hiscore and hidistance for next game
|
||||
if (score > hiscore) hiscore = score;
|
||||
if (distance > hidistance) hidistance = distance;
|
||||
}
|
||||
}
|
||||
else // Sweet fish
|
||||
{
|
||||
enemyActive[i] = false;
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
|
||||
if (!gameraMode) foodBar += 80;
|
||||
else foodBar += 25;
|
||||
|
||||
score += 10;
|
||||
|
||||
if (foodBar == 400)
|
||||
{
|
||||
gameraMode = true;
|
||||
|
||||
PlaySound(growl);
|
||||
}
|
||||
|
||||
PlaySound(eat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gamera mode logic
|
||||
if (gameraMode)
|
||||
{
|
||||
foodBar--;
|
||||
|
||||
if (foodBar <= 0)
|
||||
{
|
||||
gameraMode = false;
|
||||
enemySpeed -= 2;
|
||||
if (enemySpeed < 10) enemySpeed = 10;
|
||||
}
|
||||
}
|
||||
|
||||
// Update distance counter
|
||||
distance += 0.5f;
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Press enter to play again
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
|
||||
// Reset player
|
||||
playerRail = 1;
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
|
||||
// Reset enemies data
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
int enemyProb = GetRandomValue(0, 100);
|
||||
|
||||
if (enemyProb < 30) enemyType[i] = 0;
|
||||
else if (enemyProb < 60) enemyType[i] = 1;
|
||||
else if (enemyProb < 90) enemyType[i] = 2;
|
||||
else enemyType[i] = 3;
|
||||
|
||||
//enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
|
||||
enemySpeed = 10;
|
||||
|
||||
// Reset game variables
|
||||
score = 0;
|
||||
distance = 0.0;
|
||||
foodBar = 0;
|
||||
gameraMode = false;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Draw background (common to all screens)
|
||||
DrawTexture(sky, 0, 0, WHITE);
|
||||
|
||||
DrawTexture(mountains, backScrolling, 0, WHITE);
|
||||
DrawTexture(mountains, screenWidth + backScrolling, 0, WHITE);
|
||||
|
||||
if (!gameraMode)
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, (Color){ 16, 189, 227, 255});
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 16, 189, 227, 255});
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, (Color){ 255, 113, 66, 255});
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 255, 113, 66, 255});
|
||||
}
|
||||
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Draw title
|
||||
DrawTexture(title, screenWidth/2 - title.width/2, screenHeight/2 - title.height/2 - 80, WHITE);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER", (Vector2){ screenWidth/2 - 150, 480 }, font.baseSize, 0, WHITE);
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Draw water lines
|
||||
for (int i = 0; i < 5; i++) DrawRectangle(0, i*120 + 120, screenWidth, 110, Fade(SKYBLUE, 0.1f));
|
||||
|
||||
// Draw player
|
||||
if (!gameraMode) DrawTexture(turtle, playerBounds.x - 14, playerBounds.y - 14, WHITE);
|
||||
else DrawTexture(gamera, playerBounds.x - 64, playerBounds.y - 64, WHITE);
|
||||
|
||||
// Draw player bounding box
|
||||
//if (!gameraMode) DrawRectangleRec(playerBounds, Fade(GREEN, 0.4f));
|
||||
//else DrawRectangleRec(playerBounds, Fade(ORANGE, 0.4f));
|
||||
|
||||
// Draw enemies
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
// Draw enemies
|
||||
switch(enemyType[i])
|
||||
{
|
||||
case 0: DrawTexture(shark, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 1: DrawTexture(orca, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 2: DrawTexture(swhale, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 3: DrawTexture(fish, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Draw enemies bounding boxes
|
||||
/*
|
||||
switch(enemyType[i])
|
||||
{
|
||||
case 0: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 1: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 2: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 3: DrawRectangleRec(enemyBounds[i], Fade(GREEN, 0.5f)); break;
|
||||
default: break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// Draw gameplay interface
|
||||
DrawRectangle(20, 20, 400, 40, Fade(GRAY, 0.4f));
|
||||
DrawRectangle(20, 20, foodBar, 40, ORANGE);
|
||||
DrawRectangleLines(20, 20, 400, 40, BLACK);
|
||||
|
||||
DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ screenWidth - 300, 20 }, font.baseSize, -2, ORANGE);
|
||||
DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 550, 20 }, font.baseSize, -2, ORANGE);
|
||||
|
||||
if (gameraMode)
|
||||
{
|
||||
DrawText("GAMERA MODE", 60, 22, 40, GRAY);
|
||||
DrawTexture(gframe, 0, 0, Fade(WHITE, 0.5f));
|
||||
}
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Draw a transparent black rectangle that covers all screen
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, Fade(BLACK, 0.4f));
|
||||
|
||||
DrawTextEx(font, "GAME OVER", (Vector2){ 300, 160 }, font.baseSize*3, -2, MAROON);
|
||||
|
||||
DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ 680, 350 }, font.baseSize, -2, GOLD);
|
||||
DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 290, 350 }, font.baseSize, -2, GOLD);
|
||||
DrawTextEx(font, FormatText("HISCORE: %04i", hiscore), (Vector2){ 665, 400 }, font.baseSize, -2, ORANGE);
|
||||
DrawTextEx(font, FormatText("HIDISTANCE: %04i", (int)hidistance), (Vector2){ 270, 400 }, font.baseSize, -2, ORANGE);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER to REPLAY", (Vector2){ screenWidth/2 - 250, 520 }, font.baseSize, -2, LIGHTGRAY);
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Unload textures
|
||||
UnloadTexture(sky);
|
||||
UnloadTexture(mountains);
|
||||
UnloadTexture(sea);
|
||||
UnloadTexture(gframe);
|
||||
UnloadTexture(title);
|
||||
UnloadTexture(turtle);
|
||||
UnloadTexture(shark);
|
||||
UnloadTexture(orca);
|
||||
UnloadTexture(swhale);
|
||||
UnloadTexture(fish);
|
||||
UnloadTexture(gamera);
|
||||
|
||||
// Unload font texture
|
||||
UnloadFont(font);
|
||||
|
||||
// Unload sounds
|
||||
UnloadSound(eat);
|
||||
UnloadSound(die);
|
||||
UnloadSound(growl);
|
||||
|
||||
UnloadMusicStream(music); // Unload music
|
||||
CloseAudioDevice(); // Close audio device
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,495 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib game - Dr. Turtle & Mr. Gamera
|
||||
*
|
||||
* 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.6 (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"
|
||||
|
||||
#include <math.h> // Used for sinf()
|
||||
|
||||
#define MAX_ENEMIES 10
|
||||
|
||||
typedef enum { TITLE, GAMEPLAY, ENDING } GameScreen;
|
||||
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int screenWidth = 1280;
|
||||
const int screenHeight = 720;
|
||||
|
||||
// Init window
|
||||
InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA");
|
||||
|
||||
// Initialize audio device
|
||||
InitAudioDevice();
|
||||
|
||||
// Load game resources: textures
|
||||
Texture2D sky = LoadTexture("resources/sky.png");
|
||||
Texture2D mountains = LoadTexture("resources/mountains.png");
|
||||
Texture2D sea = LoadTexture("resources/sea.png");
|
||||
Texture2D title = LoadTexture("resources/title.png");
|
||||
Texture2D turtle = LoadTexture("resources/turtle.png");
|
||||
Texture2D gamera = LoadTexture("resources/gamera.png");
|
||||
Texture2D shark = LoadTexture("resources/shark.png");
|
||||
Texture2D orca = LoadTexture("resources/orca.png");
|
||||
Texture2D swhale = LoadTexture("resources/swhale.png");
|
||||
Texture2D fish = LoadTexture("resources/fish.png");
|
||||
Texture2D gframe = LoadTexture("resources/gframe.png");
|
||||
|
||||
// Load game resources: fonts
|
||||
Font font = LoadFont("resources/komika.png");
|
||||
|
||||
// Load game resources: sounds
|
||||
Sound eat = LoadSound("resources/eat.wav");
|
||||
Sound die = LoadSound("resources/die.wav");
|
||||
Sound growl = LoadSound("resources/gamera.wav");
|
||||
|
||||
// Load music stream and start playing music
|
||||
Music music = LoadMusicStream("resources/speeding.ogg");
|
||||
PlayMusicStream(music);
|
||||
|
||||
// Define scrolling variables
|
||||
int backScrolling = 0;
|
||||
int seaScrolling = 0;
|
||||
|
||||
// Define current screen
|
||||
GameScreen currentScreen = TITLE;
|
||||
|
||||
// Define player variables
|
||||
int playerRail = 1;
|
||||
Rectangle playerBounds = { 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
bool gameraMode = false;
|
||||
|
||||
// Define enemies variables
|
||||
Rectangle enemyBounds[MAX_ENEMIES];
|
||||
int enemyRail[MAX_ENEMIES];
|
||||
int enemyType[MAX_ENEMIES];
|
||||
bool enemyActive[MAX_ENEMIES];
|
||||
float enemySpeed = 10;
|
||||
|
||||
// Init enemies variables
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
// Define enemy type (all same probability)
|
||||
//enemyType[i] = GetRandomValue(0, 3);
|
||||
|
||||
// Probability system for enemies type
|
||||
int enemyProb = GetRandomValue(0, 100);
|
||||
|
||||
if (enemyProb < 30) enemyType[i] = 0;
|
||||
else if (enemyProb < 60) enemyType[i] = 1;
|
||||
else if (enemyProb < 90) enemyType[i] = 2;
|
||||
else enemyType[i] = 3;
|
||||
|
||||
// define enemy rail
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
|
||||
// Define additional game variables
|
||||
int score = 0;
|
||||
float distance = 0.0f;
|
||||
int hiscore = 0;
|
||||
float hidistance = 0.0f;
|
||||
int foodBar = 0;
|
||||
int framesCounter = 0;
|
||||
|
||||
unsigned char blue = 200;
|
||||
float timeCounter = 0;
|
||||
|
||||
SetTargetFPS(60); // Setup game frames per second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateMusicStream(music); // Refill music stream buffers (if required)
|
||||
|
||||
framesCounter++;
|
||||
|
||||
// Sea color tint effect
|
||||
blue = 210 + 25 * sinf(timeCounter);
|
||||
timeCounter += 0.01;
|
||||
|
||||
// Game screens management
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Sea scrolling
|
||||
seaScrolling -= 2;
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Press enter to change to gameplay screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Background scrolling logic
|
||||
backScrolling--;
|
||||
if (backScrolling <= -screenWidth) backScrolling = 0;
|
||||
|
||||
// Sea scrolling logic
|
||||
seaScrolling -= (enemySpeed - 2);
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Player movement logic
|
||||
if (IsKeyPressed(KEY_DOWN)) playerRail++;
|
||||
else if (IsKeyPressed(KEY_UP)) playerRail--;
|
||||
|
||||
// Check player not out of rails
|
||||
if (playerRail > 4) playerRail = 4;
|
||||
else if (playerRail < 0) playerRail = 0;
|
||||
|
||||
// Update player bounds
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
|
||||
// Enemies activation logic (every 40 frames)
|
||||
if (framesCounter > 40)
|
||||
{
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i] == false)
|
||||
{
|
||||
enemyActive[i] = true;
|
||||
i = MAX_ENEMIES;
|
||||
}
|
||||
}
|
||||
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
// Enemies logic
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
enemyBounds[i].x -= enemySpeed;
|
||||
}
|
||||
|
||||
// Check enemies out of screen
|
||||
if (enemyBounds[i].x <= 0 - 128)
|
||||
{
|
||||
enemyActive[i] = false;
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
}
|
||||
}
|
||||
|
||||
if (!gameraMode) enemySpeed += 0.005;
|
||||
|
||||
// Check collision player vs enemies
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
if (CheckCollisionRecs(playerBounds, enemyBounds[i]))
|
||||
{
|
||||
if (enemyType[i] < 3) // Bad enemies
|
||||
{
|
||||
if (gameraMode)
|
||||
{
|
||||
if (enemyType[i] == 0) score += 50;
|
||||
else if (enemyType[i] == 1) score += 150;
|
||||
else if (enemyType[i] == 2) score += 300;
|
||||
|
||||
foodBar += 15;
|
||||
|
||||
enemyActive[i] = false;
|
||||
|
||||
// After enemy deactivation, reset enemy parameters to be reused
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
|
||||
PlaySound(eat);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Player die logic
|
||||
PlaySound(die);
|
||||
|
||||
currentScreen = ENDING;
|
||||
framesCounter = 0;
|
||||
|
||||
// Save hiscore and hidistance for next game
|
||||
if (score > hiscore) hiscore = score;
|
||||
if (distance > hidistance) hidistance = distance;
|
||||
}
|
||||
}
|
||||
else // Sweet fish
|
||||
{
|
||||
enemyActive[i] = false;
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
|
||||
if (!gameraMode) foodBar += 80;
|
||||
else foodBar += 25;
|
||||
|
||||
score += 10;
|
||||
|
||||
if (foodBar == 400)
|
||||
{
|
||||
gameraMode = true;
|
||||
|
||||
PlaySound(growl);
|
||||
}
|
||||
|
||||
PlaySound(eat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gamera mode logic
|
||||
if (gameraMode)
|
||||
{
|
||||
foodBar--;
|
||||
|
||||
if (foodBar <= 0)
|
||||
{
|
||||
gameraMode = false;
|
||||
enemySpeed -= 2;
|
||||
if (enemySpeed < 10) enemySpeed = 10;
|
||||
}
|
||||
}
|
||||
|
||||
// Update distance counter
|
||||
distance += 0.5f;
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Press enter to play again
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
|
||||
// Reset player
|
||||
playerRail = 1;
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
gameraMode = false;
|
||||
|
||||
// Reset enemies data
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
int enemyProb = GetRandomValue(0, 100);
|
||||
|
||||
if (enemyProb < 30) enemyType[i] = 0;
|
||||
else if (enemyProb < 60) enemyType[i] = 1;
|
||||
else if (enemyProb < 90) enemyType[i] = 2;
|
||||
else enemyType[i] = 3;
|
||||
|
||||
//enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
|
||||
enemySpeed = 10;
|
||||
|
||||
// Reset game variables
|
||||
score = 0;
|
||||
distance = 0.0;
|
||||
foodBar = 0;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Draw background (common to all screens)
|
||||
DrawTexture(sky, 0, 0, WHITE);
|
||||
|
||||
DrawTexture(mountains, backScrolling, 0, WHITE);
|
||||
DrawTexture(mountains, screenWidth + backScrolling, 0, WHITE);
|
||||
|
||||
if (!gameraMode)
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, (Color){ 16, 189, blue, 255});
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 16, 189, blue, 255});
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, (Color){ 255, 113, 66, 255});
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 255, 113, 66, 255});
|
||||
}
|
||||
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Draw title
|
||||
DrawTexture(title, screenWidth/2 - title.width/2, screenHeight/2 - title.height/2 - 80, WHITE);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER", (Vector2){ screenWidth/2 - 150, 480 }, font.baseSize, 0, WHITE);
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Draw water lines
|
||||
for (int i = 0; i < 5; i++) DrawRectangle(0, i*120 + 120, screenWidth, 110, Fade(SKYBLUE, 0.1f));
|
||||
|
||||
// Draw player
|
||||
if (!gameraMode) DrawTexture(turtle, playerBounds.x - 14, playerBounds.y - 14, WHITE);
|
||||
else DrawTexture(gamera, playerBounds.x - 64, playerBounds.y - 64, WHITE);
|
||||
|
||||
// Draw player bounding box
|
||||
//if (!gameraMode) DrawRectangleRec(playerBounds, Fade(GREEN, 0.4f));
|
||||
//else DrawRectangleRec(playerBounds, Fade(ORANGE, 0.4f));
|
||||
|
||||
// Draw enemies
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
// Draw enemies
|
||||
switch(enemyType[i])
|
||||
{
|
||||
case 0: DrawTexture(shark, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 1: DrawTexture(orca, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 2: DrawTexture(swhale, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 3: DrawTexture(fish, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Draw enemies bounding boxes
|
||||
/*
|
||||
switch(enemyType[i])
|
||||
{
|
||||
case 0: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 1: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 2: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 3: DrawRectangleRec(enemyBounds[i], Fade(GREEN, 0.5f)); break;
|
||||
default: break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// Draw gameplay interface
|
||||
DrawRectangle(20, 20, 400, 40, Fade(GRAY, 0.4f));
|
||||
DrawRectangle(20, 20, foodBar, 40, ORANGE);
|
||||
DrawRectangleLines(20, 20, 400, 40, BLACK);
|
||||
|
||||
DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ screenWidth - 300, 20 }, font.baseSize, -2, ORANGE);
|
||||
DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 550, 20 }, font.baseSize, -2, ORANGE);
|
||||
|
||||
if (gameraMode)
|
||||
{
|
||||
DrawText("GAMERA MODE", 60, 22, 40, GRAY);
|
||||
DrawTexture(gframe, 0, 0, Fade(WHITE, 0.5f));
|
||||
}
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Draw a transparent black rectangle that covers all screen
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, Fade(BLACK, 0.4f));
|
||||
|
||||
DrawTextEx(font, "GAME OVER", (Vector2){ 300, 160 }, font.baseSize*3, -2, MAROON);
|
||||
|
||||
DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ 680, 350 }, font.baseSize, -2, GOLD);
|
||||
DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 290, 350 }, font.baseSize, -2, GOLD);
|
||||
DrawTextEx(font, FormatText("HISCORE: %04i", hiscore), (Vector2){ 665, 400 }, font.baseSize, -2, ORANGE);
|
||||
DrawTextEx(font, FormatText("HIDISTANCE: %04i", (int)hidistance), (Vector2){ 270, 400 }, font.baseSize, -2, ORANGE);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER to REPLAY", (Vector2){ screenWidth/2 - 250, 520 }, font.baseSize, -2, LIGHTGRAY);
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Unload textures
|
||||
UnloadTexture(sky);
|
||||
UnloadTexture(mountains);
|
||||
UnloadTexture(sea);
|
||||
UnloadTexture(gframe);
|
||||
UnloadTexture(title);
|
||||
UnloadTexture(turtle);
|
||||
UnloadTexture(shark);
|
||||
UnloadTexture(orca);
|
||||
UnloadTexture(swhale);
|
||||
UnloadTexture(fish);
|
||||
UnloadTexture(gamera);
|
||||
|
||||
// Unload font texture
|
||||
UnloadFont(font);
|
||||
|
||||
// Unload sounds
|
||||
UnloadSound(eat);
|
||||
UnloadSound(die);
|
||||
UnloadSound(growl);
|
||||
|
||||
UnloadMusicStream(music); // Unload music
|
||||
CloseAudioDevice(); // Close audio device
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
project(drturtle)
|
||||
|
||||
# Executable & linking
|
||||
add_executable(${PROJECT_NAME} 06_drturtle_final.c)
|
||||
if (NOT TARGET raylib)
|
||||
find_package(raylib 2.0 REQUIRED)
|
||||
endif()
|
||||
target_link_libraries(${PROJECT_NAME} raylib)
|
||||
|
||||
# Resources
|
||||
# Copy all of the resource files to the destination
|
||||
file(COPY "resources/" DESTINATION "resources/")
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
This game sources are licensed under an unmodified zlib/libpng license,
|
||||
which is an OSI-certified, BSD-like license:
|
||||
|
||||
Copyright (c) 2013-2017 Ramon Santamaria (@raysan5)
|
||||
|
||||
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.
|
||||
|
|
@ -1,385 +0,0 @@
|
|||
#**************************************************************************************************
|
||||
#
|
||||
# raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5
|
||||
#
|
||||
# Copyright (c) 2013-2020 Ramon Santamaria (@raysan5)
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#**************************************************************************************************
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
# Define required raylib variables
|
||||
PROJECT_NAME ?= drturtle
|
||||
RAYLIB_VERSION ?= 3.0.0
|
||||
RAYLIB_API_VERSION ?= 3
|
||||
RAYLIB_PATH ?= C:\GitHub\raylib
|
||||
|
||||
# Define default options
|
||||
|
||||
# One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
PLATFORM ?= PLATFORM_DESKTOP
|
||||
|
||||
# Locations of your newly installed library and associated headers. See ../src/Makefile
|
||||
# On Linux, if you have installed raylib but cannot compile the examples, check that
|
||||
# the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations.
|
||||
# To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED.
|
||||
# To enable compile-time linking to a special version of libraylib.so, change these variables here.
|
||||
# To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below.
|
||||
# If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime,
|
||||
# the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH.
|
||||
# RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths.
|
||||
DESTDIR ?= /usr/local
|
||||
RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib
|
||||
# RAYLIB_H_INSTALL_PATH locates the installed raylib header and associated source files.
|
||||
RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include
|
||||
|
||||
# Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
|
||||
RAYLIB_LIBTYPE ?= STATIC
|
||||
|
||||
# Build mode for project: DEBUG or RELEASE
|
||||
BUILD_MODE ?= RELEASE
|
||||
|
||||
# Use external GLFW library instead of rglfw module
|
||||
# TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3
|
||||
USE_EXTERNAL_GLFW ?= FALSE
|
||||
|
||||
# Use Wayland display server protocol on Linux desktop
|
||||
# by default it uses X11 windowing system
|
||||
USE_WAYLAND_DISPLAY ?= FALSE
|
||||
|
||||
# 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
|
||||
else
|
||||
UNAMEOS=$(shell uname)
|
||||
ifeq ($(UNAMEOS),Linux)
|
||||
PLATFORM_OS=LINUX
|
||||
endif
|
||||
ifeq ($(UNAMEOS),FreeBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),OpenBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),NetBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),DragonFly)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),Darwin)
|
||||
PLATFORM_OS=OSX
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
UNAMEOS=$(shell uname)
|
||||
ifeq ($(UNAMEOS),Linux)
|
||||
PLATFORM_OS=LINUX
|
||||
endif
|
||||
endif
|
||||
|
||||
# RAYLIB_PATH adjustment for different platforms.
|
||||
# If using GNU make, we can get the full path to the top of the tree. Windows? BSD?
|
||||
# Required for ldconfig or other tools that do not perform path expansion.
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
RAYLIB_PREFIX ?= ..
|
||||
RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX))
|
||||
endif
|
||||
endif
|
||||
# Default path for raylib on Raspberry Pi, if installed in different path, update it!
|
||||
# This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki.
|
||||
# TODO: update install: target in src/Makefile for RPI, consider relation to LINUX.
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
RAYLIB_PATH ?= /home/pi/raylib
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# Emscripten required variables
|
||||
EMSDK_PATH ?= C:/emsdk
|
||||
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/fastcomp/emscripten
|
||||
CLANG_PATH = $(EMSDK_PATH)/fastcomp/bin
|
||||
PYTHON_PATH = $(EMSDK_PATH)/python/2.7.13.1_64bit/python-2.7.13.amd64
|
||||
NODE_PATH = $(EMSDK_PATH)/node/12.9.1_64bit/bin
|
||||
export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH);C:\raylib\MinGW\bin:$$(PATH)
|
||||
endif
|
||||
|
||||
# Define raylib release directory for compiled library.
|
||||
# RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version
|
||||
RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src
|
||||
|
||||
# EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries
|
||||
# into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH
|
||||
# so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux
|
||||
# without formal installation from ../src/Makefile. It aids portability and is useful if you have
|
||||
# multiple versions of raylib, have raylib installed to a non-standard location, or want to
|
||||
# bundle libraylib.so with your game. Change it to your liking.
|
||||
# NOTE: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH,
|
||||
# The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH,
|
||||
# Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
|
||||
# To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute.
|
||||
# To see which libraries a built example is linking to, ldd core/core_basic_window;
|
||||
# Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing.
|
||||
EXAMPLE_RUNTIME_PATH ?= $(RAYLIB_RELEASE_PATH)
|
||||
|
||||
# Define default C compiler: gcc
|
||||
# NOTE: define g++ compiler if using C++
|
||||
CC = gcc
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
# OSX default compiler
|
||||
CC = clang
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# FreeBSD, OpenBSD, NetBSD, DragonFly default compiler
|
||||
CC = clang
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
ifeq ($(USE_RPI_CROSS_COMPILER),TRUE)
|
||||
# Define RPI cross-compiler
|
||||
#CC = armv6j-hardfloat-linux-gnueabi-gcc
|
||||
CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# HTML5 emscripten compiler
|
||||
# WARNING: To compile to HTML5, code must be redesigned
|
||||
# to use emscripten.h and emscripten_set_main_loop()
|
||||
CC = emcc
|
||||
endif
|
||||
|
||||
# Define default make program: Mingw32-make
|
||||
MAKE = mingw32-make
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
MAKE = make
|
||||
endif
|
||||
endif
|
||||
|
||||
# Define compiler flags:
|
||||
# -O1 defines optimization level
|
||||
# -g include debug information on compilation
|
||||
# -s strip unnecessary data from build
|
||||
# -Wall turns on most, but not all, compiler warnings
|
||||
# -std=c99 defines C language mode (standard C from 1999 revision)
|
||||
# -std=gnu99 defines C language mode (GNU C from 1999 revision)
|
||||
# -Wno-missing-braces ignore invalid warning (GCC bug 53119)
|
||||
# -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
|
||||
CFLAGS += -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces
|
||||
|
||||
ifeq ($(BUILD_MODE),DEBUG)
|
||||
CFLAGS += -g
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
CFLAGS += -s ASSERTIONS=1 --profiling
|
||||
endif
|
||||
else
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
CFLAGS += -Os
|
||||
else
|
||||
CFLAGS += -s -O1
|
||||
endif
|
||||
endif
|
||||
|
||||
# Additional flags for compiler (if desired)
|
||||
#CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
ifeq ($(RAYLIB_LIBTYPE),STATIC)
|
||||
CFLAGS += -D_DEFAULT_SOURCE
|
||||
endif
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
# Explicitly enable runtime link to libraylib.so
|
||||
CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
CFLAGS += -std=gnu99
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# -Os # size optimization
|
||||
# -O2 # optimization level 2, if used, also set --memory-init-file 0
|
||||
# -s USE_GLFW=3 # Use glfw3 library (context/input management)
|
||||
# -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing -> WARNING: Audio buffers could FAIL!
|
||||
# -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
|
||||
# -s USE_PTHREADS=1 # multithreading support
|
||||
# -s WASM=0 # disable Web Assembly, emitted by default
|
||||
# -s EMTERPRETIFY=1 # enable emscripten code interpreter (very slow)
|
||||
# -s EMTERPRETIFY_ASYNC=1 # support synchronous loops by emterpreter
|
||||
# -s FORCE_FILESYSTEM=1 # force filesystem to load/save files data
|
||||
# -s ASSERTIONS=1 # enable runtime checks for common memory allocation errors (-O1 and above turn it off)
|
||||
# --profiling # include information for code profiling
|
||||
# --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
|
||||
# --preload-file resources # specify a resources folder for data compilation
|
||||
CFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=67108864 --preload-file resources
|
||||
|
||||
# Define a custom shell .html and output extension
|
||||
CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
|
||||
EXT = .html
|
||||
endif
|
||||
|
||||
# Define include paths for required headers
|
||||
# NOTE: Several external required libraries (stb and others)
|
||||
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
|
||||
|
||||
# Define additional directories containing required header files
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
# RPI required libraries
|
||||
INCLUDE_PATHS += -I/opt/vc/include
|
||||
INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux
|
||||
INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Consider -L$(RAYLIB_H_INSTALL_PATH)
|
||||
INCLUDE_PATHS += -I/usr/local/include
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Reset everything.
|
||||
# Precedence: immediately local, installed version, raysan5 provided libs -I$(RAYLIB_H_INSTALL_PATH) -I$(RAYLIB_PATH)/release/include
|
||||
INCLUDE_PATHS = -I$(RAYLIB_H_INSTALL_PATH) -isystem. -isystem$(RAYLIB_PATH)/src -isystem$(RAYLIB_PATH)/release/include -isystem$(RAYLIB_PATH)/src/external
|
||||
endif
|
||||
endif
|
||||
|
||||
# Define library paths containing required libs.
|
||||
LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
# resource file contains windows executable icon and properties
|
||||
LDFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data
|
||||
# -Wl,--subsystem,windows hides the console window
|
||||
ifeq ($(BUILD_MODE), RELEASE)
|
||||
LDFLAGS += -Wl,--subsystem,windows
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Consider -L$(RAYLIB_INSTALL_PATH)
|
||||
LDFLAGS += -L. -Lsrc -L/usr/local/lib
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Reset everything.
|
||||
# Precedence: immediately local, installed version, raysan5 provided libs
|
||||
LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
LDFLAGS += -L/opt/vc/lib
|
||||
endif
|
||||
|
||||
# Define any libraries required on linking
|
||||
# if you want to link libraries (libname.so or libname.a), use the -lname
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
# Libraries for Windows desktop compilation
|
||||
# NOTE: WinMM library required to set high-res timer resolution
|
||||
LDLIBS = -lraylib -lopengl32 -lgdi32 -lwinmm
|
||||
# Required for physac examples
|
||||
LDLIBS += -static -lpthread
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Libraries for Debian GNU/Linux desktop compiling
|
||||
# NOTE: Required packages: libegl1-mesa-dev
|
||||
LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
|
||||
|
||||
# On X11 requires also below libraries
|
||||
LDLIBS += -lX11
|
||||
# NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
|
||||
#LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||
|
||||
# On Wayland windowing system, additional libraries requires
|
||||
ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
|
||||
LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
|
||||
endif
|
||||
# Explicit link to libc
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
LDLIBS += -lc
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
# Libraries for OSX 10.9 desktop compiling
|
||||
# NOTE: Required packages: libopenal-dev libegl1-mesa-dev
|
||||
LDLIBS = -lraylib -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling
|
||||
# NOTE: Required packages: mesa-libs
|
||||
LDLIBS = -lraylib -lGL -lpthread -lm
|
||||
|
||||
# On XWindow requires also below libraries
|
||||
LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||
endif
|
||||
ifeq ($(USE_EXTERNAL_GLFW),TRUE)
|
||||
# NOTE: It could require additional packages installed: libglfw3-dev
|
||||
LDLIBS += -lglfw
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
# Libraries for Raspberry Pi compiling
|
||||
# NOTE: Required packages: libasound2-dev (ALSA)
|
||||
LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# Libraries for web (HTML5) compiling
|
||||
LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc
|
||||
endif
|
||||
|
||||
# Define all source files required
|
||||
SCREENS = drturtle_final_web \
|
||||
|
||||
# typing 'make' will invoke the default target entry
|
||||
all: $(SCREENS)
|
||||
|
||||
%: %.c
|
||||
ifeq ($(PLATFORM),PLATFORM_ANDROID)
|
||||
$(MAKE) -f Makefile.Android PROJECT_NAME=$@ PROJECT_SOURCE_FILES=$<
|
||||
else
|
||||
$(CC) -o $(PROJECT_NAME)$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||
endif
|
||||
|
||||
# Clean everything
|
||||
clean:
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
del *.o *.exe /s
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable|x-pie-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -fv
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
find . -type f -perm +ugo+x -delete
|
||||
rm -f *.o
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
find . -type f -executable -delete
|
||||
rm -fv *.o
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
del *.o *.html *.js
|
||||
endif
|
||||
@echo Cleaning done
|
||||
|
||||
|
|
@ -1,544 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib game - Dr. Turtle & Mr. Gamera
|
||||
*
|
||||
* 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.6 (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"
|
||||
#include <math.h> // Used for sinf()
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#define MAX_ENEMIES 10
|
||||
|
||||
typedef enum { TITLE = 0, GAMEPLAY, ENDING } GameScreen;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Global Variables Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
const int screenWidth = 1280;
|
||||
const int screenHeight = 720;
|
||||
|
||||
Texture2D sky;
|
||||
Texture2D mountains;
|
||||
Texture2D sea;
|
||||
Texture2D title;
|
||||
Texture2D turtle;
|
||||
Texture2D gamera;
|
||||
Texture2D shark;
|
||||
Texture2D orca;
|
||||
Texture2D swhale;
|
||||
Texture2D fish;
|
||||
Texture2D gframe;
|
||||
|
||||
Font font;
|
||||
|
||||
Sound eat;
|
||||
Sound die;
|
||||
Sound growl;
|
||||
|
||||
Music music;
|
||||
|
||||
// Define scrolling variables
|
||||
int backScrolling = 0;
|
||||
int seaScrolling = 0;
|
||||
|
||||
// Define current screen
|
||||
GameScreen currentScreen = 0;
|
||||
|
||||
// Define player variables
|
||||
int playerRail = 1;
|
||||
Rectangle playerBounds;
|
||||
bool gameraMode = false;
|
||||
|
||||
// Define enemies variables
|
||||
Rectangle enemyBounds[MAX_ENEMIES];
|
||||
int enemyRail[MAX_ENEMIES];
|
||||
int enemyType[MAX_ENEMIES];
|
||||
bool enemyActive[MAX_ENEMIES];
|
||||
float enemySpeed = 10;
|
||||
|
||||
// Define additional game variables
|
||||
int score = 0;
|
||||
float distance = 0.0f;
|
||||
int hiscore = 0;
|
||||
float hidistance = 0.0f;
|
||||
int foodBar = 0;
|
||||
int framesCounter = 0;
|
||||
|
||||
unsigned char blue = 200;
|
||||
float timeCounter = 0;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
void UpdateDrawFrame(void); // Update and Draw one frame
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Main Enry Point
|
||||
//----------------------------------------------------------------------------------
|
||||
int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Init window
|
||||
InitWindow(screenWidth, screenHeight, "Dr. Turtle & Mr. GAMERA");
|
||||
|
||||
// Initialize audio device
|
||||
InitAudioDevice();
|
||||
|
||||
// Load game resources: textures
|
||||
sky = LoadTexture("resources/sky.png");
|
||||
mountains = LoadTexture("resources/mountains.png");
|
||||
sea = LoadTexture("resources/sea.png");
|
||||
title = LoadTexture("resources/title.png");
|
||||
turtle = LoadTexture("resources/turtle.png");
|
||||
gamera = LoadTexture("resources/gamera.png");
|
||||
shark = LoadTexture("resources/shark.png");
|
||||
orca = LoadTexture("resources/orca.png");
|
||||
swhale = LoadTexture("resources/swhale.png");
|
||||
fish = LoadTexture("resources/fish.png");
|
||||
gframe = LoadTexture("resources/gframe.png");
|
||||
|
||||
// Load game resources: fonts
|
||||
font = LoadFont("resources/komika.png");
|
||||
|
||||
// Load game resources: sounds
|
||||
eat = LoadSound("resources/eat.wav");
|
||||
die = LoadSound("resources/die.wav");
|
||||
growl = LoadSound("resources/gamera.wav");
|
||||
|
||||
// Load music stream and start playing music
|
||||
music = LoadMusicStream("resources/speeding.ogg");
|
||||
PlayMusicStream(music);
|
||||
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
|
||||
// Init enemies variables
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
// Define enemy type (all same probability)
|
||||
//enemyType[i] = GetRandomValue(0, 3);
|
||||
|
||||
// Probability system for enemies type
|
||||
int enemyProb = GetRandomValue(0, 100);
|
||||
|
||||
if (enemyProb < 30) enemyType[i] = 0;
|
||||
else if (enemyProb < 60) enemyType[i] = 1;
|
||||
else if (enemyProb < 90) enemyType[i] = 2;
|
||||
else enemyType[i] = 3;
|
||||
|
||||
// define enemy rail
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||
#else
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
UpdateDrawFrame();
|
||||
}
|
||||
#endif
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Unload textures
|
||||
UnloadTexture(sky);
|
||||
UnloadTexture(mountains);
|
||||
UnloadTexture(sea);
|
||||
UnloadTexture(gframe);
|
||||
UnloadTexture(title);
|
||||
UnloadTexture(turtle);
|
||||
UnloadTexture(shark);
|
||||
UnloadTexture(orca);
|
||||
UnloadTexture(swhale);
|
||||
UnloadTexture(fish);
|
||||
UnloadTexture(gamera);
|
||||
|
||||
// Unload font texture
|
||||
UnloadFont(font);
|
||||
|
||||
// Unload sounds
|
||||
UnloadSound(eat);
|
||||
UnloadSound(die);
|
||||
UnloadSound(growl);
|
||||
|
||||
UnloadMusicStream(music); // Unload music
|
||||
CloseAudioDevice(); // Close audio device
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Module Functions Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
void UpdateDrawFrame(void)
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateMusicStream(music); // Refill music stream buffers (if required)
|
||||
|
||||
framesCounter++;
|
||||
|
||||
// Sea color tint effect
|
||||
blue = 210 + 25 * sinf(timeCounter);
|
||||
timeCounter += 0.01;
|
||||
|
||||
// Game screens management
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Sea scrolling
|
||||
seaScrolling -= 2;
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Press enter to change to gameplay screen
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Background scrolling logic
|
||||
backScrolling--;
|
||||
if (backScrolling <= -screenWidth) backScrolling = 0;
|
||||
|
||||
// Sea scrolling logic
|
||||
seaScrolling -= (enemySpeed - 2);
|
||||
if (seaScrolling <= -screenWidth) seaScrolling = 0;
|
||||
|
||||
// Player movement logic
|
||||
if (IsKeyPressed(KEY_DOWN)) playerRail++;
|
||||
else if (IsKeyPressed(KEY_UP)) playerRail--;
|
||||
|
||||
// Check player not out of rails
|
||||
if (playerRail > 4) playerRail = 4;
|
||||
else if (playerRail < 0) playerRail = 0;
|
||||
|
||||
// Update player bounds
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
|
||||
// Enemies activation logic (every 40 frames)
|
||||
if (framesCounter > 40)
|
||||
{
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i] == false)
|
||||
{
|
||||
enemyActive[i] = true;
|
||||
i = MAX_ENEMIES;
|
||||
}
|
||||
}
|
||||
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
// Enemies logic
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
enemyBounds[i].x -= enemySpeed;
|
||||
}
|
||||
|
||||
// Check enemies out of screen
|
||||
if (enemyBounds[i].x <= 0 - 128)
|
||||
{
|
||||
enemyActive[i] = false;
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
}
|
||||
}
|
||||
|
||||
if (!gameraMode) enemySpeed += 0.005;
|
||||
|
||||
// Check collision player vs enemies
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
if (CheckCollisionRecs(playerBounds, enemyBounds[i]))
|
||||
{
|
||||
if (enemyType[i] < 3) // Bad enemies
|
||||
{
|
||||
if (gameraMode)
|
||||
{
|
||||
if (enemyType[i] == 0) score += 50;
|
||||
else if (enemyType[i] == 1) score += 150;
|
||||
else if (enemyType[i] == 2) score += 300;
|
||||
|
||||
foodBar += 15;
|
||||
|
||||
enemyActive[i] = false;
|
||||
|
||||
// After enemy deactivation, reset enemy parameters to be reused
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
|
||||
PlaySound(eat);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Player die logic
|
||||
PlaySound(die);
|
||||
|
||||
currentScreen = ENDING;
|
||||
framesCounter = 0;
|
||||
|
||||
// Save hiscore and hidistance for next game
|
||||
if (score > hiscore) hiscore = score;
|
||||
if (distance > hidistance) hidistance = distance;
|
||||
}
|
||||
}
|
||||
else // Sweet fish
|
||||
{
|
||||
enemyActive[i] = false;
|
||||
enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
|
||||
if (!gameraMode) foodBar += 80;
|
||||
else foodBar += 25;
|
||||
|
||||
score += 10;
|
||||
|
||||
if (foodBar == 400)
|
||||
{
|
||||
gameraMode = true;
|
||||
|
||||
PlaySound(growl);
|
||||
}
|
||||
|
||||
PlaySound(eat);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Gamera mode logic
|
||||
if (gameraMode)
|
||||
{
|
||||
foodBar--;
|
||||
|
||||
if (foodBar <= 0)
|
||||
{
|
||||
gameraMode = false;
|
||||
enemySpeed -= 2;
|
||||
if (enemySpeed < 10) enemySpeed = 10;
|
||||
}
|
||||
}
|
||||
|
||||
// Update distance counter
|
||||
distance += 0.5f;
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Press enter to play again
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
currentScreen = GAMEPLAY;
|
||||
|
||||
// Reset player
|
||||
playerRail = 1;
|
||||
playerBounds = (Rectangle){ 30 + 14, playerRail*120 + 90 + 14, 100, 100 };
|
||||
gameraMode = false;
|
||||
|
||||
// Reset enemies data
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
int enemyProb = GetRandomValue(0, 100);
|
||||
|
||||
if (enemyProb < 30) enemyType[i] = 0;
|
||||
else if (enemyProb < 60) enemyType[i] = 1;
|
||||
else if (enemyProb < 90) enemyType[i] = 2;
|
||||
else enemyType[i] = 3;
|
||||
|
||||
//enemyType[i] = GetRandomValue(0, 3);
|
||||
enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
// Make sure not two consecutive enemies in the same row
|
||||
if (i > 0) while (enemyRail[i] == enemyRail[i - 1]) enemyRail[i] = GetRandomValue(0, 4);
|
||||
|
||||
enemyBounds[i] = (Rectangle){ screenWidth + 14, 120*enemyRail[i] + 90 + 14, 100, 100 };
|
||||
enemyActive[i] = false;
|
||||
}
|
||||
|
||||
enemySpeed = 10;
|
||||
|
||||
// Reset game variables
|
||||
score = 0;
|
||||
distance = 0.0;
|
||||
foodBar = 0;
|
||||
framesCounter = 0;
|
||||
}
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
// Draw background (common to all screens)
|
||||
DrawTexture(sky, 0, 0, WHITE);
|
||||
|
||||
DrawTexture(mountains, backScrolling, 0, WHITE);
|
||||
DrawTexture(mountains, screenWidth + backScrolling, 0, WHITE);
|
||||
|
||||
if (!gameraMode)
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, (Color){ 16, 189, blue, 255});
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 16, 189, blue, 255});
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawTexture(sea, seaScrolling, 0, (Color){ 255, 113, 66, 255});
|
||||
DrawTexture(sea, screenWidth + seaScrolling, 0, (Color){ 255, 113, 66, 255});
|
||||
}
|
||||
|
||||
switch (currentScreen)
|
||||
{
|
||||
case TITLE:
|
||||
{
|
||||
// Draw title
|
||||
DrawTexture(title, screenWidth/2 - title.width/2, screenHeight/2 - title.height/2 - 80, WHITE);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER", (Vector2){ screenWidth/2 - 150, 480 }, font.baseSize, 1, WHITE);
|
||||
|
||||
} break;
|
||||
case GAMEPLAY:
|
||||
{
|
||||
// Draw water lines
|
||||
for (int i = 0; i < 5; i++) DrawRectangle(0, i*120 + 120, screenWidth, 110, Fade(SKYBLUE, 0.1f));
|
||||
|
||||
// Draw player
|
||||
if (!gameraMode) DrawTexture(turtle, playerBounds.x - 14, playerBounds.y - 14, WHITE);
|
||||
else DrawTexture(gamera, playerBounds.x - 64, playerBounds.y - 64, WHITE);
|
||||
|
||||
// Draw player bounding box
|
||||
//if (!gameraMode) DrawRectangleRec(playerBounds, Fade(GREEN, 0.4f));
|
||||
//else DrawRectangleRec(playerBounds, Fade(ORANGE, 0.4f));
|
||||
|
||||
// Draw enemies
|
||||
for (int i = 0; i < MAX_ENEMIES; i++)
|
||||
{
|
||||
if (enemyActive[i])
|
||||
{
|
||||
// Draw enemies
|
||||
switch(enemyType[i])
|
||||
{
|
||||
case 0: DrawTexture(shark, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 1: DrawTexture(orca, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 2: DrawTexture(swhale, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
case 3: DrawTexture(fish, enemyBounds[i].x - 14, enemyBounds[i].y - 14, WHITE); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
// Draw enemies bounding boxes
|
||||
/*
|
||||
switch(enemyType[i])
|
||||
{
|
||||
case 0: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 1: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 2: DrawRectangleRec(enemyBounds[i], Fade(RED, 0.5f)); break;
|
||||
case 3: DrawRectangleRec(enemyBounds[i], Fade(GREEN, 0.5f)); break;
|
||||
default: break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// Draw gameplay interface
|
||||
DrawRectangle(20, 20, 400, 40, Fade(GRAY, 0.4f));
|
||||
DrawRectangle(20, 20, foodBar, 40, ORANGE);
|
||||
DrawRectangleLines(20, 20, 400, 40, BLACK);
|
||||
|
||||
DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ screenWidth - 300, 20 }, font.baseSize, -2, ORANGE);
|
||||
DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 550, 20 }, font.baseSize, -2, ORANGE);
|
||||
|
||||
if (gameraMode)
|
||||
{
|
||||
DrawText("GAMERA MODE", 60, 22, 40, GRAY);
|
||||
DrawTexture(gframe, 0, 0, Fade(WHITE, 0.5f));
|
||||
}
|
||||
|
||||
} break;
|
||||
case ENDING:
|
||||
{
|
||||
// Draw a transparent black rectangle that covers all screen
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, Fade(BLACK, 0.4f));
|
||||
|
||||
DrawTextEx(font, "GAME OVER", (Vector2){ 300, 160 }, font.baseSize*3, -2, MAROON);
|
||||
|
||||
DrawTextEx(font, FormatText("SCORE: %04i", score), (Vector2){ 680, 350 }, font.baseSize, -2, GOLD);
|
||||
DrawTextEx(font, FormatText("DISTANCE: %04i", (int)distance), (Vector2){ 290, 350 }, font.baseSize, -2, GOLD);
|
||||
DrawTextEx(font, FormatText("HISCORE: %04i", hiscore), (Vector2){ 665, 400 }, font.baseSize, -2, ORANGE);
|
||||
DrawTextEx(font, FormatText("HIDISTANCE: %04i", (int)hidistance), (Vector2){ 270, 400 }, font.baseSize, -2, ORANGE);
|
||||
|
||||
// Draw blinking text
|
||||
if ((framesCounter/30) % 2) DrawTextEx(font, "PRESS ENTER to REPLAY", (Vector2){ screenWidth/2 - 250, 520 }, font.baseSize, -2, LIGHTGRAY);
|
||||
|
||||
} break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
EndDrawing();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 79 KiB |
|
Before Width: | Height: | Size: 1.4 MiB |
|
Before Width: | Height: | Size: 70 KiB |
|
Before Width: | Height: | Size: 232 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 744 KiB |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 132 KiB |
|
Before Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 14 KiB |
238
games/floppy.c
|
|
@ -1,238 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib - sample game: floppy
|
||||
*
|
||||
* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria
|
||||
*
|
||||
* This game has been created using raylib v1.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"
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Some Defines
|
||||
//----------------------------------------------------------------------------------
|
||||
#define MAX_TUBES 100
|
||||
#define FLOPPY_RADIUS 24
|
||||
#define TUBES_WIDTH 80
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
typedef struct Floppy {
|
||||
Vector2 position;
|
||||
int radius;
|
||||
Color color;
|
||||
} Floppy;
|
||||
|
||||
typedef struct Tubes {
|
||||
Rectangle rec;
|
||||
Color color;
|
||||
bool active;
|
||||
} Tubes;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Global Variables Declaration
|
||||
//------------------------------------------------------------------------------------
|
||||
static const int screenWidth = 800;
|
||||
static const int screenHeight = 450;
|
||||
|
||||
static bool gameOver = false;
|
||||
static bool pause = false;
|
||||
static int score = 0;
|
||||
static int hiScore = 0;
|
||||
|
||||
static Floppy floppy = { 0 };
|
||||
static Tubes tubes[MAX_TUBES*2] = { 0 };
|
||||
static Vector2 tubesPos[MAX_TUBES] = { 0 };
|
||||
static int tubesSpeedX = 0;
|
||||
static bool superfx = false;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Declaration (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
static void InitGame(void); // Initialize game
|
||||
static void UpdateGame(void); // Update game (one frame)
|
||||
static void DrawGame(void); // Draw game (one frame)
|
||||
static void UnloadGame(void); // Unload game
|
||||
static void UpdateDrawFrame(void); // Update and Draw (one frame)
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
// Initialization
|
||||
//---------------------------------------------------------
|
||||
InitWindow(screenWidth, screenHeight, "sample game: floppy");
|
||||
|
||||
InitGame();
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||
#else
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update and Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateDrawFrame();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
#endif
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadGame(); // Unload loaded data (textures, sounds, models...)
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Definitions (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
// Initialize game variables
|
||||
void InitGame(void)
|
||||
{
|
||||
floppy.radius = FLOPPY_RADIUS;
|
||||
floppy.position = (Vector2){80, screenHeight/2 - floppy.radius};
|
||||
tubesSpeedX = 2;
|
||||
|
||||
for (int i = 0; i < MAX_TUBES; i++)
|
||||
{
|
||||
tubesPos[i].x = 400 + 280*i;
|
||||
tubesPos[i].y = -GetRandomValue(0, 120);
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_TUBES*2; i += 2)
|
||||
{
|
||||
tubes[i].rec.x = tubesPos[i/2].x;
|
||||
tubes[i].rec.y = tubesPos[i/2].y;
|
||||
tubes[i].rec.width = TUBES_WIDTH;
|
||||
tubes[i].rec.height = 255;
|
||||
|
||||
tubes[i+1].rec.x = tubesPos[i/2].x;
|
||||
tubes[i+1].rec.y = 600 + tubesPos[i/2].y - 255;
|
||||
tubes[i+1].rec.width = TUBES_WIDTH;
|
||||
tubes[i+1].rec.height = 255;
|
||||
|
||||
tubes[i/2].active = true;
|
||||
}
|
||||
|
||||
score = 0;
|
||||
|
||||
gameOver = false;
|
||||
superfx = false;
|
||||
pause = false;
|
||||
}
|
||||
|
||||
// Update game (one frame)
|
||||
void UpdateGame(void)
|
||||
{
|
||||
if (!gameOver)
|
||||
{
|
||||
if (IsKeyPressed('P')) pause = !pause;
|
||||
|
||||
if (!pause)
|
||||
{
|
||||
for (int i = 0; i < MAX_TUBES; i++) tubesPos[i].x -= tubesSpeedX;
|
||||
|
||||
for (int i = 0; i < MAX_TUBES*2; i += 2)
|
||||
{
|
||||
tubes[i].rec.x = tubesPos[i/2].x;
|
||||
tubes[i+1].rec.x = tubesPos[i/2].x;
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_SPACE) && !gameOver) floppy.position.y -= 3;
|
||||
else floppy.position.y += 1;
|
||||
|
||||
// Check Collisions
|
||||
for (int i = 0; i < MAX_TUBES*2; i++)
|
||||
{
|
||||
if (CheckCollisionCircleRec(floppy.position, floppy.radius, tubes[i].rec))
|
||||
{
|
||||
gameOver = true;
|
||||
pause = false;
|
||||
}
|
||||
else if ((tubesPos[i/2].x < floppy.position.x) && tubes[i/2].active && !gameOver)
|
||||
{
|
||||
score += 100;
|
||||
tubes[i/2].active = false;
|
||||
|
||||
superfx = true;
|
||||
|
||||
if (score > hiScore) hiScore = score;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
InitGame();
|
||||
gameOver = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw game (one frame)
|
||||
void DrawGame(void)
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
if (!gameOver)
|
||||
{
|
||||
DrawCircle(floppy.position.x, floppy.position.y, floppy.radius, DARKGRAY);
|
||||
|
||||
// Draw tubes
|
||||
for (int i = 0; i < MAX_TUBES; i++)
|
||||
{
|
||||
DrawRectangle(tubes[i*2].rec.x, tubes[i*2].rec.y, tubes[i*2].rec.width, tubes[i*2].rec.height, GRAY);
|
||||
DrawRectangle(tubes[i*2 + 1].rec.x, tubes[i*2 + 1].rec.y, tubes[i*2 + 1].rec.width, tubes[i*2 + 1].rec.height, GRAY);
|
||||
}
|
||||
|
||||
// Draw flashing fx (one frame only)
|
||||
if (superfx)
|
||||
{
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, WHITE);
|
||||
superfx = false;
|
||||
}
|
||||
|
||||
DrawText(TextFormat("%04i", score), 20, 20, 40, GRAY);
|
||||
DrawText(TextFormat("HI-SCORE: %04i", hiScore), 20, 70, 20, LIGHTGRAY);
|
||||
|
||||
if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
|
||||
}
|
||||
else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// Unload game variables
|
||||
void UnloadGame(void)
|
||||
{
|
||||
// TODO: Unload all dynamic loaded data (textures, sounds, models...)
|
||||
}
|
||||
|
||||
// Update and Draw (one frame)
|
||||
void UpdateDrawFrame(void)
|
||||
{
|
||||
UpdateGame();
|
||||
DrawGame();
|
||||
}
|
||||
|
|
@ -1,279 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib - sample game: gold fever
|
||||
*
|
||||
* Sample game developed by Ian Eito, Albert Martos and Ramon Santamaria
|
||||
*
|
||||
* This game has been created using raylib v1.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"
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
typedef struct Player {
|
||||
Vector2 position;
|
||||
Vector2 speed;
|
||||
int radius;
|
||||
} Player;
|
||||
|
||||
typedef struct Enemy {
|
||||
Vector2 position;
|
||||
Vector2 speed;
|
||||
int radius;
|
||||
int radiusBounds;
|
||||
bool moveRight;
|
||||
} Enemy;
|
||||
|
||||
typedef struct Points {
|
||||
Vector2 position;
|
||||
int radius;
|
||||
int value;
|
||||
bool active;
|
||||
} Points;
|
||||
|
||||
typedef struct Home {
|
||||
Rectangle rec;
|
||||
bool active;
|
||||
bool save;
|
||||
Color color;
|
||||
} Home;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Global Variables Declaration
|
||||
//------------------------------------------------------------------------------------
|
||||
static const int screenWidth = 800;
|
||||
static const int screenHeight = 450;
|
||||
|
||||
static bool gameOver = false;
|
||||
static bool pause = false;
|
||||
static int score = 0;
|
||||
static int hiScore = 0;
|
||||
|
||||
static Player player = { 0 };
|
||||
static Enemy enemy = { 0 };
|
||||
static Points points = { 0 };
|
||||
static Home home = { 0 };
|
||||
static bool follow = false;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Declaration (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
static void InitGame(void); // Initialize game
|
||||
static void UpdateGame(void); // Update game (one frame)
|
||||
static void DrawGame(void); // Draw game (one frame)
|
||||
static void UnloadGame(void); // Unload game
|
||||
static void UpdateDrawFrame(void); // Update and Draw (one frame)
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
// Initialization (Note windowTitle is unused on Android)
|
||||
//---------------------------------------------------------
|
||||
InitWindow(screenWidth, screenHeight, "sample game: gold fever");
|
||||
|
||||
InitGame();
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||
#else
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update and Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateDrawFrame();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
#endif
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadGame(); // Unload loaded data (textures, sounds, models...)
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Definitions (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
// Initialize game variables
|
||||
void InitGame(void)
|
||||
{
|
||||
pause = false;
|
||||
score = 0;
|
||||
|
||||
player.position = (Vector2){50, 50};
|
||||
player.radius = 20;
|
||||
player.speed = (Vector2){5, 5};
|
||||
|
||||
enemy.position = (Vector2){screenWidth - 50, screenHeight/2};
|
||||
enemy.radius = 20;
|
||||
enemy.radiusBounds = 150;
|
||||
enemy.speed = (Vector2){3, 3};
|
||||
enemy.moveRight = true;
|
||||
follow = false;
|
||||
|
||||
points.radius = 10;
|
||||
points.position = (Vector2){GetRandomValue(points.radius, screenWidth - points.radius), GetRandomValue(points.radius, screenHeight - points.radius)};
|
||||
points.value = 100;
|
||||
points.active = true;
|
||||
|
||||
home.rec.width = 50;
|
||||
home.rec.height = 50;
|
||||
home.rec.x = GetRandomValue(0, screenWidth - home.rec.width);
|
||||
home.rec.y = GetRandomValue(0, screenHeight - home.rec.height);
|
||||
home.active = false;
|
||||
home.save = false;
|
||||
}
|
||||
|
||||
// Update game (one frame)
|
||||
void UpdateGame(void)
|
||||
{
|
||||
if (!gameOver)
|
||||
{
|
||||
if (IsKeyPressed('P')) pause = !pause;
|
||||
|
||||
if (!pause)
|
||||
{
|
||||
// Control player
|
||||
if (IsKeyDown(KEY_RIGHT)) player.position.x += player.speed.x;
|
||||
if (IsKeyDown(KEY_LEFT)) player.position.x -= player.speed.x;
|
||||
if (IsKeyDown(KEY_UP)) player.position.y -= player.speed.y;
|
||||
if (IsKeyDown(KEY_DOWN)) player.position.y += player.speed.y;
|
||||
|
||||
// Wall behaviour player
|
||||
if (player.position.x - player.radius <= 0) player.position.x = player.radius;
|
||||
if (player.position.x + player.radius >= screenWidth) player.position.x = screenWidth - player.radius;
|
||||
if (player.position.y - player.radius <= 0) player.position.y = player.radius;
|
||||
if (player.position.y + player.radius >= screenHeight) player.position.y = screenHeight - player.radius;
|
||||
|
||||
// IA Enemy
|
||||
if ( (follow || CheckCollisionCircles(player.position, player.radius, enemy.position, enemy.radiusBounds)) && !home.save)
|
||||
{
|
||||
if (player.position.x > enemy.position.x) enemy.position.x += enemy.speed.x;
|
||||
if (player.position.x < enemy.position.x) enemy.position.x -= enemy.speed.x;
|
||||
|
||||
if (player.position.y > enemy.position.y) enemy.position.y += enemy.speed.y;
|
||||
if (player.position.y < enemy.position.y) enemy.position.y -= enemy.speed.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (enemy.moveRight) enemy.position.x += enemy.speed.x;
|
||||
else enemy.position.x -= enemy.speed.x;
|
||||
}
|
||||
|
||||
// Wall behaviour enemy
|
||||
if (enemy.position.x - enemy.radius <= 0) enemy.moveRight = true;
|
||||
if (enemy.position.x + enemy.radius >= screenWidth) enemy.moveRight = false;
|
||||
|
||||
if (enemy.position.x - enemy.radius <= 0) enemy.position.x = enemy.radius;
|
||||
if (enemy.position.x + enemy.radius >= screenWidth) enemy.position.x = screenWidth - enemy.radius;
|
||||
if (enemy.position.y - enemy.radius <= 0) enemy.position.y = enemy.radius;
|
||||
if (enemy.position.y + enemy.radius >= screenHeight) enemy.position.y = screenHeight - enemy.radius;
|
||||
|
||||
// Collisions
|
||||
if (CheckCollisionCircles(player.position, player.radius, points.position, points.radius) && points.active)
|
||||
{
|
||||
follow = true;
|
||||
points.active = false;
|
||||
home.active = true;
|
||||
}
|
||||
|
||||
if (CheckCollisionCircles(player.position, player.radius, enemy.position, enemy.radius) && !home.save)
|
||||
{
|
||||
gameOver = true;
|
||||
|
||||
if (hiScore < score) hiScore = score;
|
||||
}
|
||||
|
||||
if (CheckCollisionCircleRec(player.position, player.radius, home.rec))
|
||||
{
|
||||
follow = false;
|
||||
|
||||
if (!points.active)
|
||||
{
|
||||
score += points.value;
|
||||
points.active = true;
|
||||
enemy.speed.x += 0.5;
|
||||
enemy.speed.y += 0.5;
|
||||
points.position = (Vector2){GetRandomValue(points.radius, screenWidth - points.radius), GetRandomValue(points.radius, screenHeight - points.radius)};
|
||||
}
|
||||
|
||||
home.save = true;
|
||||
}
|
||||
else home.save = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
InitGame();
|
||||
gameOver = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw game (one frame)
|
||||
void DrawGame(void)
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
if (!gameOver)
|
||||
{
|
||||
if (follow)
|
||||
{
|
||||
DrawRectangle(0, 0, screenWidth, screenHeight, RED);
|
||||
DrawRectangle(10, 10, screenWidth - 20, screenHeight - 20, RAYWHITE);
|
||||
}
|
||||
|
||||
DrawRectangleLines(home.rec.x, home.rec.y, home.rec.width, home.rec.height, BLUE);
|
||||
|
||||
DrawCircleLines(enemy.position.x, enemy.position.y, enemy.radiusBounds, RED);
|
||||
DrawCircleV(enemy.position, enemy.radius, MAROON);
|
||||
|
||||
DrawCircleV(player.position, player.radius, GRAY);
|
||||
if (points.active) DrawCircleV(points.position, points.radius, GOLD);
|
||||
|
||||
DrawText(TextFormat("SCORE: %04i", score), 20, 15, 20, GRAY);
|
||||
DrawText(TextFormat("HI-SCORE: %04i", hiScore), 300, 15, 20, GRAY);
|
||||
|
||||
if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
|
||||
}
|
||||
else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// Unload game variables
|
||||
void UnloadGame(void)
|
||||
{
|
||||
// TODO: Unload all dynamic loaded data (textures, sounds, models...)
|
||||
}
|
||||
|
||||
// Update and Draw (one frame)
|
||||
void UpdateDrawFrame(void)
|
||||
{
|
||||
UpdateGame();
|
||||
DrawGame();
|
||||
}
|
||||
566
games/gorilas.c
|
|
@ -1,566 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib - sample game: gorilas
|
||||
*
|
||||
* Sample game Marc Palau and Ramon Santamaria
|
||||
*
|
||||
* This game has been created using raylib v1.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"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Some Defines
|
||||
//----------------------------------------------------------------------------------
|
||||
#define MAX_BUILDINGS 15
|
||||
#define MAX_EXPLOSIONS 200
|
||||
#define MAX_PLAYERS 2
|
||||
|
||||
#define BUILDING_RELATIVE_ERROR 30 // Building size random range %
|
||||
#define BUILDING_MIN_RELATIVE_HEIGHT 20 // Minimum height in % of the screenHeight
|
||||
#define BUILDING_MAX_RELATIVE_HEIGHT 60 // Maximum height in % of the screenHeight
|
||||
#define BUILDING_MIN_GRAYSCALE_COLOR 120 // Minimum gray color for the buildings
|
||||
#define BUILDING_MAX_GRAYSCALE_COLOR 200 // Maximum gray color for the buildings
|
||||
|
||||
#define MIN_PLAYER_POSITION 5 // Minimum x position %
|
||||
#define MAX_PLAYER_POSITION 20 // Maximum x position %
|
||||
|
||||
#define GRAVITY 9.81f
|
||||
#define DELTA_FPS 60
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
typedef struct Player {
|
||||
Vector2 position;
|
||||
Vector2 size;
|
||||
|
||||
Vector2 aimingPoint;
|
||||
int aimingAngle;
|
||||
int aimingPower;
|
||||
|
||||
Vector2 previousPoint;
|
||||
int previousAngle;
|
||||
int previousPower;
|
||||
|
||||
Vector2 impactPoint;
|
||||
|
||||
bool isLeftTeam; // This player belongs to the left or to the right team
|
||||
bool isPlayer; // If is a player or an AI
|
||||
bool isAlive;
|
||||
} Player;
|
||||
|
||||
typedef struct Building {
|
||||
Rectangle rectangle;
|
||||
Color color;
|
||||
} Building;
|
||||
|
||||
typedef struct Explosion {
|
||||
Vector2 position;
|
||||
int radius;
|
||||
bool active;
|
||||
} Explosion;
|
||||
|
||||
typedef struct Ball {
|
||||
Vector2 position;
|
||||
Vector2 speed;
|
||||
int radius;
|
||||
bool active;
|
||||
} Ball;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Global Variables Declaration
|
||||
//------------------------------------------------------------------------------------
|
||||
static const int screenWidth = 800;
|
||||
static const int screenHeight = 450;
|
||||
|
||||
static bool gameOver = false;
|
||||
static bool pause = false;
|
||||
|
||||
static Player player[MAX_PLAYERS] = { 0 };
|
||||
static Building building[MAX_BUILDINGS] = { 0 };
|
||||
static Explosion explosion[MAX_EXPLOSIONS] = { 0 };
|
||||
static Ball ball = { 0 };
|
||||
|
||||
static int playerTurn = 0;
|
||||
static bool ballOnAir = false;
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Declaration (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
static void InitGame(void); // Initialize game
|
||||
static void UpdateGame(void); // Update game (one frame)
|
||||
static void DrawGame(void); // Draw game (one frame)
|
||||
static void UnloadGame(void); // Unload game
|
||||
static void UpdateDrawFrame(void); // Update and Draw (one frame)
|
||||
|
||||
// Additional module functions
|
||||
static void InitBuildings(void);
|
||||
static void InitPlayers(void);
|
||||
static bool UpdatePlayer(int playerTurn);
|
||||
static bool UpdateBall(int playerTurn);
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
int main(void)
|
||||
{
|
||||
// Initialization (Note windowTitle is unused on Android)
|
||||
//---------------------------------------------------------
|
||||
InitWindow(screenWidth, screenHeight, "sample game: gorilas");
|
||||
|
||||
InitGame();
|
||||
|
||||
#if defined(PLATFORM_WEB)
|
||||
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
|
||||
#else
|
||||
|
||||
SetTargetFPS(60);
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update and Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
UpdateDrawFrame();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
#endif
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
UnloadGame(); // Unload loaded data (textures, sounds, models...)
|
||||
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Module Functions Definitions (local)
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
// Initialize game variables
|
||||
void InitGame(void)
|
||||
{
|
||||
// Init shoot
|
||||
ball.radius = 10;
|
||||
ballOnAir = false;
|
||||
ball.active = false;
|
||||
|
||||
InitBuildings();
|
||||
InitPlayers();
|
||||
|
||||
// Init explosions
|
||||
for (int i = 0; i < MAX_EXPLOSIONS; i++)
|
||||
{
|
||||
explosion[i].position = (Vector2){ 0.0f, 0.0f };
|
||||
explosion[i].radius = 30;
|
||||
explosion[i].active = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Update game (one frame)
|
||||
void UpdateGame(void)
|
||||
{
|
||||
if (!gameOver)
|
||||
{
|
||||
if (IsKeyPressed('P')) pause = !pause;
|
||||
|
||||
if (!pause)
|
||||
{
|
||||
if (!ballOnAir) ballOnAir = UpdatePlayer(playerTurn); // If we are aiming
|
||||
else
|
||||
{
|
||||
if (UpdateBall(playerTurn)) // If collision
|
||||
{
|
||||
// Game over logic
|
||||
bool leftTeamAlive = false;
|
||||
bool rightTeamAlive = false;
|
||||
|
||||
for (int i = 0; i < MAX_PLAYERS; i++)
|
||||
{
|
||||
if (player[i].isAlive)
|
||||
{
|
||||
if (player[i].isLeftTeam) leftTeamAlive = true;
|
||||
if (!player[i].isLeftTeam) rightTeamAlive = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (leftTeamAlive && rightTeamAlive)
|
||||
{
|
||||
ballOnAir = false;
|
||||
ball.active = false;
|
||||
|
||||
playerTurn++;
|
||||
|
||||
if (playerTurn == MAX_PLAYERS) playerTurn = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
gameOver = true;
|
||||
|
||||
// if (leftTeamAlive) left team wins
|
||||
// if (rightTeamAlive) right team wins
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IsKeyPressed(KEY_ENTER))
|
||||
{
|
||||
InitGame();
|
||||
gameOver = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw game (one frame)
|
||||
void DrawGame(void)
|
||||
{
|
||||
BeginDrawing();
|
||||
|
||||
ClearBackground(RAYWHITE);
|
||||
|
||||
if (!gameOver)
|
||||
{
|
||||
// Draw buildings
|
||||
for (int i = 0; i < MAX_BUILDINGS; i++) DrawRectangleRec(building[i].rectangle, building[i].color);
|
||||
|
||||
// Draw explosions
|
||||
for (int i = 0; i < MAX_EXPLOSIONS; i++)
|
||||
{
|
||||
if (explosion[i].active) DrawCircle(explosion[i].position.x, explosion[i].position.y, explosion[i].radius, RAYWHITE);
|
||||
}
|
||||
|
||||
// Draw players
|
||||
for (int i = 0; i < MAX_PLAYERS; i++)
|
||||
{
|
||||
if (player[i].isAlive)
|
||||
{
|
||||
if (player[i].isLeftTeam) DrawRectangle(player[i].position.x - player[i].size.x/2, player[i].position.y - player[i].size.y/2,
|
||||
player[i].size.x, player[i].size.y, BLUE);
|
||||
else DrawRectangle(player[i].position.x - player[i].size.x/2, player[i].position.y - player[i].size.y/2,
|
||||
player[i].size.x, player[i].size.y, RED);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw ball
|
||||
if (ball.active) DrawCircle(ball.position.x, ball.position.y, ball.radius, MAROON);
|
||||
|
||||
// Draw the angle and the power of the aim, and the previous ones
|
||||
if (!ballOnAir)
|
||||
{
|
||||
// Draw shot information
|
||||
/*
|
||||
if (player[playerTurn].isLeftTeam)
|
||||
{
|
||||
DrawText(TextFormat("Previous Point %i, %i", (int)player[playerTurn].previousPoint.x, (int)player[playerTurn].previousPoint.y), 20, 20, 20, DARKBLUE);
|
||||
DrawText(TextFormat("Previous Angle %i", player[playerTurn].previousAngle), 20, 50, 20, DARKBLUE);
|
||||
DrawText(TextFormat("Previous Power %i", player[playerTurn].previousPower), 20, 80, 20, DARKBLUE);
|
||||
DrawText(TextFormat("Aiming Point %i, %i", (int)player[playerTurn].aimingPoint.x, (int)player[playerTurn].aimingPoint.y), 20, 110, 20, DARKBLUE);
|
||||
DrawText(TextFormat("Aiming Angle %i", player[playerTurn].aimingAngle), 20, 140, 20, DARKBLUE);
|
||||
DrawText(TextFormat("Aiming Power %i", player[playerTurn].aimingPower), 20, 170, 20, DARKBLUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
DrawText(TextFormat("Previous Point %i, %i", (int)player[playerTurn].previousPoint.x, (int)player[playerTurn].previousPoint.y), screenWidth*3/4, 20, 20, DARKBLUE);
|
||||
DrawText(TextFormat("Previous Angle %i", player[playerTurn].previousAngle), screenWidth*3/4, 50, 20, DARKBLUE);
|
||||
DrawText(TextFormat("Previous Power %i", player[playerTurn].previousPower), screenWidth*3/4, 80, 20, DARKBLUE);
|
||||
DrawText(TextFormat("Aiming Point %i, %i", (int)player[playerTurn].aimingPoint.x, (int)player[playerTurn].aimingPoint.y), screenWidth*3/4, 110, 20, DARKBLUE);
|
||||
DrawText(TextFormat("Aiming Angle %i", player[playerTurn].aimingAngle), screenWidth*3/4, 140, 20, DARKBLUE);
|
||||
DrawText(TextFormat("Aiming Power %i", player[playerTurn].aimingPower), screenWidth*3/4, 170, 20, DARKBLUE);
|
||||
}
|
||||
*/
|
||||
|
||||
// Draw aim
|
||||
if (player[playerTurn].isLeftTeam)
|
||||
{
|
||||
// Previous aiming
|
||||
DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 },
|
||||
(Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 },
|
||||
player[playerTurn].previousPoint, GRAY);
|
||||
|
||||
// Actual aiming
|
||||
DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 },
|
||||
(Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 },
|
||||
player[playerTurn].aimingPoint, DARKBLUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Previous aiming
|
||||
DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 },
|
||||
(Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 },
|
||||
player[playerTurn].previousPoint, GRAY);
|
||||
|
||||
// Actual aiming
|
||||
DrawTriangle((Vector2){ player[playerTurn].position.x - player[playerTurn].size.x/4, player[playerTurn].position.y + player[playerTurn].size.y/4 },
|
||||
(Vector2){ player[playerTurn].position.x + player[playerTurn].size.x/4, player[playerTurn].position.y - player[playerTurn].size.y/4 },
|
||||
player[playerTurn].aimingPoint, MAROON);
|
||||
}
|
||||
}
|
||||
|
||||
if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY);
|
||||
}
|
||||
else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
// Unload game variables
|
||||
void UnloadGame(void)
|
||||
{
|
||||
// TODO: Unload all dynamic loaded data (textures, sounds, models...)
|
||||
}
|
||||
|
||||
// Update and Draw (one frame)
|
||||
void UpdateDrawFrame(void)
|
||||
{
|
||||
UpdateGame();
|
||||
DrawGame();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Additional module functions
|
||||
//--------------------------------------------------------------------------------------
|
||||
static void InitBuildings(void)
|
||||
{
|
||||
// Horizontal generation
|
||||
int currentWidth = 0;
|
||||
|
||||
// We make sure the absolute error randomly generated for each building, has as a minimum value the screenWidth.
|
||||
// This way all the screen will be filled with buildings. Each building will have a different, random width.
|
||||
|
||||
float relativeWidth = 100/(100 - BUILDING_RELATIVE_ERROR);
|
||||
float buildingWidthMean = (screenWidth*relativeWidth/MAX_BUILDINGS) + 1; // We add one to make sure we will cover the whole screen.
|
||||
|
||||
// Vertical generation
|
||||
int currentHeighth = 0;
|
||||
int grayLevel;
|
||||
|
||||
// Creation
|
||||
for (int i = 0; i < MAX_BUILDINGS; i++)
|
||||
{
|
||||
// Horizontal
|
||||
building[i].rectangle.x = currentWidth;
|
||||
building[i].rectangle.width = GetRandomValue(buildingWidthMean*(100 - BUILDING_RELATIVE_ERROR/2)/100 + 1, buildingWidthMean*(100 + BUILDING_RELATIVE_ERROR)/100);
|
||||
|
||||
currentWidth += building[i].rectangle.width;
|
||||
|
||||
// Vertical
|
||||
currentHeighth = GetRandomValue(BUILDING_MIN_RELATIVE_HEIGHT, BUILDING_MAX_RELATIVE_HEIGHT);
|
||||
building[i].rectangle.y = screenHeight - (screenHeight*currentHeighth/100);
|
||||
building[i].rectangle.height = screenHeight*currentHeighth/100 + 1;
|
||||
|
||||
// Color
|
||||
grayLevel = GetRandomValue(BUILDING_MIN_GRAYSCALE_COLOR, BUILDING_MAX_GRAYSCALE_COLOR);
|
||||
building[i].color = (Color){ grayLevel, grayLevel, grayLevel, 255 };
|
||||
}
|
||||
}
|
||||
|
||||
static void InitPlayers(void)
|
||||
{
|
||||
for (int i = 0; i < MAX_PLAYERS; i++)
|
||||
{
|
||||
player[i].isAlive = true;
|
||||
|
||||
// Decide the team of this player
|
||||
if (i % 2 == 0) player[i].isLeftTeam = true;
|
||||
else player[i].isLeftTeam = false;
|
||||
|
||||
// Now there is no AI
|
||||
player[i].isPlayer = true;
|
||||
|
||||
// Set size, by default by now
|
||||
player[i].size = (Vector2){ 40, 40 };
|
||||
|
||||
// Set position
|
||||
if (player[i].isLeftTeam) player[i].position.x = GetRandomValue(screenWidth*MIN_PLAYER_POSITION/100, screenWidth*MAX_PLAYER_POSITION/100);
|
||||
else player[i].position.x = screenWidth - GetRandomValue(screenWidth*MIN_PLAYER_POSITION/100, screenWidth*MAX_PLAYER_POSITION/100);
|
||||
|
||||
for (int j = 0; j < MAX_BUILDINGS; j++)
|
||||
{
|
||||
if (building[j].rectangle.x > player[i].position.x)
|
||||
{
|
||||
// Set the player in the center of the building
|
||||
player[i].position.x = building[j-1].rectangle.x + building[j-1].rectangle.width/2;
|
||||
// Set the player at the top of the building
|
||||
player[i].position.y = building[j-1].rectangle.y - player[i].size.y/2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set statistics to 0
|
||||
player[i].aimingPoint = player[i].position;
|
||||
player[i].previousAngle = 0;
|
||||
player[i].previousPower = 0;
|
||||
player[i].previousPoint = player[i].position;
|
||||
player[i].aimingAngle = 0;
|
||||
player[i].aimingPower = 0;
|
||||
|
||||
player[i].impactPoint = (Vector2){ -100, -100 };
|
||||
}
|
||||
}
|
||||
|
||||
static bool UpdatePlayer(int playerTurn)
|
||||
{
|
||||
// If we are aiming at the firing quadrant, we calculate the angle
|
||||
if (GetMousePosition().y <= player[playerTurn].position.y)
|
||||
{
|
||||
// Left team
|
||||
if (player[playerTurn].isLeftTeam && GetMousePosition().x >= player[playerTurn].position.x)
|
||||
{
|
||||
// Distance (calculating the fire power)
|
||||
player[playerTurn].aimingPower = sqrt(pow(player[playerTurn].position.x - GetMousePosition().x, 2) + pow(player[playerTurn].position.y - GetMousePosition().y, 2));
|
||||
// Calculates the angle via arcsin
|
||||
player[playerTurn].aimingAngle = asin((player[playerTurn].position.y - GetMousePosition().y)/player[playerTurn].aimingPower)*RAD2DEG;
|
||||
// Point of the screen we are aiming at
|
||||
player[playerTurn].aimingPoint = GetMousePosition();
|
||||
|
||||
// Ball fired
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
player[playerTurn].previousPoint = player[playerTurn].aimingPoint;
|
||||
player[playerTurn].previousPower = player[playerTurn].aimingPower;
|
||||
player[playerTurn].previousAngle = player[playerTurn].aimingAngle;
|
||||
ball.position = player[playerTurn].position;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Right team
|
||||
else if (!player[playerTurn].isLeftTeam && GetMousePosition().x <= player[playerTurn].position.x)
|
||||
{
|
||||
// Distance (calculating the fire power)
|
||||
player[playerTurn].aimingPower = sqrt(pow(player[playerTurn].position.x - GetMousePosition().x, 2) + pow(player[playerTurn].position.y - GetMousePosition().y, 2));
|
||||
// Calculates the angle via arcsin
|
||||
player[playerTurn].aimingAngle = asin((player[playerTurn].position.y - GetMousePosition().y)/player[playerTurn].aimingPower)*RAD2DEG;
|
||||
// Point of the screen we are aiming at
|
||||
player[playerTurn].aimingPoint = GetMousePosition();
|
||||
|
||||
// Ball fired
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
player[playerTurn].previousPoint = player[playerTurn].aimingPoint;
|
||||
player[playerTurn].previousPower = player[playerTurn].aimingPower;
|
||||
player[playerTurn].previousAngle = player[playerTurn].aimingAngle;
|
||||
ball.position = player[playerTurn].position;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player[playerTurn].aimingPoint = player[playerTurn].position;
|
||||
player[playerTurn].aimingPower = 0;
|
||||
player[playerTurn].aimingAngle = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
player[playerTurn].aimingPoint = player[playerTurn].position;
|
||||
player[playerTurn].aimingPower = 0;
|
||||
player[playerTurn].aimingAngle = 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool UpdateBall(int playerTurn)
|
||||
{
|
||||
static int explosionNumber = 0;
|
||||
|
||||
// Activate ball
|
||||
if (!ball.active)
|
||||
{
|
||||
if (player[playerTurn].isLeftTeam)
|
||||
{
|
||||
ball.speed.x = cos(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS;
|
||||
ball.speed.y = -sin(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS;
|
||||
ball.active = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
ball.speed.x = -cos(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS;
|
||||
ball.speed.y = -sin(player[playerTurn].previousAngle*DEG2RAD)*player[playerTurn].previousPower*3/DELTA_FPS;
|
||||
ball.active = true;
|
||||
}
|
||||
}
|
||||
|
||||
ball.position.x += ball.speed.x;
|
||||
ball.position.y += ball.speed.y;
|
||||
ball.speed.y += GRAVITY/DELTA_FPS;
|
||||
|
||||
// Collision
|
||||
if (ball.position.x + ball.radius < 0) return true;
|
||||
else if (ball.position.x - ball.radius > screenWidth) return true;
|
||||
else
|
||||
{
|
||||
// Player collision
|
||||
for (int i = 0; i < MAX_PLAYERS; i++)
|
||||
{
|
||||
if (CheckCollisionCircleRec(ball.position, ball.radius, (Rectangle){ player[i].position.x - player[i].size.x/2, player[i].position.y - player[i].size.y/2,
|
||||
player[i].size.x, player[i].size.y }))
|
||||
{
|
||||
// We can't hit ourselves
|
||||
if (i == playerTurn) return false;
|
||||
else
|
||||
{
|
||||
// We set the impact point
|
||||
player[playerTurn].impactPoint.x = ball.position.x;
|
||||
player[playerTurn].impactPoint.y = ball.position.y + ball.radius;
|
||||
|
||||
// We destroy the player
|
||||
player[i].isAlive = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Building collision
|
||||
// NOTE: We only check building collision if we are not inside an explosion
|
||||
for (int i = 0; i < MAX_BUILDINGS; i++)
|
||||
{
|
||||
if (CheckCollisionCircles(ball.position, ball.radius, explosion[i].position, explosion[i].radius - ball.radius))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < MAX_BUILDINGS; i++)
|
||||
{
|
||||
if (CheckCollisionCircleRec(ball.position, ball.radius, building[i].rectangle))
|
||||
{
|
||||
// We set the impact point
|
||||
player[playerTurn].impactPoint.x = ball.position.x;
|
||||
player[playerTurn].impactPoint.y = ball.position.y + ball.radius;
|
||||
|
||||
// We create an explosion
|
||||
explosion[explosionNumber].position = player[playerTurn].impactPoint;
|
||||
explosion[explosionNumber].active = true;
|
||||
explosionNumber++;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
cmake_minimum_required(VERSION 2.6)
|
||||
project(just_do)
|
||||
|
||||
# Grab the screens
|
||||
file(GLOB screen_sources "screens/*.c")
|
||||
|
||||
# Executable & linking
|
||||
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.c ${screen_sources})
|
||||
if (NOT TARGET raylib)
|
||||
find_package(raylib 2.0 REQUIRED)
|
||||
endif()
|
||||
target_link_libraries(${PROJECT_NAME} raylib)
|
||||
|
||||
# Resources
|
||||
# Copy all of the resource files to the destination
|
||||
file(COPY "resources/" DESTINATION "resources/")
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
|
||||
This game sources are licensed under an unmodified zlib/libpng license,
|
||||
which is an OSI-certified, BSD-like license:
|
||||
|
||||
Copyright (c) 2013-2017 Ramon Santamaria (@raysan5)
|
||||
|
||||
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.
|
||||
|
|
@ -1,413 +0,0 @@
|
|||
#**************************************************************************************************
|
||||
#
|
||||
# raylib makefile for Desktop platforms, Raspberry Pi, Android and HTML5
|
||||
#
|
||||
# Copyright (c) 2013-2020 Ramon Santamaria (@raysan5)
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
#**************************************************************************************************
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
# Define required raylib variables
|
||||
PROJECT_NAME ?= just_do
|
||||
RAYLIB_VERSION ?= 3.0.0
|
||||
RAYLIB_API_VERSION ?= 3
|
||||
RAYLIB_PATH ?= C:\GitHub\raylib
|
||||
|
||||
# Define default options
|
||||
|
||||
# One of PLATFORM_DESKTOP, PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
|
||||
PLATFORM ?= PLATFORM_DESKTOP
|
||||
|
||||
# Locations of your newly installed library and associated headers. See ../src/Makefile
|
||||
# On Linux, if you have installed raylib but cannot compile the examples, check that
|
||||
# the *_INSTALL_PATH values here are the same as those in src/Makefile or point to known locations.
|
||||
# To enable system-wide compile-time and runtime linking to libraylib.so, run ../src/$ sudo make install RAYLIB_LIBTYPE_SHARED.
|
||||
# To enable compile-time linking to a special version of libraylib.so, change these variables here.
|
||||
# To enable runtime linking to a special version of libraylib.so, see EXAMPLE_RUNTIME_PATH below.
|
||||
# If there is a libraylib in both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH, at runtime,
|
||||
# the library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over the one at RAYLIB_INSTALL_PATH.
|
||||
# RAYLIB_INSTALL_PATH should be the desired full path to libraylib. No relative paths.
|
||||
DESTDIR ?= /usr/local
|
||||
RAYLIB_INSTALL_PATH ?= $(DESTDIR)/lib
|
||||
# RAYLIB_H_INSTALL_PATH locates the installed raylib header and associated source files.
|
||||
RAYLIB_H_INSTALL_PATH ?= $(DESTDIR)/include
|
||||
|
||||
# Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
|
||||
RAYLIB_LIBTYPE ?= STATIC
|
||||
|
||||
# Build mode for project: DEBUG or RELEASE
|
||||
BUILD_MODE ?= RELEASE
|
||||
|
||||
# Use external GLFW library instead of rglfw module
|
||||
# TODO: Review usage on Linux. Target version of choice. Switch on -lglfw or -lglfw3
|
||||
USE_EXTERNAL_GLFW ?= FALSE
|
||||
|
||||
# Use Wayland display server protocol on Linux desktop
|
||||
# by default it uses X11 windowing system
|
||||
USE_WAYLAND_DISPLAY ?= FALSE
|
||||
|
||||
# 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
|
||||
else
|
||||
UNAMEOS=$(shell uname)
|
||||
ifeq ($(UNAMEOS),Linux)
|
||||
PLATFORM_OS=LINUX
|
||||
endif
|
||||
ifeq ($(UNAMEOS),FreeBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),OpenBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),NetBSD)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),DragonFly)
|
||||
PLATFORM_OS=BSD
|
||||
endif
|
||||
ifeq ($(UNAMEOS),Darwin)
|
||||
PLATFORM_OS=OSX
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
UNAMEOS=$(shell uname)
|
||||
ifeq ($(UNAMEOS),Linux)
|
||||
PLATFORM_OS=LINUX
|
||||
endif
|
||||
endif
|
||||
|
||||
# RAYLIB_PATH adjustment for different platforms.
|
||||
# If using GNU make, we can get the full path to the top of the tree. Windows? BSD?
|
||||
# Required for ldconfig or other tools that do not perform path expansion.
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
RAYLIB_PREFIX ?= ..
|
||||
RAYLIB_PATH = $(realpath $(RAYLIB_PREFIX))
|
||||
endif
|
||||
endif
|
||||
# Default path for raylib on Raspberry Pi, if installed in different path, update it!
|
||||
# This is not currently used by src/Makefile. Not sure of its origin or usage. Refer to wiki.
|
||||
# TODO: update install: target in src/Makefile for RPI, consider relation to LINUX.
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
RAYLIB_PATH ?= /home/pi/raylib
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# Emscripten required variables
|
||||
EMSDK_PATH ?= C:/emsdk
|
||||
EMSCRIPTEN_PATH ?= $(EMSDK_PATH)/fastcomp/emscripten
|
||||
CLANG_PATH = $(EMSDK_PATH)/fastcomp/bin
|
||||
PYTHON_PATH = $(EMSDK_PATH)/python/2.7.13.1_64bit/python-2.7.13.amd64
|
||||
NODE_PATH = $(EMSDK_PATH)/node/12.9.1_64bit/bin
|
||||
export PATH = $(EMSDK_PATH);$(EMSCRIPTEN_PATH);$(CLANG_PATH);$(NODE_PATH);$(PYTHON_PATH);C:\raylib\MinGW\bin:$$(PATH)
|
||||
endif
|
||||
|
||||
# Define raylib release directory for compiled library.
|
||||
# RAYLIB_RELEASE_PATH points to provided binaries or your freshly built version
|
||||
RAYLIB_RELEASE_PATH ?= $(RAYLIB_PATH)/src
|
||||
|
||||
# EXAMPLE_RUNTIME_PATH embeds a custom runtime location of libraylib.so or other desired libraries
|
||||
# into each example binary compiled with RAYLIB_LIBTYPE=SHARED. It defaults to RAYLIB_RELEASE_PATH
|
||||
# so that these examples link at runtime with your version of libraylib.so in ../release/libs/linux
|
||||
# without formal installation from ../src/Makefile. It aids portability and is useful if you have
|
||||
# multiple versions of raylib, have raylib installed to a non-standard location, or want to
|
||||
# bundle libraylib.so with your game. Change it to your liking.
|
||||
# NOTE: If, at runtime, there is a libraylib.so at both EXAMPLE_RUNTIME_PATH and RAYLIB_INSTALL_PATH,
|
||||
# The library at EXAMPLE_RUNTIME_PATH, if present, will take precedence over RAYLIB_INSTALL_PATH,
|
||||
# Implemented for LINUX below with CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
|
||||
# To see the result, run readelf -d core/core_basic_window; looking at the RPATH or RUNPATH attribute.
|
||||
# To see which libraries a built example is linking to, ldd core/core_basic_window;
|
||||
# Look for libraylib.so.1 => $(RAYLIB_INSTALL_PATH)/libraylib.so.1 or similar listing.
|
||||
EXAMPLE_RUNTIME_PATH ?= $(RAYLIB_RELEASE_PATH)
|
||||
|
||||
# Define default C compiler: gcc
|
||||
# NOTE: define g++ compiler if using C++
|
||||
CC = gcc
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
# OSX default compiler
|
||||
CC = clang
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# FreeBSD, OpenBSD, NetBSD, DragonFly default compiler
|
||||
CC = clang
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
ifeq ($(USE_RPI_CROSS_COMPILER),TRUE)
|
||||
# Define RPI cross-compiler
|
||||
#CC = armv6j-hardfloat-linux-gnueabi-gcc
|
||||
CC = $(RPI_TOOLCHAIN)/bin/arm-linux-gnueabihf-gcc
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# HTML5 emscripten compiler
|
||||
# WARNING: To compile to HTML5, code must be redesigned
|
||||
# to use emscripten.h and emscripten_set_main_loop()
|
||||
CC = emcc
|
||||
endif
|
||||
|
||||
# Define default make program: Mingw32-make
|
||||
MAKE = mingw32-make
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
MAKE = make
|
||||
endif
|
||||
endif
|
||||
|
||||
# Define compiler flags:
|
||||
# -O1 defines optimization level
|
||||
# -g include debug information on compilation
|
||||
# -s strip unnecessary data from build
|
||||
# -Wall turns on most, but not all, compiler warnings
|
||||
# -std=c99 defines C language mode (standard C from 1999 revision)
|
||||
# -std=gnu99 defines C language mode (GNU C from 1999 revision)
|
||||
# -Wno-missing-braces ignore invalid warning (GCC bug 53119)
|
||||
# -D_DEFAULT_SOURCE use with -std=c99 on Linux and PLATFORM_WEB, required for timespec
|
||||
CFLAGS += -Wall -std=c99 -D_DEFAULT_SOURCE -Wno-missing-braces
|
||||
|
||||
ifeq ($(BUILD_MODE),DEBUG)
|
||||
CFLAGS += -g
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
CFLAGS += -s ASSERTIONS=1 --profiling
|
||||
endif
|
||||
else
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
CFLAGS += -Os
|
||||
else
|
||||
CFLAGS += -s -O1
|
||||
endif
|
||||
endif
|
||||
|
||||
# Additional flags for compiler (if desired)
|
||||
#CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
ifeq ($(RAYLIB_LIBTYPE),STATIC)
|
||||
CFLAGS += -D_DEFAULT_SOURCE
|
||||
endif
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
# Explicitly enable runtime link to libraylib.so
|
||||
CFLAGS += -Wl,-rpath,$(EXAMPLE_RUNTIME_PATH)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
CFLAGS += -std=gnu99
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# -Os # size optimization
|
||||
# -O2 # optimization level 2, if used, also set --memory-init-file 0
|
||||
# -s USE_GLFW=3 # Use glfw3 library (context/input management)
|
||||
# -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing -> WARNING: Audio buffers could FAIL!
|
||||
# -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
|
||||
# -s USE_PTHREADS=1 # multithreading support
|
||||
# -s WASM=0 # disable Web Assembly, emitted by default
|
||||
# -s EMTERPRETIFY=1 # enable emscripten code interpreter (very slow)
|
||||
# -s EMTERPRETIFY_ASYNC=1 # support synchronous loops by emterpreter
|
||||
# -s FORCE_FILESYSTEM=1 # force filesystem to load/save files data
|
||||
# -s ASSERTIONS=1 # enable runtime checks for common memory allocation errors (-O1 and above turn it off)
|
||||
# --profiling # include information for code profiling
|
||||
# --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
|
||||
# --preload-file resources # specify a resources folder for data compilation
|
||||
CFLAGS += -s USE_GLFW=3 -s TOTAL_MEMORY=67108864 --preload-file resources
|
||||
|
||||
# Define a custom shell .html and output extension
|
||||
CFLAGS += --shell-file $(RAYLIB_PATH)/src/shell.html
|
||||
EXT = .html
|
||||
endif
|
||||
|
||||
# Define include paths for required headers
|
||||
# NOTE: Several external required libraries (stb and others)
|
||||
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external
|
||||
|
||||
# Define additional directories containing required header files
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
# RPI required libraries
|
||||
INCLUDE_PATHS += -I/opt/vc/include
|
||||
INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux
|
||||
INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Consider -L$(RAYLIB_H_INSTALL_PATH)
|
||||
INCLUDE_PATHS += -I/usr/local/include
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Reset everything.
|
||||
# Precedence: immediately local, installed version, raysan5 provided libs -I$(RAYLIB_H_INSTALL_PATH) -I$(RAYLIB_PATH)/release/include
|
||||
INCLUDE_PATHS = -I$(RAYLIB_H_INSTALL_PATH) -isystem. -isystem$(RAYLIB_PATH)/src -isystem$(RAYLIB_PATH)/release/include -isystem$(RAYLIB_PATH)/src/external
|
||||
endif
|
||||
endif
|
||||
|
||||
# Define library paths containing required libs.
|
||||
LDFLAGS = -L. -L$(RAYLIB_RELEASE_PATH) -L$(RAYLIB_PATH)/src
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
# resource file contains windows executable icon and properties
|
||||
LDFLAGS += $(RAYLIB_PATH)/src/raylib.rc.data
|
||||
# -Wl,--subsystem,windows hides the console window
|
||||
ifeq ($(BUILD_MODE), RELEASE)
|
||||
LDFLAGS += -Wl,--subsystem,windows
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Consider -L$(RAYLIB_INSTALL_PATH)
|
||||
LDFLAGS += -L. -Lsrc -L/usr/local/lib
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Reset everything.
|
||||
# Precedence: immediately local, installed version, raysan5 provided libs
|
||||
LDFLAGS = -L. -L$(RAYLIB_INSTALL_PATH) -L$(RAYLIB_RELEASE_PATH)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
LDFLAGS += -L/opt/vc/lib
|
||||
endif
|
||||
|
||||
# Define any libraries required on linking
|
||||
# if you want to link libraries (libname.so or libname.a), use the -lname
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
# Libraries for Windows desktop compilation
|
||||
# NOTE: WinMM library required to set high-res timer resolution
|
||||
LDLIBS = -lraylib -lopengl32 -lgdi32 -lwinmm
|
||||
# Required for physac examples
|
||||
LDLIBS += -static -lpthread
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
# Libraries for Debian GNU/Linux desktop compiling
|
||||
# NOTE: Required packages: libegl1-mesa-dev
|
||||
LDLIBS = -lraylib -lGL -lm -lpthread -ldl -lrt
|
||||
|
||||
# On X11 requires also below libraries
|
||||
LDLIBS += -lX11
|
||||
# NOTE: It seems additional libraries are not required any more, latest GLFW just dlopen them
|
||||
#LDLIBS += -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||
|
||||
# On Wayland windowing system, additional libraries requires
|
||||
ifeq ($(USE_WAYLAND_DISPLAY),TRUE)
|
||||
LDLIBS += -lwayland-client -lwayland-cursor -lwayland-egl -lxkbcommon
|
||||
endif
|
||||
# Explicit link to libc
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
LDLIBS += -lc
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
# Libraries for OSX 10.9 desktop compiling
|
||||
# NOTE: Required packages: libopenal-dev libegl1-mesa-dev
|
||||
LDLIBS = -lraylib -framework OpenGL -framework Cocoa -framework IOKit -framework CoreAudio -framework CoreVideo
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),BSD)
|
||||
# Libraries for FreeBSD, OpenBSD, NetBSD, DragonFly desktop compiling
|
||||
# NOTE: Required packages: mesa-libs
|
||||
LDLIBS = -lraylib -lGL -lpthread -lm
|
||||
|
||||
# On XWindow requires also below libraries
|
||||
LDLIBS += -lX11 -lXrandr -lXinerama -lXi -lXxf86vm -lXcursor
|
||||
endif
|
||||
ifeq ($(USE_EXTERNAL_GLFW),TRUE)
|
||||
# NOTE: It could require additional packages installed: libglfw3-dev
|
||||
LDLIBS += -lglfw
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
# Libraries for Raspberry Pi compiling
|
||||
# NOTE: Required packages: libasound2-dev (ALSA)
|
||||
LDLIBS = -lraylib -lbrcmGLESv2 -lbrcmEGL -lpthread -lrt -lm -lbcm_host -ldl
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# Libraries for web (HTML5) compiling
|
||||
LDLIBS = $(RAYLIB_RELEASE_PATH)/libraylib.bc
|
||||
endif
|
||||
|
||||
# Define all source files required
|
||||
PROJECT_SOURCE_FILES ?= \
|
||||
just_do.c \
|
||||
screens/screen_logo.c \
|
||||
screens/screen_level00.c \
|
||||
screens/screen_level01.c \
|
||||
screens/screen_level02.c \
|
||||
screens/screen_level03.c \
|
||||
screens/screen_level04.c \
|
||||
screens/screen_level05.c \
|
||||
screens/screen_level06.c \
|
||||
screens/screen_level07.c \
|
||||
screens/screen_level08.c \
|
||||
screens/screen_level09.c
|
||||
|
||||
# Define all object files from source files
|
||||
OBJS = $(patsubst %.c, %.o, $(PROJECT_SOURCE_FILES))
|
||||
|
||||
# For Android platform we call a custom Makefile.Android
|
||||
ifeq ($(PLATFORM),PLATFORM_ANDROID)
|
||||
MAKEFILE_PARAMS = -f Makefile.Android
|
||||
export PROJECT_NAME
|
||||
export PROJECT_SOURCE_FILES
|
||||
else
|
||||
MAKEFILE_PARAMS = $(PROJECT_NAME)
|
||||
endif
|
||||
|
||||
# Default target entry
|
||||
# NOTE: We call this Makefile target or Makefile.Android target
|
||||
all:
|
||||
$(MAKE) $(MAKEFILE_PARAMS)
|
||||
|
||||
# Project target defined by PROJECT_NAME
|
||||
$(PROJECT_NAME): $(OBJS)
|
||||
$(CC) -o $(PROJECT_NAME)$(EXT) $(OBJS) $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
|
||||
|
||||
# Compile source files
|
||||
# NOTE: This pattern will compile every module defined on $(OBJS)
|
||||
%.o: %.c
|
||||
$(CC) -c $< -o $@ $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
|
||||
|
||||
# Clean everything
|
||||
clean:
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||
del *.o *.exe /s
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),LINUX)
|
||||
find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable|x-pie-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -fv
|
||||
endif
|
||||
ifeq ($(PLATFORM_OS),OSX)
|
||||
find . -type f -perm +ugo+x -delete
|
||||
rm -f *.o
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
find . -type f -executable -delete
|
||||
rm -fv *.o
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
del *.o *.html *.js
|
||||
endif
|
||||
@echo Cleaning done
|
||||
|
||||
|
|
@ -1,300 +0,0 @@
|
|||
#**************************************************************************************************
|
||||
#
|
||||
# raylib makefile for Android project (APK building)
|
||||
#
|
||||
# Copyright (c) 2017 Ramon Santamaria (@raysan5)
|
||||
#
|
||||
# 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 required raylib variables
|
||||
PLATFORM ?= PLATFORM_ANDROID
|
||||
RAYLIB_PATH ?= ..\..
|
||||
|
||||
# Define Android architecture (armeabi-v7a, arm64-v8a, x86, x86-64) and API version
|
||||
ANDROID_ARCH ?= ARM
|
||||
ANDROID_API_VERSION = 21
|
||||
ifeq ($(ANDROID_ARCH),ARM)
|
||||
ANDROID_ARCH_NAME = armeabi-v7a
|
||||
endif
|
||||
ifeq ($(ANDROID_ARCH),ARM64)
|
||||
ANDROID_ARCH_NAME = arm64-v8a
|
||||
endif
|
||||
|
||||
# Required path variables
|
||||
# NOTE: JAVA_HOME must be set to JDK
|
||||
JAVA_HOME ?= C:/JavaJDK
|
||||
ANDROID_HOME = C:/android-sdk
|
||||
ANDROID_TOOLCHAIN = C:/android_toolchain_$(ANDROID_ARCH)_API$(ANDROID_API_VERSION)
|
||||
ANDROID_BUILD_TOOLS = $(ANDROID_HOME)/build-tools/28.0.1
|
||||
ANDROID_PLATFORM_TOOLS = $(ANDROID_HOME)/platform-tools
|
||||
|
||||
# Android project configuration variables
|
||||
PROJECT_NAME ?= raylib_game
|
||||
PROJECT_LIBRARY_NAME ?= main
|
||||
PROJECT_BUILD_PATH ?= android.$(PROJECT_NAME)
|
||||
PROJECT_RESOURCES_PATH ?= resources
|
||||
PROJECT_SOURCE_FILES ?= raylib_game.c
|
||||
|
||||
# Some source files are placed in directories, when compiling to some
|
||||
# output directory other than source, that directory must pre-exist.
|
||||
# Here we get a list of required folders that need to be created on
|
||||
# code output folder $(PROJECT_BUILD_PATH)\obj to avoid GCC errors.
|
||||
PROJECT_SOURCE_DIRS = $(sort $(dir $(PROJECT_SOURCE_FILES)))
|
||||
|
||||
# Android app configuration variables
|
||||
APP_LABEL_NAME ?= rGame
|
||||
APP_COMPANY_NAME ?= raylib
|
||||
APP_PRODUCT_NAME ?= rgame
|
||||
APP_VERSION_CODE ?= 1
|
||||
APP_VERSION_NAME ?= 1.0
|
||||
APP_ICON_LDPI ?= $(RAYLIB_PATH)\logo\raylib_36x36.png
|
||||
APP_ICON_MDPI ?= $(RAYLIB_PATH)\logo\raylib_48x48.png
|
||||
APP_ICON_HDPI ?= $(RAYLIB_PATH)\logo\raylib_72x72.png
|
||||
APP_SCREEN_ORIENTATION ?= landscape
|
||||
APP_KEYSTORE_PASS ?= raylib
|
||||
|
||||
# Library type used for raylib: STATIC (.a) or SHARED (.so/.dll)
|
||||
RAYLIB_LIBTYPE ?= STATIC
|
||||
|
||||
# Library path for libraylib.a/libraylib.so
|
||||
RAYLIB_LIB_PATH = $(RAYLIB_PATH)\src
|
||||
|
||||
# Shared libs must be added to APK if required
|
||||
# NOTE: Generated NativeLoader.java automatically load those libraries
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
PROJECT_SHARED_LIBS = lib/$(ANDROID_ARCH_NAME)/libraylib.so
|
||||
endif
|
||||
|
||||
# Compiler and archiver
|
||||
# NOTE: GCC is being deprecated in Android NDK r16
|
||||
ifeq ($(ANDROID_ARCH),ARM)
|
||||
CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-clang
|
||||
AR = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-ar
|
||||
endif
|
||||
ifeq ($(ANDROID_ARCH),ARM64)
|
||||
CC = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-clang
|
||||
AR = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-ar
|
||||
endif
|
||||
|
||||
# Compiler flags for arquitecture
|
||||
ifeq ($(ANDROID_ARCH),ARM)
|
||||
CFLAGS = -std=c99 -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
|
||||
endif
|
||||
ifeq ($(ANDROID_ARCH),ARM64)
|
||||
CFLAGS = -std=c99 -target aarch64 -mfix-cortex-a53-835769
|
||||
endif
|
||||
# Compilation functions attributes options
|
||||
CFLAGS += -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC
|
||||
# Compiler options for the linker
|
||||
CFLAGS += -Wall -Wa,--noexecstack -Wformat -Werror=format-security -no-canonical-prefixes
|
||||
# Preprocessor macro definitions
|
||||
CFLAGS += -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=$(ANDROID_API_VERSION)
|
||||
|
||||
# Paths containing required header files
|
||||
INCLUDE_PATHS = -I. -I$(RAYLIB_PATH)/src -I$(RAYLIB_PATH)/src/external/android/native_app_glue
|
||||
|
||||
# Linker options
|
||||
LDFLAGS = -Wl,-soname,lib$(PROJECT_LIBRARY_NAME).so -Wl,--exclude-libs,libatomic.a
|
||||
LDFLAGS += -Wl,--build-id -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--warn-shared-textrel -Wl,--fatal-warnings
|
||||
# Force linking of library module to define symbol
|
||||
LDFLAGS += -u ANativeActivity_onCreate
|
||||
# Library paths containing required libs
|
||||
LDFLAGS += -L. -L$(PROJECT_BUILD_PATH)/obj -L$(PROJECT_BUILD_PATH)/lib/$(ANDROID_ARCH_NAME) -L$(ANDROID_TOOLCHAIN)\sysroot\usr\lib
|
||||
|
||||
# Define any libraries to link into executable
|
||||
# if you want to link libraries (libname.so or libname.a), use the -lname
|
||||
LDLIBS = -lm -lc -lraylib -llog -landroid -lEGL -lGLESv2 -lOpenSLES -ldl
|
||||
|
||||
# Generate target objects list from PROJECT_SOURCE_FILES
|
||||
OBJS = $(patsubst %.c, $(PROJECT_BUILD_PATH)/obj/%.o, $(PROJECT_SOURCE_FILES))
|
||||
|
||||
# Android APK building process... some steps required...
|
||||
# NOTE: typing 'make' will invoke the default target entry called 'all',
|
||||
all: create_temp_project_dirs \
|
||||
copy_project_required_libs \
|
||||
copy_project_resources \
|
||||
generate_loader_script \
|
||||
generate_android_manifest \
|
||||
generate_apk_keystore \
|
||||
config_project_package \
|
||||
compile_project_code \
|
||||
compile_project_class \
|
||||
compile_project_class_dex \
|
||||
create_project_apk_package \
|
||||
sign_project_apk_package \
|
||||
zipalign_project_apk_package
|
||||
|
||||
# Create required temp directories for APK building
|
||||
create_temp_project_dirs:
|
||||
if not exist $(PROJECT_BUILD_PATH) mkdir $(PROJECT_BUILD_PATH)
|
||||
if not exist $(PROJECT_BUILD_PATH)\obj mkdir $(PROJECT_BUILD_PATH)\obj
|
||||
if not exist $(PROJECT_BUILD_PATH)\src mkdir $(PROJECT_BUILD_PATH)\src
|
||||
if not exist $(PROJECT_BUILD_PATH)\src\com mkdir $(PROJECT_BUILD_PATH)\src\com
|
||||
if not exist $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME) mkdir $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME)
|
||||
if not exist $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME)\$(APP_PRODUCT_NAME) mkdir $(PROJECT_BUILD_PATH)\src\com\$(APP_COMPANY_NAME)\$(APP_PRODUCT_NAME)
|
||||
if not exist $(PROJECT_BUILD_PATH)\lib mkdir $(PROJECT_BUILD_PATH)\lib
|
||||
if not exist $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME) mkdir $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME)
|
||||
if not exist $(PROJECT_BUILD_PATH)\bin mkdir $(PROJECT_BUILD_PATH)\bin
|
||||
if not exist $(PROJECT_BUILD_PATH)\res mkdir $(PROJECT_BUILD_PATH)\res
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\drawable-ldpi mkdir $(PROJECT_BUILD_PATH)\res\drawable-ldpi
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\drawable-mdpi mkdir $(PROJECT_BUILD_PATH)\res\drawable-mdpi
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\drawable-hdpi mkdir $(PROJECT_BUILD_PATH)\res\drawable-hdpi
|
||||
if not exist $(PROJECT_BUILD_PATH)\res\values mkdir $(PROJECT_BUILD_PATH)\res\values
|
||||
if not exist $(PROJECT_BUILD_PATH)\assets mkdir $(PROJECT_BUILD_PATH)\assets
|
||||
if not exist $(PROJECT_BUILD_PATH)\assets\$(PROJECT_RESOURCES_PATH) mkdir $(PROJECT_BUILD_PATH)\assets\$(PROJECT_RESOURCES_PATH)
|
||||
if not exist $(PROJECT_BUILD_PATH)\obj\screens mkdir $(PROJECT_BUILD_PATH)\obj\screens
|
||||
$(foreach dir, $(PROJECT_SOURCE_DIRS), $(call create_dir, $(dir)))
|
||||
|
||||
define create_dir
|
||||
if not exist $(PROJECT_BUILD_PATH)\obj\$(1) mkdir $(PROJECT_BUILD_PATH)\obj\$(1)
|
||||
endef
|
||||
|
||||
# Copy required shared libs for integration into APK
|
||||
# NOTE: If using shared libs they are loaded by generated NativeLoader.java
|
||||
copy_project_required_libs:
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
copy /Y $(RAYLIB_LIB_PATH)\libraylib.so $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME)\libraylib.so
|
||||
endif
|
||||
ifeq ($(RAYLIB_LIBTYPE),STATIC)
|
||||
copy /Y $(RAYLIB_LIB_PATH)\libraylib.a $(PROJECT_BUILD_PATH)\lib\$(ANDROID_ARCH_NAME)\libraylib.a
|
||||
endif
|
||||
|
||||
# Copy project required resources: strings.xml, icon.png, assets
|
||||
# NOTE: Required strings.xml is generated and game resources are copied to assets folder
|
||||
# TODO: Review xcopy usage, it can not be found in some systems!
|
||||
copy_project_resources:
|
||||
copy $(APP_ICON_LDPI) $(PROJECT_BUILD_PATH)\res\drawable-ldpi\icon.png /Y
|
||||
copy $(APP_ICON_MDPI) $(PROJECT_BUILD_PATH)\res\drawable-mdpi\icon.png /Y
|
||||
copy $(APP_ICON_HDPI) $(PROJECT_BUILD_PATH)\res\drawable-hdpi\icon.png /Y
|
||||
@echo ^<?xml version="1.0" encoding="utf-8"^?^> > $(PROJECT_BUILD_PATH)/res/values/strings.xml
|
||||
@echo ^<resources^>^<string name="app_name"^>$(APP_LABEL_NAME)^</string^>^</resources^> >> $(PROJECT_BUILD_PATH)/res/values/strings.xml
|
||||
if exist $(PROJECT_RESOURCES_PATH) C:\Windows\System32\xcopy $(PROJECT_RESOURCES_PATH) $(PROJECT_BUILD_PATH)\assets\$(PROJECT_RESOURCES_PATH) /Y /E /F
|
||||
|
||||
# Generate NativeLoader.java to load required shared libraries
|
||||
# NOTE: Probably not the bet way to generate this file... but it works.
|
||||
generate_loader_script:
|
||||
@echo package com.$(APP_COMPANY_NAME).$(APP_PRODUCT_NAME); > $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo. >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo public class NativeLoader extends android.app.NativeActivity { >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo static { >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
ifeq ($(RAYLIB_LIBTYPE),SHARED)
|
||||
@echo System.loadLibrary("raylib"); >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
endif
|
||||
@echo System.loadLibrary("$(PROJECT_LIBRARY_NAME)"); >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo } >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
@echo } >> $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
|
||||
# Generate AndroidManifest.xml with all the required options
|
||||
# NOTE: Probably not the bet way to generate this file... but it works.
|
||||
generate_android_manifest:
|
||||
@echo ^<?xml version="1.0" encoding="utf-8"^?^> > $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<manifest xmlns:android="http://schemas.android.com/apk/res/android" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo package="com.$(APP_COMPANY_NAME).$(APP_PRODUCT_NAME)" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:versionCode="$(APP_VERSION_CODE)" android:versionName="$(APP_VERSION_NAME)" ^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<uses-sdk android:minSdkVersion="$(ANDROID_API_VERSION)" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<uses-feature android:glEsVersion="0x00020000" android:required="true" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<application android:allowBackup="false" android:label="@string/app_name" android:icon="@drawable/icon" ^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<activity android:name="com.$(APP_COMPANY_NAME).$(APP_PRODUCT_NAME).NativeLoader" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:configChanges="orientation|keyboardHidden|screenSize" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:screenOrientation="$(APP_SCREEN_ORIENTATION)" android:launchMode="singleTask" >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo android:clearTaskOnLaunch="true"^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<meta-data android:name="android.app.lib_name" android:value="$(PROJECT_LIBRARY_NAME)" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<intent-filter^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<action android:name="android.intent.action.MAIN" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^<category android:name="android.intent.category.LAUNCHER" /^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</intent-filter^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</activity^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</application^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
@echo ^</manifest^> >> $(PROJECT_BUILD_PATH)/AndroidManifest.xml
|
||||
|
||||
# Generate storekey for APK signing: $(PROJECT_NAME).keystore
|
||||
# NOTE: Configure here your Distinguished Names (-dname) if required!
|
||||
generate_apk_keystore:
|
||||
if not exist $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore $(JAVA_HOME)/bin/keytool -genkeypair -validity 1000 -dname "CN=$(APP_COMPANY_NAME),O=Android,C=ES" -keystore $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore -storepass $(APP_KEYSTORE_PASS) -keypass $(APP_KEYSTORE_PASS) -alias $(PROJECT_NAME)Key -keyalg RSA
|
||||
|
||||
# Config project package and resource using AndroidManifest.xml and res/values/strings.xml
|
||||
# NOTE: Generates resources file: src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/R.java
|
||||
config_project_package:
|
||||
$(ANDROID_BUILD_TOOLS)/aapt package -f -m -S $(PROJECT_BUILD_PATH)/res -J $(PROJECT_BUILD_PATH)/src -M $(PROJECT_BUILD_PATH)/AndroidManifest.xml -I $(ANDROID_HOME)/platforms/android-$(ANDROID_API_VERSION)/android.jar
|
||||
|
||||
# Compile native_app_glue code as static library: obj/libnative_app_glue.a
|
||||
compile_native_app_glue:
|
||||
$(CC) -c $(RAYLIB_PATH)/src/external/android/native_app_glue/android_native_app_glue.c -o $(PROJECT_BUILD_PATH)/obj/native_app_glue.o $(CFLAGS)
|
||||
$(AR) rcs $(PROJECT_BUILD_PATH)/obj/libnative_app_glue.a $(PROJECT_BUILD_PATH)/obj/native_app_glue.o
|
||||
|
||||
# Compile project code into a shared library: lib/lib$(PROJECT_LIBRARY_NAME).so
|
||||
compile_project_code: $(OBJS)
|
||||
$(CC) -o $(PROJECT_BUILD_PATH)/lib/$(ANDROID_ARCH_NAME)/lib$(PROJECT_LIBRARY_NAME).so $(OBJS) -shared $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
# Compile all .c files required into object (.o) files
|
||||
# NOTE: Those files will be linked into a shared library
|
||||
$(PROJECT_BUILD_PATH)/obj/%.o:%.c
|
||||
$(CC) -c $^ -o $@ $(INCLUDE_PATHS) $(CFLAGS) --sysroot=$(ANDROID_TOOLCHAIN)/sysroot
|
||||
|
||||
# Compile project .java code into .class (Java bytecode)
|
||||
compile_project_class:
|
||||
$(JAVA_HOME)/bin/javac -verbose -source 1.7 -target 1.7 -d $(PROJECT_BUILD_PATH)/obj -bootclasspath $(JAVA_HOME)/jre/lib/rt.jar -classpath $(ANDROID_HOME)/platforms/android-$(ANDROID_API_VERSION)/android.jar;$(PROJECT_BUILD_PATH)/obj -sourcepath $(PROJECT_BUILD_PATH)/src $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/R.java $(PROJECT_BUILD_PATH)/src/com/$(APP_COMPANY_NAME)/$(APP_PRODUCT_NAME)/NativeLoader.java
|
||||
|
||||
# Compile .class files into Dalvik executable bytecode (.dex)
|
||||
# NOTE: Since Android 5.0, Dalvik interpreter (JIT) has been replaced by ART (AOT)
|
||||
compile_project_class_dex:
|
||||
$(ANDROID_BUILD_TOOLS)/dx --verbose --dex --output=$(PROJECT_BUILD_PATH)/bin/classes.dex $(PROJECT_BUILD_PATH)/obj
|
||||
|
||||
# Create Android APK package: bin/$(PROJECT_NAME).unsigned.apk
|
||||
# NOTE: Requires compiled classes.dex and lib$(PROJECT_LIBRARY_NAME).so
|
||||
# NOTE: Use -A resources to define additional directory in which to find raw asset files
|
||||
create_project_apk_package:
|
||||
$(ANDROID_BUILD_TOOLS)/aapt package -f -M $(PROJECT_BUILD_PATH)/AndroidManifest.xml -S $(PROJECT_BUILD_PATH)/res -A $(PROJECT_BUILD_PATH)/assets -I $(ANDROID_HOME)/platforms/android-$(ANDROID_API_VERSION)/android.jar -F $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).unsigned.apk $(PROJECT_BUILD_PATH)/bin
|
||||
cd $(PROJECT_BUILD_PATH) && $(ANDROID_BUILD_TOOLS)/aapt add bin/$(PROJECT_NAME).unsigned.apk lib/$(ANDROID_ARCH_NAME)/lib$(PROJECT_LIBRARY_NAME).so $(PROJECT_SHARED_LIBS)
|
||||
|
||||
# Create signed APK package using generated Key: bin/$(PROJECT_NAME).signed.apk
|
||||
sign_project_apk_package:
|
||||
$(JAVA_HOME)/bin/jarsigner -keystore $(PROJECT_BUILD_PATH)/$(PROJECT_NAME).keystore -storepass $(APP_KEYSTORE_PASS) -keypass $(APP_KEYSTORE_PASS) -signedjar $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).signed.apk $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).unsigned.apk $(PROJECT_NAME)Key
|
||||
|
||||
# Create zip-aligned APK package: $(PROJECT_NAME).apk
|
||||
zipalign_project_apk_package:
|
||||
$(ANDROID_BUILD_TOOLS)/zipalign -f 4 $(PROJECT_BUILD_PATH)/bin/$(PROJECT_NAME).signed.apk $(PROJECT_NAME).apk
|
||||
|
||||
# Install $(PROJECT_NAME).apk to default emulator/device
|
||||
# NOTE: Use -e (emulator) or -d (device) parameters if required
|
||||
install:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb install --abi $(ANDROID_ARCH_NAME) -rds $(PROJECT_NAME).apk
|
||||
|
||||
# Check supported ABI for the device (armeabi-v7a, arm64-v8a, x86, x86_64)
|
||||
check_device_abi:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb shell getprop ro.product.cpu.abi
|
||||
|
||||
# Monitorize output log coming from device, only raylib tag
|
||||
logcat:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat -c
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat raylib:V *:S
|
||||
|
||||
# Install and monitorize $(PROJECT_NAME).apk to default emulator/device
|
||||
deploy:
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb install -r $(PROJECT_NAME).apk
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat -c
|
||||
$(ANDROID_PLATFORM_TOOLS)/adb logcat raylib:V *:S
|
||||
|
||||
#$(ANDROID_PLATFORM_TOOLS)/adb logcat *:W
|
||||
|
||||
# Clean everything
|
||||
clean:
|
||||
del $(PROJECT_BUILD_PATH)\* /f /s /q
|
||||
rmdir $(PROJECT_BUILD_PATH) /s /q
|
||||
@echo Cleaning done
|
||||
|
|
@ -1,356 +0,0 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* JUST DO [GLOBAL GAME JAM 2015]
|
||||
*
|
||||
* Experimental puzzle game that lets the user try to find a logic
|
||||
* solution to different shape-color-based situations.
|
||||
*
|
||||
* This game has been created using raylib 1.6 (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"
|
||||
#include "screens/screens.h" // NOTE: Defines global variable: 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;
|
||||
Music music;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// 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 (Note windowTitle is unused on Android)
|
||||
//---------------------------------------------------------
|
||||
InitWindow(screenWidth, screenHeight, "JUST DO [GGJ15]");
|
||||
|
||||
// Load global data here (assets that must be available in all screens, i.e. fonts)
|
||||
InitAudioDevice();
|
||||
|
||||
levelWin = LoadSound("resources/win.wav");
|
||||
music = LoadMusicStream("resources/ambient.ogg");
|
||||
|
||||
// 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
|
||||
{
|
||||
UpdateDrawFrame();
|
||||
}
|
||||
#endif
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Unload all global loaded data (i.e. fonts) here!
|
||||
UnloadSound(levelWin);
|
||||
UnloadMusicStream(music);
|
||||
|
||||
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 (currentScreen != LOGO) UpdateMusicStream(music);
|
||||
|
||||
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(music);
|
||||
SetMusicVolume(music, 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();
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
|
@ -1,167 +0,0 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib - Standard Game template
|
||||
*
|
||||
* Level00 Screen Functions Definitions (Init, Update, Draw, Unload)
|
||||
*
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib - Standard Game template
|
||||
*
|
||||
* Level01 Screen Functions Definitions (Init, Update, Draw, Unload)
|
||||
*
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
|
@ -1,157 +0,0 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib - Standard Game template
|
||||
*
|
||||
* Level02 Screen Functions Definitions (Init, Update, Draw, Unload)
|
||||
*
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib - Standard Game template
|
||||
*
|
||||
* Level03 Screen Functions Definitions (Init, Update, Draw, Unload)
|
||||
*
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* 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;
|
||||
}
|
||||
|
|
@ -1,147 +0,0 @@
|
|||
/**********************************************************************************************
|
||||
*
|
||||
* raylib - Standard Game template
|
||||
*
|
||||
* Level04 Screen Functions Definitions (Init, Update, Draw, Unload)
|
||||
*
|
||||
* Copyright (c) 2014 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* 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;
|
||||
}
|
||||