mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added more raylib examples.
This commit is contained in:
BIN
resources/examples/raylib/guy.iqm
Normal file
BIN
resources/examples/raylib/guy.iqm
Normal file
Binary file not shown.
BIN
resources/examples/raylib/guyanim.iqm
Normal file
BIN
resources/examples/raylib/guyanim.iqm
Normal file
Binary file not shown.
BIN
resources/examples/raylib/guytex.png
Normal file
BIN
resources/examples/raylib/guytex.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 295 KiB |
BIN
resources/examples/raylib/raybunny.png
Normal file
BIN
resources/examples/raylib/raybunny.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 466 B |
@@ -1,6 +1,3 @@
|
||||
module arkanoid;
|
||||
import raylib55;
|
||||
import std::math;
|
||||
/**
|
||||
*
|
||||
* raylib - classic game: arkanoid
|
||||
@@ -11,6 +8,9 @@ import std::math;
|
||||
* Copyright (c) 2015 Ramon Santamaria (@raysan5)
|
||||
*/
|
||||
|
||||
module arkanoid;
|
||||
import raylib55, std::math;
|
||||
|
||||
const int SCREEN_WIDTH = 800;
|
||||
const int SCREEN_HEIGHT = 450;
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
module arkanoid;
|
||||
import raylib55;
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [audio] example - module playing
|
||||
@@ -15,6 +13,8 @@ import raylib55;
|
||||
* converted to C3 by Christoffer Lerno
|
||||
*
|
||||
********************************************************************************************/
|
||||
module raylib_audio_module;
|
||||
import raylib55;
|
||||
|
||||
const MAX_CIRCLES = 64;
|
||||
|
||||
|
||||
112
resources/examples/raylib/raylib_models_animation_playing.c3
Normal file
112
resources/examples/raylib/raylib_models_animation_playing.c3
Normal file
@@ -0,0 +1,112 @@
|
||||
module raylib_models;
|
||||
import raylib55;
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - animation playing
|
||||
*
|
||||
* Example complexity rating: [★★☆☆] 2/4
|
||||
*
|
||||
* Example originally created with raylib 2.5, last time updated with raylib 3.5
|
||||
*
|
||||
* Example contributed by Culacant (@culacant) and reviewed by Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||
* BSD-like license that allows static linking with closed source software
|
||||
*
|
||||
* Copyright (c) 2019-2025 Culacant (@culacant) and Ramon Santamaria (@raysan5)
|
||||
* converted to C3 by Christoffer Lerno
|
||||
*
|
||||
********************************************************************************************
|
||||
*
|
||||
* NOTE: To export a model from blender, make sure it is not posed, the vertices need to be
|
||||
* in the same position as they would be in edit mode and the scale of your models is
|
||||
* set to 0. Scaling can be done from the export menu
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
fn int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int SCREEN_WIDTH = 800;
|
||||
const int SCREEN_HEIGHT = 450;
|
||||
|
||||
rl::init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [models] example - animation playing");
|
||||
|
||||
// Define the camera to look into our 3d world
|
||||
RLCamera camera = {
|
||||
.position = { .xyz = 10 }, // Camera position
|
||||
.target = { .xyz = 0 }, // Camera looking at point
|
||||
.up = { 0, 1, 0 }, // Camera up vector (rotation towards target)
|
||||
.fovy = 45, // Camera field-of-view Y
|
||||
.projection = PERSPECTIVE // Camera mode type
|
||||
};
|
||||
|
||||
RLModel model = rl::load_model("guy.iqm"); // Load the animated model mesh and basic data
|
||||
RLTexture2D texture = rl::load_texture("guytex.png"); // Load model texture and set material
|
||||
model.materials[0].set_texture(DIFFUSE, texture); // Set model material map texture
|
||||
|
||||
RLVector3 position; // Set model position to zero
|
||||
|
||||
// Load animation data
|
||||
RLModelAnimation[] anims = rl::load_model_animations("guyanim.iqm");
|
||||
int anim_frame_counter = 0;
|
||||
|
||||
rl::disable_cursor(); // Catch cursor
|
||||
rl::set_target_fps(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!rl::window_should_close()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
rl::update_camera(&camera, FIRST_PERSON);
|
||||
|
||||
// Play animation when spacebar is held down
|
||||
if (rl::is_key_down(SPACE))
|
||||
{
|
||||
anim_frame_counter++;
|
||||
rl::update_model_animation(model, anims[0], anim_frame_counter);
|
||||
if (anim_frame_counter >= anims[0].frame_count) anim_frame_counter = 0;
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl::@drawing()
|
||||
{
|
||||
rl::clear_background(rl::RAYWHITE);
|
||||
rl::@mode3d(camera)
|
||||
{
|
||||
rl::draw_model_ex(model, position, { 1, 0, 0 }, -90, (RLVector3)1, rl::WHITE);
|
||||
|
||||
foreach (RLTransform pose : anims[0].frame_poses[anim_frame_counter][:model.bone_count])
|
||||
{
|
||||
rl::draw_cube(pose.translation, 0.2f, 0.2f, 0.2f, rl::RED);
|
||||
}
|
||||
|
||||
rl::draw_grid(10, 1); // Draw a grid
|
||||
};
|
||||
|
||||
rl::draw_text("PRESS SPACE to PLAY MODEL ANIMATION", 10, 10, 20, rl::MAROON);
|
||||
rl::draw_text("(c) Guy IQM 3D model by @culacant", SCREEN_WIDTH - 200, SCREEN_HEIGHT - 20, 10, rl::GRAY);
|
||||
|
||||
};
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
rl::unload_texture(texture); // Unload texture
|
||||
rl::unload_model_animations(anims); // Unload model animations data
|
||||
rl::unload_model(model); // Unload model
|
||||
|
||||
rl::close_window(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
133
resources/examples/raylib/raylib_textures_bunnymark.c3
Normal file
133
resources/examples/raylib/raylib_textures_bunnymark.c3
Normal file
@@ -0,0 +1,133 @@
|
||||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [textures] example - bunnymark
|
||||
*
|
||||
* Example complexity rating: [★★★☆] 3/4
|
||||
*
|
||||
* Example originally created with raylib 1.6, last time updated with raylib 2.5
|
||||
*
|
||||
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
||||
* BSD-like license that allows static linking with closed source software
|
||||
*
|
||||
* Copyright (c) 2014-2025 Ramon Santamaria (@raysan5)
|
||||
* converted to C3 by Christoffer Lerno
|
||||
*
|
||||
********************************************************************************************/
|
||||
module raylib_audio_module;
|
||||
import raylib55;
|
||||
|
||||
const int MAX_BUNNIES = 50000; // 50K bunnies limit
|
||||
|
||||
// This is the maximum amount of elements (quads) per batch
|
||||
// NOTE: This value is defined in [rlgl] module and can be changed there
|
||||
const int MAX_BATCH_ELEMENTS = 8192;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Types and Structures Definition
|
||||
//----------------------------------------------------------------------------------
|
||||
struct Bunny
|
||||
{
|
||||
RLVector2 position;
|
||||
RLVector2 speed;
|
||||
RLColor color;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Program main entry point
|
||||
//------------------------------------------------------------------------------------
|
||||
fn int main()
|
||||
{
|
||||
// Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
const int SCREEN_WIDTH = 800;
|
||||
const int SCREEN_HEIGHT = 450;
|
||||
|
||||
rl::init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [textures] example - bunnymark");
|
||||
|
||||
// Load bunny texture
|
||||
RLTexture2D tex_bunny = rl::load_texture("raybunny.png");
|
||||
|
||||
Bunny[] bunnies = mem::alloc_array(Bunny, MAX_BUNNIES); // Bunnies array
|
||||
|
||||
int bunnies_count = 0; // Bunnies counter
|
||||
|
||||
rl::set_target_fps(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
// Main game loop
|
||||
while (!rl::window_should_close()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
if (rl::is_mouse_button_down(LEFT))
|
||||
{
|
||||
// Create more bunnies
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
if (bunnies_count < MAX_BUNNIES)
|
||||
{
|
||||
bunnies[bunnies_count] = {
|
||||
.position = rl::get_mouse_position(),
|
||||
.speed = { rl::get_random_value(-250, 250) / 60.0f, rl::get_random_value(-250, 250) / 60.0f },
|
||||
.color = { (char)rl::get_random_value(50, 240), (char)rl::get_random_value(80, 240), (char)rl::get_random_value(100, 240), 255 }
|
||||
};
|
||||
bunnies_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update bunnies
|
||||
foreach (&bunny : bunnies[:bunnies_count])
|
||||
{
|
||||
bunny.position += bunny.speed;
|
||||
if (bunny.position.x + tex_bunny.width / 2.0f > rl::get_screen_width()
|
||||
|| bunny.position.x + tex_bunny.width / 2.0f < 0)
|
||||
{
|
||||
bunny.speed.x *= -1;
|
||||
}
|
||||
if (bunny.position.y + tex_bunny.height / 2.0f > rl::get_screen_height()
|
||||
|| bunny.position.y + tex_bunny.height / 2.0f - 40 < 0)
|
||||
{
|
||||
bunny.speed.y *= -1;
|
||||
}
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
//----------------------------------------------------------------------------------
|
||||
rl::@drawing()
|
||||
{
|
||||
rl::clear_background(rl::RAYWHITE);
|
||||
|
||||
foreach (&bunny : bunnies[:bunnies_count])
|
||||
{
|
||||
// NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS),
|
||||
// a draw call is launched and buffer starts being filled again;
|
||||
// before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU...
|
||||
// Process of sending data is costly and it could happen that GPU data has not been completely
|
||||
// processed for drawing while new data is tried to be sent (updating current in-use buffers)
|
||||
// it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies
|
||||
rl::draw_texture(tex_bunny, (int)bunny.position.x, (int)bunny.position.y, bunny.color);
|
||||
}
|
||||
|
||||
rl::draw_rectangle(0, 0, SCREEN_WIDTH, 40, rl::BLACK);
|
||||
rl::draw_text(rl::text_format("bunnies: %i", bunnies_count), 120, 10, 20, rl::GREEN);
|
||||
rl::draw_text(rl::text_format("batched draw calls: %i", 1 + bunnies_count / MAX_BATCH_ELEMENTS), 320, 10, 20, rl::MAROON);
|
||||
|
||||
rl::draw_fps(10, 10);
|
||||
|
||||
};
|
||||
//----------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
free(bunnies); // Unload bunnies data array
|
||||
|
||||
rl::unload_texture(tex_bunny); // Unload bunny texture
|
||||
|
||||
rl::close_window(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user