Permalink
Browse files

splitting asteroids

  • Loading branch information...
1 parent fd118ef commit a0637893c960535648d90ef64c48f1d2801a19e9 @kurazu committed Jul 20, 2011
Showing with 8 additions and 6 deletions.
  1. +6 −4 src/controller.coffee
  2. +2 −2 src/view.coffee
View
@@ -146,18 +146,20 @@ class Asteroid extends Shape
@generation = parent.generation + 1
@model = Object.create parent.model
@model.position = Object.create parent.model.position
+ @model.rotation = rand(Math.PI / 8, Math.PI) * (if rand(0, 1) >= 0.5 then 1 else -1)
@model.velocity_vector = Object.create parent.model.velocity_vector
- @scale = parent.scale * 2
- @vertices = Object.create parent.vertices
+ @scale = 0.75
+ @vertices = parent.vertices
# split into smaller asteroids
split: () ->
- if @generation >= @max_generation
+ if @generation > @max_generation
return # no more splitting
for i in [0...@generation]
split = new Asteroid this
- split.model.velocity_vector.rotate (i + 1) / @generation * Math.PI * 2
+ split.model.velocity_vector.rotate (i + 1) / @generation * Math.PI * 2 + Math.PI / 2
@addShape split
+ undefined
asteroids.controller.Rocket = Rocket
asteroids.controller.Asteroid = Asteroid
View
@@ -19,7 +19,7 @@ class Space
draw: (shapes) ->
time = getTime()
if time - @prev_time > 1000
- @fps = (time - @prev_time) / @frames
+ @fps = @frames
@prev_time = time
@frames = 0
@frames++
@@ -29,7 +29,7 @@ class Space
@ctx.beginPath()
@ctx.fillStyle = 'white'
@ctx.font = 'bold 12px Verdana'
- @ctx.fillText "#{@fps.toFixed(1)} FPS", 2, 10
+ @ctx.fillText "#{@fps} FPS", 2, 10
@ctx.fill()
@ctx.restore()
shape.draw @ctx for shape in shapes

0 comments on commit a063789

Please sign in to comment.