Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Got EPIC mode almost entirely working.

  • Loading branch information...
commit 63c815b98c397c60ff0f3f2d60db9d5abc0354a4 1 parent ab0c27a
Bil Bas authored
3  lib/ruby_armor/ruby_warrior_ext/abilities/rest.rb
@@ -5,7 +5,8 @@ class Rest < Base
5 5 def perform
6 6 original = @unit.health
7 7 original_perform
8   - $window.current_game_state.unit_health_changed(@unit, @unit.health - original) if @unit.health > original
  8 + state = $window.game_state_manager.inside_state || $window.current_game_state
  9 + state.unit_health_changed(@unit, @unit.health - original) if @unit.health > original
9 10 end
10 11 end
11 12 end
5 lib/ruby_armor/ruby_warrior_ext/units/base.rb
@@ -3,8 +3,9 @@ module Units
3 3 class Base
4 4 alias_method :original_take_damage, :take_damage
5 5 def take_damage(amount)
6   - $window.current_game_state.unit_health_changed self, -amount
7   - original_take_damage(amount)
  6 + state = $window.game_state_manager.inside_state || $window.current_game_state
  7 + state.unit_health_changed self, -amount
  8 + original_take_damage amount
8 9 end
9 10 end
10 11 end
5 lib/ruby_armor/states/choose_profile.rb
@@ -24,8 +24,9 @@ def setup
24 24 @game.profiles.each do |profile|
25 25 config = WarriorConfig.new profile
26 26
27   - title = "#{profile.warrior_name.ljust(20)} #{profile.tower.name.rjust(12)}:#{profile.level_number} #{profile.score.to_s.rjust(5)}"
28   - tip = "Play as #{profile.warrior_name} the #{config.warrior_class.capitalize} - #{profile.tower.name} - level #{profile.level_number} - score #{profile.score}"
  27 + name_of_level = profile.epic? ? "EPIC" : profile.level_number.to_s
  28 + title = "#{profile.warrior_name.ljust(20)} #{profile.tower.name.rjust(12)}:#{name_of_level[0, 1]} #{profile.score.to_s.rjust(5)}"
  29 + tip = "Play as #{profile.warrior_name} the #{config.warrior_class.capitalize} - #{profile.tower.name} - level #{name_of_level} - score #{profile.score}"
29 30
30 31 # Can be disabled because of a bug in RubyWarrior paths.
31 32 button title, button_options.merge(tip: tip, enabled: File.directory?(profile.tower_path),
98 lib/ruby_armor/states/play.rb
@@ -90,7 +90,7 @@ def setup
90 90 create_ui_bar
91 91 end
92 92
93   - @turn_slider = slider width: 780, range: 0..MAX_TURNS, value: 0, enabled: false, tip: "Turn" do |_, turn|
  93 + @turn_slider = slider width: 774, range: 0..MAX_TURNS, value: 0, enabled: false, tip: "Turn" do |_, turn|
94 94 @log_contents["current turn"].text = replace_log @turn_logs[turn]
95 95 refresh_labels
96 96 end
@@ -102,6 +102,21 @@ def setup
102 102 end
103 103 end
104 104
  105 + # Return to normal mode if extra levels have been added.
  106 + if profile.epic?
  107 + if profile.level_after_epic?
  108 + # TODO: do something with log.
  109 + log = record_log do
  110 + @game.go_back_to_normal_mode
  111 + end
  112 + else
  113 + # TODO: do something with log.
  114 + log = record_log do
  115 + @game.play_epic_mode
  116 + end
  117 + end
  118 + end
  119 +
105 120 prepare_level
106 121 end
107 122
@@ -109,7 +124,7 @@ def create_ui_bar
109 124 vertical padding: 0, height: 260, width: 100, spacing: 6 do
110 125 # Labels at top-right.
111 126 @tower_label = label "", tip: "Each tower has a different difficulty level"
112   - @level_label = label "Level:", tip: "Each tower contains 9 levels"
  127 + @level_label = label "Level:"
113 128 @turn_label = label "Turn:", tip: "Current turn; starvation at #{MAX_TURNS} to avoid endless games"
114 129 @health_label = label "Health:", tip: "The warrior's remaining health; death occurs at 0"
115 130
@@ -126,6 +141,7 @@ def create_ui_bar
126 141 end
127 142
128 143 @reset_button = button "Reset", button_options.merge(tip: "Restart the level") do
  144 + profile.level_number = 0 if profile.epic?
129 145 prepare_level
130 146 end
131 147
@@ -135,11 +151,35 @@ def create_ui_bar
135 151
136 152 @continue_button = button "Continue", button_options.merge(tip: "Climb up the stairs to the next level") do
137 153 # Save the code used to complete the level for posterity.
138   - File.open File.join(profile.player_path, "ruby_armor/player_#{level.number.to_s.rjust(2, '0')}.rb"), "w" do |file|
  154 + File.open File.join(profile.player_path, "ruby_armor/player_#{profile.epic? ? "EPIC" : level.number.to_s.rjust(2, '0')}.rb"), "w" do |file|
139 155 file.puts @loaded_code
  156 +
  157 + file.puts
  158 + file.puts
  159 + file.puts "#" * 40
  160 + file.puts "=begin"
  161 + file.puts
  162 + file.puts record_log { level.tally_points }
  163 + file.puts
  164 +
  165 + if profile.epic? and @game.final_report
  166 + file.puts @game.final_report
  167 + else
  168 + file.puts "Completed in #{turn} turns."
  169 + end
  170 +
  171 + file.puts
  172 + file.puts "=end"
  173 + file.puts "#" * 40
140 174 end
  175 +
141 176 # Move to next level.
142   - @game.prepare_next_level
  177 + if @game.next_level.exists?
  178 + @game.prepare_next_level
  179 + else
  180 + @game.prepare_epic_mode
  181 + end
  182 +
143 183 prepare_level
144 184 end
145 185
@@ -162,7 +202,7 @@ def create_ui_bar
162 202
163 203 # Review old level code.
164 204 @review_button = button "Review", button_options.merge(tip: "Review code used for each level",
165   - enabled: false, border_thickness: 0) do
  205 + enabled: false, border_thickness: 0, shortcut: :v) do
166 206 ReviewCode.new(profile).show
167 207 end
168 208 end
@@ -208,7 +248,7 @@ def create_file_tabs
208 248 @file_tabs_group = group do
209 249 @file_tab_buttons = horizontal padding: 0, spacing: 4 do
210 250 %w[README player.rb].each do |name|
211   - radio_button(name.to_s, name, border_thickness: 0, tip: "View #{name}")
  251 + radio_button(name.to_s, name, border_thickness: 0, tip: "View #{File.join profile.player_path, name}")
212 252 end
213 253
214 254 horizontal padding_left: 50, padding: 0 do
@@ -276,7 +316,7 @@ def create_file_tab_windows
276 316 def prepare_level
277 317 @recorded_log = nil # Not initially logging.
278 318
279   - @log_contents["full log"].text = ""
  319 + @log_contents["full log"].text = "" #unless profile.epic? # TODO: Might need to avoid this, since it could get REALLY long.
280 320 @continue_button.enabled = false
281 321 @hint_button.enabled = false
282 322 @reset_button.enabled = false
@@ -284,7 +324,16 @@ def prepare_level
284 324
285 325 @exception = nil
286 326
287   - @game.prepare_next_level unless profile.current_level.number > 0
  327 + if profile.current_level.number.zero?
  328 + if profile.epic?
  329 + @game.prepare_epic_mode
  330 + profile.level_number += 1
  331 + profile.current_epic_score = 0
  332 + profile.current_epic_grades = {}
  333 + else
  334 + @game.prepare_next_level
  335 + end
  336 + end
288 337
289 338 create_sync_timer
290 339
@@ -306,7 +355,8 @@ def prepare_level
306 355 # Initial log entry.
307 356 self.puts "- turn 0 -"
308 357 self.print floor.character
309   - print "#{profile.warrior_name} climbs up to level #{level.number}\n"
  358 + self.print "#{profile.warrior_name} climbs up to level #{level.number}\n"
  359 + @log_contents["full log"].text += @log_contents["current turn"].text
310 360
311 361 @tile_set = %w[beginner intermediate].index(profile.tower.name) || 2 # We don't know what the last tower will be called.
312 362
@@ -375,7 +425,8 @@ def effective_turn
375 425
376 426 def refresh_labels
377 427 @tower_label.text = profile.tower.name.capitalize
378   - @level_label.text = "Level: #{level.number}"
  428 + @level_label.text = "Level: #{profile.epic? ? "E" : " "}#{level.number}"
  429 + @level_label.tip = profile.epic? ? "Playing in EPIC mode" : "Playing in normal mode"
379 430 @turn_label.text = "Turn: #{effective_turn.to_s.rjust(2)}"
380 431 @health_label.text = "Health: #{@health[effective_turn].to_s.rjust(2)}"
381 432 end
@@ -459,14 +510,31 @@ def play_turn
459 510 refresh_labels
460 511
461 512 if level.passed?
462   - if @game.next_level.exists?
463   - @continue_button.enabled = true
  513 + @continue_button.enabled = true unless profile.epic?
  514 +
  515 + if profile.next_level.exists?
464 516 self.puts "Success! You have found the stairs."
  517 + level.tally_points
  518 +
  519 + if profile.epic?
  520 + # Start the next level immediately.
  521 + self.puts "\n#{"-" * 25}\n"
  522 +
  523 + # Rush onto the next level immediately!
  524 + profile.level_number += 1
  525 + prepare_level
  526 + start_level
  527 + end
465 528 else
466 529 self.puts "CONGRATULATIONS! You have climbed to the top of the tower and rescued the fair maiden Ruby."
  530 + level.tally_points
  531 +
  532 + if profile.epic?
  533 + self.puts @game.final_report if @game.final_report
  534 + profile.save
  535 + end
467 536 end
468 537
469   - level.tally_points
470 538 level_ended
471 539
472 540 elsif level.failed?
@@ -488,6 +556,8 @@ def play_turn
488 556
489 557 # Not necessarily complete; just finished.
490 558 def level_ended
  559 + return if profile.epic?
  560 +
491 561 @hint_button.enabled = true
492 562 @turn_slider.enabled = true
493 563 @turn_slider.instance_variable_set :@range, 0..turn
@@ -605,6 +675,8 @@ def draw_units
605 675 end
606 676
607 677 def unit_health_changed(unit, amount)
  678 + return unless @level_offset_x # Ignore changes out of order, such as between epic levels.
  679 +
608 680 color = (amount > 0) ? Color::GREEN : Color::RED
609 681 y_offset = (amount > 0) ? -0.15 : +0.15
610 682 FloatingText.create "#{amount > 0 ? "+" : ""}#{amount}",
4 lib/ruby_armor/states/review_code.rb
... ... @@ -1,10 +1,10 @@
1 1 module RubyArmor
2 2 class ReviewCode < Fidgit::DialogState
3   - LEVELS = 1..9
  3 + LEVELS = (1..9).to_a + [:EPIC]
4 4
5 5 class << self
6 6 def path_for_level(profile, level)
7   - File.join(profile.player_path, "ruby_armor/player_#{level.to_s.rjust(2, '0')}.rb")
  7 + File.join(profile.player_path, "ruby_armor/player_#{level.is_a?(Symbol) ? level : level.to_s.rjust(2, '0')}.rb")
8 8 end
9 9
10 10 # Check if there are levels saved that can be recalled.

0 comments on commit 63c815b

Please sign in to comment.
Something went wrong with that request. Please try again.