diff --git a/assets/drink.png b/assets/drink.png new file mode 100644 index 0000000..69552f8 Binary files /dev/null and b/assets/drink.png differ diff --git a/assets/original/drink.png b/assets/original/drink.png new file mode 100644 index 0000000..45ed2dd Binary files /dev/null and b/assets/original/drink.png differ diff --git a/game.js b/game.js index 223dc60..c95de82 100644 --- a/game.js +++ b/game.js @@ -28,6 +28,7 @@ function preload() { this.load.image('bricks', 'assets/bricks.png'); this.load.image('pee', 'assets/pee_test.png'); this.load.image('clay', 'assets/platform_clay.png'); + this.load.image('drink', 'assets/drink.png'); // //Create an animation for walking left // 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() { // Add background image @@ -60,7 +61,8 @@ function create() { // Add Elevators //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 platforms.create(1200, 500, 'ground') @@ -74,9 +76,8 @@ function create() { .setSize(1296/2, 50) .setOffset(0, 25); - // Decorations - decorations = this.physics.add.staticGroup(); - decorations.create(100, 250, 'pee') + // pee + peeTest = this.physics.add.image(100, 200, 'pee') .setScale(.10) .refreshBody(); @@ -91,9 +92,40 @@ function create() { // Add collision and sound 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 }); + 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 this.cameras.main.startFollow(player, true, 0, 0.1);