mirror of
https://github.com/TimeCrafters/timecrafters_configuration_tool_desktop.git
synced 2025-12-15 13:32:33 +00:00
Added Turn state path draw
This commit is contained in:
3
Gemfile
3
Gemfile
@@ -1,4 +1,3 @@
|
||||
source "https://rubygems.org"
|
||||
|
||||
gem "cyberarm_engine"
|
||||
gem "faker", group: :development
|
||||
gem "cyberarm_engine"
|
||||
@@ -106,7 +106,7 @@ class State
|
||||
def initialize(robot:, distance:, power:)
|
||||
@robot = robot
|
||||
@distance = distance
|
||||
@power = power
|
||||
@power = power.clamp(-1.0, 1.0)
|
||||
end
|
||||
|
||||
def start
|
||||
@@ -116,12 +116,15 @@ class State
|
||||
@goal.y += Math.sin(@robot.angle.gosu_to_radians) * @distance
|
||||
|
||||
@complete = false
|
||||
@allowable_error = 3.0
|
||||
@allowable_error = 1.0
|
||||
end
|
||||
|
||||
def draw
|
||||
Gosu.draw_line(@robot.position.x + @robot.width / 2, @robot.position.y + @robot.depth / 2, Gosu::Color::GREEN, @goal.x + @robot.width / 2, @goal.y + @robot.depth / 2, Gosu::Color::GREEN)
|
||||
Gosu.draw_rect(@goal.x + (@robot.width / 2 - 2), @goal.y + (@robot.depth / 2 - 2), 4, 4, Gosu::Color::RED)
|
||||
Gosu.draw_line(
|
||||
@robot.position.x + @robot.width / 2, @robot.position.y + @robot.depth / 2, TAC::Palette::TIMECRAFTERS_TERTIARY,
|
||||
@goal.x + @robot.width / 2, @goal.y + @robot.depth / 2, TAC::Palette::TIMECRAFTERS_TERTIARY
|
||||
)
|
||||
Gosu.draw_rect(@goal.x + (@robot.width / 2 - 1), @goal.y + (@robot.depth / 2 - 1), 2, 2, Gosu::Color::RED)
|
||||
end
|
||||
|
||||
def update(dt)
|
||||
@@ -144,27 +147,58 @@ class State
|
||||
def initialize(robot:, relative_angle:, power:)
|
||||
@robot = robot
|
||||
@relative_angle = relative_angle
|
||||
@power = power
|
||||
@power = power.clamp(-1.0, 1.0)
|
||||
end
|
||||
|
||||
def start
|
||||
@starting_angle = @robot.angle
|
||||
@last_angle = @starting_angle
|
||||
@target_angle = (@starting_angle + @relative_angle) % 360.0
|
||||
@complete = false
|
||||
@allowable_error = 3.0
|
||||
end
|
||||
|
||||
def draw
|
||||
Gosu.rotate(@target_angle, @robot.position.x + @robot.width / 2, @robot.position.y + @robot.depth / 2) do
|
||||
fraction = 0
|
||||
angle_difference = Gosu.angle_diff(@target_angle, @robot.angle)
|
||||
|
||||
if angle_difference > 0
|
||||
fraction = angle_difference / 360.0
|
||||
else
|
||||
fraction = (angle_difference - 360 % 360) / 360.0
|
||||
end
|
||||
|
||||
Gosu.draw_arc(
|
||||
@robot.position.x + @robot.width / 2,
|
||||
@robot.position.y + @robot.depth / 2,
|
||||
@robot.width > @robot.depth ? @robot.width : @robot.depth,
|
||||
fraction,
|
||||
360,
|
||||
1,
|
||||
TAC::Palette::TIMECRAFTERS_TERTIARY
|
||||
)
|
||||
end
|
||||
|
||||
Gosu.draw_circle(
|
||||
@robot.position.x + @robot.width / 2 + Gosu.offset_x(@target_angle, @robot.width > @robot.depth ? @robot.width : @robot.depth),
|
||||
@robot.position.y + @robot.depth / 2 + Gosu.offset_y(@target_angle, @robot.width > @robot.depth ? @robot.width : @robot.depth),
|
||||
1,
|
||||
9,
|
||||
Gosu::Color::RED
|
||||
)
|
||||
# Gosu.draw_arc(@position.x, @position.y, 6, 1.0, 32, 2, @alliance)
|
||||
end
|
||||
|
||||
def update(dt)
|
||||
target_angle = (@starting_angle + @relative_angle) % 360.0
|
||||
|
||||
if @robot.angle.between?(target_angle - @allowable_error, target_angle + @allowable_error)
|
||||
if @robot.angle.between?(@target_angle - @allowable_error, @target_angle + @allowable_error)
|
||||
@complete = true
|
||||
@robot.angle = target_angle
|
||||
@robot.angle = @target_angle
|
||||
|
||||
elsif Gosu.angle_diff(@starting_angle, target_angle) > 0
|
||||
elsif Gosu.angle_diff(@starting_angle, @target_angle) > 0
|
||||
@robot.angle += @power * dt * @robot.speed
|
||||
|
||||
elsif Gosu.angle_diff(@starting_angle, target_angle) < 0
|
||||
elsif Gosu.angle_diff(@starting_angle, @target_angle) < 0
|
||||
@robot.angle -= @power * dt * @robot.speed
|
||||
end
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ module TAC
|
||||
flow width: 1.0, height: 0.05 do
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/right.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Run simulation" do
|
||||
begin
|
||||
@simulation_start_time = Gosu.milliseconds
|
||||
@simulation = TAC::Simulator::Simulation.new(source_code: @source_code.value, field_container: @field_container)
|
||||
@simulation.start
|
||||
rescue SyntaxError, NameError, NoMethodError, TypeError, ArgumentError => e
|
||||
@@ -32,7 +33,7 @@ module TAC
|
||||
end
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/stop.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Stop simulation" do
|
||||
@simulation.queue.clear if @simulation
|
||||
@simulation.robots.each { |robot| robot.queue.clear } if @simulation
|
||||
end
|
||||
button get_image("#{TAC::ROOT_PATH}/media/icons/save.png"), image_width: THEME_ICON_SIZE, width: 0.49, tip: "Save source code" do
|
||||
File.open("#{TAC::ROOT_PATH}/data/simulator.rb", "w") { |f| f.write @source_code.value }
|
||||
@@ -73,6 +74,7 @@ robot.forward 100"
|
||||
super
|
||||
|
||||
@simulation.update if @simulation
|
||||
@simulation_status.value = "Time: #{((Gosu.milliseconds - @simulation_start_time) / 1000.0).round(1)} seconds" if @simulation_start_time
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user