Skip to content

Commit

Permalink
issue #349, #376 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rlszabo committed Apr 19, 2023
1 parent ea7323d commit 3f9fc27
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ export function activate(context: vscode.ExtensionContext) {
updateExtensionPositionContext,
),
);

updateStatusBar();

const spec = PetSpecification.fromConfiguration();
Expand Down Expand Up @@ -365,6 +366,15 @@ export function activate(context: vscode.ExtensionContext) {
}),
);

context.subscriptions.push(
vscode.commands.registerCommand('vscode-pets.throw-with-mouse', () => {
const panel = getPetPanel();
if (panel !== undefined) {
panel.setThrowWithMouse(true);
}
}),
);

context.subscriptions.push(
vscode.commands.registerCommand('vscode-pets.delete-pet', async () => {
const panel = getPetPanel();
Expand Down
5 changes: 3 additions & 2 deletions src/panel/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ export function petPanelApp(
if (canvas) {
canvas.style.display = 'block';
}
ballState = new BallState(100, 100, 4, 5);
/* spawn with randomize */
ballState = new BallState(0, 0, 0, 0, true);
}

function dynamicThrowOn() {
Expand Down Expand Up @@ -430,6 +431,7 @@ export function petPanelApp(
canvas.style.display = 'none';
}
}

function throwBall() {
if (!ballState.paused) {
requestAnimationFrame(throwBall);
Expand Down Expand Up @@ -461,7 +463,6 @@ export function petPanelApp(
}

ballState.vy += gravity;

ballState.cx += ballState.vx;
ballState.cy += ballState.vy;
drawBall();
Expand Down
44 changes: 39 additions & 5 deletions src/panel/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,47 @@ export class BallState {
vy: number;
paused: boolean;

constructor(cx: number, cy: number, vx: number, vy: number) {
this.cx = cx;
this.cy = cy;
this.vx = vx;
this.vy = vy;
constructor(
cx: number,
cy: number,
vx: number,
vy: number,
randomize?: boolean,
) {
if (randomize !== undefined && randomize === true) {
const rVals = this.randomizeBallState();
this.cx = rVals[0];
this.cy = rVals[1];
this.vx = rVals[2];
this.vy = rVals[3];
} else {
this.cx = cx;
this.cy = cy;
this.vx = vx;
this.vy = vy;
}
this.paused = false;
}

private randomizeBallState(): Array<number> {
/* velocity */
const randVx: Array<number> = [
//avoids values close to 0
-1 * (Math.floor(Math.random() * 12) + 3), //left
Math.floor(Math.random() * 12) + 3, // right
];
const randVy: number = Math.floor(Math.random() * 20 - 10);
/* position */
const randX: number = Math.floor(
Math.random() * (window.innerWidth * 0.8) + 10,
);
const randY: number =
Math.floor(Math.random() * (window.innerHeight * 0.6)) + 30;

/* flip a coin to throw left or right */
const coin: number = Math.floor(Math.random() * 2);
return [randX, randY, randVx[coin], randVy];
}
}

export function isStateAboveGround(state: States): boolean {
Expand Down

0 comments on commit 3f9fc27

Please sign in to comment.