turns out eating wasnt working right. it does now! only for dur 4

This commit is contained in:
Sam 2024-06-30 00:20:14 +12:00
parent 8a6aa8beab
commit d372e109fa
6 changed files with 24 additions and 9 deletions

View File

@ -131,8 +131,12 @@ const hatConfig = {
cap: { x: 3.5, y: -13 }, cap: { x: 3.5, y: -13 },
top_hat: { x: 2, y: -20 }, top_hat: { x: 2, y: -20 },
center_box_full: { x: 0, y: 0 }, center_box_full: { x: 0, y: 0 },
center_box_hollow: { x: 0, y: 0 }, center_box_hollow: { x: 0, y: 0 }
// Add more hats with their specific offsets here };
const foodConfig = {
apple: { sizeMult: 3.5, n: 4 },
nothing: { sizeMult: 2, n: 5 },
}; };

View File

@ -60,18 +60,20 @@ class Larry extends BaseShape {
this.speedMultiplier = 100; this.speedMultiplier = 100;
this.isEating = false; this.isEating = false;
this.eatEndTimestamp= 0; this.eatEndTimestamp = 0;
this.eatDuration = eatDuration; this.eatDuration = eatDuration;
this.eatSpeed = eatSpeed; this.eatSpeed = eatSpeed;
this.bodyImage = new Image(); this.bodyImage = new Image();
this.headImage = new Image(); this.headImage = new Image();
this.foodImage = new Image();
this.hatImage = new Image(); this.hatImage = new Image();
this.shellImage = new Image(); this.shellImage = new Image();
this.backgroundImage = new Image(); this.backgroundImage = new Image();
this.bodyImage.src = 'larry_photos/body.png'; this.bodyImage.src = 'larry_photos/body.png';
this.headImage.src = 'larry_photos/head.png'; this.headImage.src = 'larry_photos/head.png';
this.foodImage.src = 'larry_photos/';
this.hatImage.src = ''; this.hatImage.src = '';
this.shellImage.src = ''; this.shellImage.src = '';
this.backgroundImage.src = ''; this.backgroundImage.src = '';
@ -103,14 +105,22 @@ class Larry extends BaseShape {
const headX = bodyX + (53.5 * this.magnitude - this.headWidth * this.magnitude / 2); const headX = bodyX + (53.5 * this.magnitude - this.headWidth * this.magnitude / 2);
let headY = bodyY + (this.bodyHeight * this.magnitude - 7 * this.magnitude) - this.headHeight * this.magnitude; let headY = bodyY + (this.bodyHeight * this.magnitude - 7 * this.magnitude) - this.headHeight * this.magnitude;
//eating
if (timestamp < this.eatEndTimestamp) { if (timestamp < this.eatEndTimestamp) {
console.log("eating") console.log("eating")
const adjustedTimestamp = timestamp -this.eatEndTimestamp + parseInt(this.eatDuration)/(1000/60); const adjustedTimestamp = this.eatEndTimestamp - timestamp + parseInt(this.eatDuration) / (1000 / 60);
console.log(adjustedTimestamp)
const eatMaxHeight = 20; const eatMaxHeight = 20;
// const eatingYOffset = ((Math.cos((adjustedTimestamp -Math.PI/2+ 0.5 * Math.PI) * (this.eatSpeed/100)*0.1 - Math.PI / 2) + 1) / 2) * eatMaxHeight; // const eatingYOffset = ((Math.cos((adjustedTimestamp -Math.PI/2+ 0.5 * Math.PI) * (this.eatSpeed/100)*0.1 - Math.PI / 2) + 1) / 2) * eatMaxHeight;
const eatingYOffset = ((Math.sin((adjustedTimestamp * 2 * Math.PI * this.eatSpeed/100 * 0.1) - Math.PI / 2) + 1) / 2) * eatMaxHeight; const eatingYOffset = ((Math.sin((adjustedTimestamp * 2 * Math.PI * this.eatSpeed / 100 * 0.1) - Math.PI / 2) + 1) / 2) * eatMaxHeight;
headY -= eatingYOffset; headY -= eatingYOffset;
const n = this.eatDuration
console.log(adjustedTimestamp)
console.log((-adjustedTimestamp + 10 * n) / 10)
console.log(Math.floor((-adjustedTimestamp + (10/(this.eatSpeed/100)) * n) / (10/(this.eatSpeed/100))))
const frame = Math.floor((-adjustedTimestamp + (10/(this.eatSpeed/100)) * n) / (10/(this.eatSpeed/100)))
this.foodImage.src = "larry_photos/foods/" + document.getElementById('elselectedFood').value+ frame + ".png";
ctx.drawImage(this.foodImage, centerX, centerY,200,226.5)
} }
ctx.drawImage(this.headImage, headX, headY, this.headWidth * this.magnitude, this.headHeight * this.magnitude); ctx.drawImage(this.headImage, headX, headY, this.headWidth * this.magnitude, this.headHeight * this.magnitude);
@ -141,8 +151,9 @@ class Larry extends BaseShape {
startEating() { startEating() {
console.log("Larry starts eating"); console.log("Larry starts eating");
this.foodImage.src = document.getElementById('elselectedFood').value
this.isEating = true; this.isEating = true;
this.eatEndTimestamp = this.lastTimestamp + (parseInt(this.eatDuration)/3)*1000/(1000/60); this.eatEndTimestamp = this.lastTimestamp + (parseInt(this.eatDuration)/(6*(this.eatSpeed/100))) * 1000 / (1000 / 60);
console.log(this.eatEndTimestamp) console.log(this.eatEndTimestamp)
// setTimeout(() => { // setTimeout(() => {
// this.isEating = false; // this.isEating = false;
@ -167,7 +178,7 @@ class Larry extends BaseShape {
} }
recalculateHatOffsets(offsets) { recalculateHatOffsets(offsets) {
this.hatXoffset = (this.headWidth * this.magnitude) / 2 - (this.hatImage.width * this.magnitude) / 2 + (offsets.x * this.magnitude); this.hatXoffset = (this.headWidth * this.magnitude) / 2 - (this.hatImage.width * this.magnitude) / 2 + (offsets.x * this.magnitude);
this.hatYoffset = (this.headHeight * this.magnitude) - (this.hatImage.height/2 * this.magnitude) + (offsets.y * this.magnitude); this.hatYoffset = (this.headHeight * this.magnitude) - (this.hatImage.height / 2 * this.magnitude) + (offsets.y * this.magnitude);
} }
setMagnitude(newMagnitude) { setMagnitude(newMagnitude) {
this.magnitude = newMagnitude; this.magnitude = newMagnitude;

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 641 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 339 KiB