Skip to content

Commit

Permalink
it works!
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredonline committed Nov 17, 2014
1 parent 1c87c61 commit fba4e28
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Actor {
}

impl Clone for Actor {
pub fn clone(&self) -> Actor {
fn clone(&self) -> Actor {
let mc = self.movement_component.box_clone();
Actor::new(self.position.x, self.position.y, self.display_char, mc, self.is_pc, self.foreground, self.background, self.health)
}
Expand Down
16 changes: 8 additions & 8 deletions src/game.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ impl MoveInfo {
}
}

pub struct Game<'a, 'b> {
pub struct Game {
pub move_info: Rc<RefCell<MoveInfo>>,
pub exit: bool,
pub window_bounds: Bound,
pub rendering_component: Box<RenderingComponent + 'a>,
pub game_state: Box<GameState<'a> + 'a>,
pub windows: Windows<'a>,
pub rendering_component: Box<RenderingComponent + 'static>,
pub game_state: Box<GameState + 'static>,
pub windows: Windows,
pub maps: Maps
}

impl<'a, 'b> Game<'a, 'b> {
pub fn new() -> Game<'a, 'b> {
impl Game {
pub fn new() -> Game {
let total_bounds = Bound::new(0, 0, 99, 61);
let stats_bounds = Bound::new(79, 0, 99, 49);
let input_bounds = Bound::new(0, 50, 99, 51);
Expand Down Expand Up @@ -92,11 +92,11 @@ impl<'a, 'b> Game<'a, 'b> {
}
}

pub fn render(&'a mut self) {
pub fn render(&mut self) {
self.game_state.render(&mut self.rendering_component, &mut self.maps, &mut self.windows);
}

pub fn update(&'b mut self) {
pub fn update(&mut self) {
if self.game_state.should_update_state() {
self.game_state.exit();
self.update_state();
Expand Down
35 changes: 21 additions & 14 deletions src/game_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ use game::MoveInfo;
use input::{KeyCode, SpecialKey};
use combat::{Weapon, Boomerang};

pub trait GameState<'a> {
pub trait GameState {
fn new() -> Self;
fn new_with_weapon(Box<Weapon + 'a>) -> Self;
fn new_with_weapon(Box<Weapon + 'static>) -> Self;

fn enter(&self, &mut Windows) {}
fn exit(&self) {}

fn update(&mut self, maps: &mut Maps, windows: &mut Windows, Rc<RefCell<MoveInfo>>);
fn render<'r>(&mut self, renderer: &mut Box<RenderingComponent>, maps: &mut Maps, windows: &'r mut Windows<'r>) {
fn render(&mut self, renderer: &mut Box<RenderingComponent>, maps: &mut Maps, windows: &mut Windows) {
renderer.before_render_new_frame();
let mut all_windows = windows.all_windows();
for window in all_windows.iter_mut() {
renderer.attach_window(*window);
}
let ref mut stats = windows.stats;
renderer.attach_window(stats);

let ref mut input = windows.input;
renderer.attach_window(input);

let ref mut messages = windows.messages;
renderer.attach_window(messages);

let ref mut map = windows.map;
renderer.attach_window(map);
maps.render(renderer);
renderer.after_render_new_frame();
}
Expand All @@ -31,12 +38,12 @@ pub trait GameState<'a> {

pub struct MovementGameState;

impl<'a> GameState<'a> for MovementGameState {
impl GameState for MovementGameState {
fn new() -> MovementGameState {
MovementGameState
}

fn new_with_weapon(_: Box<Weapon + 'a>) -> MovementGameState {
fn new_with_weapon(_: Box<Weapon>) -> MovementGameState {
MovementGameState
}

Expand Down Expand Up @@ -69,21 +76,21 @@ impl<'a> GameState<'a> for MovementGameState {
}
}

pub struct AttackInputGameState<'a> {
pub struct AttackInputGameState {
should_update_state: bool,
pub weapon: Box<Weapon + 'a>
pub weapon: Box<Weapon + 'static>
}

impl<'a> GameState<'a> for AttackInputGameState<'a> {
fn new() -> AttackInputGameState<'a> {
impl GameState for AttackInputGameState {
fn new() -> AttackInputGameState {
let weapon : Box<Boomerang> = box Weapon::new();
AttackInputGameState {
should_update_state: false,
weapon: weapon
}
}

fn new_with_weapon(weapon: Box<Weapon + 'a>) -> AttackInputGameState<'a> {
fn new_with_weapon(weapon: Box<Weapon + 'static>) -> AttackInputGameState {
AttackInputGameState {
should_update_state: false,
weapon: weapon
Expand Down
8 changes: 4 additions & 4 deletions src/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::rand::Rng;
pub trait MovementComponent {
fn new(Rc<RefCell<MoveInfo>>) -> Self;
fn update(&self, Point, &mut Windows) -> Point;
fn box_clone(&self) -> Box<MovementComponent>;
fn box_clone(&self) -> Box<MovementComponent + 'static>;
}

pub struct AggroMovementComponent {
Expand All @@ -36,7 +36,7 @@ impl MovementComponent for AggroMovementComponent {
AggroMovementComponent { move_info: move_info }
}

fn box_clone(&self) -> Box<MovementComponent> {
fn box_clone(&self) -> Box<MovementComponent + 'static> {
box AggroMovementComponent { move_info: self.move_info.clone() }
}

Expand Down Expand Up @@ -81,7 +81,7 @@ impl MovementComponent for UserMovementComponent {
UserMovementComponent { move_info: move_info }
}

fn box_clone(&self) -> Box<MovementComponent> {
fn box_clone(&self) -> Box<MovementComponent + 'static> {
box UserMovementComponent { move_info: self.move_info.clone() }
}

Expand Down Expand Up @@ -135,7 +135,7 @@ impl MovementComponent for RandomMovementComponent {
RandomMovementComponent { move_info: move_info }
}

fn box_clone(&self) -> Box<MovementComponent> {
fn box_clone(&self) -> Box<MovementComponent + 'static> {
box RandomMovementComponent { move_info: self.move_info.clone() }
}

Expand Down
8 changes: 4 additions & 4 deletions src/rendering/renderers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ pub trait RenderingComponent {
fn translate_color(&self, Color) -> tcod::Color;
}

pub struct TcodRenderingComponent<'a> {
pub struct TcodRenderingComponent {
pub console: Console,
pub input_component: Box<InputComponent<KeyState> + 'a>
pub input_component: Box<InputComponent<KeyState> + 'static>
}

impl<'a> RenderingComponent for TcodRenderingComponent<'a> {
fn new(bounds: Bound) -> TcodRenderingComponent<'a> {
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,
Expand Down
23 changes: 6 additions & 17 deletions src/rendering/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,25 +120,14 @@ impl WindowComponent for TcodMessagesWindowComponent {
window_component_getters!()
}

pub struct Windows<'a> {
pub stats: Box<WindowComponent + 'a>,
pub map: Box<WindowComponent + 'a>,
pub input: Box<WindowComponent + 'a>,
pub messages: Box<WindowComponent + 'a>
pub struct Windows {
pub stats: Box<WindowComponent + 'static>,
pub map: Box<WindowComponent + 'static>,
pub input: Box<WindowComponent + 'static>,
pub messages: Box<WindowComponent + 'static>
}

impl<'a > Windows<'a > {
pub fn all_windows(&'a mut self) -> Vec<&mut Box<WindowComponent>> {
let windows = vec![
&mut self.stats,
&mut self.input,
&mut self.messages,
&mut self.map
];

return windows;
}

impl Windows {
pub fn get_map_bounds(&self) -> Bound {
self.map.get_bounds()
}
Expand Down

0 comments on commit fba4e28

Please sign in to comment.