diff --git a/Cargo.toml b/Cargo.toml index 8211886..9458a05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,4 +63,4 @@ comet_resources = { path = "./crates/comet_resources", workspace = true } comet_ecs = { path = "./crates/comet_ecs", workspace = true } comet_input = { path = "./crates/comet_input", workspace = true } comet_log = { path = "./crates/comet_log", workspace = true } -comet_structs = { path = "./crates/comet_structs", workspace = true } \ No newline at end of file +comet_structs = { path = "./crates/comet_structs", workspace = true } diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..89fb6c3 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,14 @@ +# Examples + +This directory contains a few examples that demonstrate how you can use Comet to create an application/game. + +Simply run +```bash +cargo run --example +``` + +| Example | Description | +|------------------------------------|-----------------------------------------------------------------------------------------| +| [hello_world](hello_world) | A simple boilerplate example to show how to properly start creating a Comet App. | +| [textured_entity](textured_entity) | This covers the basics on how to create a camera and your first entity with a texture | + diff --git a/examples/hello_world.rs b/examples/hello_world.rs new file mode 100644 index 0000000..26078cd --- /dev/null +++ b/examples/hello_world.rs @@ -0,0 +1,17 @@ +use comet::prelude::*; + +// This function will only be called once before the event loop starts. +fn setup(app: &mut App, renderer: &mut Renderer2D) {} + +// This function will be called on every tick after the event loop starts. +fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) {} + +fn main() { + // This creates a window with the title "Hello world". + // Note: You can call your functions differently if you want to though it is advised to use + // `setup` and `update` as the names. + // You can also replace `Renderer2D` with any other struct that implements the `Renderer` trait. + App::new() + .with_title("Hello world") + .run::(setup, update); +} \ No newline at end of file diff --git a/examples/textured_entity.rs b/examples/textured_entity.rs new file mode 100644 index 0000000..603cc22 --- /dev/null +++ b/examples/textured_entity.rs @@ -0,0 +1,32 @@ +use comet::prelude::*; + +fn setup(app: &mut App, renderer: &mut Renderer2D) { + // Creating a texture atlas from the provided textures in the vector + renderer.set_texture_atlas(vec!["./resources/textures/comet_icon.png".to_string()]); + + // Creating a camera entity + let cam = app.new_entity(); + app.add_component(cam, Transform2D::new()); + app.add_component(cam, Camera2D::new(Vec2::new(2.0, 2.0), 1.0, 1)); + + // Creating a textured entity + let e0 = app.new_entity(); + app.add_component(e0, Transform2D::new()); + + let mut render = Render2D::new(); + render.set_visibility(true); + render.set_texture("./resources/textures/comet_icon.png"); + + app.add_component(e0, render); +} + +fn update(app: &mut App, renderer: &mut Renderer2D, dt: f32) { + renderer.render_scene_2d(app.world()) +} + +fn main() { + App::new() + .with_title("Textured Entity") + .with_preset(App2D) + .run::(setup, update); +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index b21606b..aa8afee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,4 +16,5 @@ pub mod prelude { pub use comet_log::*; pub use comet_colors::*; pub use comet_ecs::*; + pub use comet_math::*; } \ No newline at end of file