Something went wrong. Try again.
🎠 Powerfull and simple 2D game engine with ecs based on raylib forked from vyacheslavhere.tngl.sh/carousel
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263use carousel::{ core::{ Game, State, settings::{ ClockSettings, DebugSettings, DrawSettings, PhysicsSettings, Settings, StageSettings, WindowSettings, }, }, draw::color::Color, stage::basic::{Position, Shape, ShapeKind},};
struct MyGame { a: f32,}
impl Game for MyGame { fn start(&mut self, ctxt: &mut carousel::core::ctxt::Ctxt) { let _ = ctxt .world .entity() .with(Position(360, 240)) .with(Shape(ShapeKind::Circle(10.0), Color::GREEN)) .spawn(); }
fn update(&mut self, ctxt: &mut carousel::core::ctxt::Ctxt) { let center_x = 360.0; let center_y = 240.0; let radius = 100.0;
let x = center_x + self.a.cos() * radius; let y = center_y + self.a.sin() * radius;
ctxt.world .query() .with::<Position>() .perform() .iter() .for_each(|e| { *ctxt.world.get_mut::<Position>(*e).unwrap() = Position(x.round() as i32, y.round() as i32); });
self.a += 0.05; }}
fn main() { let game = MyGame { a: 0f32 }; let mut state = State::new( game, Settings::new( ClockSettings::new(30.0), WindowSettings::new("Hello, world", 720, 480), StageSettings::new(DrawSettings::new(Color::WHITE)), PhysicsSettings::default(), DebugSettings, ), ); state.start_game();}