schule-pong/src/engine/objs.rs
2024-02-23 08:37:13 +01:00

38 lines
796 B
Rust

use std::rc::Rc;
use self::obj_traits::MovingObject;
use super::{render::RenderCtx, BG, FG};
pub mod geometry;
pub mod obj_traits;
pub mod primitive_shapes;
pub struct World {
objects: Vec<Rc<dyn MovingObject>>,
}
impl World {
pub fn new() -> Self {
Self {
objects: Vec::new(),
}
}
pub fn insert(&mut self, obj: Rc<dyn MovingObject>) -> usize {
self.objects.push(obj);
self.objects.len() - 1
}
pub fn get(&self, i: usize) -> Rc<dyn MovingObject> {
self.objects[i].clone()
}
pub fn get_mut(&mut self, i: usize) -> &mut Rc<dyn MovingObject> {
&mut self.objects[i]
}
pub fn draw_all(&self, ctx: &mut RenderCtx<'_, '_>) {
self.objects.iter().for_each(|obj| obj.display(ctx))
}
}