Reputation: 140
I have a simple program, but I have an issue. I previously had a problem with the page displaying "Loading..." before, but I fixed that. Whenever I try to load now, I get "localhost refused to connect". I have tried the internet but all the fixes seem to be for the first error. How do I get it to load? Here is the code:
let pew;
let crosshair;
let imgConst = 100;
var imgSize = imgConst;
var imgChange = [4, (6 + 2/3), 10, -10, -10, -10, -10, -20, (-33 - 1/3), -50];
for(var i = 0; i = imgChange.length; i++) {
imgChange[i] = imgSize + imgConst/imgChange[i]
console.log(i)
}
function preload() {
crosshair = loadImage('crosshair.png')
}
function setup() {
createCanvas(windowWidth, windowHeight);
frameRate(10);
noStroke();
noCursor();
pew = new bullet();
}
function draw() {
background(50, 89, 100);
//Shrink bullets
pew.shrink()
//crosshair
image(crosshair, mouseX - imgSize/2, mouseY - imgSize/2, imgSize, imgSize);
}
// bullet class
class bullet {
constructor() {
this.x = [];
this.y = [];
this.size = [];
this.shrinkSpeed = 1;
this.diameter = 10;
}
shrink() {
fill(61, 41, 15)
for(var i = 0; i < this.x.length; i++) {
if(this.size[i] <= 1) {
this.size.splice(i);
} else {
ellipse(this.x[i], this.y[i], this.size[i], this.size[i]);
this.size[i] = this.size[i] - this.shrinkSpeed;
}
}
}
add() {
this.x.push(mouseX);
this.y.push(mouseY);
this.size.push(this.diameter)
for( i = 0; i < imgChange.length * 1; i ++) {
imgSize = imgChange[floor(i)]
console.log(imgSize);
}
}
}
function mousePressed() {
//add bullet
pew.add();
}
Upvotes: 0
Views: 1437
Reputation: 681
You have 2 problems in for loops.
First, in your first for loop, change i = imgChange.length
to i < imgChange.length
. Second, you are missing a var
in the add()
function of your bullet class: for( i = 0
.
Now, your code should run.
Upvotes: 1