diff options
Diffstat (limited to 'game.html.coffee')
| -rw-r--r-- | game.html.coffee | 95 |
1 files changed, 78 insertions, 17 deletions
diff --git a/game.html.coffee b/game.html.coffee index 8f3e453..2ffe016 100644 --- a/game.html.coffee +++ b/game.html.coffee @@ -4,7 +4,7 @@ # This program is available under the terms of the MIT License -version = "0.2.347" +version = "0.2.398" { htmlcup } = require 'htmlcup' @@ -170,6 +170,8 @@ genPage = -> draw: -> @py-- super() + oxygen: 10 + score: 5 bumpedInto: (o, qd, dx, dy)@> return if @dead # if dx * dx * 2 > qd @@ -321,18 +323,32 @@ genPage = -> goodnight: (game)@> game.quitSlowBubbles() bumpedInto: (o)@> o.dead = true + oxygenation: oxygenation = + create: @> oxygen: 0.7; __proto__: @ + addFrom: (o)@> + (o = o.oxygen)? then + { oxygen } = @ + oxygen += o * 0.001 + if oxygen > 1.0 + oxygen = 1.0 + @oxygen = oxygen + consume: @> + @oxygen *= 0.99999 Vaquita: Vaquita = class extends Sprite twist: [ pixyvaquita_twist_l, pixyvaquita_twist_r ] constructor: -> @lr = 16 @tb = 16 + @oxygen = oxygenation.create() super() draw: -> + @oxygen.consume() if @vx < 0 @lr = - 18 else if @vx > 0 @lr = 18 super() + bumpedInto: (x)@> @oxygen.addFrom(x) AiVaquita: AiVaquita = class extends Vaquita constructor: -> @image = pixyvaquita @@ -366,6 +382,7 @@ genPage = -> @fpy = @py ? 0 @touch = @game.touchInput @auto_to = 40 + @score = 0 beat_lr: 0 move: -> { touch } = @ @@ -436,6 +453,10 @@ genPage = -> else if vx * vx + (vy * vy / 4) > 1 @image = @twist[@beat_lr++ & 1] super() + bumpedInto: (x)@> + @oxygen.addFrom(x) + { score } = x + @score += score if score? addVaquita: -> # n = v.cloneNode() # n.setAttribute "opacity", "0.5" @@ -874,7 +895,7 @@ genPage = -> narrator: do-> first: null last: null - add: (t)@> + say: (t)@> { last, game } = @ game.other.narrator = @ unless game.other.narrator? first = null @@ -898,23 +919,28 @@ genPage = -> ex = radx dy = rady - rady / 3 last = null + { random } = @Math while first? # x = first.x unless (x = first.x)? - if x > radx2 - break - else - first.x = radx2 + unless px > radx2 - 10 + first.x = radx2 break p = charMap[first.c] - x-- + isLast = x < radx2 + x -= radx + # x -= 1 + (atan((x * x / 100) / 50) | 0) + x -= 1 + ((x * x) >> 10) + x += radx x = px if x < px first.x = x ly = last?.y y = first.y ?= ly ? dy - y += ((@Math.random()*3)|0) - 1 + rr = random() + y += ((rr*(3/0.33))|0) - 1 if rr < 0.33 ly? then - dd = 1 + (x - px) + dd = 1 + x - px + # y = ly + dd y = (y > ly + dd then ly + dd else y < ly - dd then ly - dd else y) first.y = y { o, w } = p @@ -924,9 +950,23 @@ genPage = -> px = x + w + 1 last = first first = first.next - @first = first if x <= -w + @first = first if x <= -w __proto__: textRenderer - + scoreBox: + textRenderer: textRenderer + score: 0 + draw: @> + { game, textRenderer } = @ + textRenderer.drawText "Score: #{game.vilma.score}", 0, 10 + textRenderer.drawText "Time: #{game.getPlayTimeText(2)}", 0, 20 + textRenderer.drawText "Oxygen: #{game.vilma.oxygen.oxygen * 100 + 0.1 | 0}", 0, 30 + textRenderer.drawText "Depth: #{(game.getDepth() * 100).toFixed(1)} m", 0, 40 + show: @> + { game } = @ + game.other.scoreBox = @ + hide: @> + { game } = @ + delete game.other.scoreBox waves: intro: @> @@ -983,7 +1023,9 @@ genPage = -> # # t.restore() # logzoom: 0 seafloor: seafloorPlane = __proto__: SeaFloor - getDepth: @> @seafloor.fy / @seafloor.mfy + getDepth: @> + r = @seafloor.fy / @seafloor.mfy + r < 0 then 0 else r waterscape: waterscape = do-> __proto__: WaterPlane # color: "cyan" @@ -1090,16 +1132,24 @@ genPage = -> time.setFutureChain([ do-> after: 0 - run: @> @narrator.add "Vilma, " + run: @> @narrator.say "Vilma, " do-> after: 4 - run: @> @narrator.add "the Happy Vaquita,\n" + run: @> @narrator.say "the Happy Vaquita, \n" do-> after: 4 - run: @> @narrator.add "presents\n" + run: @> @narrator.say "presents... \n" do-> after: 4 - run: @> @narrator.add "The Moon is Sinking" + run: @> @narrator.say "The Moon is sinking" + do-> + after: 4 + run: @> + @time.playTime = 0 + @vilma.score = 0 + @scoreBox.game = @ + @scoreBox.show() + ]) @collisions.setup(radx, rady) @@ -1144,12 +1194,24 @@ genPage = -> clear: @> @b = new @Array(@b.length) # Discrete board for detecting collisions @l = [ ] # List of collisions targets + getPlayTimeText: (dec)@> + { playTime } = @time + s = playTime % 60 + playTime = (playTime / 60) | 0 + m = playTime % 60 + playTime = (playTime / 60) | 0 + m = m.toString().replace(/^[0-9]$/, ((x)-> "0" + x)) + s = s.toFixed(dec).replace(/^[0-9][.]/, ((x)-> "0" + x)) + "#{playTime}:#{m}:#{s}".replace(/:([0-9][:.])/g, ((x, y)-> ":0" + y)) time: + playTime: 0 current: 0 advance: @> { current, game, tickTime } = @ + @playTime += tickTime (current += tickTime) > 1 then current -= 1 + @total++ (future = @future)? then future.after > 0 then future.after-- else @future = future.next @@ -1240,7 +1302,6 @@ genPage = -> if (@gameloop.ticks & 0xff) is 0xff fps.innerHTML = "#{@gameloop.fps} fps" - jaws: jaws window: window spaceKey: spaceKey |
