From e0ba49c368f95a1e71ae5b1c0d947b417e4f17f0 Mon Sep 17 00:00:00 2001 From: rsninja722 Date: Sun, 19 Apr 2020 16:08:00 -0400 Subject: [PATCH] objectives and temp player --- docs/assets/images/box.png | Bin 0 -> 257 bytes docs/assets/images/boxNoOutline.png | Bin 0 -> 208 bytes docs/assets/images/cereal.png | Bin 0 -> 283 bytes docs/assets/images/playerArm.png | Bin 0 -> 83 bytes docs/assets/images/playerBody.png | Bin 0 -> 343 bytes docs/assets/images/playerHead.png | Bin 0 -> 176 bytes docs/assets/images/playerLeg.png | Bin 0 -> 202 bytes docs/assets/images/post.png | Bin 0 -> 268 bytes docs/assets/js/constants.js | 2 +- docs/assets/js/index.js | 10 ++- docs/assets/js/player/arm.js | 22 +++++++ docs/assets/js/player/player.js | 82 +++++++++++++++++++++++- docs/assets/js/playing/objective.js | 41 ++++++++++++ docs/assets/js/playing/playing.js | 10 +++ docs/assets/js/transition/transition.js | 2 +- docs/assets/js/world/level.js | 2 +- docs/index.html | 5 +- 17 files changed, 170 insertions(+), 6 deletions(-) create mode 100644 docs/assets/images/box.png create mode 100644 docs/assets/images/boxNoOutline.png create mode 100644 docs/assets/images/cereal.png create mode 100644 docs/assets/images/playerArm.png create mode 100644 docs/assets/images/playerBody.png create mode 100644 docs/assets/images/playerHead.png create mode 100644 docs/assets/images/playerLeg.png create mode 100644 docs/assets/images/post.png create mode 100644 docs/assets/js/player/arm.js create mode 100644 docs/assets/js/playing/objective.js diff --git a/docs/assets/images/box.png b/docs/assets/images/box.png new file mode 100644 index 0000000000000000000000000000000000000000..0f46acdddcfb96fbbf8623792dc4137cfeaf5e44 GIT binary patch literal 257 zcmV+c0sj7pP)=7M}Ak9JxXjYgD;g_ObsS?y>-8cj&UBq0F+{h)O*G0dmi00000NkvXX Hu0mjfY7Ap6 literal 0 HcmV?d00001 diff --git a/docs/assets/images/boxNoOutline.png b/docs/assets/images/boxNoOutline.png new file mode 100644 index 0000000000000000000000000000000000000000..b4a166a41a662507c1c73f223c02fdf57b537e53 GIT binary patch literal 208 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F5M?jcysy3fAP_W6< z#WBR9H#tEf=z-6a`~Qst>;7vRF~s%=&fJ{zGG@=R)j4-h6db=jUs1_wrl51t(Mvo3 zhwIG!EiZ2&{Pg>O5SXZ&)M!}t-uA$U7Z;P+Kp`-xdVc zYa)0QOuzj2n?anPmEoySBE$2$w-_9~)`7)Qya3Xy$T^u|-rD^PvP=iS8bBIB0H#^` z-F&dv<9`kelFDjuZ-B!9W&oi?^^%d3;oSKyw@O1TaS?83{1ONs&7R>+v literal 0 HcmV?d00001 diff --git a/docs/assets/images/playerBody.png b/docs/assets/images/playerBody.png new file mode 100644 index 0000000000000000000000000000000000000000..9477bf3f751b50b1b638d20f85433015d9f88253 GIT binary patch literal 343 zcmV-d0jU0oP)MFCtgMEi@b2AP47{S*V9h8BAG}awurYqe@Z{+mu%XBbL2MKgLGB?*A;_wOhmJ8Y zbNetTNZbOO4mT0mYM4Tp8*wUxxe>!edpj$JBWH!c*1!PB6!H~f4aTa()7BevL9RXp+soH$fK*1zW z7sn8Zsl5|U^Bz#(ah`jIllg#vhXD(>K}MAZqu1sBr7>@&_cQJBu4-Jf<*Ew9gJem$ z$Oi78JekMVG&pHr$eMMHE8^1EJ<|S3^4z)E51jUy7R`6NwLoZRjLZJ}pO+ebV|eMK VHsi0j{b8VO44$rjF6*2UngF=jI}ZQ= literal 0 HcmV?d00001 diff --git a/docs/assets/images/playerLeg.png b/docs/assets/images/playerLeg.png new file mode 100644 index 0000000000000000000000000000000000000000..4045e9554f8fc884099b023bd1955d495c4f8ab9 GIT binary patch literal 202 zcmeAS@N?(olHy`uVBq!ia0vp^Y(Ol`0U|eFuSoz>6FprVLo|YuQxXyq47Ozb;$O6L z#}mnYwY4V-{#D2-D|(_pyL=kUHx3vIVCg!09wpO A(EtDd literal 0 HcmV?d00001 diff --git a/docs/assets/images/post.png b/docs/assets/images/post.png new file mode 100644 index 0000000000000000000000000000000000000000..2851f4f6a2c808590313f65de7c6bd11a6c145b9 GIT binary patch literal 268 zcmV+n0rUQeP)pU>FSpP(B*X3$zS_i@Ur2f4=mB;qJ8y3{RfFVW{4A32T7kj0Knh z-`+iEIDP&q`36wz0+0b95I=Vx`CfSb;w5 literal 0 HcmV?d00001 diff --git a/docs/assets/js/constants.js b/docs/assets/js/constants.js index bf02610..8e09787 100644 --- a/docs/assets/js/constants.js +++ b/docs/assets/js/constants.js @@ -56,7 +56,7 @@ var constants = { select_range: 10, leg_length: 75, hip: { - offset_x: 20, + offset_x: 16, offset_y: 35 }, defaultX: 600, diff --git a/docs/assets/js/index.js b/docs/assets/js/index.js index 10fbdce..938241c 100644 --- a/docs/assets/js/index.js +++ b/docs/assets/js/index.js @@ -16,7 +16,15 @@ images = [ "tutArrow.png", "tutKeyZ.png", "tutKeyX.png", - "tutKeyC.png" + "tutKeyC.png", + "cereal.png", + "post.png", + "box.png", + "boxNoOutline.png", + "playerBody.png", + "playerLeg.png", + "playerArm.png", + "playerHead.png" ]; audio = [ diff --git a/docs/assets/js/player/arm.js b/docs/assets/js/player/arm.js new file mode 100644 index 0000000..d5aef8e --- /dev/null +++ b/docs/assets/js/player/arm.js @@ -0,0 +1,22 @@ +// a Class for legs +class Arm { + + constructor(x, y, len, angle) { + + this.x = x; + this.y = y; + + + this.len = len; + this.len2 = this.len * this.len; + this.angle = angle; + + this.x2 = this.x + len * Math.cos(angle); + this.y2 = this.y + len * Math.sin(angle); + } + +}; + +Arm.prototype.draw = function () { + img(sprites.playerArm,(this.x+this.x2)/2,(this.y+this.y2)/2,this.angle-pi/2,4,4); +}; diff --git a/docs/assets/js/player/player.js b/docs/assets/js/player/player.js index 47a8ac3..94dbab8 100644 --- a/docs/assets/js/player/player.js +++ b/docs/assets/js/player/player.js @@ -8,12 +8,17 @@ class Player { 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, constants.player.leg_length, Math.PI*2.5); this.rightLeg = new Leg(this.hipRight.x, this.hipRight.y, constants.player.leg_length, Math.PI*2.5); + this.leftArm = new Arm(this.hipLeft.x + 8, this.y - constants.player.hip.offset_y, 64, Math.PI/2); + this.rightArm = new Arm(this.hipRight.x - 8, this.y - constants.player.hip.offset_y, 64, Math.PI/2); + this.head = {x:this.x,y:this.y-this.h/2,angle:Math.PI*1.5}; this.legSelected = "R"; this.shouldMoveLeg = false; this.collided = false; this.lastBodyX = x; this.lastBodyY = y; this.hover = { active: false, leg: "R" }; + this.holdingBox = false; + this.armVel = 1; } } @@ -76,6 +81,12 @@ Player.prototype.update = function() { } } + // place box + if(this.holdingBox && this.x > -275 && this.y < 100) { + this.holdingBox = false; + boxOnTable = true; + } + // god mode // if(keyDown[k.w]) { // this.y-=5; @@ -89,6 +100,43 @@ Player.prototype.update = function() { // if(keyDown[k.d]) { // this.x+=5; // } + + var halfPI = pi/2; + if(this.leftArm.angle > halfPI) { + this.leftArm.angle -= 0.05 * this.armVel; + } + if(this.leftArm.angle < halfPI) { + this.leftArm.angle += 0.05 * this.armVel; + } + if(this.rightArm.angle > halfPI) { + this.rightArm.angle -= 0.05 * this.armVel; + } + if(this.rightArm.angle < halfPI) { + this.rightArm.angle += 0.05 * this.armVel; + } + this.armVel += 0.05; + + if(this.head.angle > halfPI + pi) { + this.head.angle -= 0.05; + } + if(this.head.angle < halfPI + pi) { + this.head.angle += 0.05; + } + + var arm = this.leftArm; + arm.x = this.x + constants.player.hip.offset_x + 8; + arm.y = this.y - constants.player.hip.offset_y; + arm.x2 = arm.x + arm.len * Math.cos(arm.angle); + arm.y2 = arm.y + arm.len * Math.sin(arm.angle); + + var arm = this.rightArm; + arm.x = this.x - constants.player.hip.offset_x - 8; + arm.y = this.y - constants.player.hip.offset_y; + arm.x2 = arm.x + arm.len * Math.cos(arm.angle); + arm.y2 = arm.y + arm.len * Math.sin(arm.angle); + + this.head.x = this.x; + this.head.y = this.y-this.h/2; centerCameraOn(this.x,this.y); // camera limits @@ -211,9 +259,24 @@ Player.prototype.moveLeg = function(){ this.y = this.lastBodyY; } + // arm and head flailing + var bodyDifY = this.lastBodyY - this.y; + if(!isNaN(bodyDifY)) { + if(bodyDifY < 0) { + this.leftArm.angle -= Math.abs(bodyDifY)/10; + this.rightArm.angle += Math.abs(bodyDifY)/10; + } + } + var bodyDifX = this.lastBodyX - this.x; + if(!isNaN(bodyDifX)) { + this.leftArm.angle -= bodyDifX/20; + this.rightArm.angle -= bodyDifX/20; + this.head.angle += bodyDifX/30; + } this.lastBodyX = this.x; this.lastBodyY = this.y; + this.armVel = 1; } Player.prototype.updateHips = function() { @@ -223,7 +286,16 @@ Player.prototype.updateHips = function() { 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); + + this.leftArm.draw(); + this.rightArm.draw(); + + 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); + } + // boxNoOutline if(this.hover.active) { if(this.hover.leg === "R") { curCtx.shadowBlur = 10; @@ -248,6 +320,14 @@ Player.prototype.draw = function() { this.leftLeg.draw(); this.rightLeg.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); + + 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); + + + } // https://github.com/scottglz/distance-to-line-segment/blob/master/index.js diff --git a/docs/assets/js/playing/objective.js b/docs/assets/js/playing/objective.js new file mode 100644 index 0000000..7ce1d82 --- /dev/null +++ b/docs/assets/js/playing/objective.js @@ -0,0 +1,41 @@ +class Objective { + constructor(x,y,w,h,imgName,callback) { + this.x = x; + this.y = y; + this.w = w; + this.h = h; + this.imgName = imgName; + this.callback = callback; + } +} + +Objective.prototype.draw = function() { + imgIgnoreCutoff(sprites[this.imgName],this.x,this.y,0,4,4); +} + +Objective.prototype.update = function() { + if(rectrect(this,player)) { + this.callback(); + return true; + } + return false; +} + +var Objectives = []; +function updateObjectives() { + for(var i=0;i 0){ - currentAlpha -= .005; + currentAlpha -= .5; } diff --git a/docs/assets/js/world/level.js b/docs/assets/js/world/level.js index 265b892..ac27956 100644 --- a/docs/assets/js/world/level.js +++ b/docs/assets/js/world/level.js @@ -12,7 +12,7 @@ class block { } // create blocks -var blockData = [705,-8,491,64,460,27,74,64,425,64,74,64,389,99,74,64,352,135,74,64,321,167,74,64,285,203,74,64,249,239,74,64,-18,299,3314,111,-43,205,59,90,-44,207,80,63,-168,199,128,108,-168,144,158,25,-978,-101,158,984,14,-398,1958,85,928,-192,58,345,664,-101,25,133,867,-102,25,133,765,-97,185,67]; +var blockData = [705,-8,491,64,460,27,74,64,425,64,74,64,389,99,74,64,352,135,74,64,321,167,74,64,285,203,74,64,249,239,74,64,-18,299,3314,111,-43,205,59,90,-168,199,128,108,-168,144,158,25,-978,-101,158,984,14,-398,1958,85,928,-192,58,345,664,-101,25,133,867,-102,25,133,765,-97,185,67]; for (let i = 0, l = blockData.length; i < l; i += 4) { collisionRects.push(new block(blockData[i], blockData[i + 1], blockData[i + 2], blockData[i + 3])); } diff --git a/docs/index.html b/docs/index.html index 6b7ceab..1f703d0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3,6 +3,7 @@ error: title is undefined +