Skip to content

Commit

Permalink
Better death animations
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Mark Schwartz committed Nov 28, 2012
1 parent 9af3113 commit 33d88d7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
Binary file added explosion0.wav
Binary file not shown.
Binary file added explosion1.wav
Binary file not shown.
45 changes: 35 additions & 10 deletions game.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Number.prototype.clamp = (min, max) ->
randInRange = (l, h) ->
l + Math.random() * (h - l)

randNorm = () ->
((Math.random() for i in [1..12]).reduce (t,s) -> t + s) / 12

hsv2rgb = (h, s, v) ->
c = v * s
h_p = h / 60.0
Expand Down Expand Up @@ -67,6 +70,8 @@ sounds =
intro: 'DST-ClubNight.mp3'
level1: 'DST-SpaceBuddha.mp3'
hum: 'hum.wav'
explosion0: 'explosion0.wav'
explosion1: 'explosion1.wav'

atom.preloadSounds sounds, (x) -> game.loaded = true

Expand Down Expand Up @@ -142,7 +147,7 @@ class Scene

beam_hit = (@ship?.collideEnemy e for e in @enemies).some (x) -> x
if beam_hit
game.soundOn 'hum'
game.soundOn 'hum', .5
else
game.soundOff 'hum'

Expand Down Expand Up @@ -181,15 +186,16 @@ class Scene
@bullets.push new Bullet x, y, bullet.move, bullet.image

spawnEnemy: (x, y, e) ->
@enemies.push new Enemy x, y, e.move, e.fire, e.bullet, e.animate, e.health
@enemies.push new Enemy x, y, e.move, e.fire, e.bullet, e.animate, e.health, e.die

spawnExplosion: (x, y) ->
color = new Rainbow
for i in [1..40]
spawnExplosion: (x, y, n = 60, speed = [50, 200]) ->
while n > 0
n -= 1
theta = randInRange 0, 2 * Math.PI
speed = randInRange 20, 100
s= randInRange speed[0], speed[1]
r = randInRange 1, 3
@explosions.push new Explosion x, y, (moveStraightGravity speed * Math.cos(theta), speed * Math.sin(theta)), r, color.next()
@explosions.push new Explosion x, y, (moveStraight s* Math.cos(theta), s* Math.sin(theta)), r, [254,124,5]

undefined

showShip: (x = atom.width * .5, y = atom.height * .7, speed = 150) ->
Expand Down Expand Up @@ -329,13 +335,23 @@ fireEvery = (fireEvery=1) ->
true
else false

die =
normal: (e) ->
atom.playSound 'explosion0'
game.scene.spawnExplosion e.x, e.y
massive: (e) ->
atom.playSound 'explosion1'
for i in [0 .. 15]
game.scene.spawnExplosion atom.width * randNorm() + e.x - atom.width/2, atom.height * randNorm() + e.y - atom.height/2

enemy =
basic: (dx, dy, fireRate = .5) ->
move: moveStraight dx, dy
fire: fireEvery fireRate
bullet: [() -> bulletStraight()]
animate: new AnimationRotate atom.images.eye, 2
health: 500
die: die.normal
circle: (n=6, speed=100)->
move: moveStraight()
fire: fireEvery 1
Expand All @@ -348,6 +364,7 @@ enemy =
)(i, 1)
animate: new AnimationRotate atom.images.wheel
health: 1000
die: die.normal
fan: (dx, dy, n=6, speed=100)->
odd = 1
ret =
Expand All @@ -362,12 +379,14 @@ enemy =
)
animate: new Animation enemyImage
health: 1000
die: die.normal
direct: (dx, dy, g) ->
move: moveStraightGravity dx, dy, g
fire: fireEvery 1
bullet: [(dt, s, e) -> bulletDirect s, e]
animate: new Animation enemyImage
health: 1250
die: die.normal

buddha1: (theta0 = 0, theta1 = Math.PI, dtheta = Math.PI/9.5, speed = 100) ->
move: moveRandom()
Expand All @@ -391,7 +410,8 @@ enemy =
]

animate: new Animation atom.images.buddha1
health: 50000
health: 50000
die: die.massive


class Enemy
Expand Down Expand Up @@ -430,7 +450,7 @@ class Enemy
@health -= dh * @health_coeff
if @health <= 0
@alive = false
game.scene.spawnExplosion @x, @y
@die this


class Ship
Expand Down Expand Up @@ -698,10 +718,11 @@ class Game extends atom.Game
else if @music_source?
@musicPlay @music_source

soundOn: (sound) ->
soundOn: (sound, gain = 1) ->
if not @playing[sound]? or @playing[sound].playbackState == 3
@playing[sound] = atom.playSound sound
@playing[sound].loop = true
@playing[sound].gain.value = gain

soundOff: (sound) ->
if @playing[sound]?
Expand Down Expand Up @@ -759,6 +780,10 @@ level1 = [
{waitUntil: (s) -> s.enemies.length <= 0},
{wait: 5},
{do: (s) -> s.spawnEnemy atom.width/2, 150, enemy.buddha1()},
{waitUntil: (s) -> s.enemies.length <= 0},
{wait:2},
{do: (s) -> s.fadeOut 2},
{wait: 3},
#{changeScene: true}
]

Expand Down

0 comments on commit 33d88d7

Please sign in to comment.