diff --git a/Example/MyPongScene.cpp b/Example/MyPongScene.cpp index 4f0d9c0..47c6bdc 100644 --- a/Example/MyPongScene.cpp +++ b/Example/MyPongScene.cpp @@ -11,6 +11,12 @@ #include +#define LEFT_PADDLE_UP_KEY GLFW_KEY_A +#define LEFT_PADDLE_DOWN_KEY GLFW_KEY_Z + +#define RIGHT_PADDLE_UP_KEY GLFW_KEY_APOSTROPHE +#define RIGHT_PADDLE_DOWN_KEY GLFW_KEY_SLASH + #define OUTLINE_THICKNESS 25.0f #define OUTLINE_OFFSET 25.0f @@ -102,11 +108,11 @@ void MyPongScene::update(float delta_time, clock_t clock) if (m_left_lives > 0) { - if (m_input_manager.is_key_down(GLFW_KEY_A)) + if (m_input_manager.is_key_down(LEFT_PADDLE_UP_KEY)) { m_paddle_left_pose.translate(up * PADDLE_SPEED * delta_time); } - if (m_input_manager.is_key_down(GLFW_KEY_Z)) + if (m_input_manager.is_key_down(LEFT_PADDLE_DOWN_KEY)) { m_paddle_left_pose.translate(down * PADDLE_SPEED * delta_time); } @@ -114,12 +120,11 @@ void MyPongScene::update(float delta_time, clock_t clock) if (m_right_lives > 0) { - if (m_input_manager.is_key_down(GLFW_KEY_APOSTROPHE)) + if (m_input_manager.is_key_down(RIGHT_PADDLE_UP_KEY)) { m_paddle_right_pose.translate(up * PADDLE_SPEED * delta_time); } - - if (m_input_manager.is_key_down(GLFW_KEY_SLASH)) + if (m_input_manager.is_key_down(RIGHT_PADDLE_DOWN_KEY)) { m_paddle_right_pose.translate(down * PADDLE_SPEED * delta_time); } @@ -146,7 +151,7 @@ void MyPongScene::update(float delta_time, clock_t clock) m_ball_direction.y = glm::abs(m_ball_direction.y); } - // Bounce Left Right (temp. should be adding points) + // Scoring if (ball_position.x + HALF_BALL_THICKNESS + OUTLINE_INWARDS > m_screen_size.x / 2.0f) { @@ -171,13 +176,31 @@ void MyPongScene::update(float delta_time, clock_t clock) if (physics::collision::rect_in_rect(ball_hitbox, left_paddle_hitbox)) { - m_ball_direction = rand_dir((float)charcoal::TAU_7_8, (float)charcoal::TAU_7_8 + (float)charcoal::TAU_1_4); + float ball_y = m_ball_direction.y * m_ball_speed; + if (m_input_manager.is_key_down(LEFT_PADDLE_UP_KEY)) + { + ball_y += PADDLE_SPEED; + } + else if (m_input_manager.is_key_down(LEFT_PADDLE_DOWN_KEY)) + { + ball_y -= PADDLE_SPEED; + } + m_ball_direction = glm::normalize(glm::vec2(m_ball_speed, ball_y)); m_ball_speed += BALL_SPEED_INCREMENT; } if (physics::collision::rect_in_rect(ball_hitbox, right_paddle_hitbox)) { - m_ball_direction = rand_dir((float)charcoal::TAU_3_8, (float)charcoal::TAU_5_8); + float ball_y = m_ball_direction.y * m_ball_speed; + if (m_input_manager.is_key_down(RIGHT_PADDLE_UP_KEY)) + { + ball_y += PADDLE_SPEED; + } + else if (m_input_manager.is_key_down(RIGHT_PADDLE_DOWN_KEY)) + { + ball_y -= PADDLE_SPEED; + } + m_ball_direction = glm::normalize(glm::vec2(-m_ball_speed, ball_y)); m_ball_speed += BALL_SPEED_INCREMENT; } diff --git a/Example/MyPongScene.h b/Example/MyPongScene.h index e695a9d..de0977b 100644 --- a/Example/MyPongScene.h +++ b/Example/MyPongScene.h @@ -30,8 +30,6 @@ private: vec2 rand_dir(float radians_low, float radians_high); - float add_magnitude(float value, float added); - void reset_ball(); basic::Renderable m_outline_column;