nothing Posted September 4, 2017 Share Posted September 4, 2017 function start(conf) { var game = new Phaser.Game(conf.width, conf.height, Phaser.AUTO, null, { preload: preload, create: create, update: update, render: render }); var heroid; var heroname = []; var platform = []; var cursors; var jumpButton; var spaceSkok; var velocityBall; var facing = "left"; var fireButton1; velocityBall = true; var recordVelocity; var things; var weapons = []; var config = document.getElementById("con"); config.innerHTML = JSON.stringify(conf); //(conf); function preload() { game.scale.scaleMode = Phaser.ScaleManager.NO_SCALE; // canvas se nepřispůsobuje obrazovce game.scale.pageAlignHorizontally = true; //nemám ponětí game.scale.pageAlignVertically = true; // nemám ponětí game.stage.backgroundColor = '#eee'; // barva canvasu startinitpreload() }; function create() { cursors = game.input.keyboard.createCursorKeys(); game.physics.startSystem(Phaser.Physics.ARCADE); startinitcreate(); jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); fireButton1 = game.input.keyboard.addKey(Phaser.KeyCode.ONE); } function update() { // updateEdit() colide1(); bulletColide(); if (heroname[heroid].body.onFloor() || heroname[heroid].body.touching.down) { //tato podmínka určuje zda je hráč ve vzduchu || pokud ano tak heroname[heroid].body.velocity.x = 0; // if (cursors.left.isDown) { // facing = "left"; heroname[heroid].body.velocity.x = -250; // | } else if (cursors.right.isDown) { facing = "right"; heroname[heroid].body.velocity.x = 250; } } else { if (heroname[heroid].body.velocity.x < 0) { if (cursors.right.isDown && -20 > heroname[heroid].body.velocity.x) { // pokud ne tak normální ovládání facing = "right"; heroname[heroid].body.velocity.x = heroname[heroid].body.velocity.x + 8; } else if (cursors.left.isDown && heroname[heroid].body.velocity.x > -350) { facing = "left"; heroname[heroid].body.velocity.x = heroname[heroid].body.velocity.x - 6; } } else if (heroname[heroid].body.velocity.x != 0) { if (cursors.left.isDown && heroname[heroid].body.velocity.x > 20) { facing = "left"; heroname[heroid].body.velocity.x = heroname[heroid].body.velocity.x - 8; } else if (cursors.right.isDown && heroname[heroid].body.velocity.x < 350) { // pokud ne tak normální ovládání facing = "right"; heroname[heroid].body.velocity.x = heroname[heroid].body.velocity.x + 6; } } else if (heroname[heroid].body.velocity.x == 0) { if (cursors.left.isDown) { facing = "left"; heroname[heroid].body.velocity.x = heroname[heroid].body.velocity.x - 8; } else if (cursors.right.isDown) { // pokud ne tak normální ovládání facing = "right"; heroname[heroid].body.velocity.x = heroname[heroid].body.velocity.x + 8; } } } if (jumpButton.isDown && heroname[heroid].body.velocity.y > -500 && spaceSkok == false) { // SKÁKÁNÍ if (velocityBall == true) { record(); } var rozdil; rozdil = recordVelocity - heroname[heroid].y; if (rozdil < 12) { heroname[heroid].body.velocity.y = heroname[heroid].body.velocity.y - 110; //debugj.innerHTML = heroname[heroid].body.velocity.y + "<br> ahoj" + spaceSkok + "<br>" + velocityheroname[heroid] + " " + rozdil; } } else if (heroname[heroid].body.onFloor() || heroname[heroid].body.touching.down) { heroname[heroid].body.velocity.y = 0; spaceSkok = false; } else if (heroname[heroid].body.velocity.y < -400) { spaceSkok = true; } if (fireButton1.isDown) { //bullet.x = 100; if (facing == "left") { things.bulletAngleOffset = 0; things.fireAngle = Phaser.ANGLE_LEFT; things.fire(); } else { things.bulletAngleOffset = 180; things.fireAngle = Phaser.ANGLE_RIGHT; things.fire(); } } clicked() }; function record() { recordVelocity = heroname[heroid].y; } function render() { } var initpreloadplatform = function (val3) { game.load.image(val3.name2, val3.sprite); } function startinitpreload() { var localx = conf.alivethings; for (i = 0; i < localx.length; i++) { var neco5; neco5 = new initpreload(localx[i].load); } var localy = conf.objects; for (a = 0; a < localy.length; a++) { var neco6; neco6 = new initpreloadplatform(localy[a].load); } var localo = conf.weapons; for (a = 0; a < localo.length; a++) { var neco7; neco7 = new initpreloadplatform(localo[a].load); } var localz; localz = conf.weaponsHero; var neco2; neco2 = new initpreload(localz.load); } var initpreload = function (val1) { game.load.image(val1.name2, val1.sprite); } function startinitcreate() { // game.physics.startSystem(Phaser.Physics.ARCADE); var localx = conf.alivethings; var localy = conf.objects; for (i = 0; i < localx.length; i++) { var neco3; neco3 = new initcreate(localx[i], i); if (localx[i].other.hero == true) { heroid = i - 1; } } for (l = 0; l < localy.length; l++) { var neco4; neco4 = new initcreateplatform(localy[l], l); }; var locali = conf.weapons; for (q = 0; q < localy.length; q++) { var neco8; neco8 = new initCreateWeapons(locali[q], q); }; var localz; localz = conf.weaponsHero; var neco; neco = new initcreateweapons(localz, conf.weaponsHero.load.name2); } var initcreateweapons = function (val4, a) { things = game.add.weapon(conf.weaponsHero.other.numberOfBullets, a); things.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; things.bulletSpeed = val4.other.bulletSpeed; things.trackSprite(heroname[heroid], 14, 0); things.fireRate = val4.other.fireRate; } var initcreateplatform = function (val4, t) { platform[t] = game.add.physicsGroup(); for (i = 0; i < val4.other.position.length; i++) { platform[t].create(val4.other.position[i].x, val4.other.position[i].y, val4.load.name2); if (val4.load.immovable == true) { platform[t].setAll('body.immovable', true); } } } function ballHitBrick(bullet, platform) { bullet.kill(); } function ballHitHero(bullet, bullet1) { bullet.kill() } var initcreate = function (val2, i) { heroname[i] = game.add.sprite(val2.other.position[0], val2.other.position[1], val2.load.name2); heroname[i].anchor.set(val2.other.anchor); if (val2.other.physic == true) { game.physics.enable(heroname[i], Phaser.Physics.ARCADE); heroname[i].body.gravity.y = val2.other.gravity; heroname[i].body.collideWorldBounds = true; heroname[i].body.bounce.set(0); game.physics.arcade.enable(heroname[i]); } } function bulletColide() { var delka1 = conf.objects.length; var delka2 = conf.alivethings.length; for (i = 0; i < delka1; i++) { game.physics.arcade.overlap(things.bullets, platform[i], ballHitBrick); } for (j = 0; j < delka2; j++) { if (j != heroid) { game.physics.arcade.overlap(things.bullets, heroname[j], ballHitHero); } } } function colide1() { var prom1 = heroname; var prom2 = platform; var delka1 = conf.alivethings.length; for (q = 0; q < delka1; q++) { for (l = q + 1; l < delka1; l++) { var p = l - 1; game.physics.arcade.collide(prom1[q], prom1[l]); game.physics.arcade.collide(prom1[q], prom2[p]); } }; } function clicked() { things.destroy() } var initCreateWeapons = function (aaa, aba) { } } Problem is here function clicked(){things.destroy()}; things is a weapon and works correctly. Thank you for comments. Ps: sorry for long code Link to comment Share on other sites More sharing options...
samme Posted September 5, 2017 Share Posted September 5, 2017 On 9/4/2017 at 11:09 AM, nothing said: Problem is here function clicked(){things.destroy()}; What is the problem? What happens? Link to comment Share on other sites More sharing options...
nothing Posted September 6, 2017 Author Share Posted September 6, 2017 Sorry, I forgot to put it there. The function things.destroy() doesnt work. I have already solved. Link to comment Share on other sites More sharing options...
Recommended Posts