1010 function preload() {
1111
1212 game.load.atlas('tank', 'assets/games/tanks/tanks.png', 'assets/games/tanks/tanks.json');
13- game.load.image('bullet', 'assets/sprites/enemy- bullet.png');
13+ game.load.image('bullet', 'assets/games/tanks/ bullet.png');
1414 game.load.image('earth', 'assets/games/tanks/scorched_earth.png');
1515
1616 }
1717
18+ var land;
19+
20+ var shadow;
1821 var tank;
1922 var turret;
20- var shadow;
2123
22- var currentSpeed = 0;
23-
24- var land;
24+ var enemy;
2525
26+ var currentSpeed = 0;
2627 var cursors;
27- var bullets;
2828
29+ var bullets;
2930 var fireRate = 100;
3031 var nextFire = 0;
3132
3233 function create() {
3334
3435 // Resize our game world to be a 2000x2000 square
35- // game.world.setBounds(-1000, -1000, 2000, 2000);
36- game.world.setBounds(0, 0, 1000, 1000);
37-
38- console.log(game.world.bounds.right, 'bot', this.game.world.bounds.bottom);
39- console.log(game.camera.bounds.right, 'cbot', this.game.camera.bounds.bottom);
36+ game.world.setBounds(-1000, -1000, 2000, 2000);
4037
4138 // Our tiled scrolling background
4239 land = game.add.tileSprite(0, 0, 800, 600, 'earth');
@@ -46,37 +43,46 @@ function create() {
4643 shadow = game.add.sprite(0, 0, 'tank', 'shadow');
4744 shadow.anchor.setTo(0.5, 0.5);
4845
46+ // Our bullet group
47+ bullets = game.add.group();
48+ bullets.createMultiple(50, 'bullet');
49+ bullets.setAll('anchor.x', 0.5);
50+ bullets.setAll('anchor.y', 0.5);
51+ bullets.setAll('outOfBoundsKill', true);
52+
4953 // The base of our tank
5054 tank = game.add.sprite(0, 0, 'tank', 'tank1');
5155 tank.anchor.setTo(0.5, 0.5);
5256 tank.animations.add('move', ['tank1', 'tank2', 'tank3', 'tank4', 'tank5', 'tank6'], 20, true);
53- tank.play('move');
57+ // tank.play('move');
5458
5559 // This will force it to decelerate and limit its speed
5660 tank.body.drag.setTo(200, 200);
5761 tank.body.maxVelocity.setTo(400, 400);
5862 tank.body.collideWorldBounds = true;
5963
60- // Our bullet group
61- bullets = game.add.group();
62- bullets.createMultiple(50, 'bullet');
63- bullets.setAll('anchor.x', 0.5);
64- bullets.setAll('anchor.y', 0.5);
65- bullets.setAll('outOfBoundsKill', true);
6664
6765 // Finally the turret that we place on-top of the tank body
6866 turret = game.add.sprite(0, 0, 'tank', 'turret');
69- turret.anchor.setTo(0.5, 0.5);
67+ turret.anchor.setTo(0.3, 0.5);
68+
69+ enemy = game.add.sprite(900, 400, 'tank', 'tank1');
70+ enemy.anchor.setTo(0.5, 0.5);
71+ enemy.body.immovable = true;
72+ enemy.body.collideWorldBounds = true;
7073
7174 game.camera.follow(tank);
72- // game.camera.deadzone = new Phaser.Rectangle(100, 100, 600, 400);
75+ game.camera.deadzone = new Phaser.Rectangle(100, 100, 600, 400);
76+ game.camera.focusOnXY(0, 0);
7377
7478 cursors = game.input.keyboard.createCursorKeys();
7579
7680 }
7781
7882 function update() {
7983
84+ game.physics.collide(tank, enemy);
85+
8086 if (cursors.left.isDown)
8187 {
8288 tank.angle -= 4;
@@ -139,7 +145,7 @@ function fire() {
139145
140146 bullet.reset(turret.x, turret.y);
141147
142- game.physics.moveToPointer(bullet, 1000);
148+ bullet.rotation = game.physics.moveToPointer(bullet, 1000);
143149 }
144150
145151 }
@@ -151,15 +157,10 @@ function render() {
151157 // game.debug.renderText('sr: ' + tank.body.right, 32, 100);
152158 // game.debug.renderText('sb: ' + tank.body.bottom, 32, 132);
153159
154- game.debug.renderSpriteCorners(tank, true, true);
160+ // game.debug.renderSpriteCorners(tank, true, true);
155161
156162 game.debug.renderCameraInfo(game.camera, 500, 32);
157-
158- game.debug.renderLocalTransformInfo(tank, 32, 32);
159- game.debug.renderWorldTransformInfo(tank, 32, 200);
160-
161-
162- // game.debug.renderSpriteInfo(sprite, 32, 450);
163+ game.debug.renderSpriteInfo(tank, 32, 450);
163164
164165 }
165166
0 commit comments