Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8" />
- <title>WeWork Game</title>
- <!--<script src="//cdn.jsdelivr.net/phaser/2.2.2/phaser.min.js"></script>-->
- <script src="//cdn.jsdelivr.net/phaser/2.2.2/phaser.js"></script>
- <style type="text/css">
- body {
- margin: 0;
- }
- </style>
- </head>
- <body>
- <script type="text/javascript">
- var game = new Phaser.Game(/*2084, 1989*/1200, 600, Phaser.AUTO, '', { preload: preload, create: create, update: update});
- function preload() {
- //game.load.image('platform', './objects/platform.png')
- //game.load.image('background', './background/background.gif');
- //game.load.image('ground', './objects/platform.png');
- game.load.image('block', './objects/block.png');
- game.load.tilemap('level', './background/tilemaps/level1.json', null, Phaser.Tilemap.TILED_JSON);
- game.load.image('tiles', './background/tilemaps/tiles.png');
- game.load.spritesheet('zero', './characters/megaman.png', 50, 50);
- game.load.image('stars', './objects/energy.png');
- }
- var map;
- var backgroundLayer;
- var blockLayer;
- var patches;
- var player;
- var cursors;
- var block;
- //var platform;
- var stars;
- var score = 0;
- var scoreText;
- function create() {
- map = game.add.tilemap("level");
- map.addTilesetImage('tiles', 'tiles');
- blockLayer = map.createLayer('solids');
- blockLayer.reziseWorld();
- backgroundLayer = map.createLayer('cosmetics');
- backgroundLayer.resizeWorld();
- patches = map.createLayer('backing');
- patches.resizeWorld();
- // We're going to be using physics, so enable the Arcade Physics system
- game.physics.startSystem(Phaser.Physics.ARCADE);
- // A simple background for our game
- // game.add.sprite(0, 0, 'bg');
- block = game.add.group();
- block.enableBody = true;
- var blockA = block.create(20, 550, 'block');
- blockA.body.immovable = true;
- // The player and its settings
- player = game.add.sprite(50, game.world.height - 150, 'zero');
- // We need to enable physics on the player
- game.physics.arcade.enable(player);
- // Player physics properties.
- player.body.gravity.y = 1000;
- player.body.collideWorldBounds = true;
- // Our two animations, walking left and right.
- player.animations.add('stand', [0, 0, 0, 1, 0, 2], 5, true);
- player.animations.add('left', [3, 4, 5, 4], 5, true);
- player.animations.add('right', [3, 4, 5, 4], 5, true);
- player.animations.add('jump', [6], 30, true);
- //player.animations.add('jump', [6], true);
- // Finally some stars to collect
- stars = game.add.group();
- // We will enable physics for any stars that is created in this group
- stars.enableBody = true;
- // Here we'll create 12 of them evenly spaced apart
- for (var i = 0; i < 12; i++)
- {
- // Create a stars inside of the 'stars' group
- var star = stars.create(i * 70, 0, 'stars');
- // Let gravity do its thing
- star.body.gravity.y = 150;
- star.body.collideWorldBounds = true;
- // This just gives each stars a slightly random bounce value
- star.body.bounce.y = 0.7 + Math.random() * 0.2;
- }
- // The score
- scoreText = game.add.text(16, 16, 'Score: 0', { fontSize: '32px', fill: '#FFFFFF' });
- // Our controls.
- cursors = game.input.keyboard.createCursorKeys();
- //Command that uses camera to follow player
- game.camera.follow(player);
- }
- function update() {
- // Checks to see if the player overlaps with any of the stars, if he does call the collectstars function
- game.physics.arcade.overlap(player, stars, collectstars, null, this);
- game.physics.arcade.collide(player, block);
- // Reset the players velocity (movement)
- player.body.velocity.x = 0;
- if (cursors.left.isDown)
- {
- // Move to the left
- player.body.velocity.x = -150;
- player.animations.play('left');
- }
- else if (cursors.right.isDown)
- {
- // Move to the right
- player.body.velocity.x = 150;
- player.animations.play('right');
- }
- else
- {
- // Stand still
- player.animations.stop();
- player.animations.play('stand');
- }
- // Allow the player to jump if they are touching the ground.
- if (cursors.up.isDown && player.body.touching.down)
- {
- player.body.velocity.y = -450;
- player.animations.play('jump');
- }
- if (scoreText.text == 'Score: ' + 120) {
- game.add.text(50, 50, 'CONGRATULATIONS!!! You have collected ALL the Energy Orbs!', { fontSize: '32px', fill: '#FFFFFF' });
- }
- }
- function collectstars (player, stars) {
- // Removes the stars from the screen
- stars.kill();
- // Add and update the score
- score += 10;
- scoreText.text = 'Score: ' + score;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment