Skip to content

Commit

Permalink
more refactoring. We've not got a load of comments which we should cu…
Browse files Browse the repository at this point in the history
…ll..
  • Loading branch information
will-clarke committed Aug 23, 2017
1 parent f42e524 commit 4814209
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
12 changes: 5 additions & 7 deletions src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ impl Board {

pub fn update_game_state<'a>(&'a mut self, input: &'a mut Input, state: &'a mut State, score: &'a mut Score, tick_count: i32) {

if &input.shape_toggle == &true && &state.shape_toggle == &true {
if input.shape_toggle && state.shape_toggle {
// TODO - implement next
// state.shape.rotate(tick_count);
}

// todo: refactor these toggles!
if &input.shape_toggle == &true {
if &state.shape_toggle == &true {
if input.shape_toggle {
if state.shape_toggle {
state.shape_toggle = false;
} else {
state.shape_toggle = true;
Expand All @@ -56,10 +56,8 @@ impl Board {
let paddle_line_segment = self.l_paddle.line_segment();
state.paddle_line = paddle_line_segment.clone();


// info!("LINES: count: {:?}, {:?}", &intersection_lines.0.len(), &intersection_lines);

self.ball = self.ball.update_position(&state, input, score);
self.ball = self.ball.update_position(state, input, score);
info!("<ball: [x: {}, y: {}]>", self.ball.current_position.x, self.ball.current_position.y);
}

pub fn starting_triangle() -> LineSegments {
Expand Down
19 changes: 10 additions & 9 deletions src/geometry/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ impl Vector {
Angle((((f64::atan2(self.x, self.y) / TAU ) + 1.0) % 1.0).abs())
}

pub fn magnitude(&mut self) -> f64 {
f64::sqrt((self.x * self.x) + (self.y * self.y))
}
// pub fn magnitude(&mut self) -> f64 {
// f64::sqrt((self.x * self.x) + (self.y * self.y))
// }

}

impl ops::Sub for Vector {
Expand Down Expand Up @@ -90,9 +91,9 @@ fn test_angle() {
}


#[test]
fn test_magnitude() {
let magnitude = Vector { x: 2.0, y: 5.0 }.magnitude();
let expected = 5.385;
assert!( magnitude - expected < 0.01 );
}
// #[test]
// fn test_magnitude() {
// let magnitude = Vector { x: 2.0, y: 5.0 }.magnitude();
// let expected = 5.385;
// assert!( magnitude - expected < 0.01 );
// }
13 changes: 3 additions & 10 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,11 @@ impl Input {

match ch
{
65 | KEY_UP => { self.l_player = Some(Direction::Up); }, // UP KEY
66 | KEY_DOWN => { self.l_player = Some(Direction::Down); }, // DOWN KEY

// TODO: WHY DOESNT THE DEFAULT KEY_LEFT ETC.. WORK ON MY MAC?
// KEY_DOWN => { self.l_player = Some(Direction::Down); },
KEY_LEFT => { self.paused_toggle = true; printw("OMG"); ; self.l_player = Some(Direction::Left); },
65 | 107 | KEY_UP => { self.l_player = Some(Direction::Up); }, // UP KEY , k
66 | 106 | KEY_DOWN => { self.l_player = Some(Direction::Down); }, // DOWN KEY, j
KEY_LEFT => { self.paused_toggle = true; ; self.l_player = Some(Direction::Left); },
KEY_RIGHT => { self.l_player = Some(Direction::Right); },
// KEY_UP => { self.l_player = Some(Direction::Up); },

106 => { self.l_player = Some(Direction::Down); }, // j
107 => { self.l_player = Some(Direction::Up); }, // k

114 => { self.restart_toggle = true; }, // r
113 => { self.quit = true; }, //q
112 => { self.paused_toggle = true; }, //p
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extern crate num;
extern crate ncurses;
extern crate rand;

// #[macro_use]
#[macro_use]
extern crate log;
extern crate env_logger;

Expand Down

0 comments on commit 4814209

Please sign in to comment.