Updated header file includes; Changed base speed; Started working on networking code, to send a character when the paddle is moved or stopped

master
Aadhavan Srinivasan 9 months ago
parent 8ea9764165
commit 7557ce7cf5

@ -2,9 +2,10 @@
#include <cmath>
#include <ctime>
#include <raylib-cpp.hpp>
#include "paddle.hpp"
#include "ball.hpp"
#include "math-helpers.hpp"
#include "includes/paddle.hpp"
#include "includes/ball.hpp"
#include "includes/math-helpers.hpp"
#include "includes/client.hpp"
/* Global variables used to instantiate structs */
const int WIDTH = 1500;
@ -15,7 +16,7 @@ const int PADDLE_SPEED = 8;
const int CIRC_RAD = 10;
const float BASE_BOUNCE_DEG = 60;
const float BASE_BOUNCE_RAD = (BASE_BOUNCE_DEG / 180.0) * M_PI;
const float BASE_SPEED_COMPONENTS = 15;
const float BASE_SPEED_COMPONENTS = 18;
const float BASE_SPEED = sqrt(powf(BASE_SPEED_COMPONENTS, 2) * 2);
raylib::Vector2 changeVelocityAfterCollision(Paddle paddle, Ball ball) {
@ -48,6 +49,7 @@ int main() {
std::string points_str = std::string("0\t\t0");
bool game_started = false;
srand(std::time(NULL));
Client client = Client(4,'T',"127.0.0.1",6500);
/* Instantiate Paddle and Ball objects */
Paddle pad1 = Paddle(10, (HEIGHT / 2) - (RECT_H / 2), RECT_W, RECT_H);
@ -83,12 +85,15 @@ int main() {
}
if (IsKeyPressed(KEY_UP)) {
client.sendAll(std::string("U"));
pad2.velocity.y = (-1) * PADDLE_SPEED;
}
if (IsKeyPressed(KEY_DOWN)) {
client.sendAll(std::string("D"));
pad2.velocity.y = PADDLE_SPEED;
}
if (IsKeyReleased(KEY_UP) || IsKeyReleased(KEY_DOWN)) {
client.sendAll(std::string("S"));
pad2.velocity.y = 0;
}

Loading…
Cancel
Save