mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Added HUD widgets, make Boot and Close use button_up instead of button_down
This commit is contained in:
25
lib/hud/widget.rb
Normal file
25
lib/hud/widget.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class IMICFPS
|
||||
class HUD
|
||||
class Widget
|
||||
include CommonMethods
|
||||
attr_reader :options
|
||||
|
||||
def initialize(options = {})
|
||||
@options = options
|
||||
@player = options[:player]
|
||||
@margin = 10
|
||||
|
||||
setup
|
||||
end
|
||||
|
||||
def setup
|
||||
end
|
||||
|
||||
def draw
|
||||
end
|
||||
|
||||
def update
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
29
lib/hud/widgets/ammo.rb
Normal file
29
lib/hud/widgets/ammo.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
class IMICFPS
|
||||
class HUD
|
||||
class AmmoWidget < HUD::Widget
|
||||
def setup
|
||||
@text = Text.new("")
|
||||
@background = Gosu::Color.new(0x88222222)
|
||||
end
|
||||
|
||||
def draw
|
||||
Gosu.draw_rect(
|
||||
@text.x - @margin, @text.y - @margin,
|
||||
@text.width + @margin * 2, @text.height + @margin * 2,
|
||||
@background
|
||||
)
|
||||
@text.draw
|
||||
end
|
||||
|
||||
def update
|
||||
if (Gosu.milliseconds / 1000.0) % 1.0 >= 0.9
|
||||
random = "#{rand(0..999)}".rjust(3, "0")
|
||||
@text.text = "Pistol\nAMMO: #{random}"
|
||||
end
|
||||
|
||||
@text.x = window.width - (@margin * 2 + @text.width)
|
||||
@text.y = window.height - (@margin * 2 + @text.height)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
48
lib/hud/widgets/health.rb
Normal file
48
lib/hud/widgets/health.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
class IMICFPS
|
||||
class HUD
|
||||
class HealthWidget < HUD::Widget
|
||||
def setup
|
||||
@spacer = 0
|
||||
@text = Text.new("")
|
||||
@width = 512
|
||||
@height = 24
|
||||
@slant = 32
|
||||
|
||||
@color = Gosu::Color.rgba(100, 100, 200, 128)
|
||||
@shield = Gosu::Color.rgba(200, 100, 50, 200)
|
||||
|
||||
@health = 0.0
|
||||
end
|
||||
|
||||
def draw
|
||||
@text.draw
|
||||
fill_quad(
|
||||
window.width / 2 - @width / 2, @spacer, # TOP LEFT
|
||||
window.width / 2 + @width / 2, @spacer, # TOP RIGHT
|
||||
window.width / 2 + @width / 2 - @slant, @spacer + @height, # BOTTOM RIGHT
|
||||
window.width / 2 - @width / 2 + @slant, @spacer + @height, # BOTTOM LEFT
|
||||
@color
|
||||
)
|
||||
|
||||
# Current Health
|
||||
fill_quad(
|
||||
window.width / 2 - @width / 2, @spacer, # TOP LEFT
|
||||
(window.width / 2 - @width / 2) + @width * @health, @spacer, # TOP RIGHT
|
||||
(window.width / 2 - @width / 2) + @width * @health - @slant, @spacer + @height, # BOTTOM RIGHT
|
||||
window.width / 2 - @width / 2 + @slant, @spacer + @height, # BOTTOM LEFT
|
||||
@shield
|
||||
)
|
||||
end
|
||||
|
||||
def update
|
||||
percentage = "#{(@health * 100).round}".rjust(3, "0")
|
||||
@text.text = "[Health #{percentage}%]"
|
||||
@text.x = window.width / 2 - @text.width / 2
|
||||
@text.y = @spacer + @height / 2 - @text.height / 2
|
||||
|
||||
@health += 0.1 * window.dt
|
||||
@health = 0 if @health > 1.0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
28
lib/hud/widgets/radar.rb
Normal file
28
lib/hud/widgets/radar.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
class IMICFPS
|
||||
class HUD
|
||||
class RadarWidget < HUD::Widget
|
||||
def setup
|
||||
@size = 256
|
||||
@color = Gosu::Color.new(0x88222222)
|
||||
|
||||
@text = Text.new("RADAR")
|
||||
end
|
||||
|
||||
def draw
|
||||
Gosu.draw_rect(
|
||||
@margin, window.height - (@size + @margin),
|
||||
@size, @size,
|
||||
@color
|
||||
)
|
||||
|
||||
@text.draw
|
||||
end
|
||||
|
||||
def update
|
||||
@text.text = "RADAR: X #{@player.position.x.round(1)} Y #{@player.position.z.round(1)}"
|
||||
@text.x = @margin + @size / 2 - @text.width / 2
|
||||
@text.y = window.height - (@margin + @size)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user