Added Director, Player and stubbed Order, mostly working Entity#rotate_towards

This commit is contained in:
2019-10-02 22:35:44 -05:00
parent e29bc47817
commit 8be63d8ebe
9 changed files with 185 additions and 19 deletions

View File

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