| 
				
			 | 
			
			 | 
			@@ -1,3 +1,5 @@ | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			mod components; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			use sdl2::pixels::Color; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			use sdl2::event::Event; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			use sdl2::keyboard::Keycode; | 
		
		
	
	
		
			
			| 
				
			 | 
			
			 | 
			@@ -10,52 +12,9 @@ use specs_derive::Component; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			use std::time::Duration; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			const PLAYER_MOVEMENT_SPEED: i32 = 20; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#[derive(Debug, Clone, Copy, PartialEq, Eq)] | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			enum Direction { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    Up, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    Down, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    Left, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    Right, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#[derive(Component, Debug)] | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#[storage(VecStorage)] | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			struct Position(Point); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#[derive(Component, Debug)] | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#[storage(VecStorage)] | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			struct Velocity { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    speed: i32, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    direction: Direction, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#[derive(Component, Debug, Clone)] | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#[storage(VecStorage)] | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			struct Sprite { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    spritesheet: usize, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    region: Rect, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#[derive(Component, Debug)] | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#[storage(VecStorage)] | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			struct MovementAnimation { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    current_frame: usize, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    up_frames: Vec<Sprite>, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    down_frames: Vec<Sprite>, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    left_frames: Vec<Sprite>, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    right_frames: Vec<Sprite>, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			use crate::components::*; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#[derive(Debug)] | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			struct Player { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    position: Point, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    sprite: Rect, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    speed: i32, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    direction: Direction, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    current_frame: i32, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			} | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			const PLAYER_MOVEMENT_SPEED: i32 = 20; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			fn direction_spritesheet_row(direction: Direction) -> i32 { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    use self::Direction::*; | 
		
		
	
	
		
			
			| 
				
			 | 
			
			 | 
			@@ -164,13 +123,13 @@ fn main() -> Result<(), String> { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        down_frames: character_animation_frames(player_spritesheet, player_top_left_frame, Direction::Down), | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        left_frames: character_animation_frames(player_spritesheet, player_top_left_frame, Direction::Left), | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        right_frames: character_animation_frames(player_spritesheet, player_top_left_frame, Direction::Right), | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    } | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    }; | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    let mut world = World::new(); | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
  | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    world.create_entity() | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        .with(Position(Point::new(0, 0))) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        .with(Velocity {speed: 0, direction: Direction::Right}), | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        .with(Velocity {speed: 0, direction: Direction::Right}) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        .with(player_animation.right_frames[0].clone()) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        .with(player_animation) | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        .build(); |