Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Spooner/ruby_armor
base: ec5ae902ee
...
head fork: Spooner/ruby_armor
compare: aec08f53fe
  • 3 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
2  lib/ruby_armor.rb
@@ -15,11 +15,13 @@
require "ruby_armor/ruby_warrior_ext/position"
require "ruby_armor/ruby_warrior_ext/ui"
+require "ruby_armor/ruby_warrior_ext/player_generator"
require "ruby_armor/ruby_warrior_ext/units/base"
require "ruby_armor/ruby_warrior_ext/abilities/rest"
require "ruby_armor/floating_text"
require "ruby_armor/sprite_sheet"
+require "ruby_armor/states/create_profile"
require "ruby_armor/states/choose_profile"
require "ruby_armor/states/play"
require "ruby_armor/states/review_code"
View
17 lib/ruby_armor/ruby_warrior_ext/player_generator.rb
@@ -0,0 +1,17 @@
+module RubyWarrior
+ class PlayerGenerator
+ def generate
+ if level.number == 1
+ FileUtils.mkdir_p(level.player_path)
+ # Read and write, so that line-endings are correct for the OS.
+ File.open(level.player_path + '/player.rb', "w") do |f|
+ f.write File.read(templates_path + '/player.rb')
+ end
+ end
+
+ File.open(level.player_path + '/README', 'w') do |f|
+ f.write read_template(templates_path + '/README.erb')
+ end
+ end
+ end
+end
View
63 lib/ruby_armor/states/choose_profile.rb
@@ -1,23 +1,21 @@
module RubyArmor
class ChooseProfile < Fidgit::GuiState
- DEFAULT_WARRIOR_CLASS = :valkyrie
-
def setup
super
+ on_input :escape, :hide
+
# Create the game.
@game = RubyWarrior::Game.new
warrior_sprites = SpriteSheet.new "warriors.png", Play::SPRITE_WIDTH, Play::SPRITE_HEIGHT, 4
- vertical align_h: :center, spacing: 40 do
- vertical align: :center, padding: 0 do
- label "RubyArmor", align: :center, font_height: 80, padding_top: 50
- label "by Spooner", align: :center, font_height: 12
+ vertical align_h: :center, spacing: 30 do
+ vertical align: :center, padding_top: 30, padding: 0 do
+ label "ryanb's RubyWarrior is wearing Spooner's", align: :center, font_height: 12
+ label "RubyArmor", align: :center, font_height: 80
end
- button_options = { width: 400, align: :center, justify: :center }
-
# Use existing profile.
vertical padding: 0, align_h: :center do
scroll_window height: 250, width: 460 do
@@ -29,8 +27,8 @@ def setup
tip = "Play as #{profile.warrior_name} the #{config.warrior_class.capitalize} - #{profile.tower.name} - level #{name_of_level} - score #{profile.score}"
# Can be disabled because of a bug in RubyWarrior paths.
- button title, button_options.merge(tip: tip, enabled: File.directory?(profile.tower_path),
- icon: warrior_sprites[0, Play::WARRIORS[config.warrior_class]], icon_options: { factor: 2 }) do
+ button title, width: 400, tip: tip, enabled: File.directory?(profile.tower_path),
+ icon: warrior_sprites[0, Play::WARRIORS[config.warrior_class]], icon_options: { factor: 2 } do
play profile, config
end
end
@@ -38,42 +36,18 @@ def setup
end
# Option to create a new profile.
- vertical padding: 0, align: :center do
- horizontal align: :center, padding: 0 do
- @new_name = text_area width: 300, height: 30, font_height: 20 do |_, text|
- duplicate = @game.profiles.any? {|p| p.warrior_name.downcase == text.downcase }
- @new_profile_button.enabled = !(text.empty? or duplicate)
- end
-
- @new_profile_button = button "New", button_options.merge(width: 90, tip: "Create a new profile") do
- play *new_profile(@new_name.text)
- end
-
- new_name = File.basename File.expand_path("~")
- new_name = "Player" if new_name.empty?
- @new_name.text = new_name
+ horizontal align: :center do
+ button "Create new profile", shortcut: :auto, shortcut_color: Play::SHORTCUT_COLOR do
+ CreateProfile.new(@game, warrior_sprites).show
end
- # Choose class; just cosmetic.
- @warrior_class = group align_h: :center do
- horizontal padding: 0, align_h: :center do
- Play::WARRIORS.each do |warrior, row|
- radio_button "", warrior, tip: "Play as a #{warrior.capitalize} (The difference between classes is purely cosmetic!)",
- :icon => warrior_sprites[0, row], :icon_options => { :factor => 4 }
- end
- end
+ button "Exit", shortcut: :x, shortcut_color: Play::SHORTCUT_COLOR do
+ exit!
end
-
- @warrior_class.value = DEFAULT_WARRIOR_CLASS
end
end
end
- def update
- super
- @new_name.focus self unless @new_name.focused?
- end
-
def finalize
super
container.clear
@@ -83,16 +57,5 @@ def play(profile, config)
@game.instance_variable_set :@profile, profile
push_game_state Play.new(@game, config)
end
-
- def new_profile(name)
- new_profile = RubyWarrior::Profile.new
- new_profile.tower_path = @game.towers[0].path
- new_profile.warrior_name = name
-
- config = WarriorConfig.new new_profile
- config.warrior_class = @warrior_class.value
-
- [new_profile, config]
- end
end
end
View
79 lib/ruby_armor/states/create_profile.rb
@@ -0,0 +1,79 @@
+module RubyArmor
+ class CreateProfile < Fidgit::DialogState
+ DEFAULT_WARRIOR_CLASS = :valkyrie
+
+ def initialize(game, warrior_sprites)
+ @game = game
+
+ super shadow_full: true
+
+ on_input :escape, :hide
+ on_input [:return, :enter] do
+ @new_profile_button.activate if @new_profile_button.enabled?
+ end
+
+ # Option to create a new profile.
+ vertical align: :center, border_thickness: 4, background_color: Color::BLACK do
+ label "Create new profile", font_height: 20
+
+ @new_name = text_area width: 300, height: 30, font_height: 20 do |_, text|
+ duplicate = @game.profiles.any? {|p| p.warrior_name.downcase == text.downcase }
+ @new_profile_button.enabled = !(text.empty? or duplicate)
+ end
+
+ # Choose class; just cosmetic.
+ @warrior_class = group align_h: :center do
+ horizontal padding: 0, align_h: :center do
+ Play::WARRIORS.each do |warrior, row|
+ radio_button "", warrior, tip: "Play as a #{warrior.capitalize} (The difference between classes is purely cosmetic!)",
+ :icon => warrior_sprites[0, row], :icon_options => { :factor => 4 }
+ end
+ end
+ end
+
+ horizontal align: :center do
+ button "Cancel" do
+ hide
+ end
+
+ @new_profile_button = button "Create", justify: :center, tip: "Create a new profile" do
+ play *new_profile(@new_name.text)
+ end
+ end
+
+ new_name = File.basename File.expand_path("~")
+ new_name = "Player" if new_name.empty?
+ @new_name.text = new_name
+
+ @warrior_class.value = DEFAULT_WARRIOR_CLASS
+ end
+ end
+
+ def update
+ super
+ @new_name.focus self unless @new_name.focused?
+ end
+
+ def finalize
+ super
+ container.clear
+ end
+
+ def play(profile, config)
+ @game.instance_variable_set :@profile, profile
+ hide
+ push_game_state Play.new(@game, config)
+ end
+
+ def new_profile(name)
+ new_profile = RubyWarrior::Profile.new
+ new_profile.tower_path = @game.towers[0].path
+ new_profile.warrior_name = name
+
+ config = WarriorConfig.new new_profile
+ config.warrior_class = @warrior_class.value
+
+ [new_profile, config]
+ end
+ end
+end
View
18 lib/ruby_armor/states/play.rb
@@ -14,6 +14,8 @@ class Play < Fidgit::GuiState
SHORTCUT_COLOR = Color.rgb(175, 255, 100)
+ FILE_SYNC_DELAY = 0.5 # 2 polls per second.
+
# Sprites to show based on player facing.
FACINGS = {
:east => 0,
@@ -392,7 +394,8 @@ def prepare_level
def create_sync_timer
stop_timer :refresh_code
friendly_line_endings = false
- every(100, :name => :refresh_code) do
+
+ every(FILE_SYNC_DELAY * 1000, :name => :refresh_code) do
begin
player_file = File.join level.player_path, "player.rb"
player_code = File.read player_file
@@ -401,18 +404,6 @@ def create_sync_timer
unless @loaded_code == stripped_code
$stdout.puts "Detected change in player.rb"
- # Rewrite file as Windows text file if it is the default (a unix file).
- # If the file loaded in binary == the code loaded as text, then the file
- # must have Unix endings (\n => same as a text file in memory) rather than
- # Windows endings (\r\n => different than text file in memory).
- if !friendly_line_endings and Gem.win_platform? and
- (File.open(player_file, "rb", &:read).strip == stripped_code)
-
- File.open(player_file, "w") {|f| f.puts player_code }
- $stdout.puts "Converted to Windows line endings: #{player_file}"
- end
- friendly_line_endings = true # Either will have or don't need to.
-
@file_contents["player.rb"].text = stripped_code
@loaded_code = stripped_code
prepare_level
@@ -514,6 +505,7 @@ def play_turn
refresh_labels
if level.passed?
+ stop_timer :refresh_code # Don't sync after successful completion, unless reset.
@reset_button.enabled = false if profile.epic? # Continue will save performance; reset won't.
@continue_button.enabled = true
View
6 lib/ruby_armor/states/review_code.rb
@@ -16,9 +16,11 @@ def saved_levels?(profile)
def initialize(profile)
super(shadow_full: true)
+ on_input :escape, :hide
+
@profile = profile
- vertical spacing: 10, align: :center, background_color: Color::BLACK do
+ vertical spacing: 10, align: :center, border_thickness: 4, background_color: Color::BLACK do
label "Reviewing code that completed levels in #{profile.tower.name} tower", font_height: 20
@tab_group = group do
@@ -57,7 +59,7 @@ def initialize(profile)
end
end
- button "Close", shortcut: :escape, align_h: :center, border_thickness: 0 do
+ button "Close", shortcut: :auto, shortcut_color: Play::SHORTCUT_COLOR, align_h: :center, border_thickness: 0 do
hide
end

No commit comments for this range

Something went wrong with that request. Please try again.