Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-libs
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
zeroing-libs
Commits
2533efe0
Commit
2533efe0
authored
Aug 11, 2020
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
111
parent
5a8face8
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
238 additions
and
653 deletions
+238
-653
p2demo.json
dist/customs/p2demo.json
+1
-1
app.js
src/custom/p2demo/debug/app.js
+3
-4
main.js
src/custom/p2demo/debug/main.js
+127
-296
main.js.map
src/custom/p2demo/debug/main.js.map
+1
-1
GameView.ts
src/custom/p2demo/src/game/GameView.ts
+106
-350
GameWrapper.ts
src/custom/p2demo/src/game/GameWrapper.ts
+0
-1
No files found.
dist/customs/p2demo.json
View file @
2533efe0
...
...
@@ -89,5 +89,5 @@
}
},
"id"
:
"p2demo"
,
"code"
:
"(function (global, factory) {
\n
\t
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
\n\t
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
\n\t
(global = global || self, global.p2demo = factory(global.tslib));
\n
}(this, (function (tslib) { 'use strict';
\n\n\t
var props = {};
\n\t
function prepareProps() {
\n\t
var metaProps = getProps();
\n\t
engine.injectProp(props, metaProps);
\n\t
}
\n\t
function injectProps(p) {
\n\t
engine.injectProp(props, p);
\n\t
}
\n\n\t
var picMap = {};
\n\t
var posMap = {};
\n\t
var qietu = (function (parent, url, MAX_COL, MAX_ROW) {
\n\t
if (picMap[url]) {
\n\t
var pics = picMap[url];
\n\t
for (var _i = 0, pics_1 = pics; _i < pics_1.length; _i++) {
\n\t
var pic = pics_1[_i];
\n\t
parent.addChild(pic);
\n\t
}
\n\t
return [picMap[url], posMap[url]];
\n\t
}
\n\t
var W = props.W;
\n\t
var H = props.H;
\n\t
var GAP = props.GAP;
\n\t
var spr = [];
\n\t
var pos = [];
\n\t
var _loop_1 = function (row) {
\n\t
var _loop_2 = function (col) {
\n\t
var child = engine.Sprite.fromImage(url);
\n\t
spr.push(child);
\n\t
child.scaleX = 1 / MAX_COL;
\n\t
child.scaleY = 1 / MAX_ROW;
\n\t
parent.addChild(child);
\n\t
child.x = col * (W / MAX_COL + GAP);
\n\t
child.y = row * (H / MAX_ROW + GAP);
\n\t
pos.push([child.x, child.y]);
\n\t
child.addEventListener(engine.Event.COMPLETE, function () {
\n\t
var uvs = new Float32Array([
\n\t
col / MAX_COL,
\n\t
row / MAX_ROW,
\n\t
(col + 1) / MAX_COL,
\n\t
row / MAX_ROW,
\n\t
(col + 1) / MAX_COL,
\n\t
(row + 1) / MAX_ROW,
\n\t
col / MAX_COL,
\n\t
(row + 1) / MAX_ROW,
\n\t
]);
\n\t
child.uvs = uvs;
\n\t
});
\n\t
};
\n\t
for (var col = 0; col < MAX_COL; col++) {
\n\t
_loop_2(col);
\n\t
}
\n\t
};
\n\t
for (var row = 0; row < MAX_ROW; row++) {
\n\t
_loop_1(row);
\n\t
}
\n\t
picMap[url] = spr.concat([]);
\n\t
posMap[url] = pos.concat([]);
\n\t
return [spr, pos];
\n\t
});
\n\n\t
function getIndexFromRC(row, col, maxCol) {
\n\t
var index;
\n\t
index = row * maxCol + col;
\n\t
return index;
\n\t
}
\n\t
function getRandomArray(array) {
\n\t
array.sort(function () {
\n\t
return .5 - Math.random();
\n\t
});
\n\t
}
\n\n\t
var MAX_COL;
\n\t
var MAX_ROW;
\n\t
var W;
\n\t
var H;
\n\t
var GAP;
\n\t
var GAME_TIME;
\n\t
var w;
\n\t
var h;
\n\t
var GameView = (function (_super) {
\n\t
tslib.__extends(GameView, _super);
\n\t
function GameView() {
\n\t
var _this = _super.call(this) || this;
\n\t
_this._timeCounter = 0;
\n\t
_this.listenStageOn = 1;
\n\t
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
\n\t
return _this;
\n\t
}
\n\t
GameView.prototype.start = function () {
\n\t
var _this = this;
\n\t
MAX_COL = props.column || props.MAX_COL;
\n\t
MAX_ROW = props.row || props.MAX_ROW;
\n\t
GAME_TIME = props.gameTime || props.GAME_TIME;
\n\t
console.log('start', props.column, props.row, props.gameTime);
\n\t
if (!this.guideHole) {
\n\t
this.guideHole = new engine.Image();
\n\t
this.guideHole.source = 'asset://' + props.blockUrl;
\n\t
this.guideHole.mouseChildren = this.guideHole.mouseEnabled = false;
\n\t
}
\n\t
if (this.pictures) {
\n\t
for (var _i = 0, _a = this.pictures; _i < _a.length; _i++) {
\n\t
var pic = _a[_i];
\n\t
if (pic && pic.wrapper)
\n\t
pic.wrapper.removeChild(pic);
\n\t
}
\n\t
}
\n\t
console.log('on start');
\n\t
engine.globalEvent.dispatchEvent('pictures-time-update', {
\n\t
second: this.getSecond(),
\n\t
});
\n\t
var result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);
\n\t
this.picturesWrapper.addChild(this.guideHole);
\n\t
console.log(this.picturesWrapper);
\n\t
this.pictures = result[0];
\n\t
this.rightList = this.pictures.concat([]);
\n\t
var posList = result[1];
\n\t
getRandomArray(this.pictures);
\n\t
var i = 0;
\n\t
var len;
\n\t
len = this.pictures.length;
\n\t
for (; i < len; i++) {
\n\t
this.dragPic = this.pictures[i];
\n\t
this.pictures[i].addEventListener(engine.MouseEvent.MOUSE_DOWN, this.onDown, this);
\n\t
var _b = posList[i], x = _b[0], y = _b[1];
\n\t
this.dragPic.x = x;
\n\t
this.dragPic.y = y;
\n\t
}
\n\t
this._timer = setInterval(function () {
\n\t
_this.onTimer();
\n\t
}, 10);
\n\t
this.date = new Date().getTime();
\n\t
};
\n\t
GameView.prototype.onTimer = function () {
\n\t
var date = new Date().getTime();
\n\t
var gap = ((date - this.date) / 1000);
\n\t
this.date = date;
\n\t
console.log(gap,
\"
gap
\"
);
\n\t
GAME_TIME -= gap;
\n\t
if (GAME_TIME < 0) {
\n\t
GAME_TIME = 0;
\n\t
}
\n\t
GAME_TIME = this.afterPointTwo(GAME_TIME);
\n\t
GAME_TIME = GAME_TIME.toFixed(2);
\n\t
if (GAME_TIME < 10) {
\n\t
GAME_TIME = '0' + GAME_TIME;
\n\t
}
\n\t
console.log(GAME_TIME);
\n\t
engine.globalEvent.dispatchEvent('pictures-time-update', {
\n\t
second: this.getSecond(),
\n\t
});
\n\t
if (this.getSecond() == 0) {
\n\t
this.stop();
\n\t
engine.globalEvent.dispatchEvent('pictures-game-fail', {
\n\t
reason: 1
\n\t
});
\n\t
}
\n\t
};
\n\t
GameView.prototype.afterPointTwo = function (n) {
\n\t
var floatN = parseFloat(n);
\n\t
if (isNaN(floatN)) {
\n\t
return;
\n\t
}
\n\t
floatN = Math.round(floatN * 100) / 100;
\n\t
return floatN;
\n\t
};
\n\t
GameView.prototype.getSecond = function () {
\n\t
return GAME_TIME;
\n\t
};
\n\t
GameView.prototype.stop = function () {
\n\t
GAME_TIME = props.GAME_TIME;
\n\t
clearInterval(this._timer);
\n\t
var len = this.pictures.length;
\n\t
for (var i = 0; i < len; i++) {
\n\t
this.pictures[i].removeAllEventListener();
\n\t
}
\n\t
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
\n\t
};
\n\t
GameView.prototype.createRects = function () { };
\n\t
GameView.prototype.setup = function () {
\n\t
MAX_COL = props.MAX_COL;
\n\t
MAX_ROW = props.MAX_ROW;
\n\t
GAME_TIME = props.GAME_TIME;
\n\t
W = props.W;
\n\t
H = props.H;
\n\t
GAP = props.GAP;
\n\t
w = W / MAX_COL;
\n\t
h = H / MAX_ROW;
\n\t
console.log('onSteup', props);
\n\t
var parent = new engine.Sprite();
\n\t
this.picturesWrapper = parent;
\n\t
this.addChild(parent);
\n\t
};
\n\t
GameView.prototype.onDown = function (e) {
\n\t
var stageLeft = (750 - props.W) / 2;
\n\t
var stageTop = (this.stage.height - props.H) / 2;
\n\t
this.dragPic = e.target;
\n\t
this.picturesWrapper.addChild(this.dragPic);
\n\t
this.localPicX = e.localX / MAX_COL;
\n\t
this.localPicY = e.localY / MAX_ROW;
\n\t
this.distanceX = this.dragPic.x;
\n\t
this.distanceY = this.dragPic.y;
\n\t
this.indexJ = Math.floor((this.distanceX) / (w + GAP));
\n\t
this.indexI = Math.floor((this.distanceY) / (h + GAP));
\n\t
this.index = (this.indexI) * MAX_COL + this.indexJ;
\n\t
this.centerX = Math.floor((e.clientX - stageLeft) / w) * w + w / 2;
\n\t
this.centerY = Math.floor((e.clientY - stageTop) / h) * h + h / 2;
\n\t
this.stage.addEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
\n\t
this.stage.addEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
\n\t
};
\n\t
GameView.prototype.stageOnUp = function (e) {
\n\t
var stageLeft = (750 - props.W) / 2;
\n\t
var stageTop = (this.stage.height - props.H) / 2;
\n\t
this.stage.removeEventListener(engine.MouseEvent.MOUSE_MOVE, this.onMove, this);
\n\t
this.stage.removeEventListener(engine.MouseEvent.MOUSE_UP, this.stageOnUp, this);
\n\t
if (this.centerY < stageTop || this.centerX < stageLeft) {
\n\t
this.dragPic.x = this.distanceX;
\n\t
this.dragPic.y = this.distanceY;
\n\t
}
\n\t
var curJ = Math.floor(this.centerX / (w + GAP));
\n\t
var curI = Math.floor(this.centerY / (h + GAP));
\n\t
this.picturesWrapper.addChild(this.guideHole);
\n\t
if (0 <= curJ && curJ < (MAX_COL) && 0 <= curI && curI < (MAX_ROW)) {
\n\t
var index = getIndexFromRC(curI, curJ, MAX_COL);
\n\t
var dropPic = this.pictures[index];
\n\t
var dropPicX = dropPic.x + stageLeft;
\n\t
var dropPicy = dropPic.y + stageTop;
\n\t
dropPic.x = this.distanceX;
\n\t
dropPic.y = this.distanceY;
\n\t
this.dragPic.x = dropPicX - stageLeft;
\n\t
this.dragPic.y = dropPicy - stageTop;
\n\t
var dropPicIndex = this.pictures.indexOf(dropPic);
\n\t
var dragPicIndex = this.pictures.indexOf(this.dragPic);
\n\t
this.pictures[dropPicIndex] = this.dragPic;
\n\t
this.pictures[dragPicIndex] = dropPic;
\n\t
if (dragPicIndex === dropPicIndex) {
\n\t
this.dragPic.x = this.distanceX;
\n\t
this.dragPic.y = this.distanceY;
\n\t
}
\n\t
var result = true;
\n\t
for (var j = 0; j < this.rightList.length; j++) {
\n\t
if (this.rightList[j] != this.pictures[j]) {
\n\t
result = false;
\n\t
break;
\n\t
}
\n\t
}
\n\t
if (result) {
\n\t
this.onSuccess();
\n\t
}
\n\t
}
\n\t
else {
\n\t
this.dragPic.x = this.distanceX;
\n\t
this.dragPic.y = this.distanceY;
\n\t
}
\n\t
};
\n\t
GameView.prototype.onSuccess = function () {
\n\t
console.log('拼图成功!');
\n\t
engine.globalEvent.dispatchEvent('pictures-game-success', { time: GAME_TIME });
\n\t
this.stop();
\n\t
};
\n\t
GameView.prototype.onMove = function (e) {
\n\t
this.dragPic.x = e.stageX - this.localPicX - (750 - props.W) / 2;
\n\t
this.dragPic.y = e.stageY - this.localPicY - (this.stage.height - props.H) / 2;
\n\t
this.centerX = this.dragPic.x + w / 2;
\n\t
this.centerY = this.dragPic.y + h / 2;
\n\t
};
\n\t
return GameView;
\n\t
}(engine.Container));
\n\n\t
var GameWrapper = (function (_super) {
\n\t
tslib.__extends(GameWrapper, _super);
\n\t
function GameWrapper() {
\n\t
var _this = _super.call(this) || this;
\n\t
engine.globalEvent.addEventListener('pictures-start', _this.start, _this);
\n\t
engine.globalEvent.addEventListener('pictures-stop', _this.stop, _this);
\n\t
var gameView = _this._gameView = new GameView();
\n\t
_this.addChild(gameView);
\n\t
return _this;
\n\t
}
\n\t
GameWrapper.prototype.start = function (event) {
\n\t
injectProps(event.data);
\n\t
this._gameView.start();
\n\t
};
\n\t
GameWrapper.prototype.stop = function (event) {
\n\t
this._gameView.stop();
\n\t
};
\n\t
return GameWrapper;
\n\t
}(engine.Container));
\n\n\t
function index (props) {
\n\t
prepareProps();
\n\t
injectProps(props);
\n\t
var instance = new GameWrapper();
\n\t
return instance;
\n\t
}
\n\n\t
return index;
\n\n
})));
\n
"
"code"
:
"(function (global, factory) {
\n
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
\n
typeof define === 'function' && define.amd ? define(['tslib'], factory) :
\n
(global = global || self, global.p2demo = factory(global.tslib));
\n
}(this, (function (tslib) { 'use strict';
\n\n
var GameView = (function (_super) {
\n
tslib.__extends(GameView, _super);
\n
function GameView() {
\n
var _this = _super.call(this) || this;
\n
_this.factor = 10;
\n
_this.isDebug = 1;
\n
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
\n
return _this;
\n
}
\n
GameView.prototype.createBall = function (r) {
\n
var shape = new engine.Shape();
\n
shape.beginFill(0xfff000);
\n
shape.drawCircle(0, 0, r);
\n
shape.endFill();
\n
return shape;
\n
};
\n
GameView.prototype.start = function () {
\n
console.log('start');
\n
this.stage.addEventListener(engine.MouseEvent.CLICK, this.onClick, this);
\n
};
\n
GameView.prototype.createBox = function (width, height) {
\n
var shape = new engine.Shape();
\n
shape.beginFill(0xfff000);
\n
shape.drawRect(-width / 2, -height / 2, width, height);
\n
shape.endFill();
\n
return shape;
\n
};
\n
GameView.prototype.onClick = function (e) {
\n
var _a = this, world = _a.world, factor = _a.factor;
\n
var positionX = (e.stageX / factor);
\n
var positionY = ((engine.gameStage.stage.height - e.stageY) / factor);
\n
var display;
\n
if (Math.random() > .5) {
\n
var boxShape = new p2.Box({ width: 200 / factor, height: 100 / factor });
\n
var boxBody = new p2.Body({ mass: 1, position: [positionX, positionY], angularVelocity: 1 });
\n
boxBody.addShape(boxShape);
\n
world.addBody(boxBody);
\n
if (this.isDebug) {
\n
display = this.createBox(boxShape.width * factor, boxShape.height * factor);
\n
}
\n
}
\n
else {
\n
var boxShape = new p2.Circle({ radius: 200 / 2 / factor });
\n
var boxBody = new p2.Body({ mass: 1, position: [positionX, positionY] });
\n
boxBody.addShape(boxShape);
\n
world.addBody(boxBody);
\n
if (this.isDebug) {
\n
display = this.createBall(boxShape.radius * factor);
\n
}
\n
}
\n
boxBody.displays = [display];
\n
this.addChild(display);
\n
};
\n
GameView.prototype.setup = function () {
\n
console.log('setup');
\n
var world = new p2.World({});
\n
world.sleepMode = p2.World.BODY_SLEEPING;
\n
var planeShape = new p2.Plane();
\n
var planeBody = new p2.Body();
\n
planeBody.addShape(planeShape);
\n
planeBody.displays = [];
\n
world.addBody(planeBody);
\n
this.world = world;
\n
this.stage.addEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this);
\n
};
\n
GameView.prototype.onEnterFrame = function () {
\n
var _a = this, world = _a.world, factor = _a.factor;
\n
world.step(60 / 1000);
\n
var stageHeight = engine.gameStage.stage.height;
\n
var l = world.bodies.length;
\n
for (var i = 0; i < l; i++) {
\n
var boxBody = world.bodies[i];
\n
var box = boxBody.displays[0];
\n
if (box) {
\n
box.x = boxBody.position[0] * factor;
\n
box.y = stageHeight - boxBody.position[1] * factor;
\n
box.rotation = 360 - (boxBody.angle + boxBody.shapes[0].angle) * 180 / Math.PI;
\n
if (boxBody.sleepState == p2.Body.SLEEPING) {
\n
box.alpha = 0.5;
\n
}
\n
else {
\n
box.alpha = 1;
\n
}
\n
}
\n
}
\n
};
\n
return GameView;
\n
}(engine.Container));
\n\n
var props = {};
\n
function prepareProps() {
\n
var metaProps = getProps();
\n
engine.injectProp(props, metaProps);
\n
}
\n
function injectProps(p) {
\n
engine.injectProp(props, p);
\n
}
\n
//# sourceMappingURL=props.js.map
\n\n
var GameWrapper = (function (_super) {
\n
tslib.__extends(GameWrapper, _super);
\n
function GameWrapper() {
\n
var _this = _super.call(this) || this;
\n
engine.globalEvent.addEventListener('pictures-start', _this.start, _this);
\n
engine.globalEvent.addEventListener('pictures-stop', _this.stop, _this);
\n
var gameView = _this._gameView = new GameView();
\n
_this.addChild(gameView);
\n
return _this;
\n
}
\n
GameWrapper.prototype.start = function (event) {
\n
injectProps(event.data);
\n
this._gameView.start();
\n
};
\n
GameWrapper.prototype.stop = function (event) {
\n
};
\n
return GameWrapper;
\n
}(engine.Container));
\n
//# sourceMappingURL=GameWrapper.js.map
\n\n
function index (props) {
\n
prepareProps();
\n
injectProps(props);
\n
var instance = new GameWrapper();
\n
return instance;
\n
}
\n
//# sourceMappingURL=index.js.map
\n\n
return index;
\n\n
})));
\n
"
}
src/custom/p2demo/debug/app.js
View file @
2533efe0
...
...
@@ -2,7 +2,7 @@
* Created by renjianfeng on 2020-03-13.
*/
const
customId
=
'p
ictures
'
;
const
customId
=
'p
2demo
'
;
(
async
function
()
{
let
customModule
=
await
fetch
(
`../meta.json`
);
...
...
@@ -55,9 +55,8 @@ function launchWithCustomModule(customModule) {
});
const
d
=
engine
.
gameStage
.
sceneContainer
.
getChildAt
(
0
);
engine
.
gameStage
.
sceneContainer
.
getChildAt
(
0
).
x
=
(
d
.
stage
.
width
-
props
.
W
)
/
2
;
engine
.
gameStage
.
sceneContainer
.
getChildAt
(
0
).
y
=
(
d
.
stage
.
height
-
props
.
H
)
/
2
;
},
1000
);
},
100
);
// setTimeout(() => {
// engine.globalEvent.dispatchEvent('pictures-start', {
...
...
src/custom/p2demo/debug/main.js
View file @
2533efe0
...
...
@@ -4,275 +4,105 @@
(
global
=
global
||
self
,
global
.
p2demo
=
factory
(
global
.
tslib
));
}(
this
,
(
function
(
tslib
)
{
'use strict'
;
var
props
=
{};
function
prepareProps
()
{
var
metaProps
=
getProps
();
engine
.
injectProp
(
props
,
metaProps
);
}
function
injectProps
(
p
)
{
engine
.
injectProp
(
props
,
p
);
}
var
picMap
=
{};
var
posMap
=
{};
var
qietu
=
(
function
(
parent
,
url
,
MAX_COL
,
MAX_ROW
)
{
if
(
picMap
[
url
])
{
var
pics
=
picMap
[
url
];
for
(
var
_i
=
0
,
pics_1
=
pics
;
_i
<
pics_1
.
length
;
_i
++
)
{
var
pic
=
pics_1
[
_i
];
parent
.
addChild
(
pic
);
}
return
[
picMap
[
url
],
posMap
[
url
]];
}
var
W
=
props
.
W
;
var
H
=
props
.
H
;
var
GAP
=
props
.
GAP
;
var
spr
=
[];
var
pos
=
[];
var
_loop_1
=
function
(
row
)
{
var
_loop_2
=
function
(
col
)
{
var
child
=
engine
.
Sprite
.
fromImage
(
url
);
spr
.
push
(
child
);
child
.
scaleX
=
1
/
MAX_COL
;
child
.
scaleY
=
1
/
MAX_ROW
;
parent
.
addChild
(
child
);
child
.
x
=
col
*
(
W
/
MAX_COL
+
GAP
);
child
.
y
=
row
*
(
H
/
MAX_ROW
+
GAP
);
pos
.
push
([
child
.
x
,
child
.
y
]);
child
.
addEventListener
(
engine
.
Event
.
COMPLETE
,
function
()
{
var
uvs
=
new
Float32Array
([
col
/
MAX_COL
,
row
/
MAX_ROW
,
(
col
+
1
)
/
MAX_COL
,
row
/
MAX_ROW
,
(
col
+
1
)
/
MAX_COL
,
(
row
+
1
)
/
MAX_ROW
,
col
/
MAX_COL
,
(
row
+
1
)
/
MAX_ROW
,
]);
child
.
uvs
=
uvs
;
});
};
for
(
var
col
=
0
;
col
<
MAX_COL
;
col
++
)
{
_loop_2
(
col
);
}
};
for
(
var
row
=
0
;
row
<
MAX_ROW
;
row
++
)
{
_loop_1
(
row
);
}
picMap
[
url
]
=
spr
.
concat
([]);
posMap
[
url
]
=
pos
.
concat
([]);
return
[
spr
,
pos
];
});
function
getIndexFromRC
(
row
,
col
,
maxCol
)
{
var
index
;
index
=
row
*
maxCol
+
col
;
return
index
;
}
function
getRandomArray
(
array
)
{
array
.
sort
(
function
()
{
return
.
5
-
Math
.
random
();
});
}
var
MAX_COL
;
var
MAX_ROW
;
var
W
;
var
H
;
var
GAP
;
var
GAME_TIME
;
var
w
;
var
h
;
var
GameView
=
(
function
(
_super
)
{
tslib
.
__extends
(
GameView
,
_super
);
function
GameView
()
{
var
_this
=
_super
.
call
(
this
)
||
this
;
_this
.
_timeCounter
=
0
;
_this
.
listenStageOn
=
1
;
_this
.
factor
=
1
0
;
_this
.
isDebug
=
1
;
_this
.
once
(
engine
.
Event
.
ADDED_TO_STAGE
,
_this
.
setup
,
_this
);
return
_this
;
}
GameView
.
prototype
.
createBall
=
function
(
r
)
{
var
shape
=
new
engine
.
Shape
();
shape
.
beginFill
(
0xfff000
);
shape
.
drawCircle
(
0
,
0
,
r
);
shape
.
endFill
();
return
shape
;
};
GameView
.
prototype
.
start
=
function
()
{
var
_this
=
this
;
MAX_COL
=
props
.
column
||
props
.
MAX_COL
;
MAX_ROW
=
props
.
row
||
props
.
MAX_ROW
;
GAME_TIME
=
props
.
gameTime
||
props
.
GAME_TIME
;
console
.
log
(
'start'
,
props
.
column
,
props
.
row
,
props
.
gameTime
);
if
(
!
this
.
guideHole
)
{
this
.
guideHole
=
new
engine
.
Image
();
this
.
guideHole
.
source
=
'asset://'
+
props
.
blockUrl
;
this
.
guideHole
.
mouseChildren
=
this
.
guideHole
.
mouseEnabled
=
false
;
}
if
(
this
.
pictures
)
{
for
(
var
_i
=
0
,
_a
=
this
.
pictures
;
_i
<
_a
.
length
;
_i
++
)
{
var
pic
=
_a
[
_i
];
if
(
pic
&&
pic
.
wrapper
)
pic
.
wrapper
.
removeChild
(
pic
);
}
}
console
.
log
(
'on start'
);
engine
.
globalEvent
.
dispatchEvent
(
'pictures-time-update'
,
{
second
:
this
.
getSecond
(),
});
var
result
=
qietu
(
this
.
picturesWrapper
,
props
.
picUrl
,
MAX_COL
,
MAX_ROW
);
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
console
.
log
(
this
.
picturesWrapper
);
this
.
pictures
=
result
[
0
];
this
.
rightList
=
this
.
pictures
.
concat
([]);
var
posList
=
result
[
1
];
getRandomArray
(
this
.
pictures
);
var
i
=
0
;
var
len
;
len
=
this
.
pictures
.
length
;
for
(;
i
<
len
;
i
++
)
{
this
.
dragPic
=
this
.
pictures
[
i
];
this
.
pictures
[
i
].
addEventListener
(
engine
.
MouseEvent
.
MOUSE_DOWN
,
this
.
onDown
,
this
);
var
_b
=
posList
[
i
],
x
=
_b
[
0
],
y
=
_b
[
1
];
this
.
dragPic
.
x
=
x
;
this
.
dragPic
.
y
=
y
;
}
this
.
_timer
=
setInterval
(
function
()
{
_this
.
onTimer
();
},
10
);
this
.
date
=
new
Date
().
getTime
();
console
.
log
(
'start'
);
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
CLICK
,
this
.
onClick
,
this
);
};
GameView
.
prototype
.
onTimer
=
function
()
{
var
date
=
new
Date
().
getTime
();
var
gap
=
((
date
-
this
.
date
)
/
1000
);
this
.
date
=
date
;
console
.
log
(
gap
,
"gap"
);
GAME_TIME
-=
gap
;
if
(
GAME_TIME
<
0
)
{
GAME_TIME
=
0
;
}
GAME_TIME
=
this
.
afterPointTwo
(
GAME_TIME
);
GAME_TIME
=
GAME_TIME
.
toFixed
(
2
);
if
(
GAME_TIME
<
10
)
{
GAME_TIME
=
'0'
+
GAME_TIME
;
GameView
.
prototype
.
createBox
=
function
(
width
,
height
)
{
var
shape
=
new
engine
.
Shape
();
shape
.
beginFill
(
0xfff000
);
shape
.
drawRect
(
-
width
/
2
,
-
height
/
2
,
width
,
height
);
shape
.
endFill
();
return
shape
;
};
GameView
.
prototype
.
onClick
=
function
(
e
)
{
var
_a
=
this
,
world
=
_a
.
world
,
factor
=
_a
.
factor
;
var
positionX
=
(
e
.
stageX
/
factor
);
var
positionY
=
((
engine
.
gameStage
.
stage
.
height
-
e
.
stageY
)
/
factor
);
var
display
;
if
(
Math
.
random
()
>
.
5
)
{
var
boxShape
=
new
p2
.
Box
({
width
:
200
/
factor
,
height
:
100
/
factor
});
var
boxBody
=
new
p2
.
Body
({
mass
:
1
,
position
:
[
positionX
,
positionY
],
angularVelocity
:
1
});
boxBody
.
addShape
(
boxShape
);
world
.
addBody
(
boxBody
);
if
(
this
.
isDebug
)
{
display
=
this
.
createBox
(
boxShape
.
width
*
factor
,
boxShape
.
height
*
factor
);
}
console
.
log
(
GAME_TIME
);
engine
.
globalEvent
.
dispatchEvent
(
'pictures-time-update'
,
{
second
:
this
.
getSecond
(),
});
if
(
this
.
getSecond
()
==
0
)
{
this
.
stop
();
engine
.
globalEvent
.
dispatchEvent
(
'pictures-game-fail'
,
{
reason
:
1
});
}
};
GameView
.
prototype
.
afterPointTwo
=
function
(
n
)
{
var
floatN
=
parseFloat
(
n
);
if
(
isNaN
(
floatN
))
{
return
;
else
{
var
boxShape
=
new
p2
.
Circle
({
radius
:
200
/
2
/
factor
});
var
boxBody
=
new
p2
.
Body
({
mass
:
1
,
position
:
[
positionX
,
positionY
]
});
boxBody
.
addShape
(
boxShape
);
world
.
addBody
(
boxBody
);
if
(
this
.
isDebug
)
{
display
=
this
.
createBall
(
boxShape
.
radius
*
factor
);
}
floatN
=
Math
.
round
(
floatN
*
100
)
/
100
;
return
floatN
;
};
GameView
.
prototype
.
getSecond
=
function
()
{
return
GAME_TIME
;
};
GameView
.
prototype
.
stop
=
function
()
{
GAME_TIME
=
props
.
GAME_TIME
;
clearInterval
(
this
.
_timer
);
var
len
=
this
.
pictures
.
length
;
for
(
var
i
=
0
;
i
<
len
;
i
++
)
{
this
.
pictures
[
i
].
removeAllEventListener
();
}
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
boxBody
.
displays
=
[
display
];
this
.
addChild
(
display
);
};
GameView
.
prototype
.
createRects
=
function
()
{
};
GameView
.
prototype
.
setup
=
function
()
{
MAX_COL
=
props
.
MAX_COL
;
MAX_ROW
=
props
.
MAX_ROW
;
GAME_TIME
=
props
.
GAME_TIME
;
W
=
props
.
W
;
H
=
props
.
H
;
GAP
=
props
.
GAP
;
w
=
W
/
MAX_COL
;
h
=
H
/
MAX_ROW
;
console
.
log
(
'onSteup'
,
props
);
var
parent
=
new
engine
.
Sprite
();
this
.
picturesWrapper
=
parent
;
this
.
addChild
(
parent
);
};
GameView
.
prototype
.
onDown
=
function
(
e
)
{
var
stageLeft
=
(
750
-
props
.
W
)
/
2
;
var
stageTop
=
(
this
.
stage
.
height
-
props
.
H
)
/
2
;
this
.
dragPic
=
e
.
target
;
this
.
picturesWrapper
.
addChild
(
this
.
dragPic
);
this
.
localPicX
=
e
.
localX
/
MAX_COL
;
this
.
localPicY
=
e
.
localY
/
MAX_ROW
;
this
.
distanceX
=
this
.
dragPic
.
x
;
this
.
distanceY
=
this
.
dragPic
.
y
;
this
.
indexJ
=
Math
.
floor
((
this
.
distanceX
)
/
(
w
+
GAP
));
this
.
indexI
=
Math
.
floor
((
this
.
distanceY
)
/
(
h
+
GAP
));
this
.
index
=
(
this
.
indexI
)
*
MAX_COL
+
this
.
indexJ
;
this
.
centerX
=
Math
.
floor
((
e
.
clientX
-
stageLeft
)
/
w
)
*
w
+
w
/
2
;
this
.
centerY
=
Math
.
floor
((
e
.
clientY
-
stageTop
)
/
h
)
*
h
+
h
/
2
;
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
console
.
log
(
'setup'
);
var
world
=
new
p2
.
World
({});
world
.
sleepMode
=
p2
.
World
.
BODY_SLEEPING
;
var
planeShape
=
new
p2
.
Plane
();
var
planeBody
=
new
p2
.
Body
();
planeBody
.
addShape
(
planeShape
);
planeBody
.
displays
=
[];
world
.
addBody
(
planeBody
);
this
.
world
=
world
;
this
.
stage
.
addEventListener
(
engine
.
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
,
this
);
};
GameView
.
prototype
.
stageOnUp
=
function
(
e
)
{
var
stageLeft
=
(
750
-
props
.
W
)
/
2
;
var
stageTop
=
(
this
.
stage
.
height
-
props
.
H
)
/
2
;
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
if
(
this
.
centerY
<
stageTop
||
this
.
centerX
<
stageLeft
)
{
this
.
dragPic
.
x
=
this
.
distanceX
;
this
.
dragPic
.
y
=
this
.
distanceY
;
}
var
curJ
=
Math
.
floor
(
this
.
centerX
/
(
w
+
GAP
));
var
curI
=
Math
.
floor
(
this
.
centerY
/
(
h
+
GAP
));
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
if
(
0
<=
curJ
&&
curJ
<
(
MAX_COL
)
&&
0
<=
curI
&&
curI
<
(
MAX_ROW
))
{
var
index
=
getIndexFromRC
(
curI
,
curJ
,
MAX_COL
);
var
dropPic
=
this
.
pictures
[
index
];
var
dropPicX
=
dropPic
.
x
+
stageLeft
;
var
dropPicy
=
dropPic
.
y
+
stageTop
;
dropPic
.
x
=
this
.
distanceX
;
dropPic
.
y
=
this
.
distanceY
;
this
.
dragPic
.
x
=
dropPicX
-
stageLeft
;
this
.
dragPic
.
y
=
dropPicy
-
stageTop
;
var
dropPicIndex
=
this
.
pictures
.
indexOf
(
dropPic
);
var
dragPicIndex
=
this
.
pictures
.
indexOf
(
this
.
dragPic
);
this
.
pictures
[
dropPicIndex
]
=
this
.
dragPic
;
this
.
pictures
[
dragPicIndex
]
=
dropPic
;
if
(
dragPicIndex
===
dropPicIndex
)
{
this
.
dragPic
.
x
=
this
.
distanceX
;
this
.
dragPic
.
y
=
this
.
distanceY
;
GameView
.
prototype
.
onEnterFrame
=
function
()
{
var
_a
=
this
,
world
=
_a
.
world
,
factor
=
_a
.
factor
;
world
.
step
(
60
/
1000
);
var
stageHeight
=
engine
.
gameStage
.
stage
.
height
;
var
l
=
world
.
bodies
.
length
;
for
(
var
i
=
0
;
i
<
l
;
i
++
)
{
var
boxBody
=
world
.
bodies
[
i
];
var
box
=
boxBody
.
displays
[
0
];
if
(
box
)
{
box
.
x
=
boxBody
.
position
[
0
]
*
factor
;
box
.
y
=
stageHeight
-
boxBody
.
position
[
1
]
*
factor
;
box
.
rotation
=
360
-
(
boxBody
.
angle
+
boxBody
.
shapes
[
0
].
angle
)
*
180
/
Math
.
PI
;
if
(
boxBody
.
sleepState
==
p2
.
Body
.
SLEEPING
)
{
box
.
alpha
=
0.5
;
}
var
result
=
true
;
for
(
var
j
=
0
;
j
<
this
.
rightList
.
length
;
j
++
)
{
if
(
this
.
rightList
[
j
]
!=
this
.
pictures
[
j
])
{
result
=
false
;
break
;
}
}
if
(
result
)
{
this
.
onSuccess
();
else
{
box
.
alpha
=
1
;
}
}
else
{
this
.
dragPic
.
x
=
this
.
distanceX
;
this
.
dragPic
.
y
=
this
.
distanceY
;
}
};
GameView
.
prototype
.
onSuccess
=
function
()
{
console
.
log
(
'拼图成功!'
);
engine
.
globalEvent
.
dispatchEvent
(
'pictures-game-success'
,
{
time
:
GAME_TIME
});
this
.
stop
();
};
GameView
.
prototype
.
onMove
=
function
(
e
)
{
this
.
dragPic
.
x
=
e
.
stageX
-
this
.
localPicX
-
(
750
-
props
.
W
)
/
2
;
this
.
dragPic
.
y
=
e
.
stageY
-
this
.
localPicY
-
(
this
.
stage
.
height
-
props
.
H
)
/
2
;
this
.
centerX
=
this
.
dragPic
.
x
+
w
/
2
;
this
.
centerY
=
this
.
dragPic
.
y
+
h
/
2
;
};
return
GameView
;
}(
engine
.
Container
));
var
props
=
{};
function
prepareProps
()
{
var
metaProps
=
getProps
();
engine
.
injectProp
(
props
,
metaProps
);
}
function
injectProps
(
p
)
{
engine
.
injectProp
(
props
,
p
);
}
//# sourceMappingURL=props.js.map
var
GameWrapper
=
(
function
(
_super
)
{
tslib
.
__extends
(
GameWrapper
,
_super
);
function
GameWrapper
()
{
...
...
@@ -288,10 +118,10 @@
this
.
_gameView
.
start
();
};
GameWrapper
.
prototype
.
stop
=
function
(
event
)
{
this
.
_gameView
.
stop
();
};
return
GameWrapper
;
}(
engine
.
Container
));
//# sourceMappingURL=GameWrapper.js.map
function
index
(
props
)
{
prepareProps
();
...
...
@@ -299,6 +129,7 @@
var
instance
=
new
GameWrapper
();
return
instance
;
}
//# sourceMappingURL=index.js.map
return
index
;
...
...
src/custom/p2demo/debug/main.js.map
View file @
2533efe0
{"version":3,"file":"index.js","sources":["src/custom/p2demo/src/props.ts","src/custom/p2demo/src/game/qietu.ts","src/custom/p2demo/src/game/utils.ts","src/custom/p2demo/src/game/GameView.ts","src/custom/p2demo/src/game/GameWrapper.ts","src/custom/p2demo/src/index.ts"],"sourcesContent":["/**\n * Created by rockyl on 2020-01-21.\n */\n\nexport let props: any = {};\n\nexport function prepareProps() {\n\tlet metaProps = getProps();\n\n\tengine.injectProp(props, metaProps);\n}\n\nexport function injectProps(p) {\n\tengine.injectProp(props, p);\n}\n","import { props } from \"../props\";\nconst urls = [];\nconst picMap = {};\nconst posMap = {};\nexport default (parent, url, MAX_COL, MAX_ROW) => {\n if (picMap[url]) {\n const pics:any[] = picMap[url];\n for (const pic of pics) {\n parent.addChild(pic);\n }\n return [picMap[url], posMap[url]]\n }\n\n const W = props.W;\n const H = props.H;\n const GAP = props.GAP;\n\n const spr = [];\n const pos = []\n\n for (let row = 0; row < MAX_ROW; row++) {\n for (let col = 0; col < MAX_COL; col++) {\n\n const child = engine.Sprite.fromImage(url);\n spr.push(child);\n\n child.scaleX = 1 / MAX_COL;\n child.scaleY = 1 / MAX_ROW;\n parent.addChild(child);\n child.x = col * (W / MAX_COL + GAP);\n child.y = row * (H / MAX_ROW + GAP);\n pos.push([child.x, child.y]);\n // child.texture.addEventListener('update', () => {\n child.addEventListener(engine.Event.COMPLETE, () => {\n const uvs = new Float32Array([\n col / MAX_COL,\n row / MAX_ROW,\n (col + 1) / MAX_COL,\n row / MAX_ROW,\n (col + 1) / MAX_COL,\n (row + 1) / MAX_ROW,\n col / MAX_COL,\n (row + 1) / MAX_ROW,\n ]);\n\n child.uvs = uvs;\n // spr.push(child);\n });\n }\n }\n picMap[url] = spr.concat([]);\n posMap[url] = pos.concat([]);;\n // console.log(spr);\n return [spr, pos];\n};\n","/**\n * Created by rockyl on 2020-01-21.\n */\n\nexport function getTexture(uuid) {\n\treturn engine.Texture.from(getAssetByUUID(uuid).uuid);\n}\n\nexport function getTextureByName(name) {\n\treturn getTexture(engine.getAssetByName(name).uuid);\n}\n\nexport function playSound(name) {\n\tengine.playSound(engine.getAssetByName(name).uuid, {keep: true});\n}\nexport function createSvga(name, anchorName?) {\n\tlet inst = new svga.Svga();\n\tinst.source = 'asset://' + engine.getAssetByName(name).uuid;\n\treturn inst;\n}\n\nexport function getIndexFromRC(row,col,maxCol){\n\tlet index;\n\tindex = row * maxCol + col ;\n\treturn index\n}\n\n\n\n\nexport function getRandomArray(array){\n\tarray.sort(function() {\n\t\treturn .5 - Math.random();\n\t});\n}","/**\n * Created by rockyl on 2018/8/16.\n */\n\nimport { props } from \"../props\";\nimport qietu from \"./qietu\";\nimport { getIndexFromRC, getRandomArray, getTexture } from \"./utils\";\nimport ObjectPool = engine.ObjectPool;\n\n// let OFFSET_X;\n// let OFFSET_Y;\nlet MAX_COL;\nlet MAX_ROW;\nlet W;\nlet H;\nlet GAP;\nlet GAME_TIME;\n// 每张图片宽\nlet w;\n// 每张图片高\nlet h;\n\nexport default class GameView extends engine.Container {\n private _timer;\n private _timeCounter = 0;\n\n private date\n\n start() {\n //优先获取start事件接收到的参数\n MAX_COL = props.column || props.MAX_COL;\n MAX_ROW = props.row || props.MAX_ROW;\n GAME_TIME = props.gameTime || props.GAME_TIME;\n console.log('start',props.column,props.row,props.gameTime)\n\n if (!this.guideHole) {\n this.guideHole = new engine.Image();\n this.guideHole.source = 'asset://' + props.blockUrl;\n this.guideHole.mouseChildren = this.guideHole.mouseEnabled = false;\n }\n\n if (this.pictures) {\n for (const pic of this.pictures) {\n if (pic && pic.wrapper)\n pic.wrapper.removeChild(pic);\n }\n }\n\n console.log('on start')\n engine.globalEvent.dispatchEvent('pictures-time-update', {\n second: this.getSecond(),\n });\n\n // 图片一维数组\n const result = qietu(this.picturesWrapper, props.picUrl, MAX_COL, MAX_ROW);\n this.picturesWrapper.addChild(this.guideHole);\n\n console.log(this.picturesWrapper)\n\n this.pictures = result[0];\n this.rightList = this.pictures.concat([]);\n const posList = result[1];\n getRandomArray(this.pictures);\n\n let i = 0;\n let len;\n len = this.pictures.length;\n\n\n for (; i < len; i++) {\n this.dragPic = this.pictures[i];\n this.pictures[i].addEventListener(\n engine.MouseEvent.MOUSE_DOWN,\n this.onDown,\n this\n );\n const [x, y] = posList[i];\n this.dragPic.x = x;\n this.dragPic.y = y;\n\n }\n\n this._timer = setInterval(() => {\n this.onTimer();\n }, 10)\n\n this.date = new Date().getTime();\n\n }\n\n onTimer() {\n\n let date = new Date().getTime();\n\n let gap = ((date - this.date) / 1000);\n this.date = date;\n console.log(gap,\"gap\");\n\n // 以GAME_TIME为标准\n GAME_TIME -= gap;\n if(GAME_TIME < 0){\n GAME_TIME = 0;\n }\n GAME_TIME = this.afterPointTwo(GAME_TIME);\n GAME_TIME = GAME_TIME.toFixed(2)\n if (GAME_TIME < 10) {\n GAME_TIME = '0' + GAME_TIME\n }\n console.log(GAME_TIME);\n\n\n engine.globalEvent.dispatchEvent('pictures-time-update', {\n second: this.getSecond(),\n });\n\n if (this.getSecond() == 0) {\n this.stop();\n engine.globalEvent.dispatchEvent('pictures-game-fail', {\n reason: 1\n });\n }\n }\n\n afterPointTwo(n) {\n\n var floatN = parseFloat(n);\n if (isNaN(floatN)) {\n return;\n }\n floatN = Math.round(floatN * 100) / 100;\n return floatN;\n\n }\n\n getSecond() {\n return GAME_TIME\n }\n\n stop() {\n \n GAME_TIME = props.GAME_TIME\n clearInterval(this._timer);\n let len = this.pictures.length;\n for(let i=0;i<len;i++){\n this.pictures[i].removeAllEventListener();\n }\n\n this.stage.removeEventListener(\n engine.MouseEvent.MOUSE_UP,\n this.stageOnUp,\n this\n );\n \n }\n\n constructor() {\n super();\n this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);\n }\n\n //当前图片对象\n dragPic;\n // 鼠标在当前图片上的位置\n localPicX;\n localPicY;\n // 拖动的图片最开始的位置(左上角为准)\n distanceX;\n distanceY;\n // 图片中心的位置\n centerX: number;\n centerY: number;\n\n pictures: engine.Sprite[];\n\n // 点击图片时的一维数组索引\n index;\n // 计算目标图片行和列的位置\n indexI: number;\n indexJ: number;\n rightList: engine.Sprite[];\n\n private picturesWrapper: engine.Sprite;\n private guideHole: engine.Image;\n\n createRects() { }\n setup() {\n\n MAX_COL = props.MAX_COL;\n MAX_ROW = props.MAX_ROW;\n GAME_TIME = props.GAME_TIME;\n // OFFSET_X = props.OFFSET_X;\n // OFFSET_Y = props.OFFSET_Y;\n W = props.W;\n H = props.H;\n GAP = props.GAP;\n // 每张图片宽\n w = W / MAX_COL;\n // 每张图片高\n h = H / MAX_ROW;\n\n console.log('onSteup', props);\n\n const parent = new engine.Sprite();\n this.picturesWrapper = parent;\n this.addChild(parent);\n\n // this.picturesWrapper.x = OFFSET_X;\n // this.picturesWrapper.y = OFFSET_Y;\n\n // 添加按钮\n // const btn = new engine.Rect();\n // btn.width = 200;\n // btn.height = 100;\n // btn.stage.top = 1000;\n // btn.stage.left = 350;\n // btn.fillColor = 'cyan';\n // this.addChild(btn)\n\n // btn.addEventListener(engine.MouseEvent.CLICK,this.onClk,this)\n\n }\n\n onDown(e: engine.MouseEvent) {\n // console.log(e);\n\n let stageLeft = (750 - props.W) / 2\n let stageTop = (this.stage.height - props.H) / 2;\n\n // 创建一个图片对象接收当前位置信息\n this.dragPic = e.target;\n this.picturesWrapper.addChild(this.dragPic);\n\n\n // 鼠标的偏移量\n this.localPicX = e.localX / MAX_COL;\n this.localPicY = e.localY / MAX_ROW;\n\n // 最开始图片的位置\n this.distanceX = this.dragPic.x ;\n this.distanceY = this.dragPic.y;\n\n // 最开始点击的图片的索引值\n\n this.indexJ = Math.floor((this.distanceX) / (w + GAP));\n this.indexI = Math.floor((this.distanceY) / (h + GAP));\n this.index = (this.indexI) * MAX_COL + this.indexJ;\n\n\n // this.centerX = Math.floor(e.clientX / w) * w + w / 2;\n // this.centerY = Math.floor(e.clientY / h) * h + h / 2;\n\n this.centerX = Math.floor((e.clientX - stageLeft) / w) * w + w / 2;\n this.centerY = Math.floor((e.clientY - stageTop) / h) * h + h / 2;\n\n this.stage.addEventListener(\n engine.MouseEvent.MOUSE_MOVE,\n this.onMove,\n this\n );\n this.stage.addEventListener(\n engine.MouseEvent.MOUSE_UP,\n this.stageOnUp,\n this\n );\n\n }\n\n listenStageOn = 1;\n\n stageOnUp(e) {\n\n let stageLeft = (750 - props.W) / 2\n let stageTop = (this.stage.height - props.H) / 2;\n\n this.stage.removeEventListener(\n engine.MouseEvent.MOUSE_MOVE,\n this.onMove,\n this\n );\n\n this.stage.removeEventListener(\n engine.MouseEvent.MOUSE_UP,\n this.stageOnUp,\n this\n );\n\n // 拖动的图片的中心位置在图片之外,回到原来的位置\n if (this.centerY < stageTop || this.centerX < stageLeft) {\n this.dragPic.x = this.distanceX ;\n this.dragPic.y = this.distanceY ;\n }\n\n // 判断图片是否进入另一张图片的范围内\n // 要交换的图片第几行第几列\n let curJ = Math.floor(this.centerX / (w + GAP));\n let curI = Math.floor(this.centerY / (h + GAP));\n\n this.picturesWrapper.addChild(this.guideHole);\n\n\n // 点击图片的位置\n\n if ( 0 <= curJ && curJ < (MAX_COL) && 0 <= curI && curI < (MAX_ROW)) {\n\n // 获取交互图片的索引值\n let index = getIndexFromRC(curI, curJ, MAX_COL);\n // console.log(index);\n\n //要交换的图片\n let dropPic = this.pictures[index];\n\n let dropPicX = dropPic.x + stageLeft;\n let dropPicy = dropPic.y + stageTop;\n\n dropPic.x = this.distanceX;\n dropPic.y = this.distanceY;\n\n this.dragPic.x = dropPicX - stageLeft;\n this.dragPic.y = dropPicy - stageTop;\n\n // 交换之后索引也需要交换\n\n const dropPicIndex = this.pictures.indexOf(dropPic);\n const dragPicIndex = this.pictures.indexOf(this.dragPic);\n\n this.pictures[dropPicIndex] = this.dragPic;\n this.pictures[dragPicIndex] = dropPic;\n\n // 图片中心还是在原来的位置\n if (dragPicIndex === dropPicIndex) {\n this.dragPic.x = this.distanceX\n this.dragPic.y = this.distanceY\n }\n\n let result = true;\n for (let j = 0; j < this.rightList.length; j++) {\n if (this.rightList[j] != this.pictures[j]) {\n result = false;\n break;\n }\n }\n\n if (result) {\n this.onSuccess();\n\n }\n } else {\n this.dragPic.x = this.distanceX\n this.dragPic.y = this.distanceY\n }\n\n\n }\n\n private onSuccess() {\n console.log('拼图成功!');\n engine.globalEvent.dispatchEvent('pictures-game-success', { time: GAME_TIME });\n this.stop();\n\n }\n\n onMove(e: engine.MouseEvent) {\n // 当前图片的位置\n this.dragPic.x = e.stageX - this.localPicX - (750 - props.W) / 2;\n this.dragPic.y = e.stageY - this.localPicY - (this.stage.height - props.H) / 2;\n\n // 当前图片的中心位置\n this.centerX = this.dragPic.x + w / 2;\n this.centerY = this.dragPic.y + h / 2;\n }\n\n // onClk(e){\n // // 重置时间\n // this._timeCounter = 0;\n // //重置图片顺序\n\n\n // }\n\n\n}\n","/**\n * Created by rockyl on 2020-01-09.\n */\n\nimport GameView from \"./GameView\";\nimport { injectProps } from \"../props\";\n\n\nexport class GameWrapper extends engine.Container {\n\t// private _status;\n\tprivate _gameView: GameView;\n\n\n\n\n\n\tconstructor() {\n\t\tsuper();\n\n\t\tengine.globalEvent.addEventListener('pictures-start', this.start, this);\n\t\tengine.globalEvent.addEventListener('pictures-stop', this.stop, this);\n\n\t\t//创建实例\n\t\tlet gameView = this._gameView = new GameView();\n\t\tthis.addChild(gameView);\n\n\t}\n\n\tstart(event: engine.Event) {\n\t\tinjectProps(event.data);\n\n\t\t// this._status = 1;\n\n\t\tthis._gameView.start();\n\t}\n\tstop(event: engine.Event) {\n\t\t\n\t\tthis._gameView.stop();\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-20.\n */\n\nimport {GameWrapper} from \"./game/GameWrapper\";\nimport {injectProps, prepareProps} from \"./props\";\n\nexport default function (props) {\n\tprepareProps();\n\tinjectProps(props);\n\n\tlet instance = new GameWrapper();\n\t\n\treturn instance;\n}\n"],"names":["__extends"],"mappings":";;;;;;CAIO,IAAI,KAAK,GAAQ,EAAE,CAAC;UAEX,YAAY;KAC3B,IAAI,SAAS,GAAG,QAAQ,EAAE,CAAC;KAE3B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;CACrC,CAAC;UAEe,WAAW,CAAC,CAAC;KAC5B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC7B;;CCZA,IAAM,MAAM,GAAG,EAAE,CAAC;CAClB,IAAM,MAAM,GAAG,EAAE,CAAC;AAClB,cAAe,UAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,OAAO;KAC3C,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE;SACf,IAAM,IAAI,GAAS,MAAM,CAAC,GAAG,CAAC,CAAC;SAC/B,KAAkB,UAAI,EAAJ,aAAI,EAAJ,kBAAI,EAAJ,IAAI,EAAE;aAAnB,IAAM,GAAG,aAAA;aACZ,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;UACtB;SACD,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;MAClC;KAED,IAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;KAClB,IAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;KAClB,IAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;KAEtB,IAAM,GAAG,GAAG,EAAE,CAAC;KACf,IAAM,GAAG,GAAG,EAAE,CAAA;6BAEL,GAAG;iCACD,GAAG;aAEV,IAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;aAC3C,GAAG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AC,CA/BgC,MAAM,CAAC,SAAS,GA+BhD;;iBChCwB,KAAK;KAC7B,YAAY,EAAE,CAAC;KACf,WAAW,CAAC,KAAK,CAAC,CAAC;KAEnB,IAAI,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;KAEjC,OAAO,QAAQ,CAAC;CACjB,CAAC;;;;;;;;"}
\ No newline at end of file
{"version":3,"file":"index.js","sources":["src/custom/p2demo/src/game/GameView.ts","src/custom/p2demo/src/props.ts","src/custom/p2demo/src/game/GameWrapper.ts","src/custom/p2demo/src/index.ts"],"sourcesContent":["export default class GameView extends engine.Container {\n world: p2.World;\n factor: number = 10;\n isDebug = 1;\n constructor() {\n super();\n this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);\n }\n\n private createBall(r: number) {\n var shape = new engine.Shape();\n shape.beginFill(0xfff000);\n shape.drawCircle(0, 0, r);\n shape.endFill();\n return shape;\n }\n\n start() {\n console.log('start');\n this.stage.addEventListener(engine.MouseEvent.CLICK, this.onClick, this);\n }\n\n private createBox(width: number, height: number): engine.Shape {\n var shape = new engine.Shape();\n shape.beginFill(0xfff000);\n shape.drawRect(-width / 2, -height / 2, width, height);\n shape.endFill();\n return shape;\n }\n\n onClick(e: engine.MouseEvent) {\n // const box = this.createBox(750, 100)\n // this.addChild(box);\n // box.x = 750/2;\n // box.y = 1624/2;\n // engine.Tween.get(box, { loop: true }).to({ rotation: 360 }, 1000)\n // return;\n\n // const ball = this.createBall(750/2);\n // this.addChild(ball);\n // ball.x = e.stageX;\n // ball.y = e.stageY;\n // return;\n const { world, factor } = this;\n var positionX: number = (e.stageX / factor);\n var positionY: number = ((engine.gameStage.stage.height - e.stageY) / factor);\n var display: engine.DisplayObject;\n\n if (Math.random() > .5) {\n //添加方形刚体\n var boxShape: p2.Shape = new p2.Box({ width: 200/factor, height: 100/factor });\n var boxBody: p2.Body = new p2.Body({ mass: 1, position: [positionX, positionY], angularVelocity: 1 });\n boxBody.addShape(boxShape);\n world.addBody(boxBody);\n\n if (this.isDebug) {\n display = this.createBox((<p2.Box>boxShape).width * factor, (<p2.Box>boxShape).height * factor);\n } else {\n // display = self.createBitmapByName(\"rect\");\n // display.width = (<p2.Box>boxShape).width * factor;\n // display.height = (<p2.Box>boxShape).height * factor;\n }\n }\n else {\n //添加圆形刚体\n var boxShape: p2.Shape = new p2.Circle({ radius: 200 / 2 / factor });\n var boxBody: p2.Body = new p2.Body({ mass: 1, position: [positionX, positionY] });\n boxBody.addShape(boxShape);\n world.addBody(boxBody);\n\n if (this.isDebug) {\n display = this.createBall((<p2.Circle>boxShape).radius * factor);\n } else {\n // display = self.createBitmapByName(\"circle\");\n }\n\n // display.width = (<p2.Circle>boxShape).radius * 2 * factor;\n // display.height = (<p2.Circle>boxShape).radius * 2 * factor;\n\n }\n\n // display.anchorX = display.width / 2;\n // display.anchorY = display.height / 2;\n\n boxBody.displays = [display];\n\n this.addChild(display);\n\n }\n\n setup() {\n console.log('setup');\n\n //创建world\n var world: p2.World = new p2.World({\n // gravity: [0, 0],\n });\n\n world.sleepMode = p2.World.BODY_SLEEPING;\n\n //创建plane\n var planeShape: p2.Plane = new p2.Plane();\n var planeBody: p2.Body = new p2.Body();\n planeBody.addShape(planeShape);\n planeBody.displays = [];\n world.addBody(planeBody);\n this.world = world;\n\n this.stage.addEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this)\n }\n\n onEnterFrame() {\n const { world, factor } = this;\n world.step(60 / 1000);\n const stageHeight = engine.gameStage.stage.height;\n var l = world.bodies.length;\n\n for (var i: number = 0; i < l; i++) {\n var boxBody: p2.Body = world.bodies[i];\n var box = boxBody.displays[0];\n if (box) {\n box.x = boxBody.position[0] * factor;\n box.y = stageHeight - boxBody.position[1] * factor;\n\n box.rotation = 360 - (boxBody.angle + boxBody.shapes[0].angle) * 180 / Math.PI;\n if (boxBody.sleepState == p2.Body.SLEEPING) {\n box.alpha = 0.5;\n }\n else {\n box.alpha = 1;\n }\n }\n }\n\n }\n\n}\n","/**\n * Created by rockyl on 2020-01-21.\n */\n\nexport let props: any = {};\n\nexport function prepareProps() {\n\tlet metaProps = getProps();\n\n\tengine.injectProp(props, metaProps);\n}\n\nexport function injectProps(p) {\n\tengine.injectProp(props, p);\n}\n","/**\n * Created by rockyl on 2020-01-09.\n */\n\nimport GameView from \"./GameView\";\nimport { injectProps } from \"../props\";\n\n\nexport class GameWrapper extends engine.Container {\n\t// private _status;\n\tprivate _gameView: GameView;\n\n\n\n\n\n\tconstructor() {\n\t\tsuper();\n\n\t\tengine.globalEvent.addEventListener('pictures-start', this.start, this);\n\t\tengine.globalEvent.addEventListener('pictures-stop', this.stop, this);\n\n\t\t//创建实例\n\t\tlet gameView = this._gameView = new GameView();\n\t\tthis.addChild(gameView);\n\n\t}\n\n\tstart(event: engine.Event) {\n\t\tinjectProps(event.data);\n\n\t\t// this._status = 1;\n\n\t\tthis._gameView.start();\n\t}\n\tstop(event: engine.Event) {\n\t\t\n\t}\n}\n","/**\n * Created by rockyl on 2019-11-20.\n */\n\nimport {GameWrapper} from \"./game/GameWrapper\";\nimport {injectProps, prepareProps} from \"./props\";\n\nexport default function (props) {\n\tprepareProps();\n\tinjectProps(props);\n\n\tlet instance = new GameWrapper();\n\t\n\treturn instance;\n}\n"],"names":["__extends"],"mappings":";;;;;;EAAA;MAAsCA,kCAAgB;MAIpD;UAAA,YACE,iBAAO,SAER;UALD,YAAM,GAAW,EAAE,CAAC;UACpB,aAAO,GAAG,CAAC,CAAC;UAGV,KAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,KAAI,CAAC,KAAK,EAAE,KAAI,CAAC,CAAC;;OAC1D;MAEO,6BAAU,GAAlB,UAAmB,CAAS;UAC1B,IAAI,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;UAC/B,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;UAC1B,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,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CAAC,CAAC;MAEnB,IAAI,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;MAEjC,OAAO,QAAQ,CAAC;EACjB,CAAC;;;;;;;;;"}
\ No newline at end of file
src/custom/p2demo/src/game/GameView.ts
View file @
2533efe0
/**
* Created by rockyl on 2018/8/16.
*/
import
{
props
}
from
"../props"
;
import
qietu
from
"./qietu"
;
import
{
getIndexFromRC
,
getRandomArray
,
getTexture
}
from
"./utils"
;
import
ObjectPool
=
engine
.
ObjectPool
;
// let OFFSET_X;
// let OFFSET_Y;
let
MAX_COL
;
let
MAX_ROW
;
let
W
;
let
H
;
let
GAP
;
let
GAME_TIME
;
// 每张图片宽
let
w
;
// 每张图片高
let
h
;
export
default
class
GameView
extends
engine
.
Container
{
private
_timer
;
private
_timeCounter
=
0
;
private
date
start
()
{
//优先获取start事件接收到的参数
MAX_COL
=
props
.
column
||
props
.
MAX_COL
;
MAX_ROW
=
props
.
row
||
props
.
MAX_ROW
;
GAME_TIME
=
props
.
gameTime
||
props
.
GAME_TIME
;
console
.
log
(
'start'
,
props
.
column
,
props
.
row
,
props
.
gameTime
)
if
(
!
this
.
guideHole
)
{
this
.
guideHole
=
new
engine
.
Image
();
this
.
guideHole
.
source
=
'asset://'
+
props
.
blockUrl
;
this
.
guideHole
.
mouseChildren
=
this
.
guideHole
.
mouseEnabled
=
false
;
}
if
(
this
.
pictures
)
{
for
(
const
pic
of
this
.
pictures
)
{
if
(
pic
&&
pic
.
wrapper
)
pic
.
wrapper
.
removeChild
(
pic
);
}
}
console
.
log
(
'on start'
)
engine
.
globalEvent
.
dispatchEvent
(
'pictures-time-update'
,
{
second
:
this
.
getSecond
(),
});
// 图片一维数组
const
result
=
qietu
(
this
.
picturesWrapper
,
props
.
picUrl
,
MAX_COL
,
MAX_ROW
);
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
console
.
log
(
this
.
picturesWrapper
)
this
.
pictures
=
result
[
0
];
this
.
rightList
=
this
.
pictures
.
concat
([]);
const
posList
=
result
[
1
];
getRandomArray
(
this
.
pictures
);
let
i
=
0
;
let
len
;
len
=
this
.
pictures
.
length
;
for
(;
i
<
len
;
i
++
)
{
this
.
dragPic
=
this
.
pictures
[
i
];
this
.
pictures
[
i
].
addEventListener
(
engine
.
MouseEvent
.
MOUSE_DOWN
,
this
.
onDown
,
this
);
const
[
x
,
y
]
=
posList
[
i
];
this
.
dragPic
.
x
=
x
;
this
.
dragPic
.
y
=
y
;
}
this
.
_timer
=
setInterval
(()
=>
{
this
.
onTimer
();
},
10
)
this
.
date
=
new
Date
().
getTime
();
world
:
p2
.
World
;
factor
:
number
=
10
;
isDebug
=
1
;
constructor
()
{
super
();
this
.
once
(
engine
.
Event
.
ADDED_TO_STAGE
,
this
.
setup
,
this
);
}
onTimer
()
{
let
date
=
new
Date
().
getTime
();
let
gap
=
((
date
-
this
.
date
)
/
1000
);
this
.
date
=
date
;
console
.
log
(
gap
,
"gap"
);
// 以GAME_TIME为标准
GAME_TIME
-=
gap
;
if
(
GAME_TIME
<
0
){
GAME_TIME
=
0
;
private
createBall
(
r
:
number
)
{
var
shape
=
new
engine
.
Shape
();
shape
.
beginFill
(
0xfff000
);
shape
.
drawCircle
(
0
,
0
,
r
);
shape
.
endFill
();
return
shape
;
}
GAME_TIME
=
this
.
afterPointTwo
(
GAME_TIME
);
GAME_TIME
=
GAME_TIME
.
toFixed
(
2
)
if
(
GAME_TIME
<
10
)
{
GAME_TIME
=
'0'
+
GAME_TIME
}
console
.
log
(
GAME_TIME
);
engine
.
globalEvent
.
dispatchEvent
(
'pictures-time-update'
,
{
second
:
this
.
getSecond
(),
});
if
(
this
.
getSecond
()
==
0
)
{
this
.
stop
();
engine
.
globalEvent
.
dispatchEvent
(
'pictures-game-fail'
,
{
reason
:
1
});
start
()
{
console
.
log
(
'start'
);
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
CLICK
,
this
.
onClick
,
this
);
}
private
createBox
(
width
:
number
,
height
:
number
):
engine
.
Shape
{
var
shape
=
new
engine
.
Shape
();
shape
.
beginFill
(
0xfff000
);
shape
.
drawRect
(
-
width
/
2
,
-
height
/
2
,
width
,
height
);
shape
.
endFill
();
return
shape
;
}
onClick
(
e
:
engine
.
MouseEvent
)
{
// const box = this.createBox(750, 100)
// this.addChild(box);
// box.x = 750/2;
// box.y = 1624/2;
// engine.Tween.get(box, { loop: true }).to({ rotation: 360 }, 1000)
// return;
// const ball = this.createBall(750/2);
// this.addChild(ball);
// ball.x = e.stageX;
// ball.y = e.stageY;
// return;
const
{
world
,
factor
}
=
this
;
var
positionX
:
number
=
(
e
.
stageX
/
factor
);
var
positionY
:
number
=
((
engine
.
gameStage
.
stage
.
height
-
e
.
stageY
)
/
factor
);
var
display
:
engine
.
DisplayObject
;
if
(
Math
.
random
()
>
.
5
)
{
//添加方形刚体
var
boxShape
:
p2
.
Shape
=
new
p2
.
Box
({
width
:
200
/
factor
,
height
:
100
/
factor
});
var
boxBody
:
p2
.
Body
=
new
p2
.
Body
({
mass
:
1
,
position
:
[
positionX
,
positionY
],
angularVelocity
:
1
});
boxBody
.
addShape
(
boxShape
);
world
.
addBody
(
boxBody
);
if
(
this
.
isDebug
)
{
display
=
this
.
createBox
((
<
p2
.
Box
>
boxShape
).
width
*
factor
,
(
<
p2
.
Box
>
boxShape
).
height
*
factor
);
}
else
{
// display = self.createBitmapByName("rect");
// display.width = (<p2.Box>boxShape).width * factor;
// display.height = (<p2.Box>boxShape).height * factor;
}
}
else
{
//添加圆形刚体
var
boxShape
:
p2
.
Shape
=
new
p2
.
Circle
({
radius
:
200
/
2
/
factor
});
var
boxBody
:
p2
.
Body
=
new
p2
.
Body
({
mass
:
1
,
position
:
[
positionX
,
positionY
]
});
boxBody
.
addShape
(
boxShape
);
world
.
addBody
(
boxBody
);
afterPointTwo
(
n
)
{
var
floatN
=
parseFloat
(
n
);
if
(
isNaN
(
floatN
))
{
return
;
if
(
this
.
isDebug
)
{
display
=
this
.
createBall
((
<
p2
.
Circle
>
boxShape
).
radius
*
factor
);
}
else
{
// display = self.createBitmapByName("circle");
}
floatN
=
Math
.
round
(
floatN
*
100
)
/
100
;
return
floatN
;
}
// display.width = (<p2.Circle>boxShape).radius * 2 * factor;
// display.height = (<p2.Circle>boxShape).radius * 2 * factor;
getSecond
()
{
return
GAME_TIME
}
stop
()
{
GAME_TIME
=
props
.
GAME_TIME
clearInterval
(
this
.
_timer
);
let
len
=
this
.
pictures
.
length
;
for
(
let
i
=
0
;
i
<
len
;
i
++
){
this
.
pictures
[
i
].
removeAllEventListener
();
}
// display.anchorX = display.width / 2;
// display.anchorY = display.height / 2;
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
boxBody
.
displays
=
[
display
];
}
this
.
addChild
(
display
);
constructor
()
{
super
();
this
.
once
(
engine
.
Event
.
ADDED_TO_STAGE
,
this
.
setup
,
this
);
}
//当前图片对象
dragPic
;
// 鼠标在当前图片上的位置
localPicX
;
localPicY
;
// 拖动的图片最开始的位置(左上角为准)
distanceX
;
distanceY
;
// 图片中心的位置
centerX
:
number
;
centerY
:
number
;
pictures
:
engine
.
Sprite
[];
// 点击图片时的一维数组索引
index
;
// 计算目标图片行和列的位置
indexI
:
number
;
indexJ
:
number
;
rightList
:
engine
.
Sprite
[];
private
picturesWrapper
:
engine
.
Sprite
;
private
guideHole
:
engine
.
Image
;
createRects
()
{
}
setup
()
{
console
.
log
(
'setup'
);
MAX_COL
=
props
.
MAX_COL
;
MAX_ROW
=
props
.
MAX_ROW
;
GAME_TIME
=
props
.
GAME_TIME
;
// OFFSET_X = props.OFFSET_X;
// OFFSET_Y = props.OFFSET_Y;
W
=
props
.
W
;
H
=
props
.
H
;
GAP
=
props
.
GAP
;
// 每张图片宽
w
=
W
/
MAX_COL
;
// 每张图片高
h
=
H
/
MAX_ROW
;
console
.
log
(
'onSteup'
,
props
);
const
parent
=
new
engine
.
Sprite
();
this
.
picturesWrapper
=
parent
;
this
.
addChild
(
parent
);
// this.picturesWrapper.x = OFFSET_X;
// this.picturesWrapper.y = OFFSET_Y;
// 添加按钮
// const btn = new engine.Rect();
// btn.width = 200;
// btn.height = 100;
// btn.stage.top = 1000;
// btn.stage.left = 350;
// btn.fillColor = 'cyan';
// this.addChild(btn)
// btn.addEventListener(engine.MouseEvent.CLICK,this.onClk,this)
}
onDown
(
e
:
engine
.
MouseEvent
)
{
// console.log(e);
let
stageLeft
=
(
750
-
props
.
W
)
/
2
let
stageTop
=
(
this
.
stage
.
height
-
props
.
H
)
/
2
;
// 创建一个图片对象接收当前位置信息
this
.
dragPic
=
e
.
target
;
this
.
picturesWrapper
.
addChild
(
this
.
dragPic
);
// 鼠标的偏移量
this
.
localPicX
=
e
.
localX
/
MAX_COL
;
this
.
localPicY
=
e
.
localY
/
MAX_ROW
;
// 最开始图片的位置
this
.
distanceX
=
this
.
dragPic
.
x
;
this
.
distanceY
=
this
.
dragPic
.
y
;
// 最开始点击的图片的索引值
this
.
indexJ
=
Math
.
floor
((
this
.
distanceX
)
/
(
w
+
GAP
));
this
.
indexI
=
Math
.
floor
((
this
.
distanceY
)
/
(
h
+
GAP
));
this
.
index
=
(
this
.
indexI
)
*
MAX_COL
+
this
.
indexJ
;
// this.centerX = Math.floor(e.clientX / w) * w + w / 2;
// this.centerY = Math.floor(e.clientY / h) * h + h / 2;
this
.
centerX
=
Math
.
floor
((
e
.
clientX
-
stageLeft
)
/
w
)
*
w
+
w
/
2
;
this
.
centerY
=
Math
.
floor
((
e
.
clientY
-
stageTop
)
/
h
)
*
h
+
h
/
2
;
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
addEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
}
listenStageOn
=
1
;
stageOnUp
(
e
)
{
let
stageLeft
=
(
750
-
props
.
W
)
/
2
let
stageTop
=
(
this
.
stage
.
height
-
props
.
H
)
/
2
;
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMove
,
this
);
this
.
stage
.
removeEventListener
(
engine
.
MouseEvent
.
MOUSE_UP
,
this
.
stageOnUp
,
this
);
// 拖动的图片的中心位置在图片之外,回到原来的位置
if
(
this
.
centerY
<
stageTop
||
this
.
centerX
<
stageLeft
)
{
this
.
dragPic
.
x
=
this
.
distanceX
;
this
.
dragPic
.
y
=
this
.
distanceY
;
}
// 判断图片是否进入另一张图片的范围内
// 要交换的图片第几行第几列
let
curJ
=
Math
.
floor
(
this
.
centerX
/
(
w
+
GAP
));
let
curI
=
Math
.
floor
(
this
.
centerY
/
(
h
+
GAP
));
this
.
picturesWrapper
.
addChild
(
this
.
guideHole
);
// 点击图片的位置
if
(
0
<=
curJ
&&
curJ
<
(
MAX_COL
)
&&
0
<=
curI
&&
curI
<
(
MAX_ROW
))
{
// 获取交互图片的索引值
let
index
=
getIndexFromRC
(
curI
,
curJ
,
MAX_COL
);
// console.log(index);
//要交换的图片
let
dropPic
=
this
.
pictures
[
index
];
let
dropPicX
=
dropPic
.
x
+
stageLeft
;
let
dropPicy
=
dropPic
.
y
+
stageTop
;
dropPic
.
x
=
this
.
distanceX
;
dropPic
.
y
=
this
.
distanceY
;
this
.
dragPic
.
x
=
dropPicX
-
stageLeft
;
this
.
dragPic
.
y
=
dropPicy
-
stageTop
;
// 交换之后索引也需要交换
//创建world
var
world
:
p2
.
World
=
new
p2
.
World
({
// gravity: [0, 0],
});
const
dropPicIndex
=
this
.
pictures
.
indexOf
(
dropPic
);
const
dragPicIndex
=
this
.
pictures
.
indexOf
(
this
.
dragPic
);
world
.
sleepMode
=
p2
.
World
.
BODY_SLEEPING
;
this
.
pictures
[
dropPicIndex
]
=
this
.
dragPic
;
this
.
pictures
[
dragPicIndex
]
=
dropPic
;
//创建plane
var
planeShape
:
p2
.
Plane
=
new
p2
.
Plane
();
var
planeBody
:
p2
.
Body
=
new
p2
.
Body
();
planeBody
.
addShape
(
planeShape
);
planeBody
.
displays
=
[];
world
.
addBody
(
planeBody
);
this
.
world
=
world
;
// 图片中心还是在原来的位置
if
(
dragPicIndex
===
dropPicIndex
)
{
this
.
dragPic
.
x
=
this
.
distanceX
this
.
dragPic
.
y
=
this
.
distanceY
this
.
stage
.
addEventListener
(
engine
.
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
,
this
)
}
let
result
=
true
;
for
(
let
j
=
0
;
j
<
this
.
rightList
.
length
;
j
++
)
{
if
(
this
.
rightList
[
j
]
!=
this
.
pictures
[
j
])
{
result
=
false
;
break
;
}
}
onEnterFrame
()
{
const
{
world
,
factor
}
=
this
;
world
.
step
(
60
/
1000
);
const
stageHeight
=
engine
.
gameStage
.
stage
.
height
;
var
l
=
world
.
bodies
.
length
;
if
(
result
)
{
this
.
onSuccess
();
for
(
var
i
:
number
=
0
;
i
<
l
;
i
++
)
{
var
boxBody
:
p2
.
Body
=
world
.
bodies
[
i
];
var
box
=
boxBody
.
displays
[
0
];
if
(
box
)
{
box
.
x
=
boxBody
.
position
[
0
]
*
factor
;
box
.
y
=
stageHeight
-
boxBody
.
position
[
1
]
*
factor
;
box
.
rotation
=
360
-
(
boxBody
.
angle
+
boxBody
.
shapes
[
0
].
angle
)
*
180
/
Math
.
PI
;
if
(
boxBody
.
sleepState
==
p2
.
Body
.
SLEEPING
)
{
box
.
alpha
=
0.5
;
}
}
else
{
this
.
dragPic
.
x
=
this
.
distanceX
this
.
dragPic
.
y
=
this
.
distanceY
else
{
box
.
alpha
=
1
;
}
}
private
onSuccess
()
{
console
.
log
(
'拼图成功!'
);
engine
.
globalEvent
.
dispatchEvent
(
'pictures-game-success'
,
{
time
:
GAME_TIME
});
this
.
stop
();
}
onMove
(
e
:
engine
.
MouseEvent
)
{
// 当前图片的位置
this
.
dragPic
.
x
=
e
.
stageX
-
this
.
localPicX
-
(
750
-
props
.
W
)
/
2
;
this
.
dragPic
.
y
=
e
.
stageY
-
this
.
localPicY
-
(
this
.
stage
.
height
-
props
.
H
)
/
2
;
// 当前图片的中心位置
this
.
centerX
=
this
.
dragPic
.
x
+
w
/
2
;
this
.
centerY
=
this
.
dragPic
.
y
+
h
/
2
;
}
// onClk(e){
// // 重置时间
// this._timeCounter = 0;
// //重置图片顺序
// }
}
src/custom/p2demo/src/game/GameWrapper.ts
View file @
2533efe0
...
...
@@ -35,6 +35,5 @@ export class GameWrapper extends engine.Container {
}
stop
(
event
:
engine
.
Event
)
{
this
.
_gameView
.
stop
();
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment