Permalink
Browse files

more method signature/constructor cleanup

  • Loading branch information...
1 parent e6f8300 commit 50ae952f21687187cd6d3707b70d674030ba060c @bgoodspeed committed Nov 5, 2010
Showing with 23 additions and 22 deletions.
  1. +2 −2 lib/domain/player.rb
  2. +17 −16 lib/tile_system/interaction_helper.rb
  3. +4 −4 lib/world_weapons/world_weapon_helper.rb
View
@@ -33,11 +33,11 @@ def initialize( position, universe, party, filename, sx, sy, game)
@hero_x_dim = position.dimension.x
@hero_y_dim = position.dimension.y
- @interaction_helper = InteractionHelper.new(self, @universe, InteractionPolicy.immediate_return)
+ @interaction_helper = InteractionHelper.new(game, InteractionPolicy.immediate_return)
@keys = KeyHolder.new
@coordinate_helper = CoordinateHelper.new(position, @keys, @universe)
@animation_helper = AnimationHelper.new(@keys)
- @weapon_helper = WorldWeaponHelper.new(self, @universe)
+ @weapon_helper = WorldWeaponHelper.new(game)
sprite_pos = position.clone
sprite_pos.position = SdlCoordinate.new(sx,sy)
@animated_sprite_helper = AnimatedSpriteHelper.new(filename, sprite_pos)
@@ -2,41 +2,42 @@ class InteractionHelper
@@INTERACTION_DISTANCE_THRESHOLD = 80 #XXX tweak this, currently set to 1/2 a tile
attr_accessor :facing
- def initialize(player, universe, policy)
- @player = player
- @universe = universe
+ def initialize(game, policy)
+ @game = game
+ @player = game.player
+ @universe = game.universe
@facing = :down
@policy = policy
end
def interact_with_current_tile(game, tilex, tiley, this_tile_interacts)
- this_tile_interacts.activate(game, @player, @universe.current_world, tilex, tiley)
+ this_tile_interacts.activate(game, game.player, game.universe.current_world, tilex, tiley)
end
def interact_with_dialog
@universe.dialog_layer.toggle_activity
end
def interact_with_facing_tile(game, facing_tilex, facing_tiley, facing_tile_interacts)
- facing_tile_interacts.activate(game,@player, @universe.current_world, facing_tilex, facing_tiley)
+ facing_tile_interacts.activate(game, game.player, game.universe.current_world, facing_tilex, facing_tiley)
end
def interact_with_npc(game, interactable_npcs)
npc = interactable_npcs[0] #TODO what if there are multiple npcs to interact w/? one at a time? all of them?
- npc.interact(game, @universe, @player)
+ npc.interact(game, game.universe, game.player) #TODO change the expected signature for interact and make interactable api tests
end
def interact_with_facing(game, px,py)
- if @universe.dialog_layer.active
+ if game.universe.dialog_layer.active
puts "confirming/closing/paging dialog"
interact_with_dialog
return if @policy.return_after_dialog
end
puts "you are facing #{@facing}"
- tilex = @universe.current_world.x_offset_for_interaction(px)
- tiley = @universe.current_world.y_offset_for_interaction(py)
- this_tile_interacts = @universe.current_world.interaction_interpreter.interpret(tilex, tiley)
+ tilex = game.universe.current_world.x_offset_for_interaction(px)
+ tiley = game.universe.current_world.y_offset_for_interaction(py)
+ this_tile_interacts = game.universe.current_world.interaction_interpreter.interpret(tilex, tiley)
facing_tile_interacts = false
if this_tile_interacts
@@ -48,25 +49,25 @@ def interact_with_facing(game, px,py)
if @facing == :down
facing_tilex = tilex
facing_tiley = tiley + 1
- facing_tile_dist = (@universe.current_world.interaction_interpreter.top_side(tiley + 1) - py).abs
+ facing_tile_dist = (game.universe.current_world.interaction_interpreter.top_side(tiley + 1) - py).abs
end
if @facing == :up
facing_tilex = tilex
facing_tiley = tiley - 1
- facing_tile_dist = (@universe.current_world.interaction_interpreter.bottom_side(tiley - 1) - py).abs
+ facing_tile_dist = (game.universe.current_world.interaction_interpreter.bottom_side(tiley - 1) - py).abs
end
if @facing == :left
facing_tilex = tilex - 1
facing_tiley = tiley
- facing_tile_dist = (@universe.current_world.interaction_interpreter.right_side(tilex - 1) - px).abs
+ facing_tile_dist = (game.universe.current_world.interaction_interpreter.right_side(tilex - 1) - px).abs
end
if @facing == :right
facing_tilex = tilex + 1
facing_tiley = tiley
- facing_tile_dist = (@universe.current_world.interaction_interpreter.left_side(tilex + 1) - px).abs
+ facing_tile_dist = (game.universe.current_world.interaction_interpreter.left_side(tilex + 1) - px).abs
end
- facing_tile_interacts = @universe.current_world.interaction_interpreter.interpret(facing_tilex, facing_tiley)
+ facing_tile_interacts = game.universe.current_world.interaction_interpreter.interpret(facing_tilex, facing_tiley)
facing_tile_close_enough = facing_tile_dist < @@INTERACTION_DISTANCE_THRESHOLD
if facing_tile_close_enough and facing_tile_interacts
@@ -76,7 +77,7 @@ def interact_with_facing(game, px,py)
return if @policy.return_after_facing
end
- interactable_npcs = @universe.current_world.npcs.select {|npc| npc.nearby?(px,py, @@INTERACTION_DISTANCE_THRESHOLD, @@INTERACTION_DISTANCE_THRESHOLD) }
+ interactable_npcs = game.universe.current_world.npcs.select {|npc| npc.nearby?(px,py, @@INTERACTION_DISTANCE_THRESHOLD, @@INTERACTION_DISTANCE_THRESHOLD) }
unless interactable_npcs.empty?
puts "you can interact with the npc: #{interactable_npcs[0]}"
interact_with_npc(game, interactable_npcs)
@@ -5,11 +5,11 @@ class WorldWeaponHelper
def_delegators :@weapon, :draw_weapon
def_delegators :@interaction_helper, :facing, :facing=
- def initialize(player, universe)
- @player = player
+ def initialize(game)
+ @player = game.player
@weapon = nil
- @universe = universe
- @interaction_helper = WorldWeaponInteractionHelper.new(@player, @universe, InteractionPolicy.process_all)
+ @universe = game.universe
+ @interaction_helper = WorldWeaponInteractionHelper.new(game, InteractionPolicy.process_all)
end
def use_weapon

0 comments on commit 50ae952

Please sign in to comment.