Skip to content

Commit

Permalink
Not every object has a position
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielVartanov committed Jul 19, 2015
1 parent 75d0ac2 commit 5113ae3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions lib/game_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

module GeekGame
class GameObject
attr_reader :position
attr_reader :birth_time

def initialize
Expand All @@ -30,9 +29,9 @@ def distance_to(another_object)
def to_hash
{
id: id,
type: self.class.to_s.demodulize.underscore,
position: position.to_array
type: self.class.to_s.demodulize.underscore
}.tap do |hash|
hash[:position] = position.to_array if respond_to?(:position) && position
hash[:player_color] = player.color if respond_to?(:player) && player
hash[:angle] = angle if respond_to?(:angle)
end
Expand All @@ -59,11 +58,14 @@ def define_properties(*properties)

protected

attr_writer :position
attr_writer :birth_time

def register!
GeekGame.game_objects << self
end

def deregister!
GeekGame.game_objects.delete self
end
end
end
4 changes: 2 additions & 2 deletions lib/metal_derrick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class MetalDerrick < Facility
facility_properties connection_distance: 20
metal_derrick_properties metal_bars_per_chunk: 5, cooldown_period: 2.0

attr_reader :metal_bars_available
attr_reader :metal_bars_available, :position
alias :metal_bars_available? :metal_bars_available

def initialize(position:)
Expand Down Expand Up @@ -41,7 +41,7 @@ def to_hash

protected

attr_writer :metal_bars_available
attr_writer :metal_bars_available, :position
attr_accessor :seconds_passed_since_last_extraction

def can_give_metal_to?(bot)
Expand Down
4 changes: 2 additions & 2 deletions lib/recharger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Recharger < Facility

recharger_properties range: 300.0, charge_rate: 0.1

attr_reader :player
attr_reader :player, :position

def initialize(params)
self.position = params[:position]
Expand All @@ -27,6 +27,6 @@ def update(seconds)

protected

attr_writer :player
attr_writer :player, :position
end
end
4 changes: 2 additions & 2 deletions lib/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Shell < GameObject
MAX_RANGE = 400
MAX_DAMAGE = 80

attr_reader :owner, :angle
attr_reader :owner, :angle, :position

def initialize(params={})
self.angle = params[:angle] || 0
Expand Down Expand Up @@ -43,7 +43,7 @@ def hit?(bot)

protected

attr_writer :owner, :angle
attr_writer :owner, :angle, :position
attr_accessor :initial_position
end
end
2 changes: 2 additions & 0 deletions lib/tracked_bot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class TrackedBot < GameObject
attr_reader :battery
attr_reader :player
attr_reader :angle
attr_reader :position

def track_axis
Line(left_track_position, right_track_position)
Expand Down Expand Up @@ -76,6 +77,7 @@ def normalized_axis_vector
attr_writer :health_points
attr_writer :player
attr_writer :angle
attr_writer :position

def advancing_cost(seconds)
movement_cost * seconds * (left_track.power + right_track.power)
Expand Down

0 comments on commit 5113ae3

Please sign in to comment.