mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Added main menu, added loading screen, hacked and chiseled things until I could load models without attaching to a gameobject.
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
class IMICFPS
|
||||
class GameState
|
||||
include CommonMethods
|
||||
|
||||
def initialize
|
||||
attr_reader :options
|
||||
def initialize(options = {})
|
||||
@options = options
|
||||
@delta_time = Gosu.milliseconds
|
||||
setup
|
||||
end
|
||||
|
||||
def push_game_state(klass_or_instance)
|
||||
$window.push_game_state(klass_or_instance)
|
||||
end
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ Camera X:#{@camera.x.round(2)} Y:#{@camera.y.round(2)} Z:#{@camera.z.round(2)}
|
||||
#{if @camera.game_object then "Actor X:#{@camera.game_object.x.round(2)} Y:#{@camera.game_object.y.round(2)} Z:#{@camera.game_object.z.round(2)}";end}
|
||||
Field Of View: #{@camera.field_of_view}
|
||||
Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
||||
Faces: #{@number_of_faces}
|
||||
Faces: #{$window.number_of_faces}
|
||||
Last Frame: #{delta_time*1000.0}ms (#{Gosu.fps} fps)
|
||||
|
||||
Draw Skydome: #{@draw_skydome}
|
||||
@@ -117,7 +117,7 @@ eos
|
||||
@camera.update
|
||||
|
||||
$window.close if $window.button_down?(Gosu::KbEscape)
|
||||
@number_of_faces = 0
|
||||
$window.number_of_faces = 0
|
||||
@delta_time = Gosu.milliseconds
|
||||
end
|
||||
|
||||
|
||||
@@ -1,9 +1,126 @@
|
||||
class IMICFPS
|
||||
class Menu < GameState
|
||||
def title(text, color = Gosu::Color.rgba(127, 64, 0, 200))
|
||||
def initialize
|
||||
@elements = []
|
||||
@size = 50
|
||||
@slope = 250
|
||||
@color_step = 10
|
||||
@base_color = Gosu::Color.rgb(255, 127, 0)
|
||||
super
|
||||
end
|
||||
|
||||
def link(text, color = Gosu::Color::BLUE, &block)
|
||||
def title(text, color = @base_color)
|
||||
@elements << Text.new(text, color: color, size: 100, x: 0, y: 15, alignment: :center)
|
||||
end
|
||||
|
||||
def link(text, color = Gosu::Color.rgb(0,127,127), &block)
|
||||
text = Text.new(text, color: color, size: 50, x: 0, y: 100+(60*@elements.count), alignment: :center)
|
||||
@elements << Link.new(text, self, block)
|
||||
end
|
||||
|
||||
def draw
|
||||
@background ||= Gosu.record(Gosu.screen_width, Gosu.screen_height) do
|
||||
((Gosu.screen_height+@slope)/@size).times do |i|
|
||||
fill_quad(
|
||||
0, i*@size,
|
||||
0, @slope+(i*@size),
|
||||
$window.width/2, (-@slope)+(i*@size),
|
||||
$window.width/2, i*@size,
|
||||
Gosu::Color.rgba(@base_color.red-i*@color_step, @base_color.green-i*@color_step, @base_color.blue-i*@color_step, 200)
|
||||
)
|
||||
fill_quad(
|
||||
$window.width, i*@size,
|
||||
$window.width, @slope+(i*@size),
|
||||
$window.width/2, (-@slope)+(i*@size),
|
||||
$window.width/2, i*@size,
|
||||
Gosu::Color.rgba(@base_color.red-i*@color_step, @base_color.green-i*@color_step, @base_color.blue-i*@color_step, 200)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@background.draw(0, 0, 0)
|
||||
|
||||
# Box
|
||||
draw_rect(
|
||||
$window.width/4, 0,
|
||||
$window.width/2, $window.height,
|
||||
Gosu::Color.rgba(100, 100, 100, 150)
|
||||
# Gosu::Color.rgba(@base_color.red+@color_step, @base_color.green+@color_step, @base_color.blue+@color_step, 200)
|
||||
)
|
||||
|
||||
# Texts
|
||||
@elements.each do |e|
|
||||
e.draw
|
||||
end
|
||||
|
||||
# Cursor
|
||||
fill_quad(
|
||||
mouse_x, mouse_y,
|
||||
mouse_x+16, mouse_y+16,
|
||||
mouse_x, mouse_y+16,
|
||||
mouse_x, mouse_y+16,
|
||||
Gosu::Color::RED, Float::INFINITY
|
||||
)
|
||||
end
|
||||
|
||||
def update
|
||||
@elements.each do |e|
|
||||
e.update
|
||||
end
|
||||
end
|
||||
|
||||
def fill_quad(x1, y1, x2, y2, x3, y3, x4, y4, color = Gosu::Color::WHITE, z = 0, mode = :default)
|
||||
draw_quad(
|
||||
x1,y1, color,
|
||||
x2,y2, color,
|
||||
x3,y3, color,
|
||||
x4,y4, color,
|
||||
z, mode
|
||||
)
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
close if id == Gosu::KbEscape
|
||||
if Gosu::MsLeft
|
||||
@elements.each do |e|
|
||||
next unless e.is_a?(Link)
|
||||
if mouse_over?(e)
|
||||
e.clicked
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def mouse_over?(object)
|
||||
if mouse_x.between?(object.x, object.x+object.width)
|
||||
if mouse_y.between?(object.y, object.y+object.height)
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class Link
|
||||
attr_reader :text, :block
|
||||
def initialize(text, host, block)
|
||||
@text, @host, @block = text, host, block
|
||||
@color = @text.color
|
||||
@hover_color = Gosu::Color.rgb(255, 127, 0)
|
||||
end
|
||||
|
||||
def update
|
||||
if @host.mouse_over?(self)
|
||||
@text.color = @hover_color
|
||||
else
|
||||
@text.color = @color
|
||||
end
|
||||
end
|
||||
|
||||
def x; text.x; end
|
||||
def y; text.y; end
|
||||
def width; text.width; end
|
||||
def height; text.height; end
|
||||
def draw; text.draw; end
|
||||
def clicked; @block.call; end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,6 +2,12 @@ class IMICFPS
|
||||
class MainMenu < Menu
|
||||
def setup
|
||||
title "I-MIC FPS"
|
||||
link "Single Player" do
|
||||
push_game_state(LoadingState.new(forward: Game))
|
||||
end
|
||||
link "Exit" do
|
||||
$window.close
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user