-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.coffee
651 lines (595 loc) · 19.1 KB
/
client.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
###
Copyright (c) 2011-2012 Emanuel Rylke
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
###
initStubs = []
runStubs = (stubs) ->
if stubs.length > 0
stubs.shift()()
setTimeout (-> runStubs stubs), 1
#maybe i should have a better solution for when stubs are added after all are processed
else
setTimeout (-> runStubs stubs), 300
FAST_PLAY = window.location.hash == '#fast'
NUM_ALTAR_PIECES = if FAST_PLAY then 1 else 7
AXE_PRICE = if FAST_PLAY then 3 else 12
arrows = []
bunnies = new parray 5000, 500
deathbunnies = []
flowers = new parray 5000, 500
trees = new stparray 5000
zombies = new parray 5000, 500
altarPieces = []
altarPiecesCount = 0
altarInInventar = false
altar = {hp: 1000, maxhp: 1000}
hasAxe = false
patches = new stparray 5000
@patches = patches
randpos = ->
loop
p = [5000 * Math.random(), 5000 * Math.random()]
foo = false
patches.eachin p, [0, 0], (patch) ->
if (distance patch.p, p) < patch.r
foo = true
if foo
return p
hunter = null
knuth = null
dogpos = null
doggoal = null
doghasbunny = false
dogrun = false
dogpath = []
dogspeed = 0
deathbunnycount = 0
logs = 0
mp = [0, 0]
mousePressed = false
frameInterval = null
getTime = -> (new Date()).getTime()
frameTimer = 0
nigth = null
lastZombieWave = getTime()
lastZombieWaveOffset = 0
zombieWaveSize = 1
shooting = false
pause = false
drawPs = []
brownbunny = loadImg 'brownbunny.png'
deathbrownbunny = loadImg 'deathbrownbunny.png'
dog = loadImg 'dog.png'
flower = loadImg 'flower.png'
hunterImg = loadImg 'hunter.png'
zombie = loadImg 'zombie.png'
#control flow of doom !
#also needs to be optimized
initStubs.push ->
while patches.length() < (if FAST_PLAY then 10 else 50)
flpatch = {r: 40 + Math.random() * 400, n: []}
flpatch.p = [flpatch.r + Math.random() * ((if FAST_PLAY then 1000 else 5000) - flpatch.r * 2), "foo"]
flpatch.p[1] = 0 - flpatch.r
loop
if flpatch.p[0] - flpatch.r < 0 || flpatch.p[0] + flpatch.r > 5000 || flpatch.p[1] + flpatch.r > 5000
flpatch.p[1] = Math.min 5000 - flpatch.r, flpatch.p[1]
patches.add flpatch
break
obst = false
foo = false
mindist = 50
patches.eachin (minus flpatch.p, [flpatch.r, flpatch.r]), [flpatch.r * 2, flpatch.r * 2 + 50], (i) ->
mindist = Math.min mindist, (distance i.p, flpatch.p) + 2 - i.r - flpatch.r
if (distance i.p, flpatch.p) + 2 < i.r + flpatch.r
if obst && not foo
patches.add flpatch
foo = true
else
obst = i
if foo
break
if obst
flpatch.p[1] += 0.1
if obst.p[0] < flpatch.p[0]
flpatch.p[0]++
else
flpatch.p[0]--
else
flpatch.p[1] += Math.max 1, mindist
null
initStubs.push ->
patches.each (patch) ->
patches.eachinradius patch.p, patch.r, (other) ->
if patch != other
patch.n.push other
initStubs.push ->
patches.each ({r, p}) ->
for i in [0...Math.pow(Math.random() * 2, 3) | 0]
tp = plus p, mult (sincos (Math.random() * tau)), (r + 10)
if not getPatch tp
trees.add {p: tp, r: Math.random() * 100 + 40}
runGame = ->
frameInterval = setInterval (->
try
step()
catch err
clearInterval frameInterval
throw err
), 40
initStubs.push ->
{p, r} = patches.biggestinradius [(if FAST_PLAY then 1000 else 4000), 4000], 2000, (x) -> -1 * (distance [4000, 4000], x.p)
hunter = new Shooter p
dogpos = plus p, [r / 2, 0]
doggoal = hunter.p
{p} = patches.biggestinradius [1000, 4000], 2000, (x) -> x.r / (1500 + (distance x.p, [1000, 4000]))
knuth = new Shooter p
runGame()
initStubs.push ->
altarPieces = (randpos() for i in [0...NUM_ALTAR_PIECES])
rand255 = ->
Math.floor(255 * Math.random())
mapcanvas = ($ '<canvas width="1000" height="1000">')[0]
mapctx = mapcanvas.getContext '2d'
mapctx.scale 0.2, 0.2
mapctx.lineWidth = 10
mapctx.strokeStyle = 'rgba(0, 0, 0, 0.1)'
mapctx.fillStyle = 'rgba(0, 0, 0, 0.1)'
drawOnMap = (patch) ->
if not patch.drawn
{r, p, n} = patch
for other in n
fillRect mapctx, (minus (intersect patch, other), [10, 10]), [20, 20]
mapctx.beginPath()
arc mapctx, p, r, 0, tau + 0.001
mapctx.stroke()
patch.drawn = true
initStubs.push ->
drawOnMap (getPatch hunter.p)
rockbg1 = loadImg 'rock-bg1.png'
rockbg2 = loadImg 'rock-bg2.png'
meadowbg1 = loadImg 'bg.png'
meadowbg2 = loadImg 'bg2.png'
bgTiles = {}
getBgTile = (p) ->
if bgTiles[p]
bgTiles[p]
else
cacheTile = true
can = ($ '<canvas width="1000" height="1000">')[0]
pctx = can.getContext '2d'
pctx.fillStyle = '#44aa00'
translate pctx, minus [0, 0], p
patches.eachin p, [1000, 1000], ({r, p}) ->
pctx.beginPath()
arc pctx, p, r, 0, tau + 0.001
pctx.fill()
pctx.globalCompositeOperation = 'source-atop'
for img in [meadowbg1, meadowbg2]
if img.complete
foo = [img.width, img.height]
eachinarearange (floorBy2d p, foo), (plus p, [1000, 1000]), foo, (pb) ->
drawImage pctx, img, pb
else
cacheTile = false
# patches.eachin p, [1000, 1000], ({r, p}) ->
#pctx.fillStyle = 'rgba(' + rand255() + ', '+ rand255() + ', ' + rand255() + ', 0.1)'
#pctx.beginPath()
#arc pctx, p, r, 0, tau + 0.001
#pctx.fill()
rockcan = ($ '<canvas width="1000" height="1000">')[0]
rctx = rockcan.getContext '2d'
translate rctx, minus [0, 0], p
for img in [rockbg1, rockbg2]
if img.complete
foo = [img.width, img.height]
eachinarearange (floorBy2d p, foo), (plus p, [1000, 1000]), foo, (pb) ->
drawImage rctx, img, pb
else
cacheTile = false
drawImage rctx, can, p
if cacheTile
bgTiles[p] = rockcan
rockcan
drawHPBar = (ctx, p, hp, maxhp) ->
size = Math.pow(maxhp, 0.5) * 4
ctx.fillStyle = '#aa2255'
fillRect ctx, (minus p, [size / 2, 25]), [size, 3]
ctx.fillStyle = '#00dd00'
fillRect ctx, (minus p, [size / 2, 25]), [size* hp / maxhp, 3]
drawEntity = (ctx, img, {p, hp, maxhp}) ->
if img
drawImage ctx, img, (minus p, [20, 20])
else
fillRect ctx, (minus p, [20, 20]), [40, 40]
if maxhp
drawHPBar ctx, p, hp, maxhp
draw = ->
ctx.font = '40px sans-serif'
ctx.textBaseline = 'middle'
ctx.save()
translate ctx, minus [500, 250], hunter.p
eachinarearange (floorBy2d (minus hunter.p, [500, 250]), [1000, 1000]), (plus hunter.p, [500, 250]), [1000, 1000], (pb) ->
drawImage ctx, getBgTile(pb), pb
ctx.fillStyle = '#bbaaaa'
ctx.strokeStyle = '#000000'
for p in altarPieces
fillRect ctx, (minus p, [20, 20]), [40, 40]
for db in deathbunnies
drawEntity ctx, deathbrownbunny, db
flowers.eachin (minus hunter.p, [500, 250]), [1000, 500], ({p}) ->
drawImage ctx, flower, (minus p, [10, 10])
bunnies.eachin (minus hunter.p, [500, 250]), [1000, 500], ({p}) ->
drawImage ctx, brownbunny, (minus p, [20, 20])
drawImage ctx, dog, (minus dogpos, [20, 20])
if doghasbunny
drawImage ctx, deathbrownbunny, (minus dogpos, [10, 10])
fillRect ctx, (minus knuth.p, [20, 20]), [40, 40]
if altar.p
drawEntity ctx, null, altar
drawImage ctx, hunterImg, (minus hunter.p, [20, 20])
ctx.fillStyle = '#ffffff'
ctx.fillText "Knuth", knuth.p[0] - 40, knuth.p[1] - 40
ctx.strokeText "Knuth", knuth.p[0] - 40, knuth.p[1] - 40
zombies.eachin (minus hunter.p, [500, 250]), [1000, 500], (z) ->
drawEntity ctx, zombie, z
for {p, m} in arrows
ctx.beginPath()
moveTo ctx, p
lineTo ctx, plus p, m
ctx.closePath()
ctx.stroke()
ctx.fillStyle = 'rgba(32, 110, 10, 0.8)'
ctx.strokeStyle = 'rgb(64, 220, 10)'
trees.eachin (minus hunter.p, [500, 250]), [1000, 500], ({p, r, hp, maxhp}) ->
ctx.beginPath()
arc ctx, p, r, 0, tau + 0.001
ctx.fill()
if hasAxe and (distance p, mousep()) < r
ctx.stroke()
if maxhp
ctx.save()
drawHPBar ctx, p, hp, maxhp
ctx.restore()
for p in drawPs
fillRect ctx, p, [10, 10]
drawPs = []
ctx.restore()
ctx.save()
translate ctx, minus [500, 250], (mult hunter.p, 0.2)
drawImage ctx, mapcanvas, [0, 0]
ctx.scale 0.2, 0.2
ctx.fillStyle = 'rgba(255,255,255, 0.4)'
for p in altarPieces
if (getPatch p).drawn
fillRect ctx, (minus p, [10, 10]), [20, 20]
ctx.restore()
ctx.fillStyle = "rgba(0, 0, 0, #{nigth})"
fillRect ctx, [0, 0], [1000, 500]
#reverse hitp checking
hitp = (bunny) ->
for a in arrows
if contains a.p, (minus bunny.p, [20, 20]), (plus bunny.p, [20, 20])
a.p = [-100, -100]
return true
false
intersect = (patch1, patch2) ->
plus patch1.p, (mult (direction patch1.p, patch2.p), patch1.r)
getPatch = (p) ->
res = false
patches.eachin p, [0, 0], (patch) ->
if (distance p, patch.p) < patch.r
res = patch
return res
#I wish you luck understanding this function and i'm sorry that i didn't document it
pathing = (p1, p2) ->
p1patch = getPatch p1
p2patch = getPatch p2
if not p2patch
return [p1]
else if p2patch == p1patch || not p1patch
return [p2]
else
open = [{heurD: (distance p1, p2), measD: 0, p: [p2patch]}]
closed = []
loop
open.sort (a, b) ->
(a.heurD + a.measD) - (b.heurD + b.measD)
if open.length == 0
return [p1]
pth = open.shift()
closed.push pth.p[0]
for n in pth.p[0].n
if n == p1patch
return [(intlvmap [n, pth.p...], intersect)..., p2]
bar = one closed, (x) ->
x == n
if not bar
newpath =
heurD: (distance p1, (intersect pth.p[0], n))
measD: (pth.measD + (distance (intersect pth.p[0], n), (if pth.p.length > 1 then (intersect pth.p[0], pth.p[1]) else p2)))
p: [n, pth.p...]
bla = true
for j in [0...(open.length)]
if open[j].p[0] == n
if open[j].heurD + open[j].measD > newpath.heurD + newpath.measD
open[j] = newpath
bla = false
break
if bla
open.push newpath
throw "the controlflow should never go here"
walk = (start, goal, speed) ->
path = pathing start, goal
plus start, mult (direction start, path[0]), speed
class Shooter
constructor: (@p) ->
@target = null
@lastShoot = 0
behave: ->
if @target && frameTimer - 4 > @lastShoot
arrows.push {h: 30, p: @p, m: mult (direction @p, @target), 20}
@lastShoot = frameTimer
drawInventar = ->
res = ''
if hasAxe
res += '<br>Axe: 1'
if deathbunnycount > 0
res += '<br>Bunnies: ' + deathbunnycount
if logs > 0
res += '<br>Logs: ' + logs
if altarPiecesCount > 0
res += '<br>Altar Pieces: ' + altarPiecesCount
if altarPiecesCount == NUM_ALTAR_PIECES
res +='<br><a onclick="javascript:repairAltar()" href="javascript:void(0)">repair altar</a>'
if altarInInventar
res += '<br>Altar: 1<br><a onclick="javascript:placeAltar()" href="javascript:void(0)">place altar</a>'
if res
res = 'Inventar:' + res
if (distance hunter.p, knuth.p) < 200 and deathbunnycount >= AXE_PRICE and not hasAxe
res = '<a onclick="javascript:buyAxe()" href="javascript:void(0)">buy axe for ' + AXE_PRICE + ' bunnies</a><br>' + res
foo = $('#inventar')[0]
if foo.innerHTML != res
foo.innerHTML = res
collectAltarPiece = ->
altarPiecesCount++
@repairAltar = ->
altarPiecesCount = 0
altarInInventar = true
false
@placeAltar = ->
altar.p = hunter.p
altarInInventar = false
false
@buyAxe = ->
hasAxe = true
deathbunnycount -= AXE_PRICE
false
mousep = ->
(plus mp, (minus hunter.p, [500, 250]))
step = ->
for patch in (getPatch hunter.p).n
drawOnMap patch
frameTimer++
nigth = (((Math.sin frameTimer / (25 * 60)) + 1) / 4)
if mousePressed
hunter.goal = mousep()
if hunter.goal
hunter.p = walk hunter.p, hunter.goal, 6
if (distance hunter.p, hunter.goal) < 6
hunter.goal = null
bunnies.add {p: randpos(), alarmed: false, life: 100} if bunnies.length() < 5
flowers.add {p: randpos(), death: false} if ptrue 0.5
if getTime() - 60 * 1000 > lastZombieWave
for i in [0...zombieWaveSize]
hp = 5 + Math.random() * 10 | 0
zombies.add {p: randpos(), sleep: 100, hp: hp, maxhp: hp, subgoal: [0, 0], subgoalcounter: 0}
zombieWaveSize++
lastZombieWave = getTime()
if hunter.target
hunter.target = mousep()
hunter.behave()
knuth.target = null
foo = 1
zombies.eachinradius knuth.p, 400, (zombie) ->
if Math.random() < 1/foo
knuth.target = zombie.p
foo++
knuth.behave()
altarPieces = altarPieces.filter (a) ->
if distance(a, hunter.p) < 40
collectAltarPiece()
false
else
true
newarrows = []
for a in arrows
goal = plus a.p, a.m
bar = false
patches.eachin goal, [0, 0], (patch) ->
if (distance patch.p, goal) < patch.r - 1
bar = true
if bar
a.p = goal
foo = true
zombies.eachinradius a.p, 20, (zombie) ->
if foo
zombie.hp--
foo = false
if a.h > 1 && foo && bar
a.h -= 1
newarrows.push a
arrows = newarrows
newbunnies = new parray 5000, 500
bunnies.each (bunny) ->
bunnygoal = bunny.p
bunnyspeed = 0
if (hitp bunny)
deathbunnies.push bunny
return
if bunny.life < 1
return
bunny.life--
dist = distance hunter.p, bunny.p
if dist < 150
bunnies.eachinradius bunny.p, 150, (otherbunny) ->
otherbunny.alarmed = true
if bunny.alarmed
bunny.alarmed = dist < 600
bunnyspeed = 10
d = 0
patch = getPatch bunny.p
for other in patch.n
inter = intersect patch, other
newd = (distance inter, bunny.p)
hd = (distance inter, hunter.p)
if newd < hd and d < hd
d = hd
bunnygoal = other.p
else
if bunny.life > 1000
bunny.life -= 200
bunny.life /= 2
newbunnies.add {
p: (plus bunny.p, [0, 0]),
alarmed: false,
life: bunny.life}
f = {p: [99999,99999]}
flowers.eachin (minus bunny.p, [500, 500]), [1000, 1000], (f2) ->
if (distance f.p, bunny.p) > (distance f2.p, bunny.p)
if (distance f2.p, bunny.p) > (distance f2.p, hunter.p)
other = true
else
other = false
bunnies.eachin (minus bunny.p, [50, 50]), [100, 100], (otherbunny) ->
if (bunny != otherbunny) && (distance f2.p, bunny.p) > (distance f2.p, otherbunny.p)
other = true
if not other
f = f2
if f.p[0] != 99999
bunnyspeed = 8
bunnygoal = f.p
if (distance f.p, bunny.p) < 20
bunny.life += 50
flowers.del f
bunny.p = walk bunny.p, bunnygoal, bunnyspeed
newbunnies.add bunny
bunnies = newbunnies
doggoal = dogpos
if doghasbunny
if (distance dogpos, hunter.p) < 50
deathbunnycount++
doghasbunny = false
else
dogspeed = 10
doggoal = hunter.p
else
db = {p: [99999, 99999]}
for db2 in deathbunnies
dist = distance db2.p, dogpos
if dist < 500 && dist < (distance dogpos, db.p)
db = db2
if db.p[0] != 99999
dogspeed = 10
doggoal = db.p
else if dogrun
if (distance dogpos, hunter.p) > 90
dogspeed = 7
doggoal = hunter.p
else
dogrun = false
else if (distance dogpos, hunter.p) > 250
dogrun = true
dogpos = walk dogpos, doggoal, dogspeed
newzombies = new parray 5000, 500
zombies.each (zombie) ->
if (not FAST_PLAY) and nigth < 0.25
zombie.hp -= 0.1
if zombie.sleep < 1
if zombie.subgoalcounter < 1 || (distance zombie.subgoal, zombie.p) < zombie.hp / 2 || (distance zombie.p, hunter.p) < 400
zombie.subgoal = (pathing zombie.p, altar.p or hunter.p)[0]
zombie.subgoalcounter = 200
zombie.subgoalcounter--
zombie.p = plus zombie.p, (mult (direction zombie.p, zombie.subgoal), zombie.hp / 2)
zombies.eachinradius zombie.p, 40, (other) ->
if other != zombie
if other.sleep < 5
other.sleep += 10
if 0 < zombie.maxhp - zombie.hp < other.maxhp - other.hp
other.hp--
zombie.hp++
if (distance hunter.p, zombie.p) < 10
pr "You die! but you got #{deathbunnycount} bunnies!"
clearInterval frameInterval
else
zombie.sleep--
if zombie.hp> 0
newzombies.add zombie
zombies = newzombies
if altar.p
altar.hp = Math.min(altar.maxhp, altar.hp + 0.005)
zombies.eachinradius altar.p, 40, (z) ->
altar.hp -= 0.01
if altar.hp <= 0
altar.p = undefined
newdeathbunnies = []
for db in deathbunnies
if (distance db.p, hunter.p) < 50
deathbunnycount++
else if (not doghasbunny) && (distance db.p, dogpos) < 50
doghasbunny = true
else
newdeathbunnies.push db
deathbunnies = newdeathbunnies
trees.eachinradius hunter.p, 200, (tree) ->
if tree.maxhp
tree.hp--
if tree.hp is 0
trees.del tree
logs++
draw()
drawInventar()
($ document).keydown (evt) ->
switch String.fromCharCode(evt.which)
when ' '
if hunter.target
hunter.target = null
else
cnvs = $ 'canvas'
mp = minus [evt.pageX, evt.pageY], [cnvs.offset().left, cnvs.offset().top]
hunter.target = (plus mp, (minus hunter.p, [500, 250]))
when 'P'
if pause
pause = false
lastZombieWave = getTime() - lastZombieWaveOffset
runGame()
else
pause = true
clearInterval frameInterval
lastZombieWaveOffset = getTime() - lastZombieWave
ctx.fillStyle = 'rgba(128,128,128,0.3)'
fillRect ctx, [0, 0], [1000, 500]
ctx.fillStyle = '#000000'
ctx.fillText "Press P to continue playing.", 200, 250
else
return
evt.preventDefault()
$ ->
runStubs initStubs
cnvs = $ 'canvas'
($ 'canvas').mousemove (evt) ->
mp = minus [evt.pageX, evt.pageY], [cnvs.offset().left, cnvs.offset().top]
evt.preventDefault()
($ 'canvas').mousedown (evt) ->
mousePressed = true
mp = minus [evt.pageX, evt.pageY], [cnvs.offset().left, cnvs.offset().top]
hunter.goal = mousep()
true
($ 'canvas').mouseup ->
mousePressed = false
if hasAxe
trees.eachinradius mousep(), 0, (tree) ->
tree.maxhp = 100
tree.hp = 100
true