# Learn phaser physics: bug invaders

So I was working on this project([https://www.codecademy.com/paths/create-video-games-with-phaser/tracks/game-dev-learn-phaser-basics-and-physics/modules/game-dev-learn-phaser-physics/projects/bug-invaders) and I got to step 21 and the project blanked on me. I thought it was originally just me making a mistake so I took out my initial mistake but the game screen just remained blank. I am unsure if this is a bug or me just being ignorant of other errors. If you all could take a look at my code and tell me if I did something wrong or I should be concerned. I am literally 7 steps away from the end and I would like to finish this today or tomorrow. Thank you in advance.

``````function preload() {
}

// Helper Methods below:
// sortedEnemies() returns an array of enemy sprites sorted by their x coordinate
function sortedEnemies(){
const orderedByXCoord = gameState.enemies.getChildren().sort((a, b) => a.x - b.x);
return orderedByXCoord;
}
// numOfTotalEnemies() returns the number of total enemies
function numOfTotalEnemies() {
const totalEnemies = gameState.enemies.getChildren().length;
}

const gameState = {};

function create() {
// When gameState.active is true, the game is being played and not over. When gameState.active is false, then it's game over
gameState.active = true;

// When gameState.active is false, the game will listen for a pointerup event and restart when the event happens
this.input.on('pointerup', () => {
if (gameState.active === false) {
this.scene.restart();
}
})

// Creating static platforms
platforms.create(225, 490, 'platform').setScale(1, .3).refreshBody();

// Displays the initial number of bugs, this value is initially hardcoded as 24
gameState.scoreText = this.add.text(175, 482, 'Bugs Left: 24', { fontSize: '15px', fill: '#000000' });

// Uses the physics plugin to create Codey

// Create Collider objects
gameState.player.setCollideWorldBounds(true);

// Creates cursor objects to be used in update()
gameState.cursors = this.input.keyboard.createCursorKeys();

for(let yVal = 1; yVal < 4; yVal++) {
for(let xVal = 1; xVal < 9; xVal++) {
gameState.enemies.create(50 * xVal, 50 * yVal, 'bug1').setScale(.6). setGravityY(-200);
}
}

const genPellet = () => {
let randomBug =
Phaser.Utils.Array.GetRandom(gameState.enemies.getChildren());
pellets.create(randomBug.x, randomBug.y, 'bugPellet')
}
delay: 300,
callback: genPellet,
callbackScope: this,
loop: true,
});
pellet.destroy();
});
gameState.active = false;
gameState.pelletsLoop.destroy();
this.physics.pause();
this.phyics.pause();
this.add.text(210, 250, 'Game Over /n Click to restart', {
fontSize: '15px', fill: '#000000'});
});

bug.destroy(),
repellent.destroy();
gameState.scoreText.setText(`Bugs Left\${numOfTotalEnemies()}`);
});
}

function update() {
if (gameState.active) {
// If the game is active, then players can control Codey
if (gameState.cursors.left.isDown) {
gameState.player.setVelocityX(-160);
} else if (gameState.cursors.right.isDown) {
gameState.player.setVelocityX(160);
} else {
gameState.player.setVelocityX(0);
}

// Execute code if the spacebar key is pressed
if (Phaser.Input.Keyboard.JustDown(gameState.cursors.space)) {
gameState.bugRepellent.create(gameState.player.x, gameState.player.y, 'bugRepellent').setGravityY(-400);
}

// Add logic for winning condition and enemy movements below:
if(numOfTotalEnemies() === 0) {
gameState.active = false;
this.add.text(350, 160, 'Victory, bugs exterminated!'{fontsize:'15px', fill:'#000000'});
}
const gameState = {
enemyVelocity: 1
}
}
}

const config = {
type: Phaser.AUTO,
width: 450,
height: 500,
backgroundColor: "b9eaff",
physics: {
gravity: { y: 200 },
enableBody: true,
}
},
scene: {