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

Commit

Permalink
Cleaning up.
Browse files Browse the repository at this point in the history
  • Loading branch information
chaficnajjar committed Jun 26, 2016
1 parent 35b2e6f commit fc02b1c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -4,10 +4,10 @@ OBJS := $(SRCS:.cc=.o)

DEBUG := -g

SDL_INCLUDE := `sdl2-config --cflags` -I.
SDL_INCLUDE := `sdl2-config --cflags`
SDL_LIB := `sdl2-config --libs` -lSDL2_ttf -lSDL2_mixer

CPPFLAGS += $(SDL_INCLUDE)
CPPFLAGS += $(SDL_INCLUDE) -I.
CXXFLAGS += $(DEBUG) -Wall -std=c++11
LDFLAGS += $(SDL_LIB)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -9,7 +9,7 @@ Pong clone written in C++ with SDL 2.0.

You will need:

+ [SDL 2.0](https://www.libsdl.org/hg.php)
+ [SDL 2.0](https://www.libsdl.org/)
+ [SDL Mixer 2.0](http://www.libsdl.org/projects/SDL_mixer/)
+ [SDL TTF 2.0](https://www.libsdl.org/projects/SDL_ttf/)

Expand Down
19 changes: 9 additions & 10 deletions src/ball.cc
Expand Up @@ -51,22 +51,21 @@ void Ball::launch_ball(Paddle *ai_paddle) {
}

void Ball::bounces_off(Paddle *paddle) {
if (paddle == nullptr)
return;
if (paddle == nullptr) return;

hits++;
hits++;

int sign = (paddle->get_x() < Pong::SCREEN_WIDTH/2) ? 1 : -1;
int sign = (paddle->get_x() < Pong::SCREEN_WIDTH/2) ? 1 : -1;

int relative_y = (y - paddle->get_y() + LENGTH);
int relative_y = (y - paddle->get_y() + LENGTH);

angle = (2.14f * relative_y - 75.0f);
angle = (2.14f * relative_y - 75.0f);

// Convert angle to radian, find its cos() and multiply by the speed.
dx = sign*speed*std::cos(angle*M_PI/180.0f);
// Convert angle to radian, find its cos() and multiply by the speed.
dx = sign*speed*std::cos(angle*M_PI/180.0f);

// Convert angle to radina, find its sin() and multiply by the speed.
dy = speed*std::sin(angle*M_PI/180.0f);
// Convert angle to radina, find its sin() and multiply by the speed.
dy = speed*std::sin(angle*M_PI/180.0f);
}

void Ball::update_speed() {
Expand Down

0 comments on commit fc02b1c

Please sign in to comment.