Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.
What is the problem with my code? var gunLoaded = true; var enemiesMovingLeft = false; var gameStarted = false; var enemiesRemaining = 4; var startTime; var elapsedTime; var energy_boltX; var energy_b
What is the problem with my code?
var gunLoaded = true;
var enemiesMovingLeft = false;
var gameStarted = false;
var enemiesRemaining = 4;
var startTime;
var elapsedTime;
var energy_boltX;
var energy_boltY;
onEvent("screen_game", "keydown", function(event) {
var shipX = getXPosition("image_ship");
var shipY = getYPosition("image_ship");
var distance = 12;
if(event.key == "Up");
{
shipY = shipY - distance;
}
if (event.key == "Down");
{
shipY = shipY + distance;
}
if (event.key == "Enter");
{
fire();
}
setPosition("image_ship", shipX, shipY);
verticalWrapAround ("image_ship");
});
function verticalWrapAround(object)
{
var objectX = getXposition(object);
var objectY = getYposition(object);
var objectHeight = getProperty(object, "height");
(if objectY < 0 - (objectHeight / 2));
{
objectY = 450 - (objectHeight / 2);
}
}
else if (object Y > 450 - objectHeight / 2);
{
objectY - 0 - (objectHeight / 2);
}
setPosition(objectX, objectY);
function fire()
if (gunLoaded) // gunLoaded == true;
gunLoaded = false;
var shipX = getXPosition("image_ship");
var shipY = getYPosition("image_ship");
var shipHeight = getProperty("image_ship", "height");
var shipWidth = getProperty("image_ship", "width");
var energyBoltHeight = getProperty("image_energy", "height");
var energyBoltX = shipX + shipWidth;
var energyBoltY = shipY + (shipHeight / 2) - (energyBoltHeight / 2);
setPosition("image_energy", energyBoltX, energyBoltY);
onEvent("button_start", "click", function(event) {
if(!gameStarted)
{
gameStarted = true;
setPosition ("button_start",100, 500);
startTime = getTime();
setPosition("image_energy", 400, 100);
timedLoop(50, function() {
updateTime();
moveEnergyBolt();
});
moveEnemy("image_enemy_one");
moveEnemy("image_enemy_two");
moveEnemy("image_enemy_three");
moveEnemy("image_enemy_four");
collisionDetection("image_enemy_one");
collisionDetection("image_enemy_two");
collisionDetection("image_enemy_three");
collisionDetection("image_enemy_four");
}
});
function updateTime()
{
var currentTime = getTime();
elapsedTime = currentTime - startTime
elapsedTime = (elapsedTime / 1000).toFixed(1);
setNumber("label_time", elapsedTime);
}
function moveEnergyBolt()
{
var energy_boltX = getXPosition("image_energy");
var energy_boltY = getYPosition("image_energy");
var energyBoltSpeed = energyBoltX / 10;
energyBoltX = energyBoltX + energyBoltSpeed;
setPosition("image_energy", energyBoltX, enenrgyBoltY);
if(enegryBoltX > 800)
gunLoaded = true;
}
function moveEnemy(name)
{
var enemyX = getXposition(name);
var enemyY = getYPosition(name);
var minX = 103;
var maxX = 200;
var distanceFromMax = maxX - enemyX;
var verticalSpeed = (distanceFromMax / 9) + 20;
var horizontalSpeed = Math.min(elapsedTime / 2), 16);
enemyY = enemyY + verticalSpeed;
if (enemyX > maxX)
enemiesMovingLeft = true;
if(enemyX < minX)
enemiesMovingLeft = false;
if(enemiesMovingLeft) // enemiesMovingLeft == true
enemyX = enemyX - horizontalSpeed;
else
enemyX = enemyX + horizontalSpeed;
setPosition(name, enemyX, enemyY);
verticalWrapAround(name);
}
function collisionDetection(object)
var energy_boltX = getXPosition("image_energy");
var energy_boltY = getYPosition("image_energy");
var objectX = getXPosition(object);
var objectY = getYPosition(object);
var energy_bolt_width = getProperty("image_energy", "width");
var energy_bolt_height = getProperty("image_energy", "height");
var objectWidth = getProperty(object,"width");
var objectHeight = getProperty(object, "height");
if(energy_boltX + energy_bolt_width >= objectX && energy_boltX <= objectX + objectWidth)
if(energy_boltY + energy_bolt_height >= objectY && energy_boltY <= objectY + objectHeight)
if(!getProperty(object, "hidden"))
hideElement(object);
enemiesRemaining--; // enemiesRemaining = enemiesRemaining - 1
if(enemiesRemaining <= 0)
stopTimedLoop();
hideElement("image_energy");