Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* Reorganize WD so it's more sane.

  • Loading branch information...
commit 35a7143657f11b0a928c0ee1e0e00a94d73ec5c6 1 parent dace94c
@stderr authored
Showing with 196 additions and 22 deletions.
  1. +2 −0  Gemfile
  2. +5 −0 Gemfile.lock
  3. +2 −2 README.markdown
  4. +32 −0 Rakefile
  5. +109 −0 bin/warp_defender.rbw
  6. +9 −0 lib/warp_defender.rb
  7. 0  lib/{ → warp_defender}/behaviors/beeline.rb
  8. 0  lib/{ → warp_defender}/behaviors/behavior.rb
  9. 0  lib/{ → warp_defender}/behaviors/hunt.rb
  10. 0  lib/{ → warp_defender}/camera.rb
  11. 0  lib/{ → warp_defender}/entities/entity.rb
  12. 0  lib/{ → warp_defender}/entities/explosion.rb
  13. 0  lib/{ → warp_defender}/entities/grunt.rb
  14. 0  lib/{ → warp_defender}/entities/player.rb
  15. 0  lib/{ → warp_defender}/entities/projectiles/bullet.rb
  16. 0  lib/{ → warp_defender}/entities/projectiles/mine.rb
  17. 0  lib/{ → warp_defender}/entities/projectiles/projectile.rb
  18. 0  lib/{ → warp_defender}/entities/projectiles/rocket.rb
  19. 0  lib/{ → warp_defender}/entities/warp.rb
  20. +35 −18 lib/{ → warp_defender}/game.rb
  21. +1 −1  lib/{ → warp_defender}/game_engine.rb
  22. 0  lib/{ → warp_defender}/game_level.rb
  23. 0  lib/{ → warp_defender}/game_states/credits.rb
  24. 0  lib/{ → warp_defender}/game_states/game_completed.rb
  25. 0  lib/{ → warp_defender}/game_states/game_over.rb
  26. 0  lib/{ → warp_defender}/game_states/game_state.rb
  27. 0  lib/{ → warp_defender}/game_states/level_completed.rb
  28. 0  lib/{ → warp_defender}/game_states/load_level.rb
  29. 0  lib/{ → warp_defender}/game_states/menu/audio.rb
  30. 0  lib/{ → warp_defender}/game_states/menu/base_menu.rb
  31. 0  lib/{ → warp_defender}/game_states/menu/display.rb
  32. 0  lib/{ → warp_defender}/game_states/menu/main_menu.rb
  33. 0  lib/{ → warp_defender}/game_states/menu/options.rb
  34. 0  lib/{ → warp_defender}/game_states/paused.rb
  35. 0  lib/{ → warp_defender}/game_states/playing.rb
  36. 0  lib/{ → warp_defender}/game_states/state_manager.rb
  37. 0  lib/{ → warp_defender}/game_states/transition.rb
  38. 0  lib/{ → warp_defender}/gosu_ext/window.rb
  39. 0  lib/{ → warp_defender}/gui/bar.rb
  40. 0  lib/{ → warp_defender}/gui/base_element.rb
  41. 0  lib/{ → warp_defender}/gui/checkbox.rb
  42. 0  lib/{ → warp_defender}/gui/level_dialog.rb
  43. 0  lib/{ → warp_defender}/gui/menu_dialog.rb
  44. 0  lib/{ → warp_defender}/gui/mini_map.rb
  45. 0  lib/{ → warp_defender}/gui/text.rb
  46. 0  lib/{ → warp_defender}/gui/weapon_display.rb
  47. +1 −1  lib/{ → warp_defender}/input_handler.rb
  48. 0  lib/{ → warp_defender}/physics/collisions.rb
  49. 0  lib/{ → warp_defender}/physics/dynamic.rb
  50. 0  lib/{ → warp_defender}/physics/static.rb
  51. 0  lib/{ → warp_defender}/render/ease.rb
  52. 0  lib/{ → warp_defender}/render/sprite.rb
  53. 0  lib/{ → warp_defender}/utils.rb
  54. 0  lib/{ → warp_defender}/weapons/blaster.rb
  55. 0  lib/{ → warp_defender}/weapons/mine_layer.rb
  56. 0  lib/{ → warp_defender}/weapons/rocket_launcher.rb
  57. 0  lib/{ → warp_defender}/weapons/weapon.rb
View
2  Gemfile
@@ -4,6 +4,8 @@ gem "gosu", "~> 0.7.40"
gem "configurability"
gem "require_all"
gem "rake"
+gem "relapse"
+gem "optparse"
group :development do
gem "ruby-debug19"
View
5 Gemfile.lock
@@ -8,7 +8,11 @@ GEM
gosu (0.7.41-x86-mingw32)
linecache19 (0.5.12)
ruby_core_source (>= 0.1.4)
+ ocra (1.3.0)
rake (0.9.2.2)
+ relapse (0.1.0)
+ ocra (~> 1.3.0)
+ rake
require_all (1.2.1)
ruby-debug-base19 (0.11.25)
columnize (>= 0.3.1)
@@ -29,5 +33,6 @@ DEPENDENCIES
configurability
gosu (~> 0.7.40)
rake
+ relapse
require_all
ruby-debug19
View
4 README.markdown
@@ -12,6 +12,6 @@
$ rake setup
-### To start the game, merely run the init.rb script:
+### To start the game, merely run the executable script:
- $ ruby init.rb
+ $ ruby bin/warp_defender.rbw
View
32 Rakefile
@@ -1,4 +1,36 @@
#!/usr/bin/env rake
+require 'relapse'
+
+# Relapse generates rake tasks for releases
+Relapse::Project.new do |p|
+ p.name = "Warp Defender"
+ p.version = WarpDefender::VERSION
+ p.executable = "bin/alpha_channel.rbw"
+ p.files = `git ls-files`.split("\n").reject {|f| f[0] == '.' }
+ p.icon = "media/icon.ico"
+ p.readme = "README.html"
+
+ p.add_link "http://www.github.com/stderr/warp_defender", "Warp Defender website"
+
+ # Create a variety of releases, for all platforms.
+ p.add_output :osx_app do |o|
+ o.url = "com.github.stderr.games.warp_defender"
+ o.wrapper = "../osx_app/RubyGosu App.app"
+ o.gems = Bundler.definition.specs_for([:default]) # Don't want :development gems.
+ end
+ p.add_output :source
+ p.add_output :win32_folder do |o|
+ o.ocra_parameters = "--no-enc"
+ end
+ p.add_output :win32_installer do |o|
+ o.ocra_parameters = "--no-enc"
+ o.start_menu_group = "Brawlsome Games"
+ end
+
+ # Create all packages as zip and 7z archives.
+ p.add_archive_format :zip
+ p.add_archive_format :'7z'
+end
bundler_installed = !!(%x[gem list] =~ /bundler/)
View
109 bin/warp_defender.rbw
@@ -0,0 +1,109 @@
+#!/usr/bin/env ruby
+
+require 'optparse'
+
+begin
+ EXTRACT_PATH = File.dirname(File.dirname(File.expand_path(__FILE__)))
+
+ ROOT_PATH = if ENV['OCRA_EXECUTABLE']
+ File.dirname(File.expand_path(ENV['OCRA_EXECUTABLE']))
+ elsif defined? OSX_EXECUTABLE_FOLDER
+ File.dirname(OSX_EXECUTABLE_FOLDER)
+ else
+ EXTRACT_PATH
+ end
+
+ APP_NAME = File.basename(__FILE__).chomp(File.extname(__FILE__))
+
+ RUNNING_FROM_EXECUTABLE = (ENV['OCRA_EXECUTABLE'] or defined?(OSX_EXECUTABLE))
+
+ DEFAULT_LOG_FILE = "#{APP_NAME}.log"
+ DEFAULT_LOG_FILE_PATH = File.join(ROOT_PATH, DEFAULT_LOG_FILE)
+
+ def parse_options
+ options = {}
+
+ OptionParser.new do |parser|
+ parser.banner =<<TEXT
+Usage: #{File.basename(__FILE__)} [options]
+
+ Defaults to using --#{RUNNING_FROM_EXECUTABLE ? 'log' : 'console'}
+
+TEXT
+
+ parser.on('-?', '-h', '--help', 'Display this screen') do
+ puts parser
+ exit
+ end
+
+ options[:dev] = false
+ parser.on('--dev', 'Development mode') do
+ options[:dev] = true
+ end
+
+ parser.on('--console', 'Console mode (no log file)') do
+ options[:log] = nil # Write to console.
+ end
+
+ parser.on('--log [FILE]', "Write log to a file (defaults to '#{DEFAULT_LOG_FILE}')") do |file|
+ options[:log] = file ? file : DEFAULT_LOG_FILE_PATH
+ end
+
+ parser.on('--timestamp', "Adds a timestamp to the log file") do
+ options[:timestamp] = true
+ end
+
+ begin
+ parser.parse!
+ rescue OptionParser::ParseError => ex
+ puts "ERROR: #{ex.message}"
+ puts
+ puts parser
+ exit
+ end
+ end
+
+ options
+ end
+
+ options = parse_options
+
+ # Default to console mode normally; default to logfile when running executable.
+ if RUNNING_FROM_EXECUTABLE and not options.has_key?(:log)
+ options[:log] = DEFAULT_LOG_FILE_PATH
+ end
+
+ LOG_FILE = options[:log]
+ DEVELOPMENT_MODE = options[:dev]
+
+ ENV['PATH'] = "#{File.join(ROOT_PATH, 'bin')};#{ENV['PATH']}"
+
+ if LOG_FILE
+ # Add a timestamp to the end of the log file-name.
+ if options[:timestamp]
+ LOG_FILE.sub!(/(\.\w+)$/, "_#{Time.now.to_s.gsub(/[^\d]/, "_")}_#{Time.now.usec.to_s.rjust(6, '0')}\\1")
+ end
+
+ puts "Redirecting output to '#{LOG_FILE}'"
+
+ original_stderr = $stderr.dup
+ $stderr.reopen LOG_FILE
+ $stderr.sync = true
+
+ original_stdout = $stdout.dup
+ $stdout.reopen LOG_FILE
+ $stdout.sync = true
+ end
+
+ require_relative "../lib/#{APP_NAME}"
+
+ exit_message = Game.run unless defined? Ocra
+
+rescue => ex
+ $stderr.puts "FATAL ERROR - #{ex.class}: #{ex.message}\n#{ex.backtrace.join("\n")}"
+ raise ex # Just to make sure that the user sees the error in the CLI/IDE too.
+ensure
+ $stderr.reopen(original_stderr) if defined?(original_stderr) and original_stderr
+ $stderr.puts exit_message if exit_message
+ $stdout.reopen(original_stdout) if defined?(original_stdout) and original_stdout
+end
View
9 lib/warp_defender.rb
@@ -0,0 +1,9 @@
+require_relative "warp_defender/game"
+
+module WarpDefender
+ VERSION = "0.5.0"
+end
+
+game = Game.new
+game.show
+
View
0  lib/behaviors/beeline.rb → lib/warp_defender/behaviors/beeline.rb
File renamed without changes
View
0  lib/behaviors/behavior.rb → lib/warp_defender/behaviors/behavior.rb
File renamed without changes
View
0  lib/behaviors/hunt.rb → lib/warp_defender/behaviors/hunt.rb
File renamed without changes
View
0  lib/camera.rb → lib/warp_defender/camera.rb
File renamed without changes
View
0  lib/entities/entity.rb → lib/warp_defender/entities/entity.rb
File renamed without changes
View
0  lib/entities/explosion.rb → lib/warp_defender/entities/explosion.rb
File renamed without changes
View
0  lib/entities/grunt.rb → lib/warp_defender/entities/grunt.rb
File renamed without changes
View
0  lib/entities/player.rb → lib/warp_defender/entities/player.rb
File renamed without changes
View
0  lib/entities/projectiles/bullet.rb → ...p_defender/entities/projectiles/bullet.rb
File renamed without changes
View
0  lib/entities/projectiles/mine.rb → ...arp_defender/entities/projectiles/mine.rb
File renamed without changes
View
0  lib/entities/projectiles/projectile.rb → ...fender/entities/projectiles/projectile.rb
File renamed without changes
View
0  lib/entities/projectiles/rocket.rb → ...p_defender/entities/projectiles/rocket.rb
File renamed without changes
View
0  lib/entities/warp.rb → lib/warp_defender/entities/warp.rb
File renamed without changes
View
53 lib/game.rb → lib/warp_defender/game.rb
@@ -1,3 +1,12 @@
+$:.unshift File.expand_path(File.dirname(__FILE__))
+# Global gems
+require 'gosu'
+require 'configurability'
+require 'configurability/config'
+require 'require_all'
+
+require_all File.join(File.dirname(__FILE__))
+
class Game < Gosu::Window
attr_accessor :fonts, :images, :animations, :sounds, :music, :sprites, :native_width, :native_height, :game_engine
@@ -34,6 +43,14 @@ def initialize
@game_engine.start!
end
+ def self.run
+ new.show
+ end
+
+ def media_path(path)
+ File.join("media/", path)
+ end
+
def update
@game_engine.update
end
@@ -56,32 +73,32 @@ def button_up(id)
end
def load_images
- @images[:background] = Gosu::Image.new(self, "media/images/space.jpg", true)
- @images[:menu_background] = Gosu::Image.new(self, "media/images/space.jpg", true)
- @images[:unchecked] = Gosu::Image.new(self, "media/images/unchecked.png", false)
- @images[:checked] = Gosu::Image.new(self, "media/images/checked.png", false)
- @images[:hud] = Gosu::Image.new(self, "media/images/hud_bottom_right.png", false)
+ @images[:background] = Gosu::Image.new(self, media_path("images/space.jpg"), true)
+ @images[:menu_background] = Gosu::Image.new(self, media_path("images/space.jpg"), true)
+ @images[:unchecked] = Gosu::Image.new(self, media_path("images/unchecked.png"), false)
+ @images[:checked] = Gosu::Image.new(self, media_path("images/checked.png"), false)
+ @images[:hud] = Gosu::Image.new(self, media_path("images/hud_bottom_right.png"), false)
end
def load_fonts
- @fonts[:menu] = Gosu::Font.new(self, 'media/fonts/space.ttf', 60)
- @fonts[:level_title] = Gosu::Font.new(self, 'media/fonts/space.ttf', 80)
- @fonts[:level_description] = Gosu::Font.new(self, 'droid_sans_mono.ttf', 24)
+ @fonts[:menu] = Gosu::Font.new(self, media_path("fonts/space.ttf"), 60)
+ @fonts[:level_title] = Gosu::Font.new(self, media_path("fonts/space.ttf"), 80)
+ @fonts[:level_description] = Gosu::Font.new(self, media_path("fonts/droid_sans_mono.ttf"), 24)
end
def load_sounds
- @sounds[:beep] = Gosu::Sample.new(self, "media/sounds/beep.wav")
- @sounds[:applause] = Gosu::Sample.new(self, "media/sounds/applause.wav")
- @sounds[:warp] = Gosu::Sample.new(self, "media/sounds/warp.wav")
- @sounds[:meteor] = Gosu::Sample.new(self, "media/sounds/meteor.wav")
- @sounds[:laser] = Gosu::Sample.new(self, "media/sounds/laser_sound.wav")
- @sounds[:rlaunch] = Gosu::Sample.new(self, "media/sounds/rlaunch.wav")
- @sounds[:explosion] = Gosu::Sample.new(self, "media/sounds/explosion.wav")
- @sounds[:click] = Gosu::Sample.new(self, "media/sounds/click.wav")
+ @sounds[:beep] = Gosu::Sample.new(self, media_path("sounds/beep.wav"))
+ @sounds[:applause] = Gosu::Sample.new(self, media_path("sounds/applause.wav"))
+ @sounds[:warp] = Gosu::Sample.new(self, media_path("sounds/warp.wav"))
+ @sounds[:meteor] = Gosu::Sample.new(self, media_path("sounds/meteor.wav"))
+ @sounds[:laser] = Gosu::Sample.new(self, media_path("sounds/laser_sound.wav"))
+ @sounds[:rlaunch] = Gosu::Sample.new(self, media_path("sounds/rlaunch.wav"))
+ @sounds[:explosion] = Gosu::Sample.new(self, media_path("sounds/explosion.wav"))
+ @sounds[:click] = Gosu::Sample.new(self, media_path("sounds/click.wav"))
end
def load_music
- @music[:theme] = Gosu::Song.new(self, "media/music/theme.ogg")
+ @music[:theme] = Gosu::Song.new(self, media_path("music/theme.ogg"))
end
def load_sprites
@@ -94,7 +111,7 @@ def load_sprites
# load any referenced files
y['layers'].each do |layer|
@animations[layer['file']] = Gosu::Image::load_tiles(self,
- "media/images/#{layer['file']}",
+ media_path("images/#{layer['file']}"),
layer['width'],
layer['height'],
false)
View
2  lib/game_engine.rb → lib/warp_defender/game_engine.rb
@@ -2,7 +2,7 @@ class GameEngine
attr_accessor :config, :level
def initialize
- @config = Configurability::Config.load(File.expand_path(File.dirname(__FILE__) +"/../config/game_data.yml"))
+ @config = Configurability::Config.load(File.expand_path(File.dirname(__FILE__) +"/../../config/game_data.yml"))
@state_manager = GameStates::StateManager.new
@level = GameLevel.new("level_one.yml")
View
0  lib/game_level.rb → lib/warp_defender/game_level.rb
File renamed without changes
View
0  lib/game_states/credits.rb → lib/warp_defender/game_states/credits.rb
File renamed without changes
View
0  lib/game_states/game_completed.rb → ...rp_defender/game_states/game_completed.rb
File renamed without changes
View
0  lib/game_states/game_over.rb → lib/warp_defender/game_states/game_over.rb
File renamed without changes
View
0  lib/game_states/game_state.rb → lib/warp_defender/game_states/game_state.rb
File renamed without changes
View
0  lib/game_states/level_completed.rb → ...p_defender/game_states/level_completed.rb
File renamed without changes
View
0  lib/game_states/load_level.rb → lib/warp_defender/game_states/load_level.rb
File renamed without changes
View
0  lib/game_states/menu/audio.rb → lib/warp_defender/game_states/menu/audio.rb
File renamed without changes
View
0  lib/game_states/menu/base_menu.rb → ...rp_defender/game_states/menu/base_menu.rb
File renamed without changes
View
0  lib/game_states/menu/display.rb → ...warp_defender/game_states/menu/display.rb
File renamed without changes
View
0  lib/game_states/menu/main_menu.rb → ...rp_defender/game_states/menu/main_menu.rb
File renamed without changes
View
0  lib/game_states/menu/options.rb → ...warp_defender/game_states/menu/options.rb
File renamed without changes
View
0  lib/game_states/paused.rb → lib/warp_defender/game_states/paused.rb
File renamed without changes
View
0  lib/game_states/playing.rb → lib/warp_defender/game_states/playing.rb
File renamed without changes
View
0  lib/game_states/state_manager.rb → ...arp_defender/game_states/state_manager.rb
File renamed without changes
View
0  lib/game_states/transition.rb → lib/warp_defender/game_states/transition.rb
File renamed without changes
View
0  lib/gosu_ext/window.rb → lib/warp_defender/gosu_ext/window.rb
File renamed without changes
View
0  lib/gui/bar.rb → lib/warp_defender/gui/bar.rb
File renamed without changes
View
0  lib/gui/base_element.rb → lib/warp_defender/gui/base_element.rb
File renamed without changes
View
0  lib/gui/checkbox.rb → lib/warp_defender/gui/checkbox.rb
File renamed without changes
View
0  lib/gui/level_dialog.rb → lib/warp_defender/gui/level_dialog.rb
File renamed without changes
View
0  lib/gui/menu_dialog.rb → lib/warp_defender/gui/menu_dialog.rb
File renamed without changes
View
0  lib/gui/mini_map.rb → lib/warp_defender/gui/mini_map.rb
File renamed without changes
View
0  lib/gui/text.rb → lib/warp_defender/gui/text.rb
File renamed without changes
View
0  lib/gui/weapon_display.rb → lib/warp_defender/gui/weapon_display.rb
File renamed without changes
View
2  lib/input_handler.rb → lib/warp_defender/input_handler.rb
@@ -1,7 +1,7 @@
module Input
# The Handler is included in the object you want to have input handling context
- # dispatch_constantt_input is for #update loops, whereas dispatch_input is for the button_down / button_up callbacks
+ # dispatch_constant_input is for #update loops, whereas dispatch_input is for the button_down / button_up callbacks
module Handler
View
0  lib/physics/collisions.rb → lib/warp_defender/physics/collisions.rb
File renamed without changes
View
0  lib/physics/dynamic.rb → lib/warp_defender/physics/dynamic.rb
File renamed without changes
View
0  lib/physics/static.rb → lib/warp_defender/physics/static.rb
File renamed without changes
View
0  lib/render/ease.rb → lib/warp_defender/render/ease.rb
File renamed without changes
View
0  lib/render/sprite.rb → lib/warp_defender/render/sprite.rb
File renamed without changes
View
0  lib/utils.rb → lib/warp_defender/utils.rb
File renamed without changes
View
0  lib/weapons/blaster.rb → lib/warp_defender/weapons/blaster.rb
File renamed without changes
View
0  lib/weapons/mine_layer.rb → lib/warp_defender/weapons/mine_layer.rb
File renamed without changes
View
0  lib/weapons/rocket_launcher.rb → lib/warp_defender/weapons/rocket_launcher.rb
File renamed without changes
View
0  lib/weapons/weapon.rb → lib/warp_defender/weapons/weapon.rb
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.