40 lines
873 B
JavaScript
40 lines
873 B
JavaScript
|
|
window.PLATFORMS_LIST = []
|
||
|
|
|
||
|
|
function getPlatforms() {
|
||
|
|
return PLATFORMS_LIST;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Spawn a platform in the world and append it to the platforms list for collision checking
|
||
|
|
* @param {number} X The X Coordinate of the platform
|
||
|
|
* @param {number} Y The Y Coordinate of the platform
|
||
|
|
*/
|
||
|
|
function spawnPlatform(X, Y) {
|
||
|
|
|
||
|
|
// Randomize Width a little bit
|
||
|
|
const DEFAULT_WIDTH = 125;
|
||
|
|
|
||
|
|
const newWidth = DEFAULT_WIDTH + ( (Math.random() - 0.5) * DEFAULT_WIDTH )
|
||
|
|
|
||
|
|
const platform = {
|
||
|
|
position: {
|
||
|
|
x: X,
|
||
|
|
y: Y,
|
||
|
|
},
|
||
|
|
size: {
|
||
|
|
x: newWidth,
|
||
|
|
y: 15,
|
||
|
|
},
|
||
|
|
step() {
|
||
|
|
|
||
|
|
},
|
||
|
|
draw() {
|
||
|
|
fill(newWidth, newWidth, 255)
|
||
|
|
rect(this.position.x, this.position.y, this.size.x, this.size.y)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
PLATFORMS_LIST.push(platform);
|
||
|
|
|
||
|
|
return platform;
|
||
|
|
}
|