use crate::components::{Renderable, Motion}; use crate::map::Map; system_impl! { Draw( resource mut game_board: carpet::GameBoard, resource map: Map, renderable: Renderable, pos: carpet::Coord, ) { game_board.clear(); for (x, y, t) in map.tiles.iter() { game_board.set([x, y], t.glyph()); } for (p, r) in (&pos, &renderable).join() { game_board.set_with_color([p.x, p.y], r.glyph, r.color); } } } system! { Move ( resource map: Map, mut motion: Motion, mut pos: carpet::Coord, ) { let tgt_x = (pos.x as i8 + motion.right) as usize; let tgt_y = (pos.y as i8 + motion.down) as usize; if map.passable((tgt_x, tgt_y)) { pos.x = tgt_x; pos.y = tgt_y; } } finally { motion.clear(); } }