fix bugs: connect everything
This commit is contained in:
parent
2debc1d5ae
commit
874f24e47f
BIN
public/assets/loop2.png
Normal file
BIN
public/assets/loop2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
|
@ -229,7 +229,7 @@ export class Cat {
|
||||||
let h = this.sprite.height;
|
let h = this.sprite.height;
|
||||||
|
|
||||||
rectMode(CENTER);
|
rectMode(CENTER);
|
||||||
rect(this.sprite.x, this.sprite.y, w, h);
|
// rect(this.sprite.x, this.sprite.y, w, h);
|
||||||
};
|
};
|
||||||
|
|
||||||
changeAni(key) {
|
changeAni(key) {
|
||||||
|
|
|
@ -3,10 +3,11 @@ import { ClickableArrow } from "./ClickableArrow";
|
||||||
import { colors } from "../utils/theme";
|
import { colors } from "../utils/theme";
|
||||||
|
|
||||||
export class ControlPanel {
|
export class ControlPanel {
|
||||||
constructor({ name, x, y, numBoxes }) {
|
constructor({ name, x, y, numBoxes, blockColor = null }) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
this.blockColor = blockColor;
|
||||||
this.numBoxes = numBoxes;
|
this.numBoxes = numBoxes;
|
||||||
this.boxWidth = 48;
|
this.boxWidth = 48;
|
||||||
this.boxHeight = 48;
|
this.boxHeight = 48;
|
||||||
|
|
|
@ -13,9 +13,6 @@ export class Flag {
|
||||||
this.size = 0;
|
this.size = 0;
|
||||||
this.locked = guarded ? true : false;
|
this.locked = guarded ? true : false;
|
||||||
|
|
||||||
this.unlockAni = false;
|
|
||||||
this.unlockProg = 1; // 1: locked, 0: unlocked
|
|
||||||
|
|
||||||
// Load the flag image
|
// Load the flag image
|
||||||
loadImage('assets/flag.png', (img) => {
|
loadImage('assets/flag.png', (img) => {
|
||||||
this.size = img.height;
|
this.size = img.height;
|
||||||
|
@ -68,6 +65,11 @@ export class Flag {
|
||||||
this.locked = mode;
|
this.locked = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restart() {
|
||||||
|
this.sprite.collider = 'none';
|
||||||
|
this.locked = true;
|
||||||
|
}
|
||||||
|
|
||||||
debug() {
|
debug() {
|
||||||
console.log(`Flag position: x=${this.x}, y=${this.y}`);
|
console.log(`Flag position: x=${this.x}, y=${this.y}`);
|
||||||
console.log(`Flag loaded: ${this.loaded}`);
|
console.log(`Flag loaded: ${this.loaded}`);
|
||||||
|
|
|
@ -64,6 +64,10 @@ export class Key {
|
||||||
return this.obtained;
|
return this.obtained;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restart() {
|
||||||
|
this.obtained = false;
|
||||||
|
}
|
||||||
|
|
||||||
debug() {
|
debug() {
|
||||||
console.log(`Flag position: x=${this.x}, y=${this.y}`);
|
console.log(`Flag position: x=${this.x}, y=${this.y}`);
|
||||||
console.log(`Flag loaded: ${this.isLoaded}`);
|
console.log(`Flag loaded: ${this.isLoaded}`);
|
||||||
|
|
|
@ -24,7 +24,7 @@ function setup(){
|
||||||
mgr.addScene(Level2);
|
mgr.addScene(Level2);
|
||||||
mgr.addScene(Level3);
|
mgr.addScene(Level3);
|
||||||
|
|
||||||
mgr.showScene(Level3);
|
mgr.showScene(StartScene);
|
||||||
};
|
};
|
||||||
|
|
||||||
function draw(){
|
function draw(){
|
||||||
|
|
|
@ -17,7 +17,6 @@ export default function Level3() {
|
||||||
const catSize = 155;
|
const catSize = 155;
|
||||||
const worldBlockSize = 125;
|
const worldBlockSize = 125;
|
||||||
const groundHeight = worldBlockSize;
|
const groundHeight = worldBlockSize;
|
||||||
// const worldHeight = windowHeight - groundHeight;
|
|
||||||
const maxIdx = {
|
const maxIdx = {
|
||||||
x: Math.ceil(windowWidth / worldBlockSize),
|
x: Math.ceil(windowWidth / worldBlockSize),
|
||||||
y: Math.floor(windowHeight / worldBlockSize)
|
y: Math.floor(windowHeight / worldBlockSize)
|
||||||
|
@ -42,9 +41,6 @@ export default function Level3() {
|
||||||
let steps;
|
let steps;
|
||||||
let loops;
|
let loops;
|
||||||
let keys;
|
let keys;
|
||||||
// let clickArrow;
|
|
||||||
|
|
||||||
// let clicked;
|
|
||||||
|
|
||||||
let levelFinished = false;
|
let levelFinished = false;
|
||||||
|
|
||||||
|
@ -54,16 +50,13 @@ export default function Level3() {
|
||||||
const buildingBlocks = [
|
const buildingBlocks = [
|
||||||
new ClickableArrow('up', false),
|
new ClickableArrow('up', false),
|
||||||
new ClickableArrow('right', false),
|
new ClickableArrow('right', false),
|
||||||
|
new ClickableArrow('left', false),
|
||||||
new ClickableArrow('loop', false),
|
new ClickableArrow('loop', false),
|
||||||
];
|
];
|
||||||
|
|
||||||
// // changed on user input
|
|
||||||
// let selectedSteps;
|
|
||||||
// let selectedBlock;
|
|
||||||
|
|
||||||
const slots = {
|
const slots = {
|
||||||
blocks: 3,
|
blocks: 4,
|
||||||
steps: 5,
|
steps: 6,
|
||||||
loops: 2,
|
loops: 2,
|
||||||
keys: 1,
|
keys: 1,
|
||||||
}
|
}
|
||||||
|
@ -101,27 +94,27 @@ export default function Level3() {
|
||||||
|
|
||||||
steps = new ControlPanel({
|
steps = new ControlPanel({
|
||||||
name: 'steps',
|
name: 'steps',
|
||||||
x: width / 32 * 7 + 48 * (slots.blocks + 1),
|
x: width / 32 * 7 + 48 * (slots.blocks + 1.5),
|
||||||
y: height / 32,
|
y: height / 32,
|
||||||
numBoxes: slots.steps,
|
numBoxes: slots.steps,
|
||||||
});
|
});
|
||||||
|
|
||||||
loops = new ControlPanel({
|
loops = new ControlPanel({
|
||||||
name: 'loop',
|
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,
|
y: height / 32,
|
||||||
numBoxes: slots.loops,
|
numBoxes: slots.loops,
|
||||||
});
|
});
|
||||||
|
|
||||||
keys = new ControlPanel({
|
keys = new ControlPanel({
|
||||||
name: 'key',
|
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,
|
y: height / 32,
|
||||||
numBoxes: slots.keys,
|
numBoxes: slots.keys,
|
||||||
});
|
});
|
||||||
|
|
||||||
flag = new Flag(12 * worldBlockSize, height - worldBlockSize * 4, catSize * 0.75, true);
|
flag = new Flag(11 * worldBlockSize, height - worldBlockSize * 4, catSize * 0.75, true);
|
||||||
key = new Key(10 * worldBlockSize, height - worldBlockSize * 4.3, catSize * 0.35);
|
key = new Key(13 * worldBlockSize, height - worldBlockSize * 4.3, catSize * 0.35);
|
||||||
|
|
||||||
for (let i = 0; i < width; i += worldBlockSize) {
|
for (let i = 0; i < width; i += worldBlockSize) {
|
||||||
let b = new Sprite(
|
let b = new Sprite(
|
||||||
|
@ -175,20 +168,7 @@ export default function Level3() {
|
||||||
_checkKeyObtained(cat, key, keys, flag);
|
_checkKeyObtained(cat, key, keys, flag);
|
||||||
if (key && !key.obtained) key.draw();
|
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) {
|
if (cat.sprite && flag.sprite) {
|
||||||
// Only finish if key is obtained
|
|
||||||
if (cat.sprite.overlaps(flag.sprite) && key && key.obtained) {
|
if (cat.sprite.overlaps(flag.sprite) && key && key.obtained) {
|
||||||
levelFinished = true;
|
levelFinished = true;
|
||||||
}
|
}
|
||||||
|
@ -274,7 +254,11 @@ export default function Level3() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.startGame = () => {
|
this.startGame = () => {
|
||||||
if (restart) cat.restart();
|
if (restart){
|
||||||
|
cat.restart();
|
||||||
|
flag.restart();
|
||||||
|
key.restart();
|
||||||
|
}
|
||||||
console.log(steps.contents);
|
console.log(steps.contents);
|
||||||
console.log(loops.contents);
|
console.log(loops.contents);
|
||||||
const flattenedSteps = _flattenSteps(steps.contents, loops.contents);
|
const flattenedSteps = _flattenSteps(steps.contents, loops.contents);
|
||||||
|
@ -314,9 +298,6 @@ function _flattenSteps(stepList, loopList) {
|
||||||
return acc;
|
return acc;
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
console.log(`flattened result`)
|
|
||||||
console.log(result);
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +309,6 @@ function _checkKeyObtained(cat, key, keys, flag) {
|
||||||
arrow.set('key');
|
arrow.set('key');
|
||||||
})
|
})
|
||||||
flag.setLocked(false);
|
flag.setLocked(false);
|
||||||
if (flag) flag.debug();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user