Merge branch 'master' of github.com:rsninja722/LudumDare46

This commit is contained in:
Evan Pratten 2020-04-19 10:04:17 -04:00
commit 531adf2c43
No known key found for this signature in database
GPG Key ID: 93AC7B3D071356D3
15 changed files with 166 additions and 42 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 685 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 470 KiB

BIN
docs/assets/images/eye.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 784 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 B

View File

@ -2,9 +2,6 @@
function drawTitleScreenUI() {
}
// UI for level transition
function drawLevelTransitionUI() {
}
// UI for playing
function drawPlayingUI() {
@ -16,6 +13,9 @@ function drawPlayingUI() {
//Respiration Monitor
respiratoryUI(cw/8*5,ch/8*7-8, cw/16, ch/8);
//Blink eye and overlay
blinkUI();
}
//UI for pause screen
@ -78,7 +78,16 @@ function heartBeatUI(x, y, width, height){
}
//Backdrop
rect(x+width/2,y+height/2,width,height,"black");
var BackdropColor;
if(pressure > 42 && pressure < 60) {
BackdropColor = "#0c2605";
} else if(pressure > 28 && pressure < 75) {
BackdropColor = "#2b2b06";
} else {
BackdropColor = "#260505";
}
rect(x+width/2,y+height/2,width,height,BackdropColor);
img(sprites.heartBack,cw-107,ch-46);
//Pressure Meter
rect(x+width-8,y+height/2,16,height,"red");
@ -93,6 +102,9 @@ function heartBeatUI(x, y, width, height){
const qrsValueAtNextPosition = heartBeatHistory[index+1];
line(x+(index*(width-16)/heartBeatHistory.length), y+(2*height/3)+(qrsValueAtPosition*(width-16)/heartBeatHistory.length), x+((index+1)*(width-16)/heartBeatHistory.length), y+(2*height/3)+(qrsValueAtNextPosition*(width-16)/heartBeatHistory.length),Math.min(3,Math.max(3/beatTimeElapsed,1)), "red");
}
// cover
img(sprites.heartCover,cw-107,ch-46);
}
//Determine next value to be added to the graph
@ -129,3 +141,21 @@ function pushNextBeatValue(){
heartBeatHistory.push(nextBeatValue);
}
function blinkUI() {
// eye
img(sprites.eye,cw-350,ch-40,0,2,2);
var alpha = clamp(eyeDryness / constants.lifeFuncs.blink.dryTime,0,1);
curCtx.globalAlpha = alpha;
img(sprites.eyeDry,cw-350,ch-40,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;
}

View File

@ -41,6 +41,9 @@ var constants = {
},
cardio:{
optimalPressure: 50
},
blink: {
dryTime: 600
}
},
player:{
@ -53,7 +56,9 @@ var constants = {
hip: {
offset_x: 15,
offset_y: 25
}
},
defaultX: 500,
defaultY: -70
}
};

View File

@ -5,7 +5,12 @@ page_preloader.show(true);
images = [
"assets/images/",
"level.png",
"level_2.png"
"level_2.png",
"heartCover.png",
"heartBack.png",
"blinkOverlay.png",
"eye.png",
"eyeDry.png"
];
audio = [
@ -61,20 +66,28 @@ function draw() {
// Handle game state
switch (globalState) {
// title screen
case globalStates.titleScreen:
drawTitleScreen();
break;
// level transition
case globalStates.levelTransition:
handleTransition();
break;
// playing
case globalStates.playing:
camera.zoom = 1;
drawWorldBlocks();
imgIgnoreCutoff(sprites.level_2,0,0,0,4,4);
player.draw();
if(!justBlinked) {
camera.zoom = 1;
drawWorldBlocks();
imgIgnoreCutoff(sprites.level_2,0,0,0,4,4);
player.draw();
} else {
rect(-camera.x - difx + cw/2,-camera.y - dify + ch/2,cw,ch,"black");
justBlinked = false;
}
break;
// paused
case globalStates.paused:

View File

@ -13,18 +13,19 @@ var breathMode = {
let currentBreathMode = breathMode.exhale;
let eyeDryness = 0;
let justBlinked = false;
function updateLife() {
if(keyDown[k.z]) {
if(keyDown[k.x]) {
if(breath === 0) currentBreathMode = breathMode.inhale;
else if(breath === constants.lifeFuncs.breath.fullBreath) currentBreathMode = breathMode.exhale;
}
breathe();
if(keyPress[k.x]) {
if(keyPress[k.c]) {
heartbeat();
}
@ -32,6 +33,12 @@ function updateLife() {
if(pressure<=0){
pressure = 0;
}
eyeDryness++;
if(keyPress[k.z]) {
blink();
}
};
function breathe() {
@ -72,4 +79,9 @@ function heartbeat() {
// Play the heartbeat sound
soundAssets.heartbeat.play();
};
};
function blink() {
eyeDryness = 0;
justBlinked = true;
}

View File

@ -4,10 +4,10 @@ class Player {
this.y = y;
this.w = constants.player.width;
this.h = constants.player.height;
this.hipLeft = { x: this.x - constants.player.hip.offset_x, y: this.y + constants.player.hip.offset_y };
this.hipRight = { x: this.x + constants.player.hip.offset_x, y: this.y + constants.player.hip.offset_y };
this.leftLeg = new Leg(this.hipLeft.x, this.hipLeft.y, 50, -Math.PI / 4);
this.rightLeg = new Leg(this.hipRight.x, this.hipRight.y, 50, Math.PI / 2);
this.hipLeft = { x: this.x + constants.player.hip.offset_x, y: this.y + constants.player.hip.offset_y };
this.hipRight = { x: this.x - constants.player.hip.offset_x, y: this.y + constants.player.hip.offset_y };
this.leftLeg = new Leg(this.hipLeft.x, this.hipLeft.y, 50, Math.PI*2.5);
this.rightLeg = new Leg(this.hipRight.x, this.hipRight.y, 50, Math.PI*2.5);
this.legSelected = "R";
this.shouldMoveLeg = false;
this.collided = false;
@ -55,17 +55,8 @@ Player.prototype.update = function() {
var targetPos = mousePosition();
var curLeg = this.getActiveLeg();
this.hover.active = false;
//left
if (distanceToLineSegment(this.leftLeg.x, this.leftLeg.y, this.leftLeg.x2, this.leftLeg.y2, targetPos.x, targetPos.y) < constants.player.select_range) {
this.hover.active = true;
this.hover.leg = "L";
if(mousePress[0]) {
this.shouldMoveLeg = true;
this.legSelected = "L";
this.hover.active = false;
}
// right
} else if (distanceToLineSegment(this.rightLeg.x, this.rightLeg.y, this.rightLeg.x2, this.rightLeg.y2, targetPos.x, targetPos.y) < constants.player.select_range) {
if (distanceToLineSegment(this.rightLeg.x, this.rightLeg.y, this.rightLeg.x2, this.rightLeg.y2, targetPos.x, targetPos.y) < constants.player.select_range) {
this.hover.active = true;
this.hover.leg = "R";
if(mousePress[0]) {
@ -73,7 +64,16 @@ Player.prototype.update = function() {
this.legSelected = "R";
this.hover.active = false;
}
}
//left
} else if (distanceToLineSegment(this.leftLeg.x, this.leftLeg.y, this.leftLeg.x2, this.leftLeg.y2, targetPos.x, targetPos.y) < constants.player.select_range) {
this.hover.active = true;
this.hover.leg = "L";
if(mousePress[0]) {
this.shouldMoveLeg = true;
this.legSelected = "L";
this.hover.active = false;
}
}
}
centerCameraOn(this.x,this.y);
@ -98,7 +98,6 @@ Player.prototype.moveLeg = function(){
// console.log(curLeg.angle.toPrecision(5),pointTo(curLeg,target).toPrecision(5));
var angleDif = turn(curLeg.angle, pointTo(curLeg, target), constants.player.leg_speed) - curLeg.angle;
curLeg.angle += angleDif;
// var angle = pointTo(curLeg,target);
curLeg.x2 = curLeg.x + curLeg.len * Math.cos(curLeg.angle);
curLeg.y2 = curLeg.y + curLeg.len * Math.sin(curLeg.angle);
@ -109,15 +108,26 @@ Player.prototype.moveLeg = function(){
curLeg.x2 = lastX;
curLeg.y2 = lastY;
curLeg.angle -= angleDif;
// finer movement
angleDif = turn(curLeg.angle, pointTo(curLeg, target), constants.player.leg_speed/8) - curLeg.angle;
curLeg.angle += angleDif;
curLeg.x2 = curLeg.x + curLeg.len * Math.cos(curLeg.angle);
curLeg.y2 = curLeg.y + curLeg.len * Math.sin(curLeg.angle);
// Collision
if(collidingWithWorld({x:curLeg.x2,y:curLeg.y2,w:2,h:2})){
this.collided = true;
curLeg.x2 = lastX;
curLeg.y2 = lastY;
curLeg.angle -= angleDif;
}
return 0;
}
if(collidingWithWorld({x:this.x, y:this.y, w:this.w, h:this.h})){
this.x = this.lastBodyX;
this.y = this.lastBodyY;
}
if (dist(curLeg, target) > curLeg.len) {
@ -169,7 +179,10 @@ Player.prototype.moveLeg = function(){
}
if(collidingWithWorld({x:this.x, y:this.y, w:this.w, h:this.h})){
this.x = this.lastBodyX;
this.y = this.lastBodyY;
}
this.lastBodyX = this.x;
@ -246,5 +259,9 @@ function distanceToLineSegment(lx1, ly1, lx2, ly2, px, py) {
var player = new Player(500,-70);
var player = new Player(constants.player.defaultX, constants.player.defaultY);
// why does this stop the legs from glitching on the first step???
player.rightLeg.angle = -pointTo({ x: player.rightLeg.x2, y: player.rightLeg.y2 }, player.hipRight);
player.leftLeg.angle = pointTo({ x: player.leftLeg.x2, y: player.leftLeg.y2 }, player.hipLeft);
player.moveLeg();

View File

@ -24,7 +24,7 @@ function handleTitleScreen(){
function handleMainScreen(){
if(timer > 20){
if(rectpoint({x:415, y:200, w: 300, h: 50}, {x:cursor.x, y:cursor.y}) && mouseDown[0]){
globalState = globalStates.playing;
globalState = globalStates.levelTransition;
timer = 0;
}
if(rectpoint({x:415, y:550, w: 300, h: 50}, {x:cursor.x, y:cursor.y}) && mouseDown[0]){

View File

@ -0,0 +1,42 @@
var currentAlpha = 1.01;
function handleTransition(){
// Calculates alpha until its zero
if(currentAlpha > 0){
currentAlpha -= .005;
}
}
// UI for level transition
function drawLevelTransitionUI() {
// centers camera on player
centerCameraOn(constants.player.defaultX, constants.player.defaultY);
// sets alpha for background drawing
canvases.ctx.globalAlpha = 1;
// draws background sprites
drawWorldBlocks();
imgIgnoreCutoff(sprites.level_2,0,0,0,4,4);
player.draw();
// sets alpha to calculated alpha for black
canvases.ctx.globalAlpha = currentAlpha;
// draw a black rect unless less the 0 alpha then switches to actual game
if(currentAlpha > 0){
rect(0, 0, 2000, 2000, "black");
}else{
globalState = globalStates.playing;
}
// resets alpha for rest of drawing
canvases.ctx.globalAlpha = 1;
}

View File

@ -1,8 +1,8 @@
<!DOCTYPE html>
<html>
<head>
<!-- <link rel="icon" type="image/gif" href="icon.png"/> -->
<title>html.aspx</title>
<link rel="icon" type="image/gif" href="assets/images/tempIcon.png"/>
<title>error: title is undefined</title>
<style>
html {
background-color: var(--theme-webpage-bg_color);
@ -13,7 +13,6 @@
top:0;bottom:0;right:0;left:0;
margin:auto;
border: 5px solid var(--theme-webpage-canvas_border);
border-radius: 10px;
background-color: var(--theme-webpage-canvas_bg);
}
</style>
@ -21,6 +20,11 @@
</head>
<body>
<canvas width="800" height="600" id="game"></canvas>
<pre style="position: absolute;left: 0;bottom: 0;"> TODO REMOVE ME
z: blink
x: breath
c: beat heart
</pre>
<!-- Graphics Library -->
<script src="assets/js/game.js"></script>
@ -48,6 +52,7 @@
<script src="assets/js/titleScreen/titleScreen.js"></script>
<script src="assets/js/UI/ui.js"></script>
<script src="assets/js/transition/transition.js"></script>
<!-- Webpage -->
<script src="assets/js/injection/cssinjector.js"></script>