line-em-up 0.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/line-em-up/game_window.rb +189 -52
  3. data/line-em-up/irb_requirements.rb +24 -2
  4. data/line-em-up/lib/config_setting.rb +126 -16
  5. data/line-em-up/lib/difficulty_setting.rb +64 -64
  6. data/line-em-up/lib/lighting.rb +143 -0
  7. data/line-em-up/lib/resolution_setting.rb +58 -58
  8. data/line-em-up/lib/setting.rb +104 -0
  9. data/line-em-up/lib/ship_loadout_setting.rb +476 -0
  10. data/line-em-up/lib/ship_setting.rb +98 -0
  11. data/line-em-up/lib/z_order.rb +1 -1
  12. data/line-em-up/loadout_window.rb +253 -0
  13. data/line-em-up/media/bullet_launcher_hardpoint.png +0 -0
  14. data/line-em-up/media/hardpoint_empty.png +0 -0
  15. data/line-em-up/media/header@2x.psd +0 -0
  16. data/line-em-up/media/laser-end-background-half.png +0 -0
  17. data/line-em-up/media/laser-end-background.png +0 -0
  18. data/line-em-up/media/laser-end-overlay-half.png +0 -0
  19. data/line-em-up/media/laser-end-overlay.png +0 -0
  20. data/line-em-up/media/laser-middle-background-half.png +0 -0
  21. data/line-em-up/media/laser-middle-background.png +0 -0
  22. data/line-em-up/media/laser-middle-overlay-half.png +0 -0
  23. data/line-em-up/media/laser-middle-overlay-short.png +0 -0
  24. data/line-em-up/media/laser-middle-overlay.png +0 -0
  25. data/line-em-up/media/laser-overlay-half.png +0 -0
  26. data/line-em-up/media/laser-overlay.png +0 -0
  27. data/line-em-up/media/laser-start-background-half.png +0 -0
  28. data/line-em-up/media/laser-start-background.png +0 -0
  29. data/line-em-up/media/laser-start-overlay-half.png +0 -0
  30. data/line-em-up/media/laser-start-overlay.png +0 -0
  31. data/line-em-up/media/laser_beam_hardpoint copy.png +0 -0
  32. data/line-em-up/media/laser_beam_hardpoint.png +0 -0
  33. data/line-em-up/media/line-em-up-resolution.png +0 -0
  34. data/line-em-up/media/menu/loadout.png +0 -0
  35. data/line-em-up/media/{start.png → menu/start.png} +0 -0
  36. data/line-em-up/media/missile_launcher.png +0 -0
  37. data/line-em-up/media/{spaceship.png → pilotable_ships/basic_ship/default.png} +0 -0
  38. data/line-em-up/media/{spaceship_original.png → pilotable_ships/basic_ship/large.png} +0 -0
  39. data/line-em-up/media/{spaceship_left.png → pilotable_ships/basic_ship/left.png} +0 -0
  40. data/line-em-up/media/pilotable_ships/basic_ship/left_broadside.png +0 -0
  41. data/line-em-up/media/pilotable_ships/basic_ship/original.png +0 -0
  42. data/line-em-up/media/{spaceship_right.png → pilotable_ships/basic_ship/right.png} +0 -0
  43. data/line-em-up/media/pilotable_ships/basic_ship/right_broadside.png +0 -0
  44. data/line-em-up/media/pilotable_ships/mite_ship/default.png +0 -0
  45. data/line-em-up/media/pilotable_ships/mite_ship/large.png +0 -0
  46. data/line-em-up/media/pilotable_ships/mite_ship/left.png +0 -0
  47. data/line-em-up/media/pilotable_ships/mite_ship/left_broadside.png +0 -0
  48. data/line-em-up/media/pilotable_ships/mite_ship/original.png +0 -0
  49. data/line-em-up/media/pilotable_ships/mite_ship/right.png +0 -0
  50. data/line-em-up/media/pilotable_ships/mite_ship/right_broadside.png +0 -0
  51. data/line-em-up/media/pilotable_ships/mite_ship.zip +0 -0
  52. data/line-em-up/models/basic_ship.rb +94 -0
  53. data/line-em-up/models/bomb.rb +1 -1
  54. data/line-em-up/models/building.rb +2 -2
  55. data/line-em-up/models/bullet.rb +127 -74
  56. data/line-em-up/models/bullet_launcher.rb +23 -0
  57. data/line-em-up/models/cursor.rb +37 -1
  58. data/line-em-up/models/dumb_missile_launcher.rb +40 -0
  59. data/line-em-up/models/dumb_projectile.rb +9 -2
  60. data/line-em-up/models/enemy_bomb.rb +1 -1
  61. data/line-em-up/models/enemy_bullet.rb +55 -0
  62. data/line-em-up/models/enemy_player.rb +1 -1
  63. data/line-em-up/models/execute_open_gl.rb +80 -0
  64. data/line-em-up/models/general_object.rb +82 -9
  65. data/line-em-up/models/gl_background.rb +103 -30
  66. data/line-em-up/models/grappling_hook.rb +1 -1
  67. data/line-em-up/models/hardpoint.rb +120 -0
  68. data/line-em-up/models/laser_launcher.rb +192 -0
  69. data/line-em-up/models/laser_particle.rb +133 -0
  70. data/line-em-up/models/launcher.rb +149 -0
  71. data/line-em-up/models/main.rb +119 -26
  72. data/line-em-up/models/menu.rb +43 -3
  73. data/line-em-up/models/menu_item.rb +25 -14
  74. data/line-em-up/models/missile_boat.rb +5 -4
  75. data/line-em-up/models/mite.rb +3 -2
  76. data/line-em-up/models/mite_ship.rb +61 -0
  77. data/line-em-up/models/mothership.rb +1 -1
  78. data/line-em-up/models/pickup.rb +2 -2
  79. data/line-em-up/models/pilotable_ship.rb +599 -0
  80. data/line-em-up/models/player.rb +207 -150
  81. data/line-em-up/models/projectile.rb +3 -24
  82. data/line-em-up/models/semi_guided_missile.rb +1 -1
  83. data/line-em-up/models/small_explosion.rb +2 -2
  84. data/line-em-up/models/star.rb +7 -2
  85. data/menu_launcher.rb +10 -6
  86. metadata +113 -10
  87. data/line-em-up/media/spaceship_left-test.png +0 -0
@@ -0,0 +1,476 @@
1
+ require 'luit'
2
+
3
+ require_relative 'setting.rb'
4
+ require_relative '../models/basic_ship.rb'
5
+ require_relative '../models/launcher.rb'
6
+ # require "#{MODEL_DIRECTORY}/basic_ship.rb"
7
+ # require_relative "config_settings.rb"
8
+
9
+ class ShipLoadoutSetting < Setting
10
+ # MEDIA_DIRECTORY
11
+ SELECTION = ::Launcher.descendants
12
+ NAME = "ship_loadout"
13
+
14
+ # def self.get_weapon_options
15
+ # ::Launcher.descendants
16
+ # end
17
+
18
+ # attr_accessor :x, :y, :font, :max_width, :max_height, :selection, :value, :ship_value
19
+ attr_accessor :value, :ship_value
20
+ attr_accessor :mouse_x, :mouse_y
21
+ def initialize window, fullscreen_height, max_width, max_height, current_height, config_file_path, ship_value, options = {}
22
+ # @window = window # Want relative to self, not window. Can't do that from settting, not a window.
23
+ @mouse_x, @mouse_y = [0,0]
24
+ @window = self # ignoring outer window here? Want actions relative to this window.
25
+ @scale = options[:scale] || 1
26
+ puts "SHIP LOADOUT SETTING SCALE: #{@scale}"
27
+ @font = Gosu::Font.new(20)
28
+ # @x = width
29
+ @y = current_height
30
+ @max_width = max_width
31
+ @max_height = max_height
32
+ @next_x = 5 * @scale
33
+ @prev_x = @max_width - 5 * @scale - @font.text_width('>')
34
+ LUIT.config({window: @window, z: 25})
35
+ @selection = []
36
+ @launchers = ::Launcher.descendants.collect{|d| d.name}
37
+ @meta_launchers = {}
38
+ @filler_items = []
39
+ @launchers.each_with_index do |klass_name, index|
40
+ klass = eval(klass_name)
41
+ image = klass.get_hardpoint_image
42
+ button_key = "clicked_launcher_#{index}".to_sym
43
+ @meta_launchers[button_key] = {follow_cursor: false, klass: klass, image: image}
44
+ @filler_items << {follow_cursor: false, klass: klass, image: image}
45
+ # @button_id_mapping[button_key] = lambda { |setting, id| setting.click_inventory(id) }
46
+ end
47
+ @hardpoint_image_z = 50
48
+ # puts "SELECTION: #{@selection}"
49
+ # puts "INNITING #{config_file_path}"
50
+ @config_file_path = config_file_path
51
+ @name = self.class::NAME
52
+ @ship_value = ship_value
53
+ klass = eval(@ship_value)
54
+ # implement hide_hardpoints on pilotable ship class
55
+ @ship = klass.new(1, @max_width / 2, max_height / 2, max_width, max_height, {use_large_image: true, hide_hardpoints: true})
56
+ # puts "RIGHT HERE!@!!!"
57
+ # puts "@ship.right_broadside_hard_points"
58
+ # puts @ship.right_broadside_hard_points
59
+ @value = ConfigSetting.get_setting(@config_file_path, @name, @selection[0])
60
+ @fullscreen_height = fullscreen_height
61
+ # @window = window
62
+ # first array is rows at the top, 2nd goes down through the rows
63
+ @inventory_matrix = []
64
+ @inventory_matrix_max_width = 4
65
+ @inventory_matrix_max_height = 7
66
+ @cell_width = 25 * @scale
67
+ @cell_height = 25 * @scale
68
+ @cell_width_padding = 5 * @scale
69
+ @cell_height_padding = 5 * @scale
70
+ @button_id_mapping = self.class.get_id_button_mapping
71
+ init_matrix
72
+ # puts "FILLER ITEMS: #{@filler_items}"
73
+ @inventory_items = retrieve_inventory_items
74
+ # fill_matrix(@filler_items)
75
+ @cursor_object = nil
76
+ @ship_hardpoints = init_hardpoints(@ship)
77
+ end
78
+
79
+ def retrieve_inventory_items
80
+ end
81
+
82
+ def self.get_id_button_mapping
83
+ values = {
84
+ next: lambda { |setting, id| setting.next_clicked },
85
+ previous: lambda { |setting, id| setting.previous_clicked }
86
+ }
87
+ end
88
+
89
+ # Use to fill when dropped on screen somewhere..
90
+ # Currently not used
91
+ def fill_matrix elements
92
+ elements.each do |element|
93
+ space = find_next_matrix_space
94
+ if space
95
+ # puts "ASSIGNING ELEMENT:"
96
+ # puts element.inspect
97
+ @inventory_matrix[space[:x]][space[:y]][:item] = element.merge({key: space[:key]})
98
+ else
99
+ puts "NO SPACE LEFT"
100
+ end
101
+ end
102
+ end
103
+
104
+ def find_next_matrix_space
105
+ found_space = nil
106
+ (0..@inventory_matrix_max_height - 1).each do |y|
107
+ (0..@inventory_matrix_max_width - 1).each do |x|
108
+ if @inventory_matrix[x][y][:item].nil?
109
+ key = "matrix_#{x}_#{y}"
110
+ found_space = {x: x, y: y, key: key}
111
+ end
112
+ break if found_space
113
+ end
114
+ break if found_space
115
+ end
116
+ return found_space
117
+ end
118
+
119
+ def init_matrix
120
+ (0..@inventory_matrix_max_width - 1).each do |i|
121
+ @inventory_matrix[i] = Array.new(@inventory_matrix_max_height)
122
+ end
123
+ current_y = @y + @cell_height_padding
124
+ current_x = @next_x
125
+ (0..@inventory_matrix_max_height - 1).each do |y|
126
+ (0..@inventory_matrix_max_width - 1).each do |x|
127
+ key = "matrix_#{x}_#{y}"
128
+ click_area = LUIT::ClickArea.new(@window, key, current_x, current_y, @cell_width, @cell_height)
129
+ # click_area = LUIT::Button.new(@window, click_key, current_x, current_y, '', @cell_width, @cell_height)
130
+ klass_name = ConfigSetting.get_mapped_setting(@config_file_path, ['Inventory', x.to_s, y.to_s])
131
+ item = nil
132
+ if klass_name
133
+ klass = eval(klass_name)
134
+ image = klass.get_hardpoint_image
135
+ item = {key: key, klass: klass, image: image}
136
+ end
137
+ # @filler_items << {follow_cursor: false, klass: klass, image: image}
138
+ @inventory_matrix[x][y] = {x: current_x, y: current_y, click_area: click_area, key: key, item: item}
139
+ current_x = current_x + @cell_width + @cell_width_padding
140
+ @button_id_mapping[key] = lambda { |setting, id| setting.click_inventory(id) }
141
+ end
142
+ current_x = @next_x
143
+ current_y = current_y + @cell_height + @cell_height_padding
144
+ end
145
+ end
146
+
147
+ def matrix_draw
148
+ (0..@inventory_matrix_max_height - 1).each do |y|
149
+ (0..@inventory_matrix_max_width - 1).each do |x|
150
+ element = @inventory_matrix[x][y]
151
+ element[:click_area].draw(0,0)
152
+ # puts "element[:item]: #{element[:item]}"
153
+ if !element[:item].nil? && element[:item][:follow_cursor] != true
154
+ image = element[:item][:image]
155
+ image.draw(element[:x] - (image.width / 2) + @cell_width / 2, element[:y] - (image.height / 2) + @cell_height / 2, @hardpoint_image_z, @scale, @scale)
156
+ end
157
+ end
158
+ end
159
+ end
160
+
161
+ def hardpoint_draw
162
+ @ship_hardpoints.each do |key, list|
163
+ if list.any?
164
+ list.each do |value|
165
+ click_area = value[:click_area]
166
+ if click_area
167
+ click_area.draw(0, 0)
168
+ else
169
+ # puts " NO CLICK AREA FOUND"
170
+ end
171
+ item = value[:item]
172
+ if item
173
+ image = item[:image]
174
+ if image
175
+ image.draw(value[:x] - (image.width / 2) + @cell_width / 2, value[:y] - (image.height / 2) + @cell_height / 2, @hardpoint_image_z, @scale, @scale)
176
+ end
177
+ end
178
+ end
179
+ else
180
+ # puts " KEY DID NOT HAVE Value"
181
+ end
182
+ end
183
+ end
184
+
185
+ def matrix_update
186
+ (0..@inventory_matrix_max_height - 1).each do |y|
187
+ (0..@inventory_matrix_max_width - 1).each do |x|
188
+ @inventory_matrix[x][y][:click_area].update(0,0)
189
+ end
190
+ end
191
+ end
192
+
193
+ def print_out_matrix
194
+ (0..@inventory_matrix_max_height - 1).each do |y|
195
+ row_value = []
196
+ (0..@inventory_matrix_max_width - 1).each do |x|
197
+ value = @inventory_matrix[x][y]
198
+ if value.nil?
199
+ value = 'O'
200
+ else
201
+ value = 'X'
202
+ end
203
+ row_value << value
204
+ end
205
+ puts row_value.join(', ')
206
+ end
207
+ end
208
+
209
+ def init_hardpoints ship
210
+ # Populate ship hardpoints from save file here.
211
+ # will be populated from the ship, don't need to here.
212
+ value = {}
213
+ groups = [
214
+ {hardpoints: ship.right_broadside_hard_points, location: :right},
215
+ {hardpoints: ship.left_broadside_hard_points, location: :left},
216
+ {hardpoints: ship.front_hard_points, location: :front}
217
+ ]
218
+ groups.each do |group|
219
+ value[group[:location]] = []
220
+ group[:hardpoints].each_with_index do |hp, index|
221
+ button_key = "#{group[:location].to_s}_hardpoint_#{index}"
222
+ # click_area = LUIT::ClickArea.new(@window, key, current_x, current_y, @cell_width, @cell_height)
223
+ # image.draw(value[:x] - (image.width / 2) + @cell_width / 2, value[:y] - (image.height / 2) + @cell_height / 2, @hardpoint_image_z)
224
+ # if group[:location] == :front
225
+ # puts "FRONT HERE!!!!!"
226
+ # puts "HP X and Y: #{hp.x} and #{hp.y}"
227
+ # puts "hp.x_offset and hp.y_offset: #{hp.x_offset} and #{hp.y_offset}"
228
+ # end
229
+ click_area = LUIT::ClickArea.new(@window, button_key, hp.x + hp.x_offset - (@cell_width / 2), hp.y + hp.y_offset - @cell_height / 2, @cell_width, @cell_height)
230
+ @button_id_mapping[button_key] = lambda { |setting, id| setting.click_ship_hardpoint(id) }
231
+ if hp.assigned_weapon_class
232
+ image = hp.assigned_weapon_class.get_hardpoint_image
233
+ item = {
234
+ image: image, key: button_key,
235
+ klass: hp.assigned_weapon_class
236
+ }
237
+
238
+ else
239
+ end
240
+ value[group[:location]] << {item: item, x: hp.x + hp.x_offset - (@cell_width / 2), y: hp.y + hp.y_offset - @cell_height / 2, click_area: click_area, key: button_key}
241
+ end
242
+ end
243
+ # puts "VALUES HERE FRONT:"
244
+ # puts value[:front]
245
+ # puts "VALUES HERE RIGHT:"
246
+ # puts value[:right].count
247
+ # puts "VALUES HERE LEFT:"
248
+ # puts value[:left].count
249
+
250
+ # ship.left_broadside_hard_points.each do |hp|
251
+ # value[:left] << {weapon_klass: hp.assigned_weapon_class, x: hp.x + hp.x_offset, y: hp.y + hp.y_offset}
252
+ # end
253
+
254
+ # ship.front_hard_points.each do |hp|
255
+ # value[:front] << {weapon_klass: hp.assigned_weapon_class, x: hp.x + hp.x_offset, y: hp.y + hp.y_offset}
256
+ # end
257
+ return value
258
+ end
259
+
260
+ def click_ship_hardpoint id
261
+ puts "click_ship_hardpoint: #{id}"
262
+ # Key is front, right, or left
263
+ # left_hardpoint_0
264
+
265
+
266
+ port, i = id.scan(/(\w+)_hardpoint_(\d+)/).first
267
+ port, i = [port.to_sym, i.to_i]
268
+ puts "PORT AND I: #{port} and #{i}"
269
+
270
+ hardpoint_element = @ship_hardpoints[port][i]
271
+ element = hardpoint_element ? hardpoint_element[:item] : nil
272
+
273
+ if @cursor_object && element
274
+ puts "@cursor_object[:key]: #{@cursor_object[:key]}"
275
+ puts "ID: #{id}"
276
+ puts "== #{@cursor_object[:key] == id}"
277
+ if @cursor_object[:key] == id
278
+ # Same Object, Unstick it, put it back
279
+ # element[:follow_cursor] = false
280
+ # @inventory_matrix[x][y][:item][:follow_cursor] =
281
+ hardpoint_element[:item] = @cursor_object
282
+ puts "CONFIG SETTING 1"
283
+ ConfigSetting.set_mapped_setting(@config_file_path, [@ship.class.name, "#{port}_hardpoint_locations", i.to_s], hardpoint_element[:item][:klass])
284
+ hardpoint_element[:item][:key] = id
285
+ @cursor_object = nil
286
+ else
287
+ # Else, drop object, pick up new object
288
+ # @cursor_object[:follow_cursor] = false
289
+ # element[:follow_cursor] = true
290
+ temp_element = element
291
+ hardpoint_element[:item] = @cursor_object
292
+ hardpoint_element[:item][:key] = id
293
+ puts "CONFIG SETTING 2 "
294
+ ConfigSetting.set_mapped_setting(@config_file_path, [@ship.class.name, "#{port}_hardpoint_locations", i.to_s], hardpoint_element[:item][:klass])
295
+ @cursor_object = temp_element
296
+ @cursor_object[:key] = nil # Original home lost, no last home of key present
297
+ # @cursor_object[:follow_cursor] = true
298
+ # WRRROOOONNGGG!
299
+ # element =
300
+ end
301
+ elsif element
302
+ # Pick up element, no current object
303
+ # element[:follow_cursor] = true
304
+ @cursor_object = element
305
+ hardpoint_element[:item] = nil
306
+ puts "CONFIG SETTING 3 "
307
+ # Not working..
308
+ puts [@ship.class.name, "#{port}_hardpoint_locations", i.to_s].to_s
309
+ ConfigSetting.set_mapped_setting(@config_file_path, [@ship.class.name, "#{port}_hardpoint_locations", i.to_s], nil)
310
+ elsif @cursor_object
311
+ # Placeing something new in inventory
312
+ hardpoint_element[:item] = @cursor_object
313
+ puts "PUTTING ELEMENT IN: #{hardpoint_element[:item]}"
314
+ puts "CONFIG SETTING 4 "
315
+ puts [@ship.class.name, "#{port}_hardpoint_locations", i.to_s].to_s
316
+ puts hardpoint_element[:item][:klass]
317
+ ConfigSetting.set_mapped_setting(@config_file_path, [@ship.class.name, "#{port}_hardpoint_locations", i.to_s], hardpoint_element[:item][:klass])
318
+ hardpoint_element[:item][:key] = id
319
+ # matrix_element[:item][:follow_cursor] = false
320
+ @cursor_object = false
321
+ end
322
+ end
323
+
324
+ def click_inventory id
325
+ puts "LUANCHER: #{id}"
326
+ puts "click_inventory: "
327
+ x, y = id.scan(/matrix_(\d+)_(\d+)/).first
328
+ x, y = [x.to_i, y.to_i]
329
+ puts "LCICKED: #{x} and #{y}"
330
+ matrix_element = @inventory_matrix[x][y]
331
+ element = matrix_element ? matrix_element[:item] : nil
332
+
333
+ # Resave new key when dropping element in.
334
+
335
+ if @cursor_object && element
336
+ puts "@cursor_object[:key]: #{@cursor_object[:key]}"
337
+ puts "ID: #{id}"
338
+ puts "== #{@cursor_object[:key] == id}"
339
+ if @cursor_object[:key] == id
340
+ # Same Object, Unstick it, put it back
341
+ # element[:follow_cursor] = false
342
+ # @inventory_matrix[x][y][:item][:follow_cursor] =
343
+ matrix_element[:item] = @cursor_object
344
+ ConfigSetting.set_mapped_setting(@config_file_path, ['Inventory', x.to_s, y.to_s], matrix_element[:item][:klass])
345
+ matrix_element[:item][:key] = id
346
+ @cursor_object = nil
347
+ else
348
+ # Else, drop object, pick up new object
349
+ # @cursor_object[:follow_cursor] = false
350
+ # element[:follow_cursor] = true
351
+ temp_element = element
352
+ matrix_element[:item] = @cursor_object
353
+ matrix_element[:item][:key] = id
354
+ ConfigSetting.set_mapped_setting(@config_file_path, ['Inventory', x.to_s, y.to_s], matrix_element[:item][:klass])
355
+ @cursor_object = temp_element
356
+ @cursor_object[:key] = nil # Original home lost, no last home of key present
357
+ # @cursor_object[:follow_cursor] = true
358
+ # WRRROOOONNGGG!
359
+ # element =
360
+ end
361
+ elsif element
362
+ # Pick up element, no current object
363
+ # element[:follow_cursor] = true
364
+ @cursor_object = element
365
+ matrix_element[:item] = nil
366
+ ConfigSetting.set_mapped_setting(@config_file_path, ['Inventory', x.to_s, y.to_s], nil)
367
+ elsif @cursor_object
368
+ # Placeing something new in inventory
369
+ matrix_element[:item] = @cursor_object
370
+ ConfigSetting.set_mapped_setting(@config_file_path, ['Inventory', x.to_s, y.to_s], matrix_element[:item][:klass])
371
+ matrix_element[:item][:key] = id
372
+ # matrix_element[:item][:follow_cursor] = false
373
+ @cursor_object = false
374
+ end
375
+ end
376
+
377
+
378
+ def get_values
379
+ # puts "GETTING DIFFICULTY: #{@value}"
380
+ if @value
381
+ @value
382
+ end
383
+ end
384
+
385
+ def hardpoint_update
386
+ @ship_hardpoints.each do |key, list|
387
+ if list.any?
388
+ list.each do |value|
389
+ click_area = value[:click_area]
390
+ if click_area
391
+ click_area.update(0, 0)
392
+ end
393
+ end
394
+ end
395
+ end
396
+ end
397
+
398
+ def update mouse_x, mouse_y, ship_value
399
+ @mouse_x, @mouse_y = [mouse_x, mouse_y]
400
+
401
+ hardpoint_update
402
+
403
+ matrix_update
404
+
405
+ if ship_value != @ship_value
406
+ @ship_value = ship_value
407
+ klass = eval(@ship_value)
408
+ @ship = klass.new(1, @max_width / 2, @max_height / 2, @max_width, @max_height, {use_large_image: true, hide_hardpoints: true})
409
+ @ship_hardpoints = init_hardpoints(@ship)
410
+ else
411
+ # Do nothing
412
+ end
413
+ return @cursor_object
414
+ end
415
+
416
+ def get_hardpoints
417
+ klass = eval(@ship_value)
418
+ return {
419
+ front: klass::FRONT_HARDPOINT_LOCATIONS,
420
+ right: klass::RIGHT_BROADSIDE_HARDPOINT_LOCATIONS,
421
+ left: klass::LEFT_BROADSIDE_HARDPOINT_LOCATIONS
422
+ }
423
+ end
424
+
425
+ def get_image
426
+ klass = eval(@ship_value)
427
+ return klass.get_right_broadside_image(klass::SHIP_MEDIA_DIRECTORY)
428
+ end
429
+
430
+ def get_large_image
431
+ klass = eval(@ship_value)
432
+ return klass.get_large_image(klass::SHIP_MEDIA_DIRECTORY)
433
+ end
434
+
435
+ # deprecated
436
+ def clicked mx, my
437
+ puts "SHIP LOADOUT CLICKED"
438
+ if is_mouse_hovering_next(mx, my)
439
+
440
+ elsif is_mouse_hovering_prev(mx, my)
441
+
442
+ end
443
+ end
444
+
445
+ def is_mouse_hovering_next mx, my
446
+ local_width = @font.text_width('>')
447
+ local_height = @font.height
448
+
449
+ (mx >= @next_x and my >= @y) and (mx <= @next_x + local_width) and (my <= @y + local_height)
450
+ end
451
+
452
+ def is_mouse_hovering_prev mx, my
453
+ local_width = @font.text_width('<')
454
+ local_height = @font.height
455
+
456
+ (mx >= @prev_x and my >= @y) and (mx <= @prev_x + local_width) and (my <= @y + local_height)
457
+ end
458
+
459
+ def draw
460
+
461
+ if @cursor_object
462
+ @cursor_object[:image].draw(@mouse_x, @mouse_y, @hardpoint_image_z, @scale, @scale)
463
+ end
464
+
465
+ hardpoint_draw
466
+
467
+ matrix_draw
468
+
469
+ @font.draw(@value, ((@max_width / 2) - @font.text_width(@value) / 2), @y, 1, 1.0, 1.0, 0xff_ffff00)
470
+
471
+ @ship.draw
472
+ @font.draw(@value, ((@max_width / 2) - @font.text_width(@value) / 2), @y, 1, 1.0, 1.0, 0xff_ffff00)
473
+ @font.draw(">", @prev_x, @y, 1, 1.0, 1.0, 0xff_ffff00)
474
+ end
475
+
476
+ end
@@ -0,0 +1,98 @@
1
+ # require 'luit'
2
+ require_relative 'setting.rb'
3
+ require_relative '../models/basic_ship.rb'
4
+ # require "#{MODEL_DIRECTORY}/basic_ship.rb"
5
+ # require_relative "config_settings.rb"
6
+
7
+ class ShipSetting < Setting
8
+ # MEDIA_DIRECTORY
9
+ SELECTION = ["MiteShip", "BasicShip"]
10
+ NAME = "ship"
11
+
12
+ # attr_accessor :mouse_x, :mouse_y, :window
13
+ attr_accessor :window
14
+ attr_accessor :mouse_x, :mouse_y
15
+ def initialize window, fullscreen_height, max_width, max_height, current_height, config_file_path
16
+ raise "NO Window" if window.nil?
17
+ @mouse_x, @mouse_y = [0,0]
18
+ @window = self # ignoring outer window here? Want actions relative to this window.
19
+ @selection = self.class::SELECTION
20
+ # puts "INNITING #{config_file_path}"
21
+ @font = Gosu::Font.new(20)
22
+ # @x = width
23
+ @y = current_height
24
+ @max_width = max_width
25
+ @max_height = max_height
26
+ @prev_x = 0
27
+ # @next_x = max_width
28
+ # LUIT 205 width == 480
29
+ # X coord system is half that of what it should be, for the LUIT elements
30
+ @next_x = max_width
31
+ @config_file_path = config_file_path
32
+ @name = self.class::NAME
33
+ @value = ConfigSetting.get_setting(@config_file_path, @name, @selection[0])
34
+ @fullscreen_height = fullscreen_height
35
+ # LUIT.config(window, nil, nil, 1)
36
+ LUIT.config({window: @window, z: 25})
37
+ @next_button = LUIT::Button.new(@window, :next, @next_x, @y, "Next", 0, 1)
38
+ # puts "CREATING NEXT BUTTON WINDOW HERE"
39
+ # puts @window.class.name
40
+ # raise "STOP HERRE"
41
+ # @next_button.x = @next_x - (@next_button.w / 2)
42
+
43
+ @prev_button = LUIT::Button.new(@window, :previous, @prev_x, @y, "Previous", 0, 1)
44
+ @button_id_mapping = self.class.get_id_button_mapping
45
+ # puts "SHIP SETTING MAPPING"
46
+ # puts @button_id_mapping
47
+ end
48
+
49
+ def self.get_id_button_mapping
50
+ {
51
+ next: lambda { |setting, id| setting.next_clicked },
52
+ previous: lambda { |setting, id| setting.previous_clicked }
53
+ }
54
+ end
55
+
56
+ def get_values
57
+ # puts "GETTING DIFFICULTY: #{@value}"
58
+ if @value
59
+ @value
60
+ end
61
+ end
62
+
63
+ # def get_image
64
+ # klass = eval(@value)
65
+ # puts "KLASS HERE : #{klass.get_image_assets_path(klass::SHIP_MEDIA_DIRECTORY)}"
66
+ # return klass.get_right_broadside_image(klass::SHIP_MEDIA_DIRECTORY)
67
+ # end
68
+
69
+ def update mouse_x, mouse_y
70
+ @mouse_x, @mouse_y = [mouse_x, mouse_y]
71
+ # puts "SHIP SETTING - UPDATE"
72
+ # @mouse_x = mouse_x
73
+ # @mouse_y = mouse_y
74
+ # @next_x = max_width / 5
75
+ # puts "new next x: #{@next_x}"
76
+ # @next_button.update(@next_x - @next_button.w, @y)
77
+ @next_button.update(-@next_button.w, 0)
78
+ # puts "NEXT IS AT: #{@next_button.x}"
79
+ # @next_button.update(@next_x - (@next_button.w / 2), @y)
80
+ @prev_button.update(0,0)
81
+ return @value
82
+ end
83
+
84
+ def draw
85
+ # @font.draw("<", @next_x, @y, 1, 1.0, 1.0, 0xff_ffff00)
86
+
87
+ @next_button.draw(-@next_button.w, 0)
88
+
89
+ # @font.draw(@value, ((@max_width / 2) - @font.text_width(@value) / 2), @y, 1, 1.0, 1.0, 0xff_ffff00)
90
+
91
+ # image = get_image
92
+ # image.draw((@max_width / 2) - image.width / 2, y + image.height / 2, 1)
93
+ @font.draw(@value, ((@max_width / 2) - @font.text_width(@value) / 2), @y, 1, 1.0, 1.0, 0xff_ffff00)
94
+ # @font.draw(">", @prev_x, @y, 1, 1.0, 1.0, 0xff_ffff00)
95
+ @prev_button.draw(0,0)
96
+ end
97
+
98
+ end
@@ -1,3 +1,3 @@
1
1
  module ZOrder
2
- Background, Building, Cursor, Projectile, BigExplosions, Pickups, Enemy, Player, SmallExplosions, UI = *0..10
2
+ Background, Building, LaserParticle, Projectile, BigExplosions, Pickups, Enemy, Player, Ship, Hardpoint, Launcher, SmallExplosions, UI, CurserUIBuffer, Cursor = *0..50
3
3
  end