Skip to content

Commit

Permalink
Ship barrage and collision detection
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroeth committed Feb 2, 2013
1 parent 2353b86 commit 5c8a3ca
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions companion_missile.rb
Expand Up @@ -20,6 +20,7 @@ def velocity_magnitude
end
end


class ShipLoader
def self.ship
self.ship_tiles.first
Expand Down Expand Up @@ -51,6 +52,8 @@ def setup

class Ship < Chingu::GameObject
traits :velocity, :vector
traits :bounding_circle, :collision_detection

attr_accessor :turn_thruster, :main_thruster

# TODO do blocks!
Expand Down Expand Up @@ -92,12 +95,46 @@ def setup


class DizzyShip < Ship
attr_accessor :target

def setup
super

self.input = {space: :missile_spread}
end

def update
super
turn_left

self.velocity = vector main_thruster
end

def missile_spread
5.times do |n|
left = TrackingShip.create
right = TrackingShip.create

left.x, left.y = self.x, self.y
right.x, right.y = self.x, self.y

left.target = self.target
right.target = self.target

spread = n * 4
speed = 10
turn = 4

left.angle = self.angle - spread
right.angle = self.angle + spread

left.turn_thruster = turn
right.turn_thruster = turn

left.main_thruster = speed
right.main_thruster = speed
end
end
end


Expand Down Expand Up @@ -125,6 +162,7 @@ def update

end


class MouseShip < Ship
traits :velocity

Expand Down Expand Up @@ -160,20 +198,28 @@ class TimeDilation
end



# TODO make larger than screeeeeeeeeeeen
class Level < Chingu::GameState
def setup
super

mouse_ship = MouseShip.create
dizzy_ship = DizzyShip.create
dizzy_ship.target = mouse_ship #temporary

rand(50).times do
(rand(3)+1).times do
ship = TrackingShip.create
ship.target = mouse_ship
end
end

def update
super

MouseShip.each_collision(TrackingShip) do |mouse_ship, tracking_ship|
tracking_ship.destroy
end
end
end


Expand Down

0 comments on commit 5c8a3ca

Please sign in to comment.