sevivon

[DORMANT] multiplayer dreidel game for mobile devices w/ godot
git clone git://git.figbert.com/sevivon.git
Log | Files | Refs | README | LICENSE

commit dd8609fb985621afb831bc59f327ad02cd837e35
parent bc223df2b4ee6ea24efa6d8e24079ce720ae2821
Author: FIGBERT <figbert@figbert.com>
Date:   Fri, 12 Feb 2021 14:31:49 -0800

Wait for player confirmation before anteing

This commit introduces a mechanic that has players
shake their devices in order to ante before proceeding
with the game.

It has one known problem to be fixed in upcoming commits.
When a player spins the dreidel and lands on something
that produces an ante request (i.e. gimmel), they are anted
almost immediately. This is caused by continued momentum
in the accelerometer from the first shake, and will be
fixed ASAP.

Diffstat:
Msrc/scripts/main.gd | 35+++++++++++++++++++++++++++++++----
1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/scripts/main.gd b/src/scripts/main.gd @@ -1,6 +1,7 @@ extends Node +signal client_anted const SERVER_IP := "10.0.0.76" const SERVER_PORT := 1780 const MAX_PLAYERS := 5 @@ -42,6 +43,7 @@ func _client_joined_server(id: int) -> void: "name": USERNAMES[players.size()], "gelt": PLAYER_STARTING_GELT, "in": true, + "paid_ante": true, } var username: String = players[id]["name"] @@ -98,12 +100,16 @@ func _end_game(message: String) -> void: remote func shake_action() -> void: var sender := get_tree().get_rpc_sender_id() if game_started: - if sender == current_turn["id"] and players[sender]["in"]: + if sender == current_turn["id"] and players[sender]["in"] and _everyone_anted(): _client_spun(sender) rpc_id(sender, "vibrate_device") + elif not players[sender]["paid_ante"]: + _send_ante_signal(sender) + rpc_id(sender, "vibrate_device") else: if players.size() > 1 and sender == players.keys()[0]: _start_game() + rpc_id(sender, "vibrate_device") func _client_spun(sender: int) -> void: @@ -112,7 +118,7 @@ func _client_spun(sender: int) -> void: if needs_ante: rpc("print_message_from_server", _gelt_status()) rpc("print_message_from_server", "Time to ante up!") - _everyone_puts_in_one() + yield(_everyone_puts_in_one(), "completed") var has_won := _check_for_winner() if has_won: var winner := _find_winner() @@ -151,15 +157,25 @@ func _spin_dreidel(id: int) -> bool: func _everyone_puts_in_one() -> void: for id in players.keys(): - if not players[id]["in"]: + if players[id]["in"]: + players[id]["paid_ante"] = false + + var ante_completed := _everyone_anted() + while not ante_completed: + var id: int = yield(self, "client_anted") + var username: String = players[id]["name"] + if not players[id]["in"] or players[id]["paid_ante"]: + ante_completed = _everyone_anted() continue if players[id]["gelt"] > 0: players[id]["gelt"] -= 1 pot += 1 + rpc("print_message_from_server", "%s has anted!" % username) else: - var username: String = players[id]["name"] rpc("print_message_from_server", "%s can't pay the ante – you lose!" % username) players[id]["in"] = false + players[id]["paid_ante"] = true + ante_completed = _everyone_anted() func _iterate_turn() -> void: @@ -179,6 +195,10 @@ func _iterate_turn() -> void: rpc("print_message_from_server", "It's now %s's turn" % username) +func _send_ante_signal(id: int) -> void: + emit_signal("client_anted", id) + + ## Client Logic func _initialize_client() -> void: var peer := NetworkedMultiplayerENet.new() @@ -213,6 +233,13 @@ remote func vibrate_device() -> void: ## Utility Functions +func _everyone_anted() -> bool: + var sum := 0 + for id in players.keys(): + sum += int(players[id]["paid_ante"]) + return true if sum == players.size() else false + + func _check_for_winner() -> bool: var sum := 0 for id in players.keys():