S = 20
TS = 24
M = 30
E = 40
NUM_HISCORES = 5
PLAYER_SPEED_CONCRETE = 10
PLAYER_SPEED_GRASS = 5
LEVELS = [
{
goats: 0
hippies: 1
goatSpeed: 10
hippieSpeed: 14
goatRandomInterval: 30
hippieRandomInterval: 10
},
{
goats: 1
hippies: 1
goatSpeed: 10
hippieSpeed: 14
goatRandomInterval: 20
hippieRandomInterval: 10
},
{
goats: 1
hippies: 2
goatSpeed: 10
hippieSpeed: 14
goatRandomInterval: 15
hippieRandomInterval: 10
},
{
goats: 2
hippies: 2
goatSpeed: 10
hippieSpeed: 14
goatRandomInterval: 15
hippieRandomInterval: 10
},
]
TIPS = [
'Tip: Fill large areas at once for more points!',
'Tip: Keep in mind that you walk slower on grass!',
'Tip: Fill 80% or eliminate all pests to win!',
'Tip: Pests still alive at the end don\'t score you any points!',
'Tip: Keep food out of reach of goats. They are bold and eat anything!',
]
window.requestAnimationFrame =
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
(callback, element) -> window.setTimeout(callback, 1000/60)
window.localStorage = window.localStorage || {}
levelIndex = null
maxLevel = null
level = null
game = null
hiscores = null
paused = false
music = null
images =
entities: null
tiles: null
background: null
carpark: null
concrete: 'src/concrete.png'
sounds =
win: 0.5
lose: 0.7
hippie_bounce: 0.2
hippie_die: 0.5
goat_bounce: 0.4
goat_die: 1.0
pour: 1.0
tape: 0.2
loadAssets = (onDone) ->
remaining = 0
for key, value of images
remaining++
im = new Image()
im.src = if value then value else "#{key}.png"
im.onload = ->
remaining--
if remaining == 0
onDone()
images[key] = im
for key, value of sounds
sounds[key] = new Sound(key, value)
return
GRASS = 0
TAPE = 1
CONCRETE = 2
LEFT = 4
RIGHT = 5
class Sound
constructor: (id, volume) ->
@volume = volume || 1
@audio = null
$.ajax(
url: id + ".wav.base64"
dataType: "text"
success: (data) =>
@src = "data:audio/wav;base64," + data
@createAudio()
error: (jqXHR, textStatus, errorThrown) ->
console.error("Failed to load " + jqXHR.url + ": " + textStatus + " " + errorThrown)
)
createAudio: ->
@audio = new Audio(@src)
@audio.preload = "auto"
@audio.volume = @volume
play: ->
return unless @audio
return unless Sound.enabled
@audio.play()
@createAudio()
Sound.enabled = true
class Music
constructor: (sources, volume, length) ->
@musics = []
for i in [0, 1]
music = $("")
for source in sources
$("