Skip to content

Commit

Permalink
Merge pull request #307 from Luke-G-Cordova/master
Browse files Browse the repository at this point in the history
Added pet interaction, Dynamic throwing!
  • Loading branch information
tonybaloney authored Nov 20, 2022
2 parents 1445f69 + 8bd5049 commit c5ea3d1
Show file tree
Hide file tree
Showing 6 changed files with 4,225 additions and 3,679 deletions.
75 changes: 74 additions & 1 deletion media/main-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,65 @@ function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType, s
}
ballState = new states_1.BallState(100, 100, 4, 5);
}
function dynamicThrowOn() {
let startMouseX;
let startMouseY;
let endMouseX;
let endMouseY;
window.onmousedown = (e) => {
if (ballState) {
ballState.paused = true;
}
if (canvas) {
canvas.style.display = 'block';
}
endMouseX = e.clientX;
endMouseY = e.clientY;
startMouseX = e.clientX;
startMouseY = e.clientY;
ballState = new states_1.BallState(e.clientX, e.clientY, 0, 0);
exports.allPets.pets.forEach((petEl) => {
if (petEl.pet.canChase) {
petEl.pet.chase(ballState, canvas);
}
});
ballState.paused = true;
drawBall();
window.onmousemove = (ev) => {
ev.preventDefault();
if (ballState) {
ballState.paused = true;
}
startMouseX = endMouseX;
startMouseY = endMouseY;
endMouseX = ev.clientX;
endMouseY = ev.clientY;
ballState = new states_1.BallState(ev.clientX, ev.clientY, 0, 0);
drawBall();
};
window.onmouseup = (ev) => {
ev.preventDefault();
window.onmouseup = null;
window.onmousemove = null;
ballState = new states_1.BallState(endMouseX, endMouseY, endMouseX - startMouseX, endMouseY - startMouseY);
exports.allPets.pets.forEach((petEl) => {
if (petEl.pet.canChase) {
petEl.pet.chase(ballState, canvas);
}
});
throwBall();
};
};
}
function dynamicThrowOff() {
window.onmousedown = null;
if (ballState) {
ballState.paused = true;
}
if (canvas) {
canvas.style.display = 'none';
}
}
function throwBall() {
if (!ballState.paused) {
requestAnimationFrame(throwBall);
Expand All @@ -579,7 +638,6 @@ function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType, s
return;
}
then = now - (elapsed % interval);
ctx.clearRect(0, 0, canvas.width, canvas.height);
if (ballState.cx + ballRadius >= canvas.width) {
ballState.vx = -ballState.vx * damping;
ballState.cx = canvas.width - ballRadius;
Expand All @@ -601,6 +659,10 @@ function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType, s
ballState.vy += gravity;
ballState.cx += ballState.vx;
ballState.cy += ballState.vy;
drawBall();
}
function drawBall() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.arc(ballState.cx, ballState.cy, ballRadius, 0, 2 * Math.PI, false);
ctx.fillStyle = '#2ed851';
Expand All @@ -620,10 +682,21 @@ function petPanelApp(basePetUri, theme, themeKind, petColor, petSize, petType, s
recoverState(basePetUri, petSize, floor, stateApi);
}
initCanvas();
let dynamicThrowToggle = false;
// Handle messages sent from the extension to the webview
window.addEventListener('message', (event) => {
const message = event.data; // The json data that the extension sent
switch (message.command) {
case 'throw-with-mouse':
if (dynamicThrowToggle) {
dynamicThrowOff();
dynamicThrowToggle = false;
}
else {
dynamicThrowOn();
dynamicThrowToggle = true;
}
break;
case 'throw-ball':
resetBall();
throwBall();
Expand Down
4 changes: 4 additions & 0 deletions media/pets.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
--input-margin-horizontal: 0;
}

*{
user-select: none;
}

body {
padding: 0 var(--container-paddding);
color: var(--vscode-foreground);
Expand Down
Loading

0 comments on commit c5ea3d1

Please sign in to comment.