|
| 1 | + |
| 2 | + <?php |
| 3 | + $title = "Following the player"; |
| 4 | + require('../head.php'); |
| 5 | +?> |
| 6 | + |
| 7 | +<script type="text/javascript"> |
| 8 | + |
| 9 | +(function () { |
| 10 | + |
| 11 | + var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update }); |
| 12 | + |
| 13 | + var baddie, |
| 14 | + keys=Phaser.Keyboard; |
| 15 | + |
| 16 | + function preload() { |
| 17 | + |
| 18 | + game.load.image('background','assets/misc/starfield.jpg'); |
| 19 | + game.load.image('ufo','assets/sprites/ufo.png'); |
| 20 | + game.load.image('baddie','assets/sprites/space-baddie.png'); |
| 21 | + |
| 22 | + |
| 23 | + } |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + function create() { |
| 28 | + |
| 29 | + game.add.tileSprite(0, 0, 2000, 2000, 'background'); |
| 30 | + |
| 31 | + game.world.setSize(1400,1400); |
| 32 | + |
| 33 | + for(var i=0,nb=10;i<nb;i++){ |
| 34 | + |
| 35 | + game.add.sprite(game.world.randomX,game.world.randomY,'ufo'); |
| 36 | + } |
| 37 | + |
| 38 | + baddie=game.add.sprite(150,320,'baddie'); |
| 39 | + |
| 40 | + game.camera.follow(baddie); |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + function update() { |
| 45 | + |
| 46 | + baddie.body.velocity.x=baddie.body.velocity.y=0; |
| 47 | + |
| 48 | + |
| 49 | + if(game.input.keyboard.isDown(keys.LEFT) && !game.input.keyboard.isDown(keys.RIGHT)){ |
| 50 | + |
| 51 | + baddie.body.velocity.x=-155; |
| 52 | + |
| 53 | + } |
| 54 | + else if(game.input.keyboard.isDown(keys.RIGHT) && !game.input.keyboard.isDown(keys.LEFT)){ |
| 55 | + baddie.body.velocity.x=155; |
| 56 | + |
| 57 | + } |
| 58 | + else if(game.input.keyboard.isDown(keys.UP) && !game.input.keyboard.isDown(keys.DOWN)){ |
| 59 | + |
| 60 | + baddie.angle=90; |
| 61 | + baddie.body.velocity.y=-155; |
| 62 | + |
| 63 | + } |
| 64 | + else if(game.input.keyboard.isDown(keys.DOWN) && !game.input.keyboard.isDown(keys.UP)){ |
| 65 | + baddie.angle=90; |
| 66 | + baddie.body.velocity.y=155; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | +})(); |
| 71 | + |
| 72 | +</script> |
| 73 | + |
| 74 | +<?php |
| 75 | + require('../foot.php'); |
| 76 | +?> |
0 commit comments