add oxygen meter
This commit is contained in:
+38
-2
@@ -185,6 +185,7 @@ function addAmmo(p) {
|
||||
}
|
||||
}
|
||||
|
||||
// * Check if Player is Swimming or Diving
|
||||
function checkLiquids() {
|
||||
var n, max, l
|
||||
for (n = 0, max = liquids.length; n < max; n++) {
|
||||
@@ -197,6 +198,38 @@ function checkLiquids() {
|
||||
} else {
|
||||
player.swimming = false
|
||||
}
|
||||
if (
|
||||
overlap(
|
||||
player.x,
|
||||
player.y - player.height,
|
||||
TILE,
|
||||
TILE,
|
||||
l.x,
|
||||
l.y,
|
||||
l.width,
|
||||
l.height
|
||||
)
|
||||
) {
|
||||
player.diving = true
|
||||
reduceOxygen(4)
|
||||
} else {
|
||||
player.diving = false
|
||||
replenishOxygen(16)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// * Reduce & Replenish Oxygen Functions
|
||||
function reduceOxygen(rate) {
|
||||
if (player.diving && globalObject.oxygen >= 0) {
|
||||
globalObject.oxygen -= rate / 100
|
||||
} else if (player.vul) {
|
||||
reduceHitpoints(player, 1, 2000)
|
||||
}
|
||||
}
|
||||
function replenishOxygen(rate) {
|
||||
if (globalObject.oxygen <= globalObject.maxOxygen) {
|
||||
globalObject.oxygen += rate / 100
|
||||
}
|
||||
}
|
||||
|
||||
@@ -252,7 +285,9 @@ function killMonster(monster) {
|
||||
}
|
||||
|
||||
// * Take Damage Function
|
||||
function reduceHitpoints(entity, damage) {
|
||||
function reduceHitpoints(entity, damage, timeout) {
|
||||
const milliceconds = timeout || 1500
|
||||
|
||||
if (
|
||||
entity.player ? globalObject.hitpoints > 1 : entity.currentHitpoints > 1
|
||||
) {
|
||||
@@ -265,7 +300,7 @@ function reduceHitpoints(entity, damage) {
|
||||
setTimeout(() => {
|
||||
entity.vul = true
|
||||
entity.hurt = false
|
||||
}, 1500)
|
||||
}, milliceconds)
|
||||
} else killEntity(entity)
|
||||
}
|
||||
|
||||
@@ -285,6 +320,7 @@ function killPlayer(player) {
|
||||
player.y = player.start.y
|
||||
player.dx = player.dy = 0
|
||||
globalObject.hitpoints = player.maxHitpoints
|
||||
globalObject.oxygen = globalObject.maxOxygen
|
||||
globalObject.lifes--
|
||||
console.log('log globalObject: ', globalObject.lifes)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user