From 3e7d8b94f1a1349ccbae107b5a2aeac9fb77e6e2 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 16 Dec 2025 23:39:52 +0800 Subject: improve raylib tests --- .../native_app/raylib_particles/src/main.cpp | 81 ++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/projects/android/native_app/raylib_particles/src/main.cpp (limited to 'tests/projects/android/native_app/raylib_particles/src/main.cpp') diff --git a/tests/projects/android/native_app/raylib_particles/src/main.cpp b/tests/projects/android/native_app/raylib_particles/src/main.cpp new file mode 100644 index 000000000..41dd8bd4a --- /dev/null +++ b/tests/projects/android/native_app/raylib_particles/src/main.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include + +#define LOG_TAG "raydemo_particles" +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__) + +struct Particle { + Vector2 position; + Vector2 velocity; + Color color; + float size; + float life; +}; + +int main(int argc, char** argv) { + InitWindow(0, 0, "Raylib Particles"); + SetTargetFPS(60); + LOGD("raylib particles starting!"); + + std::vector particles; + + while (!WindowShouldClose()) { + // Update + bool inputActive = IsMouseButtonDown(MOUSE_BUTTON_LEFT) || GetTouchPointCount() > 0; + Vector2 pos; + + if (inputActive) { + pos = GetMousePosition(); + if (GetTouchPointCount() > 0) pos = GetTouchPosition(0); + } else { + // Auto emit when idle + double time = GetTime(); + pos.x = GetScreenWidth() / 2.0f + cos(time * 3.0f) * (GetScreenWidth() / 4.0f); + pos.y = GetScreenHeight() / 2.0f + sin(time * 2.0f) * (GetScreenHeight() / 4.0f); + } + + if (inputActive || GetRandomValue(0, 100) < 50) { + int count = inputActive ? 5 : 2; + for (int i = 0; i < count; i++) { + Particle p; + p.position = pos; + p.velocity = {(float)GetRandomValue(-200, 200) / 100.0f, (float)GetRandomValue(-200, 200) / 100.0f}; + p.color = (Color){(unsigned char)GetRandomValue(0, 255), (unsigned char)GetRandomValue(0, 255), (unsigned char)GetRandomValue(0, 255), 255}; + p.size = (float)GetRandomValue(5, 20); + p.life = 1.0f; + particles.push_back(p); + } + } + + for (auto it = particles.begin(); it != particles.end();) { + it->position.x += it->velocity.x * 5.0f; + it->position.y += it->velocity.y * 5.0f; + it->life -= 0.02f; + it->size *= 0.99f; + + if (it->life <= 0) { + it = particles.erase(it); + } else { + ++it; + } + } + + // Draw + BeginDrawing(); + ClearBackground(BLACK); + + for (const auto& p : particles) { + DrawCircleV(p.position, p.size, Fade(p.color, p.life)); + } + + DrawText("Touch to create particles!", 10, 40, 20, WHITE); + DrawFPS(10, 10); + + EndDrawing(); + } + + CloseWindow(); + return 0; +} -- cgit v1.3.1 From 427f50fa45d7015bd443fa2c0d059593c826d43f Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 16 Dec 2025 23:40:36 +0800 Subject: improve tests --- tests/projects/android/native_app/raylib_basic/src/main.cpp | 13 ++++++++++++- .../android/native_app/raylib_particles/src/main.cpp | 12 ++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'tests/projects/android/native_app/raylib_particles/src/main.cpp') diff --git a/tests/projects/android/native_app/raylib_basic/src/main.cpp b/tests/projects/android/native_app/raylib_basic/src/main.cpp index b160499b7..0094d9e3c 100644 --- a/tests/projects/android/native_app/raylib_basic/src/main.cpp +++ b/tests/projects/android/native_app/raylib_basic/src/main.cpp @@ -12,7 +12,18 @@ int main(int argc, char** argv) { while (!WindowShouldClose()) { BeginDrawing(); ClearBackground(BLACK); - DrawText("Hello, xmake for raylib android!", 250, 250, 25, BLUE); + + // Draw FPS + const char* fpsText = TextFormat("%2i FPS", GetFPS()); + int fpsWidth = MeasureText(fpsText, 40); + DrawText(fpsText, GetScreenWidth() / 2 - fpsWidth / 2, 30, 40, GREEN); + + // Draw centered text + int fontSize = 50; + const char* text = "Hello, xmake for raylib android!"; + int textWidth = MeasureText(text, fontSize); + DrawText(text, GetScreenWidth() / 2 - textWidth / 2, 100, fontSize, BLUE); + EndDrawing(); } diff --git a/tests/projects/android/native_app/raylib_particles/src/main.cpp b/tests/projects/android/native_app/raylib_particles/src/main.cpp index 41dd8bd4a..5bbfc90e8 100644 --- a/tests/projects/android/native_app/raylib_particles/src/main.cpp +++ b/tests/projects/android/native_app/raylib_particles/src/main.cpp @@ -70,8 +70,16 @@ int main(int argc, char** argv) { DrawCircleV(p.position, p.size, Fade(p.color, p.life)); } - DrawText("Touch to create particles!", 10, 40, 20, WHITE); - DrawFPS(10, 10); + // Draw FPS + const char* fpsText = TextFormat("%2i FPS", GetFPS()); + int fpsWidth = MeasureText(fpsText, 40); + DrawText(fpsText, GetScreenWidth() / 2 - fpsWidth / 2, 30, 40, GREEN); + + // Draw centered instructions + int fontSize = 40; + const char* text = "Touch to create particles!"; + int textWidth = MeasureText(text, fontSize); + DrawText(text, GetScreenWidth() / 2 - textWidth / 2, 80, fontSize, WHITE); EndDrawing(); } -- cgit v1.3.1