mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-14 07:12:34 +00:00
Added Director, Player and stubbed Order, mostly working Entity#rotate_towards
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class IMICRTS
|
||||
class Entity
|
||||
attr_reader :position, :angle
|
||||
attr_reader :position, :angle, :radius
|
||||
def initialize(manifest: nil, images:, position:, angle:)
|
||||
@manifest = manifest
|
||||
@images = images
|
||||
@@ -37,5 +37,23 @@ class IMICRTS
|
||||
def draw_gizmos
|
||||
Gosu.draw_rect(@position.x - @radius, @position.y - (@radius + 2), @radius * 2, 2, Gosu::Color::GREEN, ZOrder::ENTITY_GIZMOS)
|
||||
end
|
||||
|
||||
def rotate_towards(vector)
|
||||
_angle = Gosu.angle(@position.x, @position.y, vector.x, vector.y)
|
||||
a = (360 + (_angle - @angle)) % 360
|
||||
|
||||
# Fails if vector is directly behind entity
|
||||
if @angle.between?(_angle - 3, _angle + 3)
|
||||
@angle = _angle
|
||||
elsif a < 180
|
||||
@angle -= 1
|
||||
else
|
||||
@angle += 1
|
||||
end
|
||||
|
||||
@angle %= 360
|
||||
|
||||
pp [a, _angle, @angle]
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user