本文主要是介绍星际飞船大战,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
欢迎来到程序小院
星际飞船大战
玩法:滑动鼠标控制方向,点击鼠标左键射击,生命值100分,被敌船击中减去20,
5次生命复活机会,统计分数,快去星际飞船大战吧^^。
开始游戏https://www.ormcc.com/play/gameStart/216
html
<canvas width="800" height="530"></canvas>
css
canvas {display: block; touch-action: none; user-select: none; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); width: 800px; height: 530px; cursor: inherit;}
js
starfield = game.add.tileSprite(0, 0, 800, 600, 'starfield');
//Our bullet group
bullets = game.add.group();
bullets.enableBody = true;
bullets.physicsBodyType = Phaser.Physics.ARCADE;
bullets.createMultiple(30, 'bullet');
bullets.setAll('anchor.x', 0.5);
bullets.setAll('anchor.y', 1);
bullets.setAll('outOfBoundsKill', true);
bullets.setAll('checkWorldBounds', true);
//The hero!
player = game.add.sprite(400, 500, 'ship');
player.health = 100;
player.anchor.setTo(0.5, 0.5);
game.physics.enable(player, Phaser.Physics.ARCADE);
player.body.maxVelocity.setTo(MAXSPEED, MAXSPEED);
player.body.drag.setTo(DRAG, DRAG);
player.weaponLevel = 1
player.events.onKilled.add(function(){shipTrail.kill();
});
player.events.onRevived.add(function(){shipTrail.start(false, 5000, 10);
});
//The baddies!
greenEnemies = game.add.group();
greenEnemies.enableBody = true;
greenEnemies.physicsBodyType = Phaser.Physics.ARCADE;
greenEnemies.createMultiple(5, 'enemy-green');
greenEnemies.setAll('anchor.x', 0.5);
greenEnemies.setAll('anchor.y', 0.5);
greenEnemies.setAll('scale.x', 0.5);
greenEnemies.setAll('scale.y', 0.5);
greenEnemies.setAll('angle', 180);
greenEnemies.forEach(function(enemy){addEnemyEmitterTrail(enemy);enemy.body.setSize(enemy.width * 3 / 4, enemy.height * 3 / 4);enemy.damageAmount = 20;enemy.events.onKilled.add(function(){enemy.trail.kill();});
});
game.time.events.add(1000, launchGreenEnemy);
//Blue enemy's bullets
blueEnemyBullets = game.add.group();
blueEnemyBullets.enableBody = true;
blueEnemyBullets.physicsBodyType = Phaser.Physics.ARCADE;
blueEnemyBullets.createMultiple(30, 'blueEnemyBullet');
blueEnemyBullets.callAll('crop', null, {x: 90, y: 0, width: 90, height: 70});
blueEnemyBullets.setAll('alpha', 0.9);
blueEnemyBullets.setAll('anchor.x', 0.5);
blueEnemyBullets.setAll('anchor.y', 0.5);
blueEnemyBullets.setAll('outOfBoundsKill', true);
blueEnemyBullets.setAll('checkWorldBounds', true);
blueEnemyBullets.forEach(function(enemy){enemy.body.setSize(20, 20);
});
//More baddies!
blueEnemies = game.add.group();
blueEnemies.enableBody = true;
blueEnemies.physicsBodyType = Phaser.Physics.ARCADE;
blueEnemies.createMultiple(30, 'enemy-blue');
blueEnemies.setAll('anchor.x', 0.5);
blueEnemies.setAll('anchor.y', 0.5);
blueEnemies.setAll('scale.x', 0.5);
blueEnemies.setAll('scale.y', 0.5);
blueEnemies.setAll('angle', 180);
blueEnemies.forEach(function(enemy){enemy.damageAmount = 40;
});
//The boss
boss = game.add.sprite(0, 0, 'boss');
boss.exists = false;
boss.alive = false;
boss.anchor.setTo(0.5, 0.5);
boss.damageAmount = 50;
boss.angle = 180;
boss.scale.x = 0.6;
boss.scale.y = 0.6;
game.physics.enable(boss, Phaser.Physics.ARCADE);
boss.body.maxVelocity.setTo(100, 80);
boss.dying = false;
boss.finishOff = function() {if (!boss.dying) {boss.dying = true;bossDeath.x = boss.x;bossDeath.y = boss.y;bossDeath.start(false, 1000, 50, 20);// kill boss after explotionsgame.time.events.add(1000, function(){var explosion = explosions.getFirstExists(false);var beforeScaleX = explosions.scale.x;var beforeScaleY = explosions.scale.y;var beforeAlpha = explosions.alpha;explosion.reset(boss.body.x + boss.body.halfWidth, boss.body.y + boss.body.halfHeight);explosion.alpha = 0.4;explosion.scale.x = 3;explosion.scale.y = 3;var animation = explosion.play('explosion', 30, false, true);animation.onComplete.addOnce(function(){explosion.scale.x = beforeScaleX;explosion.scale.y = beforeScaleY;explosion.alpha = beforeAlpha;});boss.kill();booster.kill();boss.dying = false;bossDeath.on = false;// queue next bossbossLaunchTimer = game.time.events.add(game.rnd.integerInRange(bossSpacing, bossSpacing + 5000), launchBoss);});// reset pacing for other enemiesblueEnemySpacing = 2500;greenEnemySpacing = 1000;// give some bonus healthplayer.health = Math.min(100, player.health + 40);shields.render();}
源码
需要源码请关注添加好友哦^ ^
转载:欢迎来到本站,转载请注明文章出处
https://ormcc.com/
这篇关于星际飞船大战的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!