Skip to content

Commit

Permalink
cleaned up some constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoodspeed committed Nov 5, 2010
1 parent f27ae8e commit 9ff4695
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 25 deletions.
13 changes: 8 additions & 5 deletions lib/domain/player.rb
Expand Up @@ -26,18 +26,21 @@ class Player




attr_reader :filename, :hero_x_dim, :hero_y_dim 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 @game = game
@universe = universe @universe = universe
@filename = filename @filename = filename
@hero_x_dim = hx @hero_x_dim = position.dimension.x
@hero_y_dim = hy @hero_y_dim = position.dimension.y

@interaction_helper = InteractionHelper.new(self, @universe, InteractionPolicy.immediate_return) @interaction_helper = InteractionHelper.new(self, @universe, InteractionPolicy.immediate_return)
@keys = KeyHolder.new @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) @animation_helper = AnimationHelper.new(@keys)
@weapon_helper = WorldWeaponHelper.new(self, @universe) @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) @mission_archive = MissionArchive.new(game)
@party = party @party = party


Expand Down
6 changes: 4 additions & 2 deletions lib/factories/game_internals_factory.rb
Expand Up @@ -68,7 +68,8 @@ def make_player(screen, universe, game)
player_file = "StickMan.PNG" player_file = "StickMan.PNG"
ssx = screen.w/2 ssx = screen.w/2
ssy = screen.h/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 player
# Make event hook to pass all events to @player#handle(). # Make event hook to pass all events to @player#handle().
Expand All @@ -88,7 +89,8 @@ def make_npc(player, universe)
EquipmentHolder.new) EquipmentHolder.new)
npcai = ArtificialIntelligence.new(RepeatingPathFollower.new("LURD", 80), nil) #TODO maybe make a noop battle strategy just in case? npcai = ArtificialIntelligence.new(RepeatingPathFollower.new("LURD", 80), nil) #TODO maybe make a noop battle strategy just in case?
#npcai = StaticPathFollower.new #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 end


def make_world2 def make_world2
Expand Down
4 changes: 3 additions & 1 deletion lib/factories/monster_factory.rb
Expand Up @@ -9,6 +9,8 @@ def make_monster(player,universe)
CharacterState.new(CharacterAttributes.new(3, 0, 1, 0, 0, 0, 0, 0)), CharacterState.new(CharacterAttributes.new(3, 0, 1, 0, 0, 0, 0, 0)),
EquipmentHolder.new) EquipmentHolder.new)
monai = ArtificialIntelligence.new(RepeatingPathFollower.new("DRUL", 80), BattleStrategy.new([BattleTactic.new("Enemy: Any -> Attack")])) 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
end end
4 changes: 4 additions & 0 deletions lib/game_requirements.rb
@@ -1,6 +1,9 @@
# To change this template, choose Tools | Templates # To change this template, choose Tools | Templates
# and open the template in the editor. # 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/resource_loader'
require 'lib/helpers/color_key_helper' require 'lib/helpers/color_key_helper'
require 'lib/helpers/json_helper' require 'lib/helpers/json_helper'
Expand All @@ -12,6 +15,7 @@
require 'lib/tile_system/json_loadable_surface' require 'lib/tile_system/json_loadable_surface'
require 'lib/tile_system/coordinate_helper' require 'lib/tile_system/coordinate_helper'



require 'lib/input/key_holder' require 'lib/input/key_holder'
require 'lib/input/event_helper' require 'lib/input/event_helper'
require 'lib/input/event_manager' require 'lib/input/event_manager'
Expand Down
10 changes: 5 additions & 5 deletions lib/helpers/animated_sprite_helper.rb
Expand Up @@ -5,16 +5,16 @@ class AnimatedSpriteHelper
include ColorKeyHelper include ColorKeyHelper
include ResourceLoader include ResourceLoader


def initialize(filename, px, py, avatar_x_dim, avatar_y_dim) def initialize(filename, position)
@all_char_postures = load_surface(filename) @all_char_postures = load_surface(filename)


set_colorkey_from_corner(@all_char_postures) set_colorkey_from_corner(@all_char_postures)
@all_char_postures.alpha = 255 @all_char_postures.alpha = 255


@px = px @px = position.position.x
@py = py #XXX this might be a bug to use these, they should come from the coord helper? @py = position.position.y #XXX this might be a bug to use these, they should come from the coord helper?
@avatar_x_dim = avatar_x_dim @avatar_x_dim = position.dimension.x
@avatar_y_dim = avatar_y_dim @avatar_y_dim = position.dimension.y




@image = Surface.new([@avatar_x_dim,@avatar_y_dim]) @image = Surface.new([@avatar_x_dim,@avatar_y_dim])
Expand Down
11 changes: 6 additions & 5 deletions lib/npcs/monster.rb
Expand Up @@ -18,16 +18,17 @@ class Monster




attr_reader :inventory, :player 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) def initialize(player, universe, filename, position, inventory=Inventory.new(255), character_attrib=nil, ai=nil)
@npc_x = npc_x @npc_x = position.dimension.x
@npc_y = npc_y @npc_y = position.dimension.y
@filename = filename @filename = filename
@universe = universe @universe = universe
@player = player @player = player
@ai = ai @ai = ai
@animated_sprite_helper = AnimatedSpriteHelper.new(filename, px, py, @npc_x, @npc_y) @animated_sprite_helper = AnimatedSpriteHelper.new(filename, position)
@keys = AlwaysDownMonsterKeyHolder.new @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) @animation_helper = AnimationHelper.new(@keys, 3)
@readiness_helper = BattleReadinessHelper.new(@@MONSTER_START_BATTLE_PTS, @@MONSTER_BATTLE_PTS_RATE) @readiness_helper = BattleReadinessHelper.new(@@MONSTER_START_BATTLE_PTS, @@MONSTER_BATTLE_PTS_RATE)
@character_attribution = character_attrib @character_attribution = character_attrib
Expand Down
4 changes: 2 additions & 2 deletions lib/npcs/talking_n_p_c.rb
Expand Up @@ -4,8 +4,8 @@ def is_blocking?
true true
end end


def initialize(player, universe, text, filename, px, py, npc_x, npc_y, inv=nil, attrib=nil, ai=nil) def initialize(player, universe, text, filename, posn, inv=nil, attrib=nil, ai=nil)
super(player, universe,filename, px, py, npc_x, npc_y, inv, attrib, ai) super(player, universe,filename, posn, inv, attrib, ai)
@text = text @text = text
end end


Expand Down
4 changes: 3 additions & 1 deletion lib/processes/reloader_helper.rb
Expand Up @@ -14,7 +14,9 @@ def replace(game, json_player)


universe.reblit_backgrounds universe.reblit_backgrounds
puts "backgrounds rebuilt" 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 #TODO update tile coords for player
game.universe = universe game.universe = universe
game.player = player game.player = player
Expand Down
7 changes: 4 additions & 3 deletions lib/tile_system/coordinate_helper.rb
Expand Up @@ -2,11 +2,12 @@
class CoordinateHelper class CoordinateHelper
attr_accessor :px, :py attr_accessor :px, :py


def initialize(px,py, key,universe, hero_x_dim, hero_y_dim, max_speed=400, accel=1200, slowdown=800) def initialize(position, key,universe, max_speed=400, accel=1200, slowdown=800)
@hero_x_dim, @hero_y_dim = hero_x_dim, hero_y_dim @hero_x_dim = position.dimension.x
@hero_y_dim = position.dimension.y
@universe = universe @universe = universe
@keys = key @keys = key
@px, @py = px, py # Current Position @px, @py = position.position.x, position.position.y # Current Position
@vx, @vy = 0, 0 # Current Velocity @vx, @vy = 0, 0 # Current Velocity
@ax, @ay = 0, 0 # Current Acceleration @ax, @ay = 0, 0 # Current Acceleration
@max_speed = max_speed # Max speed on an axis @max_speed = max_speed # Max speed on an axis
Expand Down
11 changes: 11 additions & 0 deletions lib/tile_system/positioned_tile_coordinate.rb
@@ -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
11 changes: 11 additions & 0 deletions lib/tile_system/sdl_coordinate.rb
@@ -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
3 changes: 2 additions & 1 deletion spec/battle/battle_victory_helper_spec.rb
Expand Up @@ -23,7 +23,8 @@
AnimatedSpriteHelper.should_receive(:new).and_return(@animated_sprite_helper) AnimatedSpriteHelper.should_receive(:new).and_return(@animated_sprite_helper)
@party = Party.new([], Inventory.new(255)) @party = Party.new([], Inventory.new(255))
@uni = mocking(:current_world => @world) @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 end


it "should delete the monster from the universe" do it "should delete the monster from the universe" do
Expand Down

0 comments on commit 9ff4695

Please sign in to comment.