gembots 0.1 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gembots/arena.rb +16 -2
- data/lib/gembots/bot.rb +8 -0
- data/test/test_arena.rb +4 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4be29acf29ee4311539f3c2e8374881bf51299e9
|
4
|
+
data.tar.gz: 1229f2c5c5d1b91240ff1060bbeeb4d6e8bad372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
|