mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 16:12:35 +00:00
Compare commits
1 Commits
map_editor
...
networking
| Author | SHA1 | Date | |
|---|---|---|---|
| c18309614f |
1
Gemfile
1
Gemfile
@@ -2,6 +2,7 @@ source "https://rubygems.org"
|
|||||||
gem "opengl-bindings", require: "opengl"
|
gem "opengl-bindings", require: "opengl"
|
||||||
gem "cyberarm_engine", git: "https://github.com/cyberarm/cyberarm_engine"
|
gem "cyberarm_engine", git: "https://github.com/cyberarm/cyberarm_engine"
|
||||||
gem "nokogiri", ">= 1.11.0.rc1"
|
gem "nokogiri", ">= 1.11.0.rc1"
|
||||||
|
gem "async-websocket"
|
||||||
|
|
||||||
group(:packaging) do
|
group(:packaging) do
|
||||||
gem "ocra"
|
gem "ocra"
|
||||||
|
|||||||
15
Gemfile.lock
15
Gemfile.lock
@@ -1,23 +1,22 @@
|
|||||||
GIT
|
GIT
|
||||||
remote: https://github.com/cyberarm/cyberarm_engine
|
remote: https://github.com/cyberarm/cyberarm_engine
|
||||||
revision: 4055f645f3446c61f57ad1c7748284106c1516ff
|
revision: d8551c7428da98bb7da76c138e5fbde50ef0137f
|
||||||
specs:
|
specs:
|
||||||
cyberarm_engine (0.13.1)
|
cyberarm_engine (0.13.1)
|
||||||
gosu (~> 0.15.0)
|
gosu (~> 0.15.0)
|
||||||
gosu_more_drawables (~> 0.3)
|
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
gosu (0.15.1)
|
gosu (0.15.1)
|
||||||
gosu (0.15.1-x64-mingw32)
|
gosu (0.15.1-x64-mingw32)
|
||||||
gosu_more_drawables (0.3.0)
|
mini_portile2 (2.4.0)
|
||||||
mini_portile2 (2.5.0)
|
nokogiri (1.11.0.rc1)
|
||||||
nokogiri (1.11.0.rc2)
|
mini_portile2 (~> 2.4.0)
|
||||||
mini_portile2 (~> 2.5.0)
|
nokogiri (1.11.0.rc1-x64-mingw32)
|
||||||
nokogiri (1.11.0.rc2-x64-mingw32)
|
mini_portile2 (~> 2.4.0)
|
||||||
ocra (1.3.11)
|
ocra (1.3.11)
|
||||||
opengl-bindings (1.6.10)
|
opengl-bindings (1.6.9)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
ruby
|
ruby
|
||||||
|
|||||||
16
i-mic-fps-server.rb
Normal file
16
i-mic-fps-server.rb
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
require "async/websocket"
|
||||||
|
|
||||||
|
require_relative "lib/networking/director"
|
||||||
|
require_relative "lib/networking/packet_handler"
|
||||||
|
require_relative "lib/networking/server"
|
||||||
|
require_relative "lib/networking/client"
|
||||||
|
|
||||||
|
require_relative "lib/networking/backends/memory_server"
|
||||||
|
require_relative "lib/networking/backends/memory_connection"
|
||||||
|
|
||||||
|
director = IMICFPS::Networking::Director.new(mode: :server, hostname: "0.0.0.0", port: 56789, interface: IMICFPS::Networking::MemoryServer)
|
||||||
|
director.define_singleton_method(:tick) do |dt|
|
||||||
|
puts "Ticked: #{dt}"
|
||||||
|
end
|
||||||
|
|
||||||
|
director.run.join
|
||||||
10
i-mic-fps.rb
10
i-mic-fps.rb
@@ -106,7 +106,15 @@ require_relative "lib/scenes/turn_table"
|
|||||||
require_relative "lib/crosshair"
|
require_relative "lib/crosshair"
|
||||||
require_relative "lib/demo"
|
require_relative "lib/demo"
|
||||||
|
|
||||||
require_relative "lib/overlay"
|
require_relative "lib/networking/director"
|
||||||
|
require_relative "lib/networking/packet_handler"
|
||||||
|
require_relative "lib/networking/client"
|
||||||
|
require_relative "lib/networking/server"
|
||||||
|
require_relative "lib/networking/connection"
|
||||||
|
|
||||||
|
require_relative "lib/networking/backends/memory_server"
|
||||||
|
require_relative "lib/networking/backends/memory_connection"
|
||||||
|
|
||||||
require_relative "lib/window"
|
require_relative "lib/window"
|
||||||
|
|
||||||
require_relative "lib/tools/asset_viewer"
|
require_relative "lib/tools/asset_viewer"
|
||||||
|
|||||||
10
lib/map.rb
10
lib/map.rb
@@ -14,6 +14,7 @@ class IMICFPS
|
|||||||
@lights = []
|
@lights = []
|
||||||
|
|
||||||
@collision_manager = CollisionManager.new(map: self)
|
@collision_manager = CollisionManager.new(map: self)
|
||||||
|
@renderer = window.renderer
|
||||||
Publisher.new
|
Publisher.new
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -31,12 +32,6 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
add_entity(Player.new(spawnpoint: @map_parser.spawnpoints.sample, manifest: Manifest.new(package: "base", name: "character")))
|
add_entity(Player.new(spawnpoint: @map_parser.spawnpoints.sample, manifest: Manifest.new(package: "base", name: "character")))
|
||||||
|
|
||||||
# Default lights if non are defined
|
|
||||||
if @map_parser.lights.size == 0
|
|
||||||
add_light(Light.new(id: available_light, position: Vector.new(30, 10.0, 30)))
|
|
||||||
add_light(Light.new(id: available_light, position: Vector.new(0, 100, 0), diffuse: Color.new(1.0, 0.5, 0.1)))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def data
|
def data
|
||||||
@@ -53,7 +48,7 @@ class IMICFPS
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # clear the screen and the depth buffer
|
||||||
gl_error?
|
gl_error?
|
||||||
|
|
||||||
window.renderer.draw(camera, @lights, @entities)
|
@renderer.draw(camera, @lights, @entities)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -61,7 +56,6 @@ class IMICFPS
|
|||||||
@collision_manager.update
|
@collision_manager.update
|
||||||
|
|
||||||
@entities.each(&:update)
|
@entities.each(&:update)
|
||||||
# @lights.each(&:update)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
6
lib/networking/backends/memory_connection.rb
Normal file
6
lib/networking/backends/memory_connection.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class IMICFPS
|
||||||
|
module Networking
|
||||||
|
class MemoryConnection < Connection
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
6
lib/networking/backends/memory_server.rb
Normal file
6
lib/networking/backends/memory_server.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class IMICFPS
|
||||||
|
module Networking
|
||||||
|
class MemoryServer < Server
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
18
lib/networking/client.rb
Normal file
18
lib/networking/client.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
class IMICFPS
|
||||||
|
module Networking
|
||||||
|
class Client
|
||||||
|
def initialize(socket:)
|
||||||
|
@socket = socket
|
||||||
|
end
|
||||||
|
|
||||||
|
def read
|
||||||
|
end
|
||||||
|
|
||||||
|
def write
|
||||||
|
end
|
||||||
|
|
||||||
|
def close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
14
lib/networking/connection.rb
Normal file
14
lib/networking/connection.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
class IMICFPS
|
||||||
|
module Networking
|
||||||
|
class Connection
|
||||||
|
def initialize(hostname:, port:)
|
||||||
|
end
|
||||||
|
|
||||||
|
def connect
|
||||||
|
end
|
||||||
|
|
||||||
|
def close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
61
lib/networking/director.rb
Normal file
61
lib/networking/director.rb
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
class IMICFPS
|
||||||
|
module Networking
|
||||||
|
class Director
|
||||||
|
attr_reader :mode, :hostname, :port, :tick_rate, :storage
|
||||||
|
def initialize(mode:, hostname:, port:, interface:, state: nil, tick_rate: 2)
|
||||||
|
@mode = mode
|
||||||
|
@hostname = hostname
|
||||||
|
@port = port
|
||||||
|
@state = state
|
||||||
|
@tick_rate = (1000.0 / tick_rate) / 1000.0
|
||||||
|
|
||||||
|
case @mode
|
||||||
|
when :server
|
||||||
|
@server = interface.new(hostname: @hostname, port: @port)
|
||||||
|
when :connection
|
||||||
|
@connection = interface.new(hostname: @hostname, port: @port)
|
||||||
|
when :memory
|
||||||
|
@server = interface[:server].new(hostname: @hostname, port: @port)
|
||||||
|
@connection = interface[:connection].new(hostname: @hostname, port: @port)
|
||||||
|
else
|
||||||
|
raise ArgumentError, "Expected mode to be :server, :connection, or :memory, not #{mode.inspect}"
|
||||||
|
end
|
||||||
|
|
||||||
|
@last_tick_time = milliseconds
|
||||||
|
@directing = true
|
||||||
|
@storage = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
def run
|
||||||
|
Thread.start do |thread|
|
||||||
|
while(@directing)
|
||||||
|
dt = milliseconds - @last_tick_time
|
||||||
|
|
||||||
|
tick(dt)
|
||||||
|
|
||||||
|
@server.update if @server
|
||||||
|
@connection.update if @connection
|
||||||
|
|
||||||
|
@last_tick_time = milliseconds
|
||||||
|
sleep(@tick_rate)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def tick(dt)
|
||||||
|
end
|
||||||
|
|
||||||
|
def shutdown
|
||||||
|
@directing = false
|
||||||
|
|
||||||
|
@clients.each(&:close)
|
||||||
|
@server.update if @server
|
||||||
|
@connection.update if @connection
|
||||||
|
end
|
||||||
|
|
||||||
|
def milliseconds
|
||||||
|
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
11
lib/networking/events.rb
Normal file
11
lib/networking/events.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class IMICFPS
|
||||||
|
module Networking
|
||||||
|
module Events
|
||||||
|
def on_connect(client)
|
||||||
|
end
|
||||||
|
|
||||||
|
def on_disconnect(client)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
18
lib/networking/packet.rb
Normal file
18
lib/networking/packet.rb
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
class IMICFPS
|
||||||
|
module Networking
|
||||||
|
class Packet
|
||||||
|
def initialize(type:, payload:)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.encode(packet)
|
||||||
|
"#{packet.type}|#{packet.payload}"
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.decode(string)
|
||||||
|
split = string.split("|")
|
||||||
|
|
||||||
|
Packet.new(split.first, split.last)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
6
lib/networking/packet_handler.rb
Normal file
6
lib/networking/packet_handler.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class IMICFPS
|
||||||
|
module Networking
|
||||||
|
class PacketHandler
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
26
lib/networking/server.rb
Normal file
26
lib/networking/server.rb
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
class IMICFPS
|
||||||
|
module Networking
|
||||||
|
MAX_CLIENTS = 32
|
||||||
|
|
||||||
|
class Server
|
||||||
|
attr_reader :hostname, :port, :max_clients, :clients
|
||||||
|
def initialize(hostname:, port:, max_clients: MAX_CLIENTS)
|
||||||
|
@hostname = hostname
|
||||||
|
@port = port
|
||||||
|
@max_clients = max_clients
|
||||||
|
|
||||||
|
@clients = []
|
||||||
|
@socket = nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def bind
|
||||||
|
end
|
||||||
|
|
||||||
|
def broadcast(packet)
|
||||||
|
end
|
||||||
|
|
||||||
|
def close
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
class IMICFPS
|
|
||||||
class Overlay
|
|
||||||
include CommonMethods
|
|
||||||
|
|
||||||
Slot = Struct.new(:value, :width)
|
|
||||||
|
|
||||||
def initialize
|
|
||||||
@text = CyberarmEngine::Text.new("", x: 3, y: 3, shadow_color: Gosu::Color::BLACK)
|
|
||||||
@slots = []
|
|
||||||
@space_width = @text.textobject.text_width(" ")
|
|
||||||
end
|
|
||||||
|
|
||||||
def draw
|
|
||||||
return if @text.text.empty?
|
|
||||||
width = @text.width + 8
|
|
||||||
|
|
||||||
Gosu.draw_rect(0, 0, width, (@text.height + 4), Gosu::Color.rgba(0, 0, 0, 100))
|
|
||||||
Gosu.draw_rect(2, 2, width - 4, (@text.height + 4) - 4, Gosu::Color.rgba(100, 100, 100, 100))
|
|
||||||
|
|
||||||
@text.draw
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
rebuild_slots
|
|
||||||
end
|
|
||||||
|
|
||||||
def rebuild_slots
|
|
||||||
@slots.clear
|
|
||||||
|
|
||||||
if window.config.get(:options, :fps)
|
|
||||||
create_slot "FPS: #{Gosu.fps}"
|
|
||||||
create_slot "Frame time: #{Gosu.milliseconds - window.delta_time}ms" if window.config.get(:debug_options, :stats)
|
|
||||||
end
|
|
||||||
|
|
||||||
if window.config.get(:debug_options, :stats)
|
|
||||||
create_slot "Vertices: #{formatted_number(window.number_of_vertices)}"
|
|
||||||
create_slot "Face: #{formatted_number(window.number_of_vertices / 3)}"
|
|
||||||
end
|
|
||||||
|
|
||||||
if window.config.get(:debug_options, :boundingboxes)
|
|
||||||
create_slot "Boundingboxes: #{window.config.get(:debug_options, :boundingboxes) ? 'On' : 'Off'}"
|
|
||||||
end
|
|
||||||
|
|
||||||
if window.config.get(:debug_options, :wireframe)
|
|
||||||
create_slot "Wireframes: #{window.config.get(:debug_options, :wireframe) ? 'On' : 'Off'}"
|
|
||||||
end
|
|
||||||
|
|
||||||
@text.text = ""
|
|
||||||
@slots.each_with_index do |slot, i|
|
|
||||||
@text.text += "#{slot.value} <c=ff000000>•</c> " unless i == @slots.size - 1
|
|
||||||
@text.text += "#{slot.value}" if i == @slots.size - 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_slot(string)
|
|
||||||
@slots << Slot.new(string, @text.textobject.text_width(string))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -155,7 +155,6 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
if window.config.get(:debug_options, :wireframe)
|
if window.config.get(:debug_options, :wireframe)
|
||||||
glLineWidth(2)
|
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
|
||||||
Shader.active_shader.uniform_boolean("disableLighting", true)
|
Shader.active_shader.uniform_boolean("disableLighting", true)
|
||||||
|
|
||||||
@@ -164,7 +163,6 @@ class IMICFPS
|
|||||||
|
|
||||||
Shader.active_shader.uniform_boolean("disableLighting", false)
|
Shader.active_shader.uniform_boolean("disableLighting", false)
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
|
||||||
glLineWidth(1)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, model.faces.count * 3)
|
glDrawArrays(GL_TRIANGLES, 0, model.faces.count * 3)
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ class IMICFPS
|
|||||||
@player = @map.find_entity_by(name: "character")
|
@player = @map.find_entity_by(name: "character")
|
||||||
@camera = Camera.new(position: @player.position.clone)
|
@camera = Camera.new(position: @player.position.clone)
|
||||||
@camera.attach_to(@player)
|
@camera.attach_to(@player)
|
||||||
|
@director = Networking::Director.new(mode: :memory, hostname: "i-mic.rubyclan.org", port: 56789, interface: { server: Networking::MemoryServer, connection: Networking::MemoryConnection }, state: self)
|
||||||
|
|
||||||
@crosshair = Crosshair.new
|
@crosshair = Crosshair.new
|
||||||
|
|
||||||
@text = Text.new("Pending...", x: 10, y: 22, z: 1, size: 18, font: "DejaVu Sans", shadow_color: Gosu::Color::BLACK)
|
@text = Text.new("Pending...", x: 10, y: 10, z: 1, size: 18, font: "DejaVu Sans", shadow_color: Gosu::Color::BLACK)
|
||||||
|
|
||||||
if ARGV.join.include?("--playdemo")
|
if ARGV.join.include?("--playdemo")
|
||||||
@demo = Demo.new(camera: @camera, player: @player, demo: "./demo.dat", mode: :play) if File.exist?("./demo.dat")
|
@demo = Demo.new(camera: @camera, player: @player, demo: "./demo.dat", mode: :play) if File.exist?("./demo.dat")
|
||||||
@@ -39,14 +40,19 @@ class IMICFPS
|
|||||||
control_player
|
control_player
|
||||||
|
|
||||||
@camera.update
|
@camera.update
|
||||||
|
@director.tick(window.dt)
|
||||||
|
|
||||||
if window.config.get(:debug_options, :stats)
|
if window.config.get(:debug_options, :stats)
|
||||||
@text.text = update_text
|
@text.text = update_text
|
||||||
|
elsif window.config.get(:options, :fps)
|
||||||
|
@text.text = "FPS: #{Gosu.fps}"
|
||||||
else
|
else
|
||||||
@text.text = ""
|
@text.text = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
@demo.update if @demo
|
@demo.update if @demo
|
||||||
|
|
||||||
|
window.number_of_vertices = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_text
|
def update_text
|
||||||
@@ -62,6 +68,10 @@ Camera Field Of View: #{@camera.field_of_view}
|
|||||||
Camera Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
Camera Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
||||||
|
|
||||||
#{if @camera.entity then "Actor X: #{@camera.entity.position.x.round(2)} Y: #{@camera.entity.position.y.round(2)} Z: #{@camera.entity.position.z.round(2)}";end}
|
#{if @camera.entity then "Actor X: #{@camera.entity.position.x.round(2)} Y: #{@camera.entity.position.y.round(2)} Z: #{@camera.entity.position.z.round(2)}";end}
|
||||||
|
Last Frame: #{Gosu.milliseconds - window.delta_time}ms (#{Gosu.fps} fps)
|
||||||
|
|
||||||
|
Vertices: #{formatted_number(window.number_of_vertices)}
|
||||||
|
Faces: #{formatted_number(window.number_of_vertices/3)}
|
||||||
eos
|
eos
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,7 @@ class IMICFPS
|
|||||||
class LoadingState < Menu
|
class LoadingState < Menu
|
||||||
def setup
|
def setup
|
||||||
window.needs_cursor = false
|
window.needs_cursor = false
|
||||||
if @options[:map_file]
|
@map_parser = MapParser.new(map_file: @options[:map_file])
|
||||||
@map_parser = MapParser.new(map_file: @options[:map_file])
|
|
||||||
elsif @options[:map_parser]
|
|
||||||
@map_parser = @options[:map_parser]
|
|
||||||
else
|
|
||||||
raise "Unable to load map, missing :map_file or :map_parser"
|
|
||||||
end
|
|
||||||
|
|
||||||
title "I-MIC FPS"
|
title "I-MIC FPS"
|
||||||
@subheading = Text.new("Loading Map: #{@map_parser.metadata.name}", y: 100, size: 50, alignment: :center)
|
@subheading = Text.new("Loading Map: #{@map_parser.metadata.name}", y: 100, size: 50, alignment: :center)
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ class IMICFPS
|
|||||||
@lights << @light
|
@lights << @light
|
||||||
|
|
||||||
@camera = Camera.new(position: Vector.new(0, 1.5, 5), orientation: Vector.forward)
|
@camera = Camera.new(position: Vector.new(0, 1.5, 5), orientation: Vector.forward)
|
||||||
|
@renderer = Renderer.new
|
||||||
|
|
||||||
label @manifest.name, text_size: 50
|
label @manifest.name, text_size: 50
|
||||||
label @manifest.model
|
label @manifest.model
|
||||||
@@ -54,7 +55,7 @@ class IMICFPS
|
|||||||
)
|
)
|
||||||
|
|
||||||
Gosu.gl do
|
Gosu.gl do
|
||||||
window.renderer.draw(@camera, [@light], @map.entities)
|
@renderer.draw(@camera, [@light], @map.entities)
|
||||||
end
|
end
|
||||||
|
|
||||||
@crosshair.draw
|
@crosshair.draw
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
require_relative "map_editor/lib/main_menu"
|
require_relative "map_editor/lib/main_menu"
|
||||||
require_relative "map_editor/lib/editor"
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
class IMICFPS
|
|
||||||
class MapEditorTool
|
|
||||||
class Editor < CyberarmEngine::GuiState
|
|
||||||
|
|
||||||
attr_reader :map
|
|
||||||
def setup
|
|
||||||
# TODO: Move everything required for a playable game map
|
|
||||||
# in to a Scene or Scene3D container object
|
|
||||||
# and refactor Game to use it.
|
|
||||||
Publisher.new
|
|
||||||
@map = Map.new( map_parser: @options[:map_parser] )
|
|
||||||
@camera = Camera.new( position: Vector.new )
|
|
||||||
@crosshair = Crosshair.new
|
|
||||||
|
|
||||||
@map.setup
|
|
||||||
end
|
|
||||||
|
|
||||||
def draw
|
|
||||||
super
|
|
||||||
@map.render(@camera)
|
|
||||||
@crosshair.draw
|
|
||||||
end
|
|
||||||
|
|
||||||
def update
|
|
||||||
super
|
|
||||||
Publisher.instance.publish(:tick, Gosu.milliseconds - window.delta_time)
|
|
||||||
@map.update
|
|
||||||
@camera.update
|
|
||||||
end
|
|
||||||
|
|
||||||
def button_down(id)
|
|
||||||
if id == Gosu::KB_ESCAPE
|
|
||||||
# TODO: Use Editor specific menu
|
|
||||||
push_state(GamePauseMenu)
|
|
||||||
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
InputMapper.keydown(id)
|
|
||||||
Publisher.instance.publish(:button_down, nil, id)
|
|
||||||
|
|
||||||
@map.entities.each do |entity|
|
|
||||||
entity.button_down(id) if defined?(entity.button_down)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def button_up(id)
|
|
||||||
InputMapper.keyup(id)
|
|
||||||
Publisher.instance.publish(:button_up, nil, id)
|
|
||||||
|
|
||||||
@map.entities.each do |entity|
|
|
||||||
entity.button_up(id) if defined?(entity.button_up)
|
|
||||||
end
|
|
||||||
|
|
||||||
@camera.button_up(id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -29,7 +29,7 @@ class IMICFPS
|
|||||||
flow(margin: 10) do
|
flow(margin: 10) do
|
||||||
@maps.each do |map|
|
@maps.each do |map|
|
||||||
button map.metadata.name do
|
button map.metadata.name do
|
||||||
push_state(LoadingState, map_parser: map, forward: Editor)
|
# push_state(TurnTable, manifest: manifest)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class IMICFPS
|
|||||||
push_state(ExtrasMenu)
|
push_state(ExtrasMenu)
|
||||||
end
|
end
|
||||||
|
|
||||||
link "Exit Game" do
|
link "Exit" do
|
||||||
window.close
|
window.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ class IMICFPS
|
|||||||
@renderer = Renderer.new
|
@renderer = Renderer.new
|
||||||
@renderer.preload_default_shaders
|
@renderer.preload_default_shaders
|
||||||
@scene = TurnTableScene.new
|
@scene = TurnTableScene.new
|
||||||
@overlay = Overlay.new
|
|
||||||
|
|
||||||
@canvas_size = Vector.new(self.width, self.height)
|
@canvas_size = Vector.new(self.width, self.height)
|
||||||
|
|
||||||
@@ -47,7 +46,6 @@ class IMICFPS
|
|||||||
super
|
super
|
||||||
|
|
||||||
@console.draw if @show_console
|
@console.draw if @show_console
|
||||||
@overlay.draw
|
|
||||||
draw_cursor if needs_cursor
|
draw_cursor if needs_cursor
|
||||||
|
|
||||||
_canvas_size = Vector.new(self.width, self.height)
|
_canvas_size = Vector.new(self.width, self.height)
|
||||||
@@ -67,9 +65,6 @@ class IMICFPS
|
|||||||
super
|
super
|
||||||
|
|
||||||
@console.update if @show_console
|
@console.update if @show_console
|
||||||
@overlay.update
|
|
||||||
|
|
||||||
@number_of_vertices = 0
|
|
||||||
@delta_time = Gosu.milliseconds
|
@delta_time = Gosu.milliseconds
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user