Files
penguin-jump-p5js/platform.js

40 lines
873 B
JavaScript
Raw Normal View History

2026-06-24 19:56:56 +03:00
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;
}