-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jennifer Creighton
authored and
Jennifer Creighton
committed
Jun 17, 2018
1 parent
b35aa01
commit 8119e6e
Showing
7 changed files
with
148 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
var { animate } = new Animation(); | ||
var egg = new Egg(); | ||
var tamagotchi = new Tamagotchi(); | ||
// Get canvas | ||
var canvas = document.querySelector('.animation'); | ||
canvas.width = 180; | ||
canvas.height = 120; | ||
var context = canvas.getContext('2d'); | ||
var chooseButton = document.querySelector('.choose'); | ||
|
||
chooseButton.addEventListener('click', () => { | ||
animate(egg.bounce(3)) | ||
.then(() => { | ||
console.log('Bouncing complete!'); | ||
console.log('Time to hatch!'); | ||
return animate(egg.hatch()); | ||
}).then(() => { | ||
egg.clear(); | ||
canvas.width = tamagotchi.sprite.frameHeight; | ||
canvas.height = tamagotchi.sprite.frameWidth; | ||
console.log('BABY TAMAGOTCHI!') | ||
animate(tamagotchi.bounce()); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
class Tamagotchi { | ||
constructor() { | ||
this.sprite = {}; | ||
this.sprite.image = new Image(); | ||
this.sprite.image.src = 'images/TamagotchiSprite.png'; | ||
this.sprite.height = 480; | ||
this.sprite.width = 360; | ||
this.sprite.rows = 4; | ||
this.sprite.columns = 3; | ||
this.sprite.frameCount = 3; | ||
this.sprite.frameWidth = this.sprite.width / this.sprite.columns; | ||
this.sprite.frameHeight = this.sprite.height / this.sprite.rows; | ||
|
||
this.sprite.dislike = 0; | ||
this.sprite.jump = 1; | ||
this.sprite.eat = 2; | ||
this.sprite.chill = 3; | ||
|
||
this.eat = 0; | ||
this.maxEat = 10; | ||
} | ||
|
||
clear() { | ||
const { | ||
frameWidth, | ||
frameHeight, | ||
} = this.sprite; | ||
|
||
context.clearRect(0, 0, frameWidth, frameHeight); | ||
} | ||
|
||
dislike() { | ||
|
||
} | ||
|
||
jump() { | ||
|
||
} | ||
|
||
eat() { | ||
|
||
} | ||
|
||
bounce() { | ||
const { | ||
chill, | ||
image, | ||
frameCount, | ||
frameHeight, | ||
frameWidth, | ||
} = this.sprite; | ||
|
||
var bounce = 0; | ||
var maxBounce = 2; | ||
var increment = 1; | ||
var currentFrame = 0; | ||
|
||
return (resolve) => { | ||
this.clear(); | ||
context.drawImage(image, currentFrame * frameWidth, chill * frameHeight, frameWidth, frameHeight, 0, 0, frameWidth, frameHeight); | ||
|
||
if (currentFrame === frameCount - 1) { | ||
increment = -1; | ||
} | ||
|
||
if (currentFrame === 0) { | ||
increment = 1; | ||
bounce++; | ||
} | ||
|
||
if (bounce == maxBounce) { | ||
resolve(); | ||
return true; | ||
} | ||
|
||
currentFrame += increment; | ||
}; | ||
|
||
|
||
// return (resolve) => { | ||
// goes up & down | ||
// moves left | ||
// goes up & down | ||
// moves right | ||
// repeat | ||
// }; | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,8 @@ | |
} | ||
|
||
.animation { | ||
left: 0; | ||
right: 0; | ||
bottom: 4%; | ||
left: 20%; | ||
margin: 0 auto; | ||
} |