Commit fabc9fd8 authored by Sander Kvenild's avatar Sander Kvenild
Browse files

MAde a toggle for rectangle generator

parent e7b88b76
......@@ -128,7 +128,14 @@
canvas.addEventListener("mousedown",musklikk,false);
canvas.addEventListener("mousemove",musbeveg,false);
// Output div
var shapeText = document.getElementById("shape")
var spawnRectangle = document.getElementById("rectangle")
// Flags
let rectangleClick = false;
let rectangleGenerator = false;
window.addEventListener("keypress",keypress,false);
var former = [];
......@@ -151,6 +158,9 @@
}
function nyRektangel() {
if (!rectangleGenerator) {
return;
}
let x = Math.floor(Math.random() * canvas.width);
let y = Math.floor(Math.random() * canvas.height);
let w = Math.floor(Math.random() * 50 + 20);
......@@ -183,7 +193,7 @@
}
if(fikkvalgtenboble == false) {
if (shapeText.innerText == "Sirkel") {
if (!rectangleClick) {
let r = Math.floor(Math.random() * 40 + 10);
let b = new Boble(event.x,event.y,r);
former.push(b);
......@@ -220,12 +230,18 @@
}
function keypress(event) {
if (event.code == 'KeyM') {
if (shapeText.innerText == "Sirkel") {
shapeText.innerText = "Rektangel";
} else {
shapeText.innerText = "Sirkel";
}
switch (event.code) {
case 'KeyM':
rectangleClick = !rectangleClick;
shapeText.innerText = rectangleClick ? "Rektangel" : "Sirkel"
break;
case 'KeyN':
rectangleGenerator = !rectangleGenerator;
spawnRectangle.innerText = rectangleGenerator;
break;
default:
console.log(`${event.code} is not assigned to a function`);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment