Commit 37bfed8f authored by Sander Kvenild's avatar Sander Kvenild
Browse files

Chenged name of array to better fit current use

parent e510cbf6
......@@ -84,7 +84,6 @@
ctx.strokeRect(this.x,this.y,this.w,this.h);
}
inneholder(musx,musy) {
// TODO: remake for rectangle
if (musx > this.x && musx < this.x + this.w &&
musy > this.y && musy < this.y + this.h)
{
......@@ -103,7 +102,7 @@
var shapeText = document.getElementById("shape")
window.addEventListener("keypress",keypress,false);
var bobler = [];
var former = [];
for(let i = 0; i < 10; i++) {
nyBoble();
......@@ -119,24 +118,23 @@
let r = Math.floor(Math.random() * 40 + 10);
let x = Math.floor(Math.random() * canvas.width - r);
let y = Math.floor(Math.random() * canvas.height - r);
bobler.push(new Boble(x,y,r));
former.push(new Boble(x,y,r));
}
function nyRektangel() {
// TODO: add usage
let x = Math.floor(Math.random() * canvas.width);
let y = Math.floor(Math.random() * canvas.height);
let w = Math.floor(Math.random() * 50 + 20);
let h = Math.floor(Math.random() * 50 + 20);
bobler.push(new Rektangel(x,y,w,h)); // TODO: Create new array for rektangler
former.push(new Rektangel(x,y,w,h));
}
function tegn() {
reset();
for(let i = 0; i < bobler.length; i++) {
bobler[i].flytt();
bobler[i].sjekk();
bobler[i].vis();
for(let i = 0; i < former.length; i++) {
former[i].flytt();
former[i].sjekk();
former[i].vis();
}
}
......@@ -148,9 +146,9 @@
function musklikk(event) {
var fikkvalgtenboble = false;
for(let i = 0; i < bobler.length; i++) {
if(bobler[i].inneholder(event.x,event.y)) {
bobler.splice(i,1);
for(let i = 0; i < former.length; i++) {
if(former[i].inneholder(event.x,event.y)) {
former.splice(i,1);
fikkvalgtenboble = true;
}
}
......@@ -159,22 +157,22 @@
if (shapeText.innerText == "Sirkel") {
let r = Math.floor(Math.random() * 40 + 10);
let b = new Boble(event.x,event.y,r);
bobler.push(b);
former.push(b);
} else {
let w = Math.floor(Math.random() * 50 + 20);
let h = Math.floor(Math.random() * 50 + 20);
let r = new Rektangel(event.x - w/2,event.y - h/2,w,h);
bobler.push(r);
former.push(r);
}
}
}
function musbeveg(event) {
for(let i = 0; i < bobler.length; i++) {
if(bobler[i].inneholder(event.x,event.y)) {
bobler[i].farge = "red";
for(let i = 0; i < former.length; i++) {
if(former[i].inneholder(event.x,event.y)) {
former[i].farge = "red";
} else {
bobler[i].farge = bobler[i].orginalFarge;
former[i].farge = former[i].orginalFarge;
}
}
}
......
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