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/director"
|
||||
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
|
||||
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 Director
|
||||
attr_reader :current_tick
|
||||
def initialize(map:, players:, networking_mode: :virtual, tick_rate: 10)
|
||||
@map = map
|
||||
@players = players
|
||||
@connection = IMICRTS::Connection.new(director: self, mode: networking_mode)
|
||||
@networking_mode = networking_mode
|
||||
@tick_rate = tick_rate
|
||||
|
||||
@last_tick_at = Gosu.milliseconds
|
||||
@tick_time = 1000.0 / @tick_rate
|
||||
@current_tick = 0
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -15,11 +18,14 @@ class IMICRTS
|
||||
@last_tick_at = Gosu.milliseconds
|
||||
|
||||
tick
|
||||
@connection.update
|
||||
end
|
||||
end
|
||||
|
||||
def tick
|
||||
@players.each(&:tick)
|
||||
@players.each { |player| player.tick(@current_tick) }
|
||||
|
||||
@current_tick += 1
|
||||
end
|
||||
|
||||
def player(id)
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
class IMICRTS
|
||||
class Entity
|
||||
attr_reader :position, :angle, :radius
|
||||
def initialize(manifest: nil, images:, position:, angle:)
|
||||
attr_reader :id, :position, :angle, :radius
|
||||
def initialize(id:, manifest: nil, images:, position:, angle:)
|
||||
@id = id
|
||||
@manifest = manifest
|
||||
@images = images
|
||||
@position = position
|
||||
@@ -40,20 +41,18 @@ class IMICRTS
|
||||
|
||||
def rotate_towards(vector)
|
||||
_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
|
||||
if @angle.between?(_angle - 3, _angle + 3)
|
||||
@angle = _angle
|
||||
elsif a < 180
|
||||
@angle -= 1
|
||||
@angle -= 1.0
|
||||
else
|
||||
@angle += 1
|
||||
@angle += 1.0
|
||||
end
|
||||
|
||||
@angle %= 360
|
||||
|
||||
pp [a, _angle, @angle]
|
||||
@angle %= 360.0
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,6 +1,7 @@
|
||||
class IMICRTS
|
||||
class Player
|
||||
attr_reader :id, :name, :entities, :orders, :camera
|
||||
attr_reader :selected_entities
|
||||
def initialize(id:, name: nil)
|
||||
@id = id
|
||||
@name = name ? name : "Novice-#{id}"
|
||||
@@ -8,13 +9,20 @@ class IMICRTS
|
||||
@entities = []
|
||||
@orders = []
|
||||
@camera = Camera.new
|
||||
|
||||
@selected_entities = []
|
||||
@current_entity_id = 0
|
||||
end
|
||||
|
||||
def tick
|
||||
puts "Player #{@id}-#{@name} ticked: #{Gosu.milliseconds}"
|
||||
def tick(tick_id)
|
||||
end
|
||||
|
||||
def entity(id)
|
||||
@entities.find { |ent| ent.id == id }
|
||||
end
|
||||
|
||||
def next_entity_id
|
||||
@current_entity_id += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,10 +2,12 @@ class IMICRTS
|
||||
class Game < CyberarmEngine::GuiState
|
||||
def setup
|
||||
window.show_cursor = true
|
||||
@selected_entities = []
|
||||
|
||||
@player = Player.new(id: 0)
|
||||
@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)
|
||||
|
||||
@sidebar = stack(height: 1.0) do
|
||||
@@ -17,6 +19,7 @@ class IMICRTS
|
||||
@buttons = stack(width: 75) do
|
||||
@h = button("Harvester", width: 1.0) do
|
||||
@player.entities << Entity.new(
|
||||
id: @player.next_entity_id,
|
||||
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),
|
||||
angle: rand(360)
|
||||
@@ -24,6 +27,7 @@ class IMICRTS
|
||||
end
|
||||
@c = button("Construction Worker", width: 1.0) do
|
||||
@player.entities << Entity.new(
|
||||
id: @player.next_entity_id,
|
||||
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),
|
||||
angle: rand(360)
|
||||
|
||||
Reference in New Issue
Block a user