diff --git a/.gitignore b/.gitignore index f0133cf3..2fe4b849 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.python_history # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/README.md b/README.md index 0f59a067..025990e4 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ What is JoustMania???? Cool Stuffs! -------------------------------------- -* 16+ Player support +* 18+ Player support * Super easy setup * Runs in Headless mode, no screen required * Optional web interface, view status and change game settings with your phone @@ -25,7 +25,9 @@ Cool Stuffs! Hardware --------------------------- -You will need the following to run JoustMania: +I am currently selling fully set up Joustmania devices (pi, case, bluetooth dongle, sd card) for $79 (or the $10 tier on [patreon](https://www.patreon.com/adangert)) with included shipping domestically. If you would like to inquire about purchasing a fully setup Joustmania device, please reach out to joustmaniagame@gmail.com + +If you would like to build your own device you will need the following: * A Raspberry Pi 3 B with sd card @@ -34,7 +36,7 @@ Optional and **highly recommended**: * Class 1, Bluetooth 4.0 USB adapters (http://a.co/8YKP9tG) Note on Hardware: The internal bluetooth is short range and has a high latency, making gameplay laggy and slow, although still possible. -The class 1 adapters allow bluetooth connections up to 300+ feet and allow for the gameplay to be smooth, each adapter can connect to 6 to 7 controllers. I've tested this build with three adapters and 16 controllers successfully. +The class 1 adapters allow bluetooth connections up to 300+ feet and allow for the gameplay to be smooth, each adapter can connect to 6 to 7 controllers. I've tested this build with four adapters and 18 controllers successfully. Optional: @@ -42,9 +44,9 @@ Optional: This will allow you to charge 9 controllers at once through the pi -**Note: the new psmove controllers with a micro charging connection will not work with Joustmaina, this issue is being looked at with the psmoveapi(https://github.com/thp/psmoveapi/issues/353)** +A good power supply is recommended, (if you see a lightning bolt at the top right of your screen it means your pi is under voltage) Something like this should work well: (https://www.amazon.com/dp/B00L88M8TE) + -For questions on hardware, or if you would like to inquire about purchasing a fully setup Joustmania device, please reach out to joustmaniagame@gmail.com Installation --------------------------- @@ -60,19 +62,12 @@ git clone https://github.com/adangert/JoustMania.git cd JoustMania sudo ./setup.sh ``` -If you have the bluetooth adapters, disable the on-board bluetooth -``` -sudo ./disable_internal_bluetooth.sh -``` + You can now disconnect the hdmi cable and run JoustMania in headless mode. JoustMania will automatically boot up on restart, menu music should start playing once the pi boots up. Update Joust Mania --------------------------- -You can update Joust Mania by doing a `git pull` in the main directory and running -``` -./setup.sh -``` - +Joustmania will auto update when started and connected to the internet. Sometimes there is a large update, it will say so, then you can press the start and select buttons on a controller to start this update, wait until the pi reboots. If you have the AP enabled, you may need to disable it first to gain access to the internet. Pairing controllers --------------------------- @@ -93,8 +88,7 @@ If controllers seem to pair to only one Bluetooth adapter, it is likely that the How to select a game mode --------------------------------- * In order to change between games, on any controller press the select button (located on the left side of a controller) -* Changing game types will turn you into an Admin -* In order to remove a controller from play press all four front buttons +* In order to remove a controller from play, hold the playstation button to turn off the controller. How to start a game --------------------------------- @@ -103,7 +97,7 @@ How to start a game Admin Mode (Sensitivity and convention mode settings) --------------------------------- -You can become an Admin by changing the game mode via the select button, this will allow you to modify the games settings from the four front buttons on the controller, After a game is played the Admin mode will be reset +You can become an Admin by pressing all four front buttons on any controller, this will allow you to modify the games settings from the four front buttons on the controller, After a game is played the Admin mode will be reset * (Cross) Add or remove a game from Convention mode, your controller will be green if the game is added and Red if it is not, Custom Teams mode can not be added to the Convention mode * (Circle) Change sensitivity of the game. There are three settings, slow, medium, and fast, you will hear a corresponding sound for each @@ -116,7 +110,7 @@ Joustmania can also be controlled via a web browser on your laptop or smartphone ``` sudo ./enable_ap.sh ``` -Note that this disables normal Wi-Fi on the Pi, but a wired connection will still work. The default SSID is "JOUSTMANIA" and the default password is "joustmania"; both (and other) settings may be adjusted in the apfiles/hostapd.conf file before running enable_ap.sh. To connect to the game, go to http://joust.mania in your web browser. To disable the access point and restore Wi-Fi, run the command +Note that this disables normal Wi-Fi on the Pi, the ethernet connection may not work either. The default SSID is "JOUSTMANIA" and the default password is "joustmania"; both (and other) settings may be adjusted in the apfiles/hostapd.conf file before running enable_ap.sh. To connect to the game, go to http://10.3.141.1/ in your web browser. To disable the access point and restore Wi-Fi, run the command ``` sudo ./disable_ap.sh ``` @@ -217,3 +211,8 @@ Custom Music * This mode allows for multiple game types to be randomly rotated with instructions played before each game * Random mode defaults to FFA, Random Teams, Werewolves, and Swapper, more game modes can be added or removed as an Admin or via the web interface (see above) * Modes with an insufficient number of players will be ignored, if none are available Joust Free-for-All is selected + +Support and funding +-------------------------- +If you love this game you can support its development by helping out with my patreon here: +https://www.patreon.com/adangert diff --git a/apfiles/10-wpa_supplicant b/apfiles/10-wpa_supplicant new file mode 100644 index 00000000..10b93d60 --- /dev/null +++ b/apfiles/10-wpa_supplicant @@ -0,0 +1,23 @@ +if [ -z "$wpa_supplicant_conf" ]; then + for x in \ + /etc/wpa_supplicant/wpa_supplicant-"$interface".conf \ + /etc/wpa_supplicant/wpa_supplicant.conf \ + /etc/wpa_supplicant-"$interface".conf \ + /etc/wpa_supplicant.conf \ + ; do + if [ -s "$x" ]; then + wpa_supplicant_conf="$x" + break + fi + done +fi +: ${wpa_supplicant_conf:=/etc/wpa_supplicant.conf} + +if [ "$ifwireless" = "1" ] && \ + type wpa_supplicant >/dev/null 2>&1 && \ + type wpa_cli >/dev/null 2>&1 +then + if [ "$reason" = "IPV4LL" ]; then + wpa_supplicant -B -iwlan0 -f/var/log/wpa_supplicant.log -c/etc/wpa_supplicant/wpa_supplicant.conf + fi +fi diff --git a/apfiles/90-wireless.rules b/apfiles/90-wireless.rules new file mode 100644 index 00000000..41678971 --- /dev/null +++ b/apfiles/90-wireless.rules @@ -0,0 +1,2 @@ +ACTION=="add", SUBSYSTEM=="ieee80211", KERNEL=="phy0", \ + RUN+="/sbin/iw phy %k interface add uap0 type __ap" diff --git a/apfiles/ap b/apfiles/ap new file mode 100644 index 00000000..8c43a323 --- /dev/null +++ b/apfiles/ap @@ -0,0 +1,5 @@ +allow-hotplug uap0 +auto uap0 +iface uap0 inet static + address 10.3.141.1 + netmask 255.255.255.0 diff --git a/apfiles/dnsmasq.conf b/apfiles/dnsmasq.conf index ed2b5164..e5e7cbb8 100644 --- a/apfiles/dnsmasq.conf +++ b/apfiles/dnsmasq.conf @@ -1,8 +1,24 @@ -interface=wlan0 # Use interface wlan0 -listen-address=172.24.1.1 # Explicitly specify the address to listen on -bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere -server=8.8.8.8 # Forward DNS requests to Google DNS -domain-needed # Don't forward short names -bogus-priv # Never forward addresses in the non-routed address spaces. -dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time -address=/joust.mania/172.24.1.1 +#interface=wlan0 # Use interface wlan0 +#listen-address=172.24.1.1 # Explicitly specify the address to listen on +#bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere +#server=8.8.8.8 # Forward DNS requests to Google DNS +#domain-needed # Don't forward short names +#bogus-priv # Never forward addresses in the non-routed address spaces. +#dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time +#address=/joust.mania/172.24.1.1 + +#interface=lo,uap0 # Use interface lo,uap0 +#listen-address=172.24.1.1 # Explicitly specify the address to listen on +#no-dhcp-interface=lo,wlan0 +#bind-interfaces # Bind to the interface to make sure we aren't sending things elsewhere +#server=8.8.8.8 # Forward DNS requests to Google DNS +#domain-needed # Don't forward short names +#bogus-priv # Never forward addresses in the non-routed address spaces. +#dhcp-range=172.24.1.50,172.24.1.150,12h # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 12 hour lease time +#address=/joust.mania/172.24.1.1 + +interface=lo,uap0 +no-dhcp-interface=lo,wlan0 +bind-interfaces +server=8.8.8.8 +dhcp-range=10.3.141.50,10.3.141.255,12h diff --git a/apfiles/hostapd.conf b/apfiles/hostapd.conf index 0a96477b..1c0570a6 100644 --- a/apfiles/hostapd.conf +++ b/apfiles/hostapd.conf @@ -1,44 +1,62 @@ # This is the name of the WiFi interface we configured above -interface=wlan0 +#interface=uap0 # Use the nl80211 driver with the brcmfmac driver -driver=nl80211 +#try this is might not work +#driver=nl80211 # This is the name of the network -ssid=JOUSTMANIA +#ssid=JOUSTMANIA # Use the 2.4GHz band -hw_mode=g +#hw_mode=g # Use channel 6 -channel=6 +#channel=6 # Enable 802.11n -ieee80211n=1 +#try this, it might not work +#ieee80211n=1 # Enable WMM -wmm_enabled=1 +#wmm_enabled=1 # Enable 40MHz channels with 20ns guard interval -ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] +#ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40] # Accept all MAC addresses -macaddr_acl=0 +#macaddr_acl=0 # Use WPA authentication -auth_algs=1 +#auth_algs=1 # Require clients to know the network name -ignore_broadcast_ssid=0 +#ignore_broadcast_ssid=0 # Use WPA2 -wpa=2 +#wpa=2 # Use a pre-shared key -wpa_key_mgmt=WPA-PSK +#wpa_key_mgmt=WPA-PSK # The network passphrase -wpa_passphrase=joustmania +#wpa_passphrase=joustmania # Use AES, instead of TKIP +#rsn_pairwise=CCMP + +#wpa_pairwise=TKIP + + +interface=uap0 +ssid=JOUSTMANIA +hw_mode=g +channel=6 +macaddr_acl=0 +auth_algs=1 +ignore_broadcast_ssid=0 +wpa=2 +wpa_passphrase=joustmania +wpa_key_mgmt=WPA-PSK +wpa_pairwise=TKIP rsn_pairwise=CCMP diff --git a/apfiles/interfaces b/apfiles/interfaces index 131ab885..76ad2dba 100644 --- a/apfiles/interfaces +++ b/apfiles/interfaces @@ -3,24 +3,38 @@ # Please note that this file is written to be used with dhcpcd # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' + +allow-hotplug wlan0 +auto wlan0 +iface wlan0 inet dhcp + #wcp-conf /etc/wpa_supplicant/wpa_supplicant.conf + + # Include files from /etc/network/interfaces.d: source-directory /etc/network/interfaces.d -auto lo -iface lo inet loopback +#allow-hotplug wlan0 +#iface wlan0 inet dhcp +# pre-up sleep 10 +# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf -auto eth0 -iface eth0 inet dhcp +#auto lo +#iface lo inet loopback + +#auto eth0 +#iface eth0 inet dhcp #Access point for JoustMania -allow-hotplug wlan0 -iface wlan0 inet static - address 172.24.1.1 - netmask 255.255.255.0 - network 172.24.1.0 - broadcast 172.24.1.255 +#allow-hotplug wlan0 +#iface wlan0 inet static +# address 172.24.1.1 +# netmask 255.255.255.0 +# network 172.24.1.0 +# broadcast 172.24.1.255 + +#this was already commented out # wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf -allow-hotplug wlan1 -iface wlan1 inet manual - wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf +#allow-hotplug wlan1 +#iface wlan1 inet manual +# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf diff --git a/apfiles/rc.local b/apfiles/rc.local index 0fc32485..78db611a 100755 --- a/apfiles/rc.local +++ b/apfiles/rc.local @@ -19,5 +19,19 @@ fi #Access point for JoustMania iptables-restore < /etc/iptables.ipv4.nat +#hostapd /etc/hostapd/hostapd.conf + +sleep 5 +#ifdown wlan0 + +#sleep 2 +#rm -f /var/run/wpa_supplicant/wlan0 +#ifup wlan0 +#iptables -t nat -A POSTROUTING -s 192.168.2.0/24 ! -d 192.168.2.0.0/24 -j MASQUERADE +#hostapd -B /etc/hostapd/hostapd.conf +#dnsmasq + +hostapd -B /etc/hostapd/hostapd.conf +dnsmasq exit 0 diff --git a/apfiles/station b/apfiles/station new file mode 100644 index 00000000..f06103be --- /dev/null +++ b/apfiles/station @@ -0,0 +1,3 @@ +allow-hotplug wlan0 +iface wlan0 inet manual + wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf \ No newline at end of file diff --git a/audio/Menu/added_random.wav b/audio/Menu/added_random.wav new file mode 100644 index 00000000..1279d7ff Binary files /dev/null and b/audio/Menu/added_random.wav differ diff --git a/audio/Menu/high.wav b/audio/Menu/high.wav new file mode 100644 index 00000000..8ce4e236 Binary files /dev/null and b/audio/Menu/high.wav differ diff --git a/audio/Menu/instructions_off.wav b/audio/Menu/instructions_off.wav index 19b36538..8cf58023 100644 Binary files a/audio/Menu/instructions_off.wav and b/audio/Menu/instructions_off.wav differ diff --git a/audio/Menu/instructions_on.wav b/audio/Menu/instructions_on.wav index bb2d1690..058760e5 100644 Binary files a/audio/Menu/instructions_on.wav and b/audio/Menu/instructions_on.wav differ diff --git a/audio/Menu/joustmania_failed.wav b/audio/Menu/joustmania_failed.wav new file mode 100644 index 00000000..12c93c4c Binary files /dev/null and b/audio/Menu/joustmania_failed.wav differ diff --git a/audio/Menu/joustmania_updated.wav b/audio/Menu/joustmania_updated.wav new file mode 100644 index 00000000..7235ea38 Binary files /dev/null and b/audio/Menu/joustmania_updated.wav differ diff --git a/audio/Menu/large_update.wav b/audio/Menu/large_update.wav new file mode 100644 index 00000000..5da788b4 Binary files /dev/null and b/audio/Menu/large_update.wav differ diff --git a/audio/Menu/low.wav b/audio/Menu/low.wav new file mode 100644 index 00000000..2fbf96c1 Binary files /dev/null and b/audio/Menu/low.wav differ diff --git a/audio/Menu/medium.wav b/audio/Menu/medium.wav new file mode 100644 index 00000000..a0aa1cea Binary files /dev/null and b/audio/Menu/medium.wav differ diff --git a/audio/Menu/removed_random.wav b/audio/Menu/removed_random.wav new file mode 100644 index 00000000..63564aa4 Binary files /dev/null and b/audio/Menu/removed_random.wav differ diff --git a/audio/Menu/ultra_high.wav b/audio/Menu/ultra_high.wav new file mode 100644 index 00000000..582c8516 Binary files /dev/null and b/audio/Menu/ultra_high.wav differ diff --git a/audio/Menu/ultra_low.wav b/audio/Menu/ultra_low.wav new file mode 100644 index 00000000..bcfd554b Binary files /dev/null and b/audio/Menu/ultra_low.wav differ diff --git a/audio/Menu/update_started.wav b/audio/Menu/update_started.wav new file mode 100644 index 00000000..66ad6662 Binary files /dev/null and b/audio/Menu/update_started.wav differ diff --git a/common.py b/common.py index 310fdb97..d5f53a3f 100644 --- a/common.py +++ b/common.py @@ -10,23 +10,31 @@ SETTINGSFILE = 'joustsettings.yaml' #Human speeds[slow, mid, fast] -SLOW_WARNING = [0.1, 0.15, 0.28] -SLOW_MAX = [0.25, 0.8, 1] -FAST_WARNING = [0.5, 0.6, 0.8] -FAST_MAX = [1, 1.4, 1.8] - #SLOW_WARNING = [0.1, 0.15, 0.28] -#SLOW_MAX = [0.5, 0.8, 1] +#SLOW_MAX = [0.25, 0.8, 1] #FAST_WARNING = [0.5, 0.6, 0.8] #FAST_MAX = [1, 1.4, 1.8] -WERE_SLOW_WARNING = [0.2, 0.3, 0.4] -WERE_SLOW_MAX = [0.7, 0.9, 1.1] -WERE_FAST_WARNING = [0.6, 0.7, 0.9] -WERE_FAST_MAX = [1.1, 1.5, 2.0] +SLOW_WARNING = [1.0, 1.3, 1.6, 2.0, 2.5] +SLOW_MAX = [1.1, 1.5, 1.8, 2.5, 3.2] +FAST_WARNING = [1.3, 1.6, 1.9, 2.7, 2.8] +FAST_MAX = [1.5, 1.8, 2.8, 3.2, 3.5] + +#WERE_SLOW_WARNING = [0.2, 0.3, 0.4] +#WERE_SLOW_MAX = [0.7, 0.9, 1.1] +#WERE_FAST_WARNING = [0.6, 0.7, 0.9] +#WERE_FAST_MAX = [1.1, 1.5, 2.0] + +WERE_SLOW_WARNING = [1.1, 1.4, 1.7, 2.1, 2.9] +WERE_SLOW_MAX = [1.2, 1.6, 1.9, 2.6, 3.9] +WERE_FAST_WARNING = [1.4, 1.7, 2.0, 2.8, 3.5] +WERE_FAST_MAX = [1.6, 1.9, 2.9, 3.3, 4.9] + +#ZOMBIE_WARNING = [0.5, 0.6, 0.8] +#ZOMBIE_MAX = [0.8, 1, 1.4] -ZOMBIE_WARNING = [0.5, 0.6, 0.8] -ZOMBIE_MAX = [0.8, 1, 1.4] +ZOMBIE_WARNING = [1.2, 1.5, 1.8, 2.6, 2.7] +ZOMBIE_MAX = [1.4, 1.7, 2.7, 3.1, 3.4] def get_move(serial, move_num): @@ -37,6 +45,7 @@ def get_move(serial, move_num): for move_num in range(psmove.count_connected()): move = psmove.PSMove(move_num) if move.get_serial() == serial: + print("returning " +str(move.get_serial())) return move return None else: @@ -92,6 +101,7 @@ class Button(enum.Flag): TRIGGER = psmove.Btn_T SHAPES = TRIANGLE | CIRCLE | CROSS | SQUARE + UPDATE = SELECT | START all_shapes = [Button.TRIANGLE, Button.CIRCLE, Button.CROSS, Button.SQUARE] @@ -166,6 +176,7 @@ def __str__(self): REQUIRED_SETTINGS = [ 'play_audio', 'move_can_be_admin', +'current_game', 'enforce_minimum', 'sensitivity', 'play_instructions', diff --git a/controller_process.py b/controller_process.py new file mode 100644 index 00000000..994f8f63 --- /dev/null +++ b/controller_process.py @@ -0,0 +1,34 @@ +from games import ffa, zombie, commander, swapper, tournament, speed_bomb, fight_club +import common, colors, joust, webui, piparty +#this should all be refactored to use the same options per game +def main_track_move(menu, restart, move_serial, move_num, move_opts, force_color, battery, dead_count, game_mode, \ + team, team_color_enum, controller_sensitivity, dead_move, music_speed, werewolf_reveal, show_team_colors, red_on_kill, zombie_opt,\ + commander_intro, commander_move_opt, commander_powers, commander_overdrive,five_controller_opt, swapper_team_colors,\ + invincibility, fight_club_color, num_teams,bomb_color,game_start,false_color, faked, rumble, kill_proc): + print("starting Controller Process") + + move = common.get_move(move_serial, move_num) + while(not kill_proc.value): + move.set_rumble(0) + if(restart.value == 1): + pass + elif (menu.value == 1): + piparty.track_move(move_serial, move_num, move, move_opts, force_color, battery, dead_count, restart, menu, kill_proc) + elif(game_mode.value == common.Games.Zombies.value): + zombie.track_controller(move, zombie_opt, restart, menu, controller_sensitivity) + elif(game_mode.value == common.Games.Commander.value): + commander.track_move(move, team.value, dead_move, force_color, music_speed, commander_intro, \ + commander_move_opt, commander_powers, commander_overdrive, restart, menu, controller_sensitivity) + elif(game_mode.value == common.Games.Swapper.value): + swapper.track_move(move, team, 2, swapper_team_colors, \ + dead_move, force_color, music_speed, five_controller_opt, restart, menu, controller_sensitivity) + elif(game_mode.value == common.Games.FightClub.value): + fight_club.track_move(move, dead_move, force_color, music_speed, fight_club_color, invincibility, menu, restart, controller_sensitivity) + elif(game_mode.value == common.Games.Tournament.value): + tournament.track_move(move, team, num_teams.value, dead_move, force_color, music_speed, show_team_colors, invincibility, menu, restart, controller_sensitivity) + elif(game_mode.value == common.Games.Ninja.value): + speed_bomb.track_move(move, dead_move, force_color,bomb_color, five_controller_opt, game_start, false_color, faked, rumble, menu, restart) + else: + joust.track_move(move, game_mode.value, team.value, team_color_enum, dead_move, force_color, \ + music_speed, werewolf_reveal, show_team_colors, red_on_kill, restart, menu, controller_sensitivity) + diff --git a/disable_ap.sh b/disable_ap.sh index ca706fb4..d53ca785 100755 --- a/disable_ap.sh +++ b/disable_ap.sh @@ -1,6 +1,8 @@ -if [ "$EUID" -ne 0 ]; - then echo "This script needs root... run with sudo" - exit +#!/bin/bash + +if [ $UID -ne 0 ]; then + echo "Not root. Using sudo." + exec sudo $0 fi @@ -29,4 +31,12 @@ mv /etc/sysctl.conf.bak /etc/sysctl.conf mv /etc/rc.local.bak /etc/rc.local +rm /etc/network/interfaces.d/ap + +rm /etc/network/interfaces.d/station + +rm /etc/udev/rules.d/90-wireless.rules + +mv /lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant.bak /lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant + reboot diff --git a/enable_ap.sh b/enable_ap.sh index 2b5dbc82..52aa6fe5 100755 --- a/enable_ap.sh +++ b/enable_ap.sh @@ -1,6 +1,10 @@ -if [ "$EUID" -ne 0 ]; - then echo "This script needs root... run with sudo" - exit +#!/bin/bash + +#following the guide here: https://github.com/peebles/rpi3-wifi-station-ap-stretch + +if [ $UID -ne 0 ]; then + echo "Not root. Using sudo." + exec sudo $0 fi if [ -f ./apfiles/ap_active ] @@ -10,17 +14,20 @@ fi touch ./apfiles/ap_active -apt-get install dnsmasq hostapd +apt-get install -y hostapd dnsmasq -mv /etc/dhcpcd.conf /etc/dhcpcd.conf.bak -cp ./apfiles/dhcpcd.conf /etc/dhcpcd.conf -chown :pi /etc/dhcpcd.conf +cp ./apfiles/ap /etc/network/interfaces.d/ap -mv /etc/network/interfaces /etc/network/interfaces.bak -cp ./apfiles/interfaces /etc/network/interfaces +#cp ./apfiles/station /etc/network/interfaces.d/station + +cp ./apfiles/90-wireless.rules /etc/udev/rules.d/90-wireless.rules -sudo service dhcpcd restart -ifdown wlan0; ifup wlan0 +mv /lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant /lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant.bak +cp ./apfiles/10-wpa_supplicant /lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant + + +mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak +cp ./apfiles/dnsmasq.conf /etc/dnsmasq.conf mv /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.bak cp ./apfiles/hostapd.conf /etc/hostapd/hostapd.conf @@ -28,21 +35,41 @@ cp ./apfiles/hostapd.conf /etc/hostapd/hostapd.conf mv /etc/default/hostapd /etc/default/hostapd.bak cp ./apfiles/hostapd /etc/default/hostapd -mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bak -cp ./apfiles/dnsmasq.conf /etc/dnsmasq.conf + +#for testing +#mv /etc/dhcpcd.conf /etc/dhcpcd.conf.bak +#cp ./apfiles/dhcpcd.conf /etc/dhcpcd.conf +#chown :pi /etc/dhcpcd.conf + +mv /etc/network/interfaces /etc/network/interfaces.bak +cp ./apfiles/interfaces /etc/network/interfaces + +#sudo service dhcpcd restart +#ifdown wlan0; ifup wlan0 mv /etc/sysctl.conf /etc/sysctl.conf.bak cp ./apfiles/sysctl.conf /etc/sysctl.conf +#updates for allowing joustmania to work +#echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf +#echo 1 > /proc/sys/net/ipv4/ip_forward +iptables -t nat -A POSTROUTING -s 10.3.141.0/24 ! -d 10.3.141.0/24 -j MASQUERADE +#iptables-save > /etc/iptables/rules.v4 +#sh -c "iptables-save > /etc/iptables.ipv4.nat" + iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT +#iptables -A FORWARD -i eth0 -o uap0 -m state --state RELATED,ESTABLISHED -j ACCEPT + + iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT +#iptables -A FORWARD -i uap0 -o eth0 -j ACCEPT sh -c "iptables-save > /etc/iptables.ipv4.nat" mv /etc/rc.local /etc/rc.local.bak cp ./apfiles/rc.local /etc/rc.local -update-rc.d hostapd enable -update-rc.d dnsmasq enable +#update-rc.d hostapd enable +#update-rc.d dnsmasq enable reboot diff --git a/games/commander.py b/games/commander.py index 0a24cd6b..c829aef8 100644 --- a/games/commander.py +++ b/games/commander.py @@ -23,15 +23,7 @@ MIN_MUSIC_SLOW_TIME = 10 MAX_MUSIC_SLOW_TIME = 23 -#Sensitivity of the contollers -#changes by the values in common #TODO: make commander should be harder to kill -SLOW_MAX = 1.3 -SLOW_WARNING = 0.28 -FAST_MAX = 2.5 -FAST_WARNING = 1.3 - - #How long the speed change takes INTERVAL_CHANGE = 1.5 @@ -81,16 +73,18 @@ def calculate_flash_time(r,g,b, score): new_b = int(common.lerp(255, b, flash_percent)) return (new_r, new_g, new_b) -def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, music_speed, commander_intro, move_opts, power, overdrive): - #proc = psutil.Process(os.getpid()) - #proc.nice(3) - - +def track_move(move, team, dead_move, force_color, music_speed, commander_intro, move_opts, commander_powers, commander_overdrive, restart, menu, controller_sensitivity): + if team == Team.alpha.value: + overdrive = commander_overdrive[0] + power = commander_powers[0] + else: + overdrive = commander_overdrive[1] + power = commander_powers[1] + start = False no_rumble = time.time() + 1 move_last_value = None - move = common.get_move(move_serial, move_num) - team_colors = colors.generate_colors(num_teams) + team_colors = colors.generate_colors(2) #keep on looping while move is not dead ready = False move.set_leds(0,0,0) @@ -100,7 +94,13 @@ def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, m vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 - change_arr = [0,0,0] + change = 0 + #change_arr = [0,0,0] + + SLOW_MAX = controller_sensitivity[0] + SLOW_WARNING = controller_sensitivity[1] + FAST_MAX = controller_sensitivity[2] + FAST_WARNING = controller_sensitivity[3] death_time = 8 time_of_death = time.time() @@ -130,6 +130,8 @@ def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, m move_opts[Opts.selection.value] = Selections.nothing.value while True: + if(restart.value == 1 or menu.value == 1): + return if sum(force_color) != 0: no_rumble_time = time.time() + 5 time.sleep(0.01) @@ -141,66 +143,60 @@ def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, m elif dead_move.value == 1: if move.poll(): ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf) - #total = sum([ax, ay, az]) total = sqrt(sum([ax**2, ay**2, az**2])) - if move_last_value is not None: - change_real = abs(move_last_value - total) - change_arr[0] = change_arr[1] - change_arr[1] = change_arr[2] - change_arr[2] = change_real - change = (change_arr[0] + change_arr[1]+change_arr[2])/3 + change = (change * 4 + total)/5 - if move_opts[Opts.is_commander.value] == Bool.no.value: - if overdrive.value == 0: - warning = SLOW_WARNING - threshold = SLOW_MAX - else: - warning = FAST_WARNING - threshold = FAST_MAX - else: - #if affected by overdrive, this could make the power better + if move_opts[Opts.is_commander.value] == Bool.no.value: + if overdrive.value == 0: warning = SLOW_WARNING threshold = SLOW_MAX - + else: + warning = FAST_WARNING + threshold = FAST_MAX + else: + #if affected by overdrive, this could make the power better + warning = SLOW_WARNING + threshold = SLOW_MAX + - if change > threshold: - if time.time() > no_rumble: - move.set_leds(0,0,0) - move.set_rumble(90) - dead_move.value = 0 - time_of_death = time.time() + if change > threshold: + if time.time() > no_rumble: + move.set_leds(0,0,0) + move.set_rumble(90) + dead_move.value = 0 + time_of_death = time.time() - elif change > warning and not vibrate: - if time.time() > no_rumble: - move.set_leds(20,50,100) - vibrate = True - vibration_time = time.time() + 0.5 + elif change > warning and not vibrate: + if time.time() > no_rumble: + move.set_leds(20,50,100) + vibrate = True + vibration_time = time.time() + 0.5 - else: - if move_opts[Opts.is_commander.value] == Bool.no.value: - if overdrive.value == 0: - move.set_leds(*Commander_colors[team]) - else: - move.set_leds(*Overdrive_colors[team]) + else: + if move_opts[Opts.is_commander.value] == Bool.no.value: + if overdrive.value == 0: + move.set_leds(*Commander_colors[team]) else: - move.set_leds(*calculate_flash_time(Current_commander_colors[team][0],Current_commander_colors[team][1],Current_commander_colors[team][2], power.value)) - move.set_rumble(0) + move.set_leds(*Overdrive_colors[team]) + else: + move.set_leds(*calculate_flash_time(Current_commander_colors[team][0],Current_commander_colors[team][1],Current_commander_colors[team][2], power.value)) + move.set_rumble(0) - if move_opts[Opts.is_commander.value] == Bool.yes.value: - if (move.get_buttons() == 0 and move.get_trigger() < 10): - move_opts[Opts.holding.value] = Holding.not_holding.value - - button = move.get_buttons() - #print str(power.value) - if power.value >= 1.0: - #press trigger for overdrive - if (move_opts[Opts.holding.value] == Holding.not_holding.value and move.get_trigger() > 100): - move_opts[Opts.selection.value] = Selections.trigger.value - move_opts[Opts.holding.value] = Holding.holding.value + if move_opts[Opts.is_commander.value] == Bool.yes.value: + if (move.get_buttons() == 0 and move.get_trigger() < 10): + move_opts[Opts.holding.value] = Holding.not_holding.value + + button = move.get_buttons() + #print str(power.value) + if power.value >= 1.0: + #press trigger for overdrive + if (move_opts[Opts.holding.value] == Holding.not_holding.value and move.get_trigger() > 100): + move_opts[Opts.selection.value] = Selections.trigger.value + move_opts[Opts.holding.value] = Holding.holding.value - move_last_value = total + #move_last_value = total if vibrate: flash_lights_timer += 1 if flash_lights_timer > 7: @@ -228,7 +224,8 @@ def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, m class Commander(): - def __init__(self, moves, command_queue, ns, music): + def __init__(self, moves, command_queue, ns, music, dead_moves, commander_intro, commander_move_opt,\ + commander_powers, commander_overdrive, music_speed,force_color, restart, controller_teams): self.command_queue = command_queue self.ns = ns @@ -236,56 +233,49 @@ def __init__(self, moves, command_queue, ns, music): self.sensitivity = self.ns.settings['sensitivity'] self.random_teams = self.ns.settings['random_teams'] - global SLOW_MAX - global SLOW_WARNING - global FAST_MAX - global FAST_WARNING - - SLOW_MAX = common.SLOW_MAX[self.sensitivity] - SLOW_WARNING = common.SLOW_WARNING[self.sensitivity] - FAST_MAX = common.FAST_MAX[self.sensitivity] - FAST_WARNING = common.FAST_WARNING[self.sensitivity] - self.update_time = 0 self.move_serials = moves self.tracked_moves = {} - self.dead_moves = {} + self.dead_moves = dead_moves self.teams = {} - self.music_speed = Value('d', 1) + self.music_speed = music_speed + self.music_speed.value = 1 self.running = True - self.force_move_colors = {} + self.force_move_colors = force_color self.num_teams = 2 self.werewolf_timer = 35 self.start_timer = time.time() self.audio_cue = 0 - self.move_opts = {} + self.move_opts = commander_move_opt self.current_commander = ["",""] self.time_to_power = [20,20] self.activated_time = [time.time(), time.time()] self.activated_overdrive = [time.time(), time.time()] + self.controller_teams = controller_teams - - self.powers = [Value('d', 0.0), Value('d', 0.0)] + self.powers = commander_powers + self.powers[0].value = 0.0 + self.powers[1].value = 0.0 + self.restart = restart - self.alpha_overdrive = Value('i', 0) - self.bravo_overdrive = Value('i', 0) + self.alpha_overdrive = commander_overdrive[0] + self.alpha_overdrive.value = 0 + self.bravo_overdrive = commander_overdrive[1] + self.alpha_overdrive.value = 1 self.generate_random_teams(self.num_teams) - self.commander_intro = Value('i', 1) + self.commander_intro = commander_intro + self.commander_intro.value = 1 self.powers_active = [False, False] -## try: -## music = 'audio/Commander/music/' + random.choice(os.listdir('audio/Commander/music')) -## except: -## print('no music in audio/Commander/music') self.start_beep = Audio('audio/Joust/sounds/start.wav') self.start_game = Audio('audio/Joust/sounds/start3.wav') self.explosion = Audio('audio/Joust/sounds/Explosion34.wav') @@ -322,32 +312,14 @@ def generate_random_teams(self, num_teams): def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): - time.sleep(0.02) - dead_move = Value('i', 1) - force_color = Array('i', [1] * 3) - opts = Array('i', [0] * 5) - power = self.powers[self.teams[move_serial]] - - if self.teams[move_serial] == Team.alpha.value: - overdrive = self.alpha_overdrive - else: - overdrive = self.bravo_overdrive - proc = Process(target=track_move, args=(move_serial, - move_num, - self.teams[move_serial], - self.num_teams, - dead_move, - force_color, - self.music_speed, - self.commander_intro, - opts, - power, - overdrive)) - proc.start() - self.tracked_moves[move_serial] = proc - self.dead_moves[move_serial] = dead_move - self.force_move_colors[move_serial] = force_color - self.move_opts[move_serial] = opts + self.controller_teams[move_serial].value = self.teams[move_serial] + self.dead_moves[move_serial].value = 1 + self.force_move_colors[move_serial][0] = 1 + self.force_move_colors[move_serial][1] = 1 + self.force_move_colors[move_serial][2] = 1 + for i in range(5): + self.move_opts[move_serial][i] = 0 + def change_all_move_colors(self, r, g, b): for color in self.force_move_colors.values(): @@ -408,10 +380,7 @@ def check_end_game(self): def stop_tracking_moves(self): - for proc in self.tracked_moves.values(): - proc.terminate() - proc.join() - time.sleep(0.02) + self.restart.value = 1 def end_game(self): try: @@ -563,6 +532,7 @@ def commander_intro_audio(self): def game_loop(self): self.track_moves() + self.restart.value = 0 self.commander_intro_audio() self.count_down() diff --git a/games/fight_club.py b/games/fight_club.py index d5466acd..a64549de 100644 --- a/games/fight_club.py +++ b/games/fight_club.py @@ -30,14 +30,6 @@ END_MIN_MUSIC_SLOW_TIME = 8 END_MAX_MUSIC_SLOW_TIME = 12 -#Default Sensitivity of the contollers -#These are changed from the options in common -SLOW_MAX = 1 -SLOW_WARNING = 0.28 -FAST_MAX = 1.8 -FAST_WARNING = 0.8 - - #How long the speed change takes INTERVAL_CHANGE = 1.5 @@ -46,31 +38,26 @@ KILL_GAME_PAUSE = 4 -def track_move(move_serial, move_num, dead_move, force_color, music_speed, color, invincibility): - #proc = psutil.Process(os.getpid()) - #proc.nice(3) - #explosion = Audio('audio/Joust/sounds/Explosion34.wav') - #explosion.start_effect() +def track_move(move, dead_move, force_color, music_speed, color, invincibility, menu, restart, controller_sensitivity): start = False no_rumble = time.time() + 1 move_last_value = None - move = common.get_move(move_serial, move_num) - #team_colors = colors.generate_colors(num_teams) vibrate = False vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 start_inv = False - change_arr = [0,0,0] + change = 0 + + SLOW_MAX = controller_sensitivity[0] + SLOW_WARNING = controller_sensitivity[1] + FAST_MAX = controller_sensitivity[2] + FAST_WARNING = controller_sensitivity[3] #keep on looping while move is not dead while True: - #if show_team_colors.value == 1: - # if team.value != -1: - # move.set_leds(*team_colors[team.value]) - # else: - # move.set_leds(100,100,100) - # move.update_leds() + if(menu.value == 1 or restart.value == 1): + return if sum(force_color) != 0: no_rumble_time = time.time() + 5 time.sleep(0.01) @@ -83,76 +70,66 @@ def track_move(move_serial, move_num, dead_move, force_color, music_speed, color elif dead_move.value == 1: #and not invincibility.value: if move.poll(): ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf) - #total = sum([ax, ay, az]) total = sqrt(sum([ax**2, ay**2, az**2])) - if move_last_value is not None: - change_real = abs(move_last_value - total) - change_arr[0] = change_arr[1] - change_arr[1] = change_arr[2] - change_arr[2] = change_real - change = (change_arr[0] + change_arr[1]+change_arr[2])/3 - speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) - warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) - threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) - if not start_inv and invincibility.value: - start_inv = True - vibrate = True - vibration_time = time.time() + 4 - - - if vibrate: - flash_lights_timer += 1 - if flash_lights_timer > 7: - flash_lights_timer = 0 - flash_lights = not flash_lights - if flash_lights: - #move.set_leds(100,100,100) - if color.value == 1: - move.set_leds(*colors.Colors.Orange.value) - if color.value == 2: - move.set_leds(*colors.Colors.Blue.value) - if color.value == 4: - move.set_leds(*colors.Colors.Green.value) - else: - #if team.value != -1: - # move.set_leds(*team_colors[team.value]) - #else: - move.set_leds(10,10,10) - if time.time() < vibration_time - 0.22: - move.set_rumble(110) - else: - move.set_rumble(0) - if time.time() > vibration_time: - #print("vibrate to false") - vibrate = False - start_inv = False - invincibility.value = False - else: - #move.set_leds(100,200,100) + change = (change * 4 + total)/5 + + speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) + warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) + threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) + if not start_inv and invincibility.value: + start_inv = True + vibrate = True + vibration_time = time.time() + 4 + + if vibrate: + flash_lights_timer += 1 + if flash_lights_timer > 7: + flash_lights_timer = 0 + flash_lights = not flash_lights + if flash_lights: + #move.set_leds(100,100,100) if color.value == 1: move.set_leds(*colors.Colors.Orange.value) if color.value == 2: move.set_leds(*colors.Colors.Blue.value) if color.value == 4: move.set_leds(*colors.Colors.Green.value) - - if not invincibility.value: - if change > threshold: - #print("over threshold") - if time.time() > no_rumble: - move.set_leds(*colors.Colors.Red.value) - move.set_rumble(90) - dead_move.value = -1 - - elif change > warning and not vibrate: - if time.time() > no_rumble: - vibrate = True - vibration_time = time.time() + 0.5 - move.set_leds(20,50,100) - - + else: + #if team.value != -1: + # move.set_leds(*team_colors[team.value]) + #else: + move.set_leds(10,10,10) + if time.time() < vibration_time - 0.22: + move.set_rumble(110) + else: + move.set_rumble(0) + if time.time() > vibration_time: + #print("vibrate to false") + vibrate = False + start_inv = False + invincibility.value = False + else: + #move.set_leds(100,200,100) + if color.value == 1: + move.set_leds(*colors.Colors.Orange.value) + if color.value == 2: + move.set_leds(*colors.Colors.Blue.value) + if color.value == 4: + move.set_leds(*colors.Colors.Green.value) - move_last_value = total + if not invincibility.value: + if change > threshold: + if time.time() > no_rumble: + move.set_leds(*colors.Colors.Red.value) + move.set_rumble(90) + dead_move.value = -1 + + elif change > warning and not vibrate: + if time.time() > no_rumble: + vibrate = True + vibration_time = time.time() + 0.5 + move.set_leds(20,50,100) + move.update_leds() else: if dead_move.value < 1: @@ -170,7 +147,7 @@ def track_move(move_serial, move_num, dead_move, force_color, music_speed, color class Fight_club(): - def __init__(self, moves, command_queue, ns, music): + def __init__(self, moves, command_queue, ns, music, show_team_colors, music_speed, dead_moves, force_move_colors, invincible_moves, fight_club_colors, restart): self.command_queue = command_queue self.ns = ns @@ -178,31 +155,22 @@ def __init__(self, moves, command_queue, ns, music): self.sensitivity = self.ns.settings['sensitivity'] self.play_audio = self.ns.settings['play_audio'] - print("speed is {}".format(self.sensitivity)) - global SLOW_MAX - global SLOW_WARNING - global FAST_MAX - global FAST_WARNING - - SLOW_MAX = common.SLOW_MAX[self.sensitivity] - SLOW_WARNING = common.SLOW_WARNING[self.sensitivity] - FAST_MAX = common.FAST_MAX[self.sensitivity] - FAST_WARNING = common.FAST_WARNING[self.sensitivity] - self.move_serials = moves self.tracked_moves = {} - self.dead_moves = {} - self.music_speed = Value('d', 1.5) + self.dead_moves = dead_moves + self.music_speed = music_speed + self.music_speed.value = 1.5 #Value('d', 1.5) self.running = True - self.force_move_colors = {} - self.invince_moves = {} + self.force_move_colors = force_move_colors + self.invince_moves = invincible_moves self.start_timer = time.time() self.audio_cue = 0 self.num_dead = 0 - self.show_team_colors = Value('i', 0) + self.show_team_colors = show_team_colors + self.show_team_colors.value = 0 #Value('i', 0) self.teams = {} self.update_time = 0 @@ -229,13 +197,13 @@ def __init__(self, moves, command_queue, ns, music): #just for the sound effects self.revive_time = time.time() + 4 - self.colors = {} + self.colors = fight_club_colors + self.restart = restart fast_resample = False if self.play_audio: -## music = 'audio/Joust/music/' + random.choice(os.listdir('audio/Joust/music')) self.loud_beep = Audio('audio/Joust/sounds/beep_loud.wav') self.start_beep = Audio('audio/Joust/sounds/start.wav') self.start_game = Audio('audio/Joust/sounds/start3.wav') @@ -246,7 +214,6 @@ def __init__(self, moves, command_queue, ns, music): end = False self.audio = music - #self.change_time = self.get_change_time(speed_up = True) self.speed_up = True self.currently_changing = False @@ -268,24 +235,13 @@ def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): time.sleep(0.1) - dead_move = Value('i', 0) + for i in range(3): + self.force_move_colors[move_serial][i] = 1 + + self.colors[move_serial].value = 0 + self.invince_moves[move_serial].value = True + self.dead_moves[move_serial].value = 0 - force_color = Array('i', [1] * 3) - invincibility = Value('b', True) - color = Value('i', 0) - proc = Process(target=track_move, args=(move_serial, - move_num, - dead_move, - force_color, - self.music_speed, - color, - invincibility)) - proc.start() - self.colors[move_serial] = color - self.invince_moves[move_serial] = invincibility - self.tracked_moves[move_serial] = proc - self.dead_moves[move_serial] = dead_move - self.force_move_colors[move_serial] = force_color def change_all_move_colors(self, r, g, b): for color in self.force_move_colors.values(): @@ -388,8 +344,6 @@ def alive_move_count(self): #more than one tied winner, have them face off def face_off(self): - #print(self.winning_moves) - #os.popen('espeak -ven -p 70 -a 200 "Tie game..... Face off"') Audio('audio/Fight_Club/tie_game.wav').start_effect() for move in self.move_serials: @@ -438,17 +392,12 @@ def check_end_game(self): self.check_winner() if self.round_counter == self.round_num - 5: Audio('audio/Fight_Club/5_rounds.wav').start_effect() - #os.popen('espeak -ven -p 70 -a 200 "5 rounds remain"') if self.round_counter == self.round_num - 1: Audio('audio/Fight_Club/last_round.wav').start_effect() - #os.popen('espeak -ven -p 70 -a 200 "last round"') def stop_tracking_moves(self): - for proc in self.tracked_moves.values(): - proc.terminate() - proc.join() - time.sleep(0.02) + self.restart.value = 1 def end_game(self): self.audio.stop_audio() @@ -486,9 +435,7 @@ def check_next_fighter(self): self.dead_moves[self.chosen_defender].value = 0 self.colors[self.chosen_defender].value = 0 self.chosen_defender = self.chosen_fighter - #self.colors[self.chosen_defender].value = 1 self.chosen_fighter = self.fighter_list.pop() - #self.colors[self.chosen_fighter].value = 2 self.revive_fighters() self.reset_round_timer() @@ -502,7 +449,6 @@ def check_next_fighter(self): self.colors[self.chosen_fighter].value = 0 self.dead_moves[self.chosen_fighter].value = 0 self.chosen_fighter = self.fighter_list.pop() - #self.colors[self.chosen_fighter].value = 2 self.revive_fighters() self.reset_round_timer() @@ -559,18 +505,16 @@ def reset_round_timer(self): saying = random.randint(0,2) if saying == 0: Audio('audio/Fight_Club/defender_lead.wav').start_effect() - #os.popen('espeak -ven -p 70 -a 200 "Defender has taken the lead"') elif saying == 1: Audio('audio/Fight_Club/defender_winning.wav').start_effect() - #os.popen('espeak -ven -p 70 -a 200 "Defender is now winning"') elif saying == 2: Audio('audio/Fight_Club/Defender_high_score.wav').start_effect() - #os.popen('espeak -ven -p 70 -a 200 "Defender has the high score"') self.check_end_game() def game_loop(self): self.track_moves() + self.restart.value = 0 self.show_team_colors.value = 0 self.count_down() self.change_time = time.time() + 6 @@ -592,8 +536,6 @@ def game_loop(self): self.update_time = time.time() self.check_command_queue() self.update_status('in_game') - #if self.play_audio: - #self.check_music_speed() self.check_next_fighter() self.check_end_round() if self.game_end: diff --git a/games/speed_bomb.py b/games/speed_bomb.py index 5f585897..4ec6ae7e 100644 --- a/games/speed_bomb.py +++ b/games/speed_bomb.py @@ -50,16 +50,10 @@ def calculate_flash_time(r,g,b, score): new_b = int(common.lerp(255, b, flash_percent)) return (new_r, new_g, new_b) -def track_move(move_serial, move_num, dead_move, force_color,bomb_color, move_opts, game_start, false_color, faked, rumble): - #proc = psutil.Process(os.getpid()) - #proc.nice(3) - - +def track_move(move, dead_move, force_color,bomb_color, move_opts, game_start, false_color, faked, rumble, menu, restart): start = False no_rumble = time.time() + 1 move_last_value = None - move = common.get_move(move_serial, move_num) - #keep on looping while move is not dead ready = False move.set_leds(0,0,0) @@ -79,7 +73,9 @@ def track_move(move_serial, move_num, dead_move, force_color,bomb_color, move_op move_opts[Opts.holding.value] = Holding.not_holding.value move_opts[Opts.selection.value] = Selections.nothing.value - while not super_dead: + while True: + if(menu.value == 1 or restart.value == 1): + return if sum(force_color) != 0 and game_start.value == 1: no_rumble_time = time.time() + 5 time.sleep(0.01) @@ -104,7 +100,6 @@ def track_move(move_serial, move_num, dead_move, force_color,bomb_color, move_op if(move.get_trigger() > 50 and can_fake): faking = True - #move_opts[Opts.holding.value] = Holding.holding.value move_opts[Opts.selection.value] = Selections.false_trigger.value if (move.get_trigger() <= 127): @@ -112,14 +107,11 @@ def track_move(move_serial, move_num, dead_move, force_color,bomb_color, move_op col2 = int(common.lerp(fake_bomb_color[1], no_fake_bomb_color[1], (move.get_trigger()-50)/77)) col3 = int(common.lerp(fake_bomb_color[2], no_fake_bomb_color[2], (move.get_trigger()-50)/77)) move.set_leds(col1,col2,col3) - #if (move.get_trigger() > 127 and move.get_trigger() <= 140): - # move.set_leds(*no_fake_bomb_color) if (move.get_trigger() > 127): col1 = int(common.lerp(no_fake_bomb_color[0], fake_bomb_color[0], (move.get_trigger()-127)/128)) col2 = int(common.lerp(no_fake_bomb_color[1], fake_bomb_color[1], (move.get_trigger()-127)/128)) col3 = int(common.lerp(no_fake_bomb_color[2], fake_bomb_color[2], (move.get_trigger()-127)/128)) move.set_leds(col1,col2,col3) - #move.set_leds(0,200,0) else: @@ -127,10 +119,8 @@ def track_move(move_serial, move_num, dead_move, force_color,bomb_color, move_op if game_start.value == 0: move.set_leds(*force_color) move.update_leds() - #move_opts[Opts.holding.value] == Holding.not_holding.value if faking: - #move_opts[Opts.selection.value] = Selections.not_holding.value if game_start.value == 1: can_fake = False faking = False @@ -150,7 +140,6 @@ def track_move(move_serial, move_num, dead_move, force_color,bomb_color, move_op if game_start.value == 1 and false_color.value == 1: print("JUST DIED TO BEING FAKED!!!") faked.value = 1 - #dead_move.value -= 1 move.set_rumble(0) if move_opts[Opts.holding.value] == Holding.not_holding.value and (button in common.all_shapes): @@ -170,21 +159,18 @@ def track_move(move_serial, move_num, dead_move, force_color,bomb_color, move_op else: if super_dead == False: - #for i in range(100): - # time.sleep(0.01) - # move.set_leds(0,random.randrange(100, 200),0) - # move.set_rumble(200) - # move.update_leds() super_dead = True + move.set_rumble(0) move.set_leds(0,0,0) + time.sleep(2) move.update_leds() #if we are dead class Bomb(): - def __init__(self, moves, command_queue, ns, music): + def __init__(self, moves, command_queue, ns, music, bomb_color, game_start, five_move_opts, dead_moves, force_move_colors, false_colors, was_faked, rumble, music_speed,restart): self.command_queue = command_queue self.ns = ns @@ -192,23 +178,28 @@ def __init__(self, moves, command_queue, ns, music): self.play_audio = self.ns.settings['play_audio'] self.move_serials = moves self.tracked_moves = {} - self.dead_moves = {} + self.dead_moves = dead_moves self.alive_moves = [] self.teams = {} - self.music_speed = Value('d', 1) + self.music_speed = music_speed + self.music_speed.value = 1 self.running = True - self.force_move_colors = {} - self.bomb_color = Array('i', [0] * 3) + self.force_move_colors = force_move_colors + self.bomb_color = bomb_color + for i in range(3): + self.bomb_color[i] = 0 self.start_timer = time.time() self.audio_cue = 0 self.num_bombs = 2 - self.move_opts = {} - self.false_colors = {} - self.was_faked = {} - self.rumble = {} + self.move_opts = five_move_opts + self.false_colors = false_colors + self.was_faked = was_faked + self.rumble = rumble self.bomb_length = 5.0 + self.restart = restart - self.game_start = Value('i', 0) + self.game_start = game_start + self.game_start.value = 0 self.current_rand_holder = '' self.next_rand_holder = '' self.prev_rand_holder = '' @@ -217,10 +208,6 @@ def __init__(self, moves, command_queue, ns, music): self.update_time = 0 if self.play_audio: -## try: -## music = 'audio/Commander/music/' + random.choice(os.listdir('audio/Commander/music')) -## except: -## print('no music in audio/Commander/music') self.start_beep = Audio('audio/Joust/sounds/start.wav') self.start_game = Audio('audio/Joust/sounds/start3.wav') self.explosion = Audio('audio/Joust/sounds/Explosion34.wav') @@ -256,16 +243,11 @@ def get_prev_random_holder(self): def get_next_random_holder(self): - #if self.current_rand_holder != self.bomb_serial: - #self.current_rand_holder = self.move_serials[random.choice(range(len(self.move_serials)))] - #while self.current_rand_holder == self.bomb_serial: - # self.current_rand_holder = self.move_serials[random.choice(range(len(self.move_serials)))] if self.next_rand_holder == self.bomb_serial: self.next_rand_holder = self.move_serials[random.choice(range(len(self.move_serials)))] while self.next_rand_holder == self.bomb_serial or self.dead_moves[self.next_rand_holder].value <= 0: self.next_rand_holder = self.move_serials[random.choice(range(len(self.move_serials)))] self.current_rand_holder = self.bomb_serial - #print("returning " + self.next_rand_holder) return self.next_rand_holder @@ -278,10 +260,6 @@ def get_next_bomb_holder(self, serial=None): holder = random.choice(range(len(self.move_serials))) while True: yield self.get_next_random_holder() - #new_serial = self.move_serials[holder] - #if self.dead_moves[new_serial].value > 0: - # yield new_serial - #holder = (holder +1) % len(self.move_serials) def reset_bomb_time(self): @@ -290,6 +268,7 @@ def reset_bomb_time(self): def game_loop(self): self.track_moves() + self.restart.value = 0 self.rotate_colors() self.bomb_serial = self.move_serials[random.choice(range(len(self.move_serials)))] self.next_rand_holder = self.bomb_serial @@ -380,8 +359,6 @@ def pause_for_player_death(self, dead_move, faker_move=None): faker_color_array = self.force_move_colors[faker_move] for move_serial in self.move_serials: - #if move_serial == faker_move: - # colors.change_color(faker_color_array, random.randrange(100, 200), 10, 10) if move_serial == dead_move: colors.change_color(dead_color_array, 10, random.randrange(100, 200), 10) self.rumble[move_serial].value = 150 @@ -453,25 +430,6 @@ def check_faked_out(self): if self.move_opts[prev_faker][Opts.holding.value] == Holding.not_holding.value: self.false_colors[move_serial].value = 0 - #Probably should get rid of this, or only when we are being faked out - #elif self.false_colors[move_serial].value == 0 and self.move_opts[move_serial][Opts.holding.value] == Holding.holding.value : - # if self.move_opts[move_serial][Opts.selection.value] == Selections.counter.value and self.move_opts[self.get_prev_serial(move_serial)][Opts.has_bomb.value] == Bool.yes.value: - - # self.explosion40.start_effect() - # self.Fakecountered.start_effect() - # self.pause_for_player_death(move_serial) - - # self.dead_moves[move_serial].value -= 1 - #self.move_opts[move_serial][Opts.holding.value] = Holding.holding.value - - # self.reset_bomb_length() - # self.reset_bomb_time() - - # self.move_bomb() - # print("JUST DIED TO PRESSING COUNTER") - - #check for faked - def get_next_serial(self, serial): @@ -480,9 +438,6 @@ def get_next_serial(self, serial): pos = (self.get_serial_pos(serial) + 1) % len(self.move_serials) - #pos = random.choice(range(len(self.move_serials))) - #while random_move == pos - 1: - # random_move = random.choice(range(len(self.move_serials))) new_serial = self.move_serials[pos] while self.dead_moves[new_serial].value == 0: @@ -510,33 +465,14 @@ def get_serial_pos(self, serial): def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): self.alive_moves.append(move_serial) - time.sleep(0.02) - dead_move = Value('i', 2) - force_color = Array('i', [1] * 3) - false_color = Value('i', 0) - - opts = Array('i', [0] * 5) - faked = Value('i', 0) - rumble = Value('i', 0) - - proc = Process(target=track_move, args=(move_serial, - move_num, - dead_move, - force_color, - self.bomb_color, - opts, - self.game_start, - false_color, - faked, - rumble)) - proc.start() - self.tracked_moves[move_serial] = proc - self.dead_moves[move_serial] = dead_move - self.force_move_colors[move_serial] = force_color - self.move_opts[move_serial] = opts - self.false_colors[move_serial] = false_color - self.was_faked[move_serial] = faked - self.rumble[move_serial] = rumble + self.dead_moves[move_serial].value = 2 + for i in range(3): + self.force_move_colors[move_serial][i] = 1 + for i in range(5): + self.move_opts[move_serial][i] = 0 + self.false_colors[move_serial].value = 0 + self.was_faked[move_serial].value = 0 + self.rumble[move_serial].value = 0 def rotate_colors(self): @@ -596,12 +532,6 @@ def check_dead_moves(self): self.move_opts[alive_serial][Opts.has_bomb.value] = Bool.no.value self.move_bomb() - #for i, bomb_serial in enumerate(self.bomb_serials): - #if self.bomb_serial == alive_serial: - # self.bomb_serial = next(self.bomb_generators[i]) - #self.move_opts[self.bomb_serial][Opts.has_bomb.value] = Bool.yes.value - #remove alive move: - self.alive_moves.remove(alive_serial) if self.play_audio: self.explosion.start_effect() @@ -611,10 +541,7 @@ def check_dead_moves(self): self.end_game() def stop_tracking_moves(self): - for proc in self.tracked_moves.values(): - proc.terminate() - proc.join() - time.sleep(0.02) + self.restart.value = 1 def end_game(self): if self.play_audio: diff --git a/games/swapper.py b/games/swapper.py index bc2a5c67..42c2a5f9 100644 --- a/games/swapper.py +++ b/games/swapper.py @@ -23,15 +23,6 @@ MIN_MUSIC_SLOW_TIME = 10 MAX_MUSIC_SLOW_TIME = 23 -#Sensitivity of the contollers -#changes by the values in common -#TODO: make commander should be harder to kill -SLOW_MAX = 1.3 -SLOW_WARNING = 0.28 -FAST_MAX = 2.5 -FAST_WARNING = 1.3 - - #How long the speed change takes INTERVAL_CHANGE = 1.5 @@ -79,14 +70,10 @@ def calculate_flash_time(r,g,b, score): new_b = int(common.lerp(255, b, flash_percent)) return (new_r, new_g, new_b) -def track_move(move_serial, move_num, team, num_teams, team_colors, dead_move, force_color, music_speed, move_opts): - #proc = psutil.Process(os.getpid()) - #proc.nice(3) - +def track_move(move, team, num_teams, team_colors, dead_move, force_color, music_speed, move_opts, restart, menu, controller_sensitivity): start = False no_rumble = time.time() + 1 move_last_value = None - move = common.get_move(move_serial, move_num) #keep on looping while move is not dead ready = False move.set_leds(*colors.Colors.Black.value) @@ -96,7 +83,12 @@ def track_move(move_serial, move_num, team, num_teams, team_colors, dead_move, f vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 - change_arr = [0,0,0] + change = 0 + + SLOW_MAX = controller_sensitivity[0] + SLOW_WARNING = controller_sensitivity[1] + FAST_MAX = controller_sensitivity[2] + FAST_WARNING = controller_sensitivity[3] death_time = 2 time_of_death = time.time() @@ -104,6 +96,8 @@ def track_move(move_serial, move_num, team, num_teams, team_colors, dead_move, f move_opts[Opts.selection.value] = Selections.nothing.value while True: + if(menu.value == 1 or restart.value == 1): + return if sum(force_color) != 0: no_rumble_time = time.time() + 5 time.sleep(0.01) @@ -116,58 +110,58 @@ def track_move(move_serial, move_num, team, num_teams, team_colors, dead_move, f if move.poll(): ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf) - #total = sum([ax, ay, az]) total = sqrt(sum([ax**2, ay**2, az**2])) - if move_last_value is not None: - change_real = abs(move_last_value - total) - change_arr[0] = change_arr[1] - change_arr[1] = change_arr[2] - change_arr[2] = change_real - change = (change_arr[0] + change_arr[1]+change_arr[2])/3 - - warning = SLOW_WARNING - threshold = SLOW_MAX - - - if vibrate: - flash_lights_timer += 1 - if flash_lights_timer > 7: - flash_lights_timer = 0 - flash_lights = not flash_lights - if flash_lights: - move.set_leds(*colors.Colors.White60.value) - else: - move.set_leds(*team_colors[team.value].value) - if time.time() < vibration_time - 0.22: - move.set_rumble(110) + change = (change * 4 + total)/5 + + warning = SLOW_WARNING + threshold = SLOW_MAX + + + if vibrate: + flash_lights_timer += 1 + if flash_lights_timer > 7: + flash_lights_timer = 0 + flash_lights = not flash_lights + if flash_lights: + move.set_leds(*colors.Colors.White60.value) + else: + if(team.value == 0): + + move.set_leds(team_colors[0],team_colors[1],team_colors[2]) else: - move.set_rumble(0) - if time.time() > vibration_time: - vibrate = False + move.set_leds(team_colors[3],team_colors[4],team_colors[5]) + if time.time() < vibration_time - 0.22: + move.set_rumble(110) else: - move.set_leds(*team_colors[team.value].value) - - - if change > threshold: - if time.time() > no_rumble: - #vibrate = False - move.set_leds(*colors.Colors.Black.value) - move.set_rumble(90) - dead_move.value = 0 - time_of_death = time.time() - - elif change > warning and not vibrate: - if time.time() > no_rumble: - vibrate = True - vibration_time = time.time() + 0.5 - move.set_leds(20,50,100) - #else: - # move.set_rumble(0) + move.set_rumble(0) + if time.time() > vibration_time: + vibrate = False + else: + if(team.value == 0): + + move.set_leds(team_colors[0],team_colors[1],team_colors[2]) + else: + move.set_leds(team_colors[3],team_colors[4],team_colors[5]) + + + if change > threshold: + if time.time() > no_rumble: + #vibrate = False + move.set_leds(*colors.Colors.Black.value) + move.set_rumble(90) + dead_move.value = 0 + time_of_death = time.time() + + elif change > warning and not vibrate: + if time.time() > no_rumble: + vibrate = True + vibration_time = time.time() + 0.5 + move.set_leds(20,50,100) + #else: + # move.set_rumble(0) - - move_last_value = total move.update_leds() #if we are dead elif dead_move.value <= 0: @@ -183,7 +177,7 @@ def track_move(move_serial, move_num, team, num_teams, team_colors, dead_move, f class Swapper(): - def __init__(self, moves, command_queue, ns, music): + def __init__(self, moves, command_queue, ns, music, controller_colors, dead_moves, music_speed, force_move_colors, controller_opts, controller_teams, restart): self.command_queue = command_queue self.ns = ns @@ -194,39 +188,38 @@ def __init__(self, moves, command_queue, ns, music): self.color_lock = self.ns.settings['color_lock'] self.color_lock_choices = self.ns.settings['color_lock_choices'] self.random_teams = self.ns.settings['random_teams'] - - global SLOW_MAX - global SLOW_WARNING - global FAST_MAX - global FAST_WARNING - - SLOW_MAX = common.SLOW_MAX[self.sensitivity] - SLOW_WARNING = common.SLOW_WARNING[self.sensitivity] - FAST_MAX = common.FAST_MAX[self.sensitivity] - FAST_WARNING = common.FAST_WARNING[self.sensitivity] self.move_serials = moves self.tracked_moves = {} - self.dead_moves = {} - self.teams = {} - self.music_speed = Value('d', 1) + self.dead_moves = dead_moves + self.teams = controller_teams + self.music_speed = music_speed + self.music_speed.value = 1 self.running = True - self.force_move_colors = {} + self.force_move_colors = force_move_colors self.num_teams = 2 + self.restart = restart self.start_timer = time.time() self.audio_cue = 0 - self.move_opts = {} + self.move_opts = controller_opts self.update_time = 0 self.team_colors = colors.generate_team_colors(self.num_teams,self.color_lock,self.color_lock_choices) + self.controller_colors = controller_colors + self.controller_colors[0] = self.team_colors[0].value[0] + self.controller_colors[1] = self.team_colors[0].value[1] + self.controller_colors[2] = self.team_colors[0].value[2] + + self.controller_colors[3] = self.team_colors[1].value[0] + self.controller_colors[4] = self.team_colors[1].value[1] + self.controller_colors[5] = self.team_colors[1].value[2] self.generate_random_teams(self.num_teams) if self.play_audio: -## music = 'audio/Joust/music/' + random.choice(os.listdir('audio/Joust/music')) self.start_beep = Audio('audio/Joust/sounds/start.wav') self.start_game = Audio('audio/Joust/sounds/start3.wav') @@ -238,7 +231,6 @@ def __init__(self, moves, command_queue, ns, music): except: print('no audio loaded') - #self.change_time = self.get_change_time(speed_up = True) self.change_time = time.time() + 8 self.speed_up = True self.currently_changing = False @@ -251,37 +243,22 @@ def generate_random_teams(self, num_teams): players_per_team = (len(self.move_serials)//num_teams)+1 team_num = [x for x in range(num_teams)]*players_per_team for num,move in zip(team_num,self.move_serials): - self.teams[move] = Value('i',num) + self.teams[move].value = num# = Value('i',num) else: team_pick = list(range(num_teams)) for serial in self.move_serials: - random_choice = Value('i', random.choice(team_pick) ) - self.teams[serial] = random_choice - team_pick.remove(random_choice.value) + self.teams[serial].value = random.choice(team_pick) # = random_choice + team_pick.remove(self.teams[serial].value) if not team_pick: team_pick = list(range(num_teams)) def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): - time.sleep(0.02) - dead_move = Value('i', 1) - force_color = Array('i', [1] * 3) - opts = Array('i', [0] * 5) - proc = Process(target=track_move, args=(move_serial, - move_num, - self.teams[move_serial], - self.num_teams, - self.team_colors, - dead_move, - force_color, - self.music_speed, - - opts)) - proc.start() - self.tracked_moves[move_serial] = proc - self.dead_moves[move_serial] = dead_move - self.force_move_colors[move_serial] = force_color - self.move_opts[move_serial] = opts + self.dead_moves[move_serial].value = 1 + for i in range(3): + self.force_move_colors[move_serial][i] = 1 + for i in range(5): + self.move_opts[move_serial][i]=0 def change_all_move_colors(self, r, g, b): for color in self.force_move_colors.values(): @@ -325,10 +302,7 @@ def check_end_game(self): def stop_tracking_moves(self): - for proc in self.tracked_moves.values(): - proc.terminate() - proc.join() - time.sleep(0.02) + self.restart.value = 1 def end_game(self): if self.play_audio: @@ -378,6 +352,7 @@ def end_game_sound(self, winning_team): def game_loop(self): self.track_moves() + self.restart.value = 0 self.count_down() if self.play_audio: try: diff --git a/games/tournament.py b/games/tournament.py index 4380288f..2ed632d5 100644 --- a/games/tournament.py +++ b/games/tournament.py @@ -29,14 +29,6 @@ END_MIN_MUSIC_SLOW_TIME = 8 END_MAX_MUSIC_SLOW_TIME = 12 -#Default Sensitivity of the contollers -#These are changed from the options in common -SLOW_MAX = 1 -SLOW_WARNING = 0.28 -FAST_MAX = 1.8 -FAST_WARNING = 0.8 - - #How long the speed change takes INTERVAL_CHANGE = 1.5 @@ -45,15 +37,10 @@ KILL_GAME_PAUSE = 4 -def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, music_speed, show_team_colors, invincibility): - #proc = psutil.Process(os.getpid()) - #proc.nice(3) - #explosion = Audio('audio/Joust/sounds/Explosion34.wav') - #explosion.start_effect() +def track_move(move, team, num_teams, dead_move, force_color, music_speed, show_team_colors, invincibility, menu, restart, controller_sensitivity): start = False no_rumble = time.time() + 1 move_last_value = None - move = common.get_move(move_serial, move_num) team_colors = colors.generate_colors(num_teams) vibrate = False vibration_time = time.time() + 1 @@ -61,9 +48,17 @@ def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, m flash_lights_timer = 0 start_inv = False change_arr = [0,0,0] + change = 0 + + SLOW_MAX = controller_sensitivity[0] + SLOW_WARNING = controller_sensitivity[1] + FAST_MAX = controller_sensitivity[2] + FAST_WARNING = controller_sensitivity[3] #keep on looping while move is not dead while True: + if(menu.value == 1 or restart.value == 1): + return if show_team_colors.value == 1: if team.value != -1: move.set_leds(*team_colors[team.value]) @@ -82,65 +77,57 @@ def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, m elif dead_move.value == 1 and team.value != -1: if move.poll(): ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf) - #total = sum([ax, ay, az]) total = sqrt(sum([ax**2, ay**2, az**2])) - if move_last_value is not None: - change_real = abs(move_last_value - total) - change_arr[0] = change_arr[1] - change_arr[1] = change_arr[2] - change_arr[2] = change_real - change = (change_arr[0] + change_arr[1]+change_arr[2])/3 - speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) - warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) - threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) - if not start_inv and invincibility.value == 1: - start_inv = True - vibrate = True - vibration_time = time.time() + 3 - + change = (change * 4 + total)/5 + + speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) + warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) + threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) + if not start_inv and invincibility.value == 1: + start_inv = True + vibrate = True + vibration_time = time.time() + 3 + - if vibrate: - flash_lights_timer += 1 - if flash_lights_timer > 7: - flash_lights_timer = 0 - flash_lights = not flash_lights - if flash_lights: - move.set_leds(100,100,100) - else: - if team.value != -1: - move.set_leds(*team_colors[team.value]) - else: - move.set_leds(100,100,100) - if time.time() < vibration_time - 0.22: - move.set_rumble(110) - else: - move.set_rumble(0) - if time.time() > vibration_time: - vibrate = False - start_inv = False - invincibility.value = 0 + if vibrate: + flash_lights_timer += 1 + if flash_lights_timer > 7: + flash_lights_timer = 0 + flash_lights = not flash_lights + if flash_lights: + move.set_leds(100,100,100) else: if team.value != -1: move.set_leds(*team_colors[team.value]) else: move.set_leds(100,100,100) - - if invincibility.value == 0: - if change > threshold: - if time.time() > no_rumble: - move.set_leds(0,0,0) - move.set_rumble(90) - dead_move.value = 0 - - elif change > warning and not vibrate: - if time.time() > no_rumble: - vibrate = True - vibration_time = time.time() + 0.5 - move.set_leds(20,50,100) - - + if time.time() < vibration_time - 0.22: + move.set_rumble(110) + else: + move.set_rumble(0) + if time.time() > vibration_time: + vibrate = False + start_inv = False + invincibility.value = 0 + else: + if team.value != -1: + move.set_leds(*team_colors[team.value]) + else: + move.set_leds(100,100,100) - move_last_value = total + if invincibility.value == 0: + if change > threshold: + if time.time() > no_rumble: + move.set_leds(0,0,0) + move.set_rumble(90) + dead_move.value = 0 + + elif change > warning and not vibrate: + if time.time() > no_rumble: + vibrate = True + vibration_time = time.time() + 0.5 + move.set_leds(20,50,100) + move.update_leds() else: if dead_move.value < 1: @@ -154,7 +141,7 @@ def track_move(move_serial, move_num, team, num_teams, dead_move, force_color, m class Tournament(): - def __init__(self, moves, command_queue, ns, music): + def __init__(self, moves, command_queue, ns, music, show_team_colors, music_speed, teams, dead_moves, force_move_colors, invincible_moves, num_teams, restart): self.command_queue = command_queue self.ns = ns @@ -162,36 +149,29 @@ def __init__(self, moves, command_queue, ns, music): self.sensitivity = self.ns.settings['sensitivity'] self.play_audio = self.ns.settings['play_audio'] - print("speed is {}".format(self.sensitivity)) - global SLOW_MAX - global SLOW_WARNING - global FAST_MAX - global FAST_WARNING - - SLOW_MAX = common.SLOW_MAX[self.sensitivity] - SLOW_WARNING = common.SLOW_WARNING[self.sensitivity] - FAST_MAX = common.FAST_MAX[self.sensitivity] - FAST_WARNING = common.FAST_WARNING[self.sensitivity] - self.move_serials = moves self.tracked_moves = {} - self.dead_moves = {} - self.music_speed = Value('d', 1.5) + self.dead_moves = dead_moves + self.music_speed = music_speed + self.music_speed.value = 1.5 # Value('d', 1.5) self.running = True - self.force_move_colors = {} - self.invince_moves = {} + self.force_move_colors = force_move_colors + self.invince_moves = invincible_moves self.start_timer = time.time() self.audio_cue = 0 self.num_dead = 0 - self.show_team_colors = Value('i', 0) - self.teams = {} + self.show_team_colors = show_team_colors + self.show_team_colors.value = 0 #Value('i', 0) + self.teams = teams self.update_time = 0 + self.restart = restart #self.num_teams = math.ceil(len(moves)/2) self.num_teams = len(moves) + num_teams.value = self.num_teams self.generate_random_teams(self.num_teams) @@ -201,14 +181,12 @@ def __init__(self, moves, command_queue, ns, music): if self.play_audio: print("tourney list is " + str(self.tourney_list)) -## music = 'audio/Joust/music/' + random.choice(os.listdir('audio/Joust/music')) self.start_beep = Audio('audio/Joust/sounds/start.wav') self.start_game = Audio('audio/Joust/sounds/start3.wav') self.explosion = Audio('audio/Joust/sounds/Explosion34.wav') end = False self.audio = music - #self.change_time = self.get_change_time(speed_up = True) self.speed_up = True self.currently_changing = False @@ -249,34 +227,18 @@ def insert_move(arr): def generate_random_teams(self, num_teams): team_pick = list(range(num_teams)) for serial in self.move_serials: - random_choice = Value('i', random.choice(team_pick) ) - self.teams[serial] = random_choice - team_pick.remove(random_choice.value) + self.teams[serial].value = random.choice(team_pick)# = random_choice + team_pick.remove(self.teams[serial].value) if not team_pick: team_pick = list(range(num_teams)) def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): - time.sleep(0.02) - dead_move = Value('i', 1) - - force_color = Array('i', [1] * 3) - invincibility = Value('i', 0) - proc = Process(target=track_move, args=(move_serial, - move_num, - self.teams[move_serial], - self.num_teams, - dead_move, - force_color, - self.music_speed, - self.show_team_colors, - invincibility)) - proc.start() - self.invince_moves[move_serial] = invincibility - self.tracked_moves[move_serial] = proc - self.dead_moves[move_serial] = dead_move - self.force_move_colors[move_serial] = force_color + self.invince_moves[move_serial].value = 0 + self.dead_moves[move_serial].value = 1 + for i in range(3): + self.force_move_colors[move_serial][i] = 1 def change_all_move_colors(self, r, g, b): for color in self.force_move_colors.values(): @@ -414,10 +376,7 @@ def check_end_game(self): def stop_tracking_moves(self): - for proc in self.tracked_moves.values(): - proc.terminate() - proc.join() - time.sleep(0.02) + self.restart.value = 1 def end_game(self): self.audio.stop_audio() @@ -440,6 +399,7 @@ def end_game(self): def game_loop(self): self.track_moves() + self.restart.value = 0 self.show_team_colors.value = 0 self.count_down() self.change_time = time.time() + 6 diff --git a/games/zombie.py b/games/zombie.py index 9fe1a21a..f5834159 100644 --- a/games/zombie.py +++ b/games/zombie.py @@ -9,11 +9,11 @@ from math import sqrt -human_warning = 1 -human_max = 1.8 +#human_warning = 1 +#human_max = 1.8 -zombie_warning = 0.6 -zombie_max = 1.0 +#zombie_warning = 0.6 +#zombie_max = 1.0 zombie_spawn_invincibility = 2 zombie_max_respawn_time = 30 @@ -68,13 +68,7 @@ -def track_controller(serial, num_try, opts): - move = psmove.PSMove(num_try) - if move.get_serial() != serial: - for move_num in range(psmove.count_connected()): - move = psmove.PSMove(move_num) - if move.get_serial() == serial: - break +def track_controller(move, opts, restart, menu, controller_sensitivity): time.sleep(0.01) move.set_leds(200,200,200) move.update_leds() @@ -84,43 +78,43 @@ def track_controller(serial, num_try, opts): vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 - change_arr=[0,0,0] + #change_arr=[0,0,0] + change = 0 + + human_warning = controller_sensitivity[3] + human_max = controller_sensitivity[2] + zombie_warning = controller_sensitivity[9] + zombie_max = controller_sensitivity[8] while True: + if(restart.value == 1 or menu.value == 1): + break if move.poll(): ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf) - #total = sum([ax, ay, az]) total = sqrt(sum([ax**2, ay**2, az**2])) - if move_last_value is not None: - change_real = abs(move_last_value - total) - change_arr[0] = change_arr[1] - change_arr[1] = change_arr[2] - change_arr[2] = change_real - change = (change_arr[0] + change_arr[1]+change_arr[2])/3 - # Dead - - #TODO: should probably only change this - # when the state changes (i.e. human death) - if opts[0] == 0: - warning = human_warning - threshold = human_max - if opts[0] == 1: - warning = zombie_warning - threshold = zombie_max - + change = (change * 4 + total)/5 + # Dead + #TODO: should probably only change this + # when the state changes (i.e. human death) + if opts[0] == 0: + warning = human_warning + threshold = human_max + if opts[0] == 1: + warning = zombie_warning + threshold = zombie_max - if change > threshold: - move.set_leds(255,0,0) - move.set_rumble(100) - opts[3] = 0 - - # Warn - elif change > warning and not vibrate: - move.set_leds(20,50,100) - vibrate = True - vibration_time = time.time() + 0.5 - move.update_leds() + if change > threshold: + move.set_leds(255,0,0) + move.set_rumble(100) + opts[3] = 0 + + # Warn + elif change > warning and not vibrate: + move.set_leds(20,50,100) + vibrate = True + vibration_time = time.time() + 0.5 + move.update_leds() #if we are dead if opts[3] == 0: @@ -194,14 +188,14 @@ def track_controller(serial, num_try, opts): #else: # move.set_leds(*team_colors[team.value]) move.update_leds() - move_last_value = total + #move_last_value = total #we should try one process per controller, #since only normal music will be playing #need to make this a class with zombie killing defs class Zombie: - def __init__(self, cont_alive, command_queue, ns, music): + def __init__(self, cont_alive, command_queue, ns, music,restart, zombie_opts): self.command_queue = command_queue self.ns = ns @@ -210,22 +204,13 @@ def __init__(self, cont_alive, command_queue, ns, music): self.play_audio = self.ns.settings['play_audio'] self.music = music - - global human_warning - global human_max - global zombie_warning - global zombie_max - - human_warning = common.FAST_WARNING[self.sensitivity] - human_max = common.FAST_MAX[self.sensitivity] - zombie_warning = common.ZOMBIE_WARNING[self.sensitivity] - zombie_max = common.ZOMBIE_MAX[self.sensitivity] + self.restart = restart self.update_time = 0 self.humans = [] self.alive_zombies = [] self.dead_zombies = {} - self.controller_opts = {} + self.controller_opts = zombie_opts self.controllers_alive = cont_alive self.win_time = ((len(self.controllers_alive) * 3)/16) * 60 if self.win_time <= 0: @@ -293,22 +278,25 @@ def audio_cue(self): def Start(self): running = True moves = [] + print("gonna get moves") for move_num in range(len(self.controllers_alive)): moves.append(common.get_move(self.controllers_alive[move_num], move_num)) - + print("GOT THE MOVES") serials = self.controllers_alive processes = [] for num_try, serial in enumerate(serials): starting_bullets = 0 - #starting_bullets = random.choice([0, 1]) - opts = Array('i', [0, 0, 0, 1, starting_bullets, 1, 1]) - p = Process(target=track_controller, args=(serial, num_try, opts)) - p.start() - processes.append(p) - self.controller_opts[serial] = opts + self.controller_opts[serial][0] = 0 + self.controller_opts[serial][1] = 0 + self.controller_opts[serial][2] = 0 + self.controller_opts[serial][3] = 1 + self.controller_opts[serial][4] = starting_bullets + self.controller_opts[serial][5] = 1 + self.controller_opts[serial][6] = 1 self.humans.append(serial) - + self.restart.value = 0 + print("started the controllers") if self.play_audio: human_victory = Audio('audio/Zombie/sound_effects/human_victory.wav') zombie_victory = Audio('audio/Zombie/sound_effects/zombie_victory.wav') @@ -318,8 +306,6 @@ def Start(self): molotov = Audio('audio/Zombie/sound_effects/molotov.wav') try: self.music.start_audio_loop() -## music = Audio('audio/Zombie/music/' + random.choice(os.listdir('audio/Zombie/music/'))) -## music.start_effect_music() except: print('no music in audio/Zombie/music/') @@ -386,9 +372,7 @@ def Start(self): #win scenario if len(self.humans) <= 0 or (time.time() - self.start_time) > self.win_time or self.kill_game: - for proc in processes: - proc.terminate() - proc.join() + self.restart.value = 1 pause_time = time.time() + 3 HSV = [(x*1.0/(50*len(self.controllers_alive)), 0.9, 1) for x in range(50*len(self.controllers_alive))] colour_range = [[int(x) for x in colors.hsv2rgb(*colour)] for colour in HSV] diff --git a/joust.py b/joust.py index bc8cef65..3f181bca 100644 --- a/joust.py +++ b/joust.py @@ -9,6 +9,7 @@ from enum import Enum from multiprocessing import Process, Value, Array, Queue from math import sqrt +import statistics # How fast/slow the music can go @@ -30,16 +31,16 @@ #Default Sensitivity of the contollers #These are changed from the options in common -SLOW_MAX = 1 -SLOW_WARNING = 0.28 -FAST_MAX = 1.8 -FAST_WARNING = 0.8 +#SLOW_MAX = 1 +#SLOW_WARNING = 0.28 +#FAST_MAX = 1.8 +#FAST_WARNING = 0.8 #Sensitivity of the werewolf contollers -WERE_SLOW_MAX = 1.4 -WERE_SLOW_WARNING = 0.5 -WERE_FAST_MAX = 2.3 -WERE_FAST_WARNING = 1.2 +#WERE_SLOW_MAX = 1.4 +#WERE_SLOW_WARNING = 0.5 +#WERE_FAST_MAX = 2.3 +#WERE_FAST_WARNING = 1.2 #How long the speed change takes INTERVAL_CHANGE = 1.5 @@ -49,27 +50,38 @@ KILL_GAME_PAUSE = 4 -def track_move(move_serial, move_num, game_mode, team, team_color_enum, dead_move, force_color, music_speed, werewolf_reveal, show_team_colors, red_on_kill): - #proc = psutil.Process(os.getpid()) - #proc.nice(3) - #explosion = Audio('audio/Joust/sounds/Explosion34.wav') - #explosion.start_effect() +def track_move(move, game_mode, team, team_color_enum, dead_move, force_color, \ + music_speed, werewolf_reveal, show_team_colors, red_on_kill, restart, menu, controller_sensitivity): + + SLOW_MAX = controller_sensitivity[0] + SLOW_WARNING = controller_sensitivity[1] + FAST_MAX = controller_sensitivity[2] + FAST_WARNING = controller_sensitivity[3] + + WERE_SLOW_MAX = controller_sensitivity[4] + WERE_SLOW_WARNING = controller_sensitivity[5] + WERE_FAST_MAX = controller_sensitivity[6] + WERE_FAST_WARNING = controller_sensitivity[7] + start = False - no_rumble = time.time() + 1 + no_rumble = time.time() + 2 move_last_value = None - move = common.get_move(move_serial, move_num) - my_team_colors = team_color_enum.value + my_team_colors = team_color_enum werewolf = False vibrate = False - change_arr = [0,0,0] + change_arr = [0]*8 vibration_time = time.time() + 1 flash_lights = True flash_lights_timer = 0 + previous_average = 0 + change = 0 if team < 0: team = (team + 1) * -1 werewolf = True #keep on looping while move is not dead while True: + if(restart.value == 1 or menu.value == 1): + return if show_team_colors.value == 1: move.set_leds(*my_team_colors) move.update_leds() @@ -90,85 +102,79 @@ def track_move(move_serial, move_num, game_mode, team, team_color_enum, dead_mov move.set_rumble(0) move.update_leds() no_rumble = time.time() + 0.5 - elif dead_move.value == 1 and werewolf_reveal.value > 0: + elif dead_move.value == 1 and werewolf_reveal.value > 0: + if move.poll(): ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf) total = sqrt(sum([ax**2, ay**2, az**2])) - #total = sum([ax, ay, az]) - if move_last_value is not None: - change_real = abs(move_last_value - total) - change_arr[0] = change_arr[1] - change_arr[1] = change_arr[2] - change_arr[2] = change_real - change = (change_arr[0] + change_arr[1]+change_arr[2])/3 - speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) - if werewolf: - warning = common.lerp(WERE_SLOW_WARNING, WERE_FAST_WARNING, speed_percent) - threshold = common.lerp(WERE_SLOW_MAX, WERE_FAST_MAX, speed_percent) - else: - warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) - threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) + change = (change * 4 + total)/5 + speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED) + if werewolf: + warning = common.lerp(WERE_SLOW_WARNING, WERE_FAST_WARNING, speed_percent) + threshold = common.lerp(WERE_SLOW_MAX, WERE_FAST_MAX, speed_percent) + else: + warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent) + threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent) - if vibrate: - flash_lights_timer += 1 - if flash_lights_timer > 7: - flash_lights_timer = 0 - flash_lights = not flash_lights - if flash_lights: - if game_mode == common.Games.WereJoust: - move.set_leds(*colors.Colors.Black.value) - else: - move.set_leds(*colors.Colors.White40.value) - else: - if game_mode == common.Games.WereJoust: - if werewolf_reveal.value == 2 and werewolf: - move.set_leds(*colors.Colors.Blue40.value) - else: - move.set_leds(*colors.Colors.White40.value) - else: - move.set_leds(*my_team_colors) - if time.time() < vibration_time - 0.22: - move.set_rumble(110) + if vibrate: + flash_lights_timer += 1 + if flash_lights_timer > 7: + flash_lights_timer = 0 + flash_lights = not flash_lights + if flash_lights: + if game_mode == common.Games.WereJoust.value: + move.set_leds(*colors.Colors.Black.value) else: - move.set_rumble(0) - if time.time() > vibration_time: - vibrate = False - + move.set_leds(*colors.Colors.White40.value) else: - if game_mode == common.Games.WereJoust: + if game_mode == common.Games.WereJoust.value: if werewolf_reveal.value == 2 and werewolf: move.set_leds(*colors.Colors.Blue40.value) else: move.set_leds(*colors.Colors.White40.value) else: move.set_leds(*my_team_colors) - #move.set_rumble(0) + if time.time() < vibration_time-0.25: + move.set_rumble(90) + else: + move.set_rumble(0) + if time.time() > vibration_time: + vibrate = False + + else: + if game_mode == common.Games.WereJoust.value: + if werewolf_reveal.value == 2 and werewolf: + move.set_leds(*colors.Colors.Blue40.value) + else: + move.set_leds(*colors.Colors.White40.value) + else: + move.set_leds(*my_team_colors) + #move.set_rumble(0) - if change > threshold: - if time.time() > no_rumble: - if red_on_kill: - move.set_leds(*colors.Colors.Red.value) - else: - move.set_leds(*colors.Colors.Black.value) - move.set_rumble(90) - dead_move.value = 0 + if change > threshold: + if time.time() > no_rumble: + if red_on_kill: + move.set_leds(*colors.Colors.Red.value) + else: + move.set_leds(*colors.Colors.Black.value) + move.set_rumble(90) + dead_move.value = 0 - elif change > warning and not vibrate: - if time.time() > no_rumble: - vibrate = True - vibration_time = time.time() + 0.5 - #move.set_leds(20,50,100) + elif change > warning and not vibrate: + if time.time() > no_rumble: + vibrate = True + vibration_time = time.time() + 0.5 + #move.set_leds(20,50,100) - move_last_value = total + #move_last_value = total move.update_leds() elif dead_move.value < 1: - time.sleep(0.5) - if dead_move.value == -1 and game_mode == common.Games.NonStop: + if dead_move.value == -1 and game_mode == common.Games.NonStop.value: time.sleep(2) move_last_value = 0 change_arr = [0,0,0] @@ -178,8 +184,7 @@ def track_move(move_serial, move_num, game_mode, team, team_color_enum, dead_mov class Joust(): - def __init__(self, moves, command_queue, ns, music, teams, game_mode): - + def __init__(self, moves, command_queue, ns, music, teams, game_mode,controller_teams, controller_colors, dead_moves, force_move_colors,music_speed,werewolf_reveal, show_team_colors, red_on_kill, restart): self.command_queue = command_queue self.ns = ns @@ -196,11 +201,16 @@ def __init__(self, moves, command_queue, ns, music, teams, game_mode): self.red_on_kill = self.ns.settings['red_on_kill'] self.move_serials = moves - self.tracked_moves = {} - self.dead_moves = {} - self.music_speed = Value('d', SLOW_MUSIC_SPEED) + self.restart = restart + self.dead_moves = dead_moves + self.music_speed = music_speed + self.music_speed.value = SLOW_MUSIC_SPEED + + self.controller_teams = controller_teams + self.controller_colors = controller_colors + self.running = True - self.force_move_colors = {} + self.force_move_colors = force_move_colors self.teams = teams self.num_teams = len(colors.team_color_list) @@ -208,7 +218,8 @@ def __init__(self, moves, command_queue, ns, music, teams, game_mode): self.start_timer = time.time() self.audio_cue = 0 self.num_dead = 0 - self.show_team_colors = Value('i', 0) + self.show_team_colors = show_team_colors + self.show_team_colors.value = 0 self.non_stop_deaths = {} for move in self.move_serials: @@ -220,27 +231,9 @@ def __init__(self, moves, command_queue, ns, music, teams, game_mode): self.alive_moves = [] #self.update_status('starting') - - print("speed is {}".format(self.sensitivity)) - global SLOW_MAX - global SLOW_WARNING - global FAST_MAX - global FAST_WARNING - - SLOW_MAX = common.SLOW_MAX[self.sensitivity] - SLOW_WARNING = common.SLOW_WARNING[self.sensitivity] - FAST_MAX = common.FAST_MAX[self.sensitivity] - FAST_WARNING = common.FAST_WARNING[self.sensitivity] - - print("SLOWMAX IS {}".format(SLOW_MAX)) - - #Sensitivity of the werewolf contollers - WERE_SLOW_MAX = common.WERE_SLOW_MAX[self.sensitivity] - WERE_SLOW_WARNING = common.WERE_SLOW_WARNING[self.sensitivity] - WERE_FAST_MAX = common.WERE_FAST_MAX[self.sensitivity] - WERE_FAST_WARNING = common.WERE_FAST_WARNING[self.sensitivity] - self.werewolf_reveal = Value('i', 2) + self.werewolf_reveal = werewolf_reveal + self.werewolf_reveal.value = 2 if game_mode == common.Games.JoustFFA or game_mode == common.Games.NonStop: self.num_teams = len(moves) if game_mode == common.Games.JoustRandomTeams: @@ -262,7 +255,6 @@ def __init__(self, moves, command_queue, ns, music, teams, game_mode): self.werewolf_reveal.value = 0 self.num_teams = 1 - print('HELLO THE NUMBER OF TEAMS IS %d' % self.num_teams) if self.game_mode == common.Games.JoustTeams: self.team_colors = colors.team_color_list @@ -278,7 +270,6 @@ def __init__(self, moves, command_queue, ns, music, teams, game_mode): were_num = 1 self.choose_werewolf(were_num) if self.play_audio: - #music = random.choice(glob.glob("audio/Joust/music/*")) self.start_beep = Audio('audio/Joust/sounds/start.wav') self.start_game = Audio('audio/Joust/sounds/start3.wav') self.explosion = Audio('audio/Joust/sounds/Explosion34.wav') @@ -328,8 +319,6 @@ def generate_random_teams(self, num_teams): traitor_pick = False else: self.teams[serial] = random_choice - ## print("doing random choice") - ## print(random_choice) team_pick.remove(random_choice) if not team_pick: traitor_pick = False @@ -339,23 +328,14 @@ def track_moves(self): for move_num, move_serial in enumerate(self.move_serials): self.alive_moves.append(move_serial) time.sleep(0.1) - dead_move = Value('i', 1) - force_color = Array('i', [1] * 3) - proc = Process(target=track_move, args=(move_serial, - move_num, - self.game_mode, - self.teams[move_serial], - self.team_colors[self.teams[move_serial]], - dead_move, - force_color, - self.music_speed, - self.werewolf_reveal, - self.show_team_colors, - self.red_on_kill)) - proc.start() - self.tracked_moves[move_serial] = proc - self.dead_moves[move_serial] = dead_move - self.force_move_colors[move_serial] = force_color + self.controller_teams[move_serial].value = self.teams[move_serial] + self.controller_colors[move_serial][0] = self.team_colors[self.teams[move_serial]].value[0] + self.controller_colors[move_serial][1] = self.team_colors[self.teams[move_serial]].value[1] + self.controller_colors[move_serial][2] = self.team_colors[self.teams[move_serial]].value[2] + self.dead_moves[move_serial].value = 1 + self.force_move_colors[move_serial][0] =1 + self.force_move_colors[move_serial][1] =1 + self.force_move_colors[move_serial][2] =1 def change_all_move_colors(self, r, g, b): for color in self.force_move_colors.values(): @@ -428,7 +408,6 @@ def reveal(self): def werewolf_audio_cue(self): if self.game_mode == common.Games.WereJoust: - #print self.werewolf_timer - (time.time() - self.start_timer) if self.werewolf_timer - (time.time() - self.start_timer) <= 30 and self.audio_cue == 0: Audio('audio/Joust/sounds/30 werewolf.wav').start_effect() self.audio_cue = 1 @@ -498,10 +477,7 @@ def check_end_game(self): self.game_end = True def stop_tracking_moves(self): - for proc in self.tracked_moves.values(): - proc.terminate() - proc.join() - time.sleep(0.02) + self.restart.value = 1 def end_game(self): if self.play_audio: @@ -572,6 +548,7 @@ def werewolf_intro(self): def game_loop(self): self.track_moves() + self.restart.value = 0 if self.game_mode == common.Games.WereJoust: self.werewolf_intro() self.werewolf_reveal.value = 1 diff --git a/joust.sh b/joust.sh index a92a0112..5ad8a255 100755 --- a/joust.sh +++ b/joust.sh @@ -6,4 +6,5 @@ if [ $UID -ne 0 ]; then fi export HOME="/home/pi/JoustMania" -exec /home/pi/JoustMania/venv/bin/python3.6 /home/pi/JoustMania/piparty.py +export PYTHONPATH="/home/pi/psmoveapi/build/" +exec /home/pi/JoustMania/venv/bin/python3 /home/pi/JoustMania/piparty.py diff --git a/piaudio.py b/piaudio.py index 98ecdeca..9afab86f 100644 --- a/piaudio.py +++ b/piaudio.py @@ -12,83 +12,101 @@ # import alsaaudio import threading from pydub import AudioSegment +from multiprocessing import Process, Value, Array, Queue, Manager + import common -def audio_loop(wav_data, ratio, stop_proc): - pass +def audio_loop(fname, ratio, stop_proc): # TODO: As a future improvment, we could precompute resampled versions of the track # at the "steady" playback rates, and only do dynamic resampling when transitioning # between them. - - # PERIOD=1024 * 4 - # # Two channels, two bytes per sample. - # PERIOD_BYTES = PERIOD * 2 * 2 - # - # time.sleep(0.5) - # proc = psutil.Process(os.getpid()) - # proc.nice(-5) - # time.sleep(0.02) - # - # device = alsaaudio.PCM() - # wf = wave.open(io.BytesIO(wav_data), 'rb') - # device.setchannels(wf.getnchannels()) - # - # device.setformat(alsaaudio.PCM_FORMAT_S16_LE) - # device.setperiodsize(PERIOD) - # - # if len(wf.readframes(1)) == 0: - # raise ValueError("Empty WAV file played.") - # wf.rewind() - # device.setrate(wf.getframerate()) - - # Loops samples of up to read_size bytes from the wav file. - def ReadSamples(wf, read_size): - pass - # while True: - # sample = wf.readframes(read_size) - # if len(sample) > 0: - # yield sample - # else: - # wf.rewind() - - # Writes incoming samples in chunks of write_size to device. - # Quits when stop_proc is set to a non-zero value. - def WriteSamples(device, write_size, samples): - pass - # buf = bytearray() - # for sample in samples: - # buf.extend(sample) - # while len(buf) >= write_size: - # device.write(buf[:write_size]) - # del buf[:write_size] - # if stop_proc.value: - # return - - # Resamples audio data at the rate given by 'ratio' above. - def Resample(samples): - pass - # for data in samples: - # array = numpy.fromstring(data, dtype=numpy.int16) - # # Split data into seperate channels and resample. Divide by two - # # since there are two channels. We round to the nearest multiple of - # # 32 as the resampling is more efficient the closer the sizes are to - # # being powers of two. - # num_output_frames = int(array.size / (ratio.value * 2)) & (~0x1f) - # reshapel = signal.resample(array[0::2], num_output_frames) - # reshaper = signal.resample(array[1::2], num_output_frames) - # - # final = numpy.ones((num_output_frames,2)) - # final[:, 0] = reshapel - # final[:, 1] = reshaper - # - # out_data = final.flatten().astype(numpy.int16).tostring() - # yield out_data - - # WriteSamples(device, PERIOD_BYTES, Resample(ReadSamples(wf, PERIOD))) - # - # wf.close() - # device.close() + PERIOD=1024 * 4 + # Two channels, two bytes per sample. + PERIOD_BYTES = PERIOD * 2 * 2 + + time.sleep(0.5) + proc = psutil.Process(os.getpid()) + proc.nice(-5) + time.sleep(0.02) + wav_data = None + + + + song_loaded = False + while(True): + if(stop_proc.value == 1): + pass + elif(fname['song'] != ''): + if(song_loaded == False): + try: + segment = AudioSegment.from_file(fname['song']) + except: + segment = AudioSegment.from_wav("audio/Joust/music/classical.wav") + + wav_data = io.BytesIO() + segment.export(wav_data, 'wav') + wav_data = wav_data.getbuffer() + song_loaded = True + continue + elif(stop_proc.value == 0): + device = alsaaudio.PCM() + wf = wave.open(io.BytesIO(wav_data), 'rb') + device.setchannels(wf.getnchannels()) + + device.setformat(alsaaudio.PCM_FORMAT_S16_LE) + device.setperiodsize(PERIOD) + + if len(wf.readframes(1)) == 0: + raise ValueError("Empty WAV file played.") + wf.rewind() + device.setrate(wf.getframerate()) + + # Loops samples of up to read_size bytes from the wav file. + def ReadSamples(wf, read_size): + while True: + sample = wf.readframes(read_size) + if len(sample) > 0: + yield sample + else: + wf.rewind() + + # Writes incoming samples in chunks of write_size to device. + # Quits when stop_proc is set to a non-zero value. + def WriteSamples(device, write_size, samples): + buf = bytearray() + for sample in samples: + buf.extend(sample) + while len(buf) >= write_size: + device.write(buf[:write_size]) + del buf[:write_size] + if stop_proc.value: + return + + # Resamples audio data at the rate given by 'ratio' above. + def Resample(samples): + for data in samples: + array = numpy.fromstring(data, dtype=numpy.int16) + # Split data into seperate channels and resample. Divide by two + # since there are two channels. We round to the nearest multiple of + # 32 as the resampling is more efficient the closer the sizes are to + # being powers of two. + num_output_frames = int(array.size / (ratio.value * 2)) & (~0x1f) + reshapel = signal.resample(array[0::2], num_output_frames) + reshaper = signal.resample(array[1::2], num_output_frames) + + final = numpy.ones((num_output_frames,2)) + final[:, 0] = reshapel + final[:, 1] = reshaper + + out_data = final.flatten().astype(numpy.int16).tostring() + yield out_data + + WriteSamples(device, PERIOD_BYTES, Resample(ReadSamples(wf, PERIOD))) + print("closing everything") + wf.close() + device.close() + song_loaded = False @functools.lru_cache(maxsize=128) class Audio: @@ -122,43 +140,30 @@ def start_effect_and_wait(self): @functools.lru_cache(maxsize=16) class Music: - def __init__(self, fname): - self.load_thread_ = threading.Thread(target=lambda: self.load_sample_(fname)) - self.load_thread_.start() + def __init__(self, name): + self.name = name self.transition_future_ = asyncio.Future() + + self.stop_proc = Value('i', 1) + self.ratio = Value('d' , 1.0) + manager = Manager() + self.fname = manager.dict() + self.fname['song'] = '' - def wait_for_sample_(self): - if self.load_thread_: - self.load_thread_.join() - self.load_thread_ = None - - def load_sample_(self, fname): - try: - segment = AudioSegment.from_file(fname) - except: - print("error can not convert "+fname+" to wav") - print("trying to play classical.wav instead") - segment = AudioSegment.from_wav("audio/Joust/music/classical.wav") + self.t = Process(target=audio_loop, args=(self.fname, self.ratio, self.stop_proc)) + self.t.start() - self.fname_ = fname - wav_data = io.BytesIO() - segment.export(wav_data, 'wav') - self.wav_data_ = wav_data.getbuffer() + def load_audio(self, fname): + self.fname['song'] = fname + def start_audio_loop(self): - self.wait_for_sample_() - print ('audio file is ' + str(self.fname_)) - # Start audio in seperate process to be non-blocking - self.stop_proc = Value('i', 0) - self.ratio = Value('d' , 1.0) - - self.t = Thread(target=audio_loop, args=(self.wav_data_, self.ratio, self.stop_proc)) - self.t.start() + self.stop_proc.value = 0 def stop_audio(self): self.stop_proc.value = 1 + self.fname['song'] = '' time.sleep(0.1) - self.t.join() self.transition_future_.cancel() def change_ratio(self, ratio): diff --git a/piparty.py b/piparty.py index f670ffdd..43a063a7 100644 --- a/piparty.py +++ b/piparty.py @@ -11,13 +11,15 @@ import jm_dbus elif platform == "windows": import win_jm_dbus as jm_dbus +import controller_process +import update TEAM_NUM = len(colors.team_color_list) #TEAM_COLORS = colors.generate_colors(TEAM_NUM) -SENSITIVITY_MODES = 3 +SENSITIVITY_MODES = 5 class Opts(Enum): alive = 0 @@ -39,24 +41,29 @@ class Selections(Enum): change_sensitivity = 4 change_instructions = 5 show_battery = 6 + update = 7 + admin = 8 class Holding(Enum): not_holding = 0 holding = 1 class Sensitivity(Enum): - slow = 0 - mid = 1 - fast = 2 + ultra_slow = 0 + slow = 1 + mid = 2 + fast = 3 + ultra_fast = 4 -def track_move(serial, move_num, move_opts, force_color, battery, dead_count): - move = common.get_move(serial, move_num) +def track_move(serial, move_num, move, move_opts, force_color, battery, dead_count, restart, menu, kill_proc): move.set_leds(0,0,0) move.update_leds() random_color = random.random() while True: + if(restart.value ==1 or menu.value == 0 or kill_proc.value): + return time.sleep(0.01) if move.poll(): game_mode = common.Games(move_opts[Opts.game_mode.value]) @@ -68,12 +75,12 @@ def track_move(serial, move_num, move_opts, force_color, battery, dead_count): time.sleep(0.1) else: if move_button == common.Button.SHAPES: - move_opts[Opts.alive.value] = Alive.off.value - dead_count.value = dead_count.value + 1 - move.set_leds(0,0,0) - move.set_rumble(0) - move.update_leds() - continue + move_opts[Opts.selection.value] = Selections.admin.value + move_opts[Opts.holding.value] = Holding.holding.value + + if move_button == common.Button.UPDATE: + move_opts[Opts.selection.value] = Selections.update.value + move_opts[Opts.holding.value] = Holding.holding.value #show battery level if battery.value == 1: @@ -226,7 +233,7 @@ def track_move(serial, move_num, move_opts, force_color, battery, dead_count): class Menu(): def __init__(self): - + self.big_update = update.check_for_update() self.command_queue = Queue() self.joust_manager = Manager() self.ns = self.joust_manager.Namespace() @@ -262,33 +269,65 @@ def __init__(self): self.paired_moves = [] self.move_opts = {} self.teams = {} - self.game_mode = common.Games.Random - self.old_game_mode = common.Games.Random + self.game_mode = common.Games[self.ns.settings['current_game']] + self.old_game_mode = self.game_mode self.pair = pair.Pair() - + + self.menu = Value('i', 1) + self.controller_game_mode = Value('i',1) + self.restart = Value('i',0) + self.controller_teams = {} + self.controller_colors = {} + self.dead_moves = {} + self.music_speed= Value('d', 0) + self.werewolf_reveal = Value('i', 2) + self.show_team_colors = Value('i', 0) + self.red_on_kill = Value('i', 0) + self.zombie_opts = {} + self.commander_intro = Value('i',1) + self.commander_move_opts = {} + self.commander_powers = [Value('d', 0.0), Value('d', 0.0)] + self.commander_overdrive = [Value('i', 0), Value('i', 0)] + self.five_controller_opts = {} + self.swapper_team_colors = Array('i',[0]*6) + self.fight_club_colors = {} + self.invincible_moves = {} + self.num_teams = Value('i',1) + self.bomb_color = Array('i', [0] * 3) + self.game_start = Value('i', 0) + self.false_colors = {} + self.was_faked = {} + self.rumble = {} + self.kill_controller_proc = {} + self.controller_sensitivity = Array('d', [0] *10) + self.i = 0 #load audio now so it converts before the game begins + self.menu_music = Music("menu") + self.joust_music = Music("joust") + self.zombie_music = Music("zombie") + self.commander_music = Music("commander") + self.choose_new_music() + + def choose_new_music(self): - self.joust_music = Music(random.choice(glob.glob("audio/Joust/music/*"))) - try: - self.zombie_music = Music(random.choice(glob.glob("audio/Zombie/music/*"))) - except Exception: - self.zombie_music = DummyMusic() - try: - self.commander_music = Music(random.choice(glob.glob("audio/Commander/music/*"))) - except Exception: - self.commander_music = DummyMusic() + self.joust_music.load_audio(random.choice(glob.glob("audio/Joust/music/*"))) + self.zombie_music.load_audio(random.choice(glob.glob("audio/Zombie/music/*"))) + self.commander_music.load_audio(random.choice(glob.glob("audio/Commander/music/*"))) def exclude_out_moves(self): - for move in self.moves: - serial = move.get_serial() - if serial in self.move_opts: - if self.move_opts[move.get_serial()][Opts.alive.value] == Alive.off.value: - self.out_moves[move.get_serial()] = Alive.off.value - else: - self.out_moves[move.get_serial()] = Alive.on.value + pass + #currently does not work with the new stability update + #hold in the sync button to remove it from the game + #for move in self.moves: + #serial = move.get_serial() + #if serial in self.move_opts: + #if self.move_opts[move.get_serial()][Opts.alive.value] == Alive.off.value: + #self.out_moves[move.get_serial()] = Alive.off.value + #else: + #self.out_moves[move.get_serial()] = Alive.on.value def check_for_new_moves(self): self.enable_bt_scanning(True) @@ -323,10 +362,12 @@ def pair_usb_move(self, move): self.pair_one_move = False def pair_move(self, move, move_num): + print("NOW PAIRING MOVE") move_serial = move.get_serial() if move_serial not in self.tracked_moves: color = Array('i', [0] * 3) opts = Array('i', [0] * 6) + if move_serial in self.teams: opts[Opts.team.value] = self.teams[move_serial] else: @@ -337,14 +378,78 @@ def pair_move(self, move, move_num): opts[Opts.game_mode.value] = self.game_mode.value #now start tracking the move controller - proc = Process(target=track_move, args=(move_serial, move_num, opts, color, self.show_battery, self.dead_count)) + + + + team = Value('i',0) + team_color_enum = Array('i',[0]*3) + dead_move = Value( 'i',0) + zombie_opt = Array('i', [0, 0, 0, 1, 0, 1, 1]) + five_controller_opt = Array('i',[0]*5) + + + commander_move_opt = Array('i', [0] * 5) + invincibility = Value('b', True) + fight_club_color = Value('i', 0) + false_color = Value('i', 0) + faked = Value('i', 0) + rumble = Value('i', 0) + kill_proc = Value('b', False) + + + proc = Process(target= controller_process.main_track_move, args=(self.menu, self.restart, move_serial, move_num, opts, color, self.show_battery, \ + self.dead_count, self.controller_game_mode, team, team_color_enum, self.controller_sensitivity, dead_move, \ + self.music_speed, self.werewolf_reveal, self.show_team_colors, self.red_on_kill,zombie_opt,\ + self.commander_intro, commander_move_opt, self.commander_powers, self.commander_overdrive,\ + five_controller_opt, self.swapper_team_colors, invincibility, fight_club_color, self.num_teams,\ + self.bomb_color,self.game_start,false_color, faked, rumble, kill_proc)) + proc.start() self.move_opts[move_serial] = opts self.tracked_moves[move_serial] = proc self.force_color[move_serial] = color + self.controller_teams[move_serial] = team + self.controller_colors[move_serial] = team_color_enum + self.dead_moves[move_serial] = dead_move + self.zombie_opts[move_serial] = zombie_opt + self.commander_move_opts[move_serial] = commander_move_opt + self.five_controller_opts[move_serial] = five_controller_opt + self.fight_club_colors[move_serial] = fight_club_color + self.invincible_moves[move_serial] = invincibility + self.false_colors[move_serial] = false_color + self.was_faked[move_serial] = faked + self.rumble[move_serial] = rumble + self.kill_controller_proc[move_serial] = kill_proc + self.out_moves[move.get_serial()] = Alive.on.value + + + self.exclude_out_moves() + #def kill_controller(self, move_serial): + + + def remove_controller(self, move_serial): + self.kill_controller_proc[move_serial].value = True + self.tracked_moves[move_serial].join() + self.tracked_moves[move_serial].terminate() + del self.move_opts[move_serial] + #del self.tracked_moves[move_serial] + del self.force_color[move_serial] + del self.controller_teams[move_serial] + del self.controller_colors[move_serial] + del self.dead_moves[move_serial] + del self.zombie_opts[move_serial] + del self.commander_move_opts[move_serial] + del self.five_controller_opts[move_serial] + del self.fight_club_colors[move_serial] + del self.invincible_moves[move_serial] + del self.false_colors[move_serial] + del self.was_faked[move_serial] + del self.rumble[move_serial] + del self.kill_controller_proc[move_serial] + def game_mode_announcement(self): if self.game_mode == common.Games.JoustFFA: Audio('audio/Menu/menu Joust FFA.wav').start_effect() @@ -379,11 +484,11 @@ def check_change_mode(self): if move_opt[Opts.selection.value] == Selections.change_mode.value: #remove previous admin, and set new one if self.ns.settings['move_can_be_admin']: - if self.admin_move: - self.force_color[self.admin_move][0] = 0 - self.force_color[self.admin_move][1] = 0 - self.force_color[self.admin_move][2] = 0 - self.admin_move = move + #if self.admin_move: + #self.force_color[self.admin_move][0] = 0 + #self.force_color[self.admin_move][1] = 0 + #self.force_color[self.admin_move][2] = 0 + #self.admin_move = move change_mode = True move_opt[Opts.selection.value] = Selections.nothing.value @@ -393,6 +498,7 @@ def check_change_mode(self): if change_mode: self.game_mode = self.game_mode.next() + self.update_setting('current_game',self.game_mode.name) self.reset_controller_game_state() if not self.ns.settings['play_audio']: if self.game_mode == common.Games.Commander: @@ -403,40 +509,80 @@ def check_change_mode(self): opt[Opts.game_mode.value] = self.game_mode.value if self.ns.settings['play_audio']: self.game_mode_announcement() - + + def check_new_admin(self): + for move, move_opt in self.move_opts.items(): + if move_opt[Opts.selection.value] == Selections.admin.value: + #remove previous admin, and set new one + if self.ns.settings['move_can_be_admin']: + #set the old admin_move to have no colors + if self.admin_move: + self.force_color[self.admin_move][0] = 0 + self.force_color[self.admin_move][1] = 0 + self.force_color[self.admin_move][2] = 0 + self.admin_move = move + move_opt[Opts.selection.value] = Selections.nothing.value + + #all controllers need to opt-in again in order fo the game to start def reset_controller_game_state(self): for move_opt in self.move_opts.values(): #on means off here move_opt[Opts.random_start.value] = Alive.on.value + for serial in self.move_opts.keys(): + for i in range(3): + self.force_color[serial][i] = 0 self.random_added = [] + + def check_update(self): + for move, move_opt in self.move_opts.items(): + if move_opt[Opts.selection.value] == Selections.update.value: + if self.big_update: + update.big_update() + self.big_update = False def game_loop(self): self.play_menu_music = True while True: if self.play_menu_music: self.play_menu_music = False - try: - self.menu_music = Music(random.choice(glob.glob("audio/MenuMusic/*"))) - self.menu_music.start_audio_loop() - except Exception: - self.menu_music = DummyMusic() + self.menu_music.load_audio(random.choice(glob.glob("audio/MenuMusic/*"))) + self.menu_music.start_audio_loop() self.i=self.i+1 if not self.pair_one_move and "0" in os.popen('lsusb | grep "PlayStation Move motion controller" | wc -l').read(): self.pair_one_move = True self.paired_moves = [] if self.pair_one_move: - if psmove.count_connected() != len(self.tracked_moves): + #check if there are any controllers that were shut off + if psmove.count_connected() > len(self.tracked_moves): for move_num, move in enumerate(self.moves): if move.connection_type == psmove.Conn_USB and self.pair_one_move: self.pair_usb_move(move) elif move.connection_type != psmove.Conn_USB: self.pair_move(move, move_num) + elif(len(self.tracked_moves) > len(self.moves)): + connected_serials = [x.get_serial() for x in self.moves] + tracked_serials = self.tracked_moves.keys() + keys_to_kill = [] + for serial in tracked_serials: + if serial not in connected_serials: + #self.kill_controller_proc[serial].value = True + self.remove_controller(serial) + #self.tracked_moves[serial].join() + #self.tracked_moves[serial].terminate() + keys_to_kill.append(serial) + for key in keys_to_kill: + del self.tracked_moves[key] + if key == self.admin_move: + self.admin_move = None + self.check_for_new_moves() if len(self.tracked_moves) > 0: + self.check_new_admin() self.check_change_mode() self.check_admin_controls() self.check_start_game() + self.check_update() self.check_command_queue() self.update_status('menu') @@ -477,13 +623,17 @@ def check_admin_controls(self): self.update_setting('sensitivity', (self.ns.settings['sensitivity'] + 1) % SENSITIVITY_MODES) if self.ns.settings['play_audio']: - if self.ns.settings['sensitivity'] == Sensitivity.slow.value: - Audio('audio/Menu/slow_sensitivity.wav').start_effect() + if self.ns.settings['sensitivity'] == Sensitivity.ultra_slow.value: + Audio('audio/Menu/ultra_high.wav').start_effect() + elif self.ns.settings['sensitivity'] == Sensitivity.slow.value: + Audio('audio/Menu/high.wav').start_effect() elif self.ns.settings['sensitivity'] == Sensitivity.mid.value: - Audio('audio/Menu/mid_sensitivity.wav').start_effect() + Audio('audio/Menu/medium.wav').start_effect() elif self.ns.settings['sensitivity'] == Sensitivity.fast.value: - Audio('audio/Menu/fast_sensitivity.wav').start_effect() - + Audio('audio/Menu/low.wav').start_effect() + elif self.ns.settings['sensitivity'] == Sensitivity.ultra_fast.value: + Audio('audio/Menu/ultra_low.wav').start_effect() + #no admin colors in con custom teams mode if self.game_mode == common.Games.JoustTeams or self.game_mode == common.Games.Random: self.force_color[self.admin_move][0] = 0 @@ -526,6 +676,7 @@ def initialize_settings(self): 'play_instructions': True, #we store the name, not the enum, so the webui can process it more easily 'random_modes': [common.Games.JoustFFA.name,common.Games.JoustRandomTeams.name,common.Games.WereJoust.name,common.Games.Swapper.name], + 'current_game': common.Games.JoustFFA.name, 'play_audio': True, 'move_can_be_admin': True, 'enforce_minimum': True, @@ -637,6 +788,7 @@ def check_start_game(self): if start_game: + print("starting game") if self.game_mode == common.Games.Random: self.start_game(random_mode=True) else: @@ -675,10 +827,10 @@ def play_random_instructions(self): os.popen('espeak -ven -p 70 -a 200 "Two players fight, the winner must defend thier title, the player with the highest score wins') time.sleep(5) + def start_game(self, random_mode=False): self.enable_bt_scanning(False) self.exclude_out_moves() - self.stop_tracking_moves() time.sleep(1) self.teams = {serial: self.move_opts[serial][Opts.team.value] for serial in self.tracked_moves.keys() if self.out_moves[serial] == Alive.on.value} game_moves = [move.get_serial() for move in self.moves if self.out_moves[move.get_serial()] == Alive.on.value] @@ -689,9 +841,25 @@ def start_game(self, random_mode=False): if len(game_moves) < self.game_mode.minimum_players and self.ns.settings['enforce_minimum']: Audio('audio/Menu/notenoughplayers.wav').start_effect() - self.tracked_moves = {} + self.reset_controller_game_state() return + self.menu.value = 0 + self.restart.value =1 self.update_status('starting') + + self.sensitivity = self.ns.settings['sensitivity'] + self.controller_sensitivity[0] = common.SLOW_MAX[self.sensitivity] + self.controller_sensitivity[1] = common.SLOW_WARNING[self.sensitivity] + self.controller_sensitivity[2] = common.FAST_MAX[self.sensitivity] + self.controller_sensitivity[3] = common.FAST_WARNING[self.sensitivity] + + self.controller_sensitivity[4] = common.WERE_SLOW_MAX[self.sensitivity] + self.controller_sensitivity[5] = common.WERE_SLOW_WARNING[self.sensitivity] + self.controller_sensitivity[6] = common.WERE_FAST_MAX[self.sensitivity] + self.controller_sensitivity[7] = common.WERE_FAST_WARNING[self.sensitivity] + + self.controller_sensitivity[8] = common.ZOMBIE_MAX[self.sensitivity] + self.controller_sensitivity[9] = common.ZOMBIE_WARNING[self.sensitivity] if random_mode: good_random_modes = [game for game in common.Games if game.name in self.ns.settings['random_modes']] @@ -715,32 +883,29 @@ def start_game(self, random_mode=False): self.rand_game_list.append(selected_game) self.game_mode = selected_game + self.controller_game_mode.value = self.game_mode.value if self.ns.settings['play_instructions'] and self.ns.settings['play_audio']: self.play_random_instructions() if self.game_mode == common.Games.Zombies: - zombie.Zombie(game_moves, self.command_queue, self.ns, self.zombie_music) - self.tracked_moves = {} + zombie.Zombie(game_moves, self.command_queue, self.ns, self.zombie_music, self.restart, self.zombie_opts) elif self.game_mode == common.Games.Commander: - commander.Commander(game_moves, self.command_queue, self.ns, self.commander_music) - self.tracked_moves = {} + commander.Commander(game_moves, self.command_queue, self.ns, self.commander_music, self.dead_moves, self.commander_intro, self.commander_move_opts, \ + self.commander_powers, self.commander_overdrive, self.music_speed, self.force_color, self.restart, self.controller_teams) elif self.game_mode == common.Games.Ninja: - speed_bomb.Bomb(game_moves, self.command_queue, self.ns, self.commander_music) - self.tracked_moves = {} + speed_bomb.Bomb(game_moves, self.command_queue, self.ns, self.commander_music, self.bomb_color, self.game_start, self.five_controller_opts, self.dead_moves, self.force_color, self.false_colors, self.was_faked, self.rumble, self.music_speed,self.restart) elif self.game_mode == common.Games.Swapper: - swapper.Swapper(game_moves, self.command_queue, self.ns, self.joust_music) - self.tracked_moves = {} + swapper.Swapper(game_moves, self.command_queue, self.ns, self.joust_music, \ + self.swapper_team_colors, self.dead_moves, self.music_speed, self.force_color, self.five_controller_opts, self.controller_teams, self.restart) elif self.game_mode == common.Games.FightClub: if random.randint(0,1)==1: fight_music = self.commander_music else: fight_music = self.joust_music - fight_club.Fight_club(game_moves, self.command_queue, self.ns, fight_music) - self.tracked_moves = {} + fight_club.Fight_club(game_moves, self.command_queue, self.ns, fight_music, self.show_team_colors, self.music_speed, self.dead_moves, self.force_color, self.invincible_moves, self.fight_club_colors, self.restart) elif self.game_mode == common.Games.Tournament: - tournament.Tournament(game_moves, self.command_queue, self.ns, self.joust_music) - self.tracked_moves = {} + tournament.Tournament(game_moves, self.command_queue, self.ns, self.joust_music, self.show_team_colors, self.music_speed, self.controller_teams, self.dead_moves, self.force_color, self.invincible_moves, self.num_teams, self.restart) else: if self.game_mode == common.Games.JoustFFA and self.experimental: print("Playing EXPERIMENTAL FFA Mode.") @@ -749,8 +914,7 @@ def start_game(self, random_mode=False): game.run_loop() else: #may need to put in moves that have selected to not be in the game - joust.Joust(game_moves, self.command_queue, self.ns, self.joust_music, self.teams, self.game_mode) - self.tracked_moves = {} + joust.Joust(game_moves, self.command_queue, self.ns, self.joust_music, self.teams, self.game_mode, self.controller_teams, self.controller_colors, self.dead_moves, self.force_color,self.music_speed,self.werewolf_reveal, self.show_team_colors, self.red_on_kill, self.restart) if random_mode: self.game_mode = common.Games.Random if self.ns.settings['play_instructions']: @@ -762,7 +926,12 @@ def start_game(self, random_mode=False): #turn off admin mode so someone can't accidentally press a button self.admin_move = None self.random_added = [] + self.reset_controller_game_state() + self.menu.value = 1 + self.restart.value =0 + self.reset_controller_game_state() + if __name__ == "__main__": InitAudio() piparty = Menu() diff --git a/setup.sh b/setup.sh index 7dbd5b31..a754c1d8 100755 --- a/setup.sh +++ b/setup.sh @@ -1,9 +1,12 @@ #!/bin/bash +#test setup() { # Prevent apt from prompting us about restarting services. export DEBIAN_FRONTEND=noninteractive - + sudo apt-get install -y espeak + + espeak "starting software upgrade" #update OS sudo cp -v conf/sources.list /etc/apt/sources.list || exit -1 sudo cp -v conf/apt.conf /etc/apt/apt.conf.d/10joustmania-conf || exit -1 @@ -11,7 +14,7 @@ setup() { sudo apt-get upgrade -y || exit -1 sudo apt-get dist-upgrade -y || exit -1 cd /home/pi - + espeak "Installing required software dependencies" #TODO: remove pyaudio and dependencies #install components sudo apt-get install -y \ @@ -26,6 +29,7 @@ setup() { alsa-utils alsa-tools libasound2-dev \ python-dbus-dev libdbus-glib-1-dev espeak || exit -1 + espeak "Installing PS move A.P.I. software updates" #install components for psmoveapi sudo apt-get install -y \ build-essential \ @@ -35,22 +39,31 @@ setup() { + espeak "Installing software libraries" VENV=/home/pi/JoustMania/venv # We install nearly all python deps in the virtualenv to avoid concflicts with system, except # numpy and scipy because they take forever to build. - sudo apt-get install -y -t buster libasound2-dev libasound2 python3-scipy cmake - sudo python3.6 -m pip install --upgrade virtualenv || exit -1 + sudo apt-get install -y -t buster libasound2-dev libasound2 python3-scipy cmake || exit -1 + + #install the python3 dev environment + sudo apt-get install -y python3-dev || exit -1 + sudo python3 -m pip install --upgrade virtualenv || exit -1 + espeak "installing virtual environment" # Rebuilding this is pretty cheap, so just do it every time. rm -rf $VENV - /usr/bin/python3.6 -m virtualenv --system-site-packages $VENV || exit -1 - PYTHON=$VENV/bin/python3.6 + /usr/bin/python3 -m virtualenv --system-site-packages $VENV || exit -1 + PYTHON=$VENV/bin/python3 + espeak "installing virtual environment dependencies" $PYTHON -m pip install --ignore-installed psutil flask Flask-WTF pyalsaaudio pydub pygame pyaudio pyyaml dbus-python || exit -1 + espeak "downloading PS move API" #install psmoveapi + rm -rf psmoveapi git clone --recursive git://github.com/thp/psmoveapi.git cd psmoveapi + espeak "compiling PS move API components" mkdir build cd build # we definitely don't need java, opengj, csharp, etc @@ -64,7 +77,7 @@ setup() { -DPSMOVE_BUILD_TRACKER:BOOL=ON \ -DPSMOVE_USE_PSEYE:BOOL=OFF make -j4 - cp /home/pi/psmoveapi/build/{psmove.py,_psmove.so} $VENV/lib/python3.6 + cp /home/pi/psmoveapi/build/{psmove.py,_psmove.so} $VENV/lib/python3 #installs custom supervisor script for running joustmania on startup sudo cp -r /home/pi/JoustMania/conf/supervisor/ /etc/ @@ -77,7 +90,23 @@ setup() { #Use amixer to set sound output to 100% amixer sset PCM,0 100% sudo alsactl store + + + #This will disable on-board bluetooth + #This will allow only class one long range btdongles to connect to psmove controllers + sudo grep -qxF 'dtoverlay=pi3-disable-bt' /boot/config.txt || echo "dtoverlay=pi3-disable-bt" | sudo tee -a /boot/config.txt + sudo systemctl disable hciuart || exit -1 + + uname2="$(stat --format '%U' '/home/pi/JoustMania/setup.sh')" + uname3="$(stat --format '%U' '/home/pi/JoustMania/piparty.py')" + if [ "${uname2}" = "root" ] || [ "${uname3}" = "root" ] ; then + sudo chown -R pi:pi /home/pi/JoustMania/ + espeak "permisions updated, please wait after reboot for Joustmania to start" + else + echo "no permissions to update" + fi + espeak "Joustmania successfully updated, now rebooting" # Pause a second before rebooting so we can see all the output from this script. (sleep 1; sudo reboot) & } diff --git a/update.py b/update.py new file mode 100644 index 00000000..1e959c2f --- /dev/null +++ b/update.py @@ -0,0 +1,58 @@ +import subprocess +from piaudio import Audio, InitAudio +import time +import shlex + +if __name__ == "__main__": + InitAudio() + check_for_update() + +def run_command(command): + process = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE) + outout = "" + while True: + + output = process.stdout.readline().decode("utf-8") + if (output == "b''" or output == '') and process.poll() is not None: + break + if output: + outout += output + print(output.strip()) + rc = process.poll() + return outout + +def big_update(): + Audio('audio/Menu/update_started.wav').start_effect_and_wait() + current_hash = run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git rev-parse HEAD'").strip() + run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git checkout master'") + run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git pull'") + run_command("sudo /home/pi/JoustMania/setup.sh") + #it failed if it got this far + time.sleep(3) + run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git checkout {}'".format(current_hash)) + Audio('audio/Menu/joustmania_failed.wav').start_effect_and_wait() + +def tester(): + current_hash = run_command("sudo runuser -l pi -c 'git rev-parse HEAD'").strip() + print(current_hash) + +def check_for_update(): + process = run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;pwd'") + process = run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git fetch'") + diff_files = run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git diff origin/master --name-only'").split() + print(diff_files) + + + if('setup.sh' in diff_files): + Audio('audio/Menu/large_update.wav').start_effect_and_wait() + return True + + elif (len(diff_files) >= 1): + print("doing small pull") + pull = run_command("sudo runuser -l pi -c 'cd /home/pi/JoustMania/;git pull'") + Audio('audio/Menu/joustmania_updated.wav').start_effect_and_wait() + return False + + + + diff --git a/update_permissions.sh b/update_permissions.sh new file mode 100755 index 00000000..7f5e22fa --- /dev/null +++ b/update_permissions.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sudo chown -R pi:pi .