Skip to content

Commit

Permalink
cleaned up the @@classvar usage deemed a smell
Browse files Browse the repository at this point in the history
  • Loading branch information
bgoodspeed committed Nov 12, 2010
1 parent 2e6f63a commit e30111a
Show file tree
Hide file tree
Showing 30 changed files with 161 additions and 152 deletions.
2 changes: 1 addition & 1 deletion lib/ai/battle_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def take_battle_turn(actor, battle)
if tactic.matches?
tactic.perform
else
actor.consume_readiness(@@NOOP_ACTION_COST)
actor.consume_readiness(GameSettings::NOOP_ACTION_COST)
end
end
end
2 changes: 1 addition & 1 deletion lib/battle/battle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(game, monster)
end

def accumulate_readiness(dt)
points = dt * @@READINESS_POINTS_PER_SECOND
points = dt * GameSettings::READINESS_POINTS_PER_SECOND
@player.add_readiness(points)
@monster.add_readiness(points, self)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def cursor_offsets_at(position, game, menu_action)
if matches_menu_action?(menu_action)
offset = game.current_battle_participant_offset(position)
else
offset = [@@BATTLE_INVENTORY_XC + @@BATTLE_INVENTORY_XF * position, @@BATTLE_INVENTORY_YC + @@BATTLE_INVENTORY_YF * position]
offset = [GameSettings::BATTLE_INVENTORY_XC + GameSettings::BATTLE_INVENTORY_XF * position, GameSettings::BATTLE_INVENTORY_YC + GameSettings::BATTLE_INVENTORY_YF * position]
end
offset
end
Expand Down
2 changes: 1 addition & 1 deletion lib/battle/battle_readiness_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def initialize(starting_points, growth_rate)
@starting_points = starting_points
@points = starting_points
@growth_rate = growth_rate
@points_needed_for_ready = @@READINESS_POINTS_NEEDED_TO_ACT
@points_needed_for_ready = GameSettings::READINESS_POINTS_NEEDED_TO_ACT
end

def add_readiness(points)
Expand Down
8 changes: 4 additions & 4 deletions lib/factories/game_internals_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def make_event_manager

def make_screen
#@screen = Screen.open( [640, 480] )
screen = ScreenFacade.new([@@SCREEN_X, @@SCREEN_Y])
screen.title = @@GAME_TITLE
screen = ScreenFacade.new([GameSettings::SCREEN_X, GameSettings::SCREEN_Y])
screen.title = GameSettings::GAME_TITLE
screen
end
def make_clock
Expand Down Expand Up @@ -56,7 +56,7 @@ def make_attribution
CharacterAttributionFactory.new.make_attribution
end

def make_hero(name, weapon, default_start_pts=@@HERO_START_BATTLE_PTS, default_rate=@@HERO_BATTLE_PTS_RATE, attr=make_attribution)
def make_hero(name, weapon, default_start_pts=GameSettings::HERO_START_BATTLE_PTS, default_rate=GameSettings::HERO_BATTLE_PTS_RATE, attr=make_attribution)
Hero.new(name, weapon, default_start_pts, default_rate, attr)
end

Expand All @@ -83,7 +83,7 @@ def make_player(screen, universe, game)
end

def make_world(bg_filename, inter_filename, pal, inter_pal, bgm)
WorldStateFactory.build_world_state(bg_filename,inter_filename, pal, inter_pal, @@BGX, @@BGY, [], bgm)
WorldStateFactory.build_world_state(bg_filename,inter_filename, pal, inter_pal, GameSettings::BGX, GameSettings::BGY, [], bgm)
end

def make_world1
Expand Down
2 changes: 1 addition & 1 deletion lib/factories/monster_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def make_monster(player,universe)
monattrib = CharacterAttributionFactory.new.make_attribution(CharacterAttributes.new(3, 0, 1, 0, 0, 0, 0, 0))
monai = ArtificialIntelligence.new(RepeatingPathFollower.new("DRUL", 80), BattleStrategy.new([BattleTactic.new("Enemy: Any -> Attack")]))

posn = PositionedTileCoordinate.new(SdlCoordinate.new(400, 660), SdlCoordinate.new(@@MONSTER_X, @@MONSTER_Y))
posn = PositionedTileCoordinate.new(SdlCoordinate.new(400, 660), SdlCoordinate.new(GameSettings::MONSTER_X, GameSettings::MONSTER_Y))
Monster.new(player,universe,"monster.png", posn, monster_inv, monattrib, monai)
end
end
117 changes: 72 additions & 45 deletions lib/game_settings.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,75 @@
# To change this template, choose Tools | Templates
# and open the template in the editor.
module GameSettings


@@SCREEN_X = 640
@@SCREEN_Y = 480
@@BGX = 1280
@@BGY = 960
@@MENU_LAYER_INSET = 25
@@MENU_TEXT_INSET = 10
@@NOTIFICATION_TEXT_INSET = 10
@@MENU_LINE_SPACING = 25
@@NOTIFICATION_LINE_SPACING = 25
@@MENU_TEXT_WIDTH = 100
@@LAYER_INSET = 25
@@TEXT_INSET = 10
@@HERO_START_BATTLE_PTS = 1000
@@HERO_BATTLE_PTS_RATE = 1.1
@@MONSTER_START_BATTLE_PTS = 800
@@MONSTER_BATTLE_PTS_RATE = 1.0
@@READINESS_POINTS_PER_SECOND = 1000
@@READINESS_POINTS_NEEDED_TO_ACT = 3000
@@DEFAULT_ACTION_COST = 2500
@@ATTACK_ACTION_COST = 2000
@@ITEM_ACTION_COST = 1500
@@NOOP_ACTION_COST = 1000

@@OPEN_TREASURE = 'O'
@@MONSTER_X = 32
@@MONSTER_Y = 32
@@NOTIFICATION_LAYER_WIDTH = @@SCREEN_X/3
@@NOTIFICATION_LAYER_HEIGHT = @@SCREEN_Y/3
@@NOTIFICATION_LAYER_INSET_X = 2 * @@SCREEN_X/3
@@NOTIFICATION_LAYER_INSET_Y = 2 * @@SCREEN_Y/3
@@TICKS_TO_DISPLAY_NOTIFICATIONS = 125
@@GAME_TITLE = "splatwars"

@@STATUS_WIDTH = 100
@@STATUS_HEIGHT = 300
@@MENU_DETAILS_INSET_X = 300
@@MENU_DETAILS_INSET_Y = 25
@@MENU_OPTIONS_INSET_X = 400
@@MENU_OPTIONS_INSET_Y = 25


@@BATTLE_INVENTORY_XC = 400
@@BATTLE_INVENTORY_XF = 0
@@BATTLE_INVENTORY_YC = 25
@@BATTLE_INVENTORY_YF = 25
SCREEN_X = 640
SCREEN_Y = 480
BGX = 1280
BGY = 960
MENU_LAYER_INSET = 25
MENU_TEXT_INSET = 10
NOTIFICATION_TEXT_INSET = 10
MENU_LINE_SPACING = 25
NOTIFICATION_LINE_SPACING = 25
MENU_TEXT_WIDTH = 100
LAYER_INSET = 25
TEXT_INSET = 10
HERO_START_BATTLE_PTS = 1000
HERO_BATTLE_PTS_RATE = 1.1
MONSTER_START_BATTLE_PTS = 800
MONSTER_BATTLE_PTS_RATE = 1.0
READINESS_POINTS_PER_SECOND = 1000
READINESS_POINTS_NEEDED_TO_ACT = 3000
DEFAULT_ACTION_COST = 2500
ATTACK_ACTION_COST = 2000
ITEM_ACTION_COST = 1500
NOOP_ACTION_COST = 1000

OPEN_TREASURE = 'O'
MONSTER_X = 32
MONSTER_Y = 32
NOTIFICATION_LAYER_WIDTH = SCREEN_X/3
NOTIFICATION_LAYER_HEIGHT = SCREEN_Y/3
NOTIFICATION_LAYER_INSET_X = 2 * SCREEN_X/3
NOTIFICATION_LAYER_INSET_Y = 2 * SCREEN_Y/3
TICKS_TO_DISPLAY_NOTIFICATIONS = 125
GAME_TITLE = "splatwars"

STATUS_WIDTH = 100
STATUS_HEIGHT = 300
MENU_DETAILS_INSET_X = 300
MENU_DETAILS_INSET_Y = 25
MENU_OPTIONS_INSET_X = 400
MENU_OPTIONS_INSET_Y = 25


BATTLE_INVENTORY_XC = 400
BATTLE_INVENTORY_XF = 0
BATTLE_INVENTORY_YC = 25
BATTLE_INVENTORY_YF = 25
DOWNKEY = :always_down

WEAPON_UP_OFFSET_X = -15
WEAPON_UP_OFFSET_Y = -45
WEAPON_DOWN_OFFSET_X = -15
WEAPON_DOWN_OFFSET_Y = 20
WEAPON_LEFT_OFFSET_X = -45
WEAPON_LEFT_OFFSET_Y = -15
WEAPON_RIGHT_OFFSET_X = 0
WEAPON_RIGHT_OFFSET_Y = -10
WEAPON_UP_ANGLE = 270
WEAPON_DOWN_ANGLE = 120
WEAPON_LEFT_ANGLE = -10
WEAPON_RIGHT_ANGLE = 180
WEAPON_ROTATION = 90
NUM_SLOTS = 5
FONT_DEPTH = 24
MS_PER_SEC = 1000
INTERACTION_DISTANCE_THRESHOLD = 80 #XXX tweak this, currently set to 1/2 a tile


FRAME_SWITCH_THRESHOLD = 0.40
ANIMATION_FRAMES = 4

end
6 changes: 2 additions & 4 deletions lib/helpers/animation_helper.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@

class AnimationHelper
@@FRAME_SWITCH_THRESHOLD = 0.40
@@ANIMATION_FRAMES = 4

def current_frame
@animation_frame
end

def initialize(key_holder, animation_frames=@@ANIMATION_FRAMES)
def initialize(key_holder, animation_frames=GameSettings::ANIMATION_FRAMES)
@key_holder = key_holder
@animation_counter = 0
@animation_frame = 0
@animation_frames = animation_frames
end
def update_animation(dt)
@animation_counter += dt
if @animation_counter > @@FRAME_SWITCH_THRESHOLD
if @animation_counter > GameSettings::FRAME_SWITCH_THRESHOLD
@animation_counter = 0
unless @key_holder.empty?
@animation_frame = (@animation_frame + 1) % @animation_frames
Expand Down
3 changes: 1 addition & 2 deletions lib/helpers/resource_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ class MissingResourceError < RuntimeError
end

module ResourceLoader
@@FONT_DEPTH = 24

def resource_path(elem)
File.join(Dir.pwd, 'resources', elem)
Expand All @@ -12,7 +11,7 @@ def font_path
resource_path('fonts')
end
def load_font(name)
FontFacade.new(check_file(font_path, name), @@FONT_DEPTH)
FontFacade.new(check_file(font_path, name), GameSettings::FONT_DEPTH)
end

def surface_path
Expand Down
4 changes: 2 additions & 2 deletions lib/input/key_holder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize
end


@@MS_PER_SEC = 1000

extend Forwardable
def_delegators :@keys, :include?, :empty?, :size

Expand Down Expand Up @@ -45,7 +45,7 @@ def update_timed_keys(dt)
end
}
@ms_ttl_map.each {|k,v|
newv = v - dt * @@MS_PER_SEC
newv = v - dt * GameSettings::MS_PER_SEC
if newv <= 0
delete_key(k)
@ms_ttl_map.delete(k)
Expand Down
2 changes: 1 addition & 1 deletion lib/interactables/treasure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize(name)

def activate(game, player, worldstate, tilex, tiley)
game.universe.play_sound_effect(SoundEffect::TREASURE)
worldstate.update_interaction_map(tilex, tiley, @@OPEN_TREASURE)
worldstate.update_interaction_map(tilex, tiley, GameSettings::OPEN_TREASURE)
player.add_inventory(1, @name)
game.add_notification(WorldScreenNotification.new("Got #{@name}"))
end
Expand Down
26 changes: 13 additions & 13 deletions lib/layers/battle_layer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,32 @@ def end_battle
@battle.end_battle
end
def battle_text_config_with_actions(actions)
BattleParticipantCursorTextRenderingConfig.new(actions , 2 * @@MENU_TEXT_INSET + 4*@@MENU_TEXT_WIDTH, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
BattleParticipantCursorTextRenderingConfig.new(actions , 2 * GameSettings::MENU_TEXT_INSET + 4*GameSettings::MENU_TEXT_WIDTH, 0, GameSettings::MENU_TEXT_INSET, GameSettings::MENU_LINE_SPACING)
end

def menu_layer_config

mlc = MenuLayerConfig.new
mlc.main_menu_text = TextRenderingConfig.new(@@MENU_TEXT_INSET, @@MENU_TEXT_WIDTH, @layer.h - 125, 0)
mlc.section_menu_text = TextRenderingConfig.new(@@MENU_TEXT_INSET, @@MENU_TEXT_WIDTH, @layer.h - 150, 0)
mlc.in_section_cursor = TextRenderingConfig.new(@@MENU_TEXT_INSET , @@MENU_TEXT_WIDTH, @layer.h - 175, 0)
mlc.main_menu_text = TextRenderingConfig.new(GameSettings::MENU_TEXT_INSET, GameSettings::MENU_TEXT_WIDTH, @layer.h - 125, 0)
mlc.section_menu_text = TextRenderingConfig.new(GameSettings::MENU_TEXT_INSET, GameSettings::MENU_TEXT_WIDTH, @layer.h - 150, 0)
mlc.in_section_cursor = TextRenderingConfig.new(GameSettings::MENU_TEXT_INSET , GameSettings::MENU_TEXT_WIDTH, @layer.h - 175, 0)
mlc.in_subsection_cursor = battle_text_config_with_actions([AttackBattleMenuAction])
mlc.in_option_section_cursor = battle_text_config_with_actions([UseBattleItemBattleMenuAction])
mlc.main_cursor = TextRenderingConfig.new(@@MENU_TEXT_INSET , @@MENU_TEXT_WIDTH, @layer.h - 100, 0)
mlc.layer_inset_on_screen = [@@LAYER_INSET,@@LAYER_INSET]
mlc.details_inset_on_layer = [@@MENU_DETAILS_INSET_X, @@MENU_DETAILS_INSET_Y]
mlc.options_inset_on_layer = [@@MENU_OPTIONS_INSET_X, @@MENU_OPTIONS_INSET_Y]
mlc.main_cursor = TextRenderingConfig.new(GameSettings::MENU_TEXT_INSET , GameSettings::MENU_TEXT_WIDTH, @layer.h - 100, 0)
mlc.layer_inset_on_screen = [GameSettings::LAYER_INSET,GameSettings::LAYER_INSET]
mlc.details_inset_on_layer = [GameSettings::MENU_DETAILS_INSET_X, GameSettings::MENU_DETAILS_INSET_Y]
mlc.options_inset_on_layer = [GameSettings::MENU_OPTIONS_INSET_X, GameSettings::MENU_OPTIONS_INSET_Y]

mlc
end
def end_battle_menu_layer_config

mlc = MenuLayerConfig.new
mlc.main_menu_text = TextRenderingConfig.new(@@MENU_TEXT_INSET, @@MENU_TEXT_WIDTH, 50, 0)
mlc.section_menu_text = TextRenderingConfig.new(@@MENU_TEXT_INSET, @@MENU_TEXT_WIDTH, 150, 0)
mlc.in_section_cursor = TextRenderingConfig.new(@@MENU_TEXT_INSET , @@MENU_TEXT_WIDTH,200, 0)
mlc.main_cursor = TextRenderingConfig.new(@@MENU_TEXT_INSET , @@MENU_TEXT_WIDTH,100, 0)
mlc.layer_inset_on_screen = [@@LAYER_INSET,@@LAYER_INSET]
mlc.main_menu_text = TextRenderingConfig.new(GameSettings::MENU_TEXT_INSET, GameSettings::MENU_TEXT_WIDTH, 50, 0)
mlc.section_menu_text = TextRenderingConfig.new(GameSettings::MENU_TEXT_INSET, GameSettings::MENU_TEXT_WIDTH, 150, 0)
mlc.in_section_cursor = TextRenderingConfig.new(GameSettings::MENU_TEXT_INSET , GameSettings::MENU_TEXT_WIDTH,200, 0)
mlc.main_cursor = TextRenderingConfig.new(GameSettings::MENU_TEXT_INSET , GameSettings::MENU_TEXT_WIDTH,100, 0)
mlc.layer_inset_on_screen = [GameSettings::LAYER_INSET,GameSettings::LAYER_INSET]
mlc
end

Expand Down
6 changes: 3 additions & 3 deletions lib/layers/dialog_layer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class DialogLayer < AbstractLayer
attr_accessor :visible, :text

def initialize(screen, game)
super(screen, screen.w/2 - @@LAYER_INSET, screen.h/2 - @@LAYER_INSET)
super(screen, screen.w/2 - GameSettings::LAYER_INSET, screen.h/2 - GameSettings::LAYER_INSET)
@layer.fill(:red)
@layer.alpha = 192
@text = "UNSET"
Expand All @@ -15,8 +15,8 @@ def toggle_visibility

def draw
text_surface = @font.render @text.to_s, true, [16,222,16]
text_surface.blit @layer, [@@TEXT_INSET,@@TEXT_INSET]
@layer.blit(@screen, [@@LAYER_INSET,@@LAYER_INSET])
text_surface.blit @layer, [GameSettings::TEXT_INSET,GameSettings::TEXT_INSET]
@layer.blit(@screen, [GameSettings::LAYER_INSET,GameSettings::LAYER_INSET])
end

def displayed
Expand Down
22 changes: 11 additions & 11 deletions lib/layers/menu_layer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ class MenuLayer < AbstractLayer
attr_reader :text_rendering_helper
attr_accessor :cursor_helper, :layer
def initialize(screen, game)
super(screen, (screen.w) - 2*@@MENU_LAYER_INSET, (screen.h) - 2*@@MENU_LAYER_INSET)
super(screen, (screen.w) - 2*GameSettings::MENU_LAYER_INSET, (screen.h) - 2*GameSettings::MENU_LAYER_INSET)
@layer.fill(:red)
@layer.alpha = 192
@game = game
@cursor_helper = CursorHelper.new(cursor_dims)
# @menu_helper = MenuHelper.new(screen, @layer, @text_rendering_helper, [], @@MENU_LINE_SPACING,@@MENU_LINE_SPACING)
# @menu_helper = MenuHelper.new(screen, @layer, @text_rendering_helper, [], GameSettings::MENU_LINE_SPACING,GameSettings::MENU_LINE_SPACING)

end



def cursor_dims
[@@MENU_LINE_SPACING,@@MENU_LINE_SPACING]
[GameSettings::MENU_LINE_SPACING,GameSettings::MENU_LINE_SPACING]
end

def rebuild_menu
Expand Down Expand Up @@ -65,21 +65,21 @@ def current_menu_entries(e=nil)
end

def section_text_rendering_config(depth)
TextRenderingConfig.new(2 * @@MENU_TEXT_INSET + 4*@@MENU_TEXT_WIDTH, 0, depth * @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
TextRenderingConfig.new(2 * GameSettings::MENU_TEXT_INSET + 4*GameSettings::MENU_TEXT_WIDTH, 0, depth * GameSettings::MENU_TEXT_INSET, GameSettings::MENU_LINE_SPACING)
end

def menu_layer_config

mlc = MenuLayerConfig.new
mlc.main_menu_text = TextRenderingConfig.new(@@MENU_TEXT_INSET, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
mlc.section_menu_text = TextRenderingConfig.new(3 * @@MENU_TEXT_INSET + @@MENU_TEXT_WIDTH + @@MENU_LINE_SPACING, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
mlc.main_menu_text = TextRenderingConfig.new(GameSettings::MENU_TEXT_INSET, 0, GameSettings::MENU_TEXT_INSET, GameSettings::MENU_LINE_SPACING)
mlc.section_menu_text = TextRenderingConfig.new(3 * GameSettings::MENU_TEXT_INSET + GameSettings::MENU_TEXT_WIDTH + GameSettings::MENU_LINE_SPACING, 0, GameSettings::MENU_TEXT_INSET, GameSettings::MENU_LINE_SPACING)
mlc.in_subsection_cursor = section_text_rendering_config(2)
mlc.in_option_section_cursor = section_text_rendering_config(3)
mlc.in_section_cursor = TextRenderingConfig.new(2 * @@MENU_TEXT_INSET + 4*@@MENU_TEXT_WIDTH, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
mlc.main_cursor = TextRenderingConfig.new(2 * @@MENU_TEXT_INSET + @@MENU_TEXT_WIDTH, 0, @@MENU_TEXT_INSET, @@MENU_LINE_SPACING)
mlc.layer_inset_on_screen = [@@MENU_LAYER_INSET,@@MENU_LAYER_INSET]
mlc.details_inset_on_layer = [@@MENU_DETAILS_INSET_X, @@MENU_DETAILS_INSET_Y]
mlc.options_inset_on_layer = [@@MENU_OPTIONS_INSET_X, @@MENU_OPTIONS_INSET_Y]
mlc.in_section_cursor = TextRenderingConfig.new(2 * GameSettings::MENU_TEXT_INSET + 4*GameSettings::MENU_TEXT_WIDTH, 0, GameSettings::MENU_TEXT_INSET, GameSettings::MENU_LINE_SPACING)
mlc.main_cursor = TextRenderingConfig.new(2 * GameSettings::MENU_TEXT_INSET + GameSettings::MENU_TEXT_WIDTH, 0, GameSettings::MENU_TEXT_INSET, GameSettings::MENU_LINE_SPACING)
mlc.layer_inset_on_screen = [GameSettings::MENU_LAYER_INSET,GameSettings::MENU_LAYER_INSET]
mlc.details_inset_on_layer = [GameSettings::MENU_DETAILS_INSET_X, GameSettings::MENU_DETAILS_INSET_Y]
mlc.options_inset_on_layer = [GameSettings::MENU_OPTIONS_INSET_X, GameSettings::MENU_OPTIONS_INSET_Y]
mlc
end

Expand Down
Loading

0 comments on commit e30111a

Please sign in to comment.