I am pretty new to programming, so in all honesty, I probably just made a really simple mistake. I am trying to run a game made in JavaScript, by using script tags in html. This is the code for the unfinished game:
var bulletDrawn = false;
var bulletShot = false;
var bulletSpeed = 10;
noStroke();
var keys = [];
keyPressed = function(){keys[keyCode]=true;};
keyReleased = function(){keys[keyCode]=false;};
var fScale = 0.45;
var drawBackground = function(){
background(0);
fill(120, 103, 160);
rect(10, 24, 3, 3);
fill(5, 150, 102);
rect(224, 35, 3, 3);
fill(106, 4, 170);
rect(201, 292, 3, 3);
fill(238, 1, 141);
rect(47, 259, 3, 3);
fill(255, 42, 71);
rect(120, 81, 3, 3);
fill(96, 221, 30);
rect(337, 347, 3, 3);
fill(5, 150, 102);
rect(292, 167, 3, 3);
fill(255, 255, 255);
};
var drawFighter = function(x, y){
fill(255, 255, 255);
rect(x, y, 5, 15);
rect(x-5, y+15, 15, 10);
rect(x-5, y+25, 5, 5);
rect(x+5, y+25, 5, 5);
rect(x-25,y+40, 55, 5);
rect(x, y+35, 5, 20);
rect(x-25, y+35, 5, 20);
rect(x+25, y+35, 5, 20);
rect(x-20, y+45, 5, 5);
rect(x+20, y+45, 5, 5);
rect(x-15, y+20, 5, 10);
rect(x+15, y+20, 5, 10);
rect(x-10, y+30, 5, 10);
rect(x+10, y+30, 5, 10);
rect(x-15, y+35, 5, 5);
rect(x+15, y+35, 5, 5);
fill(75, 103, 255);
rect(x-10, y+25, 5, 5);
rect(x+10, y+25, 5, 5);
rect(x-15, y+30, 5, 5);
rect(x+15, y+30, 5, 5);
fill(255, 0, 1);
rect(x-15, y+15, 5, 5);
rect(x+15, y+15, 5, 5);
rect(x+25, y+30, 5, 5);
rect(x-25, y+30, 5, 5);
rect(x, y+25, 5, 10);
rect(x-5, y+30, 5, 10);
rect(x+5, y+30, 5, 10);
rect(x-10, y+45, 10, 5);
rect(x+5, y+45, 10, 5);
};
var drawEnemyFly = function(x, y){
fill(0, 102, 255);
rect(x, y, 2, 4);
rect(x+4, y, 2, 4);
rect(x,y+10, 6, 4);
rect(x, y+16, 6, 2);
fill(255, 255, 255);
rect(x, y+6, 6, 4);
rect(x-2, y+4, 2, 4);
rect(x+2, y+4, 2, 2);
rect(x+6, y+4, 2, 4);
rect(x, y+14, 6, 2);
fill(255, 0, 1);
rect(x, y+4, 2, 2);
rect(x+4, y+4, 2, 2);
rect(x-6, y, 2, 2);
rect(x+10, y, 2, 2);
rect(x-10, y+2, 6, 6);
rect(x+10, y+2, 6, 6);
rect(x-6, y+8, 6, 8);
rect(x+6, y+8, 6, 8);
rect(x-8, y+8, 2, 2);
rect(x+12, y+8, 2, 2);
rect(x-8, y+12, 2, 6);
rect(x+12, y+12, 2, 6);
rect(x-10, y+14, 2, 2);
rect(x+14, y+14, 2, 2);
rect(x-6, y+16, 4, 2);
rect(x+9, y+16, 5, 2);
rect(x-4, y+18, 2, 2);
rect(x+9, y+18, 2, 2);
};
var fighter = {
x:189,
y:750
};
var bullet = {
x: fighter.x,
y: fighter.y,
size:3,
drawMe: function() {
fill(250, 250, 250);
drawBackground();
rect(bullet.x *fScale, bullet.y*fScale, bullet.size, bullet.size);
}
};
var enemyFly1 = {
x:230,
y:100,
power:1
};
var checkKeys = function(){
if(keys[LEFT] && fighter.x>25*1/fScale-25){
fighter.x=fighter.x-4;
}
if(keys[RIGHT] && fighter.x<370*1/fScale+30){
fighter.x=fighter.x+4;
}
if(keyCode === 32) {
bulletDrawn = true;
bulletShot = true;
bullet.x=fighter.x;
bullet.y=fighter.y;
}
};
var drawBullet = function() {
fill(255, 255, 255);
bullet.drawMe();
bullet.y = bullet.y - bulletSpeed;
};
var checkCollision = function(){
};
var enemyMovement = function(){
var pFighterX = fighter.x*fScale;
if(enemyFly1.x>pFighterX){
enemyFly1.x=enemyFly1.x-enemyFly1.power;
}
if(enemyFly1.x<pFighterX){
enemyFly1.x=enemyFly1.x+1;
}
};
var drawMenu = function(){};
var drawScene1 = function(){
var gamePlayed = true;
checkKeys();
enemyMovement();
if(bulletDrawn && bullet.y <= 750) {
fill(255, 255, 255);
drawBullet();
}
if(bullet.y < 0) {
bullet.y=fighter.y;
bulletDrawn = false;
}
drawBackground();
pushMatrix();
scale(fScale);
drawFighter(fighter.x, fighter.y);
popMatrix();
drawEnemyFly(enemyFly1.x, enemyFly1.y);
};
draw = function() {
drawScene1();
};
After I put this code in HTML tags, saved the file as a .html file, and then ran the file, It opened a blank page, with the title being the file location on my computer. What did I do wrong?