Skip to content

Commit

Permalink
feat: Add stop motion when rope is cut for the first time
Browse files Browse the repository at this point in the history
  • Loading branch information
johnedvard committed Sep 12, 2022
1 parent f77b0ff commit 1feb6be
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/Level.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { BounceBoard } from './BounceBoard';
import { Brick } from './Brick';
import { HEART_PICKUP, LEVEL_COMPLETE, PLAYER_DIED } from './gameEvents';
import {
CUT_ROPE,
HEART_PICKUP,
LEVEL_COMPLETE,
PLAYER_DIED,
} from './gameEvents';
import { initGameHints } from './gameHints';
import { Goal } from './Goal';
import { Heart } from './Heart';
Expand All @@ -19,9 +24,13 @@ export class Level {
bricks = [];
bounceBoards = [];
isLevelLoaded = false;
isFirstRopeCut = false;
isStopMotion = false;
levelId;
levelData;
capturedHearts = [];
stopMotionTime = 10;
stopMotionEllapsed = 0;
constructor({ game, levelId, levelData }) {
this.levelId = levelId;
this.levelData = levelData;
Expand Down Expand Up @@ -98,7 +107,16 @@ export class Level {

update() {
if (!this.isLevelLoaded) return;

if (this.isStopMotion) {
this.stopMotionEllapsed += 1;
if (this.stopMotionEllapsed >= this.stopMotionTime) {
this.isStopMotion = false;
}
return;
}
this.checkCollisions();

this.player.update();
this.saws.forEach((saw) => {
saw.update();
Expand Down Expand Up @@ -181,15 +199,34 @@ export class Level {
on(PLAYER_DIED, this.onPlayerDied);
on(HEART_PICKUP, this.onHeartPickup);
on(LEVEL_COMPLETE, this.onLevelComplete);
on(CUT_ROPE, this.onCutRope);
}
onCutRope = ({ rope }) => {
if (this.isFirstRopeCut) return;
this.isStopMotion = true;
this.isFirstRopeCut = true;
this.flashScreen();
};
onLevelComplete = () => {
this.storeCapturedHearts();
};
onHeartPickup = ({ heart }) => {
this.capturedHearts.push(heart);
};
flashScreen() {
const canvasEl = document.getElementById('c');
canvasEl.classList.add('flash');

setTimeout(() => {
requestAnimationFrame(() => {
canvasEl.classList.remove('flash');
});
}, 50);
}
onPlayerDied = ({}) => {
playDead();
this.isFirstRopeCut = false;
this.stopMotionEllapsed = 0;
this.player.respawnPlayer();
this.resetHearts();
this.resertSaws();
Expand Down
3 changes: 3 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,6 @@ button:hover img {
.hide {
display: none !important; /* XXX Override any other display settings on the element */
}
.flash {
background-color: var(--bgc2);
}

0 comments on commit 1feb6be

Please sign in to comment.