Escape closes soxsynth.

This commit is contained in:
Storm Dragon 2018-05-12 17:47:37 -04:00
parent 4872c92ca0
commit 4ea447b9e1
59 changed files with 15 additions and 332 deletions

10
bashit/.bashit.scoreboard Normal file
View File

@ -0,0 +1,10 @@
10 Anonymous
0 Anonymous
0 anonymous
0 anonymous
0 anonymous
0 anonymous
0 anonymous
0 anonymous
0 anonymous
0 anonymous

View File

@ -1,189 +0,0 @@
-- Store operating system commands in a variable.
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then
return s
end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
-- Speak with appropriate tool.
local function speak(text)
if os.capture("uname") == "Linux" then
os.execute('spd-say "' .. text .. '"')
else
os.execute('say "' .. text .. '"')
end
end
-- Window related variables.
local gameName = "Bottle Blaster"
local SDL = require "SDL"
local mixer = require "SDL.mixer"
local ret, err = SDL.init { SDL.flags.Video }
if not ret then
error(err)
end
local function trySDL(func, ...)
local t = { func(...) }
if not t[1] then
error(t[#t])
end
return table.unpack(t)
end
local function exit_game(SDL, mixer)
SDL.quit()
mixer.quit()
return false
end
local win, err = SDL.createWindow {
title = gameName,
width = 320,
height = 320
}
if not win then
error(err)
end
trySDL(mixer.openAudio, 44100, SDL.audioFormat.S16, 2, 1024)
-- Load all game sounds here:
-- Format: local variableName = trySDL(mixer.loadWAV, "path/to/file")
-- Supported file types flac, ogg, wav
local bottle =
{
trySDL(mixer.loadWAV, "sounds/glass1.ogg"),
trySDL(mixer.loadWAV, "sounds/glass2.ogg"),
trySDL(mixer.loadWAV, "sounds/glass3.ogg")
}
local gun =
{
trySDL(mixer.loadWAV, "sounds/gun1.ogg"),
trySDL(mixer.loadWAV, "sounds/gun2.ogg"),
trySDL(mixer.loadWAV, "sounds/gun3.ogg"),
trySDL(mixer.loadWAV, "sounds/gun4.ogg"),
trySDL(mixer.loadWAV, "sounds/gun5.ogg")
}
local empty = trySDL(mixer.loadWAV, "sounds/empty.ogg")
local load = {}
load[3] = trySDL(mixer.loadWAV, "sounds/load3.ogg")
load[4] = trySDL(mixer.loadWAV, "sounds/load3.ogg")
load[5] = trySDL(mixer.loadWAV, "sounds/load5.ogg")
local function play_sound(sound, channel, loop)
channel = channel or -1
loop = loop or 0
sound:playChannel(channel, loop)
end
local function play_at_location(sound, xPosition, yPosition)
channel = channel or -1
loop = loop or 0
xPosition = xPosition or 0
yPosition = yPosition or 0
mixer.SetPanning(-1, 255, 127)
sound:playChannel(-1, 0)
end
local function game_intro()
local sound = trySDL(mixer.loadWAV, "sounds/game-intro.ogg")
sound:playChannel(-1, 0)
while mixer.playing(-1) > 0 do
SDL.delay(100)
end
end
-- Game variables
local direction = ""
local holdKey = {}
local keyName = ""
local loaded = true
local playerPosition = math.random(0, 30)
local running = true
local weapon = 1
-- game functions.
local function player_move(position, direction)
if direction == "Left" and position > 0 then
position = position - 1
end
if direction == "Right" and position < 30 then
position = position + 1
end
return position
end
game_intro()
-- Main game loop.
while running do
-- Need a timer to make holding arrows move at a slower speed. for player_move()
playerPosition = player_move(playerPosition, direction)
-- Iterate over all events, this function does not block.
for e in SDL.pollEvent() do
if e.type == SDL.event.KeyUp then --chrys just recognice the keyup and free the loop
keyName = SDL.getKeyName(e.keysym.sym)
holdKey[keyName] = false
direction = ""
-- speak(playerPosition)
end
if e.type == SDL.event.Quit then
running = false
elseif e.type == SDL.event.KeyDown and not holdKey[keyName] then -- chrysif not already down ( see below)
keyName = SDL.getKeyName(e.keysym.sym)
holdKey[keyName] = true --chrys mark the remember the keydown
if keyName == "Q" then
running = exit_game(SDL, mixer)
elseif keyName == "Left Shift" or keyName == "Right Shift" then
if weapon >= 3 and loaded == false then
-- Need to not allow firing until loading is complete.
play_sound(load[weapon])
end
loaded = true
elseif keyName == "Space" then
if loaded == true then
play_sound(gun[weapon])
play_sound(bottle[math.random(1, #bottle)])
else
play_sound(empty)
end
if weapon >= 3 then
loaded = false
end
elseif keyName == "Left" or keyName == "Right" then
direction = keyName
elseif tonumber(keyName) == nil then -- make sure keyName can be converted to a number for remaing if statements to avoid a crash.
keyName = "0"
elseif tonumber(keyName) >= 1 and tonumber(keyName) <= 5 then
weapon = tonumber(keyName)
if weapon >= 3 then
loaded = false
else
loaded = true
end
if weapon == 1 then
speak("pistal")
elseif weapon == 2 then
speak("beretta")
elseif weapon == 3 then
speak("boomstick shotgun")
elseif weapon == 4 then
speak("pump action shotgun")
elseif weapon == 5 then
speak("bo and arrow")
end
end
end
end
end

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -21,6 +21,8 @@ done) --stdout)"
if [[ "$game" != "exit" && -n "$game" ]]; then
cd "${gameList[$game]}"
./$game""
echo
read -n1 -p "Press any key to continue" continue
else
break
fi

View File

@ -1,23 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
# Shoot the bottles as fast as possible.
from storm_games import *
sounds = initialize_gui("Bottle Blaster")
# loop forever (until a break occurs)
while True:
# wait for an event
event = pygame.event.wait()
# if the event is about a keyboard button that have been pressed...
if event.type == pygame.KEYDOWN:
sounds['bottle'].play(-1)
speak("This is a test.")
if event.type == pygame.KEYUP:
sounds['bottle'].stop()
# and if the button is the "q" letter or the "escape" key...
if event.key == pygame.K_ESCAPE:
# ... then exit from the while loop
break
time.sleep(.001)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,29 +0,0 @@
#!/bin/python
# -*- coding: utf-8 -*-
"""Standard initializations and functions shared by all games."""
from espeak import espeak
import os
from os import listdir
from os.path import isfile, join
import pygame
import time
def speak(text, interupt = True):
if interupt == True: espeak.cancel()
espeak.set_voice("en-us")
espeak.synth(text)
def initialize_gui(gameTitle):
# start pygame
pygame.init()
# start the display (required by the event loop)
pygame.display.set_mode((320, 200))
pygame.display.set_caption(gameTitle)
# Load sounds from the sound directory and creates a list like that {'bottle': 'bottle.ogg'}
soundFiles = [f for f in listdir("sounds/") if isfile(join("sounds/", f)) and (f.split('.')[1].lower() in ["ogg","wav"])]
#lets make a dict with pygame.mixer.Sound() objects {'bottle':<soundobject>}
soundData = {}
for f in soundFiles:
soundData[f.split('.')[0]] = pygame.mixer.Sound("sounds/" + f)
return soundData

View File

@ -1,19 +0,0 @@
#!/bin/bash
if [ $# -ne 1 ] ; then
echo "Usage: soundboard name, where name is the name of a soundboard you want to load."
exit 1
fi
if ! [ -d sounds/$1 ] ; then
echo "soundboard $1 not found."
exit 1
fi
while [ 1 -gt 0 ] ; do
read -sn1 key
if [ -f sounds/$1/$key.ogg ] ; then
play -qV0 sounds/$1/$key.ogg&
fi
done
exit 0

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -255,6 +255,9 @@ noteLength="0.75"
;;
"=")
noteLength="1.00"
;;
$'\e')
exit 0
esac
if [ "$instrument" == "12" ] ; then
play -qn -V0 synth pl ${note}$(($octave + 1)) pl ${note}${octave} delay 0 0.02 remix - $effect fade 0 $noteLength vol $volume &> /dev/null &

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,72 +0,0 @@
#!/bin/bash
check_dependancies()
{
if [ $# -eq 0 ] ; then
if [[ $(bash --version | head -n 1 | cut -f 1 -d "." | tr -d "[:alpha:]") < "4" ]] ; then
echo "This game requires bash version 4 or higher. Earlier versions may not be able to successfully run this code."
fi
if ! hash sox &> /dev/null ; then
echo "The program sox is required but does not appear to be installed on your system. Please install sox and try
again."
exit 1
fi
fi
for i in $@ ; do
if ! hash $i &> /dev/null ; then
echo "The program $i is required but does not appear to be installed on your system. Please install $i and try
again."
exit 1
fi
done
}
initialize_players()
{
i=1
while [ $i -le $1 ] ; do
player[$i]=0
let i++
done
}
play_sound()
{
play -qV0 sounds/$@
}
check_dependancies
check_dependancies rolldice
#get terminal width
columns=$(tput cols)
play_sound intro.ogg
#find out how many players there are
if [ $# -gt 1 ] ; then
echo "Usage: $0 or $0 number of players."
exit 1
fi
if [ $# -eq 1 ] ; then
if ! [[ "$1" =~ ^[0-9]+$ ]] ; then
echo "The number of players must be a number, 2 or greater."
exit 1
fi
if [ $1 -lt 2 ] ; then
echo "The number of players must be a number, 2 or greater."
exit 1
fi
totalPlayers=$1
else
totalPlayers=2
cpu=true
fi
initialize_players $totalPlayers
#determine who goes first.
playerIndex=$(rolldice 1d${#player[@]})
while [ $playerIndex -gt 0 ] ; do
score_keeper $playerIndex
let playerIndex++
if [ $playerIndex -gt ${#player[@]} ] ; then
playerIndex=1
fi
done
exit 0