Commit 20688a8e authored by Rahix's avatar Rahix 🦀
Browse files

Add super basic player entity

Add plumbing for the most basic player:

- A `Player` component to mark the entity which is the player.
- A `Player` resource which holds the entity ID of the player.
- A `draw_tmp_player_system` to draw the player as a circle (for now).
- A `create_player` function to create the player entity.
- Update the `moving_system` to put the camera at the player position.
parent 6282dd5a
mod edge;
mod movable;
mod node;
mod player;
mod position;
mod thesun;
pub use edge::Edge;
pub use movable::{Gravity, Movable};
pub use node::Node;
pub use player::Player;
pub use position::Position;
pub use thesun::TheSun;
pub struct Player;
mod player;
pub use player::create_player;
use crate::components;
pub fn create_player(world: &mut legion::World) -> legion::Entity {
world.push((components::Player, components::Position::new(600.0, 600.0)))
......@@ -3,6 +3,7 @@ use wasm_bindgen::prelude::*;
pub mod colliders;
pub mod colors;
pub mod components;
pub mod entities;
pub mod gamestate;
pub mod resources;
pub mod states;
mod camera;
mod clock;
mod player;
mod rendering;
pub use camera::Camera;
pub use clock::Clock;
pub use player::Player;
pub use rendering::Color;
pub use rendering::ImageHandle;
pub use rendering::Rendering;
/// Stores the entity ID of the player
pub struct Player(pub legion::Entity);
use crate::colliders;
use crate::colors;
use crate::entities;
use crate::gamestate;
use crate::resources;
use crate::svg_loader;
......@@ -20,22 +21,28 @@ impl InGameState {
let background = rendering.register_image(level.background_image.clone());
let mut resources = legion::Resources::default();
let mut world = legion::World::default();
resources.insert(resources::Camera::new(1920.0, 1080.0));
let mut world = legion::World::default();
let player = entities::create_player(&mut world);
level.apply_colliders(&mut world);
let schedule = legion::Schedule::builder()
mod camera;
mod level;
mod moving;
mod tmp_player;
pub use camera::camera_system;
pub use level::draw_level_layer_system;
pub use moving::moving_system;
pub use tmp_player::draw_tmp_player_system;
use crate::components;
use crate::resources;
use legion::IntoQuery;
pub fn moving(#[resource] camera: &mut resources::Camera) {
camera.position.x += 0.1;
pub fn moving(
world: &legion::world::SubWorld,
#[resource] camera: &mut resources::Camera,
#[resource] player: &resources::Player,
) {
let mut positions = <&components::Position>::query();
let pos = positions.get(world, player.0).unwrap().0;
camera.position = nalgebra::Point2::new(pos.x as f64, pos.y as f64);
use crate::colors;
use crate::components;
use crate::resources;
pub fn draw_tmp_player(
_player: &components::Player,
pos: &components::Position,
#[resource] rendering: &mut resources::Rendering,
) {
pos.0.x as f64,
pos.0.y as f64,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment