Permalink
Browse files

Sweet title screen

  • Loading branch information...
1 parent 3be5480 commit e1dd4c297177f513addf26a43807f172b47a9ae8 Daniel Mark Schwartz committed Nov 25, 2012
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1,6 +1,21 @@
randInRange = (l, h) ->
l + Math.random() * (h - l)
+hsv2rgb = (h, s, v) ->
+ c = v * s
+ h_p = h / 60.0
+ x = c * (1 - Math.abs(h_p%2 - 1))
+
+ [r,g,b] = [c,x,0] if 0 <= h_p < 1
+ [r,g,b] = [x,c,0] if 1 <= h_p < 2
+ [r,g,b] = [0,c,x] if 2 <= h_p < 3
+ [r,g,b] = [0,x,c] if 3 <= h_p < 4
+ [r,g,b] = [x,0,c] if 4 <= h_p < 5
+ [r,g,b] = [c,0,x] if 5 <= h_p < 6
+
+ m = v - c
+ [r,g,b].map (x) -> Math.round(255*(x+m))
+
bulletImage = new Image
bulletImage.src = 'bullet.png'
@@ -16,6 +31,27 @@ shipImage2.src = 'monk_2.png'
enemyImage = new Image
enemyImage.src = 'enemy.gif'
+#Photo credit: Christopher Chan / Foter / CC BY-NC-ND
+monkImage = new Image
+monkImage.src =
+
+imgs =
+ title_monk: 'title_monk.png'
+ tm_light: 'tm_light.png'
+ tm_dark: 'tm_dark.png'
+ enlightenment: 'enlightenment.png'
+ enlightenment_blur: 'enlightenment_blur.png'
+
+preloadImages = (imgs) ->
+ atom.images = {}
+ for name, url of imgs
+ img = new Image
+ img.src = url
+ atom.images[name] = img
+
+preloadImages imgs
+
+
sounds =
intro: 'DST-ClubNight.mp3'
@@ -352,6 +388,86 @@ class BackgroundFlat
ctx.fillStyle = @color
ctx.fillRect 0, 0, atom.width, atom.height
+class BackgroundTitle
+ constructor: () ->
+ @orbs = []
+ @orb_rate = .5
+ @orb_countdown = 0
+ @h = randInRange 0, 359
+ @g = -100
+
+ @tm_countdown = 0
+ @tm_light = true
+
+ @en_alpha = 0
+ @en_da = .8
+
+ update: (dt) ->
+ @orb_countdown -= dt
+ if @orb_countdown <= 0
+ @orb_countdown = @orb_rate
+ @h += 222.49
+ @h %= 360
+ [r,g,b] = hsv2rgb @h, .8, .8
+ rand = randInRange -60, 60
+ orb =
+ x: atom.width/2 + 30 + rand
+ y: atom.height - 150
+ dx: rand * 1.5
+ dy: randInRange(-70, -120)
+ color: "rgba(#{r}, #{g}, #{b}, .8)"
+
+ @orbs.push orb
+
+ for orb in @orbs
+ orb.dy += dt * @g
+ orb.y += orb.dy * dt
+ orb.x += orb.dx * dt
+
+ @orbs = @orbs.filter ((o) -> o.y > 0)
+
+ @tm_countdown -= dt
+ if @tm_countdown <= 0
+ @tm_countdown = randInRange .01, .2
+ @tm_light = not @tm_light
+
+ @en_alpha += dt * @en_da
+ if @en_alpha > 1
+ @en_alpha = 1
+ @en_da = -@en_da
+ if @en_alpha < 0
+ @en_alpha = 0
+ @en_da = -@en_da
+
+
+ draw: (ctx) ->
+ ctx.fillStyle = 'white'
+ ctx.fillRect 0, 0, atom.width, atom.height
+
+ for orb in @orbs
+ ctx.fillStyle = orb.color
+ do ctx.beginPath
+ ctx.arc orb.x, orb.y, 20, 0, Math.PI * 2, true
+ do ctx.fill
+
+ if @tm_light
+ i = atom.images.tm_light
+ else
+ i = atom.images.tm_dark
+ ctx.drawImage i, atom.width/2 - i.width/2, 10
+
+ i = atom.images.enlightenment_blur
+ ctx.globalAlpha = @en_alpha
+ ctx.drawImage i, atom.width/2 - i.width/2, atom.images.tm_dark.height + 20
+
+ i = atom.images.enlightenment
+ ctx.globalAlpha = 1
+ ctx.drawImage i, atom.width/2 - i.width/2, atom.images.tm_dark.height + 20
+
+ i = atom.images.title_monk
+ ctx.drawImage i, atom.width/2 - i.width/2, atom.height - i.height
+
+
class BackgroundStars
constructor: () ->
@stars = ([randInRange(0, atom.width), randInRange(0, atom.height), randInRange(1, 3)] for i in [1 .. 100])
@@ -428,7 +544,6 @@ class Game extends atom.Game
draw: ->
@scene.draw atom.context
- #Change scene after done drawing this frame
if @scene_new?
@scene = @scene_new
@scene_new = undefined
@@ -499,16 +614,16 @@ level1 = [
title = [
{
- repeat: 200,
+ repeat: 20,
waitUntil: (s) -> game.loaded,
draw: (ctx) ->
atom.context.font = '24px Georgia'
ctx.fillStyle = "blue"
ctx.fillText 'Loading', 150, atom.height/2 - 24
},
- {setBackground: new BackgroundFlat "orange"},
+ {setBackground: new BackgroundTitle},
{playMusic: 'intro'},
- {wait: 1},
+ {waitUntil: (s) -> atom.input.pressed 'space'},
{changeScene: new Scene level1}
]
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e1dd4c2

Please sign in to comment.