Skip to content

Commit

Permalink
adds game objects and player animation
Browse files Browse the repository at this point in the history
  • Loading branch information
ceceliacreates committed Sep 15, 2023
1 parent 312b2d0 commit cbcf862
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions src/game/PlayScene.js
Expand Up @@ -4,13 +4,62 @@ export class PlayScene extends Scene {
constructor () {
super({ key: 'PlayScene' })
}


preload ()
{
this.load.image('star', 'assets/star.png');
this.load.image('bomb', 'assets/bomb.png');
this.load.image('platform', 'assets/platform.png');
this.load.image('leftArrow', 'assets/leftarrow.png');
this.load.image('rightArrow', 'assets/rightarrow.png');
this.load.spritesheet('player',
'assets/player.png',
{ frameWidth: 32, frameHeight: 48 }
);
}

create () {
this.add.text(100, 100, "PlayScene", {
font: "24px Courier",
fill: "#ffffff",

// sets game values based on screen size
this.screenWidth = this.scale.width;
this.screenHeight = this.scale.height;
this.screenCenterX = this.screenWidth / 2;
this.controlsAreaHeight = this.screenHeight * 0.2;
this.gameAreaHeight = this.screenHeight - this.controlsAreaHeight;

console.log(this.gameAreaHeight, this.controlsAreaHeight, this.screenHeight)

// adds the player, platform, and controls
this.platform = this.physics.add.staticImage(0, this.gameAreaHeight, 'platform').setOrigin(0, 0).refreshBody();
this.player = this.physics.add.sprite(this.screenCenterX, this.gameAreaHeight - 24, 'player');
this.leftArrow = this.add.image(this.screenWidth * 0.1, this.gameAreaHeight + 40, 'leftArrow').setOrigin(0, 0).setInteractive()
this.rightArrow = this.add.image(this.screenWidth * 0.7, this.gameAreaHeight + 40, 'rightArrow').setOrigin(0, 0).setInteractive()

// adds animations for player
if (!this.anims.exists('left')) {
this.anims.create({
key: "left",
frames: this.anims.generateFrameNumbers('player', { start: 0, end: 3 }),
frameRate: 10,
repeat: -1,
});

}

if (!this.anims.exists('turn')) {
this.anims.create({
key: "turn",
frames: [{ key: 'player', frame: 4 }],
});
}

if (!this.anims.exists('right')) {
this.anims.create({
key: "right",
frames: this.anims.generateFrameNumbers('player', { start: 5, end: 8 }),
frameRate: 10,
repeat: -1,
});
}

}

}

0 comments on commit cbcf862

Please sign in to comment.