Moved struct definition to separate file, and added check for displaying GUI
I moved the GameType struct (and the Mode enum) to a separate file, as I will need to use it in the check_server and check_client functions as well. I also added the signum function (which was previously in sign.hpp) to this file, since it was the only function in sign.hpp. Finally, I added a check, that will only display the GUI, if the user didn't provide any command-line arguments.
This commit is contained in:
32
main.cpp
32
main.cpp
@@ -23,15 +23,14 @@
|
|||||||
#define RAYGUI_IMPLEMENTATION
|
#define RAYGUI_IMPLEMENTATION
|
||||||
#include "includes/raygui/raygui.h"
|
#include "includes/raygui/raygui.h"
|
||||||
#include "includes/raygui/style_dark.h"
|
#include "includes/raygui/style_dark.h"
|
||||||
|
|
||||||
#include "includes/paddle.hpp"
|
#include "includes/paddle.hpp"
|
||||||
#include "includes/ball.hpp"
|
#include "includes/ball.hpp"
|
||||||
#include "includes/easysock.hpp"
|
|
||||||
#include "includes/sign.hpp"
|
|
||||||
#include "includes/connect_code.hpp"
|
#include "includes/connect_code.hpp"
|
||||||
|
#include "includes/easysock.hpp"
|
||||||
#include "includes/client.hpp"
|
#include "includes/client.hpp"
|
||||||
#include "includes/server.hpp"
|
#include "includes/server.hpp"
|
||||||
#include "includes/exception_consts.hpp"
|
#include "includes/exception_consts.hpp"
|
||||||
|
#include "includes/check_input.hpp"
|
||||||
#include "includes/serialization.h"
|
#include "includes/serialization.h"
|
||||||
#include "includes/timer.h"
|
#include "includes/timer.h"
|
||||||
|
|
||||||
@@ -47,18 +46,12 @@ const float BASE_BOUNCE_RAD = (BASE_BOUNCE_DEG / 180.0) * M_PI;
|
|||||||
const float BASE_SPEED_COMPONENTS = 15;
|
const float BASE_SPEED_COMPONENTS = 15;
|
||||||
const float BASE_SPEED = sqrt(powf(BASE_SPEED_COMPONENTS, 2) * 2);
|
const float BASE_SPEED = sqrt(powf(BASE_SPEED_COMPONENTS, 2) * 2);
|
||||||
|
|
||||||
typedef enum {M_SINGLE, M_CLIENT, M_SERVER} Mode;
|
/* Simple function to return 1 if a value is positive, and -1 if it is negative */
|
||||||
|
int signum(int num) {
|
||||||
/* This struct contains a Mode enum, which indicates the type of game we are
|
int retval = 0;
|
||||||
playing (Single player, client mode or server mode). The netsock parameter is
|
(num > 0) ? retval = 1 : retval = -1;
|
||||||
a 'Sock' object - Client and Server classes inherit from this object, so this
|
return retval;
|
||||||
parameter can be instantiated to either a client or server, depending on the
|
}
|
||||||
game type. */
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Mode mode;
|
|
||||||
Sock* netsock;
|
|
||||||
} GameType;
|
|
||||||
|
|
||||||
raylib::Vector2 changeVelocityAfterCollision(Paddle paddle, Ball ball) {
|
raylib::Vector2 changeVelocityAfterCollision(Paddle paddle, Ball ball) {
|
||||||
float paddle_mid_y = (paddle.getRect().y + paddle.getRect().GetHeight()) / 2.0; /* Middle y value of rectangle */
|
float paddle_mid_y = (paddle.getRect().y + paddle.getRect().GetHeight()) / 2.0; /* Middle y value of rectangle */
|
||||||
@@ -223,8 +216,8 @@ int main(int argc, char** argv) {
|
|||||||
bool game_started = false;
|
bool game_started = false;
|
||||||
srand(std::time(NULL));
|
srand(std::time(NULL));
|
||||||
|
|
||||||
|
/* If there were no command-line arguments, the user is prompted in the GUI */
|
||||||
|
if (argc == 1) {
|
||||||
/* Display a drop-down menu, to allow user to pick between Single player, server and client. This section of the code uses the raygui library, and is written in C. */
|
/* Display a drop-down menu, to allow user to pick between Single player, server and client. This section of the code uses the raygui library, and is written in C. */
|
||||||
|
|
||||||
GuiLoadStyleDark(); // Load the dark theme style
|
GuiLoadStyleDark(); // Load the dark theme style
|
||||||
@@ -309,7 +302,10 @@ int main(int argc, char** argv) {
|
|||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
GameType type = check_server(ip_text, port_text);
|
type = check_server(ip_text, port_text);
|
||||||
|
free(ip_text);
|
||||||
|
free(port_text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Variable to store the response given by the other player */
|
/* Variable to store the response given by the other player */
|
||||||
|
Reference in New Issue
Block a user