Permalink
Browse files

steering

  • Loading branch information...
1 parent 8ba6ad9 commit e7cc0dce57b707d1a06d9ec15c1f7c644d1d65b8 @kurazu committed Jul 17, 2011
Showing with 19 additions and 5 deletions.
  1. +6 −4 src/controller.coffee
  2. +13 −1 src/game.coffee
View
@@ -32,9 +32,9 @@ class Rocket extends Shape
vertices: ROCKET_VERTICES
scale: 5.0
style: 'green'
- max_velocity: 200
- acceleration: 40
- deceleration: 60
+ max_velocity: 500
+ acceleration: 400
+ deceleration: 600
steering: Math.PI * 2
constructor: () ->
@model = new asteroids.model.Shape 250, 250, 0, 0, 0
@@ -51,12 +51,14 @@ class Rocket extends Shape
@model.velocity += @acceleration * scale
@model.velocity = @max_velocity if @model.velocity > @max_velocity
onBrake: with_scale (scale) ->
- @model.velocity += @deceleration * scale
+ @model.velocity -= @deceleration * scale
@model.velocity = 0 if @model.velocity < 0
onLeft: with_scale (scale) ->
@model.angle += @steering * scale
+ console.log 'left', @model.angle
onRight: with_scale (scale) ->
@model.angle -= @steering * scale
+ console.log 'right', @model.angle
onFire: (time) ->
console.log 'fire'
move: (timediff) ->
View
@@ -36,7 +36,19 @@ class Game
@shapes.push new asteroids.controller.Rocket()
@shapes.push new asteroids.controller.Asteroid() for i in [0..5]
move: (timediff) ->
- shape.move timediff for shape in @shapes
+ for shape in @shapes
+ shape.move timediff
+ @fixPostion shape
+ fixPostion: (shape) ->
+ pos = shape.model.position
+ if pos.x < 0
+ pos.x = 500
+ else if pos.x > 500
+ pos.x = 0
+ if pos.y < 0
+ pos.y = 500
+ else if pos.y > 500
+ pos.y = 0
onFrame: () ->
time = getTime()
timediff = time - @prevtime

0 comments on commit e7cc0dc

Please sign in to comment.