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
@@ -1,8 +1,20 @@
1
1
  require_relative 'dumb_projectile.rb'
2
- require 'opengl'
3
- # require 'ruby-opengl'
2
+ require 'gosu'
3
+ # require 'opengl'
4
4
  # require 'glu'
5
- # require 'glut'
5
+
6
+ require 'opengl'
7
+ require 'glut'
8
+
9
+
10
+ include OpenGL
11
+ include GLUT
12
+
13
+ # For opengl-bindings
14
+ # OpenGL.load_lib()
15
+
16
+ # GLUT.load_lib()
17
+
6
18
 
7
19
  class Bullet < DumbProjectile
8
20
  DAMAGE = 3
@@ -20,76 +32,117 @@ class Bullet < DumbProjectile
20
32
  # include Glut
21
33
 
22
34
 
23
- def alt_draw
24
- glClearColor(0.0, 0.2, 0.5, 1.0)
25
- glClearDepth(0)
26
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
27
- # info = @image.gl_tex_info
28
- glDepthFunc(GL_GEQUAL)
29
- glEnable(GL_DEPTH_TEST)
30
- glEnable(GL_BLEND)
31
-
32
- glMatrixMode(GL_PROJECTION)
33
- glLoadIdentity
34
- glTranslate(0, 0, -4)
35
-
36
- # glEnable(GL_TEXTURE_2D)
37
- # glBindTexture(GL_TEXTURE_2D, info.tex_name)
38
-
39
-
40
-
41
- middle_x = @screen_width / 2
42
- puts "MIDDLE X: #{middle_x}"
43
- middle_y = @screen_height / 2
44
- puts "MIDDLE Y: #{middle_y}"
45
- increment_x = 1.0 / middle_x
46
- increment_y = 1.0 / middle_y
47
- puts "INcREMENT X : #{increment_x}"
48
- puts "INcREMENT Y : #{increment_y}"
49
-
50
- puts "PRE X: #{@x}"
51
- puts "PRE Y: #{@y}"
52
- puts "MID X: #{(@x - middle_x)}"
53
- puts "MID Y: #{(@y - middle_y)}"
54
-
55
- new_pos_x = (@x - middle_x) * increment_x
56
- new_pos_y = (@y - middle_y) * increment_y
57
- # Inverted Y
58
- new_pos_y = new_pos_y * -1
59
-
60
- height = @image_height.to_f * increment_x
61
-
62
- puts "NEW POS X: #{new_pos_x}"
63
- puts "NEW POS Y: #{new_pos_y}"
64
-
65
- z = ZOrder::Projectile
66
- # @image.draw(@x - get_width / 2, @y - get_height / 2, get_draw_ordering, @scale, @scale)
67
- # gl do
68
- # points_x = 3
69
- # pounts_y = 10
70
- Gosu.gl(z) do
71
- glLineWidth(5)
72
- glBegin(GL_LINES)
73
- glColor3f(1.0, 0.0, 0.0)
74
- glVertex3d(new_pos_x, new_pos_y, z)
75
- glVertex3d(new_pos_x, new_pos_y - height, z)
76
- # glVertex3d(new_pos_x, new_pos_y - increment_y, z)
77
- # glVertex3d(0, 0, z)
78
- # glVertex3d(1, 0, z)
79
- glEnd
80
- end
81
-
82
- # Gosu.gl(z) do
83
- # glLineWidth(50)
84
- # glColor3f(1.0, 0.0, 0.0)
85
- # glBegin(GL_TRIANGLE_STRIP)
86
- # glVertex3f(0, 0.0, z)
87
- # glVertex3f(0.5, 0, z)
88
- # glVertex3f(0.5, 0.5, z)
89
- # glEnd
90
- # end
91
-
92
- # end
35
+ def draw
36
+ # draw nothing
37
+ @image.draw(@x - get_width / 2, @y - get_height / 2, get_draw_ordering, @scale, @scale)
38
+ end
39
+
40
+ def initialize(scale, screen_width, screen_height, object, options = {})
41
+ super(scale, screen_width, screen_height, object, options)
93
42
  end
94
43
 
95
- end
44
+ # def convert_x_and_y_to_opengl_coords
45
+ # # Don't have to recalce these 4 variables on each draw, save to singleton somewhere?
46
+ # middle_x = @screen_width / 2
47
+ # puts "CREEN HIEGHT: #{ @screen_height}"
48
+ # middle_y = @screen_height / 2
49
+ # increment_x = 1.0 / middle_x
50
+ # increment_y = 1.0 / middle_y
51
+ # new_pos_x = (@x - middle_x) * increment_x
52
+ # new_pos_y = (@y - middle_y) * increment_y
53
+ # # Inverted Y
54
+ # new_pos_y = new_pos_y * -1
55
+
56
+ # # height = @image_height.to_f * increment_x
57
+ # return [new_pos_x, new_pos_y, increment_x, increment_y]
58
+ # end
59
+
60
+ # def draw_gl
61
+ # new_pos_x, new_pos_y, increment_x, increment_y = convert_x_and_y_to_opengl_coords
62
+
63
+ # height = 15 * increment_y
64
+
65
+ # puts "X and Y: #{@x} and #{@y}"
66
+ # puts "increment Y: #{increment_y}"
67
+ # puts "increment X: #{increment_x}"
68
+
69
+ # puts "hieght bullet: #{height}"
70
+ # puts "NEW POS Y: #{new_pos_y}"
71
+
72
+ # z = ZOrder::Projectile
73
+
74
+ # # glLineWidth(5 * @scale)
75
+ # glLineWidth(5)
76
+ # glBegin(GL_LINES)
77
+ # # 22.4% red, 100% green and 7.8% blue
78
+ # glColor3f(1, 1.0, 1.0)
79
+ # glVertex3d(new_pos_x, new_pos_y, z)
80
+ # glVertex3d(new_pos_x, new_pos_y + height, z)
81
+ # glEnd
82
+ # end
83
+
84
+
85
+ # end
86
+
87
+
88
+
89
+ def draw_gl
90
+ # height = 20 * @scale
91
+ # width = 30 * @scale
92
+ # new_pos_x, new_pos_y, increment_x, increment_y = Bullet.convert_x_and_y_to_opengl_coords(@x, @y, @screen_width, @screen_height)
93
+ # new_width1, new_height1, increment_x, increment_y = Bullet.convert_x_and_y_to_opengl_coords(@x + width / 2, @y, @screen_width, @screen_height)
94
+ # new_width2, new_height2, increment_x, increment_y = Bullet.convert_x_and_y_to_opengl_coords(@x, @y + height, @screen_width, @screen_height)
95
+ # new_width3, new_height3, increment_x, increment_y = Bullet.convert_x_and_y_to_opengl_coords(@x - width / 2, @y, @screen_width, @screen_height)
96
+
97
+ # # height = 55 * increment_y * @scale
98
+ # # width = 55 * increment_x * @scale
99
+
100
+ # z = ZOrder::Projectile
101
+
102
+ # # glLineWidth(5 * @scale)
103
+ # # scale = 1.0 * @scale
104
+
105
+
106
+ # glBegin(GL_TRIANGLES)
107
+ # glColor4f(1, 0.5, 0.5, get_draw_ordering)
108
+ # glVertex3f(new_width1, new_height1, 0.0)
109
+ # glVertex3f(new_width2, new_height2, 0.0)
110
+ # glVertex3f(new_width3, new_height3, 0.0)
111
+ # glEnd
112
+
113
+ # # glBegin(GL_TRIANGLES)
114
+ # # glColor4f(1, 1, 1, 1)
115
+ # # glVertex3f(new_width1, new_height3 + 0.1, 0.0)
116
+ # # glVertex3f(new_width3, new_height2 + 0.1, 0.0)
117
+ # # glVertex3f(new_width2, new_height1 + 0.1, 0.0)
118
+ # # glEnd
119
+
120
+ # new_width1, new_height1, increment_x, increment_y = Bullet.convert_x_and_y_to_opengl_coords(@x - width / 2, @y + height, @screen_width , @screen_height)
121
+ # new_width2, new_height2, increment_x, increment_y = Bullet.convert_x_and_y_to_opengl_coords(@x , @y , @screen_width, @screen_height)
122
+ # new_width3, new_height3, increment_x, increment_y = Bullet.convert_x_and_y_to_opengl_coords(@x + width / 2, @y + height, @screen_width , @screen_height)
123
+ # glBegin(GL_TRIANGLES)
124
+ # glColor4f(0.5, 1, 0.5, get_draw_ordering)
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
+ # glEnd
129
+
130
+
131
+ # # =======
132
+ # # glLineWidth(20 * @scale)
133
+ # # glBegin(GL_LINES)
134
+ # # # 22.4% red, 100% green and 7.8% blue
135
+ # # glColor3f(1, 1.0, 1.0)
136
+ # # glVertex3d(new_pos_x, new_pos_y, z)
137
+ # # glVertex3d(new_pos_x, new_pos_y + height, z)
138
+ # # glEnd
139
+ # # >>>>>>> 8012b34281af3e19bb5f897bcab2161c1a00e7b0
140
+
141
+
142
+ end
143
+
144
+
145
+
146
+
147
+
148
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'launcher.rb'
2
+ class BulletLauncher < Launcher
3
+ def init_projectile options
4
+ Bullet.new(@scale, @screen_width, @screen_height, self, options)
5
+ end
6
+
7
+
8
+ def self.get_hardpoint_image
9
+ Gosu::Image.new("#{MEDIA_DIRECTORY}/bullet_launcher_hardpoint.png")
10
+ end
11
+ def draw
12
+ if @inited
13
+ if @active
14
+ # @image.draw(@x - @image_width_half, @y - @image_height_half, get_draw_ordering, @scale, @scale)
15
+ end
16
+
17
+ return true
18
+ else
19
+ return false
20
+ end
21
+ end
22
+
23
+ end
@@ -8,7 +8,9 @@ class Cursor < GeneralObject
8
8
  end
9
9
 
10
10
 
11
- def initialize scale
11
+ def initialize scale, screenx, screeny
12
+ @screen_width = screenx
13
+ @screen_height = screeny
12
14
  @scale = scale
13
15
  @image = get_image
14
16
  @image_width = @image.width * @scale
@@ -24,9 +26,43 @@ class Cursor < GeneralObject
24
26
  @image.draw(@x - @image_width_half, @y - @image_height_half, ZOrder::Cursor, @scale, @scale)
25
27
  end
26
28
 
29
+ def convert_x_and_y_to_opengl_coords
30
+ # puts "convert_x_and_y_to_opengl_coords"
31
+ # puts "@screen_width: #{@screen_width}"
32
+ middle_x = @screen_width.to_f / 2.0
33
+ # puts "MIDDLE X: #{middle_x}"
34
+ middle_y = @screen_height.to_f / 2.0
35
+ increment_x = 1.0 / middle_x
36
+ # The zoom issue maybe, not quite sure why we need the Y offset.
37
+ increment_y = (1.0 / middle_y)
38
+ new_pos_x = (@x.to_f - middle_x) * increment_x
39
+ # puts ""
40
+ new_pos_y = (@y.to_f - middle_y) * increment_y
41
+ # Inverted Y
42
+ new_pos_y = new_pos_y * -1
43
+
44
+ # height = @image_height.to_f * increment_x
45
+ # puts "@screen_height: #{@screen_height}"
46
+ # puts "@screen_width: #{@screen_width}"
47
+ # puts "@new_pos_x: #{new_pos_x}"
48
+ # puts "@new_pos_y: #{new_pos_y}"
49
+ # puts "@x: #{@x}"
50
+ # puts "@y: #{@y}"
51
+ return [new_pos_x, new_pos_y, increment_x, increment_y]
52
+ end
53
+
27
54
  def update mouse_x, mouse_y
28
55
  @x = mouse_x
29
56
  @y = mouse_y
57
+ # puts "CURSOR X: #{@x}"
58
+ # puts "CURSOR Y: #{@y}"
59
+ new_pos_x, new_pos_y, increment_x, increment_y = convert_x_and_y_to_opengl_coords
60
+ # puts "START CURSOR"
61
+ # puts " new_pos_x: #{new_pos_x}"
62
+ # puts " new_pos_y: #{new_pos_y}"
63
+ # puts " increment_x: #{increment_x}"
64
+ # puts " increment_y: #{increment_y}"
65
+ # puts "END CURSOR"
30
66
  end
31
67
 
32
68
  end
@@ -0,0 +1,40 @@
1
+ require_relative 'launcher.rb'
2
+ class DumbMissileLauncher < Launcher
3
+ MISSILE_LAUNCHER_MIN_ANGLE = 75
4
+ MISSILE_LAUNCHER_MAX_ANGLE = 105
5
+ MISSILE_LAUNCHER_INIT_ANGLE = 90
6
+ # COOLDOWN_DELAY = 15
7
+
8
+ def init_projectile pointer, options
9
+ # Bullet.new(@scale, @screen_width, @screen_height, self, options)
10
+ Missile.new(@scale, @screen_width, @screen_height, self, pointer.x, pointer.y, MISSILE_LAUNCHER_MIN_ANGLE, MISSILE_LAUNCHER_MAX_ANGLE, MISSILE_LAUNCHER_INIT_ANGLE, {damage_increase: @damage_increase})
11
+ end
12
+
13
+
14
+ def self.get_hardpoint_image
15
+ Gosu::Image.new("#{MEDIA_DIRECTORY}/missile_launcher.png")
16
+ end
17
+ # def draw
18
+ # if @inited
19
+ # if @active
20
+ # # @image.draw(@x - @image_width_half, @y - @image_height_half, get_draw_ordering, @scale, @scale)
21
+ # end
22
+
23
+ # return true
24
+ # else
25
+ # return false
26
+ # end
27
+ # end
28
+
29
+ def attack pointer
30
+ # puts "DUMB MISSILE LAUNCHER ATTACK"
31
+ if @cooldown_wait <= 0
32
+ options = {damage_increase: @damage_increase}
33
+ projectile = init_projectile(pointer, options)
34
+ # @projectiles << projectile
35
+ @cooldown_wait = get_cooldown
36
+ return projectile
37
+ end
38
+ end
39
+
40
+ end
@@ -21,13 +21,19 @@ class DumbProjectile < GeneralObject
21
21
  def initialize(scale, screen_width, screen_height, object, options = {})
22
22
  options[:relative_object] = object
23
23
  @damage_increase = options[:damage_increase] || 1
24
+ # if options[:debug] == true
25
+ # puts "NEW DUMB PROJECTILE: X- #{object.x}"
26
+ # puts "NEW DUMB PROJECTILE: y- #{object.y}"
27
+ # end
24
28
  super(scale, object.x, object.y, screen_width, screen_height, options)
25
29
  @current_speed = self.class.get_max_speed * @scale
26
30
  end
27
31
 
32
+ def draw_gl
33
+ end
28
34
 
29
- def update mouse_x = nil, mouse_y = nil, player = nil
30
- @y -= @current_speed
35
+ def update mouse_x = nil, mouse_y = nil, player = nil, scroll_factor = 1
36
+ @y -= @current_speed * scroll_factor
31
37
  @y > 0 && @y < @screen_height
32
38
  end
33
39
 
@@ -77,6 +83,7 @@ class DumbProjectile < GeneralObject
77
83
  end
78
84
  end
79
85
  @y = @off_screen if hit_object
86
+ collision_triggers if hit_object
80
87
  return {drops: drops, point_value: points, killed: killed}
81
88
  end
82
89
 
@@ -21,7 +21,7 @@ class EnemyBomb < Projectile
21
21
  end
22
22
 
23
23
 
24
- def update mouse_x = nil, mouse_y = nil, player = nil
24
+ def update mouse_x = nil, mouse_y = nil, player = nil, scroll_factor = 1
25
25
  vx = (self.class.get_starting_speed * @scale) * Math.cos(@angle * Math::PI / 180)
26
26
 
27
27
  vy = (self.class.get_starting_speed * @scale) * Math.sin(@angle * Math::PI / 180)
@@ -1,4 +1,7 @@
1
1
  require_relative 'dumb_projectile.rb'
2
+ require 'opengl'
3
+ require 'glu'
4
+ require 'glut'
2
5
 
3
6
  class EnemyBullet < DumbProjectile
4
7
  DAMAGE = 3
@@ -10,4 +13,56 @@ class EnemyBullet < DumbProjectile
10
13
  def get_image
11
14
  Gosu::Image.new("#{MEDIA_DIRECTORY}/bullet-mini-reverse.png")
12
15
  end
16
+
17
+ # include Gl
18
+ # include Glu
19
+ # include Glut
20
+
21
+ def draw
22
+ # draw nothing
23
+ end
24
+
25
+
26
+ def draw_gl
27
+ new_pos_x, new_pos_y, increment_x, increment_y = convert_x_and_y_to_opengl_coords
28
+
29
+ height = @image_height.to_f * increment_y
30
+
31
+ z = ZOrder::Projectile
32
+
33
+ glLineWidth(5 * @scale)
34
+ glBegin(GL_LINES)
35
+ glColor3f(1.0, 0.0, 0.0)
36
+ glVertex3d(new_pos_x, new_pos_y, z)
37
+ glVertex3d(new_pos_x, new_pos_y - height, z)
38
+ glEnd
39
+
40
+ # scale = 1.0 * @scale
41
+
42
+ # glColor4f(scale, scale, scale, scale / 2)
43
+
44
+ # glBegin(GL_QUADS)
45
+ # glVertex3f(-1.0, +1.0, 0.0);
46
+ # glVertex3f(-1.0, -1.0, 0.0)
47
+ # glVertex3f(+1.0, -1.0, 0.0)
48
+ # glVertex3f(+1.0, +1.0, 0.0)
49
+ # glEnd
50
+
51
+ end
52
+
53
+ # def draw_gl
54
+ # new_pos_x, new_pos_y, increment_x, increment_y = convert_x_and_y_to_opengl_coords
55
+
56
+ # height = @image_height.to_f * increment_y
57
+
58
+ # z = ZOrder::Projectile
59
+
60
+ # glLineWidth(5 * @scale)
61
+ # glBegin(GL_LINES)
62
+ # glColor3f(1.0, 0.0, 0.0)
63
+ # glVertex3d(new_pos_x, new_pos_y, z)
64
+ # glVertex3d(new_pos_x, new_pos_y - height, z)
65
+ # glEnd
66
+ # end
67
+
13
68
  end
@@ -63,7 +63,7 @@ class EnemyPlayer < GeneralObject
63
63
  @current_speed
64
64
  end
65
65
 
66
- def update mouse_x = nil, mouse_y = nil, player = nil
66
+ def update mouse_x = nil, mouse_y = nil, player = nil, scroll_factor = 1
67
67
  @cooldown_wait -= 1 if @cooldown_wait > 0
68
68
  if is_alive
69
69
  # Stay above the player
@@ -0,0 +1,80 @@
1
+ require 'gosu'
2
+
3
+ require 'opengl'
4
+ require 'glu'
5
+ require 'glut'
6
+
7
+
8
+ include OpenGL
9
+ include GLUT
10
+ # OpenGL.load_lib()
11
+ # GLUT.load_lib()
12
+
13
+ class ExecuteOpenGl
14
+ # def self.init_scene
15
+ # glEnable(GL_TEXTURE_2D)
16
+ # glShadeModel(GL_SMOOTH)
17
+ # glClearColor(0,0,0,0.5)
18
+ # glClearDepth(1)
19
+ # glBlendFunc(GL_SRC_ALPHA,GL_ONE) #see nehe08
20
+ # glEnable(GL_BLEND)
21
+ # end
22
+
23
+ # def self.add_perspective_to_scene
24
+ # glMatrixMode(GL_PROJECTION)
25
+ # glLoadIdentity
26
+ # gluPerspective(45.0, width / height, 0.1, 100.0)
27
+ # glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST) #see nehe07
28
+ # end
29
+
30
+ # include Gl
31
+ # include Glu
32
+ # include Glut
33
+
34
+ def draw background, projectiles, player
35
+ # @zoom = -14
36
+ Gosu.gl do
37
+ # init_scene
38
+ # glEnable(GL_TEXTURE_2D)
39
+ # glShadeModel(GL_SMOOTH)
40
+ # glClearColor(0.0, 0.2, 0.5, 1.0)
41
+ glClearColor(0.0, 0.0, 0.0, 0.0)
42
+ glClearDepth(0)
43
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
44
+ # glBlendFunc(GL_SRC_ALPHA,GL_ONE) #see nehe08
45
+ # glEnable(GL_BLEND)
46
+
47
+ # glMatrixMode(GL_MODELVIEW) #see lesson 01
48
+ # glLoadIdentity #see lesson 01
49
+ # glTranslatef(0, 0, -13) #see lesson 01
50
+ background.exec_gl
51
+
52
+ glShadeModel(GL_SMOOTH) # selects smooth shading
53
+ glLoadIdentity #see lesson 01
54
+ # puts "-projectile.get_draw_ordering - 10: #{-projectile.get_draw_ordering - 10}"
55
+ glTranslatef(0, 0, -13) #see lesson 01
56
+ @ambient_light = [0.5, 0.5, 0.5, 1]
57
+ mat_shininess = [50]
58
+ glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess)
59
+ glLightfv(GL_LIGHT1, GL_AMBIENT, @ambient_light) # sets ambient light for light source
60
+ glEnable(GL_LIGHT1)
61
+
62
+
63
+ projectiles.each_with_index do |projectile, i|
64
+ glMatrixMode(GL_MODELVIEW) #see lesson 01
65
+ glLoadIdentity #see lesson 01
66
+ # puts "-projectile.get_draw_ordering - 10: #{-projectile.get_draw_ordering - 10}"
67
+ glTranslatef(0, 0, -13) #see lesson 01
68
+ # glTranslatef(0, 0, -14) #see lesson 01
69
+ projectile.draw_gl
70
+ end
71
+ player.draw_gl_list.each do |item|
72
+ glMatrixMode(GL_MODELVIEW) #see lesson 01
73
+ glLoadIdentity #see lesson 01
74
+ glTranslatef(0, 0, -13) #see lesson 01
75
+ item.draw_gl
76
+ end
77
+
78
+ end
79
+ end
80
+ end
@@ -1,14 +1,26 @@
1
1
  class GeneralObject
2
- attr_accessor :time_alive, :x, :y, :health
2
+ attr_accessor :time_alive, :x, :y, :health, :image_width, :image_height, :image_size, :image_radius, :image_width_half, :image_height_half, :image_path, :inited
3
3
  LEFT = 'left'
4
4
  RIGHT = 'right'
5
5
  SCROLLING_SPEED = 4
6
6
  MAX_SPEED = 5
7
7
 
8
- def get_image
8
+ def self.get_image
9
9
  Gosu::Image.new("#{MEDIA_DIRECTORY}/question.png")
10
10
  end
11
11
 
12
+ def get_image
13
+ self.class.get_image
14
+ end
15
+
16
+ def self.get_image_path
17
+ "#{MEDIA_DIRECTORY}/question.png"
18
+ end
19
+
20
+ def get_image_path
21
+ self.class.get_image_path
22
+ end
23
+
12
24
  def initialize(scale, x, y, screen_width, screen_height, options = {})
13
25
  @scale = scale
14
26
  @image = options[:image] || get_image
@@ -19,17 +31,21 @@ class GeneralObject
19
31
  @x = options[:relative_object].x - (options[:relative_object].get_width / 2)
20
32
  @y = options[:relative_object].y
21
33
  elsif RIGHT == options[:side]
22
- @x = (options[:relative_object].x + options[:relative_object].get_width / 2) - 4
34
+ @x = (options[:relative_object].x + options[:relative_object].get_width / 2)
23
35
  @y = options[:relative_object].y
24
36
  else
25
37
  @x = options[:relative_object].x
26
38
  @y = options[:relative_object].y
27
39
  end
28
- @x = @x + options[:relative_x_padding] if options[:relative_x_padding]
29
40
  else
30
41
  @x = x
31
42
  @y = y
32
43
  end
44
+ @x = @x + options[:relative_x_padding] if options[:relative_x_padding]
45
+ @y = @y + options[:relative_y_padding] if options[:relative_y_padding]
46
+ # if options[:relative_y_padding]
47
+ # puts "options[:relative_y_padding]: #{options[:relative_y_padding]}"
48
+ # end
33
49
 
34
50
  @time_alive = 0
35
51
  # For objects that don't take damage, they'll never get hit by anything due to having 0 health
@@ -47,6 +63,7 @@ class GeneralObject
47
63
  @screen_width = screen_width
48
64
  @screen_height = screen_height
49
65
  @off_screen = screen_height + screen_height
66
+ @inited = true
50
67
  end
51
68
 
52
69
  # If using a different class for ZOrder than it has for model name, or if using subclass (from subclass or parent)
@@ -83,7 +100,7 @@ class GeneralObject
83
100
  @image_radius
84
101
  end
85
102
 
86
- def update mouse_x = nil, mouse_y = nil, player = nil
103
+ def update mouse_x = nil, mouse_y = nil, player = nil, scroll_factor = 1
87
104
  # Inherit, add logic, then call this to calculate whether it's still visible.
88
105
  # @time_alive ||= 0 # Temp solution
89
106
  @time_alive += 1
@@ -214,16 +231,72 @@ class GeneralObject
214
231
  GeneralObject.nearest_angle(angle, min_angle, max_angle)
215
232
  end
216
233
 
234
+ # # new_pos_x = @x / @screen_width.to_f * (AXIS_X_MAX - AXIS_X_MIN) + AXIS_X_MIN;
235
+ # # new_pos_y = (1 - @y / @screen_height.to_f) * (AXIS_Y_MAX - AXIS_Y_MIN) + AXIS_Y_MIN;
236
+ # # This isn't exactly right, objects are drawn farther away from center than they should be.
237
+ # def convert_x_and_y_to_opengl_coords
238
+ # # Don't have to recalce these 4 variables on each draw, save to singleton somewhere?
239
+ # middle_x = (@screen_width.to_f) / 2.0
240
+ # middle_y = (@screen_height.to_f) / 2.0
241
+ # increment_x = 1.0 / middle_x
242
+ # increment_y = 1.0 / middle_y
243
+ # new_pos_x = (@x.to_f - middle_x) * increment_x
244
+ # new_pos_y = (@y.to_f - middle_y) * increment_y
245
+ # # Inverted Y
246
+ # new_pos_y = new_pos_y * -1.0
247
+
248
+ # # height = @image_height.to_f * increment_x
249
+ # return [new_pos_x, new_pos_y, increment_x, increment_y]
250
+ # end
251
+
252
+
253
+ # This isn't exactly right, objects are drawn farther away from center than they should be.
254
+ def convert_x_and_y_to_opengl_coords
255
+ middle_x = @screen_width / 2
256
+ middle_y = @screen_height / 2
257
+
258
+ ratio = @screen_width.to_f / @screen_height.to_f
259
+
260
+ increment_x = (ratio / middle_x) * 0.97
261
+ # The zoom issue maybe, not quite sure why we need the Y offset.
262
+ increment_y = (1.0 / middle_y) * 0.75
263
+ new_pos_x = (@x - middle_x) * increment_x
264
+ new_pos_y = (@y - middle_y) * increment_y
265
+ # Inverted Y
266
+ new_pos_y = new_pos_y * -1
267
+
268
+ # height = @image_height.to_f * increment_x
269
+ return [new_pos_x, new_pos_y, increment_x, increment_y]
270
+ end
217
271
 
272
+ def self.convert_x_and_y_to_opengl_coords(x, y, screen_width, screen_height)
273
+ middle_x = screen_width.to_f / 2.0
274
+ middle_y = screen_height.to_f / 2.0
218
275
 
276
+ ratio = screen_width.to_f / screen_height.to_f
219
277
 
278
+ increment_x = (ratio / middle_x) * 0.97
279
+ # The zoom issue maybe, not quite sure why we need the Y offset.
280
+ increment_y = (1.0 / middle_y)
281
+ new_pos_x = (x.to_f - middle_x) * increment_x
282
+ new_pos_y = (y.to_f - middle_y) * increment_y
283
+ # Inverted Y
284
+ new_pos_y = new_pos_y * -1
285
+ return [new_pos_x, new_pos_y, increment_x, increment_y]
286
+ end
220
287
 
221
288
 
289
+ def y_is_on_screen
290
+ @y >= 0 && @y <= @screen_height
291
+ end
222
292
 
293
+ def collision_triggers
294
+ # Explosion or something
295
+ # Override
296
+ end
223
297
 
224
-
225
-
226
-
227
-
298
+ def self.descendants
299
+ ObjectSpace.each_object(Class).select { |klass| klass < self }
300
+ end
228
301
 
229
302
  end