 
 class Missile extends MovableBattleFieldObject
   power: 1
+  energy: 10
   speed: -> super() * 4
   set_power: (@power) ->
+    @energy = 10 * @power
   set_direction: (@direction) ->
   set_belongs_to: (@belongs_to) ->
   type: -> 'missile'
   update: ->
     super()
     # if collide with other object, then explode
-    destory_area = @destory_area()
+    destroy_area = @destroy_area()
     # START HERE
-    # @explode() unless _.every(destory_area, () -> )
-
-    # objects = @battle_field.find_objects_at(@destroy_area())
+    return @explode() if @battle_field.is_out_of_bound(destroy_area)
+
+    objects = @battle_field.find_objects_at(destroy_area)
+    _.each(objects, (object) =>
+      @energy -= object.on_hit_missile(this, destroy_area)
+    )
+    @explode() if @energy <= 0
 
   exploded: false
   explode: ->
     # bom!
     @exploded = true
 
-  # handle_move: (order, delta_time) ->
-  #   super(order, delta_time)
   destroy_area: ->
-    [x, y] = [@x(), @y()]
     switch @direction
       when 0
         [
-          x - @battle_field.default_width / 4,
-          y - (@battle_field.default_height / 4) - 1,
-          x + @battle_field.default_width / 4,
-          y - @battle_field.default_height / 4
+          @x() - @battle_field.default_width / 4,
+          @y() - (@battle_field.default_height / 4) - 10,
+          @x() + @battle_field.default_width / 4,
+          @y() - @battle_field.default_height / 4
         ]
       when 90
         [
-          x + @battle_field.default_width / 4,
-          y - @battle_field.default_height / 4,
-          x + (@battle_field.default_width / 4) + 1,
-          y + @battle_field.default_height / 4
+          @x() + @battle_field.default_width / 4,
+          @y() - @battle_field.default_height / 4,
+          @x() + (@battle_field.default_width / 4) + 10,
+          @y() + @battle_field.default_height / 4
         ]
       when 180
         [
-          x - @battle_field.default_width / 4,
-          y + @battle_field.default_height / 4,
-          x + @battle_field.default_width / 4,
-          y + (@battle_field.default_height / 4) + 1
+          @x() - @battle_field.default_width / 4,
+          @y() + @battle_field.default_height / 4,
+          @x() + @battle_field.default_width / 4,
+          @y() + (@battle_field.default_height / 4) + 10
         ]
       when 270
         [
-          x - (@battle_field.default_width / 4) - 1,
-          y - @battle_field.default_height / 4,
-          x - @battle_field.default_width / 4,
-          y + @battle_field.default_height / 4
+          @x() - (@battle_field.default_width / 4) - 10,
+          @y() - @battle_field.default_height / 4,
+          @x() - @battle_field.default_width / 4,
+          @y() + @battle_field.default_height / 4
         ]
 
 class Gift extends BattleFieldObject


class GrassTerrain extends Terrain
  enterable: (battle_field_object) -> true
  destroyable: (missile) -> missile.power >= 3
  type: -> "grass"
  layer: 2


class BattleField
  max_x: 520
  max_y: 520
  max_enegy: 100
  default_width: 40
  default_height: 40
  step: 2
