gembots 0.1.1 → 0.1.2

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: 4be29acf29ee4311539f3c2e8374881bf51299e9
4
- data.tar.gz: 1229f2c5c5d1b91240ff1060bbeeb4d6e8bad372
3
+ metadata.gz: ad9de32649b753655ebb462ea3f56dc2f2227e83
4
+ data.tar.gz: 74426bf3ccbdf33f3357bf28c6c8c248f47b397e
5
5
  SHA512:
6
- metadata.gz: 35df3db678bf53c2548d3d15c2652b6525b798cbec9d97f1b59596f0d834075a69e92c868c9b4ff36b31a4f33d3674f99a359d55a08dbe29a172c6b29a65de59
7
- data.tar.gz: 42dbe16b897a16314a0a42010b383b68861120f7ab28ac020e070f156dc8fe251ed4da25072473a7e64f5ba3c17936eb2f0bbf2589d58b7516dfd59373386ec6
6
+ metadata.gz: c1e86f79ca9ab9ae37c6306c9f7f81e45b6eba6ab929ebfb92ca85ac7948120ab1e687e34709940a52e2f632c2a81638998c13bb625928af39eb2c20084b2643
7
+ data.tar.gz: 2fdf7b3c7e5a9fb8f380eab5257ca3fb68ab4d10d0338c7e00b6807f86d650ac7e2e6cddd13f3d01782a166ff054f9a4f89043b91117af7425d95f7440e633dc
@@ -1,9 +1,11 @@
1
1
  require 'gembots'
2
2
  require 'gembots/projectile'
3
3
 
4
+ # Class used for initializing the arena and opening the window.
4
5
  class Gembots::Arena < Gosu::Window
6
+ # Array containing an instance of each bot in the arena
5
7
  attr_reader :bots
6
- attr_reader :arena
8
+
7
9
  def initialize *bots
8
10
  super 640, 480, false
9
11
  self.caption = "Gembots battle"
@@ -17,15 +19,23 @@ class Gembots::Arena < Gosu::Window
17
19
  end
18
20
  end
19
21
 
22
+ # Method called via Gosu.
23
+ # It simply calls the draw method for each projectile and bot.
20
24
  def draw
21
25
  @bots.each &:draw
22
26
  @projs.each &:draw
23
27
  end
24
28
 
29
+ # Method called via Gosu.
30
+ # It calls the update method for each projectile and bot.
31
+ # It also checks to see if a projectile has hit a bot, and deletes the bot and projectile if it has.
25
32
  def update
26
33
  @bots.each &:update
34
+ @projs.each &:update
35
+
27
36
  @bots.each do |bot|
28
37
  bot.on_idle if bot.actions.empty?
38
+
29
39
  @projs.each do |proj|
30
40
  if (Gosu::distance bot.x, bot.y, proj.x, proj.y) < 10
31
41
  @bots.delete bot
@@ -33,14 +43,15 @@ class Gembots::Arena < Gosu::Window
33
43
  end
34
44
  end
35
45
  end
36
-
37
- @projs.each &:update
38
46
  end
39
47
 
48
+ # Method called via Gosu.
49
+ # If the escape key is pressed, then the window closes.
40
50
  def button_down id
41
51
  close if id == Gosu::KbEscape
42
52
  end
43
53
 
54
+ # Spawns a Projectile instance at bot's position and angle.
44
55
  def spawn_proj bot
45
56
  @projs << Gembots::Projectile.new(self, bot.x, bot.y, bot.angle)
46
57
  end
@@ -1,9 +1,20 @@
1
1
  require 'gembots'
2
2
 
3
+ # Class used for creating a robot.
3
4
  class Gembots::Robot
4
- attr_reader :x, :y, :angle, :actions
5
+ # X and Y positions
6
+ attr_reader :x, :y
5
7
 
8
+ # Current angle of robot.
9
+ attr_reader :angle
10
+
11
+ # Array containing arrays that represent actions that need to be completed.
12
+ # The format is like: `[[:move, 10], [:turn, 90]]`, meaning the robot will move 10 forward, then turn 90 degrees clockwise.
13
+ attr_reader :actions
14
+
15
+ # Creates a new instance of the robot.
6
16
  def initialize window
17
+ @warped = false
7
18
  @actions = []
8
19
  @window = window
9
20
  @images = Gosu::Image::load_tiles(window, "media/tank.png", 32, 32, false)
@@ -11,18 +22,32 @@ class Gembots::Robot
11
22
  @x = @y = @angle = @cur_image = 0.0
12
23
  end
13
24
 
25
+ # Method called via the arena.
26
+ # Warps the robot to the position specified.
14
27
  def warp x, y
15
- @x, @y = x, y
28
+ @x, @y = x, y unless @warped
29
+ @warped = true
16
30
  end
17
31
 
32
+ # Appends a turn action to the actions array.
33
+ # The update method will turn the robot clockwise for the degree specified.
34
+ # If the degree is not specified, it defaults to 10.
35
+ # Use a negative value to rotate counter-clockwise.
18
36
  def turn angle=10
19
37
  @actions << [:turn, angle]
20
38
  end
21
39
 
40
+ # Appends a move action to the actions array.
41
+ # The update method will move the robot forward the distance specified.
42
+ # If the distance is not specified, it defaults to 10.
43
+ # Use a negative value to move in reverse.
22
44
  def move dist=10
23
45
  @actions << [:move, dist]
24
46
  end
25
47
 
48
+ # Method called via the arena.
49
+ # This attempts to preform the first action in the actions array.
50
+ # If it finishes the action, it will pop that actions from the actions array, allowing it to preform the next.
26
51
  def update
27
52
  return if @actions.empty?
28
53
  case @actions[0][0]
@@ -56,11 +81,14 @@ class Gembots::Robot
56
81
  end
57
82
  end
58
83
 
84
+ # Method called via the arena.
59
85
  def draw
60
86
  @images[@cur_image].draw_rot @x, @y, 1, @angle - 90 % 360
61
87
  @image.draw_rot @x, @y, 1, @angle - 90 % 360
62
88
  end
63
89
 
90
+ # Appends a fire action to the actions array.
91
+ # The update method will call the arena's spawn_proj method.
64
92
  def fire
65
93
  @actions << [:fire]
66
94
  end
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.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - L8D