UG_RRobots 2.0 → 2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. data/Rakefile +20 -4
  2. data/bin/rrobots +48 -17
  3. data/config/locales/en.yml +4 -2
  4. data/config/locales/fr.yml +3 -1
  5. data/doc/install.rdoc +20 -20
  6. data/doc/install_fr.rdoc +20 -20
  7. data/lib/GUI/gosu.rb +237 -0
  8. data/lib/GUI/tk.rb +215 -0
  9. data/lib/battlefield.rb +2 -0
  10. data/lib/mines.rb +36 -0
  11. data/lib/misc.rb +7 -4
  12. data/lib/robotrunner.rb +4 -0
  13. data/medias/gosu/images/blue_body000.bmp +0 -0
  14. data/medias/gosu/images/blue_radar000.bmp +0 -0
  15. data/medias/gosu/images/blue_turret000.bmp +0 -0
  16. data/medias/gosu/images/bullet.png +0 -0
  17. data/medias/gosu/images/explosion00.bmp +0 -0
  18. data/medias/gosu/images/explosion01.bmp +0 -0
  19. data/medias/gosu/images/explosion02.bmp +0 -0
  20. data/medias/gosu/images/explosion03.bmp +0 -0
  21. data/medias/gosu/images/explosion04.bmp +0 -0
  22. data/medias/gosu/images/explosion05.bmp +0 -0
  23. data/medias/gosu/images/explosion06.bmp +0 -0
  24. data/medias/gosu/images/explosion07.bmp +0 -0
  25. data/medias/gosu/images/explosion08.bmp +0 -0
  26. data/medias/gosu/images/explosion09.bmp +0 -0
  27. data/medias/gosu/images/explosion10.bmp +0 -0
  28. data/medias/gosu/images/explosion11.bmp +0 -0
  29. data/medias/gosu/images/explosion12.bmp +0 -0
  30. data/medias/gosu/images/explosion13.bmp +0 -0
  31. data/medias/gosu/images/explosion14.bmp +0 -0
  32. data/medias/gosu/images/lime_body000.bmp +0 -0
  33. data/medias/gosu/images/lime_radar000.bmp +0 -0
  34. data/medias/gosu/images/lime_turret000.bmp +0 -0
  35. data/medias/gosu/images/mine.png +0 -0
  36. data/medias/gosu/images/red_body000.bmp +0 -0
  37. data/medias/gosu/images/red_radar000.bmp +0 -0
  38. data/medias/gosu/images/red_turret000.bmp +0 -0
  39. data/medias/gosu/images/space.png +0 -0
  40. data/medias/gosu/images/toolbox.png +0 -0
  41. data/medias/gosu/images/white_body000.bmp +0 -0
  42. data/medias/gosu/images/white_radar000.bmp +0 -0
  43. data/medias/gosu/images/white_turret000.bmp +0 -0
  44. data/medias/gosu/images/yellow_body000.bmp +0 -0
  45. data/medias/gosu/images/yellow_radar000.bmp +0 -0
  46. data/medias/gosu/images/yellow_turret000.bmp +0 -0
  47. data/medias/gosu/music/song.mod +0 -0
  48. data/medias/gosu/sounds/shotborn.wav +0 -0
  49. data/medias/gosu/sounds/sunexp.wav +0 -0
  50. data/{images → medias/tk/images}/explosion00.gif +0 -0
  51. data/{images → medias/tk/images}/explosion01.gif +0 -0
  52. data/{images → medias/tk/images}/explosion02.gif +0 -0
  53. data/{images → medias/tk/images}/explosion03.gif +0 -0
  54. data/{images → medias/tk/images}/explosion04.gif +0 -0
  55. data/{images → medias/tk/images}/explosion05.gif +0 -0
  56. data/{images → medias/tk/images}/explosion06.gif +0 -0
  57. data/{images → medias/tk/images}/explosion07.gif +0 -0
  58. data/{images → medias/tk/images}/explosion08.gif +0 -0
  59. data/{images → medias/tk/images}/explosion09.gif +0 -0
  60. data/{images → medias/tk/images}/explosion10.gif +0 -0
  61. data/{images → medias/tk/images}/explosion11.gif +0 -0
  62. data/{images → medias/tk/images}/explosion12.gif +0 -0
  63. data/{images → medias/tk/images}/explosion13.gif +0 -0
  64. data/{images → medias/tk/images}/explosion14.gif +0 -0
  65. data/medias/tk/images/mine.gif +0 -0
  66. data/{images → medias/tk/images}/red_body000.gif +0 -0
  67. data/{images → medias/tk/images}/red_body010.gif +0 -0
  68. data/{images → medias/tk/images}/red_body020.gif +0 -0
  69. data/{images → medias/tk/images}/red_body030.gif +0 -0
  70. data/{images → medias/tk/images}/red_body040.gif +0 -0
  71. data/{images → medias/tk/images}/red_body050.gif +0 -0
  72. data/{images → medias/tk/images}/red_body060.gif +0 -0
  73. data/{images → medias/tk/images}/red_body070.gif +0 -0
  74. data/{images → medias/tk/images}/red_body080.gif +0 -0
  75. data/{images → medias/tk/images}/red_body090.gif +0 -0
  76. data/{images → medias/tk/images}/red_body100.gif +0 -0
  77. data/{images → medias/tk/images}/red_body110.gif +0 -0
  78. data/{images → medias/tk/images}/red_body120.gif +0 -0
  79. data/{images → medias/tk/images}/red_body130.gif +0 -0
  80. data/{images → medias/tk/images}/red_body140.gif +0 -0
  81. data/{images → medias/tk/images}/red_body150.gif +0 -0
  82. data/{images → medias/tk/images}/red_body160.gif +0 -0
  83. data/{images → medias/tk/images}/red_body170.gif +0 -0
  84. data/{images → medias/tk/images}/red_body180.gif +0 -0
  85. data/{images → medias/tk/images}/red_body190.gif +0 -0
  86. data/{images → medias/tk/images}/red_body200.gif +0 -0
  87. data/{images → medias/tk/images}/red_body210.gif +0 -0
  88. data/{images → medias/tk/images}/red_body220.gif +0 -0
  89. data/{images → medias/tk/images}/red_body230.gif +0 -0
  90. data/{images → medias/tk/images}/red_body240.gif +0 -0
  91. data/{images → medias/tk/images}/red_body250.gif +0 -0
  92. data/{images → medias/tk/images}/red_body260.gif +0 -0
  93. data/{images → medias/tk/images}/red_body270.gif +0 -0
  94. data/{images → medias/tk/images}/red_body280.gif +0 -0
  95. data/{images → medias/tk/images}/red_body290.gif +0 -0
  96. data/{images → medias/tk/images}/red_body300.gif +0 -0
  97. data/{images → medias/tk/images}/red_body310.gif +0 -0
  98. data/{images → medias/tk/images}/red_body320.gif +0 -0
  99. data/{images → medias/tk/images}/red_body330.gif +0 -0
  100. data/{images → medias/tk/images}/red_body340.gif +0 -0
  101. data/{images → medias/tk/images}/red_body350.gif +0 -0
  102. data/{images → medias/tk/images}/red_radar000.gif +0 -0
  103. data/{images → medias/tk/images}/red_radar010.gif +0 -0
  104. data/{images → medias/tk/images}/red_radar020.gif +0 -0
  105. data/{images → medias/tk/images}/red_radar030.gif +0 -0
  106. data/{images → medias/tk/images}/red_radar040.gif +0 -0
  107. data/{images → medias/tk/images}/red_radar050.gif +0 -0
  108. data/{images → medias/tk/images}/red_radar060.gif +0 -0
  109. data/{images → medias/tk/images}/red_radar070.gif +0 -0
  110. data/{images → medias/tk/images}/red_radar080.gif +0 -0
  111. data/{images → medias/tk/images}/red_radar090.gif +0 -0
  112. data/{images → medias/tk/images}/red_radar100.gif +0 -0
  113. data/{images → medias/tk/images}/red_radar110.gif +0 -0
  114. data/{images → medias/tk/images}/red_radar120.gif +0 -0
  115. data/{images → medias/tk/images}/red_radar130.gif +0 -0
  116. data/{images → medias/tk/images}/red_radar140.gif +0 -0
  117. data/{images → medias/tk/images}/red_radar150.gif +0 -0
  118. data/{images → medias/tk/images}/red_radar160.gif +0 -0
  119. data/{images → medias/tk/images}/red_radar170.gif +0 -0
  120. data/{images → medias/tk/images}/red_radar180.gif +0 -0
  121. data/{images → medias/tk/images}/red_radar190.gif +0 -0
  122. data/{images → medias/tk/images}/red_radar200.gif +0 -0
  123. data/{images → medias/tk/images}/red_radar210.gif +0 -0
  124. data/{images → medias/tk/images}/red_radar220.gif +0 -0
  125. data/{images → medias/tk/images}/red_radar230.gif +0 -0
  126. data/{images → medias/tk/images}/red_radar240.gif +0 -0
  127. data/{images → medias/tk/images}/red_radar250.gif +0 -0
  128. data/{images → medias/tk/images}/red_radar260.gif +0 -0
  129. data/{images → medias/tk/images}/red_radar270.gif +0 -0
  130. data/{images → medias/tk/images}/red_radar280.gif +0 -0
  131. data/{images → medias/tk/images}/red_radar290.gif +0 -0
  132. data/{images → medias/tk/images}/red_radar300.gif +0 -0
  133. data/{images → medias/tk/images}/red_radar310.gif +0 -0
  134. data/{images → medias/tk/images}/red_radar320.gif +0 -0
  135. data/{images → medias/tk/images}/red_radar330.gif +0 -0
  136. data/{images → medias/tk/images}/red_radar340.gif +0 -0
  137. data/{images → medias/tk/images}/red_radar350.gif +0 -0
  138. data/{images → medias/tk/images}/red_turret000.gif +0 -0
  139. data/{images → medias/tk/images}/red_turret010.gif +0 -0
  140. data/{images → medias/tk/images}/red_turret020.gif +0 -0
  141. data/{images → medias/tk/images}/red_turret030.gif +0 -0
  142. data/{images → medias/tk/images}/red_turret040.gif +0 -0
  143. data/{images → medias/tk/images}/red_turret050.gif +0 -0
  144. data/{images → medias/tk/images}/red_turret060.gif +0 -0
  145. data/{images → medias/tk/images}/red_turret070.gif +0 -0
  146. data/{images → medias/tk/images}/red_turret080.gif +0 -0
  147. data/{images → medias/tk/images}/red_turret090.gif +0 -0
  148. data/{images → medias/tk/images}/red_turret100.gif +0 -0
  149. data/{images → medias/tk/images}/red_turret110.gif +0 -0
  150. data/{images → medias/tk/images}/red_turret120.gif +0 -0
  151. data/{images → medias/tk/images}/red_turret130.gif +0 -0
  152. data/{images → medias/tk/images}/red_turret140.gif +0 -0
  153. data/{images → medias/tk/images}/red_turret150.gif +0 -0
  154. data/{images → medias/tk/images}/red_turret160.gif +0 -0
  155. data/{images → medias/tk/images}/red_turret170.gif +0 -0
  156. data/{images → medias/tk/images}/red_turret180.gif +0 -0
  157. data/{images → medias/tk/images}/red_turret190.gif +0 -0
  158. data/{images → medias/tk/images}/red_turret200.gif +0 -0
  159. data/{images → medias/tk/images}/red_turret210.gif +0 -0
  160. data/{images → medias/tk/images}/red_turret220.gif +0 -0
  161. data/{images → medias/tk/images}/red_turret230.gif +0 -0
  162. data/{images → medias/tk/images}/red_turret240.gif +0 -0
  163. data/{images → medias/tk/images}/red_turret250.gif +0 -0
  164. data/{images → medias/tk/images}/red_turret260.gif +0 -0
  165. data/{images → medias/tk/images}/red_turret270.gif +0 -0
  166. data/{images → medias/tk/images}/red_turret280.gif +0 -0
  167. data/{images → medias/tk/images}/red_turret290.gif +0 -0
  168. data/{images → medias/tk/images}/red_turret300.gif +0 -0
  169. data/{images → medias/tk/images}/red_turret310.gif +0 -0
  170. data/{images → medias/tk/images}/red_turret320.gif +0 -0
  171. data/{images → medias/tk/images}/red_turret330.gif +0 -0
  172. data/{images → medias/tk/images}/red_turret340.gif +0 -0
  173. data/{images → medias/tk/images}/red_turret350.gif +0 -0
  174. data/{images → medias/tk/images}/toolbox.gif +0 -0
  175. metadata +168 -128
  176. data/lib/tkarena.rb +0 -194
data/lib/tkarena.rb DELETED
@@ -1,194 +0,0 @@
1
- require 'tk'
2
- require 'base64'
3
-
4
- TkRobot = Struct.new(:body, :gun, :radar, :speech, :info, :status)
5
-
6
- class TkArena
7
-
8
- attr_reader :battlefield, :xres, :yres
9
- attr_accessor :speed_multiplier, :on_game_over_handlers
10
- attr_accessor :canvas, :boom, :robots, :bullets, :explosions, :colors, :toolboxes, :toolbox_img, :mines, :mine_img
11
- attr_accessor :default_skin_prefix, :path_prefix
12
-
13
- def initialize battlefield, xres, yres, speed_multiplier
14
- @battlefield = battlefield
15
- @xres, @yres = xres, yres
16
- @speed_multiplier = speed_multiplier
17
- @text_colors = ['#ff0000', '#00ff00', '#0000ff', '#ffff00', '#00ffff', '#ff00ff', '#ffffff', '#777777']
18
-
19
-
20
- @path_prefix = gem_path
21
-
22
- @default_skin_prefix = "images/red_"
23
- @on_game_over_handlers = []
24
- init_canvas
25
- init_simulation
26
- end
27
-
28
- def on_game_over(&block)
29
- @on_game_over_handlers << block
30
- end
31
-
32
- def read_gif name, c1, c2, c3
33
- data = nil
34
- open(name, 'rb') do |f|
35
- data = f.read()
36
- ncolors = 2**(1 + data[10][0] + data[10][1] * 2 + data[10][2] * 4)
37
- ncolors.times do |j|
38
- data[13 + j * 3 + 0], data[13 + j * 3 + 1], data[13 + j * 3 + 2] =
39
- data[13 + j * 3 + c1], data[13 + j * 3 + c2], data[13 + j * 3 + c3]
40
- end
41
- end
42
- TkPhotoImage.new(:data => Base64.encode64(data))
43
- end
44
-
45
- def init_canvas
46
- @canvas = TkCanvas.new(:height=>yres, :width=>xres, :scrollregion=>[0, 0, xres, yres], :background => '#000000').pack
47
- @colors = []
48
- [[0,1,1],[1,0,1],[1,1,0],[0,0,1],[1,0,0],[0,1,0],[0,0,0],[1,1,1]][0...@battlefield.robots.length].zip(@battlefield.robots) do |color, robot|
49
- bodies, guns, radars = [], [], []
50
- image_path = robot.skin_prefix || @default_skin_prefix
51
- image_path = "#{@path_prefix}/#{image_path}"
52
- reader = robot.skin_prefix ? lambda{|fn| TkPhotoImage.new(:file => fn) } : lambda{|fn| read_gif(fn, *color)}
53
- 36.times do |i|
54
- bodies << reader["#{image_path}body#{(i*10).to_s.rjust(3, '0')}.gif"]
55
- guns << reader["#{image_path}turret#{(i*10).to_s.rjust(3, '0')}.gif"]
56
- radars << reader["#{image_path}radar#{(i*10).to_s.rjust(3, '0')}.gif"]
57
- end
58
- @colors << TkRobot.new(bodies << bodies[0], guns << guns[0], radars << radars[0])
59
- end
60
-
61
- @boom = (0..14).map do |i|
62
- TkPhotoImage.new(:file => "#{path_prefix}/images/explosion#{i.to_s.rjust(2, '0')}.gif")
63
- end
64
- @toolbox_img = TkPhotoImage.new(:file => "#{path_prefix}/images/toolbox.gif")
65
- @mine_img = TkPhotoImage.new(:file => "#{path_prefix}/images/mine.gif")
66
- end
67
-
68
- def init_simulation
69
- @robots, @bullets, @explosions, @toolboxes, @mines = {}, {}, {}, {}, {}
70
- TkTimer.new(20, -1, Proc.new{
71
- begin
72
- draw_frame
73
- rescue => err
74
- puts err.class, err, err.backtrace
75
- raise
76
- end
77
- }).start
78
- end
79
-
80
- def draw_frame
81
- simulate(@speed_multiplier)
82
- draw_battlefield
83
- end
84
-
85
- def simulate(ticks=1)
86
- @explosions.reject!{|e,tko| @canvas.delete(tko) if e.dead; e.dead }
87
- @bullets.reject!{|b,tko| @canvas.delete(tko) if b.dead; b.dead }
88
- @toolboxes.reject!{|t,tko| @canvas.delete(tko) if t.dead; t.dead }
89
- @mines.reject!{|m,tko| @canvas.delete(tko) if m.dead; m.dead }
90
- @robots.reject! do |ai,tko|
91
- if ai.dead
92
- tko.status.configure(:text => I18n.t('tkarena.ai_name_dead', :ai_name => ai.name.ljust(20)))
93
- tko.each{|part| @canvas.delete(part) if part != tko.status}
94
- true
95
- end
96
- end
97
- ticks.times do
98
- if @battlefield.game_over
99
- @on_game_over_handlers.each{|h| h.call(@battlefield) }
100
- unless @game_over
101
- winner = @robots.keys.first
102
- whohaswon = if winner.nil?
103
- I18n.t('tkarena.draw')
104
- elsif @battlefield.teams.all?{|k,t|t.size<2}
105
- I18n.t('tkarena.no_team_won', :winner_name => winner.name)
106
- else
107
- I18n.t('tkarena.team_won', :winner_team => winner.team)
108
- end
109
- text_color = winner ? winner.team : 7
110
- @game_over = TkcText.new(canvas,
111
- :fill => @text_colors[text_color],
112
- :anchor => 'c', :coords => [400,400], :font=>'courier 36', :justify => 'center',
113
- :text => I18n.t('tkarena.game_over').concat("\n#{whohaswon}"))
114
- end
115
- end
116
- @battlefield.tick
117
- end
118
- end
119
-
120
- def draw_battlefield
121
- draw_toolboxes
122
- draw_mines
123
- draw_robots
124
- draw_bullets
125
- draw_explosions
126
- end
127
-
128
- def draw_robots
129
- @battlefield.robots.each_with_index do |ai, i|
130
- next if ai.dead
131
- @robots[ai] ||= TkRobot.new(
132
- TkcImage.new(@canvas, 0, 0),
133
- TkcImage.new(@canvas, 0, 0),
134
- TkcImage.new(@canvas, 0, 0),
135
- TkcText.new(@canvas,
136
- :fill => @text_colors[ai.team],
137
- :anchor => 's', :justify => 'center', :coords => [ai.x / 2, ai.y / 2 - ai.size / 2]),
138
- TkcText.new(@canvas,
139
- :fill => @text_colors[ai.team],
140
- :anchor => 'n', :justify => 'center', :coords => [ai.x / 2, ai.y / 2 + ai.size / 2]),
141
- TkcText.new(@canvas,
142
- :fill => @text_colors[ai.team],
143
- :anchor => 'nw', :coords => [10, 15 * i + 10], :font => TkFont.new("courier 9")))
144
- @robots[ai].body.configure( :image => @colors[ai.team].body[(ai.heading+5) / 10],
145
- :coords => [ai.x / 2, ai.y / 2])
146
- @robots[ai].gun.configure( :image => @colors[ai.team].gun[(ai.gun_heading+5) / 10],
147
- :coords => [ai.x / 2, ai.y / 2])
148
- @robots[ai].radar.configure(:image => @colors[ai.team].radar[(ai.radar_heading+5) / 10],
149
- :coords => [ai.x / 2, ai.y / 2])
150
- @robots[ai].speech.configure(:text => "#{ai.speech}",
151
- :coords => [ai.x / 2, ai.y / 2 - ai.size / 2])
152
- @robots[ai].info.configure(:text => "#{ai.name}\n#{'|' * (ai.energy / 5)}",
153
- :coords => [ai.x / 2, ai.y / 2 + ai.size / 2])
154
- @robots[ai].status.configure(:text => "#{ai.name.ljust(20)} #{'%.1f' % ai.energy}")
155
- end
156
- end
157
-
158
- def draw_bullets
159
- @battlefield.bullets.each do |bullet|
160
- @bullets[bullet] ||= TkcOval.new(
161
- @canvas, [-2, -2], [3, 3],
162
- :fill=>'#'+("%02x" % (128+bullet.energy*14).to_i)*3)
163
- @bullets[bullet].coords(
164
- bullet.x / 2 - 2, bullet.y / 2 - 2,
165
- bullet.x / 2 + 3, bullet.y / 2 + 3)
166
- end
167
- end
168
-
169
- def draw_mines
170
- @battlefield.mines.each do |mine|
171
- @mines[mine] ||= TkcImage.new(@canvas, mine.x / 2, mine.y / 2)
172
- @mines[mine].image(mine_img)
173
- end
174
- end
175
-
176
- def draw_explosions
177
- @battlefield.explosions.each do |explosion|
178
- @explosions[explosion] ||= TkcImage.new(@canvas, explosion.x / 2, explosion.y / 2)
179
- @explosions[explosion].image(boom[explosion.t])
180
- end
181
- end
182
-
183
- def draw_toolboxes
184
- @battlefield.toolboxes.each do |toolbox|
185
- @toolboxes[toolbox] ||= TkcImage.new(@canvas, toolbox.x / 2, toolbox.y / 2)
186
- @toolboxes[toolbox].image(toolbox_img)
187
- end
188
- end
189
-
190
- def run
191
- Tk.mainloop
192
- end
193
-
194
- end