Permalink
Browse files

made flog happy

  • Loading branch information...
1 parent 77fe8ee commit 2e6f63a458a0e16127155a3877e17d91fef49232 @bgoodspeed committed Nov 12, 2010
Showing with 93 additions and 52 deletions.
  1. +25 −13 lib/battle/battle_hud.rb
  2. +15 −16 lib/domain/game.rb
  3. +23 −11 lib/layers/battle_layer.rb
  4. +30 −12 lib/tile_system/interaction_helper.rb
@@ -11,24 +11,36 @@ def map_to_colors(rate)
1.upto(10).collect {|i| i <= r ? :blue : :red }
end
+ def fill_in_sub(s, sub, color, hi, idx, ready_colors)
+ sub.fill(color)
+ sub.blit(s, [hi * 100 + idx * 10, 5])
+ sub.fill(ready_colors[idx])
+ sub.blit(s, [hi * 100 + idx * 10, 25])
+ end
+
+ def health_rates(heroes)
+ heroes.collect {|h| h.hp_ratio * 10}
+ end
+ def ready_rates(heroes)
+ heroes.collect {|h| h.ready_ratio * 10}
+ end
+
+ def build_sub(s,hr,hi,heroes)
+ sub = @surface_factory.make_surface([10, 10])
+ colors = map_to_colors(hr)
+ ready_colors = map_to_colors(ready_rates(heroes)[hi])
+ colors.each_with_index do |color, idx|
+ fill_in_sub(s, sub, color, hi, idx, ready_colors)
+ end
+ end
+
def draw(menu_layer_config, game, battle)
heroes = battle.heroes
- hpr = heroes.collect {|h| h.hp_ratio}
- health_rates = heroes.collect {|h| h.hp_ratio * 10}
- ready_rates = heroes.collect {|h| h.ready_ratio * 10}
s = @surface_factory.make_surface([500, 50])
s.fill(:green)
- health_rates.each_with_index do |hr, hi|
- sub = @surface_factory.make_surface([10, 10])
- colors = map_to_colors(hr)
- ready_colors = map_to_colors(ready_rates[hi])
- colors.each_with_index do |color, idx|
- sub.fill(color)
- sub.blit(s, [hi * 100 + idx * 10, 5])
- sub.fill(ready_colors[idx])
- sub.blit(s, [hi * 100 + idx * 10, 25])
- end
+ health_rates(heroes).each_with_index do |hr, hi|
+ build_sub(s, hr, hi, heroes)
end
s.blit(@screen, [40,400])
View
@@ -19,10 +19,7 @@ def standard_keymap(left, down, right, up, enter, cancel)
key_press_hooks([:left, left], [:down, down], [:right, right], [:up, up], [:i, enter], [:b, cancel])
end
- def initialize(factory=GameInternalsFactory.new, trigger_factory = TriggerFactory.new)
- @factory = factory
- @screen = @factory.make_screen
-
+ def make_domain_data
world1 = @factory.make_world1
world2 = @factory.make_world2
world3 = @factory.make_world3
@@ -32,25 +29,21 @@ def initialize(factory=GameInternalsFactory.new, trigger_factory = TriggerFactor
@player = @factory.make_player(@screen, @universe, self)
world1.add_npc(@factory.make_npc(@player, @universe))
world1.add_npc(@factory.make_monster(@player, @universe))
- @hud = @factory.make_hud(@screen, @player, @universe)
- @trigger_factory = trigger_factory
-
- #TODO FIXMENOW TODOFIXMENOW
-# QuitRequestedFacade.quit_request_type => :quit, #TODO i'd rather not see direct references to facade objects, hide in a factory
-
+ end
- always_on_keymap = key_press_hooks( [:escape, :quit], [ :q, :quit],
+ def make_hook_and_event_bindings
+ always_on_keymap = key_press_hooks( [:escape, :quit], [ :q, :quit],
[ :c, :capture_ss], [ :d, :toggle_dialog_layer], [ :m, :toggle_menu], [ :p, :pause]
)
-
+
menu_killed_hooks = key_press_hooks( [ :i, :interact_with_facing],
[ :space, :use_weapon], [ :b, :toggle_bg_music]
)
menu_active_hooks = standard_keymap(:menu_left, :menu_down, :menu_right, :menu_up, :menu_enter, :menu_cancel)
battle_hooks = standard_keymap(:battle_left, :battle_down, :battle_right, :battle_up, :battle_enter, :battle_cancel)
-
+
battle_layer_hooks = [
event_hook(battle_layer, :tick, :update)
]
@@ -69,10 +62,16 @@ def initialize(factory=GameInternalsFactory.new, trigger_factory = TriggerFactor
@event_manager = @factory.make_event_manager
@event_system = @factory.make_event_system(self, always_on_keymap, menu_killed_hooks, menu_active_hooks, battle_hooks, battle_layer_hooks, player_hooks, npc_hooks)
-# @event_helper = @factory.make_event_hooks(self, always_on_hooks, menu_killed_hooks, menu_active_hooks, battle_hooks)
-# @clock = @factory.make_clock
-# @queue = @factory.make_queue
+ end
+
+ def initialize(factory=GameInternalsFactory.new, trigger_factory = TriggerFactory.new)
+ @factory = factory
+ @screen = @factory.make_screen
+ make_domain_data
+ @hud = @factory.make_hud(@screen, @player, @universe)
+ @trigger_factory = trigger_factory
+ make_hook_and_event_bindings
end
def go
@@ -72,21 +72,33 @@ def end_battle_menu_layer_config
mlc
end
- def draw()
- @layer.fill(:orange)
+ def draw_regular_battle
+ @battle.monster.draw_to(@layer)
+ rebuild_menu
+ menu.draw(menu_layer_config, @cursor_helper.path, @cursor_helper.currently_selected)
+ end
+
+
+ def draw_battle_over
+ if @battle.player_alive?
+ @end_menu.draw(end_battle_menu_layer_config, @cursor_helper.path, @cursor_helper.currently_selected)
+ else
+ puts "you died ... game should be over... whatever"
+ @end_menu.draw(end_battle_menu_layer_config,@cursor_helper.path, @cursor_helper.currently_selected)
+ end
+ end
+
+ def draw_battle
if @battle.over?
- if @battle.player_alive?
- @end_menu.draw(end_battle_menu_layer_config, @cursor_helper.path, @cursor_helper.currently_selected)
- else
- puts "you died ... game should be over... whatever"
- @end_menu.draw(end_battle_menu_layer_config,@cursor_helper.path, @cursor_helper.currently_selected)
- end
+ draw_battle_over
else
- @battle.monster.draw_to(@layer)
- rebuild_menu
- menu.draw(menu_layer_config, @cursor_helper.path, @cursor_helper.currently_selected)
+ draw_regular_battle
end
+ end
+ def draw()
+ @layer.fill(:orange)
+ draw_battle
@cursor_helper.draw_at_depth(@layer, menu_layer_config, @game, nil)
@layer.blit(@screen, menu_layer_config.layer_inset_on_screen)
@battle_hud.draw(menu_layer_config, @game, @battle) unless @battle.over?
@@ -40,16 +40,21 @@ def facing_tiley_for(tile)
calculate_facing([:left, :right], [:up], tile)
end
+ def abs_dist(a,b)
+ (a - b).abs
+ end
+
def facing_tile_distance_for(game, tilex, tiley, px, py)
- facing_tile_dist = nil
+ interp = game.universe.current_world.interaction_interpreter
+
if @facing == :down
- facing_tile_dist = (game.universe.current_world.interaction_interpreter.top_side(tiley + 1) - py).abs
+ facing_tile_dist = abs_dist(interp.top_side(tiley + 1), py)
elsif @facing == :up
- facing_tile_dist = (game.universe.current_world.interaction_interpreter.bottom_side(tiley - 1) - py).abs
+ facing_tile_dist = abs_dist(interp.bottom_side(tiley - 1), py)
elsif @facing == :left
- facing_tile_dist = (game.universe.current_world.interaction_interpreter.right_side(tilex - 1) - px).abs
+ facing_tile_dist = abs_dist(interp.right_side(tilex - 1), px)
else
- facing_tile_dist = (game.universe.current_world.interaction_interpreter.left_side(tilex + 1) - px).abs
+ facing_tile_dist = abs_dist(interp.left_side(tilex + 1), px)
end
facing_tile_dist
end
@@ -78,28 +83,41 @@ def attempt_interaction_with_npcs(game, npcs)
true
end
- def interact_with_facing(game, px,py)
- puts "mapped key to interaction helper"
- return if attempt_interaction_with_dialog(game.universe.dialog_layer) and @policy.return_after_dialog
+ def handle_dialog(game, px, py)
+ attempt_interaction_with_dialog(game.universe.dialog_layer)
+ end
+ def handle_current_tile(game, px, py)
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
-
- return if attempt_interaction_with_tile(game, tilex, tiley, this_tile_interacts) and @policy.return_after_current
+ attempt_interaction_with_tile(game, tilex, tiley, this_tile_interacts)
+ end
+ def handle_facing_tile(game, px, py)
+ tilex = game.universe.current_world.x_offset_for_interaction(px)
+ tiley = game.universe.current_world.y_offset_for_interaction(py)
facing_tilex = facing_tilex_for(tilex)
facing_tiley = facing_tiley_for(tiley)
facing_tile_dist = facing_tile_distance_for(game, tilex, tiley, px, py)
#puts "i am on #{tilex},#{tiley}, i am facing #{@facing} -> #{facing_tilex}"
facing_tile_interacts = game.universe.current_world.interaction_interpreter.interpret(facing_tilex, facing_tiley)
facing_tile_close_enough = facing_tile_dist < @@INTERACTION_DISTANCE_THRESHOLD
- return if attempt_interaction_with_facing(game, facing_tilex, facing_tiley, facing_tile_interacts, facing_tile_close_enough) and @policy.return_after_facing
-
+ attempt_interaction_with_facing(game, facing_tilex, facing_tiley, facing_tile_interacts, facing_tile_close_enough)
+ end
+
+ def handle_npcs(game, px, py)
interactable_npcs = game.universe.current_world.npcs.select {|npc| npc.nearby?(px,py, @@INTERACTION_DISTANCE_THRESHOLD, @@INTERACTION_DISTANCE_THRESHOLD) }
attempt_interaction_with_npcs(game, interactable_npcs)
+ end
+
+ def interact_with_facing(game, px,py)
+ return if handle_dialog(game, px, py) and @policy.return_after_dialog
+ return if handle_current_tile(game, px, py) and @policy.return_after_current
+ return if handle_facing_tile(game, px, py) and @policy.return_after_facing
+ handle_npcs(game, px, py)
end
end

0 comments on commit 2e6f63a

Please sign in to comment.