Added more keys and doors

This commit is contained in:
Arne van Iterson 2020-04-08 16:59:49 +02:00
parent 4f3468ed96
commit 20ca882cb6
5 changed files with 30 additions and 10 deletions

View File

@ -39,7 +39,7 @@ class Player extends TileSprite {
this.lives = 5;
this.items = {
key: false,
keys: [],
repellant: false
};

View File

@ -16,7 +16,7 @@ class Portal extends TileSprite {
this.key = key;
switch (type) {
case "Door":
case "Door_n":
this.frame = { x: 1, y: 7 };
this.hitBox = {
x: 1,
@ -25,6 +25,15 @@ class Portal extends TileSprite {
h: 45
};
break;
case "Door_s":
this.frame = { x: 2, y: 9 };
this.hitBox = {
x: 0,
y: -13,
w: 32,
h: 45
};
break;
case "Ladder":
this.frame = { x: 2, y: 7 };
this.hitBox = {
@ -49,11 +58,21 @@ class Portal extends TileSprite {
update(dt) {
super.update(dt);
if (entity.hit(this, this.player) && this.keys.action) {
if (this.key) {
if (this.player.items.key) {
this.action();
this.player.items.key = false;
if (this.key != "") {
if (this.player.items.keys.length > 0) {
for (let index = 0; index < this.player.items.keys.length; index++) {
const element = this.player.items.keys[index];
if (element == this.key) {
this.action();
this.player.items.key = false;
delete this.player.items.keys[index];
} else {
// Not the correct key
console.log("correct keyn't");
}
}
} else {
// No keys at all
console.log("keyn't");
}
} else {

View File

@ -55,6 +55,7 @@ game.run(() => {
if (mouseAim.isDown) {
console.log("cliccccccccccc");
console.log(player.items);
console.log(level);
}
// Switch to another level

View File

@ -39,7 +39,7 @@ let level = {
type: "Chest",
pos: { x: 4 * tileSize, y: 2 * tileSize },
action: (player) => {
player.items.key = true;
player.items.keys.push("1-2_1");
}
},
{
@ -50,7 +50,7 @@ let level = {
player.pos = {x:512,y:256};
player.refocus = true;
},
key: true
key: "1-2_3"
}
]
};

View File

@ -39,7 +39,7 @@ let level = {
type: "Chest",
pos: { x: 4 * tileSize, y: 2 * tileSize },
action: (player) => {
player.items.key = true;
player.items.keys.push("1-1_1");
}
},
{
@ -49,7 +49,7 @@ let level = {
action: (player, level) => {
level.switch = { module: "./src/levels/1-1 copy.js", pos: 0 };
},
key: true
key: "1-1_1"
}
]
};