line-em-up 0.3.5 → 0.3.6

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: d9421cc61562776406fdb6434aefa629abe793a3
4
- data.tar.gz: 4958a21d527c866522676a7f346b6735fc33ae2e
3
+ metadata.gz: a780d246a95abf5113ec05675e5f371d98c607e6
4
+ data.tar.gz: fbe35beb2057b0bb4585006729cb10cbd9e02d06
5
5
  SHA512:
6
- metadata.gz: ea9e7e14ff9596ed5000a2c1a0ed08c5a4b1c152a74f7c6c63ce408db376252f2289459a203265215de674ce6f807a919073f6910f7afefd0f100d3a8177fc2e
7
- data.tar.gz: 708c5fd5be3f031830ec85d22bfc28761144b4228112313d9e9a8af6da39c347b99672e384ebc4251d5430aa60902c01f870ca99fb54c77a744947cc59ac2c00
6
+ metadata.gz: 3023953f7bfbe84799d35a5525d588964c237700c63ae5521df82359e28a383146adca85a83bad6154020641ae03912bd1e311d9c6dc74a2328d32c0fe79d3c9
7
+ data.tar.gz: d1dad27f58937b300038036482dd4b630100bcebef585db019870454bf3092bcd36bd8b2b2f9490e36c72e96c4c8e3bc30ddd5a31b9c84bd01335dd25457dc44
@@ -60,7 +60,7 @@ Dir["#{CURRENT_DIRECTORY}/models/*.rb"].each { |f| require f }
60
60
  # exit if Object.const_defined?(:Ocra) #allow ocra to create an exe without executing the entire script
61
61
 
62
62
 
63
- WIDTH, HEIGHT = 640, 480
63
+ DEFAULT_WIDTH, DEFAULT_HEIGHT = 640, 480
64
64
 
65
65
  RESOLUTIONS = [[640, 480], [800, 600], [960, 720], [1024, 768], [1280, 960], [1400, 1050], [1440, 1080], [1600, 1200], [1856, 1392], [1920, 1440], [2048, 1536]]
66
66
  # RESOLUTIONS = [[640, 480], [800, 600], [960, 720], [1024, 768]]
@@ -69,81 +69,8 @@ RESOLUTIONS = [[640, 480], [800, 600], [960, 720], [1024, 768], [1280, 960], [14
69
69
  class GameWindow < Gosu::Window
70
70
  attr_accessor :width, :height, :block_all_controls
71
71
 
72
- # Switch button downs to this method
73
- def button_down(id)
74
- # puts "HERE: #{id.inspect}"
75
- # super(id)
76
- if id == Gosu::MsLeft && @menu_open && @menu
77
- @menu.clicked
78
- end
79
- end
80
-
81
- def self.reset(window, options = {})
82
- window = GameWindow.new(window.width, window.height, window.fullscreen?, {block_controls_until_button_up: true, debug: options[:debug]}).show
83
- end
84
-
85
-
86
- def self.start width = nil, height = nil, fullscreen = false, options = {}
87
- # window = GameWindow.new.show
88
- GameWindow.new(width, height, fullscreen, options).show
89
- end
90
-
91
- # When fullscreen, try to match window with screen resolution
92
- # .screen_height ⇒ Integer
93
- # The height (in pixels) of the user's primary screen.
94
- # .screen_width ⇒ Integer
95
- # The width (in pixels) of the user's primary screen.
96
-
97
- def self.fullscreen(window)
98
- window.fullscreen = !window.fullscreen?
99
- end
100
-
101
- def self.resize(window, width, height, fullscreen)
102
- window = GameWindow.new(width, height).show
103
- window.fullscreen = fullscreen
104
- end
105
-
106
- def self.find_index_of_current_resolution width, height
107
- current_index = nil
108
- counter = 0
109
- RESOLUTIONS.each do |resolution|
110
- break if current_index && current_index > 0
111
- current_index = counter if resolution[0] == width && resolution[1] == height
112
- counter += 1
113
- end
114
- return current_index
115
- end
116
-
117
- def self.up_resolution(window)
118
- # puts "UP RESLUTION"
119
- index = find_index_of_current_resolution(window.width, window.height)
120
- # puts "FOUND INDEX: #{index}"
121
- if index == RESOLUTIONS.count - 1
122
- # Max resolution, do nothing
123
- else
124
- # window.width = RESOLUTIONS[index + 1][0]
125
- # window.height = RESOLUTIONS[index + 1][1]
126
- width = RESOLUTIONS[index + 1][0]
127
- height = RESOLUTIONS[index + 1][1]
128
- # puts "UPPING TO #{width} x #{height}"
129
- window = GameWindow.new(width, height, {block_resize: true}).show
130
- end
131
- end
132
-
133
- def self.down_resolution(window)
134
- index = find_index_of_current_resolution(window.width, window.height)
135
- if index == 0
136
- # Min resolution, do nothing
137
- else
138
- # window.width = RESOLUTIONS[index - 1][0]
139
- # window.height = RESOLUTIONS[index - 1][1]
140
- width = RESOLUTIONS[index - 1][0]
141
- height = RESOLUTIONS[index - 1][1]
142
- window = GameWindow.new(width, height, {block_resize: true}).show
143
- end
144
- end
145
-
146
72
  def initialize width = nil, height = nil, fullscreen = false, options = {}
73
+ @difficulty = options[:difficulty]
147
74
  @block_all_controls = !options[:block_controls_until_button_up].nil? && options[:block_controls_until_button_up] == true ? true : false
148
75
  @debug = options[:debug]
149
76
  # GameWindow.fullscreen(self) if fullscreen
@@ -151,8 +78,8 @@ class GameWindow < Gosu::Window
151
78
  @center_ui_y = 0
152
79
  @center_ui_x = 0
153
80
 
154
- @width = width || WIDTH
155
- @height = height || HEIGHT
81
+ @width = width || DEFAULT_WIDTH
82
+ @height = height || DEFAULT_HEIGHT
156
83
 
157
84
  reset_center_font_ui_y
158
85
 
@@ -182,7 +109,7 @@ class GameWindow < Gosu::Window
182
109
 
183
110
  @gl_background = GLBackground.new
184
111
 
185
- @player = Player.new(@scale, @width / 2, @height / 2)
112
+ @player = Player.new(@scale, @width / 2, @height / 2, @width, @height)
186
113
  @grappling_hook = nil
187
114
 
188
115
  @buildings = Array.new
@@ -209,13 +136,97 @@ class GameWindow < Gosu::Window
209
136
  reset_font_ui_y
210
137
 
211
138
  # @boss_active_at_enemies_killed = 500
212
- @boss_active_at_enemies_killed = 750
213
- @boss_active_at_level = 4
139
+ if @difficulty == 'easy'
140
+ @boss_active_at_enemies_killed = 100
141
+ @boss_active_at_level = 1
142
+ elsif @difficulty == "medium"
143
+ @boss_active_at_level = 3
144
+ @boss_active_at_enemies_killed = 350
145
+ else
146
+ @boss_active_at_level = 4
147
+ @boss_active_at_enemies_killed = 700
148
+ end
149
+
214
150
  @boss_active = false
215
151
  @boss = nil
216
152
  @boss_killed = false
217
153
  end
218
154
 
155
+
156
+ # Switch button downs to this method
157
+ def button_down(id)
158
+ # puts "HERE: #{id.inspect}"
159
+ # super(id)
160
+ if id == Gosu::MsLeft && @menu_open && @menu
161
+ @menu.clicked
162
+ end
163
+ end
164
+
165
+ def self.reset(window, options = {})
166
+ window = GameWindow.new(window.width, window.height, window.fullscreen?, options.merge({block_controls_until_button_up: true})).show
167
+ end
168
+
169
+
170
+ def self.start width = nil, height = nil, fullscreen = false, options = {}
171
+ # window = GameWindow.new.show
172
+ GameWindow.new(width, height, fullscreen, options).show
173
+ end
174
+
175
+ # When fullscreen, try to match window with screen resolution
176
+ # .screen_height ⇒ Integer
177
+ # The height (in pixels) of the user's primary screen.
178
+ # .screen_width ⇒ Integer
179
+ # The width (in pixels) of the user's primary screen.
180
+
181
+ def self.fullscreen(window)
182
+ window.fullscreen = !window.fullscreen?
183
+ end
184
+
185
+ def self.resize(window, width, height, fullscreen)
186
+ window = GameWindow.new(width, height).show
187
+ window.fullscreen = fullscreen
188
+ end
189
+
190
+ def self.find_index_of_current_resolution width, height
191
+ current_index = nil
192
+ counter = 0
193
+ RESOLUTIONS.each do |resolution|
194
+ break if current_index && current_index > 0
195
+ current_index = counter if resolution[0] == width && resolution[1] == height
196
+ counter += 1
197
+ end
198
+ return current_index
199
+ end
200
+
201
+ def self.up_resolution(window)
202
+ # # puts "UP RESLUTION"
203
+ # index = find_index_of_current_resolution(window.width, window.height)
204
+ # # puts "FOUND INDEX: #{index}"
205
+ # if index == RESOLUTIONS.count - 1
206
+ # # Max resolution, do nothing
207
+ # else
208
+ # # window.width = RESOLUTIONS[index + 1][0]
209
+ # # window.height = RESOLUTIONS[index + 1][1]
210
+ # width = RESOLUTIONS[index + 1][0]
211
+ # height = RESOLUTIONS[index + 1][1]
212
+ # # puts "UPPING TO #{width} x #{height}"
213
+ # window = GameWindow.new(width, height, {block_resize: true}).show
214
+ # end
215
+ end
216
+
217
+ def self.down_resolution(window)
218
+ # index = find_index_of_current_resolution(window.width, window.height)
219
+ # if index == 0
220
+ # # Min resolution, do nothing
221
+ # else
222
+ # # window.width = RESOLUTIONS[index - 1][0]
223
+ # # window.height = RESOLUTIONS[index - 1][1]
224
+ # width = RESOLUTIONS[index - 1][0]
225
+ # height = RESOLUTIONS[index - 1][1]
226
+ # window = GameWindow.new(width, height, {block_resize: true}).show
227
+ # end
228
+ end
229
+
219
230
  def button_up id
220
231
  @block_all_controls = false
221
232
  # Grappling hook always active
@@ -260,6 +271,7 @@ class GameWindow < Gosu::Window
260
271
  end
261
272
 
262
273
  def update
274
+ @pointer.update(self.mouse_x, self.mouse_y) if @pointer
263
275
  if @start_fullscreen
264
276
  @start_fullscreen = false
265
277
  GameWindow.fullscreen(self)
@@ -271,8 +283,8 @@ class GameWindow < Gosu::Window
271
283
  @menu_open = true
272
284
  @can_open_menu = false
273
285
  @menu = Menu.new(self)
274
- @menu.add_item(Gosu::Image.new(self, "#{MEDIA_DIRECTORY}/exit.png", false), get_center_font_ui_x, get_center_font_ui_y, 1, lambda { self.close }, Gosu::Image.new(self, "#{MEDIA_DIRECTORY}/exit_hover.png", false))
275
- @menu.add_item(Gosu::Image.new(self, "#{MEDIA_DIRECTORY}/resume.png", false), get_center_font_ui_x, get_center_font_ui_y, 1, lambda { @menu_open = false; @menu = nil; @can_open_menu = true; }, Gosu::Image.new(self, "#{MEDIA_DIRECTORY}/resume.png", false))
286
+ @menu.add_item(Gosu::Image.new(self, "#{MEDIA_DIRECTORY}/exit.png", false), get_center_font_ui_x, get_center_font_ui_y, ZOrder::UI, lambda { self.close }, Gosu::Image.new(self, "#{MEDIA_DIRECTORY}/exit_hover.png", false))
287
+ @menu.add_item(Gosu::Image.new(self, "#{MEDIA_DIRECTORY}/resume.png", false), get_center_font_ui_x, get_center_font_ui_y, ZOrder::UI, lambda { @menu_open = false; @menu = nil; @can_open_menu = true; }, Gosu::Image.new(self, "#{MEDIA_DIRECTORY}/resume.png", false))
276
288
  # close!
277
289
  end
278
290
  if Gosu.button_down?(Gosu::KB_M)
@@ -312,25 +324,26 @@ class GameWindow < Gosu::Window
312
324
  end
313
325
 
314
326
  if @player.is_alive && !@game_pause && !@menu_open
315
- @player.update(@width, @height)
316
- @player.move_left(@width) if Gosu.button_down?(Gosu::KB_LEFT) || Gosu.button_down?(Gosu::GP_LEFT) || Gosu.button_down?(Gosu::KB_A)
317
- @player.move_right(@width) if Gosu.button_down?(Gosu::KB_RIGHT) || Gosu.button_down?(Gosu::GP_RIGHT) || Gosu.button_down?(Gosu::KB_D)
318
- @player.accelerate(@height) if Gosu.button_down?(Gosu::KB_UP) || Gosu.button_down?(Gosu::GP_UP) || Gosu.button_down?(Gosu::KB_W)
319
- @player.brake(@height) if Gosu.button_down?(Gosu::KB_DOWN) || Gosu.button_down?(Gosu::GP_DOWN) || Gosu.button_down?(Gosu::KB_S)
327
+ @player.update()
328
+ @player.move_left() if Gosu.button_down?(Gosu::KB_LEFT) || Gosu.button_down?(Gosu::GP_LEFT) || Gosu.button_down?(Gosu::KB_A)
329
+ @player.move_right() if Gosu.button_down?(Gosu::KB_RIGHT) || Gosu.button_down?(Gosu::GP_RIGHT) || Gosu.button_down?(Gosu::KB_D)
330
+ @player.accelerate() if Gosu.button_down?(Gosu::KB_UP) || Gosu.button_down?(Gosu::GP_UP) || Gosu.button_down?(Gosu::KB_W)
331
+ @player.brake() if Gosu.button_down?(Gosu::KB_DOWN) || Gosu.button_down?(Gosu::GP_DOWN) || Gosu.button_down?(Gosu::KB_S)
320
332
 
321
333
  if Gosu.button_down?(Gosu::MS_RIGHT)
322
334
  if @grappling_hook == nil && @player.grapple_hook_cooldown_wait <= 0
323
- @grappling_hook = GrapplingHook.new(@scale, @player, self.mouse_x, self.mouse_y)
335
+ @grappling_hook = GrapplingHook.new(@scale, @width, @height, @player, self.mouse_x, self.mouse_y)
336
+ @player.grapple_hook_cooldown_wait = @grappling_hook.cooldown_delay
324
337
  end
325
338
  end
326
339
 
327
340
  if Gosu.button_down?(Gosu::MS_LEFT)
328
- @projectiles = @projectiles + @player.trigger_secondary_attack(@width, @height, self.mouse_x, self.mouse_y)
341
+ @projectiles = @projectiles + @player.trigger_secondary_attack(@pointer)
329
342
  end
330
343
 
331
344
  if Gosu.button_down?(Gosu::KB_SPACE)
332
345
  if @player.cooldown_wait <= 0
333
- results = @player.attack(@width, @height, self.mouse_x, self.mouse_y)
346
+ results = @player.attack(@pointer)
334
347
  projectiles = results[:projectiles]
335
348
  cooldown = results[:cooldown]
336
349
  @player.cooldown_wait = cooldown.to_f.fdiv(@player.attack_speed)
@@ -368,23 +381,23 @@ class GameWindow < Gosu::Window
368
381
 
369
382
 
370
383
 
371
- @buildings.reject! { |building| !building.update(@width, @height) }
384
+ @buildings.reject! { |building| !building.update() }
372
385
 
373
386
  if @player.is_alive && @grappling_hook
374
- grap_result = @grappling_hook.update(@width, @height, @player)
387
+ grap_result = @grappling_hook.update(@player)
375
388
  @grappling_hook = nil if !grap_result
376
389
  end
377
390
 
378
- @pickups.reject! { |pickup| !pickup.update(@width, @height, self.mouse_x, self.mouse_y) }
391
+ @pickups.reject! { |pickup| !pickup.update(self.mouse_x, self.mouse_y) }
379
392
 
380
- @projectiles.reject! { |projectile| !projectile.update(@width, @height, self.mouse_x, self.mouse_y) }
393
+ @projectiles.reject! { |projectile| !projectile.update(self.mouse_x, self.mouse_y) }
381
394
 
382
- @enemy_projectiles.reject! { |projectile| !projectile.update(@width, @height, self.mouse_x, self.mouse_y) }
383
- @enemy_destructable_projectiles.reject! { |projectile| !projectile.update(@width, @height, self.mouse_x, self.mouse_y) }
384
- @enemies.reject! { |enemy| !enemy.update(@width, @height, nil, nil, @player) }
395
+ @enemy_projectiles.reject! { |projectile| !projectile.update(self.mouse_x, self.mouse_y) }
396
+ @enemy_destructable_projectiles.reject! { |projectile| !projectile.update(self.mouse_x, self.mouse_y) }
397
+ @enemies.reject! { |enemy| !enemy.update(nil, nil, @player) }
385
398
 
386
399
  if @boss
387
- result = @boss.update(@width, @height, nil, nil, @player)
400
+ result = @boss.update(nil, nil, @player)
388
401
  if !result
389
402
  @boss_killed = true
390
403
  @boss = nil
@@ -398,7 +411,7 @@ class GameWindow < Gosu::Window
398
411
 
399
412
 
400
413
  if !@boss_killed && !@boss_active
401
- @buildings.push(Building.new(@scale)) if rand(100) == 0
414
+ @buildings.push(Building.new(@scale, @width, @height)) if rand(100) == 0
402
415
  end
403
416
 
404
417
  # Temp
@@ -408,6 +421,7 @@ class GameWindow < Gosu::Window
408
421
  if @player.is_alive && rand(@enemies_random_spawn_timer) == 0 && @enemies.count <= @max_enemies
409
422
  (0..(@enemies_spawner_counter / 2).round).each do |count|
410
423
  @enemies.push(EnemyPlayer.new(@scale, @width, @height)) if @enemies.count <= @max_enemy_count
424
+ # @enemies.push(MissileBoat.new(@scale, @width, @height)) if @enemies.count == 0
411
425
  end
412
426
  end
413
427
  if @player.time_alive % 500 == 0
@@ -445,7 +459,7 @@ class GameWindow < Gosu::Window
445
459
  # Move to enemy mehtods
446
460
  @enemies.each do |enemy|
447
461
  if enemy.cooldown_wait <= 0
448
- results = enemy.attack(@width, @height, @player)
462
+ results = enemy.attack(@player)
449
463
 
450
464
  projectiles = results[:projectiles]
451
465
  cooldown = results[:cooldown]
@@ -463,7 +477,7 @@ class GameWindow < Gosu::Window
463
477
 
464
478
  if @boss
465
479
  if @boss.cooldown_wait <= 0
466
- results = @boss.attack(@width, @height, @player)
480
+ results = @boss.attack(@player)
467
481
  projectiles = results[:projectiles]
468
482
  cooldown = results[:cooldown]
469
483
  @boss.cooldown_wait = cooldown.to_f.fdiv(@boss.attack_speed)
@@ -476,7 +490,7 @@ class GameWindow < Gosu::Window
476
490
  end
477
491
  end
478
492
  if @boss.secondary_cooldown_wait <= 0
479
- results = @boss.secondary_attack(@width, @height, @player)
493
+ results = @boss.secondary_attack(@player)
480
494
 
481
495
  projectiles = results[:projectiles]
482
496
  cooldown = results[:cooldown]
@@ -491,7 +505,7 @@ class GameWindow < Gosu::Window
491
505
  end
492
506
 
493
507
  if @boss.tertiary_cooldown_wait <= 0
494
- results = @boss.tertiary_attack(@width, @height, @player)
508
+ results = @boss.tertiary_attack(@player)
495
509
 
496
510
  projectiles = results[:projectiles]
497
511
  cooldown = results[:cooldown]
@@ -517,7 +531,7 @@ class GameWindow < Gosu::Window
517
531
  @footer_bar.draw(@player)
518
532
  @boss.draw if @boss
519
533
  # @pointer.draw(self.mouse_x, self.mouse_y) if @grappling_hook.nil? || !@grappling_hook.active
520
- @pointer.draw(self.mouse_x, self.mouse_y)# if @grappling_hook.nil? || !@grappling_hook.active
534
+ @pointer.draw# if @grappling_hook.nil? || !@grappling_hook.active
521
535
 
522
536
  @player.draw() if @player.is_alive
523
537
  @grappling_hook.draw(@player) if @player.is_alive && @grappling_hook
@@ -3,9 +3,8 @@
3
3
  require 'rubygems'
4
4
  require 'gosu'
5
5
  require 'gl'
6
- # require 'rmagick'
7
- # require 'geometry'
8
- # require_relative 'star.rb'
9
- # require_relative 'bullet.rb'
10
- # require_relative 'player.rb'
11
- # require_relative 'enemy_player.rb'
6
+ CURRENT_DIRECTORY = File.expand_path('../', __FILE__)
7
+
8
+ Dir["#{CURRENT_DIRECTORY}/models/*.rb"].each { |f| require f }
9
+ Dir["#{CURRENT_DIRECTORY}/lib/*.rb"].each { |f| require f }
10
+
@@ -5,25 +5,38 @@ module ConfigSetting
5
5
  # puts "HERE: #{file_location} and #{setting_name} and #{setting_value}"
6
6
  create_file_if_non_existent(file_location)
7
7
  if setting_value
8
+ # File.open('xxx.txt').each do |line|
9
+ # print "#{line_num += 1} #{line}"
10
+ # end
8
11
  if File.readlines(file_location).grep(/#{setting_name}:/).size > 0
9
- # puts "FOUND SETTING"
10
12
  text = File.read(file_location)
11
- # puts "FOUDN IN FILE: #{text.inspect}"
12
- replace = text.gsub(/^#{setting_name}: ([^$]*)$/, setting_value)
13
- # replace = replace.gsub(/bbb/, "Replace bbb with 222")
14
- File.open(file_location, "w") {|file| file.puts "#{setting_name}: #{replace}"}
13
+ puts "READ TEXT IN FILE: #{text}"
14
+ File.open(file_location, 'w+'){|f| f << text.sub(/^#{setting_name}: ([^;]*);$/, "#{setting_name}: #{setting_value};") }
15
15
  else
16
- # puts "COULDNT FIND SETTING"
17
16
  File.open(file_location, 'a') do |f|
18
- f << "#{setting_name}: #{setting_value}"
17
+ f << "\n#{setting_name}: #{setting_value};"
19
18
  end
20
19
  end
20
+
21
+ # if File.readlines(file_location).grep(/#{setting_name}:/).size > 0
22
+ # # puts "FOUND SETTING"
23
+ # text = File.read(file_location)
24
+ # # puts "FOUDN IN FILE: #{text.inspect}"
25
+ # replace = text.gsub(/^#{setting_name}: ([^$]*)$/, setting_value)
26
+ # # replace = replace.gsub(/bbb/, "Replace bbb with 222")
27
+ # File.open(file_location, "w") {|file| file.puts "#{setting_name}: #{replace}"}
28
+ # else
29
+ # # puts "COULDNT FIND SETTING"
30
+ # File.open(file_location, 'a') do |f|
31
+ # f << "#{setting_name}: #{setting_value}"
32
+ # end
33
+ # end
21
34
  end
22
35
  end
23
36
 
24
37
  def self.get_setting file_location, setting_name, default_value
25
38
  create_file_if_non_existent(file_location)
26
- test = File.readlines(file_location).select { |line| line =~ /^#{setting_name}: ([^$]*)$/ }
39
+ test = File.readlines(file_location).select { |line| line =~ /^#{setting_name}: ([^;]*);$/ }
27
40
  if test && test.first
28
41
  # puts "BEFORE SCAN: #{test}"
29
42
  # So many firstsss
@@ -48,7 +61,7 @@ module ConfigSetting
48
61
  if test == [] || test.nil? || test == ''
49
62
  test = default_value
50
63
  end
51
- return test
64
+ return test.gsub(';', '')
52
65
  end
53
66
 
54
67
  def self.create_file_if_non_existent file_location
@@ -0,0 +1,78 @@
1
+ require_relative 'setting.rb'
2
+ # require_relative "config_settings.rb"
3
+
4
+ class DifficultySetting < Setting
5
+ DIFFICULTIES = ["easy", "medium", "hard"]
6
+ attr_accessor :x, :y, :font, :max_width, :max_height
7
+
8
+
9
+ def initialize max_width, max_height, height, config_file_path
10
+ # puts "INNITING #{config_file_path}"
11
+ @font = Gosu::Font.new(20)
12
+ # @x = width
13
+ @y = height
14
+ @max_width = max_width
15
+ @max_height = max_height
16
+ @next_x = 15
17
+ @prev_x = @max_width - 15 - @font.text_width('>')
18
+ @config_file_path = config_file_path
19
+ @name = 'difficulty'
20
+ @value = ConfigSetting.get_setting(@config_file_path, @name, DIFFICULTIES[0])
21
+ end
22
+
23
+ def get_difficulty
24
+ # puts "GETTING DIFFICULTY: #{@value}"
25
+ if @value
26
+ @value
27
+ end
28
+ end
29
+
30
+ def draw
31
+ @font.draw("<", @next_x, @y, 1, 1.0, 1.0, 0xff_ffff00)
32
+ @font.draw(@value, ((@max_width / 2) - @font.text_width(@value) / 2), @y, 1, 1.0, 1.0, 0xff_ffff00)
33
+ @font.draw(">", @prev_x, @y, 1, 1.0, 1.0, 0xff_ffff00)
34
+ end
35
+
36
+ def update mouse_x, mouse_y
37
+ end
38
+
39
+ def clicked mx, my
40
+ if is_mouse_hovering_next(mx, my)
41
+ puts "NEXT!!"
42
+ index = DIFFICULTIES.index(@value)
43
+ value = @value
44
+ if index == 0
45
+ value = DIFFICULTIES[DIFFICULTIES.count - 1]
46
+ else
47
+ value = DIFFICULTIES[index - 1]
48
+ end
49
+ ConfigSetting.set_setting(@config_file_path, @name, value)
50
+ @value = value
51
+ elsif is_mouse_hovering_prev(mx, my)
52
+ puts "PREVV!!!!"
53
+ index = DIFFICULTIES.index(@value)
54
+ value = @value
55
+ if index == DIFFICULTIES.count - 1
56
+ value = DIFFICULTIES[0]
57
+ else
58
+ value = DIFFICULTIES[index + 1]
59
+ end
60
+ ConfigSetting.set_setting(@config_file_path, @name, value)
61
+ @value = value
62
+ end
63
+ end
64
+ def is_mouse_hovering_next mx, my
65
+ local_width = @font.text_width('>')
66
+ local_height = @font.height
67
+
68
+ (mx >= @next_x and my >= @y) and (mx <= @next_x + local_width) and (my <= @y + local_height)
69
+ end
70
+ def is_mouse_hovering_prev mx, my
71
+ local_width = @font.text_width('<')
72
+ local_height = @font.height
73
+
74
+ (mx >= @prev_x and my >= @y) and (mx <= @prev_x + local_width) and (my <= @y + local_height)
75
+ end
76
+
77
+
78
+ end
Binary file
@@ -25,7 +25,7 @@ class Bomb < Projectile
25
25
  end
26
26
 
27
27
 
28
- def update width, height, mouse_x = nil, mouse_y = nil, player = nil
28
+ def update mouse_x = nil, mouse_y = nil, player = nil
29
29
  vx = (self.class.get_starting_speed * @scale) * Math.cos(@angle * Math::PI / 180)
30
30
 
31
31
  vy = (self.class.get_starting_speed * @scale) * Math.sin(@angle * Math::PI / 180)
@@ -35,6 +35,6 @@ class Bomb < Projectile
35
35
  @x = @x + vx
36
36
  @y = @y + vy
37
37
 
38
- super(width, height, mouse_x, mouse_y)
38
+ super(mouse_x, mouse_y)
39
39
  end
40
40
  end
@@ -4,18 +4,24 @@ class Building < GeneralObject
4
4
  POINT_VALUE_BASE = 1
5
5
  attr_accessor :health, :armor, :x, :y
6
6
 
7
- def initialize(scale, x = nil, y = nil)
8
- @scale = scale
7
+
8
+ def get_image
9
+ Gosu::Image.new("#{MEDIA_DIRECTORY}/building.png")
10
+ end
11
+
12
+ def initialize(scale, screen_width, screen_height, x = nil, y = nil, options = {})
13
+ # @scale = scale
9
14
  # image = Magick::Image::read("#{MEDIA_DIRECTORY}/building.png").first.resize(0.3)
10
15
  # @image = Gosu::Image.new(image, :tileable => true)
11
- @image = Gosu::Image.new("#{MEDIA_DIRECTORY}/building.png")
12
- @image_width = @image.width * @scale
13
- @image_height = @image.height * @scale
14
- @image_size = @image_width * @image_height / 2
15
- @image_radius = (@image_width + @image_height) / 4
16
- @x = rand * 800
17
- @y = 0 - get_height
16
+ # @image = Gosu::Image.new("#{MEDIA_DIRECTORY}/building.png")
17
+ # @image_width = @image.width * @scale
18
+ # @image_height = @image.height * @scale
19
+ # @image_size = @image_width * @image_height / 2
20
+ # @image_radius = (@image_width + @image_height) / 4
21
+ # @x = rand * 800
22
+ # @y = 0 - get_height
18
23
  # puts "NEW BUILDING: #{@x} and #{@y}"
24
+ super(scale, rand(screen_width), 0 - get_image.height, screen_width, screen_height, options)
19
25
  @health = 15
20
26
  @armor = 0
21
27
  @current_speed = (GLBackground::SCROLLING_SPEED * @scale)
@@ -36,11 +42,11 @@ class Building < GeneralObject
36
42
  def drops
37
43
  rand_num = rand(10)
38
44
  if rand(10) == 9
39
- [HealthPack.new(@scale, @x, @y)]
45
+ [HealthPack.new(@scale, @screen_width, @screen_height, @x, @y)]
40
46
  elsif rand(10) == 8
41
- [BombPack.new(@scale, @x, @y)]
47
+ [BombPack.new(@scale, @screen_width, @screen_height, @x, @y)]
42
48
  else
43
- [MissilePack.new(@scale, @x, @y)]
49
+ [MissilePack.new(@scale, @screen_width, @screen_height, @x, @y)]
44
50
  end
45
51
  end
46
52
 
@@ -49,10 +55,10 @@ class Building < GeneralObject
49
55
  end
50
56
 
51
57
 
52
- def update width, height, mouse_x = nil, mouse_y = nil, player = nil
58
+ def update mouse_x = nil, mouse_y = nil, player = nil
53
59
  if is_alive
54
60
  @y += @current_speed
55
- @y < height + get_height
61
+ @y < @screen_height + get_height
56
62
  else
57
63
  false
58
64
  end
@@ -1,43 +1,12 @@
1
- require_relative 'projectile.rb'
1
+ require_relative 'dumb_projectile.rb'
2
2
 
3
- class Bullet < Projectile
3
+ class Bullet < DumbProjectile
4
4
  DAMAGE = 5
5
5
  COOLDOWN_DELAY = 30
6
+ # Friendly projects are + speeds
6
7
  MAX_SPEED = 5
7
8
 
8
9
  def get_image
9
10
  Gosu::Image.new("#{MEDIA_DIRECTORY}/bullet-mini.png")
10
11
  end
11
-
12
- def initialize(scale, width, height, object, mouse_x = nil, mouse_y = nil, options = {})
13
- @scale = scale
14
- @time_alive = 0
15
- @image = get_image
16
- # @color = Gosu::Color.new(0xff_000000)
17
- # @color.red = rand(255 - 40) + 40
18
- # @color.green = rand(255 - 40) + 40
19
- # @color.blue = rand(255 - 40) + 40
20
- if LEFT == options[:side]
21
- @x = object.x - (object.get_width / 2)
22
- @y = object.y# - player.get_height
23
- elsif RIGHT == options[:side]
24
- @x = (object.x + object.get_width / 2) - 4
25
- @y = object.y# - player.get_height
26
- else
27
- @x = object.x
28
- @y = object.y
29
- end
30
- @image_width = @image.width * @scale
31
- @image_height = @image.height * @scale
32
- @image_size = @image_width * @image_height / 2
33
- @image_radius = (@image_width + @image_height) / 4
34
- @current_speed = self.class.get_max_speed * @scale
35
- end
36
-
37
- def update width, height, mouse_x = nil, mouse_y = nil, player = nil
38
- @y -= @current_speed
39
- # Return false when out of screen (gets deleted then)
40
- @y > 0 && @y < height
41
- # super(mouse_x, mouse_y)
42
- end
43
12
  end
@@ -1,6 +1,6 @@
1
1
  require_relative 'general_object.rb'
2
2
  class Cursor < GeneralObject
3
- # attr_reader :img, :visible, :imgObj
3
+ attr_accessor :x, :y, :image_width_half, :image_height_half
4
4
 
5
5
 
6
6
  def get_image
@@ -13,13 +13,20 @@ class Cursor < GeneralObject
13
13
  @image = get_image
14
14
  @image_width = @image.width * @scale
15
15
  @image_height = @image.height * @scale
16
- @image_size = @image_width * @image_height / 2
17
- @image_radius = (@image_width + @image_height) / 4
16
+ @image_width_half = @image_width / 2
17
+ @image_height_half = @image_height / 2
18
+ @x = 0
19
+ @y = 0
18
20
  end
19
21
 
20
22
 
21
- def draw mouse_x, mouse_y
22
- @image.draw(mouse_x - get_width / 2, mouse_y - get_height / 2, ZOrder::Cursor, @scale, @scale)
23
+ def draw
24
+ @image.draw(@x - @image_width_half, @y - @image_height_half, ZOrder::Cursor, @scale, @scale)
25
+ end
26
+
27
+ def update mouse_x, mouse_y
28
+ @x = mouse_x
29
+ @y = mouse_y
23
30
  end
24
31
 
25
32
  end