1- // import context from 'js-slang/context'; NOT ALLOWED
1+ import context from 'js-slang/context' ;
22import {
33 head ,
44 tail ,
@@ -77,23 +77,23 @@ const robot: Robot = {
7777let bounds : Point [ ] = [ ] ;
7878
7979// sets the context to the statedata obj, mostly for convenience so i dont have to type context.... everytime
80- // context.moduleContexts.robot_minigame.state = stateData;
80+ context . moduleContexts . robot_minigame . state = stateData ;
8181
82- export function set_pos ( x : number , y : number ) : void {
82+ function set_pos ( x : number , y : number ) : void {
8383 robot . x = x ;
8484 robot . y = y ;
8585}
8686
87- export function set_rotation ( rotation : number ) {
87+ function set_rotation ( rotation : number ) {
8888 robot . dx = Math . cos ( rotation ) ;
8989 robot . dy = - Math . sin ( rotation ) ;
9090}
9191
92- export function set_width ( width : number ) {
92+ function set_width ( width : number ) {
9393 stateData . width = width ;
9494}
9595
96- export function set_height ( height : number ) {
96+ function set_height ( height : number ) {
9797 stateData . height = height ;
9898}
9999
@@ -104,13 +104,13 @@ export function set_height(height: number) {
104104/**
105105 * Initializes a new simulation with a map of size width * height
106106 * Also sets the initial position an rotation of the robot
107- *
107+ *
108108 * @param width of the map
109109 * @param height of the map
110110 * @param posX initial X coordinate of the robot
111111 * @param posY initial Y coordinate of the robot
112112 * @param rotation initial rotation of the robot
113- */
113+ */
114114export function init (
115115 width : number ,
116116 height : number ,
@@ -138,88 +138,73 @@ export function init(
138138
139139/**
140140 * Creates a new area with the given vertices and flags
141- *
141+ *
142142 * @param vertices of the area
143143 * @param isCollidable a boolean indicating if the area is a collidable obstacle or not
144144 * @param flags any additional flags the area may have
145145 */
146146export function create_area (
147- vertices : List ,
147+ vertices : Point [ ] ,
148148 isCollidable : boolean ,
149149 flags : AreaFlags = { }
150150) {
151- // Parse vertices list into a points array
152- const points : Point [ ] = [ ] ;
151+ // // Parse vertices list into a points array
152+ // const points : Point[] = [];
153153
154- while ( vertices != null ) {
155- const p = head ( vertices ) ;
156- points . push ( { x : head ( p ) , y : tail ( p ) } ) ;
157- vertices = tail ( vertices ) ;
158- }
154+ // while (vertices != null) {
155+ // const p = head(vertices);
156+ // points.push({x: head(p), y: tail(p)});
157+ // vertices = tail(vertices);
158+ // }
159159
160160 // Store the new area
161161 stateData . areas . push ( {
162- vertices : points ,
162+ vertices,
163163 isCollidable,
164164 flags
165165 } ) ;
166166}
167167
168168/**
169169 * Creates a new obstacle
170- *
171- * @param vertices: List
170+ *
171+ * @param vertices of the obstacle
172172 */
173173export function create_obstacle (
174- vertices : List
174+ vertices : Point [ ]
175175) {
176176 create_area ( vertices , true ) ;
177177}
178178
179179/**
180180 * Creates a new rectangular, axis-aligned obstacle
181- *
182- * @param x top left corner of the
181+ *
182+ * @param x top left corner of the rectangle
183+ * @param y top right corner of the rectangle
184+ * @param width of the rectangle
185+ * @param height of the rectangle
183186 */
184-
185- /*
186- // easily set up a rectangular wall using the x and y of the top left corner, and width/height
187- export function set_rect_wall(x: number, y: number, width: number, height: number) {
188- const polygon: Polygon = [
189- {x: x, y: y},
190- {x: x + width, y: y},
191- {x: x+width, y: y+height},
192- {x: x, y:y+height}
193- ];
194-
195- stateData.walls.push(polygon);
196- }
197-
198- // creates irregularly shaped wall
199- // takes in a list of vertices as its argument
200- export function set_polygon_wall(vertices: List) {
201- const polygon: Polygon = [];
202-
203- while (vertices != null) {
204- const p = head(vertices);
205- polygon.push({x: head(p), y: tail(p)});
206- vertices = tail(vertices);
207- }
208-
209- stateData.walls.push(polygon);
187+ export function create_rect_obstacle (
188+ x : number ,
189+ y : number ,
190+ width : number ,
191+ height : number
192+ ) {
193+ create_obstacle ( [
194+ { x, y} ,
195+ { x : x + width , y} ,
196+ { x : x + width , y : y + height } ,
197+ { x, y :y + height }
198+ ] ) ;
210199}
211200
212- <<< REFACTOR / REIMPLEMENT */
213-
214-
215-
216201// ======= //
217202// SENSORS //
218203// ======= //
219204
220205/**
221206 * Get the distance to the closest collidable area
222- *
207+ *
223208 * @returns the distance to the closest obstacle
224209 */
225210export function get_distance ( ) : number {
@@ -229,7 +214,7 @@ export function get_distance() : number {
229214
230215/**
231216 * Gets the flags of the area containing the point (x, y)
232- *
217+ *
233218 * @param x coordinate
234219 * @param y coordinate
235220 * @returns the flags of the area containing (x, y)
@@ -244,23 +229,21 @@ export function get_flags(
244229
245230/**
246231 * Gets the color of the area under the robot
247- *
232+ *
248233 * @returns the color of the area under the robot
249234 */
250235export function get_color ( ) : string {
251236 // TO BE IMPLEMENTED
252- return "" ;
237+ return '' ;
253238}
254239
255-
256-
257240// ======= //
258241// ACTIONS //
259242// ======= //
260243
261244/**
262245 * Move the robot forward by the specified distance
263- *
246+ *
264247 * @param distance to move forward
265248 */
266249export function move_forward ( distance : number ) {
@@ -314,7 +297,7 @@ export function move_forward_to_wall() {
314297}
315298
316299/**
317- *
300+ *
318301 * @param angle the angle (in radians) to rotate right
319302 */
320303export function rotate ( angle : number ) {
@@ -380,7 +363,7 @@ export function turn_right() {
380363// ======= //
381364
382365/**
383- *
366+ *
384367 */
385368export function enteredAreas (
386369 check : ( area : Area [ ] ) => void
@@ -389,8 +372,6 @@ export function enteredAreas(
389372 return false ;
390373}
391374
392-
393-
394375// ==================== //
395376// Unassigned / Helpers //
396377// ==================== //
0 commit comments