From 874f24e47f2953f10bd9b91716559fdb0406d519 Mon Sep 17 00:00:00 2001 From: nadiarvi Date: Sat, 10 May 2025 18:01:00 +0900 Subject: [PATCH] fix bugs: connect everything --- public/assets/loop2.png | Bin 0 -> 2524 bytes src/components/Cat.js | 2 +- src/components/ControlPanel.js | 3 ++- src/components/Flag.js | 8 +++--- src/components/Key.js | 4 +++ src/main.js | 2 +- src/scenes/lvl3.js | 46 ++++++++++----------------------- 7 files changed, 26 insertions(+), 39 deletions(-) create mode 100644 public/assets/loop2.png diff --git a/public/assets/loop2.png b/public/assets/loop2.png new file mode 100644 index 0000000000000000000000000000000000000000..dfc592d32f31edaeb624e4222791e394e3165489 GIT binary patch literal 2524 zcmeAS@N?(olHy`uVBq!ia0y~yU;;9k7&zE~)R&4Yzkn2Hfk$L90|U1(2s1Lwnj--e zWGoJHcVbv~PUa<$!;&U>cv7h@-A}dfsp{I*uNCo5DTaJY?;UW$fuTNrNX*zU3 zK!i<*$=ckR+Ce5^-WT*m)tEjtG|Es>icW;d(W`Rq;2P8 z$T{-YMz8qcIyQzAf(#4-Dhvz?9t;c)6Brm86c`y89D%NFVgWjUlYxOlXn+;yw%=TP zcxT`D&p$phe7HOJ*|p`D3$5oI!x=>8n|Y7#%s5@h@Wb)n-)HNJALczj1oTVn zpWr?7kEb#uC~q@}UOPYmpT`#WGV@!xaeQ9-<#qi0oB!J|7&0{&@7WWbR%tE0?VODN z@#Bmg8<_@Sa=;nhgDK69I&$!o9|I5<7tS)U{Iz^~yZ%*Ft?y@M z3>)CO1l^k`6xVS)4OHG@JHi6@BiBmbq007f?5)~n;C)iI5UHE op?$x&ef-_Q+S)))Aur_9ruv=qDr}w$Y>Y8@y85}Sb4q9e0N>Y+U;qFB literal 0 HcmV?d00001 diff --git a/src/components/Cat.js b/src/components/Cat.js index 5759056..041b589 100644 --- a/src/components/Cat.js +++ b/src/components/Cat.js @@ -229,7 +229,7 @@ export class Cat { let h = this.sprite.height; rectMode(CENTER); - rect(this.sprite.x, this.sprite.y, w, h); + // rect(this.sprite.x, this.sprite.y, w, h); }; changeAni(key) { diff --git a/src/components/ControlPanel.js b/src/components/ControlPanel.js index f5f1bbc..764c52e 100644 --- a/src/components/ControlPanel.js +++ b/src/components/ControlPanel.js @@ -3,10 +3,11 @@ import { ClickableArrow } from "./ClickableArrow"; import { colors } from "../utils/theme"; export class ControlPanel { - constructor({ name, x, y, numBoxes }) { + constructor({ name, x, y, numBoxes, blockColor = null }) { this.name = name; this.x = x; this.y = y; + this.blockColor = blockColor; this.numBoxes = numBoxes; this.boxWidth = 48; this.boxHeight = 48; diff --git a/src/components/Flag.js b/src/components/Flag.js index 978a4d8..118552a 100644 --- a/src/components/Flag.js +++ b/src/components/Flag.js @@ -13,9 +13,6 @@ export class Flag { this.size = 0; this.locked = guarded ? true : false; - this.unlockAni = false; - this.unlockProg = 1; // 1: locked, 0: unlocked - // Load the flag image loadImage('assets/flag.png', (img) => { this.size = img.height; @@ -68,6 +65,11 @@ export class Flag { this.locked = mode; } + restart() { + this.sprite.collider = 'none'; + this.locked = true; + } + debug() { console.log(`Flag position: x=${this.x}, y=${this.y}`); console.log(`Flag loaded: ${this.loaded}`); diff --git a/src/components/Key.js b/src/components/Key.js index d663e0e..1b88f70 100644 --- a/src/components/Key.js +++ b/src/components/Key.js @@ -64,6 +64,10 @@ export class Key { return this.obtained; } + restart() { + this.obtained = false; + } + debug() { console.log(`Flag position: x=${this.x}, y=${this.y}`); console.log(`Flag loaded: ${this.isLoaded}`); diff --git a/src/main.js b/src/main.js index 133f97a..23df4eb 100644 --- a/src/main.js +++ b/src/main.js @@ -24,7 +24,7 @@ function setup(){ mgr.addScene(Level2); mgr.addScene(Level3); - mgr.showScene(Level3); + mgr.showScene(StartScene); }; function draw(){ diff --git a/src/scenes/lvl3.js b/src/scenes/lvl3.js index e1ba599..57ef532 100644 --- a/src/scenes/lvl3.js +++ b/src/scenes/lvl3.js @@ -17,7 +17,6 @@ export default function Level3() { const catSize = 155; const worldBlockSize = 125; const groundHeight = worldBlockSize; - // const worldHeight = windowHeight - groundHeight; const maxIdx = { x: Math.ceil(windowWidth / worldBlockSize), y: Math.floor(windowHeight / worldBlockSize) @@ -42,9 +41,6 @@ export default function Level3() { let steps; let loops; let keys; - // let clickArrow; - - // let clicked; let levelFinished = false; @@ -54,16 +50,13 @@ export default function Level3() { const buildingBlocks = [ new ClickableArrow('up', false), new ClickableArrow('right', false), + new ClickableArrow('left', false), new ClickableArrow('loop', false), ]; - - // // changed on user input - // let selectedSteps; - // let selectedBlock; const slots = { - blocks: 3, - steps: 5, + blocks: 4, + steps: 6, loops: 2, keys: 1, } @@ -101,27 +94,27 @@ export default function Level3() { steps = new ControlPanel({ name: 'steps', - x: width / 32 * 7 + 48 * (slots.blocks + 1), + x: width / 32 * 7 + 48 * (slots.blocks + 1.5), y: height / 32, numBoxes: slots.steps, }); loops = new ControlPanel({ name: 'loop', - x: width / 32 * 7 + 48 * (slots.blocks + slots.steps + 2.5), + x: width / 32 * 7 + 48 * (slots.blocks + slots.steps + 3.25), y: height / 32, numBoxes: slots.loops, }); keys = new ControlPanel({ name: 'key', - x: width / 32 * 7 + 48 * (slots.blocks + slots.steps + slots.loops + 3.5), + x: width / 32 * 7 + 48 * (slots.blocks + slots.steps + slots.loops + 4.25), y: height / 32, numBoxes: slots.keys, }); - flag = new Flag(12 * worldBlockSize, height - worldBlockSize * 4, catSize * 0.75, true); - key = new Key(10 * worldBlockSize, height - worldBlockSize * 4.3, catSize * 0.35); + flag = new Flag(11 * worldBlockSize, height - worldBlockSize * 4, catSize * 0.75, true); + key = new Key(13 * worldBlockSize, height - worldBlockSize * 4.3, catSize * 0.35); for (let i = 0; i < width; i += worldBlockSize) { let b = new Sprite( @@ -175,20 +168,7 @@ export default function Level3() { _checkKeyObtained(cat, key, keys, flag); if (key && !key.obtained) key.draw(); - // if (cat.sprite && flag.sprite) { - // if (key && key.getObtain()) { - // flag.setColliderMode('none'); - - // if (cat.sprite.overlaps(flag.sprite)) { - // levelFinished = true; - // }; - // } else { - // flag.setColliderMode('static'); - // } - // }; - if (cat.sprite && flag.sprite) { - // Only finish if key is obtained if (cat.sprite.overlaps(flag.sprite) && key && key.obtained) { levelFinished = true; } @@ -274,7 +254,11 @@ export default function Level3() { }; this.startGame = () => { - if (restart) cat.restart(); + if (restart){ + cat.restart(); + flag.restart(); + key.restart(); + } console.log(steps.contents); console.log(loops.contents); const flattenedSteps = _flattenSteps(steps.contents, loops.contents); @@ -314,9 +298,6 @@ function _flattenSteps(stepList, loopList) { return acc; }, []) - console.log(`flattened result`) - console.log(result); - return result; } @@ -328,7 +309,6 @@ function _checkKeyObtained(cat, key, keys, flag) { arrow.set('key'); }) flag.setLocked(false); - if (flag) flag.debug(); } }