tank_island 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.ruby-version +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +22 -0
  6. data/README.md +58 -0
  7. data/Rakefile +2 -0
  8. data/bin/tank_island +30 -0
  9. data/lib/entities/box.rb +28 -0
  10. data/lib/entities/bullet.rb +26 -0
  11. data/lib/entities/camera.rb +113 -0
  12. data/lib/entities/components/ai/gun.rb +114 -0
  13. data/lib/entities/components/ai/tank_chasing_state.rb +30 -0
  14. data/lib/entities/components/ai/tank_fighting_state.rb +47 -0
  15. data/lib/entities/components/ai/tank_fleeing_state.rb +50 -0
  16. data/lib/entities/components/ai/tank_motion_fsm.rb +102 -0
  17. data/lib/entities/components/ai/tank_motion_state.rb +84 -0
  18. data/lib/entities/components/ai/tank_navigating_state.rb +34 -0
  19. data/lib/entities/components/ai/tank_roaming_state.rb +83 -0
  20. data/lib/entities/components/ai/tank_stuck_state.rb +45 -0
  21. data/lib/entities/components/ai/vision.rb +109 -0
  22. data/lib/entities/components/ai_input.rb +70 -0
  23. data/lib/entities/components/box_graphics.rb +39 -0
  24. data/lib/entities/components/bullet_graphics.rb +13 -0
  25. data/lib/entities/components/bullet_physics.rb +65 -0
  26. data/lib/entities/components/bullet_sounds.rb +15 -0
  27. data/lib/entities/components/component.rb +32 -0
  28. data/lib/entities/components/damage_graphics.rb +20 -0
  29. data/lib/entities/components/explosion_graphics.rb +43 -0
  30. data/lib/entities/components/explosion_sounds.rb +16 -0
  31. data/lib/entities/components/health.rb +87 -0
  32. data/lib/entities/components/player_input.rb +100 -0
  33. data/lib/entities/components/player_sounds.rb +16 -0
  34. data/lib/entities/components/powerup_graphics.rb +22 -0
  35. data/lib/entities/components/powerup_sounds.rb +15 -0
  36. data/lib/entities/components/tank_graphics.rb +46 -0
  37. data/lib/entities/components/tank_health.rb +32 -0
  38. data/lib/entities/components/tank_physics.rb +179 -0
  39. data/lib/entities/components/tank_sounds.rb +43 -0
  40. data/lib/entities/components/tree_graphics.rb +69 -0
  41. data/lib/entities/damage.rb +26 -0
  42. data/lib/entities/explosion.rb +34 -0
  43. data/lib/entities/game_object.rb +54 -0
  44. data/lib/entities/hud.rb +79 -0
  45. data/lib/entities/map.rb +183 -0
  46. data/lib/entities/object_pool.rb +59 -0
  47. data/lib/entities/powerups/fire_rate_powerup.rb +14 -0
  48. data/lib/entities/powerups/health_powerup.rb +12 -0
  49. data/lib/entities/powerups/powerup.rb +35 -0
  50. data/lib/entities/powerups/powerup_respawn_queue.rb +23 -0
  51. data/lib/entities/powerups/repair_powerup.rb +14 -0
  52. data/lib/entities/powerups/tank_speed_powerup.rb +14 -0
  53. data/lib/entities/radar.rb +62 -0
  54. data/lib/entities/score_display.rb +35 -0
  55. data/lib/entities/tank.rb +64 -0
  56. data/lib/entities/tree.rb +18 -0
  57. data/lib/game_states/demo_state.rb +49 -0
  58. data/lib/game_states/game_state.rb +27 -0
  59. data/lib/game_states/menu_state.rb +60 -0
  60. data/lib/game_states/pause_state.rb +61 -0
  61. data/lib/game_states/play_state.rb +119 -0
  62. data/lib/misc/axis_aligned_bounding_box.rb +33 -0
  63. data/lib/misc/game_window.rb +30 -0
  64. data/lib/misc/names.rb +13 -0
  65. data/lib/misc/quad_tree.rb +91 -0
  66. data/lib/misc/stats.rb +55 -0
  67. data/lib/misc/stereo_sample.rb +96 -0
  68. data/lib/misc/utils.rb +145 -0
  69. data/media/armalite_rifle.ttf +0 -0
  70. data/media/boxes_barrels.json +60 -0
  71. data/media/boxes_barrels.png +0 -0
  72. data/media/bullet.png +0 -0
  73. data/media/c_dot.png +0 -0
  74. data/media/country_field.png +0 -0
  75. data/media/crash.ogg +0 -0
  76. data/media/damage1.png +0 -0
  77. data/media/damage2.png +0 -0
  78. data/media/damage3.png +0 -0
  79. data/media/damage4.png +0 -0
  80. data/media/decor.json +516 -0
  81. data/media/decor.png +0 -0
  82. data/media/decor.psd +0 -0
  83. data/media/explosion.mp3 +0 -0
  84. data/media/explosion.png +0 -0
  85. data/media/fire.mp3 +0 -0
  86. data/media/ground.json +492 -0
  87. data/media/ground.png +0 -0
  88. data/media/ground_units.json +900 -0
  89. data/media/ground_units.png +0 -0
  90. data/media/menu_music.mp3 +0 -0
  91. data/media/metal_interaction2.wav +0 -0
  92. data/media/names.txt +279 -0
  93. data/media/pickups.json +68 -0
  94. data/media/pickups.png +0 -0
  95. data/media/powerup.mp3 +0 -0
  96. data/media/respawn.wav +0 -0
  97. data/media/tank_driving.mp3 +0 -0
  98. data/media/top_secret.ttf +0 -0
  99. data/media/trees.png +0 -0
  100. data/media/trees_packed.json +388 -0
  101. data/media/trees_packed.png +0 -0
  102. data/media/water.png +0 -0
  103. data/spec/misc/aabb_spec.rb +85 -0
  104. data/spec/misc/quad_tree_spec.rb +137 -0
  105. data/tank_island.gemspec +29 -0
  106. metadata +223 -0
Binary file
Binary file
@@ -0,0 +1,85 @@
1
+ require_relative '../../lib/misc/axis_aligned_bounding_box'
2
+ describe AxisAlignedBoundingBox do
3
+
4
+ let(:center) { [5, 5] }
5
+ let(:half_dimension) { [10, 10] }
6
+ let(:box) { AxisAlignedBoundingBox.new(
7
+ center, half_dimension) }
8
+
9
+ let(:point1) { [4, 7] }
10
+ let(:point2) { [0, 0] }
11
+ let(:point3) { [10, 10] }
12
+ let(:point4) { [0, 10] }
13
+ let(:point5) { [10, 0] }
14
+
15
+ let(:point6) { [-2, 7] }
16
+ let(:point7) { [0, 11] }
17
+ let(:point8) { [11, 11] }
18
+ let(:point9) { [0, 11] }
19
+ let(:point10) { [11, 0] }
20
+ let(:point11) { [3, 15] }
21
+ let(:point12) { [11, 4] }
22
+ let(:point13) { [1, -4] }
23
+ let(:point14) { [-1, -4] }
24
+
25
+ describe '#contains?' do
26
+ it 'detects containing point' do
27
+ expect(box.contains?(point1)).to be_truthy
28
+ expect(box.contains?(point2)).to be_truthy
29
+ expect(box.contains?(point3)).to be_truthy
30
+ expect(box.contains?(point4)).to be_truthy
31
+ expect(box.contains?(point5)).to be_truthy
32
+ end
33
+
34
+ it 'does not detect points out of bounds' do
35
+ expect(box.contains?(point6)).to be_falsy
36
+ expect(box.contains?(point8)).to be_falsy
37
+ expect(box.contains?(point7)).to be_falsy
38
+ expect(box.contains?(point9)).to be_falsy
39
+ expect(box.contains?(point10)).to be_falsy
40
+ expect(box.contains?(point11)).to be_falsy
41
+ expect(box.contains?(point12)).to be_falsy
42
+ expect(box.contains?(point13)).to be_falsy
43
+ expect(box.contains?(point14)).to be_falsy
44
+ end
45
+ end
46
+
47
+ describe '#intersects?' do
48
+ # center within box
49
+ let(:box1) { AxisAlignedBoundingBox.new(
50
+ [8, 8], [10, 12]) }
51
+ # center out of boundaries
52
+ let(:box2) { AxisAlignedBoundingBox.new(
53
+ [12, 12], [15, 15]) }
54
+ let(:box2_1) { AxisAlignedBoundingBox.new(
55
+ [-5, -5], [1, 1]) }
56
+ # touching corners
57
+ let(:box3) { AxisAlignedBoundingBox.new(
58
+ [-1, -1], [0, 0]) }
59
+ # out of bounds
60
+ let(:box4) { AxisAlignedBoundingBox.new(
61
+ [15, 15], [17, 17]) }
62
+ let(:box5) { AxisAlignedBoundingBox.new(
63
+ [-5, -5], [-1, -1]) }
64
+ let(:box6) { AxisAlignedBoundingBox.new(
65
+ [5, 12], [6, 13]) }
66
+
67
+
68
+ it 'intersects with itself' do
69
+ expect(box.intersects?(box)).to be_truthy
70
+ end
71
+
72
+ it 'detects intersecting boxes' do
73
+ expect(box.intersects?(box1)).to be_truthy
74
+ expect(box.intersects?(box2)).to be_truthy
75
+ expect(box.intersects?(box2_1)).to be_truthy
76
+ expect(box.intersects?(box3)).to be_truthy
77
+ end
78
+
79
+ it 'does not detect interesections out of bounds' do
80
+ expect(box.intersects?(box4)).to be_falsy
81
+ expect(box.intersects?(box5)).to be_falsy
82
+ expect(box.intersects?(box6)).to be_falsy
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,137 @@
1
+ class GameObject
2
+ attr_accessor :x, :y
3
+ def initialize(x, y)
4
+ @x, @y = x, y
5
+ end
6
+
7
+ def location
8
+ [@x, @y]
9
+ end
10
+ end
11
+
12
+ require_relative '../../lib/misc/axis_aligned_bounding_box'
13
+ require_relative '../../lib/misc/quad_tree'
14
+
15
+ describe QuadTree do
16
+ let(:box) { AxisAlignedBoundingBox.new(
17
+ [5, 5], [10, 10]) }
18
+ let(:tree) { QuadTree.new(box) }
19
+
20
+ let(:location) { [5, 5] }
21
+ let(:object) { GameObject.new(*location) }
22
+
23
+ describe '#insert' do
24
+ subject { tree.insert(object) }
25
+
26
+ context 'around zero coordinates' do
27
+ let(:box) { AxisAlignedBoundingBox.new(
28
+ [0, 0], [10, 10]) }
29
+ let(:location) { [0, 0] }
30
+
31
+ it 'inserts in the middle' do
32
+ expect(subject).to be_truthy
33
+ end
34
+ end
35
+
36
+ context 'object in center' do
37
+ it 'gets inserted' do
38
+ expect(subject).to be_truthy
39
+ end
40
+ end
41
+
42
+ context 'object in corner' do
43
+ let(:location) { [10, 10] }
44
+ it 'gets inserted' do
45
+ expect(subject).to be_truthy
46
+ end
47
+ end
48
+
49
+ context 'object out of bounds' do
50
+ let(:location) { [11, 11] }
51
+ it 'does not get inserted' do
52
+ expect(subject).to be_falsy
53
+ end
54
+ end
55
+
56
+ context 'several objects' do
57
+ subject { tree.query_range(box) }
58
+ context 'to different locations' do
59
+ before do
60
+ 50.times do |i|
61
+ tree.insert(
62
+ GameObject.new(
63
+ rand(0..10),
64
+ rand(0..10)))
65
+ end
66
+ end
67
+ it 'inserts all' do
68
+ expect(subject.size).to eq 50
69
+ end
70
+ end
71
+
72
+ context 'to same location' do
73
+ before { 5.times { tree.insert(object.dup) } }
74
+
75
+ it 'still inserts all' do
76
+ expect(subject.size).to eq 5
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ describe '#query_range' do
83
+ let(:query_params) { [[5, 5], [10, 10]] }
84
+ let(:query_box) { AxisAlignedBoundingBox.new(*query_params) }
85
+ subject { tree.query_range(query_box) }
86
+
87
+ context 'empty tree' do
88
+ it 'returns empty array' do
89
+ should be_empty
90
+ end
91
+ end
92
+
93
+ context 'single object' do
94
+ before { tree.insert(object) }
95
+
96
+ context 'is found' do
97
+ let(:query_params) do
98
+ [object.location, object.location.map { |c| c + 1 }]
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ describe '#remove' do
105
+ context 'single object' do
106
+ before do
107
+ tree.insert(object)
108
+ tree.remove(object)
109
+ end
110
+ subject { tree.query_range(box) }
111
+
112
+ it 'removes it' do
113
+ expect(subject.size).to equal(0)
114
+ end
115
+ end
116
+
117
+ context 'all objects' do
118
+ before do
119
+ 50.times do
120
+ tree.insert(
121
+ GameObject.new(
122
+ rand(0..10),
123
+ rand(0..10)))
124
+ end
125
+ end
126
+ subject { tree.query_range(box) }
127
+
128
+ it 'removes it' do
129
+ expect(subject.size).to equal(50)
130
+ subject.each do |ob|
131
+ expect(tree.remove(ob)).to be_truthy
132
+ end
133
+ expect(tree.query_range(box).size).to equal(0)
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "tank_island"
7
+ spec.version = '1.0.0'
8
+ spec.authors = ["Tomas Varaneckas"]
9
+ spec.email = ["tomas.varaneckas@gmail.com"]
10
+ spec.summary = %q{Top down 2D shooter game that involves blowing up tanks}
11
+ spec.description = <<-EOS
12
+ This is a game built with Gosu library while writing "Developing Games With Ruby" book.
13
+ You can get the book at https://leanpub.com/developing-games-with-ruby
14
+ EOS
15
+ spec.homepage = "https://leanpub.com/developing-games-with-ruby"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+
26
+ spec.add_runtime_dependency 'gosu'
27
+ spec.add_runtime_dependency 'gosu_texture_packer'
28
+ spec.add_runtime_dependency 'perlin_noise'
29
+ end
metadata ADDED
@@ -0,0 +1,223 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tank_island
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Varaneckas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: gosu
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: gosu_texture_packer
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: perlin_noise
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |2
84
+ This is a game built with Gosu library while writing "Developing Games With Ruby" book.
85
+ You can get the book at https://leanpub.com/developing-games-with-ruby
86
+ email:
87
+ - tomas.varaneckas@gmail.com
88
+ executables:
89
+ - tank_island
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - ".ruby-version"
95
+ - Gemfile
96
+ - LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - bin/tank_island
100
+ - lib/entities/box.rb
101
+ - lib/entities/bullet.rb
102
+ - lib/entities/camera.rb
103
+ - lib/entities/components/ai/gun.rb
104
+ - lib/entities/components/ai/tank_chasing_state.rb
105
+ - lib/entities/components/ai/tank_fighting_state.rb
106
+ - lib/entities/components/ai/tank_fleeing_state.rb
107
+ - lib/entities/components/ai/tank_motion_fsm.rb
108
+ - lib/entities/components/ai/tank_motion_state.rb
109
+ - lib/entities/components/ai/tank_navigating_state.rb
110
+ - lib/entities/components/ai/tank_roaming_state.rb
111
+ - lib/entities/components/ai/tank_stuck_state.rb
112
+ - lib/entities/components/ai/vision.rb
113
+ - lib/entities/components/ai_input.rb
114
+ - lib/entities/components/box_graphics.rb
115
+ - lib/entities/components/bullet_graphics.rb
116
+ - lib/entities/components/bullet_physics.rb
117
+ - lib/entities/components/bullet_sounds.rb
118
+ - lib/entities/components/component.rb
119
+ - lib/entities/components/damage_graphics.rb
120
+ - lib/entities/components/explosion_graphics.rb
121
+ - lib/entities/components/explosion_sounds.rb
122
+ - lib/entities/components/health.rb
123
+ - lib/entities/components/player_input.rb
124
+ - lib/entities/components/player_sounds.rb
125
+ - lib/entities/components/powerup_graphics.rb
126
+ - lib/entities/components/powerup_sounds.rb
127
+ - lib/entities/components/tank_graphics.rb
128
+ - lib/entities/components/tank_health.rb
129
+ - lib/entities/components/tank_physics.rb
130
+ - lib/entities/components/tank_sounds.rb
131
+ - lib/entities/components/tree_graphics.rb
132
+ - lib/entities/damage.rb
133
+ - lib/entities/explosion.rb
134
+ - lib/entities/game_object.rb
135
+ - lib/entities/hud.rb
136
+ - lib/entities/map.rb
137
+ - lib/entities/object_pool.rb
138
+ - lib/entities/powerups/fire_rate_powerup.rb
139
+ - lib/entities/powerups/health_powerup.rb
140
+ - lib/entities/powerups/powerup.rb
141
+ - lib/entities/powerups/powerup_respawn_queue.rb
142
+ - lib/entities/powerups/repair_powerup.rb
143
+ - lib/entities/powerups/tank_speed_powerup.rb
144
+ - lib/entities/radar.rb
145
+ - lib/entities/score_display.rb
146
+ - lib/entities/tank.rb
147
+ - lib/entities/tree.rb
148
+ - lib/game_states/demo_state.rb
149
+ - lib/game_states/game_state.rb
150
+ - lib/game_states/menu_state.rb
151
+ - lib/game_states/pause_state.rb
152
+ - lib/game_states/play_state.rb
153
+ - lib/misc/axis_aligned_bounding_box.rb
154
+ - lib/misc/game_window.rb
155
+ - lib/misc/names.rb
156
+ - lib/misc/quad_tree.rb
157
+ - lib/misc/stats.rb
158
+ - lib/misc/stereo_sample.rb
159
+ - lib/misc/utils.rb
160
+ - media/armalite_rifle.ttf
161
+ - media/boxes_barrels.json
162
+ - media/boxes_barrels.png
163
+ - media/bullet.png
164
+ - media/c_dot.png
165
+ - media/country_field.png
166
+ - media/crash.ogg
167
+ - media/damage1.png
168
+ - media/damage2.png
169
+ - media/damage3.png
170
+ - media/damage4.png
171
+ - media/decor.json
172
+ - media/decor.png
173
+ - media/decor.psd
174
+ - media/explosion.mp3
175
+ - media/explosion.png
176
+ - media/fire.mp3
177
+ - media/ground.json
178
+ - media/ground.png
179
+ - media/ground_units.json
180
+ - media/ground_units.png
181
+ - media/menu_music.mp3
182
+ - media/metal_interaction2.wav
183
+ - media/names.txt
184
+ - media/pickups.json
185
+ - media/pickups.png
186
+ - media/powerup.mp3
187
+ - media/respawn.wav
188
+ - media/tank_driving.mp3
189
+ - media/top_secret.ttf
190
+ - media/trees.png
191
+ - media/trees_packed.json
192
+ - media/trees_packed.png
193
+ - media/water.png
194
+ - spec/misc/aabb_spec.rb
195
+ - spec/misc/quad_tree_spec.rb
196
+ - tank_island.gemspec
197
+ homepage: https://leanpub.com/developing-games-with-ruby
198
+ licenses:
199
+ - MIT
200
+ metadata: {}
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ requirements: []
216
+ rubyforge_project:
217
+ rubygems_version: 2.2.2
218
+ signing_key:
219
+ specification_version: 4
220
+ summary: Top down 2D shooter game that involves blowing up tanks
221
+ test_files:
222
+ - spec/misc/aabb_spec.rb
223
+ - spec/misc/quad_tree_spec.rb