refactor: intentionally unsafe leak to drop annoying lifetimes, use IVec2 in all remaining spots

This commit is contained in:
2025-07-24 16:04:47 -05:00
parent f41c550bb8
commit 0a82aea922
10 changed files with 135 additions and 96 deletions

View File

@@ -17,14 +17,14 @@ pub enum EdibleKind {
Fruit(FruitType),
}
pub struct Edible<'a> {
pub struct Edible {
pub base: StaticEntity,
pub kind: EdibleKind,
pub sprite: Rc<AtlasTexture<'a>>,
pub sprite: Rc<AtlasTexture>,
}
impl<'a> Edible<'a> {
pub fn new(kind: EdibleKind, cell_position: UVec2, sprite: Rc<AtlasTexture<'a>>) -> Self {
impl Edible {
pub fn new(kind: EdibleKind, cell_position: UVec2, sprite: Rc<AtlasTexture>) -> Self {
let pixel_position = Map::cell_to_pixel(cell_position);
Edible {
base: StaticEntity::new(pixel_position, cell_position),
@@ -39,26 +39,26 @@ impl<'a> Edible<'a> {
}
}
impl<'a> Entity for Edible<'a> {
impl Entity for Edible {
fn base(&self) -> &StaticEntity {
&self.base
}
}
impl<'a> Renderable for Edible<'a> {
impl Renderable for Edible {
fn render(&self, canvas: &mut Canvas<Window>) {
let pos = self.base.pixel_position;
self.sprite.render(canvas, (pos.x, pos.y), Direction::Right, Some(0));
self.sprite.render(canvas, pos, Direction::Right, Some(0));
}
}
/// Reconstruct all edibles from the original map layout
pub fn reconstruct_edibles<'a>(
pub fn reconstruct_edibles(
map: Rc<RefCell<Map>>,
pellet_sprite: Rc<AtlasTexture<'a>>,
power_pellet_sprite: Rc<AtlasTexture<'a>>,
_fruit_sprite: Rc<AtlasTexture<'a>>,
) -> Vec<Edible<'a>> {
pellet_sprite: Rc<AtlasTexture>,
power_pellet_sprite: Rc<AtlasTexture>,
_fruit_sprite: Rc<AtlasTexture>,
) -> Vec<Edible> {
let mut edibles = Vec::new();
for x in 0..BOARD_WIDTH {
for y in 0..BOARD_HEIGHT {