var config = {
type: Phaser.AUTO,
parent: 'phaser-example',
width: 656,
height: 952,
physics: {
default: "arcade",
arcade: {
gravity: {y: 200},
}
},
backgroundColor: 0x000000,
scene: [content, homepage, pickship, Game1, Game2]
};
var game = new Phaser.Game(config);
my preload
this.load.image(“background”, “assets/space.png”);
this.load.image(“ast”, “assets/spaceship.png”);
this.load.image(“laser”, “assets/laser.png”);
this.load.image(“enemy”, “assets/enemy.png”);
var score = 0;
var cursors;
var enemy;
var bullet;
var bullets;
var reset;
var player;
class Game1 extends Phaser.Scene {
constructor() {
super(“gameova”);
}
create() {
var Bullet = new Phaser.Class
({
Extends: Phaser.GameObjects.Image,
initialize:
function Bullet (scene)
{
Phaser.GameObjects.Image.call(this, scene, 0, 0, "laser");
this.speed = Phaser.Math.GetSpeed(300, 1);
},
fire: function (x, y)
{
this.setPosition(x, y);
this.setActive(true);
this.setVisible(true);
},
update: function (time, delta)
{
this.y -= this.speed * delta;
if (this.y > 822)
{
this.setActive(false);
this.setVisible(false);
}
}
});
bullets = this.physics.add.group({
classType: Bullet,
maxSize: 10000,
runChildUpdate: true
});
this.background = this.add.tileSprite(0, 0, config.width, config.height, "background")
this.background.setOrigin(0, 0);
Game1.score = this.add.text(12, 10, "Score" + score, {font: "24px Arial", fill: "white"});
cursors = this.input.keyboard.createCursorKeys();
player = this.add.image(config.width/2 +10, config.height/2 +10, "ast").setScale(0.56);
enemy = this.physics.add.group({
key: "enemy",
repeat: 4,
setXY: {x: 122, y: 4, stepX: 100}
});
this.physics.add.collider(this.enemy, this.bullet, this.enemyDone, null, this);
//the enemyDone function
//player.setCollideWorldBounds(true); this is also a problem because it says its not a function
reset = this.add.text(580, 10, "Reset", {font: "24px Arial", fill: "yellow"});
reset.inputEnabled = true;
reset.setInteractive();
reset.on("pointerdown", function (pointer) {
this.scene.start("gamee");
}, this)
}
update(time, delta) {
this.background.tilePositionY -= 0.4;
if (cursors.left.isDown) {
player.x -= 10;
}
else if (cursors.right.isDown) {
player.x += 10;
}
if (cursors.up.isDown) {
player.y -= 10;
}
else if (cursors.down.isDown) {
player.y += 10;
}
else if (cursors.space.isDown) {
bullet = bullets.get();
if (bullet)
{
bullet.fire(player.x, player.y);
}
}
score++;
Game1.score.setText("Score: " + score);
}
}
function enemyDone(bullet, enemy)
{
enemy.disableBody(true, true);
}
//problem is this function