星际飞船大战

2023-12-13 09:52:36

欢迎来到程序小院

星际飞船大战

玩法:滑动鼠标控制方向,点击鼠标左键射击,生命值100分,被敌船击中减去20,
5次生命复活机会,统计分数,快去星际飞船大战吧^^。

开始游戏icon-default.png?t=N7T8https://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?explotions
??????game.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?boss
??????????bossLaunchTimer?=?game.time.events.add(game.rnd.integerInRange(bossSpacing,?
??????????bossSpacing?+?5000),?launchBoss);
??????});

??????//??reset?pacing?for?other?enemies
??????blueEnemySpacing?=?2500;
??????greenEnemySpacing?=?1000;

??????//??give?some?bonus?health
??????player.health?=?Math.min(100,?player.health?+?40);
??????shields.render();
????}

源码

需要源码请关注添加好友哦^ ^

转载:欢迎来到本站,转载请注明文章出处https://ormcc.com/

文章来源:https://blog.csdn.net/qq_16659821/article/details/134947094
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。