game.load.tilemap('map', "tilemap.json", null, Phaser.Tilemap.TILED_JSON); game.load.image('tileset', '//i.imgur.com/PsulQEq.png'); game.load.image('mountains', '//i.imgur.com/UY3o6h1.jpg'); game.load.spritesheet('contra', '//i.imgur.com/lmXDYws.png', 45, 47); game.load.image('bullet', '//i.imgur.com/jzOjX7a.png');
{ "height":10, "layers":[ { "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 29], "height":10, "name":"layer1", "opacity":1, "type":"tilelayer", "visible":true, "width":20, "x":0, "y":0 }], "orientation":"orthogonal", "properties": { }, "tileheight":32, "tilesets":[ { "firstgid":1, "image":"tileset-platformer.png", "imageheight":544, "imagewidth":192, "margin":0, "name":"tileset", "properties": { }, "spacing":0, "tileheight":32, "tilewidth":32 }], "tilewidth":32, "version":1, "width":20 }
function spawnPlayer() { player = game.add.sprite(100,230,'contra'); game.physics.enable(player, Phaser.Physics.ARCADE); player.body.gravity.y = 500; player.body.collideWorldBounds = true; player.body.fixedRotation = true; player.frame = 1; player.animations.add('walk_right', [0,1,2,3,4,5,6,7], 12, true); player.animations.add('walk_left', [8,9,10,11,12,13,14,15], 12, true); game.camera.follow(player); }
function update() { player.body.velocity.x = 0; game.physics.arcade.collide(player, layer); if (cursors.left.isDown) { player.animations.play('walk_left'); player.body.velocity.x = -150; facing = 'left'; } else if (cursors.right.isDown) { player.animations.play('walk_right'); player.body.velocity.x = 150; facing = 'right'; } else { player.animations.stop(); if (facing == 'right') { player.frame = 0; } else { player.frame = 8; } } if (cursors.up.isDown && player.body.onFloor()) { player.body.velocity.y = -385; } }
var shotTimer = 0; function shoot() { if (shotTimer < game.time.now) { shotTimer = game.time.now + 275; var bullet; if (facing == 'right') { bullet = bullets.create(player.body.x + player.body.width / 2 + 20, player.body.y + player.body.height / 2 - 4, 'bullet'); } else { bullet = bullets.create(player.body.x + player.body.width / 2 - 20, player.body.y + player.body.height / 2 - 4, 'bullet'); } game.physics.enable(bullet, Phaser.Physics.ARCADE); bullet.outOfBoundsKill = true; bullet.anchor.setTo(0.5, 0.5); bullet.body.velocity.y = 0; if (facing == 'right') { bullet.body.velocity.x = 400; } else { bullet.body.velocity.x = -400; } } }
Teach coding to your students with MVCode Teach
MVCode offers an integrated product designed to teach coding to students.