Add platform_clay.png, update game.js with new assets and animations, add start_web.bat
This commit is contained in:
parent
bcf20226f4
commit
b8e865fe05
Binary file not shown.
|
After Width: | Height: | Size: 301 KiB |
50
game.js
50
game.js
|
|
@ -8,6 +8,7 @@ const config = {
|
||||||
gravity: { y: 300 },
|
gravity: { y: 300 },
|
||||||
debug: false
|
debug: false
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
scene: {
|
scene: {
|
||||||
preload: preload,
|
preload: preload,
|
||||||
|
|
@ -26,25 +27,26 @@ function preload() {
|
||||||
this.load.image('player_jump', 'assets/player_jump.png');
|
this.load.image('player_jump', 'assets/player_jump.png');
|
||||||
this.load.image('bricks', 'assets/bricks.png');
|
this.load.image('bricks', 'assets/bricks.png');
|
||||||
this.load.image('pee', 'assets/pee_test.png');
|
this.load.image('pee', 'assets/pee_test.png');
|
||||||
|
this.load.image('clay', 'assets/platform_clay.png');
|
||||||
|
|
||||||
//Create an animation for walking left
|
// //Create an animation for walking left
|
||||||
this.anims.create({
|
// this.anims.create({
|
||||||
key: 'walkLeft',
|
// key: 'walkLeft',
|
||||||
frames: [
|
// frames: [
|
||||||
{ key: 'player'},
|
// { key: 'player'},
|
||||||
{ key: 'player2' }
|
// { key: 'player2' }
|
||||||
]
|
// ]
|
||||||
});
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
let player, cursors, ground, platforms;
|
let player, cursors, ground, platforms;
|
||||||
|
|
||||||
|
|
||||||
function create() {
|
function create() {
|
||||||
// Add background image
|
// Add background image
|
||||||
const background = this.add.image(0, 0, 'background').setOrigin(0, 0);
|
const background = this.add.image(0, 0, 'background').setOrigin(0, 0);
|
||||||
background.scaleX = this.scale.width / background.width;
|
background.scaleX = this.scale.width / background.width;
|
||||||
background.scaleY = this.scale.height / background.height;
|
background.scaleY = this.scale.height / background.height;
|
||||||
|
background.setScrollFactor(0);
|
||||||
|
|
||||||
// Create ground
|
// Create ground
|
||||||
platforms = this.physics.add.staticGroup();
|
platforms = this.physics.add.staticGroup();
|
||||||
|
|
@ -56,6 +58,10 @@ function create() {
|
||||||
platforms.create(1100, 400, 'bricks').setScale(.5).refreshBody();
|
platforms.create(1100, 400, 'bricks').setScale(.5).refreshBody();
|
||||||
platforms.create(900, 250, 'bricks').setScale(.5).refreshBody();
|
platforms.create(900, 250, 'bricks').setScale(.5).refreshBody();
|
||||||
|
|
||||||
|
// Add Elevators
|
||||||
|
//let elevators = this.physics.add.staticGroup();
|
||||||
|
let elevators = this.physics.add.image(400, 150, 'clay').setScale(.3).setOffset(0, 30);
|
||||||
|
|
||||||
// Add Platforms
|
// Add Platforms
|
||||||
platforms.create(1200, 500, 'ground')
|
platforms.create(1200, 500, 'ground')
|
||||||
.setScale(.5)
|
.setScale(.5)
|
||||||
|
|
@ -68,31 +74,45 @@ function create() {
|
||||||
.setSize(1296/2, 50)
|
.setSize(1296/2, 50)
|
||||||
.setOffset(0, 25);
|
.setOffset(0, 25);
|
||||||
|
|
||||||
platforms.create(100, 250, 'pee')
|
// Decorations
|
||||||
|
decorations = this.physics.add.staticGroup();
|
||||||
|
decorations.create(100, 250, 'pee')
|
||||||
.setScale(.10)
|
.setScale(.10)
|
||||||
.refreshBody();
|
.refreshBody();
|
||||||
|
|
||||||
// Create player
|
// Create player
|
||||||
player = this.physics.add.sprite(200, 450, 'player');
|
player = this.physics.add.sprite(645, 450, 'player');
|
||||||
player.setBounce(0.2);
|
player.setBounce(0.2);
|
||||||
player.setSize(100, 140);
|
player.setSize(100, 140);
|
||||||
player.setOffset(30, 4);
|
player.setOffset(30, 4);
|
||||||
player.setCollideWorldBounds(true);
|
|
||||||
|
|
||||||
// Add controls
|
// Add controls
|
||||||
cursors = this.input.keyboard.createCursorKeys();
|
cursors = this.input.keyboard.createCursorKeys();
|
||||||
|
|
||||||
// Add collision and sound
|
// Add collision and sound
|
||||||
this.physics.add.collider(player, platforms);
|
this.physics.add.collider(player, platforms);
|
||||||
|
//this.physics.add.collider(player, elevators);
|
||||||
//this.sound.add('jump', { volume: 0.5 });
|
//this.sound.add('jump', { volume: 0.5 });
|
||||||
|
|
||||||
|
// Enable camera follow
|
||||||
|
this.cameras.main.startFollow(player, true, 0, 0.1);
|
||||||
|
|
||||||
|
this.tweens.add({
|
||||||
|
targets: elevators,
|
||||||
|
y: -150,
|
||||||
|
duration: 4000,
|
||||||
|
repeat: -1, // Repeat infinitely
|
||||||
|
yoyo: true, // Go back to the original position after reaching the target
|
||||||
|
ease: 'Linear' // You can change this to other easing functions like 'Sine', 'Cubic', etc.
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function update() {
|
||||||
if (cursors.left.isDown) {
|
if (cursors.left.isDown && player.body.x > 0) {
|
||||||
player.setVelocityX(-160);
|
player.setVelocityX(-160);
|
||||||
player.setFlipX(false);
|
player.setFlipX(false);
|
||||||
//player.anims.play('walkLeft', true); // Play walking animation
|
//player.anims.play('walkLeft', true); // Play walking animation
|
||||||
} else if (cursors.right.isDown) {
|
} else if (cursors.right.isDown && player.body.x < 1280 - 100) {
|
||||||
player.setVelocityX(160);
|
player.setVelocityX(160);
|
||||||
player.setFlipX(true);
|
player.setFlipX(true);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
python -m http.server 8000
|
||||||
Loading…
Reference in New Issue