1+ <!DOCTYPE HTML>
2+ <html>
3+ <head>
4+ <title>phaser.js - a new beginning</title>
5+ <?php
6+ require ('js.php ' );
7+ ?>
8+ </head>
9+ <body>
10+
11+ <script type="text/javascript">
12+
13+ (function () {
14+
15+ var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { preload: preload, create: create, update: update, render: render });
16+
17+ function preload() {
18+ game.load.image('car', 'assets/sprites/car90.png');
19+ game.load.image('ship', 'assets/sprites/xenon2_ship.png');
20+ game.load.image('baddie', 'assets/sprites/space-baddie.png');
21+ }
22+
23+ var car;
24+ var ship;
25+ var total;
26+ var aliens;
27+
28+ function create() {
29+
30+ aliens = [];
31+
32+ for (var i = 0; i < 50; i++)
33+ {
34+ var s = game.add.sprite(game.world.randomX, game.world.randomY, 'baddie');
35+ s.name = 'alien' + s;
36+ s.body.collideWorldBounds = true;
37+ s.body.bounce.setTo(1, 1);
38+ s.body.velocity.setTo(10 + Math.random() * 40, 10 + Math.random() * 40);
39+ aliens.push(s);
40+ }
41+
42+ car = game.add.sprite(400, 300, 'car');
43+ car.anchor.setTo(0.5, 0.5);
44+ car.body.collideWorldBounds = true;
45+ car.body.bounce.setTo(0.5, 0.5);
46+ car.body.allowRotation = true;
47+
48+ ship = game.add.sprite(400, 400, 'ship');
49+ ship.body.collideWorldBounds = true;
50+ ship.body.bounce.setTo(0.5, 0.5);
51+
52+ }
53+
54+ function update() {
55+
56+ car.body.velocity.x = 0;
57+ car.body.velocity.y = 0;
58+ car.body.angularVelocity = 0;
59+
60+ if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
61+ {
62+ car.body.angularVelocity = -200;
63+ }
64+ else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
65+ {
66+ car.body.angularVelocity = 200;
67+ }
68+
69+ if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
70+ {
71+ car.body.velocity.copyFrom(game.physics.velocityFromAngle(car.angle, 300));
72+ }
73+
74+ game.physics.collideGroup(aliens);
75+ // total = game.physics.overlap(ship);
76+
77+ }
78+
79+ function render() {
80+
81+ // game.debug.renderQuadTree(game.physics.quadTree);
82+ // game.debug.renderRectangle(ship.body.bounds);
83+
84+ // game.debug.renderText('total: ' + total.length, 32, 50);
85+
86+ // game.debug.renderText('up: ' + ship.body.touching.up, 32, 70);
87+ // game.debug.renderText('down: ' + ship.body.touching.down, 32, 90);
88+ // game.debug.renderText('left: ' + ship.body.touching.left, 32, 110);
89+ // game.debug.renderText('right: ' + ship.body.touching.right, 32, 130);
90+
91+ }
92+
93+ })();
94+
95+ </script>
96+
97+ </body>
98+ </html>
0 commit comments