Skip to content

Commit ae6e98c

Browse files
committed
formatting fix
1 parent aef74d5 commit ae6e98c

File tree

2 files changed

+24
-27
lines changed

2 files changed

+24
-27
lines changed

src/bundles/robot_minigame/functions.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ export function set_rotation(rotation: number) {
7070
robot.dy = -Math.sin(rotation);
7171
}
7272

73-
7473
export function set_width(width: number) {
7574
stateData.width = width;
7675
}
@@ -88,7 +87,7 @@ export function init(width: number, height: number, posX: number, posY: number,
8887
set_pos(posX, posY);
8988
set_rotation(rotation);
9089

91-
stateData.moveCommands.push({type: "begin", position: getPositionWithRotation()}); // push starting point to movepoints data
90+
stateData.moveCommands.push({type: 'begin', position: getPositionWithRotation()}); // push starting point to movepoints data
9291
stateData.isInit = true;
9392

9493
bounds = [
@@ -111,13 +110,12 @@ export function turn_left() {
111110
if (robot.dx < 0.00001 && robot.dx > -0.00001) robot.dx = 0;
112111
if (robot.dy < 0.00001 && robot.dy > -0.00001) robot.dy = 0;
113112

114-
stateData.moveCommands.push({type: "rotateLeft", position: getPositionWithRotation()});
113+
stateData.moveCommands.push({type: 'rotateLeft', position: getPositionWithRotation()});
115114

116115
// debug log
117116
logCoordinates();
118117
}
119118

120-
121119
export function turn_right() {
122120
let currentAngle = Math.atan2(-robot.dy, robot.dx);
123121

@@ -129,7 +127,7 @@ export function turn_right() {
129127
if (robot.dx < 0.00001 && robot.dx > -0.00001) robot.dx = 0;
130128
if (robot.dy < 0.00001 && robot.dy > -0.00001) robot.dy = 0;
131129

132-
stateData.moveCommands.push({type: "rotateRight", position: getPositionWithRotation()});
130+
stateData.moveCommands.push({type: 'rotateRight', position: getPositionWithRotation()});
133131

134132
// debug log
135133
logCoordinates();
@@ -146,7 +144,7 @@ export function rotate_right(angle: number) {
146144
if (robot.dx < 0.00001 && robot.dx > -0.00001) robot.dx = 0;
147145
if (robot.dy < 0.00001 && robot.dy > -0.00001) robot.dy = 0;
148146

149-
stateData.moveCommands.push({type: "rotateRight", position: getPositionWithRotation()});
147+
stateData.moveCommands.push({type: 'rotateRight', position: getPositionWithRotation()});
150148

151149
// debug log
152150
logCoordinates();
@@ -163,7 +161,7 @@ export function rotate_left(angle: number) {
163161
if (robot.dx < 0.00001 && robot.dx > -0.00001) robot.dx = 0;
164162
if (robot.dy < 0.00001 && robot.dy > -0.00001) robot.dy = 0;
165163

166-
stateData.moveCommands.push({type: "rotateLeft", position: getPositionWithRotation()});
164+
stateData.moveCommands.push({type: 'rotateLeft', position: getPositionWithRotation()});
167165

168166
logCoordinates();
169167
}
@@ -218,7 +216,7 @@ export function move_forward_to_wall(): void {
218216

219217
robot.x = nextPoint.x;
220218
robot.y = nextPoint.y;
221-
stateData.moveCommands.push({type: "move", position: getPositionWithRotation()});
219+
stateData.moveCommands.push({type: 'move', position: getPositionWithRotation()});
222220

223221
// for debug
224222
stateData.messages.push(`Distance is ${distance} Collision point at x: ${nextPoint.x}, y: ${nextPoint.y}`);
@@ -229,9 +227,9 @@ export function move_forward(moveDist: number): void {
229227
// need to check for collision with wall
230228
const dist = findDistanceToWall();
231229
stateData.messages.push(`${dist}`);
232-
230+
233231
if (dist < moveDist + robot.radius) {
234-
stateData.message = "collided";
232+
stateData.message = 'collided';
235233
stateData.success = false;
236234
moveDist = dist - robot.radius + 1; // move only until the wall
237235
}
@@ -243,7 +241,7 @@ export function move_forward(moveDist: number): void {
243241

244242
robot.x = nextPoint.x;
245243
robot.y = nextPoint.y;
246-
stateData.moveCommands.push({type: "move", position: getPositionWithRotation()});
244+
stateData.moveCommands.push({type: 'move', position: getPositionWithRotation()});
247245

248246
logCoordinates();
249247
}
@@ -252,7 +250,7 @@ export function move_forward(moveDist: number): void {
252250
// add as a command later
253251
export function sensor(): boolean {
254252
const dist = findDistanceToWall();
255-
stateData.moveCommands.push({type: "sensor", position: getPositionWithRotation()})
253+
stateData.moveCommands.push({type: 'sensor', position: getPositionWithRotation()});
256254
if (dist <= 10 + robot.radius) {
257255
return true;
258256
}
@@ -363,7 +361,7 @@ function alrCollided() {
363361

364362
function getPositionWithRotation(): PointWithRotation {
365363
const angle = Math.atan2(-robot.dy, robot.dx);
366-
return {x: robot.x, y: robot.y, rotation: angle}
364+
return {x: robot.x, y: robot.y, rotation: angle};
367365
}
368366

369367
// debug

src/tabs/RobotMaze/canvas.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export default class Canvas extends React.Component<Props, State> {
130130
const currentCommand: Command = this.commands[this.commandIndex];
131131

132132
// checking for the 3 types of commands so far: move, rotate and sensor
133-
if (currentCommand.type == "move") {
133+
if (currentCommand.type == 'move') {
134134
const targetPoint = {x: currentCommand.position.x, y: currentCommand.position.y};
135135
const dx = targetPoint.x - this.xPos;
136136
const dy = targetPoint.y - this.yPos;
@@ -148,15 +148,14 @@ export default class Canvas extends React.Component<Props, State> {
148148
this.yPos = targetPoint.y;
149149

150150
// set target to the next point in the array
151-
this.commandIndex+= 1;
151+
this.commandIndex+= 1;
152152
}
153-
}
154-
else if (currentCommand.type == "rotateLeft" || currentCommand.type == "rotateRight") {
153+
} else if (currentCommand.type == 'rotateLeft' || currentCommand.type == 'rotateRight') {
155154
const targetRotation = currentCommand.position.rotation;
156-
if (currentCommand.type == "rotateLeft") {
157-
this.rotation += 0.1;
155+
if (currentCommand.type == 'rotateLeft') {
156+
this.rotation += 0.1;
158157
} else {
159-
this.rotation -= 0.1;
158+
this.rotation -= 0.1;
160159
}
161160

162161
if (Math.abs(this.rotation - targetRotation) <= 0.1) {
@@ -166,21 +165,21 @@ export default class Canvas extends React.Component<Props, State> {
166165
if (this.rotation > Math.PI) {
167166
this.rotation -= 2 * Math.PI;
168167
}
169-
168+
170169
if (this.rotation < -Math.PI) {
171170
this.rotation += 2 * Math.PI;
172171
}
173-
172+
174173
if (Math.abs(this.rotation - targetRotation) <= 0.1) {
175174
this.rotation = targetRotation;
176175
this.commandIndex+= 1;
177176
}
178177
}
179-
} else if (currentCommand.type === "sensor") {
178+
} else if (currentCommand.type === 'sensor') {
180179
this.isPaused = true;
181180
this.unpauseTIme = Date.now() + 500;
182181
}
183-
182+
184183
if (this.commandIndex >= this.commands.length) {
185184
this.stopAnimation();
186185
}
@@ -193,7 +192,7 @@ export default class Canvas extends React.Component<Props, State> {
193192
drawRobot(ctx: CanvasRenderingContext2D, x: number, y: number, rotation: number) {
194193
const centerX = x;
195194
const centerY = y;
196-
195+
197196
ctx.save();
198197

199198
// translates the origin of the canvas to the center of the robot, then rotate
@@ -208,8 +207,8 @@ export default class Canvas extends React.Component<Props, State> {
208207
ctx.fill(); // Fill the circle
209208
ctx.closePath();
210209

211-
ctx.strokeStyle = "white";
212-
ctx.lineWidth = 2;
210+
ctx.strokeStyle = 'white';
211+
ctx.lineWidth = 2;
213212
ctx.beginPath();
214213
ctx.moveTo(this.robotSize, 0);
215214
ctx.lineTo(0, 0);

0 commit comments

Comments
 (0)