UG_RRobots 2.0 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +20 -4
- data/bin/rrobots +48 -17
- data/config/locales/en.yml +4 -2
- data/config/locales/fr.yml +3 -1
- data/doc/install.rdoc +20 -20
- data/doc/install_fr.rdoc +20 -20
- data/lib/GUI/gosu.rb +237 -0
- data/lib/GUI/tk.rb +215 -0
- data/lib/battlefield.rb +2 -0
- data/lib/mines.rb +36 -0
- data/lib/misc.rb +7 -4
- data/lib/robotrunner.rb +4 -0
- data/medias/gosu/images/blue_body000.bmp +0 -0
- data/medias/gosu/images/blue_radar000.bmp +0 -0
- data/medias/gosu/images/blue_turret000.bmp +0 -0
- data/medias/gosu/images/bullet.png +0 -0
- data/medias/gosu/images/explosion00.bmp +0 -0
- data/medias/gosu/images/explosion01.bmp +0 -0
- data/medias/gosu/images/explosion02.bmp +0 -0
- data/medias/gosu/images/explosion03.bmp +0 -0
- data/medias/gosu/images/explosion04.bmp +0 -0
- data/medias/gosu/images/explosion05.bmp +0 -0
- data/medias/gosu/images/explosion06.bmp +0 -0
- data/medias/gosu/images/explosion07.bmp +0 -0
- data/medias/gosu/images/explosion08.bmp +0 -0
- data/medias/gosu/images/explosion09.bmp +0 -0
- data/medias/gosu/images/explosion10.bmp +0 -0
- data/medias/gosu/images/explosion11.bmp +0 -0
- data/medias/gosu/images/explosion12.bmp +0 -0
- data/medias/gosu/images/explosion13.bmp +0 -0
- data/medias/gosu/images/explosion14.bmp +0 -0
- data/medias/gosu/images/lime_body000.bmp +0 -0
- data/medias/gosu/images/lime_radar000.bmp +0 -0
- data/medias/gosu/images/lime_turret000.bmp +0 -0
- data/medias/gosu/images/mine.png +0 -0
- data/medias/gosu/images/red_body000.bmp +0 -0
- data/medias/gosu/images/red_radar000.bmp +0 -0
- data/medias/gosu/images/red_turret000.bmp +0 -0
- data/medias/gosu/images/space.png +0 -0
- data/medias/gosu/images/toolbox.png +0 -0
- data/medias/gosu/images/white_body000.bmp +0 -0
- data/medias/gosu/images/white_radar000.bmp +0 -0
- data/medias/gosu/images/white_turret000.bmp +0 -0
- data/medias/gosu/images/yellow_body000.bmp +0 -0
- data/medias/gosu/images/yellow_radar000.bmp +0 -0
- data/medias/gosu/images/yellow_turret000.bmp +0 -0
- data/medias/gosu/music/song.mod +0 -0
- data/medias/gosu/sounds/shotborn.wav +0 -0
- data/medias/gosu/sounds/sunexp.wav +0 -0
- data/{images → medias/tk/images}/explosion00.gif +0 -0
- data/{images → medias/tk/images}/explosion01.gif +0 -0
- data/{images → medias/tk/images}/explosion02.gif +0 -0
- data/{images → medias/tk/images}/explosion03.gif +0 -0
- data/{images → medias/tk/images}/explosion04.gif +0 -0
- data/{images → medias/tk/images}/explosion05.gif +0 -0
- data/{images → medias/tk/images}/explosion06.gif +0 -0
- data/{images → medias/tk/images}/explosion07.gif +0 -0
- data/{images → medias/tk/images}/explosion08.gif +0 -0
- data/{images → medias/tk/images}/explosion09.gif +0 -0
- data/{images → medias/tk/images}/explosion10.gif +0 -0
- data/{images → medias/tk/images}/explosion11.gif +0 -0
- data/{images → medias/tk/images}/explosion12.gif +0 -0
- data/{images → medias/tk/images}/explosion13.gif +0 -0
- data/{images → medias/tk/images}/explosion14.gif +0 -0
- data/medias/tk/images/mine.gif +0 -0
- data/{images → medias/tk/images}/red_body000.gif +0 -0
- data/{images → medias/tk/images}/red_body010.gif +0 -0
- data/{images → medias/tk/images}/red_body020.gif +0 -0
- data/{images → medias/tk/images}/red_body030.gif +0 -0
- data/{images → medias/tk/images}/red_body040.gif +0 -0
- data/{images → medias/tk/images}/red_body050.gif +0 -0
- data/{images → medias/tk/images}/red_body060.gif +0 -0
- data/{images → medias/tk/images}/red_body070.gif +0 -0
- data/{images → medias/tk/images}/red_body080.gif +0 -0
- data/{images → medias/tk/images}/red_body090.gif +0 -0
- data/{images → medias/tk/images}/red_body100.gif +0 -0
- data/{images → medias/tk/images}/red_body110.gif +0 -0
- data/{images → medias/tk/images}/red_body120.gif +0 -0
- data/{images → medias/tk/images}/red_body130.gif +0 -0
- data/{images → medias/tk/images}/red_body140.gif +0 -0
- data/{images → medias/tk/images}/red_body150.gif +0 -0
- data/{images → medias/tk/images}/red_body160.gif +0 -0
- data/{images → medias/tk/images}/red_body170.gif +0 -0
- data/{images → medias/tk/images}/red_body180.gif +0 -0
- data/{images → medias/tk/images}/red_body190.gif +0 -0
- data/{images → medias/tk/images}/red_body200.gif +0 -0
- data/{images → medias/tk/images}/red_body210.gif +0 -0
- data/{images → medias/tk/images}/red_body220.gif +0 -0
- data/{images → medias/tk/images}/red_body230.gif +0 -0
- data/{images → medias/tk/images}/red_body240.gif +0 -0
- data/{images → medias/tk/images}/red_body250.gif +0 -0
- data/{images → medias/tk/images}/red_body260.gif +0 -0
- data/{images → medias/tk/images}/red_body270.gif +0 -0
- data/{images → medias/tk/images}/red_body280.gif +0 -0
- data/{images → medias/tk/images}/red_body290.gif +0 -0
- data/{images → medias/tk/images}/red_body300.gif +0 -0
- data/{images → medias/tk/images}/red_body310.gif +0 -0
- data/{images → medias/tk/images}/red_body320.gif +0 -0
- data/{images → medias/tk/images}/red_body330.gif +0 -0
- data/{images → medias/tk/images}/red_body340.gif +0 -0
- data/{images → medias/tk/images}/red_body350.gif +0 -0
- data/{images → medias/tk/images}/red_radar000.gif +0 -0
- data/{images → medias/tk/images}/red_radar010.gif +0 -0
- data/{images → medias/tk/images}/red_radar020.gif +0 -0
- data/{images → medias/tk/images}/red_radar030.gif +0 -0
- data/{images → medias/tk/images}/red_radar040.gif +0 -0
- data/{images → medias/tk/images}/red_radar050.gif +0 -0
- data/{images → medias/tk/images}/red_radar060.gif +0 -0
- data/{images → medias/tk/images}/red_radar070.gif +0 -0
- data/{images → medias/tk/images}/red_radar080.gif +0 -0
- data/{images → medias/tk/images}/red_radar090.gif +0 -0
- data/{images → medias/tk/images}/red_radar100.gif +0 -0
- data/{images → medias/tk/images}/red_radar110.gif +0 -0
- data/{images → medias/tk/images}/red_radar120.gif +0 -0
- data/{images → medias/tk/images}/red_radar130.gif +0 -0
- data/{images → medias/tk/images}/red_radar140.gif +0 -0
- data/{images → medias/tk/images}/red_radar150.gif +0 -0
- data/{images → medias/tk/images}/red_radar160.gif +0 -0
- data/{images → medias/tk/images}/red_radar170.gif +0 -0
- data/{images → medias/tk/images}/red_radar180.gif +0 -0
- data/{images → medias/tk/images}/red_radar190.gif +0 -0
- data/{images → medias/tk/images}/red_radar200.gif +0 -0
- data/{images → medias/tk/images}/red_radar210.gif +0 -0
- data/{images → medias/tk/images}/red_radar220.gif +0 -0
- data/{images → medias/tk/images}/red_radar230.gif +0 -0
- data/{images → medias/tk/images}/red_radar240.gif +0 -0
- data/{images → medias/tk/images}/red_radar250.gif +0 -0
- data/{images → medias/tk/images}/red_radar260.gif +0 -0
- data/{images → medias/tk/images}/red_radar270.gif +0 -0
- data/{images → medias/tk/images}/red_radar280.gif +0 -0
- data/{images → medias/tk/images}/red_radar290.gif +0 -0
- data/{images → medias/tk/images}/red_radar300.gif +0 -0
- data/{images → medias/tk/images}/red_radar310.gif +0 -0
- data/{images → medias/tk/images}/red_radar320.gif +0 -0
- data/{images → medias/tk/images}/red_radar330.gif +0 -0
- data/{images → medias/tk/images}/red_radar340.gif +0 -0
- data/{images → medias/tk/images}/red_radar350.gif +0 -0
- data/{images → medias/tk/images}/red_turret000.gif +0 -0
- data/{images → medias/tk/images}/red_turret010.gif +0 -0
- data/{images → medias/tk/images}/red_turret020.gif +0 -0
- data/{images → medias/tk/images}/red_turret030.gif +0 -0
- data/{images → medias/tk/images}/red_turret040.gif +0 -0
- data/{images → medias/tk/images}/red_turret050.gif +0 -0
- data/{images → medias/tk/images}/red_turret060.gif +0 -0
- data/{images → medias/tk/images}/red_turret070.gif +0 -0
- data/{images → medias/tk/images}/red_turret080.gif +0 -0
- data/{images → medias/tk/images}/red_turret090.gif +0 -0
- data/{images → medias/tk/images}/red_turret100.gif +0 -0
- data/{images → medias/tk/images}/red_turret110.gif +0 -0
- data/{images → medias/tk/images}/red_turret120.gif +0 -0
- data/{images → medias/tk/images}/red_turret130.gif +0 -0
- data/{images → medias/tk/images}/red_turret140.gif +0 -0
- data/{images → medias/tk/images}/red_turret150.gif +0 -0
- data/{images → medias/tk/images}/red_turret160.gif +0 -0
- data/{images → medias/tk/images}/red_turret170.gif +0 -0
- data/{images → medias/tk/images}/red_turret180.gif +0 -0
- data/{images → medias/tk/images}/red_turret190.gif +0 -0
- data/{images → medias/tk/images}/red_turret200.gif +0 -0
- data/{images → medias/tk/images}/red_turret210.gif +0 -0
- data/{images → medias/tk/images}/red_turret220.gif +0 -0
- data/{images → medias/tk/images}/red_turret230.gif +0 -0
- data/{images → medias/tk/images}/red_turret240.gif +0 -0
- data/{images → medias/tk/images}/red_turret250.gif +0 -0
- data/{images → medias/tk/images}/red_turret260.gif +0 -0
- data/{images → medias/tk/images}/red_turret270.gif +0 -0
- data/{images → medias/tk/images}/red_turret280.gif +0 -0
- data/{images → medias/tk/images}/red_turret290.gif +0 -0
- data/{images → medias/tk/images}/red_turret300.gif +0 -0
- data/{images → medias/tk/images}/red_turret310.gif +0 -0
- data/{images → medias/tk/images}/red_turret320.gif +0 -0
- data/{images → medias/tk/images}/red_turret330.gif +0 -0
- data/{images → medias/tk/images}/red_turret340.gif +0 -0
- data/{images → medias/tk/images}/red_turret350.gif +0 -0
- data/{images → medias/tk/images}/toolbox.gif +0 -0
- metadata +168 -128
- 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
|