Skip to content

Commit

Permalink
bug fix + minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
vuonghy2442 committed Apr 3, 2024
1 parent dc10ddc commit a71f201
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ function getCard(rank, suit) {
return cardArray[cardId(rank, suit)];
}

const THRES = 0.06;
const THRES = 0.1;
const THRES_2 = THRES * THRES;

var snap_audio = new Audio('sound/snap.mp3');
Expand Down Expand Up @@ -424,6 +424,7 @@ function initGame() {
c.turnUp();
c.draggable = false;
c.createDOM(x * 100, y * 100);
cardArray[cardId(card.rank - 1, card.suit)].moveToFront();
}

if (card.rank > 0) {
Expand Down Expand Up @@ -454,9 +455,6 @@ function initGame() {
})

function moveCard(event, card) {
if (!card.isDraggable()) return;
snap_audio.play();

const origin = game.find_origin(card);

let moving_cards = [card];
Expand All @@ -467,6 +465,9 @@ function initGame() {
moving_cards = p.slice(id);
}

if (moving_cards.some((c) => !c.isDraggable())) return;
snap_audio.play();

moving_cards.forEach((c) => c.moveToFront());


Expand Down Expand Up @@ -509,15 +510,15 @@ function initGame() {
let [u, v] = curPilePos[p];
const [dx, dy] = [x - u, y - v];
let dis2 = distance2(x, y, u, v);
let d = Math.max(Math.sqrt(dis2) / THRES - 1, 0);
let d = Math.max(Math.sqrt(dis2) / THRES - 0.5, 0);

if (d == 0 && snapped < 0) {
if (d < 0.5 && snapped < 0) {
snapped = p;
} else if (d > 0 && snapped >= 0) {
} else if (d > 0.5 && snapped >= 0) {
snapped = -1;
}

const force = d > 0 ? 0 : 1;
const force = d > 0 ? Math.exp(-d) : 1;
x -= dx * force;
y -= dy * force;
}
Expand Down

0 comments on commit a71f201

Please sign in to comment.