"death", and overlays, and bmg fix

This commit is contained in:
rsninja722 2020-04-20 13:04:54 -04:00
parent 31dd77c3f8
commit 35ce95cc88
16 changed files with 134 additions and 65 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 83 B

After

Width:  |  Height:  |  Size: 163 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 B

After

Width:  |  Height:  |  Size: 396 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 B

After

Width:  |  Height:  |  Size: 122 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 159 B

After

Width:  |  Height:  |  Size: 152 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 176 B

After

Width:  |  Height:  |  Size: 228 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 202 B

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 B

View File

@ -20,8 +20,60 @@ function drawPlayingUI() {
//Respiration Monitor //Respiration Monitor
respiratoryUI(cw / 8 * 5, ch / 8 * 7 - 8 + playingUIOffsets.breath, cw / 16, ch / 8); respiratoryUI(cw / 8 * 5, ch / 8 * 7 - 8 + playingUIOffsets.breath, cw / 16, ch / 8);
//Blink eye and overlay //Blink eye
blinkUI(); blinkUI();
switch(tutState) {
case tutorialStates.getCereal:
text("Objective: eat breakfast",10,ch-30,"black",2);
break;
case tutorialStates.getMail:
text("Objective: bring in the mail",10,ch-30,"black",2);
break;
case tutorialStates.goToBed:
text("Objective: go back to bed",10,ch-30,"black",2);
break;
}
var alpha;
// dry overlay
if (eyeDryness > constants.lifeFuncs.blink.dryTime) {
alpha = (eyeDryness - constants.lifeFuncs.blink.dryTime) / 350;
curCtx.globalAlpha = alpha;
img(sprites.blinkOverlay, cw / 2, ch / 2);
}
// blue overlay
switch (currentBreathMode) {
case breathMode.inhale:
if (fullBreathTimer >= 200) {
alpha = (fullBreathTimer-200) / 200;
curCtx.globalAlpha = clamp(alpha,0,1);
img(sprites.breathOverlay, cw / 2, ch / 2);
}
break;
case breathMode.exhale:
if (noBreathTimer >= 200) {
alpha = (noBreathTimer-200) / 200;
curCtx.globalAlpha = clamp(alpha,0,1);
img(sprites.breathOverlay, cw / 2, ch / 2);
}
break;
}
if(pressure > 80) {
alpha = (pressure-80) / 20;
curCtx.globalAlpha = clamp(alpha,0,1);
img(sprites.beatOverlay, cw / 2, ch / 2);
}
if( pressure < 25 ) {
alpha = (25-pressure) / 25;
curCtx.globalAlpha = clamp(alpha,0,1);
img(sprites.beatOverlay, cw / 2, ch / 2);
}
curCtx.globalAlpha = 1;
} }
//UI for pause screen //UI for pause screen
@ -164,13 +216,5 @@ function blinkUI() {
var alpha = clamp(eyeDryness / constants.lifeFuncs.blink.dryTime, 0, 1); var alpha = clamp(eyeDryness / constants.lifeFuncs.blink.dryTime, 0, 1);
curCtx.globalAlpha = alpha; curCtx.globalAlpha = alpha;
img(sprites.eyeDry, cw - 350, ch - 40 + playingUIOffsets.blink, 0, 2, 2); img(sprites.eyeDry, cw - 350, ch - 40 + playingUIOffsets.blink, 0, 2, 2);
// dry overlay
if (eyeDryness > constants.lifeFuncs.blink.dryTime) {
alpha = (eyeDryness - constants.lifeFuncs.blink.dryTime) / 350;
curCtx.globalAlpha = alpha;
img(sprites.blinkOverlay, cw / 2, ch / 2);
}
curCtx.globalAlpha = 1; curCtx.globalAlpha = 1;
} }

View File

@ -9,6 +9,8 @@ images = [
"heartCover.png", "heartCover.png",
"heartBack.png", "heartBack.png",
"blinkOverlay.png", "blinkOverlay.png",
"breathOverlay.png",
"beatOverlay.png",
"eye.png", "eye.png",
"eyeDry.png", "eyeDry.png",
"tutSelect0.png", "tutSelect0.png",
@ -23,6 +25,7 @@ images = [
"boxNoOutline.png", "boxNoOutline.png",
"playerBody.png", "playerBody.png",
"playerLeg.png", "playerLeg.png",
"playerLegActive.png",
"playerArm.png", "playerArm.png",
"playerHead.png", "playerHead.png",
"playerFoot.png", "playerFoot.png",

View File

@ -19,14 +19,16 @@ let justBlinked = false;
function updateLife() { function updateLife() {
if (playingUIOffsets.breath === 0) { if (playingUIOffsets.breath === 0) {
if (keyDown[k.x]) { if (keyPress[k.x]) {
if (breath === 0) { if (breath === 0) {
currentBreathMode = breathMode.inhale; currentBreathMode = breathMode.inhale;
soundAssets.inhale.play(); soundAssets.inhale.play();
} } else if (breath === constants.lifeFuncs.breath.fullBreath) {
else if (breath === constants.lifeFuncs.breath.fullBreath) {
currentBreathMode = breathMode.exhale; currentBreathMode = breathMode.exhale;
soundAssets.exhale.play(); soundAssets.exhale.play();
} else {
player.stuckTime = 30;
soundAssets.cough.play();
} }
if(Date.now() - keyPromptTime > 3000) { if(Date.now() - keyPromptTime > 3000) {
--keyPrompts.breath; --keyPrompts.breath;
@ -53,6 +55,7 @@ function updateLife() {
pressure -= 0.1; pressure -= 0.1;
if (pressure <= 0) { if (pressure <= 0) {
pressure = 0; pressure = 0;
player.die();
} }
} }
@ -75,10 +78,13 @@ function breathe() {
if (breath >= constants.lifeFuncs.breath.fullBreath) { if (breath >= constants.lifeFuncs.breath.fullBreath) {
breath = constants.lifeFuncs.breath.fullBreath; breath = constants.lifeFuncs.breath.fullBreath;
fullBreathTimer++; fullBreathTimer++;
if (fullBreathTimer >= 600) { if (fullBreathTimer >= 300) {
//cough and lose breath or something //cough and lose breath or something
handleCough(); handleCough();
} }
if (fullBreathTimer >= 400) {
player.die();
}
} else { } else {
fullBreathTimer = 0; fullBreathTimer = 0;
} }
@ -92,6 +98,9 @@ function breathe() {
//cough and lose breath or something //cough and lose breath or something
handleCough(); handleCough();
} }
if (noBreathTimer >= 400) {
player.die();
}
} else { } else {
noBreathTimer = 0; noBreathTimer = 0;
} }
@ -124,6 +133,7 @@ function heartbeat() {
pressure += 10; pressure += 10;
if (pressure >= 100) { if (pressure >= 100) {
pressure = 100; pressure = 100;
player.die();
} }
heartBeat = true; heartBeat = true;

View File

@ -19,6 +19,7 @@ class Player {
this.hover = { active: false, leg: "R" }; this.hover = { active: false, leg: "R" };
this.holdingBox = false; this.holdingBox = false;
this.armVel = 1; this.armVel = 1;
this.stuckTime = 0;
} }
} }
@ -36,11 +37,18 @@ Player.prototype.getLockedLeg = function(){
return this.rightLeg; return this.rightLeg;
} }
Player.prototype.die = function() {
console.warn("player is big ded, rip");
}
Player.prototype.update = function() { Player.prototype.update = function() {
var curLeg = this.getActiveLeg(); var curLeg = this.getActiveLeg();
// select if(this.stuckTime > 0) {
if (this.shouldMoveLeg) { --this.stuckTime;
}
// deselect
if (this.shouldMoveLeg && this.stuckTime === 0) {
this.moveLeg(); this.moveLeg();
if(mousePress[0] && collidingWithWorld({x: curLeg.x2, y: curLeg.y2, w:8, h:8})) { if(mousePress[0] && collidingWithWorld({x: curLeg.x2, y: curLeg.y2, w:8, h:8})) {
@ -54,7 +62,7 @@ Player.prototype.update = function() {
// Play the footstep sound // Play the footstep sound
playRandomFootstep(); playRandomFootstep();
} }
// deselect // select
} else { } else {
var targetPos = mousePosition(); var targetPos = mousePosition();
@ -88,18 +96,18 @@ Player.prototype.update = function() {
} }
// god mode // god mode
if(keyDown[k.w]) { // if(keyDown[k.w]) {
this.y-=5; // this.y-=5;
} // }
if(keyDown[k.s]) { // if(keyDown[k.s]) {
this.y+=5; // this.y+=5;
} // }
if(keyDown[k.a]) { // if(keyDown[k.a]) {
this.x-=5; // this.x-=5;
} // }
if(keyDown[k.d]) { // if(keyDown[k.d]) {
this.x+=5; // this.x+=5;
} // }
var halfPI = pi/2; var halfPI = pi/2;
if(this.leftArm.angle > halfPI) { if(this.leftArm.angle > halfPI) {
@ -289,56 +297,51 @@ Player.prototype.draw = function() {
// rect(this.x, this.y, this.w, this.h, "green"); // rect(this.x, this.y, this.w, this.h, "green");
img(sprites.playerBody,this.x,this.y,0,4,4); img(sprites.playerBody,this.x,this.y,0,4,4);
this.leftArm.draw(); img(sprites.playerHead,this.head.x + Math.cos(this.head.angle) * 20,this.head.y + Math.sin(this.head.angle) * 20,this.head.angle,4,4);
if(this.stuckTime) {
img(sprites.playerArm,this.x,this.y-50,2,4,4);
} else {
this.leftArm.draw();
}
this.rightArm.draw(); this.rightArm.draw();
if(this.holdingBox) { if(this.holdingBox) {
img(sprites.boxNoOutline,this.leftArm.x2 - Math.cos(this.leftArm.angle)*15,this.leftArm.y2- Math.sin(this.leftArm.angle)*15,this.leftArm.angle,4,4); img(sprites.boxNoOutline,this.leftArm.x2 - Math.cos(this.leftArm.angle)*15,this.leftArm.y2- Math.sin(this.leftArm.angle)*15,this.leftArm.angle,4,4);
} }
// boxNoOutline
if(this.hover.active) { if(this.hover.active) {
if(this.hover.leg === "R") { if(this.hover.leg === "R") {
curCtx.shadowBlur = 10; img(sprites.playerLeg,(this.leftLeg.x+this.leftLeg.x2)/2,(this.leftLeg.y+this.leftLeg.y2)/2,this.leftLeg.angle+pi/2,4,4);
curCtx.shadowColor = "yellow"; img(sprites.playerLegActive,(this.rightLeg.x+this.rightLeg.x2)/2,(this.rightLeg.y+this.rightLeg.y2)/2,this.rightLeg.angle+pi/2,4,4);
curCtx.lineWidth = 3;
this.rightLeg.draw();
curCtx.lineWidth = 1;
curCtx.shadowBlur = 0;
curCtx.shadowColor = "black";
this.leftLeg.draw();
} else { } else {
curCtx.shadowBlur = 10; img(sprites.playerLegActive,(this.leftLeg.x+this.leftLeg.x2)/2,(this.leftLeg.y+this.leftLeg.y2)/2,this.leftLeg.angle+pi/2,4,4);
curCtx.shadowColor = "yellow"; img(sprites.playerLeg,(this.rightLeg.x+this.rightLeg.x2)/2,(this.rightLeg.y+this.rightLeg.y2)/2,this.rightLeg.angle+pi/2,4,4);
curCtx.lineWidth = 3;
this.leftLeg.draw();
curCtx.lineWidth = 1;
curCtx.shadowBlur = 0;
curCtx.shadowColor = "black";
this.rightLeg.draw();
} }
} else { } else {
this.leftLeg.draw(); img(sprites.playerLeg,(this.leftLeg.x+this.leftLeg.x2)/2,(this.leftLeg.y+this.leftLeg.y2)/2,this.leftLeg.angle+pi/2,4,4);
this.rightLeg.draw(); img(sprites.playerLeg,(this.rightLeg.x+this.rightLeg.x2)/2,(this.rightLeg.y+this.rightLeg.y2)/2,this.rightLeg.angle+pi/2,4,4);
} }
img(sprites.playerHead,this.head.x + Math.cos(this.head.angle) * 20,this.head.y + Math.sin(this.head.angle) * 20,this.head.angle,4,4);
img(sprites.playerLeg,(this.leftLeg.x+this.leftLeg.x2)/2,(this.leftLeg.y+this.leftLeg.y2)/2,this.leftLeg.angle+pi/2,4,4);
img(sprites.playerLeg,(this.rightLeg.x+this.rightLeg.x2)/2,(this.rightLeg.y+this.rightLeg.y2)/2,this.rightLeg.angle+pi/2,4,4);
if(this.shouldMoveLeg) { if(this.shouldMoveLeg) {
if(this.legSelected === "R") { if(this.legSelected === "R") {
var active = collidingWithWorld({x: this.rightLeg.x2, y: this.rightLeg.y2, w:8, h:8}); var active = collidingWithWorld({x: this.rightLeg.x2, y: this.rightLeg.y2, w:8, h:8});
img(sprites.playerFoot,this.leftLeg.x2,this.leftLeg.y2,0,-4,4); img(sprites.playerFoot,this.leftLeg.x2,this.leftLeg.y2,0,-5,5);
img(sprites["playerFoot" + (active ? "Active" : "")],this.rightLeg.x2,this.rightLeg.y2,0,4,4); img(sprites["playerFoot" + (active ? "Active" : "")],this.rightLeg.x2,this.rightLeg.y2,0,5,5);
} else { } else {
var active = collidingWithWorld({x: this.leftLeg.x2, y: this.leftLeg.y2, w:8, h:8}); var active = collidingWithWorld({x: this.leftLeg.x2, y: this.leftLeg.y2, w:8, h:8});
img(sprites["playerFoot" + (active ? "Active" : "")],this.leftLeg.x2,this.leftLeg.y2,0,-4,4); img(sprites["playerFoot" + (active ? "Active" : "")],this.leftLeg.x2,this.leftLeg.y2,0,-5,5);
img(sprites.playerFoot,this.rightLeg.x2,this.rightLeg.y2,0,4,4); img(sprites.playerFoot,this.rightLeg.x2,this.rightLeg.y2,0,5,5);
} }
} else { } else {
img(sprites.playerFoot,this.leftLeg.x2,this.leftLeg.y2,0,-4,4); img(sprites.playerFoot,this.leftLeg.x2,this.leftLeg.y2,0,-5,5);
img(sprites.playerFoot,this.rightLeg.x2,this.rightLeg.y2,0,4,4); img(sprites.playerFoot,this.rightLeg.x2,this.rightLeg.y2,0,5,5);
} }
} }

View File

@ -37,5 +37,5 @@ function drawObjectives() {
} }
} }
Objectives.push(new Objective(-140,108,60,300,"cereal",function(){console.log("%c cereal obtained 😎","font-size:200%;");})); Objectives.push(new Objective(-140,108,60,300,"cereal",function(){console.log("%c cereal obtained 😎","font-size:200%;");tutState = tutorialStates.getMail;}));
Objectives.push(new Objective(-740,156,50,50,"box",function(){console.log("%c the entire mailbox obtained 😎","font-size:200%;");player.holdingBox = true;})); Objectives.push(new Objective(-740,156,50,50,"box",function(){console.log("%c the entire mailbox obtained 😎","font-size:200%;");player.holdingBox = true;}));

View File

@ -3,7 +3,8 @@ var tutorialStates = {
placeOnGround:1, placeOnGround:1,
goDownStairs:2, goDownStairs:2,
getCereal: 3, getCereal: 3,
getMail: 4 getMail: 4,
goToBed: 5
}; };
var tutState = tutorialStates.selectLeg; var tutState = tutorialStates.selectLeg;
@ -47,7 +48,14 @@ function handlePlaying() {
case tutorialStates.getCereal: case tutorialStates.getCereal:
break; break;
case tutorialStates.getMail: case tutorialStates.getMail:
if(!player.holdingBox) {
tutState = tutorialStates.goToBed;
}
break;
case tutorialStates.goToBed:
if(player.x > 560) {
}
break; break;
} }

View File

@ -40,6 +40,7 @@ class SoundSnippet {
// Set the audio SRC // Set the audio SRC
this.audio = new Howl({src:[this.assetPath], loop: (this.assetType == audioAssetType.bgm.bgm)}); this.audio = new Howl({src:[this.assetPath], loop: (this.assetType == audioAssetType.bgm.bgm)});
// Create a callback for loading finished // Create a callback for loading finished
this.audio.once("load", () => { this.audio.once("load", () => {
console.log(`[SoundSnippet] Loaded asset: ${this.asset_name}`); console.log(`[SoundSnippet] Loaded asset: ${this.asset_name}`);
@ -78,12 +79,12 @@ class SoundSnippet {
console.log(`[SoundSnippet] Playing ${this.asset_name} forever`); console.log(`[SoundSnippet] Playing ${this.asset_name} forever`);
// Play the snippet
this.audio.play(); this.audio.play();
// Schedule a replay worker this.audio.on('end', function(){
setInterval(() => { this.audio.play(); console.log(`[SoundSnippet] Replaying ${this.asset_name}`) }, this.getLengthSeconds() * 1000); console.log(`[SoundSnippet] Replaying ${this._src}`);
this.play();
});
} else { } else {
console.warn("[SoundSnippet] Tried to play audio with autoplay disabled. The user must press the play button before you can play audio"); console.warn("[SoundSnippet] Tried to play audio with autoplay disabled. The user must press the play button before you can play audio");