mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-13 14:52:35 +00:00
Stubbed Connection, added #next_entity_id to Player, made Director store and pass to Player the current_tick
This commit is contained in:
@@ -26,5 +26,6 @@ require_relative "lib/entity"
|
|||||||
require_relative "lib/order"
|
require_relative "lib/order"
|
||||||
require_relative "lib/director"
|
require_relative "lib/director"
|
||||||
require_relative "lib/player"
|
require_relative "lib/player"
|
||||||
|
require_relative "lib/connection"
|
||||||
|
|
||||||
IMICRTS::Window.new(width: Gosu.screen_width / 4 * 3, height: Gosu.screen_height / 4 * 3, fullscreen: false, resizable: true).show
|
IMICRTS::Window.new(width: Gosu.screen_width / 4 * 3, height: Gosu.screen_height / 4 * 3, fullscreen: false, resizable: true).show
|
||||||
9
lib/connection.rb
Normal file
9
lib/connection.rb
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
class IMICRTS
|
||||||
|
class Connection
|
||||||
|
def initialize(*args)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
class IMICRTS
|
class IMICRTS
|
||||||
class Director
|
class Director
|
||||||
|
attr_reader :current_tick
|
||||||
def initialize(map:, players:, networking_mode: :virtual, tick_rate: 10)
|
def initialize(map:, players:, networking_mode: :virtual, tick_rate: 10)
|
||||||
@map = map
|
@map = map
|
||||||
@players = players
|
@players = players
|
||||||
|
@connection = IMICRTS::Connection.new(director: self, mode: networking_mode)
|
||||||
@networking_mode = networking_mode
|
@networking_mode = networking_mode
|
||||||
@tick_rate = tick_rate
|
@tick_rate = tick_rate
|
||||||
|
|
||||||
@last_tick_at = Gosu.milliseconds
|
@last_tick_at = Gosu.milliseconds
|
||||||
@tick_time = 1000.0 / @tick_rate
|
@tick_time = 1000.0 / @tick_rate
|
||||||
|
@current_tick = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@@ -15,11 +18,14 @@ class IMICRTS
|
|||||||
@last_tick_at = Gosu.milliseconds
|
@last_tick_at = Gosu.milliseconds
|
||||||
|
|
||||||
tick
|
tick
|
||||||
|
@connection.update
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tick
|
def tick
|
||||||
@players.each(&:tick)
|
@players.each { |player| player.tick(@current_tick) }
|
||||||
|
|
||||||
|
@current_tick += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def player(id)
|
def player(id)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
class IMICRTS
|
class IMICRTS
|
||||||
class Entity
|
class Entity
|
||||||
attr_reader :position, :angle, :radius
|
attr_reader :id, :position, :angle, :radius
|
||||||
def initialize(manifest: nil, images:, position:, angle:)
|
def initialize(id:, manifest: nil, images:, position:, angle:)
|
||||||
|
@id = id
|
||||||
@manifest = manifest
|
@manifest = manifest
|
||||||
@images = images
|
@images = images
|
||||||
@position = position
|
@position = position
|
||||||
@@ -40,20 +41,18 @@ class IMICRTS
|
|||||||
|
|
||||||
def rotate_towards(vector)
|
def rotate_towards(vector)
|
||||||
_angle = Gosu.angle(@position.x, @position.y, vector.x, vector.y)
|
_angle = Gosu.angle(@position.x, @position.y, vector.x, vector.y)
|
||||||
a = (360 + (_angle - @angle)) % 360
|
a = (360.0 + (_angle - @angle)) % 360.0
|
||||||
|
|
||||||
# Fails if vector is directly behind entity
|
# Fails if vector is directly behind entity
|
||||||
if @angle.between?(_angle - 3, _angle + 3)
|
if @angle.between?(_angle - 3, _angle + 3)
|
||||||
@angle = _angle
|
@angle = _angle
|
||||||
elsif a < 180
|
elsif a < 180
|
||||||
@angle -= 1
|
@angle -= 1.0
|
||||||
else
|
else
|
||||||
@angle += 1
|
@angle += 1.0
|
||||||
end
|
end
|
||||||
|
|
||||||
@angle %= 360
|
@angle %= 360.0
|
||||||
|
|
||||||
pp [a, _angle, @angle]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
class IMICRTS
|
class IMICRTS
|
||||||
class Player
|
class Player
|
||||||
attr_reader :id, :name, :entities, :orders, :camera
|
attr_reader :id, :name, :entities, :orders, :camera
|
||||||
|
attr_reader :selected_entities
|
||||||
def initialize(id:, name: nil)
|
def initialize(id:, name: nil)
|
||||||
@id = id
|
@id = id
|
||||||
@name = name ? name : "Novice-#{id}"
|
@name = name ? name : "Novice-#{id}"
|
||||||
@@ -8,13 +9,20 @@ class IMICRTS
|
|||||||
@entities = []
|
@entities = []
|
||||||
@orders = []
|
@orders = []
|
||||||
@camera = Camera.new
|
@camera = Camera.new
|
||||||
|
|
||||||
|
@selected_entities = []
|
||||||
|
@current_entity_id = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def tick
|
def tick(tick_id)
|
||||||
puts "Player #{@id}-#{@name} ticked: #{Gosu.milliseconds}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def entity(id)
|
def entity(id)
|
||||||
|
@entities.find { |ent| ent.id == id }
|
||||||
|
end
|
||||||
|
|
||||||
|
def next_entity_id
|
||||||
|
@current_entity_id += 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2,10 +2,12 @@ class IMICRTS
|
|||||||
class Game < CyberarmEngine::GuiState
|
class Game < CyberarmEngine::GuiState
|
||||||
def setup
|
def setup
|
||||||
window.show_cursor = true
|
window.show_cursor = true
|
||||||
@selected_entities = []
|
|
||||||
|
|
||||||
@player = Player.new(id: 0)
|
@player = Player.new(id: 0)
|
||||||
@director = Director.new(map: nil, players: [@player])
|
@director = Director.new(map: nil, players: [@player])
|
||||||
|
|
||||||
|
@selected_entities = []
|
||||||
|
|
||||||
@mouse_pos = CyberarmEngine::Text.new("X: 0\nY: 0", x: 500, y: 10, z: Float::INFINITY)
|
@mouse_pos = CyberarmEngine::Text.new("X: 0\nY: 0", x: 500, y: 10, z: Float::INFINITY)
|
||||||
|
|
||||||
@sidebar = stack(height: 1.0) do
|
@sidebar = stack(height: 1.0) do
|
||||||
@@ -17,6 +19,7 @@ class IMICRTS
|
|||||||
@buttons = stack(width: 75) do
|
@buttons = stack(width: 75) do
|
||||||
@h = button("Harvester", width: 1.0) do
|
@h = button("Harvester", width: 1.0) do
|
||||||
@player.entities << Entity.new(
|
@player.entities << Entity.new(
|
||||||
|
id: @player.next_entity_id,
|
||||||
images: Gosu::Image.new("#{ASSETS_PATH}/vehicles/harvester/images/harvester.png", retro: true),
|
images: Gosu::Image.new("#{ASSETS_PATH}/vehicles/harvester/images/harvester.png", retro: true),
|
||||||
position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE),
|
position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE),
|
||||||
angle: rand(360)
|
angle: rand(360)
|
||||||
@@ -24,6 +27,7 @@ class IMICRTS
|
|||||||
end
|
end
|
||||||
@c = button("Construction Worker", width: 1.0) do
|
@c = button("Construction Worker", width: 1.0) do
|
||||||
@player.entities << Entity.new(
|
@player.entities << Entity.new(
|
||||||
|
id: @player.next_entity_id,
|
||||||
images: Gosu::Image.new("#{ASSETS_PATH}/vehicles/construction_worker/images/construction_worker.png", retro: true),
|
images: Gosu::Image.new("#{ASSETS_PATH}/vehicles/construction_worker/images/construction_worker.png", retro: true),
|
||||||
position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE),
|
position: CyberarmEngine::Vector.new(rand(window.width), rand(window.height), ZOrder::GROUND_VEHICLE),
|
||||||
angle: rand(360)
|
angle: rand(360)
|
||||||
|
|||||||
Reference in New Issue
Block a user