mirror of
https://github.com/wassname/phaser.git
synced 2026-09-11 12:31:29 +08:00
Added the GameObjectManager
This commit is contained in:
@@ -16,7 +16,8 @@
|
||||
myGame.loader.load();
|
||||
|
||||
}
|
||||
|
||||
var CACTUS = 31;
|
||||
var SIGN_POST = 46;
|
||||
var map: Phaser.Tilemap;
|
||||
var car: Phaser.Sprite;
|
||||
var tile: Phaser.Tile;
|
||||
@@ -28,10 +29,10 @@
|
||||
|
||||
// When the car collides with the cactus tile we'll flash the screen red briefly,
|
||||
// but it won't stop the car (the separateX/Y values are set to false)
|
||||
map.setCollisionByIndex([31], Phaser.Collision.ANY, true, false, false);
|
||||
map.setCollisionByIndex([CACTUS], Phaser.Collision.ANY, true, false, false);
|
||||
|
||||
// When the car collides with the sign post tile we'll stop the car moving (separation is set to true)
|
||||
map.setCollisionByIndex([46], Phaser.Collision.ANY, true, true, true);
|
||||
map.setCollisionByIndex([SIGN_POST], Phaser.Collision.ANY, true, true, true);
|
||||
|
||||
// This is the callback that will be called every time map.collide() returns true
|
||||
map.collisionCallback = collide;
|
||||
@@ -79,12 +80,12 @@
|
||||
// collisionData is an array containing all of the tiles the object overlapped with (can be more than 1)
|
||||
for (var i = 0; i < collisionData.length; i++)
|
||||
{
|
||||
if (collisionData[i].tile.index == 31)
|
||||
if (collisionData[i].tile.index == CACTUS)
|
||||
{
|
||||
console.log('you hit a cactus!');
|
||||
flash.start(0xff0000, 1);
|
||||
}
|
||||
else if (collisionData[i].tile.index == 31)
|
||||
else if (collisionData[i].tile.index == SIGN_POST)
|
||||
{
|
||||
console.log('you hit a sign post!');
|
||||
}
|
||||
|
||||
+18
-16
@@ -11,7 +11,7 @@
|
||||
myGame.loader.load();
|
||||
}
|
||||
var map;
|
||||
var car;
|
||||
var ufo;
|
||||
var tile;
|
||||
var emitter;
|
||||
var test;
|
||||
@@ -19,6 +19,7 @@
|
||||
map = myGame.createTilemap('tiles', 'platform', Phaser.Tilemap.FORMAT_TILED_JSON);
|
||||
map.setCollisionRange(21, 53);
|
||||
map.setCollisionRange(105, 109);
|
||||
myGame.camera.opaque = true;
|
||||
myGame.camera.backgroundColor = 'rgb(47,154,204)';
|
||||
myGame.input.keyboard.addKeyCapture([
|
||||
Phaser.Keyboard.LEFT,
|
||||
@@ -26,36 +27,37 @@
|
||||
Phaser.Keyboard.UP,
|
||||
Phaser.Keyboard.DOWN
|
||||
]);
|
||||
emitter = myGame.createEmitter(32, 80);
|
||||
emitter.width = 700;
|
||||
emitter.makeParticles('chunk', 100, false, 1);
|
||||
emitter.gravity = 200;
|
||||
emitter.bounce = 0.8;
|
||||
emitter.start(false, 10, 0.05);
|
||||
car = myGame.createSprite(250, 64, 'ufo');
|
||||
car.renderRotation = false;
|
||||
//emitter = myGame.createEmitter(32, 80);
|
||||
//emitter.width = 700;
|
||||
//emitter.makeParticles('chunk', 100, false, 1);
|
||||
//emitter.gravity = 200;
|
||||
//emitter.bounce = 0.8;
|
||||
//emitter.start(false, 10, 0.05);
|
||||
ufo = myGame.createSprite(250, 64, 'ufo');
|
||||
ufo.renderDebug = true;
|
||||
ufo.renderRotation = false;
|
||||
test = myGame.createSprite(200, 64, 'ufo');
|
||||
test.elasticity = 1;
|
||||
test.velocity.x = 50;
|
||||
test.velocity.y = 100;
|
||||
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
ufo.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
}
|
||||
function update() {
|
||||
// Collide everything with the map
|
||||
map.collide();
|
||||
// And collide everything in the game :)
|
||||
myGame.collide();
|
||||
car.velocity.x = 0;
|
||||
car.velocity.y = 0;
|
||||
ufo.velocity.x = 0;
|
||||
ufo.velocity.y = 0;
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
|
||||
car.velocity.x = -200;
|
||||
ufo.velocity.x = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
|
||||
car.velocity.x = 200;
|
||||
ufo.velocity.x = 200;
|
||||
}
|
||||
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
|
||||
car.velocity.y = -200;
|
||||
ufo.velocity.y = -200;
|
||||
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN)) {
|
||||
car.velocity.y = 200;
|
||||
ufo.velocity.y = 200;
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
+18
-16
@@ -18,7 +18,7 @@
|
||||
}
|
||||
|
||||
var map: Phaser.Tilemap;
|
||||
var car: Phaser.Sprite;
|
||||
var ufo: Phaser.Sprite;
|
||||
var tile: Phaser.Tile;
|
||||
var emitter: Phaser.Emitter;
|
||||
var test: Phaser.Sprite;
|
||||
@@ -29,26 +29,28 @@
|
||||
map.setCollisionRange(21,53);
|
||||
map.setCollisionRange(105,109);
|
||||
|
||||
myGame.camera.opaque = true;
|
||||
myGame.camera.backgroundColor = 'rgb(47,154,204)';
|
||||
|
||||
myGame.input.keyboard.addKeyCapture([Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.UP, Phaser.Keyboard.DOWN]);
|
||||
|
||||
emitter = myGame.createEmitter(32, 80);
|
||||
emitter.width = 700;
|
||||
emitter.makeParticles('chunk', 100, false, 1);
|
||||
emitter.gravity = 200;
|
||||
emitter.bounce = 0.8;
|
||||
emitter.start(false, 10, 0.05);
|
||||
//emitter = myGame.createEmitter(32, 80);
|
||||
//emitter.width = 700;
|
||||
//emitter.makeParticles('chunk', 100, false, 1);
|
||||
//emitter.gravity = 200;
|
||||
//emitter.bounce = 0.8;
|
||||
//emitter.start(false, 10, 0.05);
|
||||
|
||||
car = myGame.createSprite(250, 64, 'ufo');
|
||||
car.renderRotation = false;
|
||||
ufo = myGame.createSprite(250, 64, 'ufo');
|
||||
ufo.renderDebug = true;
|
||||
ufo.renderRotation = false;
|
||||
|
||||
test = myGame.createSprite(200, 64, 'ufo');
|
||||
test.elasticity = 1;
|
||||
test.velocity.x = 50;
|
||||
test.velocity.y = 100;
|
||||
|
||||
car.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
ufo.setBounds(0, 0, map.widthInPixels - 32, map.heightInPixels - 32);
|
||||
|
||||
}
|
||||
|
||||
@@ -60,25 +62,25 @@
|
||||
// And collide everything in the game :)
|
||||
myGame.collide();
|
||||
|
||||
car.velocity.x = 0;
|
||||
car.velocity.y = 0;
|
||||
ufo.velocity.x = 0;
|
||||
ufo.velocity.y = 0;
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
||||
{
|
||||
car.velocity.x = -200;
|
||||
ufo.velocity.x = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
||||
{
|
||||
car.velocity.x = 200;
|
||||
ufo.velocity.x = 200;
|
||||
}
|
||||
|
||||
if (myGame.input.keyboard.isDown(Phaser.Keyboard.UP))
|
||||
{
|
||||
car.velocity.y = -200;
|
||||
ufo.velocity.y = -200;
|
||||
}
|
||||
else if (myGame.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
||||
{
|
||||
car.velocity.y = 200;
|
||||
ufo.velocity.y = 200;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user