line-em-up 0.3.4 → 0.3.5

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.
@@ -0,0 +1,244 @@
1
+ require_relative 'general_object.rb'
2
+
3
+ class Projectile < GeneralObject
4
+ attr_accessor :x, :y, :time_alive, :mouse_start_x, :mouse_start_y, :vector_x, :vector_y, :angle, :radian
5
+ # WARNING THESE CONSTANTS DON'T GET OVERRIDDEN BY SUBCLASSES. NEED GETTER METHODS
6
+ COOLDOWN_DELAY = 50
7
+ STARTING_SPEED = 3.0
8
+ INITIAL_DELAY = 0
9
+ SPEED_INCREASE_FACTOR = 0.0
10
+ DAMAGE = 5
11
+ AOE = 0
12
+ MAX_CURSOR_FOLLOW = 5 # Do we need this if we have a max speed?
13
+ ADVANCED_HIT_BOX_DETECTION = false
14
+
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
22
+
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
33
+
34
+ start_point = OpenStruct.new(:x => @x - width / 2, :y => @y - height / 2)
35
+ # start_point = GeoPoint.new(@x - WIDTH / 2, @y - HEIGHT / 2)
36
+ # 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)
38
+ # end_point = GeoPoint.new(@mouse_start_x - WIDTH / 2, @mouse_start_y - HEIGHT / 2)
39
+ @angle = calc_angle(start_point, end_point)
40
+ @radian = calc_radian(start_point, end_point)
41
+
42
+
43
+ if @angle < 0
44
+ @angle = 360 - @angle.abs
45
+ 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}"
51
+ end
52
+
53
+ # def get_image
54
+ # puts "override get_image!"
55
+ # Gosu::Image.new("#{MEDIA_DIRECTORY}/question.png")
56
+ # end
57
+
58
+ def get_draw_ordering
59
+ ZOrder::Projectile
60
+ end
61
+
62
+ def destructable?
63
+ false
64
+ end
65
+
66
+ def hit_object(object)
67
+ return hit_objects([[object]])
68
+ # puts "PROJECTILE hit object: #{test}"
69
+ # return test
70
+ end
71
+
72
+ require 'benchmark'
73
+
74
+ def hit_objects(object_groups)
75
+ drops = []
76
+ points = 0
77
+ hit_object = false
78
+ killed = 0
79
+ object_groups.each do |group|
80
+ group.each do |object|
81
+ next if object.nil?
82
+ break if hit_object
83
+ # don't hit a dead object
84
+ if object.health <= 0
85
+ next
86
+ end
87
+ # if Gosu.distance(@x, @y, object.x, object.y) < (self.get_size / 2)
88
+ if self.class.get_advanced_hit_box_detection
89
+ self_object = [[(@x - get_width / 2), (@y - get_height / 2)], [(@x + get_width / 2), (@y + get_height / 2)]]
90
+ other_object = [[(object.x - object.get_width / 2), (object.y - object.get_height / 2)], [(object.x + object.get_width / 2), (object.y + object.get_height / 2)]]
91
+ hit_object = rec_intersection(self_object, other_object)
92
+ else
93
+ # puts "HIT OBJECT DETECTION: proj-size: #{(self.get_size / 2)}"
94
+ # puts "HIT OBJECT DETECTION: obj-size: #{(self.get_size / 2)}"
95
+ hit_object = Gosu.distance(@x, @y, object.x, object.y) < self.get_radius + object.get_radius
96
+ end
97
+ if hit_object
98
+ # puts "HIT OBJECT"
99
+ # hit_object = true
100
+ 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
+ if object.respond_to?(:health) && object.respond_to?(:take_damage)
105
+ # puts "OBJECT TALING DAMAGE: #{self.class.get_damage}"
106
+ object.take_damage(self.class.get_damage)
107
+ end
108
+
109
+ if object.respond_to?(:is_alive) && !object.is_alive && object.respond_to?(:drops)
110
+
111
+ object.drops.each do |drop|
112
+ drops << drop
113
+ end
114
+ end
115
+
116
+ if object.respond_to?(:is_alive) && !object.is_alive && object.respond_to?(:get_points)
117
+ killed += 1
118
+ points = points + object.get_points
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ if hit_object && self.class.get_aoe > 0
125
+ object_groups.each do |group|
126
+ group.each do |object|
127
+ next if object.nil?
128
+ if Gosu.distance(@x, @y, object.x, object.y) < self.class.get_aoe * @scale
129
+ if object.respond_to?(:health) && object.respond_to?(:take_damage)
130
+ object.take_damage(self.class.get_damage)
131
+ end
132
+
133
+ if object.respond_to?(:is_alive) && !object.is_alive && object.respond_to?(:drops)
134
+ object.drops.each do |drop|
135
+ drops << drop
136
+ end
137
+ end
138
+
139
+ if object.respond_to?(:is_alive) && !object.is_alive && object.respond_to?(:get_points)
140
+ killed += 1
141
+ points = points + object.get_points
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
147
+ @y = -HEIGHT if hit_object
148
+ return {drops: drops, point_value: points, killed: killed}
149
+ end
150
+
151
+ protected
152
+ def self.get_damage
153
+ self::DAMAGE
154
+ end
155
+ def self.get_aoe
156
+ self::AOE
157
+ end
158
+ def self.get_cooldown_delay
159
+ self::COOLDOWN_DELAY
160
+ end
161
+ def self.get_starting_speed
162
+ self::STARTING_SPEED
163
+ end
164
+ def self.get_starting_speed
165
+ self::STARTING_SPEED
166
+ end
167
+ def self.get_initial_delay
168
+ self::INITIAL_DELAY
169
+ end
170
+ def self.get_speed_increase_factor
171
+ self::SPEED_INCREASE_FACTOR
172
+ end
173
+ def self.get_max_cursor_follow
174
+ self::MAX_CURSOR_FOLLOW
175
+ end
176
+ def self.get_advanced_hit_box_detection
177
+ self::ADVANCED_HIT_BOX_DETECTION
178
+ end
179
+
180
+
181
+ # rect1[0][0] and rect2[0][0] are the two leftmost x-coordinates of the rectangles,
182
+ # Rectangles are represented as a pair of coordinate-pairs: the
183
+ # bottom-left and top-right coordinates (given in `[x, y]` notation).
184
+ def rec_intersection(rect1, rect2)
185
+
186
+ x_min = [rect1[0][0], rect2[0][0]].max
187
+ x_max = [rect1[1][0], rect2[1][0]].min
188
+
189
+ y_min = [rect1[0][1], rect2[0][1]].max
190
+ y_max = [rect1[1][1], rect2[1][1]].min
191
+
192
+ return nil if ((x_max < x_min) || (y_max < y_min))
193
+ return [[x_min, y_min], [x_max, y_max]]
194
+ end
195
+
196
+ # puts rec_intersection(
197
+ # [[0, 0], [2, 1]],
198
+ # [[1, 0], [3, 1]]
199
+ # ) == [[1, 0], [2, 1]]
200
+
201
+ # puts rec_intersection(
202
+ # [[1, 1], [2, 2]],
203
+ # [[0, 0], [5, 5]]
204
+ # ) == [[1, 1], [2, 2]]
205
+
206
+
207
+ # puts rec_intersection(
208
+ # [[1, 1], [2, 2]],
209
+ # [[4, 4], [5, 5]]
210
+ # ) == nil
211
+
212
+ # puts rec_intersection(
213
+ # [[1, 1], [5, 4]],
214
+ # [[2, 2], [3, 5]]
215
+ # ) == [[2, 2], [3, 4]]
216
+
217
+ # private
218
+
219
+ def point_is_between_the_ys_of_the_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
220
+ (a_point_on_polygon.y <= point.y && point.y < trailing_point_on_polygon.y) ||
221
+ (trailing_point_on_polygon.y <= point.y && point.y < a_point_on_polygon.y)
222
+ end
223
+
224
+ def ray_crosses_through_line_segment?(point, a_point_on_polygon, trailing_point_on_polygon)
225
+ (point.x < (trailing_point_on_polygon.x - a_point_on_polygon.x) * (point.y - a_point_on_polygon.y) /
226
+ (trailing_point_on_polygon.y - a_point_on_polygon.y) + a_point_on_polygon.x)
227
+ end
228
+
229
+ # def is_on_screen?
230
+ # # @image.draw(@x - get_width / 2, @y - get_height / 2, ZOrder::Player)
231
+ # @y > (0 - get_height) && @y < (HEIGHT + get_height) && @x > (0 - get_width) && @x < (WIDTH + get_width)
232
+ # end
233
+
234
+ def calc_angle(point1, point2)
235
+ bearing = (180/Math::PI)*Math.atan2(point1.y-point2.y, point2.x-point1.x)
236
+ return bearing
237
+ end
238
+
239
+ def calc_radian(point1, point2)
240
+ rdn = Math.atan2(point1.y-point2.y, point2.x-point1.x)
241
+ return rdn
242
+ end
243
+
244
+ end
@@ -0,0 +1,48 @@
1
+ require_relative 'general_object.rb'
2
+
3
+ class SmallExplosion < GeneralObject
4
+ attr_reader :x, :y, :living_time
5
+ TIME_TO_LIVE = 50
6
+
7
+ def initialize(scale, x = nil, y = nil, image = nil)
8
+ @scale = scale
9
+ @smoke_scale = @scale * 1.2
10
+ @smoke = Gosu::Image.new("#{MEDIA_DIRECTORY}/smoke.png")
11
+ @image = image#Gosu::Image.new("#{MEDIA_DIRECTORY}/starfighterv4.png", :tileable => true)
12
+
13
+ @x = x || 0
14
+ @y = y || 0
15
+ @time_alive = 0
16
+ @image_width = @image.width * @scale
17
+ @image_height = @image.height * @scale
18
+ @image_size = @image_width * @image_height / 2
19
+ @image_radius = (@image_width + @image_height) / 4
20
+ @current_speed = (SCROLLING_SPEED - 1) * @scale
21
+ end
22
+
23
+ def draw
24
+ spin_down = 0
25
+ if @time_alive > 0
26
+ spin_down = (@time_alive * @time_alive) / 5
27
+ end
28
+ if spin_down > (@time_alive * 10)
29
+ spin_down = @time_alive * 10
30
+ end
31
+ @smoke.draw_rot(@x, @y, ZOrder::SmallExplosions, (360 - spin_down), 0.5, 0.5, @smoke_scale, @smoke_scale)
32
+ @image.draw_rot(@x, @y, ZOrder::SmallExplosions, (360 - spin_down), 0.5, 0.5, @scale, @scale)
33
+ end
34
+
35
+
36
+ def update width, height, mouse_x = nil, mouse_y = nil, player = nil
37
+ # Remove even if hasn't gone offscreen
38
+ if @time_alive <= TIME_TO_LIVE
39
+ @time_alive += 1
40
+ @y += @current_speed
41
+ super(width, height, mouse_x, mouse_y)
42
+ else
43
+ false
44
+ end
45
+ end
46
+
47
+
48
+ end
@@ -0,0 +1,62 @@
1
+ # Also taken from the tutorial, but drawn with draw_rot and an increasing angle
2
+ # for extra rotation coolness!
3
+ require_relative 'pickup.rb'
4
+
5
+ class Star < Pickup
6
+ POINT_VALUE_BASE = 2
7
+
8
+ def initialize(scale, x = nil, y = nil)
9
+ @scale = scale
10
+ @image = get_image
11
+ @time_alive = 0
12
+ @color = Gosu::Color.new(0xff_000000)
13
+ @color.red = rand(255 - 40) + 40
14
+ @color.green = rand(255 - 40) + 40
15
+ @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
+ end
23
+
24
+ def get_image
25
+ Gosu::Image.new("#{MEDIA_DIRECTORY}/single_star.png")
26
+ end
27
+
28
+
29
+ def get_points
30
+ return POINT_VALUE_BASE
31
+ end
32
+
33
+ # def get_height
34
+ # 25 * @scale
35
+ # end
36
+
37
+ # def get_width
38
+ # 25 * @scale
39
+ # end
40
+
41
+ # def get_radius
42
+ # 13 * @scale
43
+ # end
44
+
45
+
46
+ def draw
47
+ # img = @image[Gosu.milliseconds / 100 % @image.size];
48
+ # img.draw_rot(@x, @y, ZOrder::Pickups, @y, 0.5, 0.5, @scale, @scale, @color, :add)
49
+ @image.draw_rot(@x, @y, ZOrder::Pickups, @y, 0.5, 0.5, @scale, @scale, @color, :add)
50
+ end
51
+
52
+ # def update mouse_x = nil, mouse_y = nil
53
+ # # Move towards bottom of screen
54
+ # @y += 1
55
+ # super(mouse_x, mouse_y)
56
+ # end
57
+
58
+ def collected_by_player player
59
+ player.attack_speed += 0.1
60
+ player.attack_speed = Player::MAX_ATTACK_SPEED if player.attack_speed > Player::MAX_ATTACK_SPEED
61
+ end
62
+ end
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.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Dana
@@ -191,6 +191,32 @@ files:
191
191
  - line-em-up/media/start.png
192
192
  - line-em-up/media/tileset.png
193
193
  - line-em-up/media/vera.ttf
194
+ - line-em-up/models/bomb.rb
195
+ - line-em-up/models/bomb_pack.rb
196
+ - line-em-up/models/building.rb
197
+ - line-em-up/models/bullet.rb
198
+ - line-em-up/models/cursor.rb
199
+ - line-em-up/models/enemy_bomb.rb
200
+ - line-em-up/models/enemy_bullet.rb
201
+ - line-em-up/models/enemy_homing_missile.rb
202
+ - line-em-up/models/enemy_player.rb
203
+ - line-em-up/models/footer_bar.rb
204
+ - line-em-up/models/general_object.rb
205
+ - line-em-up/models/gl_background.rb
206
+ - line-em-up/models/grappling_hook.rb
207
+ - line-em-up/models/guidable_torpedo.rb
208
+ - line-em-up/models/health_pack.rb
209
+ - line-em-up/models/menu.rb
210
+ - line-em-up/models/menu_item.rb
211
+ - line-em-up/models/missile.rb
212
+ - line-em-up/models/missile_boat.rb
213
+ - line-em-up/models/missile_pack.rb
214
+ - line-em-up/models/mothership.rb
215
+ - line-em-up/models/pickup.rb
216
+ - line-em-up/models/player.rb
217
+ - line-em-up/models/projectile.rb
218
+ - line-em-up/models/small_explosion.rb
219
+ - line-em-up/models/star.rb
194
220
  - menu_launcher.rb
195
221
  homepage: https://github.com/danabr75/line-em-up
196
222
  licenses: