Initial commit.
This commit is contained in:
@@ -50,3 +50,10 @@ modules.order
|
|||||||
Module.symvers
|
Module.symvers
|
||||||
Mkfile.old
|
Mkfile.old
|
||||||
dkms.conf
|
dkms.conf
|
||||||
|
|
||||||
|
# Xmake
|
||||||
|
.xmake/
|
||||||
|
build/
|
||||||
|
|
||||||
|
# Clangd
|
||||||
|
.cache/
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"directory": "/home/jason/github/c_stuff/rlib_projects/ball_room",
|
||||||
|
"arguments": ["/usr/bin/gcc", "-c", "-m64", "-fvisibility=hidden", "-Wall", "-Werror", "-O3", "-D_DEFAULT_SOURCE", "-D_BSD_SOURCE", "-DHAS_FCHOWN", "-DHAS_STICKY_DIR_BIT", "-isystem", "/home/jason/.xmake/packages/r/raygui/4.0/9d606ceee8cb49559023212a8fb08d54/include", "-isystem", "/home/jason/.xmake/packages/r/raylib/5.0/aeed26e13a7a466f9d7c7ad6dd3b75c2/include", "-DNDEBUG", "-o", "build/.objs/ball_room/linux/x86_64/release/src/main.c.o", "src/main.c"],
|
||||||
|
"file": "src/main.c"
|
||||||
|
}]
|
||||||
+1895
File diff suppressed because it is too large
Load Diff
+116
@@ -0,0 +1,116 @@
|
|||||||
|
#include "raylib.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#define STB_DS_IMPLEMENTATION
|
||||||
|
#include "libs/stb_ds.h"
|
||||||
|
|
||||||
|
#define WIN_WIDTH 1000.0
|
||||||
|
#define WIN_HEIGHT 800.0
|
||||||
|
#define BG CLITERAL(Color){0x18, 0x18, 0x18, 0xFF}
|
||||||
|
|
||||||
|
// Adjust gravity value for smoother fall
|
||||||
|
#define GRAVITY 1000.0f
|
||||||
|
#define MAX_SPEED 16.0f
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
Circle
|
||||||
|
} entity_type;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
Vector2 position;
|
||||||
|
Color color;
|
||||||
|
int size;
|
||||||
|
entity_type type;
|
||||||
|
} Entity;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
bool is_running;
|
||||||
|
Entity* entities;
|
||||||
|
} App;
|
||||||
|
|
||||||
|
void render_entities(Entity* entities, int count)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
switch(entities[i].type)
|
||||||
|
{
|
||||||
|
case Circle:
|
||||||
|
DrawCircle(entities[i].position.x, entities[i].position.y, entities[i].size, entities[i].color);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void update_entities(Entity* entities, int count, float deltaTime)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
// Calculate new position based on gravity and deltaTime
|
||||||
|
float fallSpeed = GRAVITY * deltaTime;
|
||||||
|
// Clamp the fall speed to prevent choppiness
|
||||||
|
if (fallSpeed > MAX_SPEED) fallSpeed = MAX_SPEED;
|
||||||
|
|
||||||
|
// Update the position of each entity
|
||||||
|
if(!(entities[i].position.y >= WIN_HEIGHT - entities[i].size))
|
||||||
|
{
|
||||||
|
entities[i].position.y += fallSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
|
||||||
|
bool is_paused = false;
|
||||||
|
|
||||||
|
Entity* entity_array = NULL;
|
||||||
|
|
||||||
|
Entity c = {
|
||||||
|
{ WIN_WIDTH / 2, 0 },
|
||||||
|
RED,
|
||||||
|
20,
|
||||||
|
Circle
|
||||||
|
};
|
||||||
|
arrput(entity_array,c);
|
||||||
|
|
||||||
|
App my_app = {
|
||||||
|
true,
|
||||||
|
entity_array
|
||||||
|
};
|
||||||
|
|
||||||
|
// raylib begin
|
||||||
|
// ---------------------------------------------
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT);
|
||||||
|
InitWindow(WIN_WIDTH, WIN_HEIGHT, "Ball Room");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
while(!WindowShouldClose())
|
||||||
|
{
|
||||||
|
float dt = GetFrameTime();
|
||||||
|
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
ClearBackground(BG);
|
||||||
|
|
||||||
|
// Inputs
|
||||||
|
if (IsKeyPressed(KEY_SPACE)) is_paused = !is_paused;
|
||||||
|
|
||||||
|
// Render app
|
||||||
|
render_entities(my_app.entities, arrlen(my_app.entities));
|
||||||
|
|
||||||
|
// Update app
|
||||||
|
if(!is_paused)
|
||||||
|
update_entities(my_app.entities, arrlen(my_app.entities), dt);
|
||||||
|
|
||||||
|
DrawFPS(10, 10);
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
// ---------------------------------------------
|
||||||
|
|
||||||
|
arrfree(entity_array);
|
||||||
|
CloseWindow();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
add_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
|
set_warnings("all", "error")
|
||||||
|
|
||||||
|
add_requires("raygui")
|
||||||
|
|
||||||
|
target("ball_room")
|
||||||
|
set_kind("binary")
|
||||||
|
add_files("src/*.c")
|
||||||
|
add_packages("raygui")
|
||||||
|
add_headerfiles("src/libs/*.h")
|
||||||
|
|
||||||
|
--
|
||||||
|
-- If you want to known more usage about xmake, please see https://xmake.io
|
||||||
|
--
|
||||||
|
-- ## FAQ
|
||||||
|
--
|
||||||
|
-- You can enter the project directory firstly before building project.
|
||||||
|
--
|
||||||
|
-- $ cd projectdir
|
||||||
|
--
|
||||||
|
-- 1. How to build project?
|
||||||
|
--
|
||||||
|
-- $ xmake
|
||||||
|
--
|
||||||
|
-- 2. How to configure project?
|
||||||
|
--
|
||||||
|
-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
|
||||||
|
--
|
||||||
|
-- 3. Where is the build output directory?
|
||||||
|
--
|
||||||
|
-- The default output directory is `./build` and you can configure the output directory.
|
||||||
|
--
|
||||||
|
-- $ xmake f -o outputdir
|
||||||
|
-- $ xmake
|
||||||
|
--
|
||||||
|
-- 4. How to run and debug target after building project?
|
||||||
|
--
|
||||||
|
-- $ xmake run [targetname]
|
||||||
|
-- $ xmake run -d [targetname]
|
||||||
|
--
|
||||||
|
-- 5. How to install target to the system directory or other output directory?
|
||||||
|
--
|
||||||
|
-- $ xmake install
|
||||||
|
-- $ xmake install -o installdir
|
||||||
|
--
|
||||||
|
-- 6. Add some frequently-used compilation flags in xmake.lua
|
||||||
|
--
|
||||||
|
-- @code
|
||||||
|
-- -- add debug and release modes
|
||||||
|
-- add_rules("mode.debug", "mode.release")
|
||||||
|
--
|
||||||
|
-- -- add macro definition
|
||||||
|
-- add_defines("NDEBUG", "_GNU_SOURCE=1")
|
||||||
|
--
|
||||||
|
-- -- set warning all as error
|
||||||
|
-- set_warnings("all", "error")
|
||||||
|
--
|
||||||
|
-- -- set language: c99, c++11
|
||||||
|
-- set_languages("c99", "c++11")
|
||||||
|
--
|
||||||
|
-- -- set optimization: none, faster, fastest, smallest
|
||||||
|
-- set_optimize("fastest")
|
||||||
|
--
|
||||||
|
-- -- add include search directories
|
||||||
|
-- add_includedirs("/usr/include", "/usr/local/include")
|
||||||
|
--
|
||||||
|
-- -- add link libraries and search directories
|
||||||
|
-- add_links("tbox")
|
||||||
|
-- add_linkdirs("/usr/local/lib", "/usr/lib")
|
||||||
|
--
|
||||||
|
-- -- add system link libraries
|
||||||
|
-- add_syslinks("z", "pthread")
|
||||||
|
--
|
||||||
|
-- -- add compilation and link flags
|
||||||
|
-- add_cxflags("-stdnolib", "-fno-strict-aliasing")
|
||||||
|
-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
|
||||||
|
--
|
||||||
|
-- @endcode
|
||||||
|
--
|
||||||
|
|
||||||
Reference in New Issue
Block a user