Skip to content

Commit

Permalink
made the character faster and the eyes follow you
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyiho committed Oct 6, 2023
1 parent 1fb834f commit fc7a72e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 9 deletions.
77 changes: 69 additions & 8 deletions _posts/2023-10-04-Animation with Sprites.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand All @@ -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]){
Expand Down Expand Up @@ -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();
Expand All @@ -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]){
Expand Down Expand Up @@ -151,6 +209,7 @@ function checkForCharacterOverlap(object1){
}
}
}
}
return false;
}

Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions myScripts/CreateObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion myScripts/MovementModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Binary file modified scripts/__pycache__/convert_notebooks.cpython-310.pyc
Binary file not shown.

0 comments on commit fc7a72e

Please sign in to comment.