mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Added fonts and tweaked hud, added chat history and score board hud widgets
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
class IMICFPS
|
||||
GAME_ROOT_PATH = File.expand_path("..", File.dirname(__FILE__))
|
||||
|
||||
SANS_SERIF_FONT = "#{GAME_ROOT_PATH}/static/fonts/Oxygen_Mono/OxygenMono-Regular.ttf"
|
||||
MONOSPACE_FONT = "#{GAME_ROOT_PATH}/static/fonts/Oxygen_Mono/OxygenMono-Regular.ttf"
|
||||
|
||||
# Objects exported from blender using the default or meter object scale will be close to 1 GL unit
|
||||
MODEL_METER_SCALE = 1.0
|
||||
|
||||
|
||||
@@ -4,11 +4,15 @@ class IMICFPS
|
||||
@ammo = AmmoWidget.new({ player: player })
|
||||
@radar = RadarWidget.new({ player: player })
|
||||
@health = HealthWidget.new({ player: player })
|
||||
@chat_history = ChatHistoryWidget.new({ player: player })
|
||||
@score_board = ScoreBoardWidget.new({ player: player })
|
||||
|
||||
@hud_elements = [
|
||||
@ammo,
|
||||
@radar,
|
||||
@health,
|
||||
@chat_history,
|
||||
@score_board,
|
||||
]
|
||||
end
|
||||
|
||||
|
||||
@@ -7,8 +7,14 @@ class IMICFPS
|
||||
def initialize(options = {})
|
||||
@options = options
|
||||
@player = options[:player]
|
||||
|
||||
# Widget margin from screen edge
|
||||
# or how much widget is pushed in
|
||||
@margin = 10
|
||||
|
||||
# Widget element padding
|
||||
@padding = 10
|
||||
|
||||
setup
|
||||
end
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@ class IMICFPS
|
||||
class HUD
|
||||
class AmmoWidget < HUD::Widget
|
||||
def setup
|
||||
@text = Text.new("")
|
||||
@background = Gosu::Color.new(0x88222222)
|
||||
@text = Text.new("", size: 64, mode: :add, font: MONOSPACE_FONT)
|
||||
@background = Gosu::Color.new(0x88c64600)
|
||||
end
|
||||
|
||||
def draw
|
||||
Gosu.draw_rect(
|
||||
@text.x - @margin, @text.y - @margin,
|
||||
@text.width + @margin * 2, @text.height + @margin * 2,
|
||||
@text.x - @padding, @text.y - @padding,
|
||||
@text.width + @padding * 2, @text.height + @padding * 2,
|
||||
@background
|
||||
)
|
||||
@text.draw
|
||||
@@ -17,12 +17,12 @@ class IMICFPS
|
||||
|
||||
def update
|
||||
if (Gosu.milliseconds / 1000.0) % 1.0 >= 0.9
|
||||
random = "#{rand(0..999)}".rjust(3, "0")
|
||||
@text.text = "Pistol\nAMMO: #{random}"
|
||||
random = "#{rand(0..199)}".rjust(3, "0")
|
||||
@text.text = "#{random}/999"
|
||||
end
|
||||
|
||||
@text.x = window.width - (@margin * 2 + @text.width)
|
||||
@text.y = window.height - (@margin * 2 + @text.height)
|
||||
@text.x = window.width - (@margin + @text.width + @padding)
|
||||
@text.y = window.height - (@margin + @text.height + @padding)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
76
lib/hud/widgets/chat_history.rb
Normal file
76
lib/hud/widgets/chat_history.rb
Normal file
@@ -0,0 +1,76 @@
|
||||
class IMICFPS
|
||||
class HUD
|
||||
class ChatHistoryWidget < HUD::Widget
|
||||
def setup
|
||||
@messages = []
|
||||
|
||||
@text = CyberarmEngine::Text.new(
|
||||
"",
|
||||
size: 16,
|
||||
x: @margin, y: @margin, z: 45,
|
||||
shadow_size: 0.5,
|
||||
shadow_alpha: 0,
|
||||
shadow_color: Gosu::Color::WHITE,
|
||||
mode: :add,
|
||||
font: SANS_SERIF_FONT
|
||||
)
|
||||
|
||||
@last_message_time = 0
|
||||
@message_interval = 1_500
|
||||
end
|
||||
|
||||
def draw
|
||||
@text.draw
|
||||
end
|
||||
|
||||
def update
|
||||
@text.text = @messages.last(15).map { |m| "#{m}\n" }.join
|
||||
|
||||
if Gosu.milliseconds - @last_message_time >= @message_interval
|
||||
@last_message_time = Gosu.milliseconds
|
||||
@message_interval = rand(500..3_000)
|
||||
|
||||
@messages << random_message
|
||||
end
|
||||
end
|
||||
|
||||
def random_message
|
||||
usernames = [
|
||||
"Cyberarm", "Cyber", "TankKiller", "DavyJones",
|
||||
]
|
||||
entities = [
|
||||
"Alternate Tank", "Hover Hank", "Helicopter", "Jeep"
|
||||
]
|
||||
|
||||
locations = [
|
||||
"Compass Bridge", "Compass Power Plant", "Gort Power Plant", "Gort Bridge", "Nest"
|
||||
]
|
||||
|
||||
events = [:spot, :kill, :target, :message]
|
||||
|
||||
messages = [
|
||||
"Need more tanks!",
|
||||
"I need 351 credits to purchase a tank",
|
||||
"I got 300",
|
||||
]
|
||||
|
||||
segments = {
|
||||
spot: [
|
||||
" spotted a <c=ffa51d2d>#{entities.sample}</c> at <c=ff26a269>#{locations.sample}</c>"
|
||||
],
|
||||
kill: [
|
||||
" killed <c=ffa51d2d>#{usernames.sample}</c>"
|
||||
],
|
||||
target: [
|
||||
" targeted <c=ffa51d2d>#{entities.sample} (#{usernames.sample})</c>"
|
||||
],
|
||||
message: [
|
||||
"<c=ffe66100>: #{messages.sample}</c>"
|
||||
]
|
||||
}
|
||||
|
||||
"<c=ffe66100>#{usernames.sample}</c>#{segments[events.sample].sample}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,13 +3,13 @@ class IMICFPS
|
||||
class HealthWidget < HUD::Widget
|
||||
def setup
|
||||
@spacer = 0
|
||||
@text = Text.new("")
|
||||
@text = Text.new("", mode: :add, font: MONOSPACE_FONT)
|
||||
@width = 512
|
||||
@height = 24
|
||||
@slant = 32
|
||||
|
||||
@color = Gosu::Color.rgba(100, 100, 200, 128)
|
||||
@shield = Gosu::Color.rgba(200, 100, 50, 200)
|
||||
@color = Gosu::Color.new(0x66ffa348)
|
||||
@shield = Gosu::Color.new(0xaae66100)
|
||||
|
||||
@health = 0.0
|
||||
end
|
||||
@@ -17,19 +17,24 @@ class IMICFPS
|
||||
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
|
||||
window.width / 2 - @width / 2, @spacer + @margin, # TOP LEFT
|
||||
window.width / 2 + @width / 2, @spacer + @margin, # TOP RIGHT
|
||||
window.width / 2 + @width / 2 - @slant, @spacer + @margin + @height, # BOTTOM RIGHT
|
||||
window.width / 2 - @width / 2 + @slant, @spacer + @margin + @height, # BOTTOM LEFT
|
||||
@color
|
||||
)
|
||||
|
||||
bottom_right = (window.width / 2 - @width / 2) + @width * @health - @slant
|
||||
if @width * @health - @slant < @slant
|
||||
bottom_right = (window.width / 2 - @width / 2) + @slant
|
||||
end
|
||||
|
||||
# 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
|
||||
window.width / 2 - @width / 2, @spacer + @margin, # TOP LEFT
|
||||
(window.width / 2 - @width / 2) + @width * @health, @spacer + @margin, # TOP RIGHT
|
||||
bottom_right, @spacer + @margin + @height, # BOTTOM RIGHT
|
||||
window.width / 2 - @width / 2 + @slant, @spacer + @margin + @height, # BOTTOM LEFT
|
||||
@shield
|
||||
)
|
||||
end
|
||||
@@ -38,7 +43,7 @@ class IMICFPS
|
||||
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
|
||||
@text.y = @spacer + @margin + @height / 2 - @text.height / 2
|
||||
|
||||
@health += 0.1 * window.dt
|
||||
@health = 0 if @health > 1.0
|
||||
|
||||
@@ -2,17 +2,24 @@ class IMICFPS
|
||||
class HUD
|
||||
class RadarWidget < HUD::Widget
|
||||
def setup
|
||||
@size = 256
|
||||
@color = Gosu::Color.new(0x88222222)
|
||||
@size = 288
|
||||
@border_color = Gosu::Color.new(0x88c64600)
|
||||
@radar_color = Gosu::Color.new(0x88212121)
|
||||
|
||||
@text = Text.new("RADAR")
|
||||
@text = Text.new("RADAR", size: 18, mode: :add, font: MONOSPACE_FONT)
|
||||
end
|
||||
|
||||
def draw
|
||||
Gosu.draw_rect(
|
||||
@margin, window.height - (@size + @margin),
|
||||
@size, @size,
|
||||
@color
|
||||
@border_color
|
||||
)
|
||||
|
||||
Gosu.draw_rect(
|
||||
@margin + @padding, window.height - (@size + @margin) + @padding,
|
||||
@size - @padding * 2, @size - @padding * 2,
|
||||
@radar_color
|
||||
)
|
||||
|
||||
@text.draw
|
||||
@@ -21,7 +28,7 @@ class IMICFPS
|
||||
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)
|
||||
@text.y = window.height - (@margin + @size + @text.height)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
92
lib/hud/widgets/score_board.rb
Normal file
92
lib/hud/widgets/score_board.rb
Normal file
@@ -0,0 +1,92 @@
|
||||
class IMICFPS
|
||||
class HUD
|
||||
class ScoreBoardWidget < HUD::Widget
|
||||
def setup
|
||||
@usernames = Array("AAAA".."zzzz")#"Adran".."Zebra")
|
||||
|
||||
@text = CyberarmEngine::Text.new(
|
||||
"",
|
||||
size: 16,
|
||||
x: @margin, y: @margin, z: 45,
|
||||
shadow: true,
|
||||
shadow_size: 0.5,
|
||||
shadow_alpha: 30,
|
||||
shadow_color: Gosu::Color::WHITE,
|
||||
mode: :add,
|
||||
font: MONOSPACE_FONT
|
||||
)
|
||||
|
||||
set_text
|
||||
end
|
||||
|
||||
def draw
|
||||
@text.draw
|
||||
end
|
||||
|
||||
def update
|
||||
@text.x = window.width - (@text.width + @margin)
|
||||
end
|
||||
|
||||
def generate_random_data
|
||||
number_of_players = rand(2..32)
|
||||
|
||||
data = {
|
||||
teams: [
|
||||
{
|
||||
name: "Compass",
|
||||
credits: 0,
|
||||
score: 0,
|
||||
},
|
||||
{
|
||||
name: "Gort",
|
||||
credits: 0,
|
||||
score: 0,
|
||||
}
|
||||
],
|
||||
players: []
|
||||
}
|
||||
|
||||
number_of_players.times do |i|
|
||||
data[:players] << {
|
||||
team: i.even? ? 0 : 1,
|
||||
username: @usernames.sample,
|
||||
score: rand(0..29_999),
|
||||
credits: rand(0..9_999)
|
||||
}
|
||||
end
|
||||
|
||||
data[:teams][0][:credits] = data[:players].select { |player| player[:team] == 0 }.map { |player| player[:credits] }.reduce(0, :+)
|
||||
data[:teams][0][:score] = data[:players].select { |player| player[:team] == 0 }.map { |player| player[:score] }.reduce(0, :+)
|
||||
|
||||
data[:teams][1][:credits] = data[:players].select { |player| player[:team] == 1 }.map { |player| player[:credits] }.reduce(0, :+)
|
||||
data[:teams][1][:score] = data[:players].select { |player| player[:team] == 1 }.map { |player| player[:score] }.reduce(0, :+)
|
||||
|
||||
data[:players].sort! { |player| player[:score] }
|
||||
|
||||
return data
|
||||
end
|
||||
|
||||
def set_text
|
||||
team_header = [:name, :credits, :score]
|
||||
player_header = [:username, :credits, :score]
|
||||
|
||||
data = generate_random_data
|
||||
|
||||
text = ""
|
||||
text += "# Team Credits Score\n"
|
||||
data[:teams].each_with_index do |team, i|
|
||||
text += "<c=#{i.even? ? 'ffe66100' : 'ffa51d2d'}>#{i} #{team[:name]} #{i.even? ? team[:credits] : '-----'} #{team[:score]}</c>\n"
|
||||
end
|
||||
|
||||
text += "\n"
|
||||
|
||||
text += "# Name Credits Score\n"
|
||||
data[:players].each_with_index do |player, i|
|
||||
text += "<c=#{i.even? ? 'ffe66100' : 'ffa51d2d'}>#{i} #{player[:username]} #{i.even? ? player[:credits] : '-----'} #{player[:score]}</c>\n"
|
||||
end
|
||||
|
||||
@text.text = text
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user