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