Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- const Game = new Phaser.Game(800, 800, Phaser.AUTO, 'game-canvas', { preload, create, update })
- let sprite, sprite2;
- function preload() {
- // 640x222, 5el in one line
- Game.load.spritesheet('bob', 'bob.png', 640 / 5, 222 / 1);
- }
- let counter = 0;
- let textVar;
- let speed = 5;
- let pos = 'up';
- function create() {
- sprite = Game.add.sprite(30, 20, 'bob');
- sprite.animations.add('walk', [0, 1, 2], 10, true);
- sprite.animations.play('walk');
- sprite.x = 0;
- sprite.y = 0;
- }
- function update() {
- switch (pos) {
- case 'left': sprite.x += speed; break;
- case 'right': sprite.x -= speed; break;
- case 'up': sprite.y -= speed; break;
- case 'down': sprite.y += speed; break;
- }
- switch (pos) {
- case 'left':
- if (sprite.x > Game.width - sprite.width) {
- pos = 'down';
- sprite.x = Game.width;
- }
- sprite.angle = 0;
- break;
- case 'down':
- if (sprite.y > Game.height - sprite.height) {
- pos = 'right';
- sprite.y = Game.height;
- }
- sprite.angle = 90;
- break;
- case 'right':
- if (sprite.x <= sprite.width) {
- pos = 'up';
- sprite.x = 0;
- }
- sprite.angle = 180;
- break;
- case 'up':
- if (sprite.y <= sprite.height) {
- pos = 'left';
- sprite. y = 0
- }
- sprite.angle = 270;
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement