Compare commits
3 Commits
1f470e23ee
...
c8f29d1336
| Author | SHA1 | Date | |
|---|---|---|---|
| c8f29d1336 | |||
| 0d1dc049b5 | |||
| f4bbb6ef6a |
35
includes/timer.h
Normal file
35
includes/timer.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* This file defines a simple timer struct, and methods to initialize it,
|
||||||
|
and keep track of time elapsed.
|
||||||
|
It was copied from https://github.com/raysan5/raylib/wiki/Frequently-Asked-Questions#how-do-i-make-a-timer */
|
||||||
|
|
||||||
|
typedef struct Timer {
|
||||||
|
double start_time; // Start time (seconds)
|
||||||
|
double lifetime; // Lifetime (seconds)
|
||||||
|
} Timer;
|
||||||
|
|
||||||
|
Timer timer_init(double lifetime_secs)
|
||||||
|
{
|
||||||
|
Timer timer;
|
||||||
|
timer.start_time = GetTime();
|
||||||
|
timer.lifetime = lifetime_secs;
|
||||||
|
|
||||||
|
return timer;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool timer_done(Timer timer)
|
||||||
|
{
|
||||||
|
return GetTime() - timer.start_time >= timer.lifetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
double timer_get_elapsed(Timer timer)
|
||||||
|
{
|
||||||
|
return GetTime() - timer.start_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
74
main.cpp
74
main.cpp
@@ -33,6 +33,7 @@
|
|||||||
#include "includes/server.hpp"
|
#include "includes/server.hpp"
|
||||||
#include "includes/exception_consts.hpp"
|
#include "includes/exception_consts.hpp"
|
||||||
#include "includes/serialization.h"
|
#include "includes/serialization.h"
|
||||||
|
#include "includes/timer.h"
|
||||||
|
|
||||||
/* Global variables used to instantiate structs */
|
/* Global variables used to instantiate structs */
|
||||||
const int WIDTH = 1500;
|
const int WIDTH = 1500;
|
||||||
@@ -235,36 +236,79 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
/* Set variables to position objects on screen */
|
/* Set variables to position objects on screen */
|
||||||
int selected_item = 0; // variable to hold the index of the selected item
|
int selected_item = 0; // variable to hold the index of the selected item
|
||||||
char* game_mode_txt = "Select Game Mode"; // Text to display
|
char* text_to_display = "Select Game Mode"; // Text to display
|
||||||
/* Size of the label, drop down box and button */
|
/* Size of the label, drop down box and button */
|
||||||
Vector2 label_size = MeasureTextEx(GetFontDefault(), game_mode_txt, font_size, font_spacing); // Set the size based on the width of the string to print, the font size and the text spacing. I added 1 to font_size and font_spacing, to account for any possible rounding errors, since the function expects floats.
|
Vector2 label_size = MeasureTextEx(GetFontDefault(), text_to_display, font_size, font_spacing); // Set the size based on the width of the string to print, the font size and the text spacing. I added 1 to font_size and font_spacing, to account for any possible rounding errors, since the function expects floats.
|
||||||
Vector2 box_size = (Vector2){label_size.x, HEIGHT / 20};
|
Vector2 box_size = (Vector2){label_size.x, HEIGHT / 20};
|
||||||
bool is_being_edited = false; // Indicates whether the drop-down menu is being 'edited' i.e. whether an option is being selected
|
bool is_being_edited = false; // Indicates whether the drop-down menu is being 'edited' i.e. whether an option is being selected
|
||||||
bool button_pressed = false; // Indicates whether the submit button has been pressed
|
bool button_pressed = false; // Indicates whether the submit button has been pressed
|
||||||
|
|
||||||
while (button_pressed == false) {
|
while (button_pressed == false) {
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
GuiLabel((Rectangle){(WIDTH/2)-(label_size.x/2), (HEIGHT/8), label_size.x, label_size.y}, game_mode_txt);
|
GuiLabel((Rectangle){(WIDTH/2)-(label_size.x/2), (HEIGHT/8), label_size.x, label_size.y}, text_to_display); // Label to display text on top
|
||||||
if (is_being_edited) {
|
|
||||||
GuiLock();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Button that allows user to proceed */
|
if (is_being_edited) {
|
||||||
button_pressed = GuiButton((Rectangle){(WIDTH/2)-(box_size.x/2), (HEIGHT/2) + (HEIGHT/8), box_size.x, box_size.y}, "Continue");
|
GuiLock(); // If the drop-down menu is being 'edited', we need to prevent the user from modifying any other aspect of the UI
|
||||||
|
}
|
||||||
|
|
||||||
/* Drop-down menu, that allows user to select game mode */
|
/* Button that allows user to proceed */
|
||||||
if (GuiDropdownBox((Rectangle){(WIDTH/2) - (box_size.x/2), (HEIGHT/2) - (HEIGHT/8), box_size.x, box_size.y}, "SINGLE;CLIENT;SERVER", &selected_item, is_being_edited)) { // This function returns != 0 if there was a mouse click inside the dropdown area
|
button_pressed = GuiButton((Rectangle){(WIDTH/2)-(box_size.x/2), (HEIGHT/2) + (HEIGHT/8), box_size.x, box_size.y}, "Continue");
|
||||||
is_being_edited = !is_being_edited; // If the dropdown menu was selected, then it is being edited (or not being edited, if it previously was).
|
|
||||||
}
|
|
||||||
|
|
||||||
// printf("%d\n", selected_item);
|
/* Drop-down menu, that allows user to select game mode */
|
||||||
GuiUnlock();
|
if (GuiDropdownBox((Rectangle){(WIDTH/2) - (box_size.x/2), (HEIGHT/2) - (HEIGHT/8), box_size.x, box_size.y}, "SINGLE;CLIENT;SERVER", &selected_item, is_being_edited)) { // This function returns != 0 if there was a mouse click inside the dropdown area
|
||||||
|
is_being_edited = !is_being_edited; // If the dropdown menu was selected, then it is being edited (or not being edited, if it previously was).
|
||||||
|
}
|
||||||
|
|
||||||
|
GuiUnlock();
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Single player mode */
|
||||||
|
if (selected_item == M_SINGLE) {
|
||||||
|
GuiSetStyle(DEFAULT, TEXT_WRAP_MODE, TEXT_WRAP_WORD); // Enable text wrapping so that the long text, displayed below, will be wrapped
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(BLACK);
|
||||||
|
GuiLabel((Rectangle){(WIDTH/2)-(WIDTH/8), (HEIGHT/2)-(HEIGHT/8), WIDTH/4, HEIGHT/4}, "W and S control left paddle, Up and Down arrow keys control right paddle. Good luck!");
|
||||||
|
EndDrawing();
|
||||||
|
Timer timer = timer_init(5);
|
||||||
|
while (!timer_done(timer));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Server mode, ask user to input IP address and port */
|
||||||
|
if (selected_item == M_SERVER) {
|
||||||
|
button_pressed = false; // Whether submit button is pressed
|
||||||
|
char* ip_text = (char *)calloc(100, sizeof(char)); // Holds input of IP text box
|
||||||
|
char* port_text = (char *)calloc(20, sizeof(char)); // Holds input of port text box
|
||||||
|
char* ip_label = "Local IP address";
|
||||||
|
char* port_label = "Port number (1024 - 65535)";
|
||||||
|
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_port = false; // Indicates whether the port text box is being edited
|
||||||
|
while (button_pressed == false) {
|
||||||
|
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}, ip_label); // Label to display text on top
|
||||||
|
/* The reason this if statement exists, is largely the same as the reasoning for the drop-down menu. We want to make the text box editable
|
||||||
|
if it has been clicked. If it is already editable, we want to make it read-only if the user clicks outside the box. This functionality
|
||||||
|
is mostly handled in the GuiTextBox function. If the text box is in edit mode, this function returns nonzero if the user clicks INSIDE
|
||||||
|
the box. If the text box is in editable mode, this function returns nonzero if the user clicks OUTSIDE the box. */
|
||||||
|
if (GuiTextBox((Rectangle){(WIDTH/2) - (box_size.x/2), (HEIGHT/2) - (HEIGHT/6), box_size.x, box_size.y}, ip_text, 100, editing_ip)) {
|
||||||
|
editing_ip = !editing_ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Label and text box for port. See above for explanation of if statement. */
|
||||||
|
GuiLabel((Rectangle){(WIDTH/2)-(label_size.x/2), (HEIGHT/2) - label_size.y, port_label_x_size }, port_label); // Label to display text on top
|
||||||
|
if (GuiTextBox((Rectangle){(WIDTH/2) - (box_size.x/2), (HEIGHT/2), box_size.x, box_size.y}, port_text, 100, editing_port)) {
|
||||||
|
editing_port = !editing_port;
|
||||||
|
}
|
||||||
|
|
||||||
|
button_pressed = GuiButton((Rectangle){(WIDTH/2) - (box_size.x/2), (HEIGHT/2) + (HEIGHT/6), box_size.x, box_size.y}, "Start Server");
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Variable to store the response given by the other player */
|
/* Variable to store the response given by the other player */
|
||||||
std::string response;
|
std::string response;
|
||||||
|
|||||||
15
todo.txt
15
todo.txt
@@ -1,8 +1,9 @@
|
|||||||
1. Try to make the ball go between screens.
|
1. Try to make the ball go between screens.
|
||||||
3. ----SHOULD BE DONE---- Add code to zip the dist/ folder inside the release_build script.
|
2. ----SHOULD BE DONE---- Add code to zip the dist/ folder inside the release_build script.
|
||||||
4. Sign Windows executable, to remove 'Unknown Publisher' warnings.
|
3. Sign Windows executable, to remove 'Unknown Publisher' warnings.
|
||||||
5. Remove debugging print statements.
|
4. Remove debugging print statements.
|
||||||
6. Create and publish statically-linked Linux binary, and create a build script for packaging it.
|
5. Create and publish statically-linked Linux binary, and create a build script for packaging it.
|
||||||
7. Figure out how to build statically-linked Mac binary, and create a build script for packaging it.
|
6. Figure out how to build statically-linked Mac binary, and create a build script for packaging it.
|
||||||
8. ----IN PROGRESS---- Figure out how to input game mode and (if applicable) IP address and port through the GUI, instead of the command-line.
|
7. ----IN PROGRESS---- Figure out how to input game mode and (if applicable) IP address and port through the GUI, instead of the command-line.
|
||||||
9. Clean up / refactor the raygui code in main.cpp, that asks user for game mode. Instead of just having a giant blob of code in main.cpp, maybe split it into a function, or move it to another file.
|
8. Clean up / refactor the raygui code in main.cpp, that asks user for game mode. Instead of just having a giant blob of code in main.cpp, maybe split it into a function, or move it to another file. It should be easy to split it into a different function, since none of the functions take any specific parameters. The text box function, for example, only takes in the rectangle coordinates, and the text to display. I can move the code to a function, and then pass in any parameters that I need to pass in (I don't think I need to pass many parameters, though).
|
||||||
|
9. Allow the user to quit before the game actually starts i.e. while they are inputting the game mode.
|
||||||
|
|||||||
Reference in New Issue
Block a user