mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
Removed global state for LightManager and ObjectManager, they're now inside GameState. Simplified terrain mesh.
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
class IMICFPS
|
||||
class GameState
|
||||
include CommonMethods
|
||||
include ObjectManager
|
||||
include LightManager
|
||||
|
||||
attr_reader :options
|
||||
def initialize(options = {})
|
||||
@options = options
|
||||
@delta_time = Gosu.milliseconds
|
||||
@game_objects = []
|
||||
@lights = []
|
||||
|
||||
setup
|
||||
end
|
||||
|
||||
def push_game_state(klass_or_instance)
|
||||
$window.push_game_state(klass_or_instance)
|
||||
window.push_game_state(klass_or_instance)
|
||||
end
|
||||
|
||||
def setup
|
||||
@@ -21,6 +27,9 @@ class IMICFPS
|
||||
def update
|
||||
end
|
||||
|
||||
def button_down(id)
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,16 +4,16 @@ class IMICFPS
|
||||
include GLU
|
||||
|
||||
def setup
|
||||
@renderer = Renderer.new
|
||||
@terrain = Terrain.new#(size: 170, height: 0)
|
||||
@renderer = Renderer.new(game_state: self)
|
||||
@terrain = Terrain.new(game_state: self)#(size: 170, height: 0)
|
||||
@draw_skydome = true
|
||||
@skydome = Skydome.new(scale: 0.08, backface_culling: false, auto_manage: false)
|
||||
|
||||
25.times do
|
||||
Tree.new(x: rand(@terrain.width)-(@terrain.width/2.0), z: rand(@terrain.depth)-(@terrain.depth/2.0), terrain: @terrain)
|
||||
Tree.new(x: rand(@terrain.width)-(@terrain.width/2.0), z: rand(@terrain.depth)-(@terrain.depth/2.0), terrain: @terrain, game_state: self)
|
||||
end
|
||||
|
||||
@player = Player.new(x: 1, y: 0, z: -1, terrain: @terrain)
|
||||
@player = Player.new(x: 1, y: 0, z: -1, terrain: @terrain, game_state: self)
|
||||
@camera = Camera.new(x: 0, y: -2, z: 1)
|
||||
@camera.attach_to(@player)
|
||||
|
||||
@@ -24,8 +24,8 @@ class IMICFPS
|
||||
# @font = Gosu::Font.new(18, name: "DejaVu Sans")
|
||||
@text = MultiLineText.new("Pending...", x: 10, y: 10, z: 1, size: 18, font: "DejaVu Sans")
|
||||
|
||||
Light.new(x: 3, y: -6, z: 6)
|
||||
Light.new(x: 0, y: 100, z: 0, diffuse: Color.new(1.0, 0.5, 0.1))
|
||||
Light.new(x: 3, y: -6, z: 6, game_state: self)
|
||||
Light.new(x: 0, y: 100, z: 0, diffuse: Color.new(1.0, 0.5, 0.1), game_state: self)
|
||||
end
|
||||
|
||||
def glError?
|
||||
@@ -46,7 +46,7 @@ class IMICFPS
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
|
||||
glError?
|
||||
|
||||
LightManager.lights.each(&:draw)
|
||||
@lights.each(&:draw)
|
||||
|
||||
@camera.draw
|
||||
@renderer.opengl_renderer.draw_object(@skydome) if @skydome.renderable
|
||||
@@ -106,8 +106,8 @@ eos
|
||||
@text.text = string
|
||||
|
||||
# Expensive AABB collision detection
|
||||
ObjectManager.objects.each do |object|
|
||||
ObjectManager.objects.each do |b|
|
||||
@game_objects.each do |object|
|
||||
@game_objects.each do |b|
|
||||
next if object == b
|
||||
next if object.is_a?(Terrain) || b.is_a?(Terrain)
|
||||
|
||||
@@ -124,7 +124,7 @@ eos
|
||||
end
|
||||
end
|
||||
|
||||
ObjectManager.objects.each(&:update)
|
||||
@game_objects.each(&:update)
|
||||
|
||||
@skydome.update if @skydome.renderable
|
||||
|
||||
@@ -136,7 +136,7 @@ eos
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
ObjectManager.objects.each do |object|
|
||||
@game_objects.each do |object|
|
||||
object.button_up(id) if defined?(object.button_up)
|
||||
end
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ class IMICFPS
|
||||
def setup
|
||||
@header = Text.new("I-MIC FPS", y: 10, size: 100, alignment: :center)
|
||||
@subheading = Text.new("Loading Assets", y: 100, size: 50, alignment: :center)
|
||||
@state = Text.new("Preparing...", y: $window.height/2-40, size: 40, alignment: :center)
|
||||
@percentage = Text.new("0%", y: $window.height-50-25, size: 50, alignment: :center)
|
||||
@state = Text.new("Preparing...", y: window.height/2-40, size: 40, alignment: :center)
|
||||
@percentage = Text.new("0%", y: window.height-50-25, size: 50, alignment: :center)
|
||||
|
||||
@dummy_game_object = nil
|
||||
@assets = []
|
||||
@@ -15,7 +15,7 @@ class IMICFPS
|
||||
add_asset(:obj, "objects/biped.obj")
|
||||
|
||||
# Currently broken
|
||||
Shader.new(name: "lighting", vertex_file: "shaders/vertex/lighting.glsl", fragment_file: "shaders/fragment/lighting.glsl")
|
||||
# Shader.new(name: "lighting", vertex_file: "shaders/vertex/lighting.glsl", fragment_file: "shaders/fragment/lighting.glsl")
|
||||
|
||||
@act = false
|
||||
@cycled = false
|
||||
@@ -29,7 +29,15 @@ class IMICFPS
|
||||
@subheading.draw
|
||||
@state.draw
|
||||
|
||||
fill(Gosu::Color.rgba(127, 64, 0, 150))
|
||||
# fill()
|
||||
color = Gosu::Color.rgb(255, 127, 0)
|
||||
color_two = Gosu::Color.rgb(200, 100, 0)
|
||||
Gosu.draw_quad(
|
||||
0, 0, color,
|
||||
window.width, 0, color_two,
|
||||
0, window.height, color,
|
||||
window.width, window.height, color_two
|
||||
)
|
||||
progressbar
|
||||
end
|
||||
|
||||
@@ -58,7 +66,7 @@ class IMICFPS
|
||||
end
|
||||
else
|
||||
@state.text = "Loading #{@assets[@asset_index][:path].split('/').last}..."
|
||||
@state.x = ($window.width/2)-(@state.width/2)
|
||||
@state.x = (window.width/2)-(@state.width/2)
|
||||
@cycled = true
|
||||
end
|
||||
end
|
||||
@@ -69,8 +77,8 @@ class IMICFPS
|
||||
|
||||
def progressbar
|
||||
@percentage.draw
|
||||
progress = (@asset_index.to_f/@assets.count)*$window.width
|
||||
draw_rect(0, $window.height-100, progress, 100, Gosu::Color.rgb(255,127,0))
|
||||
progress = (@asset_index.to_f/@assets.count)*window.width
|
||||
draw_rect(0, window.height-100, progress, 100, Gosu::Color.rgb(255,127,0))
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,7 +6,7 @@ class IMICFPS
|
||||
push_game_state(LoadingState.new(forward: Game))
|
||||
end
|
||||
link "Exit" do
|
||||
$window.close
|
||||
window.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user