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.lives = 5;
this.items = { this.items = {
key: false, keys: [],
repellant: false repellant: false
}; };

View File

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

View File

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

View File

@ -39,7 +39,7 @@ let level = {
type: "Chest", type: "Chest",
pos: { x: 4 * tileSize, y: 2 * tileSize }, pos: { x: 4 * tileSize, y: 2 * tileSize },
action: (player) => { 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.pos = {x:512,y:256};
player.refocus = true; player.refocus = true;
}, },
key: true key: "1-2_3"
} }
] ]
}; };

View File

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