// ---------------------------- // PORTALS // ---------------------------- let portals = []; // portal template: // { x, y, type } type = "blue" | "yellow" | "red" function applyPortal(type) { if (type === "blue") { speed = 2; player.gravity = 0.3; } if (type === "yellow") { speed = 4; player.gravity = 0.6; } if (type === "red") { speed = 8; player.gravity = 1.0; } } function drawPortals() { portals.forEach(p => { if (p.type === "blue") ctx.fillStyle = "lightblue"; if (p.type === "yellow") ctx.fillStyle = "yellow"; if (p.type === "red") ctx.fillStyle = "red"; ctx.fillRect(p.x, p.y, 20, 40); // collision with player if ( player.x < p.x + 20 && player.x + player.size > p.x && player.y < p.y + 40 && player.y + player.size > p.y ) { applyPortal(p.type); } }); portals = portals.filter(p => p.x > -50); }