Last active
August 29, 2015 14:06
-
-
Save jaredonline/2743a5e94009a8ec26c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct Game<'a> { | |
pub exit: bool, | |
pub window_bounds: Bound, | |
pub rendering_component: Box<RenderingComponent>, | |
pub stats_window: Box<WindowComponent>, | |
pub map_window: Box<WindowComponent>, | |
pub input_window: Box<WindowComponent>, | |
pub messages_window: Box<WindowComponent> | |
} | |
pub trait RenderingComponent { | |
fn new(Bound) -> Self; | |
fn before_render_new_frame(&mut self); | |
fn render_object(&mut self, Point, char); | |
fn after_render_new_frame(&mut self); | |
fn wait_for_keypress(&self) -> KeyState; | |
fn attach_window(&mut self, &mut Box<WindowComponent>); | |
} | |
impl RenderingComponent for TcodRenderingComponent { | |
fn new(bounds: Bound) -> TcodRenderingComponent { | |
let console = Console::init_root( | |
(bounds.max.x + 1) as int, | |
(bounds.max.y + 1) as int, | |
"libtcod Rust tutorial", false | |
); | |
TcodRenderingComponent { | |
console: console, | |
bounds: bounds | |
} | |
} | |
fn before_render_new_frame(&mut self) { | |
self.console.clear(); | |
} | |
fn attach_window(&mut self, window: &mut Box<WindowComponent>) { | |
window.clear(); | |
//let mut line = 0; | |
//for m in window.get_messages().iter() { | |
//window.print_message(0, line, tcod::Left, m.as_slice()); | |
//line = line + 1; | |
//} | |
let bounds = window.get_bounds(); | |
let console = window.get_console(); | |
Console::blit(&*console, 0, 0, (bounds.max.x as int) + 1, (bounds.max.y as int) + 1, &mut self.console, bounds.min.x as int, bounds.min.y as int, 1f32, 1f32); | |
} | |
fn render_object(&mut self, position: Point, symbol: char) { | |
self.console.put_char(position.x as int, position.y as int, symbol, background_flag::Set); | |
} | |
fn after_render_new_frame(&mut self) { | |
self.console.flush(); | |
} | |
fn wait_for_keypress(&self) -> KeyState { | |
self.console.wait_for_keypress(true) | |
} | |
} | |
Users/jmcfarland/code/rust/dwemthys/src/game/mod.rs:22:34: 22:52 error: explicit lifetime bound required | |
/Users/jmcfarland/code/rust/dwemthys/src/game/mod.rs:22 pub rendering_component: Box<RenderingComponent>, | |
^~~~~~~~~~~~~~~~~~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment