diff --git a/game.coffee b/game.coffee index 96a45337d2..ab7157638a 100644 --- a/game.coffee +++ b/game.coffee @@ -40,6 +40,8 @@ class Rainbow @h %= 360 [r,g,b] = hsv2rgb @h, s, v +rainbow = new Rainbow + imgs = bullet: 'bullet.png' eyeGreen: 'eye_green.png' @@ -168,6 +170,20 @@ class Scene if @fade_cb? do @fade_cb + if @text? + @text_time += dt + if @text_time > @text_dur + @text = null + + @text_y += @text_speed * dt + + if @text_time < @text_fade_dur + @text_fade = @text_time/@text_fade_dur + else if @text_time > @text_dur - @text_fade_dur + @text_fade = 1 - (@text_time-@text_dur+@text_fade_dur)/@text_fade_dur + else + @text_fade = 1 + this draw: (ctx) -> @@ -182,6 +198,15 @@ class Scene e.draw ctx for e in @enemies b.draw ctx for b in @bullets + if @text? + [r,g,b] = @text_color + ctx.font = '16px "Apple Chancery", Mistral' + ctx.fillStyle = "rgba(#{r},#{g},#{b},#{@text_fade})" + i = 1 + for t in @text + atom.context.fillText t, @text_x, 20 * i + @text_y + i++ + ctx.fillStyle = "rgba(255,255,255,#{@fade})" ctx.fillRect 0, 0, atom.width, atom.height @@ -202,9 +227,19 @@ class Scene undefined - showShip: (x = atom.width * .5, y = atom.height * .7) -> + shipShow: (x = atom.width * .5, y = atom.height * .7) -> @ship = new Ship x, y + textShow: (text, dur = 6, fade = 3, speed = 60) -> + @text = text + @text_time = 0 + @text_dur = dur + @text_fade_dur = fade + @text_x = randInRange 10, 250 + @text_y = 0 + @text_speed = speed + @text_color = do rainbow.next + fadeOut: (duration, callback) -> @fade = 0 @fade_speed = 1 / duration @@ -675,7 +710,6 @@ class BackgroundTitle @orbs = [] @orb_rate = .5 @orb_countdown = 0 - @orb_color = new Rainbow @g = -100 @tm_countdown = 0 @@ -693,7 +727,7 @@ class BackgroundTitle @orb_countdown -= dt if @orb_countdown <= 0 @orb_countdown = @orb_rate - [r,g,b] = @orb_color.next() + [r,g,b] = rainbow.next() rand = randInRange -60, 60 orb = x: atom.width/2 + 30 + rand @@ -888,6 +922,11 @@ class Game extends atom.Game if @playing[sound]? @playing[sound].noteOff 0 +text = + enemy: ['Your worst enemy cannot','harm you as much as your','own unguarded thoughts.'] + peace: ['Peace comes from within.', 'Do not seek it without.'] + able: ['He is able who','thinks he is able.'] + credits = [ {do: (s) -> s.fadeIn 2}, {do: (s) -> s.background = new BackgroundCredits 'green'}, @@ -902,9 +941,10 @@ level1 = [ {do: (s) -> s.fadeIn 5}, {do: (s) -> game.musicPlay 'level1'}, {do: (s) -> s.background = new BackgroundStars}, - {do: (s) -> do s.showShip}, + {do: (s) -> do s.shipShow}, {repeat: 7, wait: .5, do: (s) -> s.spawnEnemy 10, 10, (enemy.basic 50)}, {repeat: 7, wait: .5, do: (s) -> s.spawnEnemy 390, 10, (enemy.basic -50)}, + {do: (s) -> s.textShow text.enemy}, {wait: 1}, {wait: 1, from: 100, to: 300, step: 100, do: (s, x) -> s.spawnEnemy x, 10, enemy.circle 8}, {wait: 2}, @@ -921,6 +961,8 @@ level1 = [ {wait: 3}, {from: 200, to: 100, step: -20, wait: .75, do: (s, x) -> s.spawnEnemy x, 10, (enemy.fan 50)}, {from: 200, to: 300, step: 20, wait: .75, do: (s, x) -> s.spawnEnemy x, 10, (enemy.fan -50)}, + {wait: 2}, + {do: (s) -> s.textShow text.enemy}, {wait: 3}, {do: (s) -> s.spawnEnemy 10, 10, enemy.direct 50, 200, -75}, {wait: 1}, @@ -947,6 +989,7 @@ level1 = [ {wait: .5}, {from: 200, to: 100, step: -20, wait: .75, do: (s, x) -> s.spawnEnemy x, 10, (enemy.fan 50)}, {waitUntil: (s) -> s.enemies.length <= 0}, + {do: (s) -> s.textShow text.able}, {wait: 5}, {do: (s) -> s.spawnEnemy atom.width/2, 150, enemy.buddha1()}, {waitUntil: (s) -> s.enemies.length <= 0},