Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - var statePlay = {
- create: function(){
- game.physics.arcade.gravity.y = 1200;
- this.map = game.add.tilemap('Tilemap1');
- this.map.addTilesetImage ('Tilemap1', 'ImageTilemap1');
- this.map.setCollisionByExclusion([0], true, 'LayerBlock');
- this.layerBackground = this.map.createLayer('LayerBackground');
- this.layerBlock = this.map.createLayer('LayerBlock');
- this.keyboard = game.input.keyboard.createCursorKeys();
- this.coinGroup = game.add.group();
- this.coinGroup.enabledBody = true;
- this.map.createFromObjects ('LayerObject', 4, 'ImageCoin', 0, true, false, this.coinGroup);
- //this.ObjectCoinCreate();
- //this.ObjectPlayerCreate();
- },
- update: function(){
- //this.CollisionObject();
- //this.ObjectPlayerUpdate();
- //this.OverlapObject();
- },
- CollisionObject: function(){
- game.physics.arcade.collide(this.player, this.layerBlock);
- for(var i = 0; i < this.coinArray.length; i ++){
- game.physics.arcade.collide(this.coinArray[i], this.layerBlock);
- }
- },
- FindGameObjectsByType: function(_layer, _map, _type){
- var findObjects = new Array();
- _map.objects[_layer].forEach(
- function(_element){
- if(_element.properties.type == _type){
- _element.y -= _map.tileHeight;
- findObjects.push(_element);
- }
- }
- );
- return findObjects;
- },
- PlayerCollectsCoin: function(_player, _coin){ _coin.destroy(true); },
- ObjectCoinCreate: function(){
- var findCoin = this.FindGameObjectsByType('LayerObject', this.map, 'coin');
- this.coinArray = new Array(findCoin.length);
- for(var i = 0; i < this.coinArray.length; i ++){
- this.coinArray[i] = game.add.sprite(findCoin[i].x, findCoin[i].y, 'ImageCoin');
- this.coinArray[i].enabledBody = true;
- game.physics.arcade.enable (this.coinArray[i]);
- this.coinArray[i].body.immovable = true;
- this.coinArray[i].body.moves = false;
- }
- },
- ObjectPlayerCreate: function(){
- var findPlayer = this.FindGameObjectsByType('LayerObject', this.map, 'playerPortal');
- this.player = game.add.sprite(findPlayer[0].x, findPlayer[0].y, 'ImagePlayer');
- this.player.enabledBody = true;
- game.physics.arcade.enable (this.player);
- },
- ObjectPlayerUpdate: function(){
- if (this.keyboard.left.isDown) { this.player.body.velocity.x = -200; }
- else if (this.keyboard.right.isDown) { this.player.body.velocity.x = 200; }
- else { this.player.body.velocity.x = 0; }
- if(
- this.keyboard.up.isDown &&
- this.player.body.onFloor()
- ){ this.player.body.velocity.y = -500; }
- },
- OverlapObject: function(){
- for(var i = 0; i < this.coinArray.length; i ++){
- game.physics.arcade.overlap(this.player, this.coinArray[i], this.PlayerCollectsCoin, null, this);
- }
- }
- };
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment                    
                 
                    