feat(game): add drink collection mechanics and score tracking
- Added 'drink' image asset and loaded it in preload - Introduced drink collection logic with scoring system - Implemented overlap detection between player and drink items - Added score display that updates with collected drinks and earned points - Modified platform positioning and added physics interactions
This commit is contained in:
parent
b8e865fe05
commit
5de7951bdc
Binary file not shown.
|
After Width: | Height: | Size: 5.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 894 KiB |
44
game.js
44
game.js
|
|
@ -28,6 +28,7 @@ function preload() {
|
||||||
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');
|
this.load.image('clay', 'assets/platform_clay.png');
|
||||||
|
this.load.image('drink', 'assets/drink.png');
|
||||||
|
|
||||||
// //Create an animation for walking left
|
// //Create an animation for walking left
|
||||||
// this.anims.create({
|
// this.anims.create({
|
||||||
|
|
@ -39,7 +40,7 @@ function preload() {
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
let player, cursors, ground, platforms;
|
let player, cursors, ground, platforms, drinks=0, score = 0, scoreText;
|
||||||
|
|
||||||
function create() {
|
function create() {
|
||||||
// Add background image
|
// Add background image
|
||||||
|
|
@ -60,7 +61,8 @@ function create() {
|
||||||
|
|
||||||
// Add Elevators
|
// Add Elevators
|
||||||
//let elevators = this.physics.add.staticGroup();
|
//let elevators = this.physics.add.staticGroup();
|
||||||
let elevators = this.physics.add.image(400, 150, 'clay').setScale(.3).setOffset(0, 30);
|
let elevators = this.physics.add.image(400, 200, 'clay')
|
||||||
|
.setScale(.3);
|
||||||
|
|
||||||
// Add Platforms
|
// Add Platforms
|
||||||
platforms.create(1200, 500, 'ground')
|
platforms.create(1200, 500, 'ground')
|
||||||
|
|
@ -74,9 +76,8 @@ function create() {
|
||||||
.setSize(1296/2, 50)
|
.setSize(1296/2, 50)
|
||||||
.setOffset(0, 25);
|
.setOffset(0, 25);
|
||||||
|
|
||||||
// Decorations
|
// pee
|
||||||
decorations = this.physics.add.staticGroup();
|
peeTest = this.physics.add.image(100, 200, 'pee')
|
||||||
decorations.create(100, 250, 'pee')
|
|
||||||
.setScale(.10)
|
.setScale(.10)
|
||||||
.refreshBody();
|
.refreshBody();
|
||||||
|
|
||||||
|
|
@ -91,9 +92,40 @@ function create() {
|
||||||
|
|
||||||
// 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.physics.add.collider(player, elevators);
|
||||||
//this.sound.add('jump', { volume: 0.5 });
|
//this.sound.add('jump', { volume: 0.5 });
|
||||||
|
|
||||||
|
stars = this.physics.add.group({
|
||||||
|
key: 'drink',
|
||||||
|
repeat: 13,
|
||||||
|
setXY: { x: 200, y: 0, stepX: 70 }
|
||||||
|
});
|
||||||
|
|
||||||
|
stars.children.iterate(function (child) {
|
||||||
|
|
||||||
|
child.setBounceY(Phaser.Math.FloatBetween(0.4, 0.8));
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
this.physics.add.collider(stars, platforms);
|
||||||
|
this.physics.add.collider(peeTest, platforms);
|
||||||
|
this.physics.add.overlap(player, stars, collectDrink, null, this);
|
||||||
|
this.physics.add.overlap(player, peeTest, collectPee, null, this);
|
||||||
|
|
||||||
|
function collectDrink (player, star) {
|
||||||
|
star.disableBody(true, true);
|
||||||
|
drinks += 1;
|
||||||
|
scoreText.setText('Drinks: ' + drinks + ' Score: ' + score);
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectPee (player, peeTest) {
|
||||||
|
score += drinks * 10;
|
||||||
|
drinks = 0;
|
||||||
|
scoreText.setText('Drinks: ' + drinks + ' Score: ' + score);
|
||||||
|
}
|
||||||
|
|
||||||
|
scoreText = this.add.text(16, 16, 'Drinks: 0 Score: 0', { fontSize: '32px', fill: '#000' });
|
||||||
|
|
||||||
// Enable camera follow
|
// Enable camera follow
|
||||||
this.cameras.main.startFollow(player, true, 0, 0.1);
|
this.cameras.main.startFollow(player, true, 0, 0.1);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue