line-em-up 0.4.0 → 2.0.0
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 +4 -4
- data/line-em-up/game_window.rb +189 -52
- data/line-em-up/irb_requirements.rb +24 -2
- data/line-em-up/lib/config_setting.rb +126 -16
- data/line-em-up/lib/difficulty_setting.rb +64 -64
- data/line-em-up/lib/lighting.rb +143 -0
- data/line-em-up/lib/resolution_setting.rb +58 -58
- data/line-em-up/lib/setting.rb +104 -0
- data/line-em-up/lib/ship_loadout_setting.rb +476 -0
- data/line-em-up/lib/ship_setting.rb +98 -0
- data/line-em-up/lib/z_order.rb +1 -1
- data/line-em-up/loadout_window.rb +253 -0
- data/line-em-up/media/bullet_launcher_hardpoint.png +0 -0
- data/line-em-up/media/hardpoint_empty.png +0 -0
- data/line-em-up/media/header@2x.psd +0 -0
- data/line-em-up/media/laser-end-background-half.png +0 -0
- data/line-em-up/media/laser-end-background.png +0 -0
- data/line-em-up/media/laser-end-overlay-half.png +0 -0
- data/line-em-up/media/laser-end-overlay.png +0 -0
- data/line-em-up/media/laser-middle-background-half.png +0 -0
- data/line-em-up/media/laser-middle-background.png +0 -0
- data/line-em-up/media/laser-middle-overlay-half.png +0 -0
- data/line-em-up/media/laser-middle-overlay-short.png +0 -0
- data/line-em-up/media/laser-middle-overlay.png +0 -0
- data/line-em-up/media/laser-overlay-half.png +0 -0
- data/line-em-up/media/laser-overlay.png +0 -0
- data/line-em-up/media/laser-start-background-half.png +0 -0
- data/line-em-up/media/laser-start-background.png +0 -0
- data/line-em-up/media/laser-start-overlay-half.png +0 -0
- data/line-em-up/media/laser-start-overlay.png +0 -0
- data/line-em-up/media/laser_beam_hardpoint copy.png +0 -0
- data/line-em-up/media/laser_beam_hardpoint.png +0 -0
- data/line-em-up/media/line-em-up-resolution.png +0 -0
- data/line-em-up/media/menu/loadout.png +0 -0
- data/line-em-up/media/{start.png → menu/start.png} +0 -0
- data/line-em-up/media/missile_launcher.png +0 -0
- data/line-em-up/media/{spaceship.png → pilotable_ships/basic_ship/default.png} +0 -0
- data/line-em-up/media/{spaceship_original.png → pilotable_ships/basic_ship/large.png} +0 -0
- data/line-em-up/media/{spaceship_left.png → pilotable_ships/basic_ship/left.png} +0 -0
- data/line-em-up/media/pilotable_ships/basic_ship/left_broadside.png +0 -0
- data/line-em-up/media/pilotable_ships/basic_ship/original.png +0 -0
- data/line-em-up/media/{spaceship_right.png → pilotable_ships/basic_ship/right.png} +0 -0
- data/line-em-up/media/pilotable_ships/basic_ship/right_broadside.png +0 -0
- data/line-em-up/media/pilotable_ships/mite_ship/default.png +0 -0
- data/line-em-up/media/pilotable_ships/mite_ship/large.png +0 -0
- data/line-em-up/media/pilotable_ships/mite_ship/left.png +0 -0
- data/line-em-up/media/pilotable_ships/mite_ship/left_broadside.png +0 -0
- data/line-em-up/media/pilotable_ships/mite_ship/original.png +0 -0
- data/line-em-up/media/pilotable_ships/mite_ship/right.png +0 -0
- data/line-em-up/media/pilotable_ships/mite_ship/right_broadside.png +0 -0
- data/line-em-up/media/pilotable_ships/mite_ship.zip +0 -0
- data/line-em-up/models/basic_ship.rb +94 -0
- data/line-em-up/models/bomb.rb +1 -1
- data/line-em-up/models/building.rb +2 -2
- data/line-em-up/models/bullet.rb +127 -74
- data/line-em-up/models/bullet_launcher.rb +23 -0
- data/line-em-up/models/cursor.rb +37 -1
- data/line-em-up/models/dumb_missile_launcher.rb +40 -0
- data/line-em-up/models/dumb_projectile.rb +9 -2
- data/line-em-up/models/enemy_bomb.rb +1 -1
- data/line-em-up/models/enemy_bullet.rb +55 -0
- data/line-em-up/models/enemy_player.rb +1 -1
- data/line-em-up/models/execute_open_gl.rb +80 -0
- data/line-em-up/models/general_object.rb +82 -9
- data/line-em-up/models/gl_background.rb +103 -30
- data/line-em-up/models/grappling_hook.rb +1 -1
- data/line-em-up/models/hardpoint.rb +120 -0
- data/line-em-up/models/laser_launcher.rb +192 -0
- data/line-em-up/models/laser_particle.rb +133 -0
- data/line-em-up/models/launcher.rb +149 -0
- data/line-em-up/models/main.rb +119 -26
- data/line-em-up/models/menu.rb +43 -3
- data/line-em-up/models/menu_item.rb +25 -14
- data/line-em-up/models/missile_boat.rb +5 -4
- data/line-em-up/models/mite.rb +3 -2
- data/line-em-up/models/mite_ship.rb +61 -0
- data/line-em-up/models/mothership.rb +1 -1
- data/line-em-up/models/pickup.rb +2 -2
- data/line-em-up/models/pilotable_ship.rb +599 -0
- data/line-em-up/models/player.rb +207 -150
- data/line-em-up/models/projectile.rb +3 -24
- data/line-em-up/models/semi_guided_missile.rb +1 -1
- data/line-em-up/models/small_explosion.rb +2 -2
- data/line-em-up/models/star.rb +7 -2
- data/menu_launcher.rb +10 -6
- metadata +113 -10
- data/line-em-up/media/spaceship_left-test.png +0 -0
@@ -1,8 +1,26 @@
|
|
1
|
+
require 'gosu'
|
2
|
+
# # require 'opengl'
|
3
|
+
# # require 'glu'
|
4
|
+
|
5
|
+
# require 'opengl'
|
6
|
+
# require 'glut'
|
7
|
+
|
1
8
|
require 'opengl'
|
9
|
+
require 'glut'
|
10
|
+
|
11
|
+
include OpenGL
|
12
|
+
include GLUT
|
13
|
+
# For opengl-bindings
|
14
|
+
# OpenGL.load_lib()
|
15
|
+
# GLUT.load_lib()
|
16
|
+
|
17
|
+
|
2
18
|
class GLBackground
|
3
19
|
# Height map size
|
4
20
|
POINTS_X = 7
|
21
|
+
MAP_WIDTH = 15
|
5
22
|
POINTS_Y = 7
|
23
|
+
MAP_HEIGHT = 11
|
6
24
|
# Scrolling speed
|
7
25
|
SCROLLS_PER_STEP = 50
|
8
26
|
# TEMP USING THIS, CANNOT FIND SCROLLING SPEED
|
@@ -10,33 +28,72 @@ class GLBackground
|
|
10
28
|
|
11
29
|
def initialize
|
12
30
|
@image = Gosu::Image.new("#{MEDIA_DIRECTORY}/earth.png", :tileable => true)
|
13
|
-
@scrolls = 0
|
14
|
-
@height_map = Array.new(
|
31
|
+
@scrolls = 0.0
|
32
|
+
@height_map = Array.new(MAP_HEIGHT) { Array.new(MAP_WIDTH) { rand } }
|
33
|
+
@movement_y = 0.0
|
34
|
+
@movement_x = 0.0
|
15
35
|
end
|
36
|
+
|
37
|
+
# def scroll factor = 1, movement_x, movement_y
|
38
|
+
# @scrolls += 1.0 * factor
|
39
|
+
# if @scrolls >= SCROLLS_PER_STEP
|
40
|
+
# @scrolls = 0
|
41
|
+
# @height_map.shift
|
42
|
+
# @height_map.push Array.new(POINTS_X) { rand }
|
43
|
+
# end
|
44
|
+
# end
|
16
45
|
|
17
|
-
def scroll
|
18
|
-
@scrolls += 1
|
19
|
-
if
|
20
|
-
@scrolls = 0
|
46
|
+
def scroll factor = 1, movement_x, movement_y
|
47
|
+
# @scrolls += 1.0 * factor
|
48
|
+
if movement_y >= SCROLLS_PER_STEP
|
21
49
|
@height_map.shift
|
22
|
-
@height_map.push Array.new(
|
50
|
+
@height_map.push Array.new(MAP_WIDTH) { rand }
|
51
|
+
movement_y = 0
|
52
|
+
end
|
53
|
+
if movement_y <= -SCROLLS_PER_STEP
|
54
|
+
@height_map.pop
|
55
|
+
@height_map.unshift(Array.new(MAP_WIDTH) { rand })
|
56
|
+
movement_y = 0
|
57
|
+
end
|
58
|
+
|
59
|
+
if movement_x >= SCROLLS_PER_STEP
|
60
|
+
# @height_map.shift
|
61
|
+
# @height_map.push Array.new(POINTS_X) { rand }
|
62
|
+
@height_map.each do |row|
|
63
|
+
row.shift
|
64
|
+
row.push(rand)
|
65
|
+
end
|
66
|
+
movement_x = 0
|
67
|
+
end
|
68
|
+
if movement_x <= -SCROLLS_PER_STEP
|
69
|
+
@height_map.each do |row|
|
70
|
+
row.pop
|
71
|
+
row.unshift(rand)
|
72
|
+
end
|
73
|
+
movement_x = 0
|
23
74
|
end
|
75
|
+
|
76
|
+
|
77
|
+
@movement_y = movement_y
|
78
|
+
@movement_x = movement_x
|
79
|
+
return [movement_x, movement_y]
|
24
80
|
end
|
25
81
|
|
82
|
+
# Not needed
|
26
83
|
def draw(z)
|
27
84
|
# gl will execute the given block in a clean OpenGL environment, then reset
|
28
85
|
# everything so Gosu's rendering can take place again.
|
29
|
-
Gosu.gl(z)
|
86
|
+
Gosu.gl(z) do
|
87
|
+
glClearColor(0.0, 0.2, 0.5, 1.0)
|
88
|
+
glClearDepth(0)
|
89
|
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
90
|
+
exec_gl
|
91
|
+
end
|
30
92
|
end
|
31
93
|
|
32
|
-
|
33
|
-
|
34
|
-
include Gl
|
94
|
+
# include Gl
|
35
95
|
|
36
96
|
def exec_gl
|
37
|
-
glClearColor(0.0, 0.2, 0.5, 1.0)
|
38
|
-
glClearDepth(0)
|
39
|
-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
40
97
|
|
41
98
|
# Get the name of the OpenGL texture the Image resides on, and the
|
42
99
|
# u/v coordinates of the rect it occupies.
|
@@ -45,47 +102,63 @@ class GLBackground
|
|
45
102
|
info = @image.gl_tex_info
|
46
103
|
return unless info
|
47
104
|
|
105
|
+
# return true
|
106
|
+
|
48
107
|
# Pretty straightforward OpenGL code.
|
49
108
|
|
50
109
|
glDepthFunc(GL_GEQUAL)
|
51
110
|
glEnable(GL_DEPTH_TEST)
|
52
|
-
glEnable(GL_BLEND)
|
111
|
+
# glEnable(GL_BLEND)
|
53
112
|
|
54
113
|
glMatrixMode(GL_PROJECTION)
|
55
114
|
glLoadIdentity
|
56
115
|
glFrustum(-0.10, 0.10, -0.075, 0.075, 1, 100)
|
116
|
+
# gluPerspective(45.0, 800 / 600 , 0.1, 100.0)
|
57
117
|
|
58
118
|
glMatrixMode(GL_MODELVIEW)
|
59
119
|
glLoadIdentity
|
60
|
-
|
120
|
+
glTranslated(0, 0, -4)
|
61
121
|
|
62
122
|
glEnable(GL_TEXTURE_2D)
|
63
|
-
glBindTexture(GL_TEXTURE_2D, info.tex_name)
|
64
123
|
|
65
|
-
|
66
|
-
|
67
|
-
0
|
68
|
-
|
124
|
+
# puts "SCROLLS AND PER STEP: #{@scrolls / SCROLLS_PER_STEP}"
|
125
|
+
# puts "SCROLL AND STEP: #{@scrolls} and #{SCROLLS_PER_STEP}"
|
126
|
+
# offs_y = 1.0 * @scrolls / SCROLLS_PER_STEP
|
127
|
+
# puts "SCROLLS AND PER STEP: #{@scrolls / SCROLLS_PER_STEP}"
|
128
|
+
# puts "SCROLL AND STEP: #{@scrolls} and #{SCROLLS_PER_STEP}"
|
129
|
+
# offs_y = 1.0 * @scrolls / SCROLLS_PER_STEP
|
130
|
+
offs_y = 1.0 * @movement_y / SCROLLS_PER_STEP
|
131
|
+
offs_x = 1.0 * @movement_x / SCROLLS_PER_STEP
|
132
|
+
|
133
|
+
|
134
|
+
glBindTexture(GL_TEXTURE_2D, info.tex_name)
|
135
|
+
# Offset keeps screen from clipping into blackness on the left side.
|
136
|
+
offs_x = offs_x + 1
|
137
|
+
0.upto(MAP_HEIGHT - 2) do |y|
|
138
|
+
0.upto(MAP_WIDTH - 2) do |x|
|
69
139
|
glBegin(GL_TRIANGLE_STRIP)
|
70
|
-
z = @height_map[y][x]
|
71
|
-
|
140
|
+
z = @height_map[y][x] || 0.0
|
141
|
+
# raise "no Z" if z.nil?
|
142
|
+
glTexCoord2d(info.left, info.top)
|
143
|
+
# glColor4d(1, 1, 1, z)
|
72
144
|
glTexCoord2d(info.left, info.top)
|
73
|
-
glVertex3d(-0.5 + (x - 0.0) / (POINTS_X-1), -0.5 + (y - offs_y - 0.0) / (POINTS_Y-2), z)
|
145
|
+
glVertex3d(-0.5 + (x - offs_x - 0.0) / (POINTS_X-1), -0.5 + (y - offs_y - 0.0) / (POINTS_Y-2), z)
|
74
146
|
|
75
147
|
z = @height_map[y+1][x]
|
76
|
-
glColor4d(1, 1, 1, z)
|
148
|
+
# glColor4d(1, 1, 1, z)
|
77
149
|
glTexCoord2d(info.left, info.bottom)
|
78
|
-
glVertex3d(-0.5 + (x - 0.0) / (POINTS_X-1), -0.5 + (y - offs_y + 1.0) / (POINTS_Y-2), z)
|
150
|
+
glVertex3d(-0.5 + (x - offs_x - 0.0) / (POINTS_X-1), -0.5 + (y - offs_y + 1.0) / (POINTS_Y-2), z)
|
79
151
|
|
80
152
|
z = @height_map[y][x + 1]
|
81
|
-
glColor4d(1, 1, 1, z)
|
153
|
+
# glColor4d(1, 1, 1, z)
|
82
154
|
glTexCoord2d(info.right, info.top)
|
83
|
-
|
155
|
+
puts "#{x}, #{offs_x}, #{POINTS_X}, #{y}, #{offs_y}, #{POINTS_Y}, #{z}"
|
156
|
+
glVertex3d(-0.5 + (x - offs_x + 1.0) / (POINTS_X-1), -0.5 + (y - offs_y - 0.0) / (POINTS_Y-2), z)
|
84
157
|
|
85
158
|
z = @height_map[y+1][x + 1]
|
86
|
-
glColor4d(1, 1, 1, z)
|
159
|
+
# glColor4d(1, 1, 1, z)
|
87
160
|
glTexCoord2d(info.right, info.bottom)
|
88
|
-
glVertex3d(-0.5 + (x + 1.0) / (POINTS_X-1), -0.5 + (y - offs_y + 1.0) / (POINTS_Y-2), z)
|
161
|
+
glVertex3d(-0.5 + (x - offs_x + 1.0) / (POINTS_X-1), -0.5 + (y - offs_y + 1.0) / (POINTS_Y-2), z)
|
89
162
|
glEnd
|
90
163
|
end
|
91
164
|
end
|
@@ -187,7 +187,7 @@ class GrapplingHook < GeneralObject
|
|
187
187
|
end
|
188
188
|
|
189
189
|
if @reached_end_point || @reached_max_length
|
190
|
-
@reached_back_to_player = true if Gosu.distance(@x - get_width / 2, @y - get_height / 2, player.x, player.y) < (self.get_radius *
|
190
|
+
@reached_back_to_player = true if Gosu.distance(@x - get_width / 2, @y - get_height / 2, player.x, player.y) < ((self.get_radius * 2) * @scale)
|
191
191
|
end
|
192
192
|
|
193
193
|
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require_relative 'general_object.rb'
|
2
|
+
require 'gosu'
|
3
|
+
|
4
|
+
require 'opengl'
|
5
|
+
require 'glut'
|
6
|
+
|
7
|
+
|
8
|
+
include OpenGL
|
9
|
+
include GLUT
|
10
|
+
|
11
|
+
# Not intended to be overridden
|
12
|
+
class Hardpoint < GeneralObject
|
13
|
+
attr_accessor :x, :y, :assigned_weapon_class, :slot_type
|
14
|
+
attr_accessor :group_number, :y_offset, :x_offset, :main_weapon, :image_hardpoint, :image_hardpoint_width_half, :image_hardpoint_height_half, :image_angle
|
15
|
+
|
16
|
+
|
17
|
+
# MISSILE_LAUNCHER_MIN_ANGLE = 75
|
18
|
+
# MISSILE_LAUNCHER_MAX_ANGLE = 105
|
19
|
+
# MISSILE_LAUNCHER_INIT_ANGLE = 90
|
20
|
+
|
21
|
+
def initialize(scale, x, y, screen_width, screen_height, group_number, x_offset, y_offset, item, slot_type, options = {})
|
22
|
+
# puts "GHARDPOINT INIT: #{y_offset}"
|
23
|
+
@group_number = group_number
|
24
|
+
@x_offset = x_offset# * scale
|
25
|
+
@y_offset = y_offset# * scale
|
26
|
+
@slot_type = slot_type
|
27
|
+
super(scale, x + @x_offset, y + @y_offset, screen_width, screen_height, options)
|
28
|
+
@main_weapon = nil
|
29
|
+
@drawable_items_near_self = []
|
30
|
+
|
31
|
+
if item
|
32
|
+
@assigned_weapon_class = item
|
33
|
+
@image_hardpoint = item.get_hardpoint_image
|
34
|
+
else
|
35
|
+
@image_hardpoint = Gosu::Image.new("#{MEDIA_DIRECTORY}/hardpoint_empty.png")
|
36
|
+
end
|
37
|
+
@image_hardpoint_width_half = @image_hardpoint.width / 2
|
38
|
+
@image_hardpoint_height_half = @image_hardpoint.height / 2
|
39
|
+
@image_angle = options[:image_angle]
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
def stop_attack
|
45
|
+
# puts "HARDPOINT STOP ATTACK"
|
46
|
+
@main_weapon.deactivate if @main_weapon
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
def attack pointer, opts = {}
|
51
|
+
# puts "HARDPOINT ATTACK"
|
52
|
+
attack_projectile = nil
|
53
|
+
if @main_weapon.nil?
|
54
|
+
# options = {damage_increase: @damage_increase, relative_y_padding: @image_height_half}
|
55
|
+
options = {}
|
56
|
+
options[:damage_increase] = opts[:damage_increase] if opts[:damage_increase]
|
57
|
+
options[:image_angle] = @image_angle
|
58
|
+
if @assigned_weapon_class
|
59
|
+
@main_weapon = @assigned_weapon_class.new(@scale, @screen_width, @screen_height, self, options)
|
60
|
+
@drawable_items_near_self << @main_weapon
|
61
|
+
attack_projectile = @main_weapon.attack(pointer)
|
62
|
+
end
|
63
|
+
else
|
64
|
+
@main_weapon.active = true if @main_weapon.active == false
|
65
|
+
@drawable_items_near_self << @main_weapon
|
66
|
+
attack_projectile = @main_weapon.attack(pointer)
|
67
|
+
end
|
68
|
+
if attack_projectile
|
69
|
+
return {
|
70
|
+
projectiles: [attack_projectile],
|
71
|
+
cooldown: @assigned_weapon_class::COOLDOWN_DELAY
|
72
|
+
}
|
73
|
+
else
|
74
|
+
return nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_x
|
79
|
+
@x
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_y
|
83
|
+
@y
|
84
|
+
end
|
85
|
+
|
86
|
+
def get_draw_ordering
|
87
|
+
ZOrder::Hardpoint
|
88
|
+
end
|
89
|
+
|
90
|
+
def draw
|
91
|
+
# puts "DRAWING HARDPOINT: #{@x} and #{@y}"
|
92
|
+
@drawable_items_near_self.reject! { |item| item.draw }
|
93
|
+
|
94
|
+
if @image_angle != nil
|
95
|
+
@image_hardpoint.draw_rot(@x, @y, get_draw_ordering, @image_angle, 0.5, 0.5, @scale, @scale)
|
96
|
+
else
|
97
|
+
@image_hardpoint.draw(@x - @image_hardpoint_width_half, @y - @image_hardpoint_height_half, get_draw_ordering, @scale, @scale)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
def draw_gl
|
103
|
+
@drawable_items_near_self.reject! { |item| item.draw_gl }
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def update mouse_x = nil, mouse_y = nil, player = nil, scroll_factor = 1
|
108
|
+
# puts "HARDPOINT X offset: #{@x_offset}"
|
109
|
+
# puts "HARDPOINT Y offset: #{@y_offset}"
|
110
|
+
@x = player.x + @x_offset# * @scale
|
111
|
+
@y = player.y + @y_offset# * @scale
|
112
|
+
# Update list of weapons for special cases like beans. Could iterate though an association in the future.
|
113
|
+
@main_weapon.update(mouse_x, mouse_y, self, scroll_factor) if @main_weapon
|
114
|
+
# @cooldown_wait -= 1 if @cooldown_wait > 0
|
115
|
+
# @secondary_cooldown_wait -= 1 if @secondary_cooldown_wait > 0
|
116
|
+
# @grapple_hook_cooldown_wait -= 1 if @grapple_hook_cooldown_wait > 0
|
117
|
+
# @time_alive += 1 if self.is_alive
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require_relative 'dumb_projectile.rb'
|
2
|
+
require_relative 'laser_particle.rb'
|
3
|
+
require 'opengl'
|
4
|
+
require 'glu'
|
5
|
+
require 'glut'
|
6
|
+
|
7
|
+
# Should be LaserLauncher
|
8
|
+
class LaserLauncher < Launcher
|
9
|
+
attr_accessor :x, :y, :active, :projectiles, :image_path, :test, :inited
|
10
|
+
# DAMAGE = 0.001
|
11
|
+
# Doesn't work
|
12
|
+
COOLDOWN_DELAY = 0
|
13
|
+
# Friendly projects are + speeds
|
14
|
+
MAX_SPEED = 15
|
15
|
+
|
16
|
+
def init_projectile options
|
17
|
+
LaserParticle.new(@scale, @screen_width, @screen_height, self, options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(scale, screen_width, screen_height, object, options = {})
|
21
|
+
options[:relative_y_padding] = -(object.image_height_half)
|
22
|
+
puts "START LASER BEAM: #{options}"
|
23
|
+
super(scale, screen_width, screen_height, object, options)
|
24
|
+
@active = true
|
25
|
+
@projectiles = []
|
26
|
+
@image_optional = self.class.get_image
|
27
|
+
@inited = true
|
28
|
+
@cooldown_wait = 0
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.get_image
|
32
|
+
# optional image
|
33
|
+
Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-start-overlay.png")
|
34
|
+
end
|
35
|
+
|
36
|
+
# def self.get_hardpoint_image
|
37
|
+
# Gosu::Image.new("#{MEDIA_DIRECTORY}/laser_beam_hardpoint.png")
|
38
|
+
# end
|
39
|
+
|
40
|
+
def get_cooldown
|
41
|
+
self.class::COOLDOWN_DELAY
|
42
|
+
end
|
43
|
+
|
44
|
+
# only needed for is-head command
|
45
|
+
def attack pointer
|
46
|
+
if @cooldown_wait <= 0
|
47
|
+
@cooldown_wait = get_cooldown
|
48
|
+
options = {damage_increase: @damage_increase}
|
49
|
+
if @projectiles.count == 0
|
50
|
+
options[:is_head] = true
|
51
|
+
end
|
52
|
+
projectile = LaserParticle.new(@scale, @screen_width, @screen_height, self, options)
|
53
|
+
@projectiles << projectile
|
54
|
+
return projectile
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Get image is called before the initialization is complete
|
59
|
+
def get_image
|
60
|
+
Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-start-overlay.png")
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_hardpoint_image
|
64
|
+
Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-beam-hardpoint.png")
|
65
|
+
end
|
66
|
+
|
67
|
+
def deactivate
|
68
|
+
@active = false
|
69
|
+
@projectiles.each do |particle|
|
70
|
+
particle.active = false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# custom
|
75
|
+
def update mouse_x = nil, mouse_y = nil, object = nil, scroll_factor = 1
|
76
|
+
@cooldown_wait -= 1.0 if @cooldown_wait > 0.0
|
77
|
+
if @inited && @active
|
78
|
+
@x = object.x
|
79
|
+
@y = object.y
|
80
|
+
end
|
81
|
+
if !@active && @projectiles.count == 0
|
82
|
+
return false
|
83
|
+
else
|
84
|
+
found_collision = false
|
85
|
+
@projectiles.reverse.each do |particle|
|
86
|
+
if found_collision
|
87
|
+
particle.active = false
|
88
|
+
elsif particle.collision
|
89
|
+
found_collision = true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
@projectiles.reject! do |particle|
|
93
|
+
# puts "LASETER PART UPDATE: #{particle.collision}"
|
94
|
+
if @active && particle.active
|
95
|
+
result = !particle.parental_update(nil, nil, object)
|
96
|
+
result
|
97
|
+
else
|
98
|
+
result = !particle.parental_update(nil, nil, nil)
|
99
|
+
result
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
return true
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# def get_draw_ordering
|
108
|
+
# ZOrder::LaserBeam
|
109
|
+
# end
|
110
|
+
|
111
|
+
# Furthest active particle in active beam
|
112
|
+
def get_furthest_active_particle
|
113
|
+
last_active_particle = nil
|
114
|
+
if @active
|
115
|
+
@projectiles.reverse.each do |lp|
|
116
|
+
if lp.active && lp.y_is_on_screen
|
117
|
+
last_active_particle = lp
|
118
|
+
else
|
119
|
+
break
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
return last_active_particle
|
125
|
+
end
|
126
|
+
|
127
|
+
# def draw
|
128
|
+
# if @inited
|
129
|
+
# if @active
|
130
|
+
# if @image_optional
|
131
|
+
# @image_optional.draw(@x - @image_width_half, @y - @image_height_half, get_draw_ordering, @scale, @scale)
|
132
|
+
# end
|
133
|
+
# end
|
134
|
+
|
135
|
+
# return true
|
136
|
+
# else
|
137
|
+
# return false
|
138
|
+
# end
|
139
|
+
# end
|
140
|
+
|
141
|
+
def draw_gl
|
142
|
+
if @inited
|
143
|
+
z = ZOrder::Projectile
|
144
|
+
new_width1, new_height1, increment_x, increment_y = GeneralObject.convert_x_and_y_to_opengl_coords(@x - @image_width_half/8, @y - @image_height_half/2, @screen_width , @screen_height)
|
145
|
+
new_width2, new_height2, increment_x, increment_y = GeneralObject.convert_x_and_y_to_opengl_coords(@x, @y + @image_height_half/8, @screen_width , @screen_height)
|
146
|
+
new_width3, new_height3, increment_x, increment_y = GeneralObject.convert_x_and_y_to_opengl_coords(@x + @image_width_half/8, @y - @image_height_half/2, @screen_width , @screen_height)
|
147
|
+
|
148
|
+
glEnable(GL_BLEND)
|
149
|
+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
150
|
+
|
151
|
+
glBegin(GL_TRIANGLES)
|
152
|
+
glColor4f(0, 1, 0, 0.2)
|
153
|
+
glVertex3f(new_width1, new_height1, 0.0)
|
154
|
+
glVertex3f(new_width2, new_height2, 0.0)
|
155
|
+
glVertex3f(new_width3, new_height3, 0.0)
|
156
|
+
glEnd
|
157
|
+
# Not going to draw GL the laser particles - not working correctly
|
158
|
+
# if @projectiles.count > 0
|
159
|
+
# furthest_laser_particle = get_furthest_active_particle
|
160
|
+
# if furthest_laser_particle
|
161
|
+
# image = Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-middle-overlay.png")
|
162
|
+
# image_width_half = image.width / 2
|
163
|
+
# image_height_half = image.height / 2
|
164
|
+
|
165
|
+
# new_width1, new_height1, increment_x, increment_y = LaserParticle.convert_x_and_y_to_opengl_coords(@x - image_width_half/4, @y - image_height_half/2, @screen_width, @screen_height)
|
166
|
+
# new_width2, new_height2, increment_x, increment_y = LaserParticle.convert_x_and_y_to_opengl_coords(@x - image_width_half/4, furthest_laser_particle.y + image_height_half/2, @screen_width, @screen_height)
|
167
|
+
# new_width3, new_height3, increment_x, increment_y = LaserParticle.convert_x_and_y_to_opengl_coords(@x + image_width_half/4, @y - image_height_half/2, @screen_width, @screen_height)
|
168
|
+
# new_width4, new_height4, increment_x, increment_y = LaserParticle.convert_x_and_y_to_opengl_coords(@x + image_width_half/4, furthest_laser_particle.y + image_height_half/2, @screen_width, @screen_height)
|
169
|
+
|
170
|
+
# # glEnable(GL_BLEND)
|
171
|
+
# # glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
172
|
+
|
173
|
+
# glBegin(GL_TRIANGLES)
|
174
|
+
# glColor4f(0, 1, 0, 1)
|
175
|
+
# glVertex3f(new_width1, new_height1, 0.0)
|
176
|
+
# glVertex3f(new_width2, new_height2, 0.0)
|
177
|
+
# glVertex3f(new_width3, new_height3, 0.0)
|
178
|
+
# # glVertex3f(new_width4, new_height4, 0.0)
|
179
|
+
# glEnd
|
180
|
+
# glBegin(GL_TRIANGLES)
|
181
|
+
# glColor4f(0, 1, 0, 1)
|
182
|
+
# # glVertex3f(new_width1, new_height1, 0.0)
|
183
|
+
# glVertex3f(new_width2, new_height2, 0.0)
|
184
|
+
# glVertex3f(new_width3, new_height3, 0.0)
|
185
|
+
# glVertex3f(new_width4, new_height4, 0.0)
|
186
|
+
# glEnd
|
187
|
+
# end
|
188
|
+
# end
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require_relative 'dumb_projectile.rb'
|
2
|
+
require_relative 'laser_particle.rb'
|
3
|
+
require 'gosu'
|
4
|
+
# require 'opengl'
|
5
|
+
# require 'glu'
|
6
|
+
|
7
|
+
require 'opengl'
|
8
|
+
require 'glut'
|
9
|
+
|
10
|
+
|
11
|
+
include OpenGL
|
12
|
+
include GLUT
|
13
|
+
# For opengl-bindings
|
14
|
+
# OpenGL.load_lib()
|
15
|
+
# GLUT.load_lib()
|
16
|
+
|
17
|
+
class LaserParticle < DumbProjectile
|
18
|
+
attr_accessor :active, :position, :image_background, :background_image_width_half, :background_image_height_half, :collision
|
19
|
+
DAMAGE = 0.4
|
20
|
+
# DAMAGE = 0.1
|
21
|
+
# COOLDOWN_DELAY = 1
|
22
|
+
# Friendly projects are + speeds
|
23
|
+
MAX_SPEED = 15
|
24
|
+
|
25
|
+
def initialize(scale, screen_width, screen_height, object, options = {})
|
26
|
+
options[:debug] = true
|
27
|
+
|
28
|
+
options[:relative_y_padding] = -(object.image_height_half)
|
29
|
+
super(scale, screen_width, screen_height, object, options)
|
30
|
+
@active = true
|
31
|
+
if options[:is_head]
|
32
|
+
@position = :is_head
|
33
|
+
@image_background = Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-end-background.png")
|
34
|
+
@image = Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-end-overlay.png")
|
35
|
+
elsif options[:is_tail]
|
36
|
+
@position = :is_tail
|
37
|
+
@image_background = Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-start-background.png")
|
38
|
+
@image = Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-start-overlay.png")
|
39
|
+
else
|
40
|
+
@image_background = Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-middle-background.png")
|
41
|
+
@image = Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-middle-overlay-half.png")
|
42
|
+
end
|
43
|
+
|
44
|
+
@background_image_width_half = get_background_image.width / 2
|
45
|
+
@background_image_height_half = get_background_image.height / 2
|
46
|
+
@collision = false
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_draw_ordering
|
50
|
+
ZOrder::LaserParticle
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_background_image
|
54
|
+
# Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-middle-overlay.png")
|
55
|
+
if @position == :is_head
|
56
|
+
return Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-end-background.png")
|
57
|
+
elsif @position == :is_tail
|
58
|
+
return Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-start-background.png")
|
59
|
+
else
|
60
|
+
return Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-middle-background.png")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_image
|
65
|
+
# Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-middle-overlay.png")
|
66
|
+
if @position == :is_head
|
67
|
+
return Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-start-overlay.png")
|
68
|
+
elsif @position == :is_tail
|
69
|
+
return Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-end-overlay.png")
|
70
|
+
else
|
71
|
+
return Gosu::Image.new("#{MEDIA_DIRECTORY}/laser-middle-overlay.png")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def update mouse_x = nil, mouse_y = nil, player = nil, scroll_factor = 1
|
76
|
+
if @inited
|
77
|
+
@time_alive += 1
|
78
|
+
@y > 0 && @y < @screen_height
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def parental_update mouse_x = nil, mouse_y = nil, player = nil
|
83
|
+
if @inited
|
84
|
+
@y -= @current_speed
|
85
|
+
@x = player.x if player && @active
|
86
|
+
@y > 0 && @y < @screen_height
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def collision_triggers
|
91
|
+
@collision = true
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
# include Gl
|
96
|
+
# include Glu
|
97
|
+
# include Glut
|
98
|
+
|
99
|
+
def draw
|
100
|
+
if @inited# && !@active
|
101
|
+
# @image_background.draw(@x - @background_image_width_half, @y - @background_image_height_half, get_draw_ordering, @scale, @scale)
|
102
|
+
@image.draw(@x - @image_width_half, @y - @image_height_half, get_draw_ordering, @scale, @scale)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def draw_gl
|
107
|
+
# if @inited# && !@active
|
108
|
+
# new_width1, new_height1, increment_x, increment_y = LaserParticle.convert_x_and_y_to_opengl_coords(@x - @image_width_half/8, @y - @image_height_half/2, @screen_width, @screen_height)
|
109
|
+
# new_width2, new_height2, increment_x, increment_y = LaserParticle.convert_x_and_y_to_opengl_coords(@x - @image_width_half/8, @y + @image_height_half/2, @screen_width, @screen_height)
|
110
|
+
# new_width3, new_height3, increment_x, increment_y = LaserParticle.convert_x_and_y_to_opengl_coords(@x + @image_width_half/8, @y - @image_height_half/2, @screen_width, @screen_height)
|
111
|
+
# new_width4, new_height4, increment_x, increment_y = LaserParticle.convert_x_and_y_to_opengl_coords(@x + @image_width_half/8, @y + @image_height_half/2, @screen_width, @screen_height)
|
112
|
+
|
113
|
+
# glEnable(GL_BLEND)
|
114
|
+
# glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
115
|
+
|
116
|
+
# glBegin(GL_TRIANGLES)
|
117
|
+
# glColor4f(0, 1, 0, 0.2)
|
118
|
+
# glVertex3f(new_width1, new_height1, 0.0)
|
119
|
+
# glVertex3f(new_width2, new_height2, 0.0)
|
120
|
+
# glVertex3f(new_width3, new_height3, 0.0)
|
121
|
+
# # glVertex3f(new_width4, new_height4, 0.0)
|
122
|
+
# glEnd
|
123
|
+
# glBegin(GL_TRIANGLES)
|
124
|
+
# glColor4f(0, 1, 0, 0.2)
|
125
|
+
# # glVertex3f(new_width1, new_height1, 0.0)
|
126
|
+
# glVertex3f(new_width2, new_height2, 0.0)
|
127
|
+
# glVertex3f(new_width3, new_height3, 0.0)
|
128
|
+
# glVertex3f(new_width4, new_height4, 0.0)
|
129
|
+
# glEnd
|
130
|
+
# end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|