phaser/Tests/tilemap/basic tilemap.js

54 lines
2.3 KiB
JavaScript
Raw Normal View History

/// <reference path="../../Phaser/Game.ts" />
2013-04-12 17:19:56 +01:00
(function () {
2013-04-18 14:16:18 +01:00
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
2013-04-12 17:19:56 +01:00
function init() {
// Tiled JSON Test
myGame.loader.addTextFile('jsontest', 'assets/maps/test.json');
myGame.loader.addImageFile('jsontiles', 'assets/tiles/platformer_tiles.png');
// CSV Test
myGame.loader.addTextFile('csvtest', 'assets/maps/catastrophi_level2.csv');
myGame.loader.addImageFile('csvtiles', 'assets/tiles/catastrophi_tiles_16.png');
myGame.loader.addImageFile('car', 'assets/sprites/car90.png');
myGame.loader.load();
}
var car;
var map;
var bigCam;
function create() {
2013-04-18 14:16:18 +01:00
myGame.camera.deadzone = new Phaser.Rectangle(64, 64, myGame.stage.width - 128, myGame.stage.height - 128);
2013-04-12 17:19:56 +01:00
bigCam = myGame.createCamera(30, 30, 200, 200);
bigCam.showBorder = true;
bigCam.scale.setTo(1.5, 1.5);
//map = myGame.createTilemap('jsontiles', 'jsontest', Tilemap.FORMAT_TILED_JSON);
2013-04-18 14:16:18 +01:00
map = myGame.createTilemap('csvtiles', 'csvtest', Phaser.Tilemap.FORMAT_CSV, 16, 16);
2013-04-12 17:19:56 +01:00
// for now like this, but change to auto soon
myGame.world.setSize(map.widthInPixels, map.heightInPixels);
console.log('world size', map.widthInPixels, map.heightInPixels);
myGame.camera.setBounds(0, 0, myGame.world.width, myGame.world.height);
bigCam.setBounds(0, 0, myGame.world.width, myGame.world.height);
car = myGame.createSprite(300, 100, 'car');
myGame.camera.follow(car);
2013-04-18 14:16:18 +01:00
bigCam.follow(car, Phaser.Camera.STYLE_LOCKON);
2013-04-12 17:19:56 +01:00
myGame.onRenderCallback = render;
}
function update() {
//bigCam.rotation += 0.5;
car.velocity.x = 0;
car.velocity.y = 0;
car.angularVelocity = 0;
car.angularAcceleration = 0;
2013-04-18 14:16:18 +01:00
if(myGame.input.keyboard.isDown(Phaser.Keyboard.LEFT)) {
2013-04-12 17:19:56 +01:00
car.angularVelocity = -200;
2013-04-18 14:16:18 +01:00
} else if(myGame.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) {
2013-04-12 17:19:56 +01:00
car.angularVelocity = 200;
}
2013-04-18 14:16:18 +01:00
if(myGame.input.keyboard.isDown(Phaser.Keyboard.UP)) {
var motion = myGame.motion.velocityFromAngle(car.angle, 300);
2013-04-12 17:19:56 +01:00
car.velocity.copyFrom(motion);
}
}
function render() {
map.renderDebugInfo(400, 16);
}
})();