spacewar 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +54 -0
- data/bin/spacewar +4 -0
- data/lib/media/Parallax-scroll-example-layer-0.png +0 -0
- data/lib/media/Parallax-scroll-example-layer-1.png +0 -0
- data/lib/media/Parallax-scroll-example-layer-2.png +0 -0
- data/lib/media/Parallax-scroll-example-layer-3.png +0 -0
- data/lib/media/Star.png +0 -0
- data/lib/media/Starfighter.bmp +0 -0
- data/lib/media/Starfighter_p1.bmp +0 -0
- data/lib/media/Starfighter_p2.bmp +0 -0
- data/lib/media/background1.png +0 -0
- data/lib/media/bullet.png +0 -0
- data/lib/media/bullet_hit.wav +0 -0
- data/lib/media/circle.png +0 -0
- data/lib/media/city1.csv +2 -0
- data/lib/media/city1.png +0 -0
- data/lib/media/city2.png +0 -0
- data/lib/media/droid.bmp +0 -0
- data/lib/media/enemy_bullet.png +0 -0
- data/lib/media/explosion.wav +0 -0
- data/lib/media/fire_bullet.png +0 -0
- data/lib/media/fireball.png +0 -0
- data/lib/media/foo +0 -0
- data/lib/media/laser.wav +0 -0
- data/lib/media/particle.png +0 -0
- data/lib/media/plane.csv +2 -0
- data/lib/media/plane.png +0 -0
- data/lib/media/planet.png +0 -0
- data/lib/media/rect.png +0 -0
- data/lib/media/ruby.png +0 -0
- data/lib/media/saucer.csv +4 -0
- data/lib/media/saucer.gal +0 -0
- data/lib/media/saucer.png +0 -0
- data/lib/media/spaceship.png +0 -0
- data/lib/media/stickfigure.bmp +0 -0
- data/lib/media/stickfigure.png +0 -0
- data/lib/media/video_games.png +0 -0
- data/lib/media/wood.png +0 -0
- data/lib/spacewar.rb +9 -0
- data/lib/spacewar/spacewar.rb +217 -0
- data/test/helper.rb +10 -0
- data/test/test_spacewar.rb +7 -0
- metadata +112 -0
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/clean'
|
3
|
+
require 'rake/gempackagetask'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'lib/spacewar'
|
6
|
+
|
7
|
+
include FileUtils
|
8
|
+
|
9
|
+
version = Spacewar::VERSION
|
10
|
+
name = "spacewar"
|
11
|
+
|
12
|
+
spec = Gem::Specification.new do |s|
|
13
|
+
s.name = name
|
14
|
+
s.version = version
|
15
|
+
s.summary = 'There are two spaceships, a planet, gravity, missiles, and lasers. Do the math.'
|
16
|
+
s.description = 'A brave group-effort by the gentlemen at Ottawa.rb (aka OGRE), spacewar is a legitimate heir to the glory that is the original game you likely played on an xt or more ancient beast of a machine.'
|
17
|
+
s.authors = ["Edward Ocampo-Gooding", "John Duff", "Justin Bowes", "Chris Saunders", "Schwab", "Pranav Singh", "Dwayne Litzenberger", "Jean Claude Batista"]
|
18
|
+
|
19
|
+
s.email = 'edward@edwardog.net'
|
20
|
+
s.homepage = "http://github.com/edward/spacewar"
|
21
|
+
s.executables = [ "spacewar" ]
|
22
|
+
s.default_executable = "spacewar"
|
23
|
+
s.rubyforge_project = "spacewar"
|
24
|
+
|
25
|
+
s.platform = Gem::Platform::RUBY
|
26
|
+
s.has_rdoc = false
|
27
|
+
|
28
|
+
s.files = %w(Rakefile) +
|
29
|
+
Dir.glob("{bin,lib,test}/**/*")
|
30
|
+
|
31
|
+
s.require_path = "lib"
|
32
|
+
s.bindir = "bin"
|
33
|
+
|
34
|
+
s.add_dependency('chingu', '>= 0.6.7')
|
35
|
+
end
|
36
|
+
|
37
|
+
Rake::GemPackageTask.new(spec) do |p|
|
38
|
+
p.need_tar = true if RUBY_PLATFORM !~ /mswin/
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Install #{name} gem (#{version})"
|
42
|
+
task :install => [ :test, :package ] do
|
43
|
+
sh %{sudo gem install pkg/#{name}-#{version}.gem}
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Uninstall #{name} gem"
|
47
|
+
task :uninstall => [ :clean ] do
|
48
|
+
sh %{sudo gem uninstall #{name}}
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "Release #{name} gem (#{version})"
|
52
|
+
task :release => [ :test, :package ] do
|
53
|
+
sh %{gem push pkg/#{name}-#{version}.gem}
|
54
|
+
end
|
data/bin/spacewar
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/media/Star.png
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/media/city1.csv
ADDED
data/lib/media/city1.png
ADDED
Binary file
|
data/lib/media/city2.png
ADDED
Binary file
|
data/lib/media/droid.bmp
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/media/foo
ADDED
File without changes
|
data/lib/media/laser.wav
ADDED
Binary file
|
Binary file
|
data/lib/media/plane.csv
ADDED
data/lib/media/plane.png
ADDED
Binary file
|
Binary file
|
data/lib/media/rect.png
ADDED
Binary file
|
data/lib/media/ruby.png
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/lib/media/wood.png
ADDED
Binary file
|
data/lib/spacewar.rb
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
require 'gosu'
|
2
|
+
require 'chingu'
|
3
|
+
|
4
|
+
# TODO - I'd like to move these includes into the Spacewar module
|
5
|
+
include Gosu
|
6
|
+
include Chingu
|
7
|
+
|
8
|
+
module Chingu
|
9
|
+
ROOT = Spacewar::ROOT
|
10
|
+
end
|
11
|
+
|
12
|
+
module Spacewar
|
13
|
+
G_CONST = 2000
|
14
|
+
|
15
|
+
SCREEN_WIDTH = 1280
|
16
|
+
SCREEN_HEIGHT = 800
|
17
|
+
|
18
|
+
class Game < Chingu::Window
|
19
|
+
def initialize
|
20
|
+
super(Spacewar::SCREEN_WIDTH, Spacewar::SCREEN_HEIGHT)
|
21
|
+
|
22
|
+
Image.autoload_dirs << File.join(ROOT, 'media')
|
23
|
+
|
24
|
+
self.input = {:esc => :exit}
|
25
|
+
|
26
|
+
@planet = Planet.create
|
27
|
+
|
28
|
+
@player1 = Player.create({:holding_right => :turn_right,
|
29
|
+
:holding_left => :turn_left,
|
30
|
+
:holding_up => :accelerate},
|
31
|
+
:zorder => 2,
|
32
|
+
:x => 180,
|
33
|
+
:y => 240,
|
34
|
+
:image => 'Starfighter_p1.bmp')
|
35
|
+
|
36
|
+
@player2 = Player.create({:holding_d => :turn_right,
|
37
|
+
:holding_a => :turn_left,
|
38
|
+
:holding_w => :accelerate},
|
39
|
+
:zorder => 2,
|
40
|
+
:x => 400,
|
41
|
+
:y => 240,
|
42
|
+
:image => 'Starfighter_p2.bmp')
|
43
|
+
@score = 0
|
44
|
+
@score_text = Chingu::Text.create("Score: #{@score}", :x => 10, :y => 10, :zorder => 55, :size=>20)
|
45
|
+
end
|
46
|
+
|
47
|
+
def update
|
48
|
+
super
|
49
|
+
|
50
|
+
if rand(100) < 4 && Star.all.size < 25
|
51
|
+
Star.create
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Collide @player with all instances of class Star
|
56
|
+
#
|
57
|
+
@player1.each_collision(Star) do |player, star|
|
58
|
+
star.destroy
|
59
|
+
@score+=10
|
60
|
+
end
|
61
|
+
|
62
|
+
@player2.each_collision(Star) do |player, star|
|
63
|
+
star.destroy
|
64
|
+
@score-=5
|
65
|
+
end
|
66
|
+
|
67
|
+
@player1.adjust_gravity(@planet)
|
68
|
+
@player2.adjust_gravity(@planet)
|
69
|
+
|
70
|
+
Star.all.each{|star| star.adjust_gravity(@planet)}
|
71
|
+
|
72
|
+
@player1.each_collision(Player) do |player1, player2|
|
73
|
+
if player2 == @player2
|
74
|
+
player1.destroy
|
75
|
+
player2.destroy
|
76
|
+
@player1 = Player.create({:holding_right => :turn_right,
|
77
|
+
:holding_left => :turn_left,
|
78
|
+
:holding_up => :accelerate},
|
79
|
+
:zorder => 2,
|
80
|
+
:x => 180,
|
81
|
+
:y => 240,
|
82
|
+
:image => 'Starfighter_p1.bmp')
|
83
|
+
@player2 = Player.create({:holding_d => :turn_right,
|
84
|
+
:holding_a => :turn_left,
|
85
|
+
:holding_w => :accelerate},
|
86
|
+
:zorder => 2,
|
87
|
+
:x => 400,
|
88
|
+
:y => 240,
|
89
|
+
:image => 'Starfighter_p2.bmp')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
@planet.each_collision(Player) do |planet, player|
|
94
|
+
player.destroy
|
95
|
+
@score-=10000
|
96
|
+
end
|
97
|
+
|
98
|
+
@score_text.text = "Score: #{@score}"
|
99
|
+
self.caption = "Chingu Game - " + @score_text.text
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# extend game object with gravity features
|
104
|
+
class Chingu::GameObject
|
105
|
+
def adjust_gravity(source)
|
106
|
+
# Calculate vector to source
|
107
|
+
vect_x = -(self.x - source.x)
|
108
|
+
vect_y = -(self.y - source.y)
|
109
|
+
|
110
|
+
# Get length of vector to source
|
111
|
+
length = (vect_x**2 + vect_y**2)**0.5
|
112
|
+
|
113
|
+
# Calculate unit vector
|
114
|
+
vect_x = vect_x/length
|
115
|
+
vect_y = vect_y/length
|
116
|
+
|
117
|
+
# Diminish unit vector as 1/r**2
|
118
|
+
vect_x *= (1/length ** 2)
|
119
|
+
vect_y *= (1/length ** 2)
|
120
|
+
|
121
|
+
# Scale to strength of gravity and apply
|
122
|
+
self.velocity_x += vect_x * Spacewar::G_CONST
|
123
|
+
self.velocity_y += vect_y * Spacewar::G_CONST
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
class Player < Chingu::GameObject
|
128
|
+
has_trait :bounding_circle, :debug => $DEBUG
|
129
|
+
has_traits :collision_detection, :effect, :velocity
|
130
|
+
|
131
|
+
def initialize(input, options={})
|
132
|
+
super(options)
|
133
|
+
@image = Image[options[:image]]
|
134
|
+
self.input = input
|
135
|
+
self.max_velocity = 1
|
136
|
+
end
|
137
|
+
|
138
|
+
def accelerate
|
139
|
+
self.velocity_x += Gosu::offset_x(self.angle, 0.5) * self.max_velocity
|
140
|
+
self.velocity_y += Gosu::offset_y(self.angle, 0.5) * self.max_velocity
|
141
|
+
end
|
142
|
+
|
143
|
+
def turn_right
|
144
|
+
# The same can be achieved without trait 'effect' as: self.angle += 4.5
|
145
|
+
rotate(4.5)
|
146
|
+
end
|
147
|
+
|
148
|
+
def turn_left
|
149
|
+
# The same can be achieved without trait 'effect' as: self.angle -= 4.5
|
150
|
+
rotate(-4.5)
|
151
|
+
end
|
152
|
+
|
153
|
+
def update
|
154
|
+
self.velocity_x *= 0.99 # dampen the movement
|
155
|
+
self.velocity_y *= 0.99
|
156
|
+
|
157
|
+
@x %= $window.width # wrap around the screen
|
158
|
+
@y %= $window.height
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
class Planet < Chingu::GameObject
|
163
|
+
has_trait :bounding_circle, :debug => true
|
164
|
+
has_trait :collision_detection
|
165
|
+
|
166
|
+
def initialize(options = {})
|
167
|
+
super(:zorder => 1)
|
168
|
+
@image = Image["planet.png"]
|
169
|
+
self.color = Gosu::Color.new(0xff000000)
|
170
|
+
self.color.red = rand(255 - 40) + 40
|
171
|
+
self.color.green = rand(255 - 40) + 40
|
172
|
+
self.color.blue = rand(255 - 40) + 40
|
173
|
+
self.x = $window.width / 2
|
174
|
+
self.y = $window.height / 2
|
175
|
+
|
176
|
+
cache_bounding_circle
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
class Star < Chingu::GameObject
|
181
|
+
has_trait :bounding_circle, :debug => $DEBUG
|
182
|
+
has_traits :collision_detection, :velocity
|
183
|
+
|
184
|
+
def initialize(options={})
|
185
|
+
super(:zorder => 1)
|
186
|
+
@animation = Chingu::Animation.new(:file => media_path("Star.png"), :size => [25,25])
|
187
|
+
@image = @animation.next
|
188
|
+
self.color = Gosu::Color.new(0xff000000)
|
189
|
+
self.color.red = rand(255 - 40) + 40
|
190
|
+
self.color.green = rand(255 - 40) + 40
|
191
|
+
self.color.blue = rand(255 - 40) + 40
|
192
|
+
self.x = rand * $window.width
|
193
|
+
self.y = rand * $window.height
|
194
|
+
self.velocity_x = rand(10)
|
195
|
+
self.velocity_y = rand(10)
|
196
|
+
|
197
|
+
#
|
198
|
+
# A cached bounding circle will not adapt to changes in size, but it will follow objects X / Y
|
199
|
+
# Same is true for "cache_bounding_box"
|
200
|
+
#
|
201
|
+
cache_bounding_circle
|
202
|
+
end
|
203
|
+
|
204
|
+
def update
|
205
|
+
@x %= $window.width # wrap around the screen
|
206
|
+
@y %= $window.height
|
207
|
+
|
208
|
+
# Move the animation forward by fetching the next frame and putting it into @image
|
209
|
+
# @image is drawn by default by GameObject#draw
|
210
|
+
@image = @animation.next
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def self.play
|
215
|
+
Game.new.show
|
216
|
+
end
|
217
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spacewar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Edward Ocampo-Gooding
|
8
|
+
- John Duff
|
9
|
+
- Justin Bowes
|
10
|
+
- Chris Saunders
|
11
|
+
- Schwab
|
12
|
+
- Pranav Singh
|
13
|
+
- Dwayne Litzenberger
|
14
|
+
- Jean Claude Batista
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2009-12-24 00:00:00 -05:00
|
20
|
+
default_executable: spacewar
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: chingu
|
24
|
+
type: :runtime
|
25
|
+
version_requirement:
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 0.6.7
|
31
|
+
version:
|
32
|
+
description: A brave group-effort by the gentlemen at Ottawa.rb (aka OGRE), spacewar is a legitimate heir to the glory that is the original game you likely played on an xt or more ancient beast of a machine.
|
33
|
+
email: edward@edwardog.net
|
34
|
+
executables:
|
35
|
+
- spacewar
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files: []
|
39
|
+
|
40
|
+
files:
|
41
|
+
- Rakefile
|
42
|
+
- bin/spacewar
|
43
|
+
- lib/media/background1.png
|
44
|
+
- lib/media/bullet.png
|
45
|
+
- lib/media/bullet_hit.wav
|
46
|
+
- lib/media/circle.png
|
47
|
+
- lib/media/city1.csv
|
48
|
+
- lib/media/city1.png
|
49
|
+
- lib/media/city2.png
|
50
|
+
- lib/media/droid.bmp
|
51
|
+
- lib/media/enemy_bullet.png
|
52
|
+
- lib/media/explosion.wav
|
53
|
+
- lib/media/fire_bullet.png
|
54
|
+
- lib/media/fireball.png
|
55
|
+
- lib/media/foo
|
56
|
+
- lib/media/laser.wav
|
57
|
+
- lib/media/Parallax-scroll-example-layer-0.png
|
58
|
+
- lib/media/Parallax-scroll-example-layer-1.png
|
59
|
+
- lib/media/Parallax-scroll-example-layer-2.png
|
60
|
+
- lib/media/Parallax-scroll-example-layer-3.png
|
61
|
+
- lib/media/particle.png
|
62
|
+
- lib/media/plane.csv
|
63
|
+
- lib/media/plane.png
|
64
|
+
- lib/media/planet.png
|
65
|
+
- lib/media/rect.png
|
66
|
+
- lib/media/ruby.png
|
67
|
+
- lib/media/saucer.csv
|
68
|
+
- lib/media/saucer.gal
|
69
|
+
- lib/media/saucer.png
|
70
|
+
- lib/media/spaceship.png
|
71
|
+
- lib/media/Star.png
|
72
|
+
- lib/media/Starfighter.bmp
|
73
|
+
- lib/media/Starfighter_p1.bmp
|
74
|
+
- lib/media/Starfighter_p2.bmp
|
75
|
+
- lib/media/stickfigure.bmp
|
76
|
+
- lib/media/stickfigure.png
|
77
|
+
- lib/media/video_games.png
|
78
|
+
- lib/media/wood.png
|
79
|
+
- lib/spacewar/spacewar.rb
|
80
|
+
- lib/spacewar.rb
|
81
|
+
- test/helper.rb
|
82
|
+
- test/test_spacewar.rb
|
83
|
+
has_rdoc: false
|
84
|
+
homepage: http://github.com/edward/spacewar
|
85
|
+
licenses: []
|
86
|
+
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: "0"
|
97
|
+
version:
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: "0"
|
103
|
+
version:
|
104
|
+
requirements: []
|
105
|
+
|
106
|
+
rubyforge_project: spacewar
|
107
|
+
rubygems_version: 1.3.5
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: There are two spaceships, a planet, gravity, missiles, and lasers. Do the math.
|
111
|
+
test_files: []
|
112
|
+
|