Permalink
Browse files

cleaned up some constructors

  • Loading branch information...
bgoodspeed committed Nov 5, 2010
1 parent f27ae8e commit 9ff469558158ef2a0b0c5e592c26c2f1f96929d8
View
@@ -26,18 +26,21 @@ class Player
attr_reader :filename, :hero_x_dim, :hero_y_dim
- def initialize( px, py, universe, party, filename, hx, hy, sx, sy, game)
+ def initialize( position, universe, party, filename, sx, sy, game)
@game = game
@universe = universe
@filename = filename
- @hero_x_dim = hx
- @hero_y_dim = hy
+ @hero_x_dim = position.dimension.x
+ @hero_y_dim = position.dimension.y
+
@interaction_helper = InteractionHelper.new(self, @universe, InteractionPolicy.immediate_return)
@keys = KeyHolder.new
- @coordinate_helper = CoordinateHelper.new(px, py, @keys, @universe, @hero_x_dim, @hero_y_dim)
+ @coordinate_helper = CoordinateHelper.new(position, @keys, @universe)
@animation_helper = AnimationHelper.new(@keys)
@weapon_helper = WorldWeaponHelper.new(self, @universe)
- @animated_sprite_helper = AnimatedSpriteHelper.new(filename, sx, sy, @hero_x_dim, @hero_y_dim)
+ sprite_pos = position.clone
+ sprite_pos.position = SdlCoordinate.new(sx,sy)
+ @animated_sprite_helper = AnimatedSpriteHelper.new(filename, sprite_pos)
@mission_archive = MissionArchive.new(game)
@party = party
@@ -68,7 +68,8 @@ def make_player(screen, universe, game)
player_file = "StickMan.PNG"
ssx = screen.w/2
ssy = screen.h/2
- player = Player.new(ssx, ssy , universe, party, player_file, hero_x_dim, hero_y_dim , ssx, ssy, game )
+ posn = PositionedTileCoordinate.new(SdlCoordinate.new(ssx, ssy), SdlCoordinate.new(hero_x_dim, hero_y_dim))
+ player = Player.new(posn, universe, party, player_file, ssx, ssy, game )
player
# Make event hook to pass all events to @player#handle().
@@ -88,7 +89,8 @@ def make_npc(player, universe)
EquipmentHolder.new)
npcai = ArtificialIntelligence.new(RepeatingPathFollower.new("LURD", 80), nil) #TODO maybe make a noop battle strategy just in case?
#npcai = StaticPathFollower.new
- TalkingNPC.new(player, universe, "i am an npc", "gogo-npc.png", 600, 200,48,64, Inventory.new(255), npcattrib, npcai)
+ posn = PositionedTileCoordinate.new(SdlCoordinate.new(600,200), SdlCoordinate.new(48,64))
+ TalkingNPC.new(player, universe, "i am an npc", "gogo-npc.png", posn, Inventory.new(255), npcattrib, npcai)
end
def make_world2
@@ -9,6 +9,8 @@ def make_monster(player,universe)
CharacterState.new(CharacterAttributes.new(3, 0, 1, 0, 0, 0, 0, 0)),
EquipmentHolder.new)
monai = ArtificialIntelligence.new(RepeatingPathFollower.new("DRUL", 80), BattleStrategy.new([BattleTactic.new("Enemy: Any -> Attack")]))
- Monster.new(player,universe,"monster.png", 400,660, @@MONSTER_X, @@MONSTER_Y, monster_inv, monattrib, monai)
+
+ posn = PositionedTileCoordinate.new(SdlCoordinate.new(400, 660), SdlCoordinate.new(@@MONSTER_X, @@MONSTER_Y))
+ Monster.new(player,universe,"monster.png", posn, monster_inv, monattrib, monai)
end
end
View
@@ -1,6 +1,9 @@
# To change this template, choose Tools | Templates
# and open the template in the editor.
+require 'lib/tile_system/sdl_coordinate'
+require 'lib/tile_system/positioned_tile_coordinate'
+
require 'lib/helpers/resource_loader'
require 'lib/helpers/color_key_helper'
require 'lib/helpers/json_helper'
@@ -12,6 +15,7 @@
require 'lib/tile_system/json_loadable_surface'
require 'lib/tile_system/coordinate_helper'
+
require 'lib/input/key_holder'
require 'lib/input/event_helper'
require 'lib/input/event_manager'
@@ -5,16 +5,16 @@ class AnimatedSpriteHelper
include ColorKeyHelper
include ResourceLoader
- def initialize(filename, px, py, avatar_x_dim, avatar_y_dim)
+ def initialize(filename, position)
@all_char_postures = load_surface(filename)
set_colorkey_from_corner(@all_char_postures)
@all_char_postures.alpha = 255
- @px = px
- @py = py #XXX this might be a bug to use these, they should come from the coord helper?
- @avatar_x_dim = avatar_x_dim
- @avatar_y_dim = avatar_y_dim
+ @px = position.position.x
+ @py = position.position.y #XXX this might be a bug to use these, they should come from the coord helper?
+ @avatar_x_dim = position.dimension.x
+ @avatar_y_dim = position.dimension.y
@image = Surface.new([@avatar_x_dim,@avatar_y_dim])
View
@@ -18,16 +18,17 @@ class Monster
attr_reader :inventory, :player
- def initialize(player, universe, filename, px, py, npc_x = @@MONSTER_X, npc_y = @@MONSTER_Y, inventory=Inventory.new(255), character_attrib=nil, ai=nil)
- @npc_x = npc_x
- @npc_y = npc_y
+ def initialize(player, universe, filename, position, inventory=Inventory.new(255), character_attrib=nil, ai=nil)
+ @npc_x = position.dimension.x
+ @npc_y = position.dimension.y
@filename = filename
@universe = universe
@player = player
@ai = ai
- @animated_sprite_helper = AnimatedSpriteHelper.new(filename, px, py, @npc_x, @npc_y)
+ @animated_sprite_helper = AnimatedSpriteHelper.new(filename, position)
@keys = AlwaysDownMonsterKeyHolder.new
- @coordinate_helper = MonsterCoordinateHelper.new(px, py, @keys, @universe, @npc_x, @npc_y,100, 300,200)
+
+ @coordinate_helper = MonsterCoordinateHelper.new(position, @keys, @universe ,100, 300,200)
@animation_helper = AnimationHelper.new(@keys, 3)
@readiness_helper = BattleReadinessHelper.new(@@MONSTER_START_BATTLE_PTS, @@MONSTER_BATTLE_PTS_RATE)
@character_attribution = character_attrib
@@ -4,8 +4,8 @@ def is_blocking?
true
end
- def initialize(player, universe, text, filename, px, py, npc_x, npc_y, inv=nil, attrib=nil, ai=nil)
- super(player, universe,filename, px, py, npc_x, npc_y, inv, attrib, ai)
+ def initialize(player, universe, text, filename, posn, inv=nil, attrib=nil, ai=nil)
+ super(player, universe,filename, posn, inv, attrib, ai)
@text = text
end
@@ -14,7 +14,9 @@ def replace(game, json_player)
universe.reblit_backgrounds
puts "backgrounds rebuilt"
- player = Player.new(json_player.px, json_player.py, universe, json_player.party, json_player.filename, json_player.hero_x_dim, json_player.hero_y_dim, game.screen.w/2, game.screen.h/2)
+ posn = PositionedTileCoordinate.new(SdlCoordinate.new(json_player.px, json_player.py), SdlCoordinate.new(json_player.hero_x_dim, json_player.hero_y_dim))
+
+ player = Player.new(posn, universe, json_player.party, json_player.filename, game.screen.w/2, game.screen.h/2)
#TODO update tile coords for player
game.universe = universe
game.player = player
@@ -2,11 +2,12 @@
class CoordinateHelper
attr_accessor :px, :py
- def initialize(px,py, key,universe, hero_x_dim, hero_y_dim, max_speed=400, accel=1200, slowdown=800)
- @hero_x_dim, @hero_y_dim = hero_x_dim, hero_y_dim
+ def initialize(position, key,universe, max_speed=400, accel=1200, slowdown=800)
+ @hero_x_dim = position.dimension.x
+ @hero_y_dim = position.dimension.y
@universe = universe
@keys = key
- @px, @py = px, py # Current Position
+ @px, @py = position.position.x, position.position.y # Current Position
@vx, @vy = 0, 0 # Current Velocity
@ax, @ay = 0, 0 # Current Acceleration
@max_speed = max_speed # Max speed on an axis
@@ -0,0 +1,11 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class PositionedTileCoordinate
+ attr_accessor :position, :dimension
+ def initialize(position_coords, dimension_coords)
+ @position = position_coords
+ @dimension = dimension_coords
+
+ end
+end
@@ -0,0 +1,11 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+class SdlCoordinate
+ attr_accessor :x, :y
+ def initialize(x,y)
+ @x = x
+ @y = y
+
+ end
+end
@@ -23,7 +23,8 @@
AnimatedSpriteHelper.should_receive(:new).and_return(@animated_sprite_helper)
@party = Party.new([], Inventory.new(255))
@uni = mocking(:current_world => @world)
- @player = Player.new(320, 240 ,@uni, @party, "fake", 12, 12, 1111, 2222, mock_game )
+ posn = PositionedTileCoordinate.new(SdlCoordinate.new(320,240), SdlCoordinate.new(12,12) )
+ @player = Player.new(posn ,@uni, @party, "fake", 1111, 2222, mock_game )
end
it "should delete the monster from the universe" do

0 comments on commit 9ff4695

Please sign in to comment.