From 7557ce7cf5cf6b4b5b441e64c2f730c54959ab70 Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Mon, 29 Jan 2024 22:48:58 -0500 Subject: [PATCH] Updated header file includes; Changed base speed; Started working on networking code, to send a character when the paddle is moved or stopped --- main.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 007396a..754a81b 100644 --- a/main.cpp +++ b/main.cpp @@ -2,9 +2,10 @@ #include #include #include -#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; }