欢迎来到程序小院
小蜜蜂往上跳
玩法:鼠标移动方向,跳跃的小蜜蜂,跳上地板,有会动的地板,断裂的地板,
弹簧地板,根据不同的地板往上跳,统计分数,小蜜蜂快去跳一跳吧^^。
开始游戏https://www.ormcc.com/play/gameStart/213
html
<div id="game"></div>
css
#game{
width:100%;
height:100%;
overflow:hidden;
position:absolute;
top:0;
left:0;
z-index:10;
}
canvas{
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
-webkit-transform: translate(-50%,-50%);
}
js
this.isRun = false;
this.atlasKey = [
//普通地板
{id: 0, key: 'platform0', velocity: 1400,score: 1},
//只能碰一次的地板
{id: 1, key: 'platform3', velocity: 1400,score:2},
//会动的地板
{id: 2, key: 'platform1', velocity: 1400,score:3},
//会断裂的地板
{id: 3, key: 'platform2', velocity: 1400,score:0},
//弹簧
{id: 4, key: 'bonus0', velocity: 2000,score:5}
];
this.atlasMap = [];
for(var i = 0; i < 100; i++){
if(i < 60){
//普通地板
this.atlasMap.push(this.atlasKey[0]);
};
if(i < 20){
//只能碰一次的地板
this.atlasMap.push(this.atlasKey[1]);
};
if(i < 15){
//会动的地板
this.atlasMap.push(this.atlasKey[2]);
};
if(i < 5){
//会断裂的地板
this.atlasMap.push(this.atlasKey[3]);
};
};
this.score = 0;
this.atlasIndex = 0;
this.atlasMap = this.atlasMap.sort(ranArr);
this.stage.backgroundColor = '#edffd9';
//开启物理引擎
this.physics.startSystem(Phaser.Physics.ARCADE);
//适应屏幕
this.scale.scaleMode = Phaser.ScaleManager.EXACT_FIT;
this.scale.setGameSize(gameWidth * 2, gameHeight * 2);
this.scale.setMinMax(320,480,750,1366);
this.scale.onSizeChange.add(function(){
console.log('变化');
},this)
//失去焦点是否继续游戏
this.stage.disableVisibilityChange = true;
//开启鼠标事件
this.input.mouse.capture = true;
this.iniGame();
this.isRun = true;
//背景图
this.bg = this.add.sprite(0, 0,'bg');
this.bg.width = gameWidth * 2;
this.bg.height = gameHeight * 2;
this.bg.fixedToCamera = true;
this.world.setBounds(0, 0, gameWidth * 2,(gameHeight + 99999) * 2);
this.camera.y = this.world.height;
//地板
this.atlas = this.add.group();
//弹簧
this.spring = this.add.group();
//黑洞
this.hole = this.add.sprite(this.world.randomX, 0, 'atlas','obstacle4');
this.hole.visible = false;
this.hole.anchor.set(0.5);
this.hole.scale.set(gameScale);
this.physics.arcade.enable(this.hole);
//批量生成30个地板,状态是死的
this.atlas.createMultiple(30, 'atlas', 0, false);
this.atlasY = this.world.height - this.setScale(50)
for(var i = 0; i < 5; i++){
this.setAtlas(this.setScale(70 + 150 * i),this.atlasY, 'atlas', 'platform0', 0);
};
this.addAtlas(25);
this.mouseSprite = this.add.sprite(0,0);
this.mouseSprite.visible = false;
this.physics.arcade.enable(this.mouseSprite);
//主角
this.play = this.add.sprite(this.atlas.getChildAt(2).x, this.atlas.getChildAt(2).y,"atlas");
this.play.animations.add('go',Phaser.Animation.generateFrameNames('but', 1, 4, '', 0),15,true);
this.play.play('go');
this.play.isRun = true;
//超出世界死
this.play.outOfCameraBoundsKill = true;
this.play.autoCull = true;
this.play.events.onKilled.add(function(sprite){
console.log('死了')
music[4].play();
this.gameEnd(false);
},this);
this.physics.arcade.enable(this.play);
//设置重力
this.play.body.gravity.y = this.setScale(3000);
this.play.anchor.set(0.5);
this.play.y -= (this.play.height / 2 + 100) * gameScale;
this.play.scale.set(gameScale + this.setScale(0.4));
需要源码请关注添加好友哦^ ^
转载:欢迎来到本站,转载请注明文章出处
https://ormcc.com/