Skip to content

Commit 702a842

Browse files
committed
Add sense_obstacle()
1 parent 3810280 commit 702a842

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/bundles/robot_minigame/functions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,16 @@ export function get_distance() : number {
250250
return obstacleCollisions.length > 0 ? obstacleCollisions[0].distance - getRobot().radius : Infinity;
251251
}
252252

253+
// The maximum distance the robot can detect obstacles at
254+
const SENSOR_RANGE: number = 15;
255+
256+
/**
257+
* Check if there is an obstacle within a predefined distance from the robot
258+
*/
259+
export function sense_obstacle() : boolean {
260+
return get_distance() > SENSOR_RANGE;
261+
}
262+
253263
/**
254264
* Get the color of the area under the robot
255265
*

src/bundles/robot_minigame/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
export {
1010
init, create_area, create_rect_area, create_obstacle, create_rect_obstacle, complete_init,
11-
get_distance, get_color,
11+
get_distance, sense_obstacle, get_color,
1212
move_forward, move_forward_to_wall, rotate, turn_left, turn_right,
1313
should_enter_colors, run_all_tests
1414
} from './functions';

0 commit comments

Comments
 (0)