#include "game.h"
+// standard library includes
+#include <cstring>
+
// third party includes
#include <raylib.h>
-Game::Game() {}
+Game::Game() : status("Unknown status") {}
void Game::update_state(const char *playerOne, const char *playerTwo,
const char *currentPlayer, char first_first,
char first_second, char first_third, char second_first,
char second_second, char second_third, bool first_ready,
- bool second_ready, int pos) {}
+ bool second_ready, int pos) {
+ if (playerOne) {
+ this->playerOne = playerOne;
+ }
+ if (playerTwo) {
+ this->playerTwo = playerTwo;
+ }
+
+ if (std::strcmp(currentPlayer, "undefined") == 0) {
+ status = "spectator";
+ } else if (std::strcmp(currentPlayer, playerOne) == 0) {
+ status = "player one";
+ } else if (std::strcmp(currentPlayer, playerTwo) == 0) {
+ status = "player two";
+ } else {
+ status = "unknown player";
+ }
+}
void Game::do_update() {
update_impl();
BeginDrawing();
ClearBackground(BLACK);
DrawText("Testing...", 100, 100, 30, RAYWHITE);
+ DrawText(status.c_str(), 0, 200, 30, RAYWHITE);
EndDrawing();
}
#ifndef ROCK_PAPER_SCISSORS_DUEL_GAME_H_
#define ROCK_PAPER_SCISSORS_DUEL_GAME_H_
+#include <string>
+
class Game {
public:
Game();
void update_impl();
void draw_impl();
+ std::string playerOne;
+ std::string playerTwo;
+ std::string status;
+ bool isPlayerOne;
+
};
#endif
-/rock_paper_scissors_duel.html
-/rock_paper_scissors_duel.js
-/rock_paper_scissors_duel.wasm
-/rock_paper_scissors_duel.data
-/index.html
+/outdir/
+/node_modules/
+/package.json
+/package-lock.json
CXX = source ${HOME}/git/emsdk/emsdk_env.sh && em++
-all: | format rock_paper_scissors_duel.html index.html
+OUTDIR = outdir
-rock_paper_scissors_duel.html: ${SOURCES} ${HEADERS}
- ${CXX} -o rock_paper_scissors_duel.html \
+all: | format ${OUTDIR} ${OUTDIR}/rock_paper_scissors_duel.html ${OUTDIR}/index.html ${OUTDIR}/logic.js ${OUTDIR}/client.js
+
+${OUTDIR}/rock_paper_scissors_duel.html: ${SOURCES} ${HEADERS} client.js logic.js
+ ${CXX} -o ${OUTDIR}/rock_paper_scissors_duel.html \
-s USE_GLFW=3 -I../wasm_includes -L../wasm_libs -lraylib \
--shell-file custom_shell.html \
-sEXPORTED_FUNCTIONS=_main,_game_visual_update \
${OTHER_FLAGS} \
${SOURCES}
+${OUTDIR}:
+ mkdir ${OUTDIR}
+
+${OUTDIR}/logic.js:
+ cp logic.js ${OUTDIR}/
+
+${OUTDIR}/client.js:
+ cp client.js ${OUTDIR}/
+
.PHONY: clean format index.html
-index.html:
- ln -sf rock_paper_scissors_duel.html index.html
+${OUTDIR}/index.html:
+ ln -sf rock_paper_scissors_duel.html ${OUTDIR}/index.html
clean:
- rm -f rock_paper_scissors_duel.html
- rm -f rock_paper_scissors_duel.js
- rm -f rock_paper_scissors_duel.wasm
- rm -f rock_paper_scissors_duel.data
- rm -f index.html
+ rm -rf ${OUTDIR}
format:
clang-format -i --style=file ${SOURCES} ${HEADERS}
visualUpdate: ({ newGame, yourPlayerId}) => {
const { player1, player2, first_choices, second_choices, first_ready, second_ready, pos } = newGame;
- Module.ccall('_game_visual_update',
+ Module.ccall('game_visual_update',
undefined,
['string', 'string', 'string',
'number', 'number', 'number',
</style>
</head>
<body>
-<!-- <script src="https://cdn.jsdelivr.net/npm/rune-games-sdk@2.5.2/dist/browser.min.js"></script> -->
+ <script src="https://cdn.jsdelivr.net/npm/rune-games-sdk@3/multiplayer.js"></script>
+ <script src="logic.js"></script>
+ <script src="client.js"></script>
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<script type='text/javascript'>
var Module = {
-Rune.initlogic({
+Rune.initLogic({
minPlayers: 2,
maxPlayers: 2,
setup: (players) => ({
game.first_ready = false;
game.second_ready = false;
if (!has_remaining) {
- if (pos <= -3) {
+ if (game.pos <= -3) {
// second won
Rune.gameOver();
- } else if (pos >= 3) {
+ } else if (game.pos >= 3) {
// first won
Rune.gameOver();
} else {