Commit 0e85c3c0 authored by 任建锋's avatar 任建锋

--

parent 91229572
No preview for this file type
No preview for this file type
This diff is collapsed.
...@@ -215,7 +215,7 @@ ...@@ -215,7 +215,7 @@
this.visible = false; this.visible = false;
setTimeout(function () { setTimeout(function () {
_this.visible = true; _this.visible = true;
_this.player.x = 375 - _this.player.width / 2; _this.player.x = props.playerPositionX;
_this.player.y = props.playerPositionY; _this.player.y = props.playerPositionY;
_this.playerSvgaRun.x = props.playerRunPosition3Offset[0]; _this.playerSvgaRun.x = props.playerRunPosition3Offset[0];
_this.playerSvgaRun.y = props.playerRunPosition3Offset[1]; _this.playerSvgaRun.y = props.playerRunPosition3Offset[1];
...@@ -276,11 +276,11 @@ ...@@ -276,11 +276,11 @@
GameView.prototype.reset = function () { GameView.prototype.reset = function () {
this.recycleGoods(); this.recycleGoods();
this.score = 0; this.score = 0;
this.speed = 1; this.speed = props.speed;
this.bg.y = -1624; this.bg.y = -this.bg3.y;
this.player.anchorY = this.player.height / 2; this.player.anchorY = this.player.height / 2;
this.player.anchorX = this.player.width / 2; this.player.anchorX = this.player.width / 2;
this.player.x = 375 - this.player.width / 2; this.player.x = props.playerPositionX;
this.player.y = props.playerPositionY; this.player.y = props.playerPositionY;
this.setPlayState(this.playerSvgaReset); this.setPlayState(this.playerSvgaReset);
}; };
...@@ -332,6 +332,7 @@ ...@@ -332,6 +332,7 @@
var _this = this; var _this = this;
this.timer = setTimeout(function () { this.timer = setTimeout(function () {
if (_this.gameIng) { if (_this.gameIng) {
_this.speed += props.acceleratedSpeed;
_this.speed += props.acceleratedSpeed; _this.speed += props.acceleratedSpeed;
if (_this.speed > props.maxSpeed) { if (_this.speed > props.maxSpeed) {
_this.speed = props.maxSpeed; _this.speed = props.maxSpeed;
...@@ -368,6 +369,9 @@ ...@@ -368,6 +369,9 @@
if (goods["npcType"] == "rain0") { if (goods["npcType"] == "rain0") {
console.log("碰到雨滴"); console.log("碰到雨滴");
_this.score += props.rainScore; _this.score += props.rainScore;
if (_this.score < 0) {
_this.score = 0;
}
_this.setBoomPosition(_this.waterSvga); _this.setBoomPosition(_this.waterSvga);
engine.Tween.get(goods, null, null, true) engine.Tween.get(goods, null, null, true)
.to({ scaleX: 0, scaleY: 0 }, 200) .to({ scaleX: 0, scaleY: 0 }, 200)
...@@ -376,6 +380,9 @@ ...@@ -376,6 +380,9 @@
else if (goods["npcType"] == "rain1") { else if (goods["npcType"] == "rain1") {
console.log("碰到雨滴"); console.log("碰到雨滴");
_this.score += props.rain2Score; _this.score += props.rain2Score;
if (_this.score < 0) {
_this.score = 0;
}
_this.setBoomPosition(_this.water2Svga); _this.setBoomPosition(_this.water2Svga);
engine.Tween.get(goods, null, null, true) engine.Tween.get(goods, null, null, true)
.to({ scaleX: 0, scaleY: 0 }, 200) .to({ scaleX: 0, scaleY: 0 }, 200)
......
...@@ -7,6 +7,11 @@ ...@@ -7,6 +7,11 @@
"type": "number", "type": "number",
"default": 900 "default": 900
}, },
"playerPositionX": {
"alias": "玩家Y轴位置",
"type": "number",
"default": 300
},
"runScore": { "runScore": {
"alias": "每前进1米加分(不能小于1)", "alias": "每前进1米加分(不能小于1)",
"type": "number", "type": "number",
......
...@@ -130,7 +130,7 @@ export default class GameView extends engine.Container { ...@@ -130,7 +130,7 @@ export default class GameView extends engine.Container {
this.visible=true; this.visible=true;
//this.player.anchorY = this.player.height / 2; //this.player.anchorY = this.player.height / 2;
// this.player.anchorX = this.player.width / 2; // this.player.anchorX = this.player.width / 2;
this.player.x = 375 - this.player.width / 2; this.player.x = props.playerPositionX;
this.player.y = props.playerPositionY; this.player.y = props.playerPositionY;
// this.stoneSvga.x = this.player.width / 2 - this.stoneSvga.width/2 + props.boomPosition1Offset[0]; // this.stoneSvga.x = this.player.width / 2 - this.stoneSvga.width/2 + props.boomPosition1Offset[0];
...@@ -228,12 +228,12 @@ export default class GameView extends engine.Container { ...@@ -228,12 +228,12 @@ export default class GameView extends engine.Container {
reset() { reset() {
this.recycleGoods() this.recycleGoods()
this.score = 0; this.score = 0;
this.speed = 1; this.speed = props.speed;
this.bg.y=-1624 this.bg.y=-this.bg3.y
this.player.anchorY = this.player.height / 2; this.player.anchorY = this.player.height / 2;
this.player.anchorX = this.player.width / 2; this.player.anchorX = this.player.width / 2;
this.player.x = 375 - this.player.width / 2; this.player.x = props.playerPositionX;
this.player.y = props.playerPositionY; this.player.y = props.playerPositionY;
this.setPlayState(this.playerSvgaReset) this.setPlayState(this.playerSvgaReset)
} }
...@@ -292,6 +292,7 @@ export default class GameView extends engine.Container { ...@@ -292,6 +292,7 @@ export default class GameView extends engine.Container {
beginNpc() { beginNpc() {
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
if (this.gameIng) { if (this.gameIng) {
this.speed += props.acceleratedSpeed;
this.speed += props.acceleratedSpeed; this.speed += props.acceleratedSpeed;
if(this.speed>props.maxSpeed){ if(this.speed>props.maxSpeed){
this.speed=props.maxSpeed this.speed=props.maxSpeed
......
...@@ -67,7 +67,6 @@ ...@@ -67,7 +67,6 @@
var random = Math.random(); var random = Math.random();
if (typeof (props.goodsProbability) == 'string') { if (typeof (props.goodsProbability) == 'string') {
props.goodsProbability = props.goodsProbability.split(',').map(function (i) { return +i; }); props.goodsProbability = props.goodsProbability.split(',').map(function (i) { return +i; });
console.log(props.goodsProbability);
} }
if (random < props.goodsProbability[0]) { if (random < props.goodsProbability[0]) {
var randomNum = Math.floor(Math.random() * 3); var randomNum = Math.floor(Math.random() * 3);
...@@ -117,6 +116,9 @@ ...@@ -117,6 +116,9 @@
function GameView() { function GameView() {
var _this = _super.call(this) || this; var _this = _super.call(this) || this;
_this.goodsItems = []; _this.goodsItems = [];
_this.viewVisible = true;
_this.cacheTime = 0;
_this.cacheTime2 = 0;
_this.moveCatchX = 0; _this.moveCatchX = 0;
_this.playerCatchX = 0; _this.playerCatchX = 0;
_this.onDownStage = function (e) { _this.onDownStage = function (e) {
...@@ -191,47 +193,71 @@ ...@@ -191,47 +193,71 @@
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDownStage, this); this.rectBg.addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDownStage, this);
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMoveStage, this); this.rectBg.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMoveStage, this);
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_OUT, this.onOutStage, this); this.rectBg.addEventListener(engine.MouseEvent.MOUSE_OUT, this.onOutStage, this);
document.addEventListener("visibilitychange", function () {
if (document.visibilityState == "visible") {
_this.viewVisible = true;
}
if (document.visibilityState == "hidden") {
_this.viewVisible = false;
}
});
this.addEventListener(engine.Event.ENTER_FRAME, this.enterFrame, this);
};
GameView.prototype.enterFrame = function () {
this.updateTime();
this.updateTimeBeginNpc();
}; };
GameView.prototype.reset = function () { GameView.prototype.reset = function () {
this.score = 0; this.score = props.speed;
this.recycleGoods(); this.recycleGoods();
this.player.x = 375 - this.player.width / 2; this.player.x = 375 - this.player.width / 2;
}; };
GameView.prototype.start = function () { GameView.prototype.start = function () {
var _this = this;
this.score = 0; this.score = 0;
this.speed = 1; this.speed = 1;
this.gameIng = true; this.gameIng = true;
this.creatNpc();
this.beginNpc(); this.beginNpc();
this.countdown = props.countDown; this.countdown = props.countDown;
this.countdownTimer = setInterval(function () { };
if (_this.gameIng) { GameView.prototype.updateTime = function () {
if (_this.countdown > 0) { if (Date.now() - this.cacheTime > 1000) {
engine.globalEvent.dispatchEvent('food-fell-time-update', { this.cacheTime = Date.now();
time: _this.countdown, }
}); else {
_this.countdown -= 1; return;
} }
else { if (this.gameIng) {
engine.globalEvent.dispatchEvent('food-fell-game-over', { if (this.countdown > 0) {
score: _this.score, engine.globalEvent.dispatchEvent('food-fell-time-update', {
reason: 1 time: this.countdown,
}); });
_this.died(); this.countdown -= 1;
} }
else {
engine.globalEvent.dispatchEvent('food-fell-game-over', {
score: this.score,
reason: 1
});
this.died();
} }
}, 1000); }
}; };
GameView.prototype.beginNpc = function () { GameView.prototype.beginNpc = function () {
var _this = this; };
this.timer = setTimeout(function () { GameView.prototype.updateTimeBeginNpc = function () {
if (_this.gameIng) { if (Date.now() - this.cacheTime2 > (2000 / this.speed)) {
_this.speed += props.acceleratedSpeed; this.cacheTime2 = Date.now();
_this.creatNpc(); }
else {
return;
}
if (this.gameIng) {
this.speed += props.acceleratedSpeed;
if (this.speed >= props.maxSpeed) {
this.speed = props.maxSpeed;
} }
_this.beginNpc(); this.creatNpc();
}, 2000 / this.speed); }
}; };
GameView.prototype.pause = function () { GameView.prototype.pause = function () {
this.gameIng = false; this.gameIng = false;
...@@ -247,7 +273,6 @@ ...@@ -247,7 +273,6 @@
var _this = this; var _this = this;
var goods = this._goods = ObjectPool$1.getObject(PoolName); var goods = this._goods = ObjectPool$1.getObject(PoolName);
this.goodsItems.push(goods); this.goodsItems.push(goods);
console.log(goods);
this.NpcBg.addChild(goods); this.NpcBg.addChild(goods);
goods.addEventListener(engine.Event.ENTER_FRAME, goods["onGoodsEnter"] = function () { goods.addEventListener(engine.Event.ENTER_FRAME, goods["onGoodsEnter"] = function () {
if (goods.y > 1624) { if (goods.y > 1624) {
...@@ -258,7 +283,6 @@ ...@@ -258,7 +283,6 @@
goods.y += (4 * _this.speed); goods.y += (4 * _this.speed);
if (_this.hasHit(_this.player, goods)) { if (_this.hasHit(_this.player, goods)) {
if (goods["npcType"].indexOf("rain") > -1) { if (goods["npcType"].indexOf("rain") > -1) {
console.log("碰到雨滴");
_this.score += props.rainScore; _this.score += props.rainScore;
_this.waterSvga.visible = true; _this.waterSvga.visible = true;
_this.waterSvga.play(false, false); _this.waterSvga.play(false, false);
...@@ -270,7 +294,6 @@ ...@@ -270,7 +294,6 @@
} }
} }
else if (goods["npcType"] == "stone") { else if (goods["npcType"] == "stone") {
console.log("碰到石头");
_this.score += props.stoneScore; _this.score += props.stoneScore;
if (_this.score < 0) { if (_this.score < 0) {
_this.score = 0; _this.score = 0;
...@@ -282,7 +305,6 @@ ...@@ -282,7 +305,6 @@
}, _this); }, _this);
} }
else if (goods["npcType"] == "boom") { else if (goods["npcType"] == "boom") {
console.log("碰到炸弹");
_this.boomSvga.visible = true; _this.boomSvga.visible = true;
_this.boomSvga.play(false, false); _this.boomSvga.play(false, false);
_this.died(); _this.died();
...@@ -332,7 +354,6 @@ ...@@ -332,7 +354,6 @@
var playerH = a.height; var playerH = a.height;
var playerW = a.width; var playerW = a.width;
var playerX = a.x; var playerX = a.x;
console.log("props", props.playerHeight);
if (props.playerHeight) { if (props.playerHeight) {
playerH = props.playerHeight; playerH = props.playerHeight;
} }
......
This diff is collapsed.
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
"speed": { "speed": {
"alias": "道具掉落初始速度", "alias": "道具掉落初始速度",
"type": "number", "type": "number",
"default": 10 "default": 1
}, },
"maxSpeed": { "maxSpeed": {
"alias": "道具掉落速度上限", "alias": "道具掉落速度上限",
......
...@@ -42,6 +42,8 @@ export default class GameView extends engine.Container { ...@@ -42,6 +42,8 @@ export default class GameView extends engine.Container {
// 当前场景上面的物品 // 当前场景上面的物品
private goodsItems = [] private goodsItems = []
private viewVisible=true;
private _goods: Goods; private _goods: Goods;
...@@ -132,15 +134,31 @@ export default class GameView extends engine.Container { ...@@ -132,15 +134,31 @@ export default class GameView extends engine.Container {
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMoveStage, this); this.rectBg.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMoveStage, this);
this.rectBg.addEventListener(engine.MouseEvent.MOUSE_OUT, this.onOutStage, this); this.rectBg.addEventListener(engine.MouseEvent.MOUSE_OUT, this.onOutStage, this);
document.addEventListener("visibilitychange",()=>{
if(document.visibilityState=="visible"){
this.viewVisible=true;
}
if(document.visibilityState=="hidden"){
this.viewVisible=false;
}
})
this.addEventListener(engine.Event.ENTER_FRAME, this.enterFrame,this)
} }
enterFrame(){
this.updateTime()
this.updateTimeBeginNpc()
}
/** /**
* 重置场景 * 重置场景
*/ */
reset() { reset() {
this.score = 0 this.score = props.speed
this.recycleGoods() this.recycleGoods()
this.player.x = 375 - this.player.width / 2; this.player.x = 375 - this.player.width / 2;
} }
...@@ -152,40 +170,59 @@ export default class GameView extends engine.Container { ...@@ -152,40 +170,59 @@ export default class GameView extends engine.Container {
this.score = 0; this.score = 0;
this.speed = 1 this.speed = 1
this.gameIng = true; this.gameIng = true;
this.creatNpc() //this.creatNpc()
this.beginNpc() this.beginNpc()
this.countdown = props.countDown; this.countdown = props.countDown;
}
this.countdownTimer = setInterval(() => {
if (this.gameIng) { cacheTime=0
if (this.countdown > 0) { updateTime(){
engine.globalEvent.dispatchEvent('food-fell-time-update', { if(Date.now()-this.cacheTime>1000){
time: this.countdown, this.cacheTime=Date.now()
}); }else{
this.countdown -= 1 return;
} else { }
engine.globalEvent.dispatchEvent('food-fell-game-over', { if (this.gameIng) {
score: this.score, if (this.countdown > 0) {
reason: 1 engine.globalEvent.dispatchEvent('food-fell-time-update', {
}); time: this.countdown,
this.died() });
} this.countdown -= 1
} else {
engine.globalEvent.dispatchEvent('food-fell-game-over', {
score: this.score,
reason: 1
});
this.died()
} }
}, 1000) }
} }
/** /**
* npc开始掉落 * npc开始掉落
*/ */
beginNpc() { beginNpc() {
this.timer = setTimeout(() => { // this.timer = setTimeout(() => {
if (this.gameIng) {
this.speed += props.acceleratedSpeed; // //递归执行
this.creatNpc() // this.beginNpc()
// }, 2000 / this.speed)
}
cacheTime2=0
updateTimeBeginNpc(){
if(Date.now()-this.cacheTime2>(2000 / this.speed)){
this.cacheTime2=Date.now()
}else{
return;
}
if (this.gameIng) {
this.speed += props.acceleratedSpeed;
if(this.speed >= props.maxSpeed){
this.speed = props.maxSpeed
} }
//递归执行 this.creatNpc()
this.beginNpc() }
}, 2000 / this.speed)
} }
/** /**
...@@ -216,7 +253,7 @@ export default class GameView extends engine.Container { ...@@ -216,7 +253,7 @@ export default class GameView extends engine.Container {
private creatNpc() { private creatNpc() {
let goods = this._goods = <Goods>ObjectPool.getObject(PoolName); let goods = this._goods = <Goods>ObjectPool.getObject(PoolName);
this.goodsItems.push(goods) this.goodsItems.push(goods)
console.log(goods); //console.log(goods);
this.NpcBg.addChild(goods); this.NpcBg.addChild(goods);
goods.addEventListener(engine.Event.ENTER_FRAME, goods["onGoodsEnter"] = () => { goods.addEventListener(engine.Event.ENTER_FRAME, goods["onGoodsEnter"] = () => {
...@@ -229,7 +266,7 @@ export default class GameView extends engine.Container { ...@@ -229,7 +266,7 @@ export default class GameView extends engine.Container {
//如果玩家和物品发生碰撞 //如果玩家和物品发生碰撞
if (this.hasHit(this.player, goods)) { if (this.hasHit(this.player, goods)) {
if (goods["npcType"].indexOf("rain") > -1) { if (goods["npcType"].indexOf("rain") > -1) {
console.log("碰到雨滴") //console.log("碰到雨滴")
this.score += props.rainScore; this.score += props.rainScore;
this.waterSvga.visible=true; this.waterSvga.visible=true;
// this.waterSvga.x= goods.x - this.player.x; // this.waterSvga.x= goods.x - this.player.x;
...@@ -243,7 +280,7 @@ export default class GameView extends engine.Container { ...@@ -243,7 +280,7 @@ export default class GameView extends engine.Container {
} }
} else if (goods["npcType"] == "stone") { } else if (goods["npcType"] == "stone") {
console.log("碰到石头") //console.log("碰到石头")
this.score += props.stoneScore this.score += props.stoneScore
if(this.score<0){ if(this.score<0){
this.score=0; this.score=0;
...@@ -254,7 +291,7 @@ export default class GameView extends engine.Container { ...@@ -254,7 +291,7 @@ export default class GameView extends engine.Container {
this.stoneSvga.visible=false; this.stoneSvga.visible=false;
}, this); }, this);
} else if (goods["npcType"] == "boom") { } else if (goods["npcType"] == "boom") {
console.log("碰到炸弹") //console.log("碰到炸弹")
this.boomSvga.visible=true; this.boomSvga.visible=true;
this.boomSvga.play(false, false) this.boomSvga.play(false, false)
this.died() this.died()
...@@ -281,7 +318,7 @@ export default class GameView extends engine.Container { ...@@ -281,7 +318,7 @@ export default class GameView extends engine.Container {
* 玩家死亡 * 玩家死亡
*/ */
private died() { private died() {
this.pause() this.pause();
} }
/** /**
...@@ -327,7 +364,6 @@ export default class GameView extends engine.Container { ...@@ -327,7 +364,6 @@ export default class GameView extends engine.Container {
let playerH=a.height let playerH=a.height
let playerW=a.width let playerW=a.width
let playerX=a.x let playerX=a.x
console.log("props",props.playerHeight)
if(props.playerHeight){ if(props.playerHeight){
playerH=props.playerHeight playerH=props.playerHeight
} }
......
...@@ -62,7 +62,7 @@ export class Goods extends engine.Container { ...@@ -62,7 +62,7 @@ export class Goods extends engine.Container {
let random=Math.random() let random=Math.random()
if(typeof (props.goodsProbability) == 'string'){ if(typeof (props.goodsProbability) == 'string'){
props.goodsProbability=props.goodsProbability.split(',').map((i: string) => +i) props.goodsProbability=props.goodsProbability.split(',').map((i: string) => +i)
console.log(props.goodsProbability); //console.log(props.goodsProbability);
} }
if(random<props.goodsProbability[0]){ if(random<props.goodsProbability[0]){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment