Skip to content
This repository has been archived by the owner on Nov 13, 2019. It is now read-only.

Commit

Permalink
Impossible to defeat player AI. Not much I, very A.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpetersen committed Feb 25, 2015
1 parent ea4f2ce commit 9b47daf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/game_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl GameController {

pub fn tick(&mut self, _: &Event, drawer: &mut RenderDrawer) {
self.move_player_paddle();
self.move_opponent_paddle();
self.move_ball();
self.draw_player(drawer);
self.draw_opponent(drawer);
Expand All @@ -47,6 +48,11 @@ impl GameController {
self.player_paddle_y = y;
}

fn move_opponent_paddle(&mut self) {
let (_, y) = self.ball_position;
self.opponent_paddle_y = y - PADDLE_HEIGHT / 2;
}

// TODO this shouldn't be framerate/vsync dependent.
// Thanks StackOverflow!
// http://stackoverflow.com/questions/5830791/find-radians-reflection-angle
Expand All @@ -70,8 +76,7 @@ impl GameController {
let player_paddle_x = PADDLE_WALL_PADDING + PADDLE_WIDTH;
let player_paddle_impacted = x <= player_paddle_x && y >= self.player_paddle_y && y <= self.player_paddle_y + PADDLE_HEIGHT;
let opponent_paddle_x = 800 - PADDLE_WALL_PADDING - PADDLE_WIDTH - BALL_BREADTH;
//let opponent_paddle_impacted = x >= opponent_paddle_x && y >= self.opponent_paddle_y && y <= self.opponent_paddle_y + PADDLE_HEIGHT;
let opponent_paddle_impacted = x >= opponent_paddle_x; // Invincible opponent until AI.
let opponent_paddle_impacted = x >= opponent_paddle_x && y >= self.opponent_paddle_y && y <= self.opponent_paddle_y + PADDLE_HEIGHT;
if player_paddle_impacted || opponent_paddle_impacted {
self.ball_angle = 0.0 - PI - self.ball_angle;
}
Expand Down

0 comments on commit 9b47daf

Please sign in to comment.