Skip to content

Commit

Permalink
freehand drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
rnickles committed Oct 7, 2024
1 parent 386d77e commit 249b88f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions game/acceptUserInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export function acceptUserInput(engine, render, gameState) {
const mousePosition = event.mouse.position;
startX = mousePosition.x;
startY = mousePosition.y;
temporaryPlatform = new Platform(startX, startY, startX, startY, engine, 'gray', true);

// Check if an active slingshot is in the list of bodies under the mouse
activeSlingshot = onActiveSlingshot(mousePosition);
Expand Down Expand Up @@ -103,14 +102,20 @@ export function acceptUserInput(engine, render, gameState) {
// magnifierSize / magnifierZoom, magnifierSize / magnifierZoom,
// 0, 0, magnifierSize, magnifierSize);
});

let delta = 8;
Matter.Events.on(mouseConstraint, 'mousemove', function(event) {
if (showMagnifier) {
const mousePosition = event.mouse.position;
endX = mousePosition.x;
endY = mousePosition.y;
Matter.Composite.remove(engine.world, temporaryPlatform.bod);
temporaryPlatform = new Platform(startX, startY, endX, endY, engine, 'gray', true);
// Matter.Composite.remove(engine.world, temporaryPlatform.bod);

if (Math.abs(endX - startX) > delta || Math.abs(endY - startY) > delta ) {
createPlatform(startX, startY, endX, endY);
startX = endX;
startY = endY;
}

// Position the magnifier to the right of the cursor
// const offsetX = -(magnifierSize/2); // Offset distance from the cursor
// const offsetY = -(magnifierSize * 2);
Expand Down Expand Up @@ -139,8 +144,8 @@ export function acceptUserInput(engine, render, gameState) {
didRelease = true;
}
else {
Matter.Composite.remove(engine.world, temporaryPlatform.bod);
createPlatform(startX, startY, endX, endY);
// Matter.Composite.remove(engine.world, temporaryPlatform.bod);
// createPlatform(startX, startY, endX, endY);
}
// // Hide the magnifier when drawing ends
// magnifierCanvas.style.display = 'none';
Expand Down
2 changes: 1 addition & 1 deletion game/objects/ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Ball extends GameObject {
restitution: 0.5,
density: 0.1,
render: {
fillStyle: 'silver'
fillStyle: 'darkblue'
},
collisionFilter: {
category: CATEGORY_DEFAULT,
Expand Down

0 comments on commit 249b88f

Please sign in to comment.