Compare commits

18 Commits

Author SHA1 Message Date
f4c3ef9b19 Renamed file 2024-03-06 15:59:46 -06:00
bb4601c5bd Chenged FPS to 60 for release build 2024-03-06 15:59:12 -06:00
45aa6ba4bc Added version number, added an additional compiler argument for Windows (doesn't work yet) 2024-03-06 15:58:47 -06:00
c3f6ae0ae9 Added .gitignore 2024-03-06 13:09:06 -06:00
21c864da60 Created script to copy DLLs into application fodler on mingw 2024-03-06 13:06:29 -06:00
a2fed8e4b0 Updated meson.build to include additional DLLs needed on Windows 2024-03-06 12:47:58 -06:00
1196ebd228 Updated README 2024-03-05 22:42:28 -05:00
3a9a32d7e3 Updated README 2024-03-05 22:29:09 -05:00
a5202ad85a Add support for building a statically linked version of the game, by specifying a command-line flag 2024-03-05 22:26:40 -05:00
61a856e88f Added raylib submodule, under subprojects directory 2024-03-05 21:03:08 -05:00
6170c95666 Delete raylib submodule and move it inside 'subprojects' 2024-03-05 20:58:41 -05:00
d6f597d8c0 Added raylib submodule 2024-03-05 20:47:18 -05:00
591c3b16a2 Fixed stupid error (using 'meson' instead of 'compiler') 2024-03-05 16:39:10 -05:00
2ea5bb4fe2 Find raylib even if pkg-config is not found 2024-03-05 16:36:43 -05:00
f961db5e58 Added code to send quit message only if game is not in single player mode 2024-03-05 07:57:20 -05:00
64aa4b1850 Replaced 'linux' with '__unix__' because the same header files are included on macOS as well. 2024-03-05 07:50:32 -05:00
0e504060cf Modified README 2024-03-04 23:51:48 -05:00
d69b627bb1 Added README 2024-03-04 23:50:16 -05:00
11 changed files with 98 additions and 15 deletions

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
main.o
easysock.o
pong
release/

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "subprojects/raylib"]
path = subprojects/raylib
url = https://github.com/raysan5/raylib.git

32
README.md Normal file
View File

@@ -0,0 +1,32 @@
## Netpong - A Pong game for the internet era
__Netpong__ is a network-enabled Pong game, written in C++. It enables two players to play against each other, provided an IP address and a port. It also supports a single-player mode.
## How it works
The game has only one runtime dependency: The [raylib](https://www.raylib.com/) graphics system. In order to write idiomatic C++, I chose to use the [raylib-cpp](https://robloach.github.io/raylib-cpp/) wrapper, which provides an object-oriented interface to the Raylib library. However, this wrapper is bundled with the project, and is thus not required to be installed.
## Building
This application uses [Meson](https://mesonbuild.com/) as a build system. To build the application:
1. Install __meson__ from the link above.
2. Install __raylib__ from the link above (THIS IS OPTIONAL, SEE STEP 5)
3. Set up the build directory with the `meson setup build` command.
4. Compile the application, with the existing raylib installation, using `meson compile -C build`.
5. If you don't have raylib installed, you can create a statically linked version of the library on Linux by running the following commands:
```
meson configure -Ddefault_library=static build/
meson compile -C build -Ddefault_library=static
```
## Running
- To run in single-player mode:
- Run the application with no arguments: `build/pong`
- Left paddle is controlled with `W` and `S` keys, right paddle is controlled with `Up` and `Down` arrow keys.
- To run in multi-player mode:
- One player runs the application in Server mode, specifying their IP address and a port: `build/pong -S <ip_address> <port>`
- The other player connects to the first player by running in Client mode, specifying the first player's IP address and port: `build/pong -C <ip_address> <port>`.
- The server controls the left paddle by default (WIP to allow the user to modify this), and the client controls the right paddle.

21
create_release_build.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/bash
# This script copies required DLLs, and the application itself into a folder called 'release'. It only runs on MinGW.
BASE_DIR=$(dirname $0)
REL_DIR="$BASE_DIR/release/dist"
mkdir -p "$REL_DIR"
# Parse the output of the 'ldd' command, and create a file with the required DLL paths.
ldd build/pong.exe | awk ' NF == 4 {print $3}' > "$BASE_DIR/tmp_file.txt"
# Copy the required DLLs.
cp $(cat "$BASE_DIR/tmp_file.txt") "$REL_DIR"
# Copy the executable itself
cp "$BASE_DIR/build/pong" "$REL_DIR"
# Remove the temporary file.
rm "$BASE_DIR/tmp_file.txt"

View File

@@ -6,7 +6,7 @@
#include <winsock.h>
#include <ws2tcpip.h>
#endif
#ifdef linux
#ifdef __unix__
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

View File

@@ -2,7 +2,7 @@
#define _SOCK_CLASS
#include <string>
#ifdef linux
#ifdef __unix__
#include <sys/socket.h>
#endif
#ifdef _WIN32

View File

@@ -211,7 +211,7 @@ int main(int argc, char** argv) {
SetTraceLogLevel(LOG_NONE);
raylib::Window window = raylib::Window(WIDTH, HEIGHT, "Pong");
window.ClearBackground(BLACK);
SetTargetFPS(10);
SetTargetFPS(60);
SetExitKey(KEY_Q);
std::string points_str = std::string("0\t\t0");
bool game_started = false;
@@ -396,11 +396,13 @@ int main(int argc, char** argv) {
}
/* If the game has been quit, ask the peer to quit as well */
to_send_data = Serial_create_data(0, 0, 0, 0, true);
type.netsock->sendAll((char *)Serial_serialize(to_send_data), sizeof(Serial_Data) + 1);
if (type.mode != M_SINGLE) {
to_send_data = Serial_create_data(0, 0, 0, 0, true);
type.netsock->sendAll((char *)Serial_serialize(to_send_data), sizeof(Serial_Data) + 1);
sock_quit();
}
window.Close();
sock_quit();
return 0;
}

View File

@@ -1,13 +1,36 @@
project('Pong', ['cpp', 'c'])
add_global_arguments('-g', '-Wall', '-pedantic', '-Wno-unused-function', '-Werror', language : ['cpp', 'c'])
raylib = dependency('raylib', native: true)
project('Pong', ['cpp', 'c'], version: '0.1')
add_global_arguments('-g', '-Wall', '-pedantic', '-Wno-unused-function', language : ['cpp', 'c'])
compiler = meson.get_compiler('cpp')
ws2_dep = compiler.find_library('ws2_32', required: false)
cmake = import('cmake')
if get_option('default_library') == 'shared'
raylib = dependency('raylib', required: false) # Try to find dependency with pkg-config
if not raylib.found()
raylib = compiler.find_library('raylib', has_headers: ['raylib.h', 'raymath.h'], required: true) # Try to manually search for the dependency
endif
# if not raylib.found()
# opt_var = cmake.subproject_options()
# opt_var.add_cmake_defines({'BUILD_SHARED_LIBS' : true})
# opt_var.add_cmake_defines({'CMAKE_SKIP_RPATH' : true})
# raylib_proj = cmake.subproject('raylib', options: opt_var)
# raylib = raylib_proj.dependency('raylib')
# endif
endif
if get_option('default_library') == 'static'
raylib_proj = cmake.subproject('raylib')
raylib = raylib_proj.dependency('raylib')
endif
#For Windows only
ws2_dep = compiler.find_library('ws2_32', required: false)
winmm = compiler.find_library('winmm', required: false)
if build_machine.system() == 'windows'
add_global_arguments('-Wl,--subsystem,windows', '-mwindows', language: ['cpp', 'c']) # Prevent opening console when game is run
endif
executable('pong',
'main.cpp', 'easysock.cpp', 'sock.cpp','paddle.cpp', 'ball.cpp', 'numeric_base.cpp', 'connect_code.cpp', 'server.cpp', 'client.cpp',
'serialization.c',
dependencies: [raylib, ws2_dep]
dependencies: [raylib, ws2_dep, winmm]
)

View File

@@ -2,7 +2,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#ifdef linux
#ifdef __unix__
#include <arpa/inet.h>
#endif
#ifdef _WIN32

View File

@@ -1,4 +1,4 @@
#ifdef linux
#ifdef __unix__
#include <sys/socket.h>
#endif
#ifdef _WIN32

1
subprojects/raylib Submodule

Submodule subprojects/raylib added at c7b362d19d