From fc7a72e32f5b97e67e91801e50ba6dbcfa3cdaaf Mon Sep 17 00:00:00 2001 From: Trystan-Schmits Date: Fri, 6 Oct 2023 22:40:10 +0000 Subject: [PATCH] made the character faster and the eyes follow you --- _posts/2023-10-04-Animation with Sprites.md | 77 ++++++++++++++++-- myScripts/CreateObject.js | 2 + myScripts/MovementModule.js | 2 +- .../convert_notebooks.cpython-310.pyc | Bin 2759 -> 2752 bytes 4 files changed, 72 insertions(+), 9 deletions(-) diff --git a/_posts/2023-10-04-Animation with Sprites.md b/_posts/2023-10-04-Animation with Sprites.md index d00551d..c6a4712 100644 --- a/_posts/2023-10-04-Animation with Sprites.md +++ b/_posts/2023-10-04-Animation with Sprites.md @@ -68,7 +68,8 @@ var eyesObject = new Object(eyes,[20,10],[60,30],[300,300],3,1) var objects = [[backgroundObject],[eyesObject],[desserObject],[slimeObject]]; -function checkForOverlap(object1,object2){ +function checkForOverlap(object1,object2, axis){ + if (axis == null){axis = 2}; var pos1 = object1.ReturnPosition().slice(); var scale1 = object1.ReturnScale().slice(); var xRange1 = [pos1[0],pos1[0]+scale1[0]]; @@ -79,6 +80,33 @@ function checkForOverlap(object1,object2){ var xRange2 = [pos2[0],pos2[0]+scale2[0]]; var yRange2 = [pos2[1],pos2[1]+scale2[1]]; + if (axis ==0){ + if (xRange1[0]>=xRange2[0]){ + if (xRange1[0]<=xRange2[1]){ + return true; + } + } + if (xRange1[1]>=xRange2[0]){ + if (xRange1[1]<=xRange2[1]){ + return true; + } + } + } + + if (axis ==1){ + if (yRange1[0]>=yRange2[0]){ + if (yRange1[0]<=yRange2[1]){ + return true; + } + } + if (yRange1[1]>=yRange2[0]){ + if (yRange1[1]<=yRange2[1]){ + return true; + } + } + } + + if (axis ==2){ if (xRange1[0]>=xRange2[0]){ if (xRange1[0]<=xRange2[1]){ if (yRange1[0]>=yRange2[0]){ @@ -107,9 +135,12 @@ function checkForOverlap(object1,object2){ } } } + } return false; } -function checkForCharacterOverlap(object1){ +function checkForCharacterOverlap(object1,axis){ + if (axis == null){axis = 2}; + var scroll = Drawer.ReturnScroll(); var pos1 = charObject.ReturnPosition().slice(); @@ -123,6 +154,33 @@ function checkForCharacterOverlap(object1){ var xRange2 = [pos2[0],pos2[0]+scale2[0]]; var yRange2 = [pos2[1],pos2[1]+scale2[1]]; + if (axis ==0){ + if (xRange1[0]>=xRange2[0]){ + if (xRange1[0]<=xRange2[1]){ + return true; + } + } + if (xRange1[1]>=xRange2[0]){ + if (xRange1[1]<=xRange2[1]){ + return true; + } + } + } + + if (axis ==1){ + if (yRange1[0]>=yRange2[0]){ + if (yRange1[0]<=yRange2[1]){ + return true; + } + } + if (yRange1[1]>=yRange2[0]){ + if (yRange1[1]<=yRange2[1]){ + return true; + } + } + } + + if (axis ==2){ if (xRange1[0]>=xRange2[0]){ if (xRange1[0]<=xRange2[1]){ if (yRange1[0]>=yRange2[0]){ @@ -151,6 +209,7 @@ function checkForCharacterOverlap(object1){ } } } + } return false; } @@ -172,17 +231,19 @@ function frame(){ //when a frame is updated slimeObject.OverridePosition([slimeObject.ReturnPosition()[0]-10/fps,0]); } - if (eyesObject.ReturnPosition()[0] < (Drawer.ReturnScroll()+canvas.offsetWidth/2)){ + //eyes + if (checkForCharacterOverlap(eyesObject,0)==true){ + eyesObject.UpdateFrame(1); + } + else if (eyesObject.ReturnPosition()[0] < (Drawer.ReturnScroll()+canvas.offsetWidth/2)){ eyesObject.UpdateFrame(0); - console.log(true); } else{ eyesObject.UpdateFrame(2); - console.log(false); } - //character Animation - var F = 0; - if (CurrentFrame % Math.round(fps/2)== 0){F+=1; charObject.UpdateFrame(F);}; + + //update character + if (CurrentFrame % Math.round(fps/8)== 0){charObject.UpdateFrame();}; switch(movement.state()){ case 0: diff --git a/myScripts/CreateObject.js b/myScripts/CreateObject.js index 7b880e9..bc37eb3 100644 --- a/myScripts/CreateObject.js +++ b/myScripts/CreateObject.js @@ -23,10 +23,12 @@ class CreateObject{ } UpdateFrame(newFrame){ + if (newFrame == null){newFrame = this.frame+1} this.frame = newFrame%this.maxFrames; } UpdateState(newState){ + if (newState == null){newState = this.state+1} this.state = newState%this.maxState; } diff --git a/myScripts/MovementModule.js b/myScripts/MovementModule.js index 5ea189e..13cbd4f 100644 --- a/myScripts/MovementModule.js +++ b/myScripts/MovementModule.js @@ -6,7 +6,7 @@ class Movement{ DeltaX = 0; //x direction of buttons pressed (1 up, -1 down, 0 none) DeltaY = 0; //y direction of buttons pressed (1 right, -1 left, 0 none) - speed = 20; //default speed + speed = 80; //default speed up = "KeyW"; //default keybinds for controls down = "KeyS"; diff --git a/scripts/__pycache__/convert_notebooks.cpython-310.pyc b/scripts/__pycache__/convert_notebooks.cpython-310.pyc index 6948ddcad5cf974923fdd6ad487ef4b2f49fc32d..c8a7203510a1dba38a540c4de01d16fc40b2f335 100644 GIT binary patch delta 54 zcmX>udO(ybpO=@50SM-u-^lfmQPxsFBR@A)KRdBFSGTk{wMf6LI5|HhRo}fRzqDYp IJktse0L%Lk(EtDd delta 61 zcmX>gdR&w%pO=@50SIC*ZshvNsN$fXk)NBYpPg8ot6N%}TBIMGkywBkgxAv PlwVq)Yq(j0X$1!WNTd_r