gembots 0.1 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e7ee5cc5f03ca3b06cda8560005f4be2a60bbe8
4
- data.tar.gz: 1272a7b540898904aafe8c4635157fbdb7c3b4a7
3
+ metadata.gz: 4be29acf29ee4311539f3c2e8374881bf51299e9
4
+ data.tar.gz: 1229f2c5c5d1b91240ff1060bbeeb4d6e8bad372
5
5
  SHA512:
6
- metadata.gz: 51c394cac319498bc612fb43b9639e88fee49ca978c92ac372d9792c3a8894e4767588683407ab3eaee6346faf3d01aae7171a9cace938291d63fe03cb1e0c4d
7
- data.tar.gz: 1e79f3722a61bbd7cbdcacb25444ba2b638d26b989642d62f1c494b382479b9236c4dc2d7ca63c57709e2a08c5d5aa74e0d65ea25cf1a1238b031de86bb32df6
6
+ metadata.gz: 35df3db678bf53c2548d3d15c2652b6525b798cbec9d97f1b59596f0d834075a69e92c868c9b4ff36b31a4f33d3674f99a359d55a08dbe29a172c6b29a65de59
7
+ data.tar.gz: 42dbe16b897a16314a0a42010b383b68861120f7ab28ac020e070f156dc8fe251ed4da25072473a7e64f5ba3c17936eb2f0bbf2589d58b7516dfd59373386ec6
data/lib/gembots/arena.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  require 'gembots'
2
+ require 'gembots/projectile'
2
3
 
3
4
  class Gembots::Arena < Gosu::Window
4
5
  attr_reader :bots
6
+ attr_reader :arena
5
7
  def initialize *bots
6
8
  super 640, 480, false
7
9
  self.caption = "Gembots battle"
8
10
  @bots = []
11
+ @projs = []
9
12
 
10
13
  bots.each do |bot_class|
11
14
  bot = bot_class.new self
@@ -16,18 +19,29 @@ class Gembots::Arena < Gosu::Window
16
19
 
17
20
  def draw
18
21
  @bots.each &:draw
22
+ @projs.each &:draw
19
23
  end
20
24
 
21
25
  def update
22
26
  @bots.each &:update
23
27
  @bots.each do |bot|
24
- if bot.actions.empty?
25
- bot.on_idle
28
+ bot.on_idle if bot.actions.empty?
29
+ @projs.each do |proj|
30
+ if (Gosu::distance bot.x, bot.y, proj.x, proj.y) < 10
31
+ @bots.delete bot
32
+ @projs.delete proj
33
+ end
26
34
  end
27
35
  end
36
+
37
+ @projs.each &:update
28
38
  end
29
39
 
30
40
  def button_down id
31
41
  close if id == Gosu::KbEscape
32
42
  end
43
+
44
+ def spawn_proj bot
45
+ @projs << Gembots::Projectile.new(self, bot.x, bot.y, bot.angle)
46
+ end
33
47
  end
data/lib/gembots/bot.rb CHANGED
@@ -49,6 +49,10 @@ class Gembots::Robot
49
49
  @actions[0][1] -= deg
50
50
 
51
51
  @actions.shift if @actions[0][1] == 0
52
+
53
+ when :fire
54
+ @window.spawn_proj self
55
+ @actions.shift
52
56
  end
53
57
  end
54
58
 
@@ -56,4 +60,8 @@ class Gembots::Robot
56
60
  @images[@cur_image].draw_rot @x, @y, 1, @angle - 90 % 360
57
61
  @image.draw_rot @x, @y, 1, @angle - 90 % 360
58
62
  end
63
+
64
+ def fire
65
+ @actions << [:fire]
66
+ end
59
67
  end
data/test/test_arena.rb CHANGED
@@ -5,15 +5,16 @@ require 'gembots/bot'
5
5
 
6
6
  class MyBot1 < Gembots::Robot
7
7
  def on_idle
8
- self.move
9
- self.turn
8
+ self.move 50
9
+ self.turn 180
10
+ self.fire
10
11
  end
11
12
  end
12
13
 
13
14
  class MyBot2 < Gembots::Robot
14
15
  def on_idle
15
- self.move 50
16
16
  self.turn 180
17
+ self.move 50
17
18
  end
18
19
  end
19
20
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gembots
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - L8D