Commit 1c89e887 authored by wildfirecode's avatar wildfirecode

1

parent 86132dab
This diff is collapsed.
...@@ -46,19 +46,19 @@ function launchWithCustomModule(customModule) { ...@@ -46,19 +46,19 @@ function launchWithCustomModule(customModule) {
}, 100); }, 100);
setTimeout(() => { setTimeout(() => {
engine.globalEvent.dispatchEvent('recycling-start', { time: 1000, maxScore: 200 }); engine.globalEvent.dispatchEvent('recycling-start', { time: 2, maxScore: 2 });
const d = engine.gameStage.sceneContainer.getChildAt(0); const d = engine.gameStage.sceneContainer.getChildAt(0);
}, 200); }, 200);
// setTimeout(() => { setTimeout(() => {
// engine.globalEvent.dispatchEvent('recycling-start', { time: 2 }); engine.globalEvent.dispatchEvent('recycling-start', { time: 8, maxScore: 2 });
// const d = engine.gameStage.sceneContainer.getChildAt(0); const d = engine.gameStage.sceneContainer.getChildAt(0);
// }, 1000 * 10); }, 1000 * 10);
}); });
engine.globalEvent.addEventListener('recycling-time-update', (e) => { engine.globalEvent.addEventListener('recycling-time-update', (e) => {
// console.log(e.type, e.data); console.log(e.type, e.data);
}); });
engine.globalEvent.addEventListener('recycling-score-update', (e) => { engine.globalEvent.addEventListener('recycling-score-update', (e) => {
console.log(e.type, e.data); console.log(e.type, e.data);
......
...@@ -241,11 +241,10 @@ ...@@ -241,11 +241,10 @@
this.conveyor1 = conveyor1; this.conveyor1 = conveyor1;
}; };
Conveyors.prototype.setDefault = function () { Conveyors.prototype.setDefault = function () {
this.clear();
this.score = 0; this.score = 0;
this.conveyorsPool.push(this.conveyor0); this.conveyorsPool.push(this.conveyor0);
this.conveyorsPool.push(this.conveyor1); this.conveyorsPool.push(this.conveyor1);
var allConfigs = shuffle(this.GarbageConfig); var allConfigs = shuffle(this.GarbageConfig.concat([]));
for (var i = 0; i < GarbageConfig.config.length; i++) { for (var i = 0; i < GarbageConfig.config.length; i++) {
allConfigs[i].idx = i; allConfigs[i].idx = i;
allConfigs[i].isRight = false; allConfigs[i].isRight = false;
...@@ -420,16 +419,19 @@ ...@@ -420,16 +419,19 @@
view.y = e.stageY - target.texture.height / 2; view.y = e.stageY - target.texture.height / 2;
view.type = target['type']; view.type = target['type'];
view.name = target['name']; view.name = target['name'];
this.wrapper.once(engine.MouseEvent.MOUSE_UP, this.onStageMouseUp, this); this.wrapper.addEventListener(engine.MouseEvent.MOUSE_UP, this.onStageMouseUp, this);
this.wrapper.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onStageMouseMove, this); this.wrapper.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onStageMouseMove, this);
}; };
Conveyors.prototype.onStageMouseMove = function (e) { Conveyors.prototype.onStageMouseMove = function (e) {
console.log('onStageMouseMove');
var view = this._currentDragView; var view = this._currentDragView;
view.x = e.stageX - view.texture.width / 2; view.x = e.stageX - view.texture.width / 2;
view.y = e.stageY - view.texture.height / 2; view.y = e.stageY - view.texture.height / 2;
}; };
Conveyors.prototype.onStageMouseUp = function (e) { Conveyors.prototype.onStageMouseUp = function (e) {
var _this = this; var _this = this;
console.log('onStageMouseUp');
this.wrapper.removeEventListener(engine.MouseEvent.MOUSE_UP, this.onStageMouseUp, this);
this.wrapper.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onStageMouseMove, this); this.wrapper.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onStageMouseMove, this);
if (!this._currentDragView) if (!this._currentDragView)
return; return;
...@@ -453,6 +455,8 @@ ...@@ -453,6 +455,8 @@
}); });
}; };
Conveyors.prototype.clear = function () { Conveyors.prototype.clear = function () {
this.conveyor0.x = 0;
this.conveyor1.x = 764;
this.conveyorsPool.forEach(function (i) { this.conveyorsPool.forEach(function (i) {
i.clear(); i.clear();
}); });
...@@ -461,6 +465,11 @@ ...@@ -461,6 +465,11 @@
this.stores = []; this.stores = [];
}; };
Conveyors.prototype.timeout = function () { Conveyors.prototype.timeout = function () {
if (this._currentDragView) {
removeChild(this._currentDragView);
}
this.wrapper.removeEventListener(engine.MouseEvent.MOUSE_UP, this.onStageMouseUp, this);
this.wrapper.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onStageMouseMove, this);
this.gameOver(); this.gameOver();
}; };
Conveyors.prototype.checkHitRect = function () { Conveyors.prototype.checkHitRect = function () {
...@@ -772,10 +781,10 @@ ...@@ -772,10 +781,10 @@
}; };
GameView.prototype.configConveyors = function () { GameView.prototype.configConveyors = function () {
var conveyor0 = new Conveyor(); var conveyor0 = new Conveyor();
conveyor0.x = 0;
var conveyor1 = new Conveyor(); var conveyor1 = new Conveyor();
this.addChild(conveyor0); this.addChild(conveyor0);
this.addChild(conveyor1); this.addChild(conveyor1);
conveyor0.x = 0;
conveyor1.x = 764; conveyor1.x = 764;
this.conveyors = new Conveyors(this); this.conveyors = new Conveyors(this);
this.conveyors.initData(conveyor0, conveyor1); this.conveyors.initData(conveyor0, conveyor1);
...@@ -811,6 +820,10 @@ ...@@ -811,6 +820,10 @@
setGuide(); setGuide();
_a.label = 2; _a.label = 2;
case 2: case 2:
this.conveyors.clear();
return [4, this.countdown.startCountDown()];
case 3:
_a.sent();
this.startGame(); this.startGame();
engine.globalEvent.dispatchEvent('recycling-time-update', { engine.globalEvent.dispatchEvent('recycling-time-update', {
second: this.getSecond(), second: this.getSecond(),
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -36,7 +36,6 @@ export default class Conveyors extends engine.Sprite { ...@@ -36,7 +36,6 @@ export default class Conveyors extends engine.Sprite {
} }
private setDefault() { private setDefault() {
this.clear();
this.score = 0; this.score = 0;
...@@ -44,7 +43,7 @@ export default class Conveyors extends engine.Sprite { ...@@ -44,7 +43,7 @@ export default class Conveyors extends engine.Sprite {
this.conveyorsPool.push(this.conveyor1); this.conveyorsPool.push(this.conveyor1);
// 本局游戏的20种垃圾 // 本局游戏的20种垃圾
const allConfigs = shuffle(this.GarbageConfig); const allConfigs = shuffle(this.GarbageConfig.concat([]));
for (let i = 0; i < GarbageConfig.config.length; i++) { for (let i = 0; i < GarbageConfig.config.length; i++) {
allConfigs[i].idx = i; allConfigs[i].idx = i;
...@@ -233,7 +232,7 @@ export default class Conveyors extends engine.Sprite { ...@@ -233,7 +232,7 @@ export default class Conveyors extends engine.Sprite {
private _currentDragView: engine.Sprite; private _currentDragView: engine.Sprite;
private _currentTarget: engine.Sprite; private _currentTarget: engine.Sprite;
onDown_garbage(e: engine.MouseEvent) { onDown_garbage(e: engine.MouseEvent) {
if(this._currentDragView){ if (this._currentDragView) {
removeChild(this._currentDragView) removeChild(this._currentDragView)
} }
const target: engine.Sprite = e.target; const target: engine.Sprite = e.target;
...@@ -246,17 +245,20 @@ export default class Conveyors extends engine.Sprite { ...@@ -246,17 +245,20 @@ export default class Conveyors extends engine.Sprite {
view.y = e.stageY - target.texture.height / 2; view.y = e.stageY - target.texture.height / 2;
view.type = target['type']; view.type = target['type'];
view.name = target['name']; view.name = target['name'];
this.wrapper.once(engine.MouseEvent.MOUSE_UP, this.onStageMouseUp, this) this.wrapper.addEventListener(engine.MouseEvent.MOUSE_UP, this.onStageMouseUp, this)
this.wrapper.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onStageMouseMove, this) this.wrapper.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onStageMouseMove, this)
} }
onStageMouseMove(e: engine.MouseEvent) { onStageMouseMove(e: engine.MouseEvent) {
console.log('onStageMouseMove')
const view = this._currentDragView; const view = this._currentDragView;
view.x = e.stageX - view.texture.width / 2; view.x = e.stageX - view.texture.width / 2;
view.y = e.stageY - view.texture.height / 2; view.y = e.stageY - view.texture.height / 2;
} }
onStageMouseUp(e: engine.MouseEvent) { onStageMouseUp(e: engine.MouseEvent) {
console.log('onStageMouseUp')
this.wrapper.removeEventListener(engine.MouseEvent.MOUSE_UP, this.onStageMouseUp, this)
this.wrapper.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onStageMouseMove, this) this.wrapper.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onStageMouseMove, this)
if (!this._currentDragView) return; if (!this._currentDragView) return;
const result: GarbageTypes = this.checkHitRect(); const result: GarbageTypes = this.checkHitRect();
...@@ -281,7 +283,9 @@ export default class Conveyors extends engine.Sprite { ...@@ -281,7 +283,9 @@ export default class Conveyors extends engine.Sprite {
}); });
} }
private clear() { clear() {
this.conveyor0.x = 0;
this.conveyor1.x = 764;
this.conveyorsPool.forEach(i => { this.conveyorsPool.forEach(i => {
i.clear(); i.clear();
}); });
...@@ -291,6 +295,11 @@ export default class Conveyors extends engine.Sprite { ...@@ -291,6 +295,11 @@ export default class Conveyors extends engine.Sprite {
} }
timeout() { timeout() {
if (this._currentDragView) {
removeChild(this._currentDragView)
}
this.wrapper.removeEventListener(engine.MouseEvent.MOUSE_UP, this.onStageMouseUp, this)
this.wrapper.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onStageMouseMove, this)
this.gameOver(); this.gameOver();
} }
......
...@@ -91,11 +91,10 @@ export default class GameView extends engine.Container { ...@@ -91,11 +91,10 @@ export default class GameView extends engine.Container {
private configConveyors() { private configConveyors() {
const conveyor0 = new Conveyor(); const conveyor0 = new Conveyor();
conveyor0.x = 0;
const conveyor1 = new Conveyor(); const conveyor1 = new Conveyor();
this.addChild(conveyor0); this.addChild(conveyor0);
this.addChild(conveyor1); this.addChild(conveyor1);
conveyor0.x = 0;
conveyor1.x = 764; conveyor1.x = 764;
this.conveyors = new Conveyors(this); this.conveyors = new Conveyors(this);
this.conveyors.initData(conveyor0, conveyor1) this.conveyors.initData(conveyor0, conveyor1)
...@@ -126,7 +125,9 @@ export default class GameView extends engine.Container { ...@@ -126,7 +125,9 @@ export default class GameView extends engine.Container {
setGuide(); setGuide();
} }
// await this.countdown.startCountDown(); this.conveyors.clear()
await this.countdown.startCountDown();
this.startGame(); this.startGame();
......
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