Last active
August 15, 2020 23:07
-
-
Save pedesen/ad3dc32d770918f379ca8e52ed82fcc2 to your computer and use it in GitHub Desktop.
Espruino Pac Man ghost animation
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
// Espruino Pac man ghost animation | |
// check this for more info: https://www.espruino.com/Graphics | |
const ghost = [` | |
#### | |
######## | |
########## | |
# #### ### | |
## ## | |
## #### ## | |
### #### ### | |
## #### #### | |
############## | |
############## | |
############## | |
############## | |
## ### ### ## | |
# ## ## # | |
`,` | |
#### | |
######## | |
########## | |
############ | |
## #### ## | |
# ## # | |
## ## ## | |
## ## ## ## ## | |
############## | |
############## | |
############## | |
############## | |
#### #### #### | |
## ## ## | |
`,` | |
#### | |
######## | |
########## | |
### #### # | |
## ## | |
## #### ## | |
### #### ### | |
#### #### ## | |
############## | |
############## | |
############## | |
############## | |
## ### ### ## | |
# ## ## # | |
`,` | |
#### | |
######## | |
########## | |
# ## ## ## # | |
# ## # | |
## ## ## | |
### #### ### | |
############## | |
############## | |
############## | |
############## | |
############## | |
#### #### #### | |
## ## ## | |
`]; | |
let ghostId; | |
const startGhostAnimation = (x, y, interval) => { | |
const ghostFrames = ghost.map((frame) => Graphics.createImage(frame)); | |
let currentFrame = 0; | |
ghostId = setInterval(() => { | |
g.clearRect(x, y, x+14, x+15); | |
g.drawImage(ghostFrames[currentFrame], x,y); | |
g.flip(); | |
currentFrame = (currentFrame + 1) % ghost.length; | |
}, interval); | |
}; | |
const stopGhostAnimation = () => { | |
clearInterval(ghostId); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment