mirror of
https://github.com/Xevion/Pac-Man.git
synced 2025-12-17 06:12:36 -06:00
refactor: intentionally unsafe leak to drop annoying lifetimes, use IVec2 in all remaining spots
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user