missile-command-ruby 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 lotu
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = missile-command-ruby
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 lotu. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'psych'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "missile-command-ruby"
9
+ gem.summary = %Q{Missile command in Ruby!}
10
+ gem.description = %Q{Protect your cities, destroy the incoming enemy missiles!}
11
+ gem.email = "dev@lobotuerto.com"
12
+ gem.homepage = "http://github.com/lobo-tuerto/missile-command-ruby"
13
+ gem.authors = ["lobo_tuerto"]
14
+ gem.add_dependency "lotu", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/rdoctask'
23
+ Rake::RDocTask.new do |rdoc|
24
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
25
+
26
+ rdoc.rdoc_dir = 'rdoc'
27
+ rdoc.title = "missile-command-ruby #{version}"
28
+ rdoc.rdoc_files.include('README*')
29
+ rdoc.rdoc_files.include('lib/**/*.rb')
30
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.5
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ MCOMMAND_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ $LOAD_PATH.unshift(MCOMMAND_ROOT)
4
+ require 'missile-command-ruby'
5
+ MissileCommand.new.show
6
+ exit 0
data/lib/cross_hair.rb ADDED
@@ -0,0 +1,28 @@
1
+ class CrossHair < Cursor
2
+
3
+ def initialize(opts={})
4
+ super
5
+ set_image 'crosshair-1.png', opts
6
+ @bajando = true
7
+ @z = 10
8
+ end
9
+
10
+ def update
11
+ super
12
+ @angle += 10 * dt
13
+ return
14
+ if @bajando && @factor_y > 0.5
15
+ @factor_y -= dt
16
+ @factor_y = 0.5 if @factor_y < 0.5
17
+ else
18
+ @bajando = false
19
+ end
20
+ if !@bajando && @factor_y < 1.0
21
+ @factor_y += dt
22
+ @factor_y = 1.0 if @factor_y > 1.0
23
+ else
24
+ @bajando = true
25
+ end
26
+ end
27
+
28
+ end
data/lib/explosion.rb ADDED
@@ -0,0 +1,49 @@
1
+ class Explosion < Actor
2
+ attr_reader :collision_radius
3
+
4
+ def initialize(opts={})
5
+ super
6
+ set_image('explosion.png', opts)
7
+ @initial_radius = 10.0
8
+ @end_radius = 100.0
9
+ @explosion_time = 3.0
10
+ @fade_after = 0.5
11
+
12
+ interpolate_alpha(:init => 255, :end => 0, :duration => @explosion_time - @fade_after, :start_in => @fade_after)
13
+ interpolate_saturation(:init => 0.0, :end => 1.0, :duration => 0.1, :loop => true)
14
+ # Don't know why gosu changes my hue when transforming saturation
15
+ # alone so we keep it fixed, or give it a little space for change
16
+ interpolate_hue(:init => @color.hue-50, :end => @color.hue+50, :loop => true, :duration => 0.5)
17
+
18
+ self.radius = @initial_radius
19
+ # Expand or shrink the explosion
20
+ interpolate(self, :radius, :init => @initial_radius, :end => @end_radius, :duration => @explosion_time)
21
+ collides_as :explosion
22
+ @z = 7
23
+ @elapsed_time = 0.0
24
+ end
25
+
26
+ def update
27
+ # Note to self: It's important to call super!
28
+ super
29
+ if @elapsed_time > @explosion_time
30
+ die
31
+ end
32
+ @elapsed_time += dt
33
+ end
34
+
35
+ def radius=(radius)
36
+ @collision_radius = radius
37
+ @factor_x = 2*radius/@image.width
38
+ @factor_y = 2*radius/@image.height
39
+ end
40
+
41
+ def to_s
42
+ ["@elapsed_time #{format('%.2f', @elapsed_time)}",
43
+ "@color.alpha #{@color.alpha}",
44
+ "@color.hue #{format('%.2f', @color.hue)}",
45
+ "@color.saturation #{format('%.2f', @color.saturation)}",
46
+ "@color.value #{format('%.2f', @color.value)}"]
47
+ end
48
+
49
+ end
Binary file
@@ -0,0 +1,18 @@
1
+ miss0000 = 380 0 75 75
2
+ miss0001 = 380 76 75 75
3
+ miss0002 = 304 76 75 75
4
+ miss0003 = 304 0 75 75
5
+ miss0004 = 228 152 75 75
6
+ miss0005 = 76 228 75 75
7
+ miss0006 = 152 228 75 75
8
+ miss0007 = 0 228 75 75
9
+ miss0008 = 304 152 75 75
10
+ miss0009 = 380 152 75 75
11
+ miss0010 = 228 76 75 75
12
+ miss0011 = 0 76 75 75
13
+ miss0012 = 76 76 75 75
14
+ miss0013 = 152 0 75 75
15
+ miss0014 = 0 0 75 75
16
+ miss0015 = 76 0 75 75
17
+ miss0016 = 152 152 75 75
18
+ miss0017 = 228 0 75 75
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,86 @@
1
+ begin
2
+ require 'rubygems'
3
+ rescue LoadError
4
+ end
5
+
6
+ require 'lotu'
7
+ include Lotu
8
+
9
+ require 'silo'
10
+ require 'explosion'
11
+ require 'missile'
12
+ require 'cross_hair'
13
+
14
+ class MissileCommand < Game
15
+
16
+ def initialize
17
+ super
18
+ setup_events
19
+ @info = TextBox.new(:size => 15)
20
+ @info.text("Press F1 to hide this text | F2 debug info | F3 toggle pause", :size => 24)
21
+ @info.watch(@systems[FpsSystem], :size => 20)
22
+ @info.watch(@systems[StalkerSystem], :color => 0xff33ccff)
23
+ @info.text("Click on screen to launch some missiles!")
24
+ end
25
+
26
+ def load_resources
27
+ with_path_from_file(__FILE__) do
28
+ load_images 'media/images'
29
+ load_sounds 'media/sounds'
30
+ load_animations 'media/animations'
31
+ end
32
+ end
33
+
34
+ def setup_input
35
+ set_keys(Gosu::KbEscape => :close,
36
+ Gosu::KbF1 => [:toggle_info, false],
37
+ Gosu::KbF2 => [:debug!, false],
38
+ Gosu::KbF3 => [:pause!, false])
39
+ end
40
+
41
+ def setup_systems
42
+ # It's important to call super here to setup the InputSystem
43
+ super
44
+ use(CollisionSystem)
45
+ use(FpsSystem)
46
+ use(StalkerSystem, :stalk => [Actor, Silo, Missile, Explosion, TextBox, Object])
47
+ end
48
+
49
+ def setup_actors
50
+ @player = Silo.new(:x => width/2,
51
+ :width => 100,
52
+ :stock => 10000,
53
+ :platform_capacity => 4,
54
+ :load_time => 0.1,
55
+ :speed => 100,
56
+ :missile_speed => 1000,
57
+ :missile_force => 1000,
58
+ :missile_mass => 0.5)
59
+ @player.set_keys(Gosu::KbA => :move_left,
60
+ Gosu::KbD => :move_right)
61
+
62
+ @cross_hair = CrossHair.new(:keys => {Gosu::MsLeft => [:click, false], Gosu::MsRight => :click},
63
+ :rand_color => true,
64
+ :mode => :additive,
65
+ :width => 100)
66
+
67
+ @silo_info = TextBox.new(:attach_to => @player, :size => 14)
68
+ @silo_info.watch(@player)
69
+ end
70
+
71
+ def setup_events
72
+ @cross_hair.on :click do |x, y|
73
+ @player.launch_missile(x, y)
74
+ end
75
+
76
+ when_colliding(:explosion, :missile) do |e, m|
77
+ m.die
78
+ end
79
+ end
80
+
81
+ def toggle_info
82
+ @info.toggle!
83
+ @silo_info.toggle!
84
+ end
85
+
86
+ end
data/lib/missile.rb ADDED
@@ -0,0 +1,51 @@
1
+ # -*- coding: utf-8 -*-
2
+ class Missile < Actor
3
+ attr_reader :collision_radius
4
+
5
+ def initialize(opts={})
6
+ super
7
+ use(SteeringSystem, opts)
8
+ activate(:seek)
9
+ collides_as :missile
10
+ @last_distance_to_target = nil
11
+ @target = nil
12
+ set_image('missile-med.png', opts)
13
+ end
14
+
15
+ def update
16
+ @last_distance_to_target = distance_to_target if @target
17
+ super
18
+ # If missile goes past target or is 10 pixels away from it, just die
19
+ if @target && (distance_to_target < 10 || !facing_target?)
20
+ die
21
+ end
22
+ return
23
+ if @bajando && @factor_y > 0.5
24
+ @factor_y -= dt
25
+ else
26
+ @bajando = false
27
+ end
28
+ if !@bajando && @factor_y < 1.0
29
+ @factor_y += dt
30
+ else
31
+ @bajando = true
32
+ end
33
+ end
34
+
35
+ def draw
36
+ super
37
+ color = @color.dup
38
+ color.saturation = color.value = 0.3
39
+ $lotu.draw_line(@pos.x, @pos.y, color, @target.x, @target.y, color) if @target
40
+ end
41
+
42
+ def die
43
+ super
44
+ Explosion.new(:x => @x, :y => @y, :color => @color, :mode => :additive)
45
+ end
46
+
47
+ def collision_radius
48
+ @width/2
49
+ end
50
+
51
+ end
data/lib/silo.rb ADDED
@@ -0,0 +1,118 @@
1
+ class Silo < Actor
2
+ attr_accessor :stock
3
+
4
+ def initialize(opts={})
5
+ super
6
+ set_image 'silo2.png', opts
7
+ @factor = @width / @image.width
8
+ @y = $lotu.height - @height/2
9
+ @z = 5
10
+ @speed = opts[:speed]
11
+
12
+ @platform = []
13
+ # How many missiles in stock?
14
+ @stock = opts[:stock]
15
+ # How many missiles on platform?
16
+ @platform_capacity = Float(opts[:platform_capacity])
17
+ # Load one missile every n seconds
18
+ @load_time = opts[:load_time]
19
+
20
+ # Missiles configuration
21
+ @missile_conf = {
22
+ :force => opts[:missile_force] || 1000,
23
+ :speed => opts[:missile_speed] || 1000,
24
+ :mass => opts[:missile_mass] || 10
25
+ }
26
+
27
+ # If negative, it adds some initial delay
28
+ @elapsed_time = -2
29
+
30
+ # Platform configuration in pixels
31
+ @head_width = 75 * @factor
32
+ @tail_width = 35 * @factor
33
+ @platform_height = 70 * @factor
34
+
35
+ @missile_image_width = 22.0
36
+ @missile_animation_width = @missile_image_width * 20 / 15
37
+
38
+ @slot_width = platform_width/@platform_capacity
39
+ end
40
+
41
+ def platform_width
42
+ @width - @head_width - @tail_width
43
+ end
44
+
45
+ def update
46
+ super
47
+ load_platform
48
+ place_missiles
49
+ end
50
+
51
+ def load_platform
52
+ if @platform.length < @platform_capacity && @stock > 0
53
+ @elapsed_time += dt
54
+ while @platform.length < @platform_capacity && @elapsed_time >= @load_time && @stock > 0
55
+ @elapsed_time -= @load_time
56
+ @platform.push(new_missile)
57
+ @stock -= 1
58
+ end
59
+ end
60
+ end
61
+
62
+ def new_missile
63
+ missile = Missile.new(:mass => @missile_conf[:mass],
64
+ :max_force => @missile_conf[:force],
65
+ :max_speed => @missile_conf[:speed],
66
+ :rand_color => true,
67
+ :width => @missile_image_width*@factor)
68
+ missile.pos.x = initial_place(missile)
69
+ missile.pos.y = @y + @height/2 - missile.height/2 - @platform_height
70
+ missile
71
+ end
72
+
73
+ def initial_place(missile)
74
+ res = @x - @width/2 + @head_width + missile.width/2 + (@platform_capacity - 1) * @slot_width
75
+ res += (@slot_width - missile.width)
76
+ res -= @elapsed_time / @load_time * @slot_width
77
+ res
78
+ end
79
+
80
+ def place_missiles
81
+ @platform.each_with_index do |missile, i|
82
+ place_to_be = @x - @width/2 + @head_width + missile.width/2 + i * @slot_width
83
+ place_to_be += i/(@platform_capacity-1) * (@slot_width - missile.width)
84
+ if missile.pos.x > initial_place(missile)
85
+ missile.pos.x = initial_place(missile)
86
+ end
87
+ if missile.pos.x > place_to_be
88
+ missile.pos.x -= @slot_width * dt / @load_time
89
+ end
90
+ if missile.pos.x <= place_to_be
91
+ missile.pos.x = place_to_be
92
+ end
93
+ end
94
+ end
95
+
96
+ def launch_missile(x, y)
97
+ if m = @platform.shift
98
+ m.target = Vector2d.new(x,y)
99
+ m.play_animation('missile.png', :width => @missile_animation_width*@factor)
100
+ end
101
+ end
102
+
103
+ def move_left
104
+ @x -= @speed * dt
105
+ end
106
+
107
+ def move_right
108
+ @x += @speed * dt
109
+ end
110
+
111
+ def to_s
112
+ ["@platform.length: #{@platform.length}",
113
+ "Missiles in stock: #{@stock}",
114
+ "Missiles on platform: #{@platform.length}",
115
+ "Elapsed loading time: #{format '%.2f', @elapsed_time}",
116
+ "Loading next missile in: #{format('%.2f', @load_time - @elapsed_time)}"]
117
+ end
118
+ end
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{missile-command-ruby}
8
+ s.version = "0.0.5"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["lobo_tuerto"]
12
+ s.date = %q{2011-02-22}
13
+ s.default_executable = %q{missile-command-ruby}
14
+ s.description = %q{Protect your cities, destroy the incoming enemy missiles!}
15
+ s.email = %q{dev@lobotuerto.com}
16
+ s.executables = ["missile-command-ruby"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "LICENSE",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "bin/missile-command-ruby",
28
+ "lib/cross_hair.rb",
29
+ "lib/explosion.rb",
30
+ "lib/media/animations/missile.png",
31
+ "lib/media/animations/missile.txt",
32
+ "lib/media/images/Starfighter.bmp",
33
+ "lib/media/images/cohete-big.png",
34
+ "lib/media/images/cohete-medium.png",
35
+ "lib/media/images/cohete-small.png",
36
+ "lib/media/images/crosshair-1.png",
37
+ "lib/media/images/crosshair-2.png",
38
+ "lib/media/images/crosshair-3.png",
39
+ "lib/media/images/crosshair.png",
40
+ "lib/media/images/explosion.png",
41
+ "lib/media/images/explosion2.png",
42
+ "lib/media/images/explosion3.png",
43
+ "lib/media/images/explosion4.png",
44
+ "lib/media/images/explosion5.png",
45
+ "lib/media/images/explosion6.png",
46
+ "lib/media/images/lobo_tuerto.png",
47
+ "lib/media/images/missile-med.png",
48
+ "lib/media/images/silo.png",
49
+ "lib/media/images/silo2.png",
50
+ "lib/media/sounds/Explosion.wav",
51
+ "lib/missile-command-ruby.rb",
52
+ "lib/missile.rb",
53
+ "lib/silo.rb",
54
+ "missile-command-ruby.gemspec"
55
+ ]
56
+ s.homepage = %q{http://github.com/lobo-tuerto/missile-command-ruby}
57
+ s.require_paths = ["lib"]
58
+ s.rubygems_version = %q{1.5.0}
59
+ s.summary = %q{Missile command in Ruby!}
60
+
61
+ if s.respond_to? :specification_version then
62
+ s.specification_version = 3
63
+
64
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
+ s.add_runtime_dependency(%q<lotu>, [">= 0"])
66
+ else
67
+ s.add_dependency(%q<lotu>, [">= 0"])
68
+ end
69
+ else
70
+ s.add_dependency(%q<lotu>, [">= 0"])
71
+ end
72
+ end
73
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: missile-command-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease: !!null
6
+ platform: ruby
7
+ authors:
8
+ - lobo_tuerto
9
+ autorequire: !!null
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-02-22 00:00:00.000000000 -06:00
13
+ default_executable: missile-command-ruby
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: lotu
17
+ requirement: &24379560 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *24379560
26
+ description: Protect your cities, destroy the incoming enemy missiles!
27
+ email: dev@lobotuerto.com
28
+ executables:
29
+ - missile-command-ruby
30
+ extensions: []
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - LICENSE
37
+ - README.rdoc
38
+ - Rakefile
39
+ - VERSION
40
+ - bin/missile-command-ruby
41
+ - lib/cross_hair.rb
42
+ - lib/explosion.rb
43
+ - lib/media/animations/missile.png
44
+ - lib/media/animations/missile.txt
45
+ - lib/media/images/Starfighter.bmp
46
+ - lib/media/images/cohete-big.png
47
+ - lib/media/images/cohete-medium.png
48
+ - lib/media/images/cohete-small.png
49
+ - lib/media/images/crosshair-1.png
50
+ - lib/media/images/crosshair-2.png
51
+ - lib/media/images/crosshair-3.png
52
+ - lib/media/images/crosshair.png
53
+ - lib/media/images/explosion.png
54
+ - lib/media/images/explosion2.png
55
+ - lib/media/images/explosion3.png
56
+ - lib/media/images/explosion4.png
57
+ - lib/media/images/explosion5.png
58
+ - lib/media/images/explosion6.png
59
+ - lib/media/images/lobo_tuerto.png
60
+ - lib/media/images/missile-med.png
61
+ - lib/media/images/silo.png
62
+ - lib/media/images/silo2.png
63
+ - lib/media/sounds/Explosion.wav
64
+ - lib/missile-command-ruby.rb
65
+ - lib/missile.rb
66
+ - lib/silo.rb
67
+ - missile-command-ruby.gemspec
68
+ has_rdoc: true
69
+ homepage: http://github.com/lobo-tuerto/missile-command-ruby
70
+ licenses: []
71
+ post_install_message: !!null
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project: !!null
89
+ rubygems_version: 1.5.0
90
+ signing_key: !!null
91
+ specification_version: 3
92
+ summary: Missile command in Ruby!
93
+ test_files: []