@ -152,7 +152,8 @@ GameType check_server_client(int argc, char** argv) {
std : : cout < < " Waiting for connection... " < < std : : endl ;
std : : cout < < " Waiting for connection... " < < std : : endl ;
std : : string response = " " ;
std : : string response = " " ;
char * temp_response = NULL ;
char * temp_response = NULL ;
/* Wait for the right client to connect. Since recvAll returns a char*, we need to create a temporary variable to check for NULL. */
/* Wait for the right client to connect. Since recvAll returns a char*, we need to create a temporary variable to check for NULL.
TODO - Check that the client actually sends ' GG ' . */
do {
do {
temp_response = server - > recvAll ( ) ;
temp_response = server - > recvAll ( ) ;
} while ( temp_response = = NULL ) ;
} while ( temp_response = = NULL ) ;
@ -278,7 +279,7 @@ int main(int argc, char** argv) {
int port_label_x_size = MeasureTextEx ( GetFontDefault ( ) , port_label , font_size , font_spacing ) . x ; // Custom size for port label, because it's long
int port_label_x_size = MeasureTextEx ( GetFontDefault ( ) , port_label , font_size , font_spacing ) . x ; // Custom size for port label, because it's long
bool editing_ip = false ; // Indicates whether the IP address text box is being edited
bool editing_ip = false ; // Indicates whether the IP address text box is being edited
bool editing_port = false ; // Indicates whether the port text box is being edited
bool editing_port = false ; // Indicates whether the port text box is being edited
while ( button_pressed = = false ) {
while ( button_pressed = = false | | ( ( strlen ( ip_text ) = = 0 ) | | ( strlen ( port_text ) = = 0 ) ) ) {
BeginDrawing ( ) ;
BeginDrawing ( ) ;
ClearBackground ( BLACK ) ;
ClearBackground ( BLACK ) ;
/* Label and text box for IP address */
/* Label and text box for IP address */
@ -306,6 +307,29 @@ int main(int argc, char** argv) {
free ( ip_text ) ;
free ( ip_text ) ;
free ( port_text ) ;
free ( port_text ) ;
}
}
if ( selected_item = = M_CLIENT ) {
button_pressed = false ; // Whether submit button is pressed
char * code_text = ( char * ) calloc ( 100 , sizeof ( char ) ) ; // Holds the connect code
const char * code_label = " Enter code: " ;
bool editing_code = false ; // Indicates whether the port text box is being edited
while ( button_pressed = = false | | ( ( strlen ( code_text ) = = 0 ) ) ) {
BeginDrawing ( ) ;
ClearBackground ( BLACK ) ;
/* Label and text box for IP address */
GuiLabel ( Rectangle { ( WIDTH / 2 ) - ( label_size . x / 2 ) , ( HEIGHT / 2 ) - ( HEIGHT / 6 ) - label_size . y - 10 , label_size . x , label_size . y } , code_label ) ;
if ( GuiTextBox ( Rectangle { ( WIDTH / 2 ) - ( box_size . x / 2 ) , ( HEIGHT / 2 ) - ( HEIGHT / 6 ) , box_size . x , box_size . y } , code_text , 100 , editing_code ) ) {
editing_code = ! editing_code ;
}
button_pressed = GuiButton ( Rectangle { ( WIDTH / 2 ) - ( box_size . x / 2 ) , ( HEIGHT / 2 ) + ( HEIGHT / 6 ) , box_size . x , box_size . y } , " Connect " ) ;
EndDrawing ( ) ;
}
type = check_client ( code_text ) ;
free ( code_text ) ;
}
}
}
/* Variable to store the response given by the other player */
/* Variable to store the response given by the other player */
@ -324,6 +348,7 @@ int main(int argc, char** argv) {
Ball ball = Ball ( window . GetWidth ( ) / 2 , window . GetHeight ( ) / 2 , CIRC_RAD , BASE_SPEED , 0 ) ;
Ball ball = Ball ( window . GetWidth ( ) / 2 , window . GetHeight ( ) / 2 , CIRC_RAD , BASE_SPEED , 0 ) ;
window . BeginDrawing ( ) ;
window . BeginDrawing ( ) ;
window . ClearBackground ( BLACK ) ;
pad1 . draw ( ) ;
pad1 . draw ( ) ;
pad2 . draw ( ) ;
pad2 . draw ( ) ;
ball . draw ( ) ;
ball . draw ( ) ;
@ -372,7 +397,6 @@ int main(int argc, char** argv) {
uint8_t * response_array = ( uint8_t * ) ( type . netsock - > recvAll ( ) ) ;
uint8_t * response_array = ( uint8_t * ) ( type . netsock - > recvAll ( ) ) ;
if ( response_array ! = NULL ) {
if ( response_array ! = NULL ) {
response_data = Serial_deserialize ( response_array ) ;
response_data = Serial_deserialize ( response_array ) ;
std : : cout < < response_data . pad_x < < " \t " < < response_data . pad_y < < " \t " < < response_data . ball_x < < " \t " < < response_data . ball_y < < std : : endl ;
} else {
} else {
/* If the response is NULL, that means it timed-out. In this case, there's no value to print */
/* If the response is NULL, that means it timed-out. In this case, there's no value to print */
std : : cout < < " NOTHING RECEIVED " < < std : : endl ;
std : : cout < < " NOTHING RECEIVED " < < std : : endl ;