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.
@@ -1,7 +1,7 @@
1
1
  require_relative 'general_object.rb'
2
2
 
3
3
  class Projectile < GeneralObject
4
- attr_accessor :x, :y, :time_alive, :mouse_start_x, :mouse_start_y, :vector_x, :vector_y, :angle, :radian
4
+ attr_accessor :x, :y, :time_alive, :vector_x, :vector_y, :angle, :radian
5
5
  # WARNING THESE CONSTANTS DON'T GET OVERRIDDEN BY SUBCLASSES. NEED GETTER METHODS
6
6
  COOLDOWN_DELAY = 50
7
7
  STARTING_SPEED = 3.0
@@ -13,47 +13,114 @@ class Projectile < GeneralObject
13
13
  ADVANCED_HIT_BOX_DETECTION = false
14
14
 
15
15
 
16
- def initialize(scale, width, height, object, mouse_x = nil, mouse_y = nil, options = {})
17
- @scale = scale
18
- @image = get_image
19
- @time_alive = 0
20
- @mouse_start_x = mouse_x
21
- @mouse_start_y = mouse_y
16
+ def get_image
17
+ puts "override get_image!"
18
+ Gosu::Image.new("#{MEDIA_DIRECTORY}/question.png")
19
+ end
22
20
 
23
- if LEFT == options[:side]
24
- @x = object.x - (object.get_width / 2)
25
- @y = object.y
26
- elsif RIGHT == options[:side]
27
- @x = (object.x + object.get_width / 2) - 4
28
- @y = object.y
29
- else
30
- @x = object.x
31
- @y = object.y
32
- end
21
+ def initialize(scale, screen_width, screen_height, object, end_point_x, end_point_y, angle_min = nil, angle_max = nil, angle_init = nil, options = {})
22
+ options[:relative_object] = object
23
+ super(scale, nil, nil, screen_width, screen_height, options)
33
24
 
34
- start_point = OpenStruct.new(:x => @x - width / 2, :y => @y - height / 2)
25
+ start_point = OpenStruct.new(:x => @x - screen_width / 2, :y => @y - screen_height / 2)
35
26
  # start_point = GeoPoint.new(@x - WIDTH / 2, @y - HEIGHT / 2)
36
27
  # end_point = OpenStruct.new(:x => @mouse_start_x, :y => @mouse_start_y)
37
- end_point = OpenStruct.new(:x => @mouse_start_x - width / 2, :y => @mouse_start_y - height / 2)
28
+ end_point = OpenStruct.new(:x => end_point_x - screen_width / 2, :y => end_point_y - screen_height / 2)
38
29
  # end_point = GeoPoint.new(@mouse_start_x - WIDTH / 2, @mouse_start_y - HEIGHT / 2)
39
30
  @angle = calc_angle(start_point, end_point)
40
31
  @radian = calc_radian(start_point, end_point)
41
32
 
33
+ # puts "PRE-ANGLE: #{@angle}"
42
34
 
35
+ @image_angle = @angle
43
36
  if @angle < 0
44
37
  @angle = 360 - @angle.abs
45
38
  end
46
- @image_width = @image.width * @scale
47
- @image_height = @image.height * @scale
48
- @image_size = @image_width * @image_height / 2
49
- @image_radius = (@image_width + @image_height) / 4
50
- # puts "INIT NEW ANGLE: #{@angle}"
39
+
40
+ if angle_min.nil? && angle_max.nil?
41
+ # do nothing
42
+ else
43
+ # if @angle < angle_min
44
+ # @angle = angle_max
45
+ # # elsif @angle < angle_min && @angle > add_angles(@angle, 180)
46
+ # # @angle = angle_max
47
+ if is_angle_between_two_angles?(@angle, angle_min, angle_max)
48
+ # Do nothing, we're good
49
+ # puts "ANGLE WAS BETWEEN TWO POINTS: #{@angle} was between #{angle_min} and #{angle_max}"
50
+ else
51
+ # puts "ANGLE WAS CHOSEN TO BE NEAREST: #{@angle} with #{angle_min} and #{angle_max}"
52
+ @angle = nearest_angle(@angle, angle_min, angle_max)
53
+ # puts "ANGLE WAS CHSOEN: #{@angle}"
54
+ end
55
+ end
56
+
57
+
58
+ if angle_init
59
+ @current_image_angle = (angle_init - 90) * -1
60
+ @end_image_angle = (@angle - 90) * -1
61
+ else
62
+ @current_image_angle = (@angle - 90) * -1
63
+ end
64
+
65
+ # puts "POST-ANGLE: #{@angle}"
66
+
67
+ # # Limit extreme angles 180 and 0 are the
68
+ # image_angle = 0
69
+ # if @angle > 160 <
70
+ # if @angle > 160 && @ange
71
+
72
+
51
73
  end
52
74
 
53
- # def get_image
54
- # puts "override get_image!"
55
- # Gosu::Image.new("#{MEDIA_DIRECTORY}/question.png")
56
- # end
75
+ def update mouse_x = nil, mouse_y = nil
76
+ if @end_image_angle && @time_alive > 10
77
+ incrementing_amount = 0.5
78
+ angle_difference = (@current_image_angle - @end_image_angle)
79
+ if incrementing_amount > angle_difference.abs
80
+ # puts "ENDING IMAGE HERE!!!!!!"
81
+ @current_image_angle = @end_image_angle
82
+ @end_image_angle = nil
83
+ elsif angle_difference > 0
84
+ @current_image_angle -= incrementing_amount
85
+ elsif angle_difference < 0
86
+ @current_image_angle += incrementing_amount
87
+ else
88
+ # puts "ENDING IMAGE HERE!!!!!!"
89
+ @current_image_angle = @end_image_angle
90
+ @end_image_angle = nil
91
+ end
92
+ end
93
+
94
+
95
+
96
+ new_speed = 0
97
+ if @time_alive > self.class.get_initial_delay
98
+ new_speed = self.class.get_starting_speed + (self.class.get_speed_increase_factor > 0 ? @time_alive * self.class.get_speed_increase_factor : 0)
99
+ new_speed = self.class.get_max_speed if new_speed > self.class.get_max_speed
100
+ new_speed = new_speed * @scale
101
+ end
102
+
103
+
104
+
105
+ vx = 0
106
+ vy = 0
107
+ if new_speed != 0
108
+ vx = ((new_speed / 3) * 1) * Math.cos(@angle * Math::PI / 180)
109
+
110
+ vy = ((new_speed / 3) * 1) * Math.sin(@angle * Math::PI / 180)
111
+ vy = vy * -1
112
+ end
113
+
114
+ @x = @x + vx
115
+ @y = @y + vy
116
+
117
+ super(mouse_x, mouse_y)
118
+ end
119
+
120
+ def draw
121
+ # limiting angle extreme by 2
122
+ @image.draw_rot(@x, @y, ZOrder::Projectile, @current_image_angle, 0.5, 0.5, @scale, @scale)
123
+ end
57
124
 
58
125
  def get_draw_ordering
59
126
  ZOrder::Projectile
@@ -69,7 +136,7 @@ class Projectile < GeneralObject
69
136
  # return test
70
137
  end
71
138
 
72
- require 'benchmark'
139
+ # require 'benchmark'
73
140
 
74
141
  def hit_objects(object_groups)
75
142
  drops = []
@@ -95,14 +162,9 @@ class Projectile < GeneralObject
95
162
  hit_object = Gosu.distance(@x, @y, object.x, object.y) < self.get_radius + object.get_radius
96
163
  end
97
164
  if hit_object
98
- # puts "HIT OBJECT"
99
165
  # hit_object = true
100
166
  if self.class.get_aoe <= 0
101
- # puts "shout be here"
102
- # puts "1: #{object.respond_to?(:health)}"
103
- # puts "2: #{object.respond_to?(:take_damage)}"
104
167
  if object.respond_to?(:health) && object.respond_to?(:take_damage)
105
- # puts "OBJECT TALING DAMAGE: #{self.class.get_damage}"
106
168
  object.take_damage(self.class.get_damage)
107
169
  end
108
170
 
@@ -144,7 +206,7 @@ class Projectile < GeneralObject
144
206
  end
145
207
  end
146
208
  end
147
- @y = -HEIGHT if hit_object
209
+ @y = @off_screen if hit_object
148
210
  return {drops: drops, point_value: points, killed: killed}
149
211
  end
150
212
 
@@ -161,9 +223,6 @@ class Projectile < GeneralObject
161
223
  def self.get_starting_speed
162
224
  self::STARTING_SPEED
163
225
  end
164
- def self.get_starting_speed
165
- self::STARTING_SPEED
166
- end
167
226
  def self.get_initial_delay
168
227
  self::INITIAL_DELAY
169
228
  end
@@ -4,7 +4,7 @@ class SmallExplosion < GeneralObject
4
4
  attr_reader :x, :y, :living_time
5
5
  TIME_TO_LIVE = 50
6
6
 
7
- def initialize(scale, x = nil, y = nil, image = nil)
7
+ def initialize(scale, screen_width, screen_height, x = nil, y = nil, image = nil, options = {})
8
8
  @scale = scale
9
9
  @smoke_scale = @scale * 1.2
10
10
  @smoke = Gosu::Image.new("#{MEDIA_DIRECTORY}/smoke.png")
@@ -18,6 +18,10 @@ class SmallExplosion < GeneralObject
18
18
  @image_size = @image_width * @image_height / 2
19
19
  @image_radius = (@image_width + @image_height) / 4
20
20
  @current_speed = (SCROLLING_SPEED - 1) * @scale
21
+
22
+ @screen_width = screen_width
23
+ @screen_height = screen_height
24
+ @off_screen = screen_height + screen_height
21
25
  end
22
26
 
23
27
  def draw
@@ -33,12 +37,12 @@ class SmallExplosion < GeneralObject
33
37
  end
34
38
 
35
39
 
36
- def update width, height, mouse_x = nil, mouse_y = nil, player = nil
40
+ def update mouse_x = nil, mouse_y = nil, player = nil
37
41
  # Remove even if hasn't gone offscreen
38
42
  if @time_alive <= TIME_TO_LIVE
39
43
  @time_alive += 1
40
44
  @y += @current_speed
41
- super(width, height, mouse_x, mouse_y)
45
+ super(mouse_x, mouse_y)
42
46
  else
43
47
  false
44
48
  end
@@ -5,20 +5,17 @@ require_relative 'pickup.rb'
5
5
  class Star < Pickup
6
6
  POINT_VALUE_BASE = 2
7
7
 
8
- def initialize(scale, x = nil, y = nil)
9
- @scale = scale
10
- @image = get_image
11
- @time_alive = 0
8
+ def initialize(scale, screen_width, screen_height, x = nil, y = nil, options = {})
9
+ # @scale = scale
10
+ # @image = get_image
11
+ # @time_alive = 0
12
+ @x = x || rand * 800
13
+ @y = y || 0
14
+ super(scale, screen_width, screen_height, @x, @y, options)
12
15
  @color = Gosu::Color.new(0xff_000000)
13
16
  @color.red = rand(255 - 40) + 40
14
17
  @color.green = rand(255 - 40) + 40
15
18
  @color.blue = rand(255 - 40) + 40
16
- @x = x || rand * 800
17
- @y = y || 0
18
- @image_width = 25 * @scale
19
- @image_height = 25 * @scale
20
- @image_radius = 13 * @scale
21
- @current_speed = SCROLLING_SPEED * @scale
22
19
  end
23
20
 
24
21
  def get_image
data/menu_launcher.rb CHANGED
@@ -49,11 +49,14 @@ class Main < Gosu::Window
49
49
  window_height = Gosu.screen_height
50
50
  @resolution_menu = ResolutionSetting.new(window_height, @width, @height, get_center_font_ui_y, CONFIG_FILE)
51
51
 
52
+ @difficulty = nil
53
+ @difficulty_menu = DifficultySetting.new(@width, @height, get_center_font_ui_y, CONFIG_FILE)
54
+
52
55
  start_image = Gosu::Image.new("#{MEDIA_DIRECTORY}/start.png")
53
56
  @game_window_width, @game_window_height, @full_screen = [nil, nil, nil]
54
- @menu.add_item(start_image, (@width / 2) - (start_image.width / 2), get_center_font_ui_y, 1, lambda {self.close; GameWindow.start(@game_window_width, @game_window_height, dynamic_get_resolution_fs, {block_controls_until_button_up: true}) }, start_image)
57
+ @menu.add_item(start_image, (@width / 2) - (start_image.width / 2), get_center_font_ui_y, 1, lambda {self.close; GameWindow.start(@game_window_width, @game_window_height, dynamic_get_resolution_fs, {block_controls_until_button_up: true, difficulty: @difficulty}) }, start_image)
55
58
  debug_start_image = Gosu::Image.new("#{MEDIA_DIRECTORY}/debug_start.png")
56
- @menu.add_item(debug_start_image, (@width / 2) - (debug_start_image.width / 2), get_center_font_ui_y, 1, lambda {self.close; GameWindow.start(@game_window_width, @game_window_height, dynamic_get_resolution_fs, {block_controls_until_button_up: true, debug: true}) }, start_image)
59
+ @menu.add_item(debug_start_image, (@width / 2) - (debug_start_image.width / 2), get_center_font_ui_y, 1, lambda {self.close; GameWindow.start(@game_window_width, @game_window_height, dynamic_get_resolution_fs, {block_controls_until_button_up: true, debug: true, difficulty: @difficulty}) }, start_image)
57
60
  # @font.draw("<", width + 15, get_center_font_ui_y, 1, 1.0, 1.0, 0xff_ffff00)
58
61
  # @font.draw("Resolution", width / 2, get_center_font_ui_y, 1, 1.0, 1.0, 0xff_ffff00)
59
62
  # @font.draw(">", width - 15, get_center_font_ui_y, 1, 1.0, 1.0, 0xff_ffff00)
@@ -67,8 +70,10 @@ class Main < Gosu::Window
67
70
  def update
68
71
  @menu.update
69
72
  @resolution_menu.update(self.mouse_x, self.mouse_y)
73
+ @difficulty_menu.update(self.mouse_x, self.mouse_y)
70
74
 
71
75
  @game_window_width, @game_window_height, @fullscreen = @resolution_menu.get_resolution
76
+ @difficulty = @difficulty_menu.get_difficulty
72
77
  @gl_background.scroll
73
78
  end
74
79
 
@@ -78,6 +83,7 @@ class Main < Gosu::Window
78
83
  reset_center_font_ui_y
79
84
  @menu.draw
80
85
  @resolution_menu.draw
86
+ @difficulty_menu.draw
81
87
  @gl_background.draw(ZOrder::Background)
82
88
  end
83
89
 
@@ -85,6 +91,7 @@ class Main < Gosu::Window
85
91
  if id == Gosu::MsLeft then
86
92
  @menu.clicked
87
93
  @resolution_menu.clicked(self.mouse_x, self.mouse_y)
94
+ @difficulty_menu.clicked(self.mouse_x, self.mouse_y)
88
95
  end
89
96
  end
90
97
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: line-em-up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Dana
@@ -63,6 +63,7 @@ files:
63
63
  - line-em-up/game_window.rb
64
64
  - line-em-up/irb_requirements.rb
65
65
  - line-em-up/lib/config_setting.rb
66
+ - line-em-up/lib/difficulty_setting.rb
66
67
  - line-em-up/lib/resolution_setting.rb
67
68
  - line-em-up/lib/setting.rb
68
69
  - line-em-up/lib/z_order.rb
@@ -160,6 +161,7 @@ files:
160
161
  - line-em-up/media/item_hover.png
161
162
  - line-em-up/media/landscape.svg
162
163
  - line-em-up/media/large_star.png
164
+ - line-em-up/media/mini_missile.png
163
165
  - line-em-up/media/mini_missile_reverse.png
164
166
  - line-em-up/media/missile.png
165
167
  - line-em-up/media/missile_boat.png
@@ -196,6 +198,7 @@ files:
196
198
  - line-em-up/models/building.rb
197
199
  - line-em-up/models/bullet.rb
198
200
  - line-em-up/models/cursor.rb
201
+ - line-em-up/models/dumb_projectile.rb
199
202
  - line-em-up/models/enemy_bomb.rb
200
203
  - line-em-up/models/enemy_bullet.rb
201
204
  - line-em-up/models/enemy_homing_missile.rb