Added fonts and tweaked hud, added chat history and score board hud widgets

This commit is contained in:
2020-07-18 13:00:22 -05:00
parent b4a0a7a8bc
commit f6e4a509fd
17 changed files with 404 additions and 25 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View 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

View File

@@ -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

View File

@@ -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

View 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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,93 @@
Copyright (c) 2010-2012, Vernon Adams (vern@newtypography.co.uk), with Reserved Font Name Nobile.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

View File

@@ -0,0 +1,93 @@
Copyright (c) 2012, vernon adams (vern@newtypography.co.uk), with Reserved Font Names 'Oxygen'
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.