Skip to content

Commit 48401aa

Browse files
author
sam
committed
Added first playing field part 3
1 parent ca6bfa4 commit 48401aa

3 files changed

Lines changed: 29 additions & 12 deletions

File tree

source/ev3dev2/simulator/Simulator.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def __init__(self, robot_state, robot_pos):
5555
self.right_ts_data = False
5656
self.top_us_data = -1
5757

58+
self.text_x = self.screen_width - apply_scaling(220)
59+
5860

5961
def setup(self):
6062
"""
@@ -126,13 +128,12 @@ def _draw_text(self):
126128
message = self.robot_state.next_sound_job()
127129
sound = message if message else '-'
128130

129-
arcade.draw_text(center_cs, self.screen_width - 140, self.screen_height - 45, arcade.color.BLACK_LEATHER_JACKET, 10)
130-
arcade.draw_text(left_ts, self.screen_width - 140, self.screen_height - 60, arcade.color.BLACK_LEATHER_JACKET, 10)
131-
arcade.draw_text(right_ts, self.screen_width - 140, self.screen_height - 75, arcade.color.BLACK_LEATHER_JACKET, 10)
132-
arcade.draw_text(top_us, self.screen_width - 140, self.screen_height - 90, arcade.color.BLACK_LEATHER_JACKET, 10)
133-
arcade.draw_text('Sound:', self.screen_width - 140, self.screen_height - 105, arcade.color.BLACK_LEATHER_JACKET, 10)
134-
arcade.draw_text(sound, self.screen_width - 140, self.screen_height - 120, arcade.color.BLACK_LEATHER_JACKET, 10,
135-
anchor_y='top')
131+
arcade.draw_text(center_cs, self.text_x, self.screen_height - apply_scaling(80), arcade.color.BLACK_LEATHER_JACKET, 10)
132+
arcade.draw_text(left_ts, self.text_x, self.screen_height - apply_scaling(100), arcade.color.BLACK_LEATHER_JACKET, 10)
133+
arcade.draw_text(right_ts, self.text_x, self.screen_height - apply_scaling(120), arcade.color.BLACK_LEATHER_JACKET, 10)
134+
arcade.draw_text(top_us, self.text_x, self.screen_height - apply_scaling(140), arcade.color.BLACK_LEATHER_JACKET, 10)
135+
arcade.draw_text('Sound:', self.text_x, self.screen_height - apply_scaling(160), arcade.color.BLACK_LEATHER_JACKET, 10)
136+
arcade.draw_text(sound, self.text_x, self.screen_height - apply_scaling(180), arcade.color.BLACK_LEATHER_JACKET, 10, anchor_y='top')
136137

137138

138139
def update(self, delta_time):
@@ -182,12 +183,12 @@ def main():
182183
default=200,
183184
help="Starting position x-coordinate of the robot, default is 200",
184185
required=False,
185-
type=int)
186+
type=check_xy)
186187
parser.add_argument("-y", "--robot_position_y",
187188
default=300,
188189
help="Starting position y-coordinate of the robot, default is 300",
189190
required=False,
190-
type=int)
191+
type=check_xy)
191192
parser.add_argument("-o", "--robot_orientation",
192193
default=0,
193194
help="Starting orientation the robot, default is 0",
@@ -226,4 +227,16 @@ def check_scale(value):
226227
return f
227228

228229

230+
def check_xy(value):
231+
try:
232+
f = int(value)
233+
except ValueError:
234+
raise argparse.ArgumentTypeError('Coordinate value must be a integer')
235+
236+
if f < 0 or f > 1000:
237+
raise argparse.ArgumentTypeError("%s is an invalid coordinate. Should be between 0 and 1000" % f)
238+
239+
return f
240+
241+
229242
main()

source/ev3dev2/simulator/config/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ image_paths:
3434

3535
obstacle_settings:
3636
border_settings:
37-
border_depth: 15
37+
border_depth: 30
3838

3939
lake_settings:
4040
border_width: 29

source/ev3dev2/simulator/connection/ServerSocket.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def __init__(self, robot_state):
2323
self.message_processor = MessageProcessor(robot_state)
2424
self.robot_state = robot_state
2525

26+
self.first_run = True
27+
2628

2729
def run(self):
2830
"""
@@ -42,6 +44,10 @@ def run(self):
4244
(client, address) = server.accept()
4345

4446
print('Connection accepted')
47+
if not self.first_run:
48+
self.robot_state.should_reset = True
49+
50+
self.first_run = False
4551
time.sleep(1)
4652

4753
try:
@@ -63,8 +69,6 @@ def run(self):
6369
print('Closing connection...')
6470
client.close()
6571

66-
self.robot_state.should_reset = True
67-
6872

6973
def _process(self, data: bytes) -> bytes:
7074
"""

0 commit comments

Comments
 (0)