first commit
|
After Width: | Height: | Size: 1.3 MiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 2.2 MiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 1003 KiB |
|
After Width: | Height: | Size: 790 KiB |
|
After Width: | Height: | Size: 94 KiB |
|
After Width: | Height: | Size: 247 KiB |
|
After Width: | Height: | Size: 312 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 31 KiB |
|
|
@ -0,0 +1,112 @@
|
|||
const config = {
|
||||
type: Phaser.AUTO,
|
||||
width: 1280,
|
||||
height: 800,
|
||||
physics: {
|
||||
default: 'arcade',
|
||||
arcade: {
|
||||
gravity: { y: 300 },
|
||||
debug: false
|
||||
}
|
||||
},
|
||||
scene: {
|
||||
preload: preload,
|
||||
create: create,
|
||||
update: update
|
||||
}
|
||||
};
|
||||
|
||||
const game = new Phaser.Game(config);
|
||||
|
||||
function preload() {
|
||||
this.load.image('background', 'assets/background.png');
|
||||
this.load.image('ground', 'assets/platforms.png');
|
||||
this.load.image('player', 'assets/player.png');
|
||||
this.load.image('player2', 'assets/player2.png');
|
||||
this.load.image('player_jump', 'assets/player_jump.png');
|
||||
this.load.image('bricks', 'assets/bricks.png');
|
||||
this.load.image('pee', 'assets/pee_test.png');
|
||||
|
||||
//Create an animation for walking left
|
||||
this.anims.create({
|
||||
key: 'walkLeft',
|
||||
frames: [
|
||||
{ key: 'player'},
|
||||
{ key: 'player2' }
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
let player, cursors, ground, platforms;
|
||||
|
||||
|
||||
function create() {
|
||||
// Add background image
|
||||
const background = this.add.image(0, 0, 'background').setOrigin(0, 0);
|
||||
background.scaleX = this.scale.width / background.width;
|
||||
background.scaleY = this.scale.height / background.height;
|
||||
|
||||
// Create ground
|
||||
platforms = this.physics.add.staticGroup();
|
||||
platforms.create(650, 750, 'ground')
|
||||
.setOffset(0, 50);
|
||||
|
||||
// Add Bricks
|
||||
platforms.create(600, 600, 'bricks').setScale(.5).refreshBody();
|
||||
platforms.create(1100, 400, 'bricks').setScale(.5).refreshBody();
|
||||
platforms.create(900, 250, 'bricks').setScale(.5).refreshBody();
|
||||
|
||||
// Add Platforms
|
||||
platforms.create(1200, 500, 'ground')
|
||||
.setScale(.5)
|
||||
.refreshBody()
|
||||
.setSize(1296/2, 50)
|
||||
.setOffset(0, 25);
|
||||
platforms.create(350, 300, 'ground')
|
||||
.setScale(.5)
|
||||
.refreshBody()
|
||||
.setSize(1296/2, 50)
|
||||
.setOffset(0, 25);
|
||||
|
||||
platforms.create(100, 250, 'pee')
|
||||
.setScale(.10)
|
||||
.refreshBody();
|
||||
|
||||
// Create player
|
||||
player = this.physics.add.sprite(200, 450, 'player');
|
||||
player.setBounce(0.2);
|
||||
player.setSize(100, 140);
|
||||
player.setOffset(30, 4);
|
||||
player.setCollideWorldBounds(true);
|
||||
|
||||
// Add controls
|
||||
cursors = this.input.keyboard.createCursorKeys();
|
||||
|
||||
// Add collision and sound
|
||||
this.physics.add.collider(player, platforms);
|
||||
//this.sound.add('jump', { volume: 0.5 });
|
||||
}
|
||||
|
||||
function update() {
|
||||
if (cursors.left.isDown) {
|
||||
player.setVelocityX(-160);
|
||||
player.setFlipX(false);
|
||||
//player.anims.play('walkLeft', true); // Play walking animation
|
||||
} else if (cursors.right.isDown) {
|
||||
player.setVelocityX(160);
|
||||
player.setFlipX(true);
|
||||
} else {
|
||||
player.setVelocityX(0);
|
||||
}
|
||||
|
||||
if (cursors.up.isDown && player.body.touching.down) {
|
||||
player.setVelocityY(-330);
|
||||
}
|
||||
|
||||
if (player.body.velocity.y > -1) {
|
||||
player.setTexture('player'); // Change texture back to normal when touching the ground
|
||||
} else {
|
||||
player.setTexture('player_jump'); // Change texture to jump
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>My Platformer Game</title>
|
||||
<style>
|
||||
body { margin: 0; }
|
||||
canvas { display: block; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<script src="https://cdn.jsdelivr.net/npm/phaser@v3.90.0/dist/phaser.min.js"></script>
|
||||
<script src="game.js"></script>
|
||||
</body>
|
||||
</html>
|
||||