Original code:
"Game 1" by Joshua Rohweder
http://www.openprocessing.org/sketch/421818
Licensed under Creative Commons Attribution ShareAlike
https://creativecommons.org/licenses/by-sa/3.0
https://creativecommons.org/licenses/GPL/2.0/
How to run:
Download the entire folder.
Open index.html with a web browser. Firefox recommended. Microsoft edge also works.
IE may not support. Chrome may not support the background music.
Introduction to files:
index.html: html page
index.js: minimal usage of sketch
myclass.js: see below
SIL Open Font License: font license
backgroundmusic.mp3: background music
Brief introduction to myclass.js:
The class is to create a game, in which a moving ball bounces on coloured tiles.
Red tile reduces a life, yellow is combo bonus, cyan doubles height and pink reduces height.
The class includes 5 functions: draww, toreset, drawtiles, drawball and checklife.
draww()
draww calls the other functions. It contains two parts: gameover and !gameover. In gameover part, toreset is called if clicked, in !gameover part, other functions are called.
toreset()
toreset is also called in the constructor to initialize the game. This function gives each tile a number 0-5 representing its attributes.
drawtiles()
According to the number allocated in function toreset(), drawtiles function colours the tiles.
drawball()
drawball draws the ball.
checklife()
checklife is called when the ball hits the ground. Other than check how many lives are left, it also changes the score and combo.
For unknown reason, the callback way of loadSound supported by p5.js cannot run in class as it did in my original adaptation.