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
8d59419f
Commit
8d59419f
authored
Aug 17, 2020
by
汪欢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
123
parent
35f79513
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
301 additions
and
4 deletions
+301
-4
basket.json
dist/customs/basket.json
+105
-0
GameTest.ts
src/custom/basket/src/game/GameTest.ts
+186
-0
GameWrapper.ts
src/custom/basket/src/game/GameWrapper.ts
+10
-4
No files found.
dist/customs/basket.json
0 → 100644
View file @
8d59419f
{
"name"
:
"拼图"
,
"desc"
:
"拼图模块1.0"
,
"props"
:
{
"OFFSET_X"
:
{
"alias"
:
"OFFSET_X"
,
"type"
:
"number"
,
"default"
:
0
},
"OFFSET_Y"
:
{
"alias"
:
"OFFSET_Y"
,
"type"
:
"number"
,
"default"
:
0
},
"GAME_TIME"
:
{
"alias"
:
"游戏时间"
,
"type"
:
"number"
,
"default"
:
20
},
"moistPercent"
:
{
"alias"
:
"湿润度"
,
"type"
:
"number"
,
"default"
:
0
}
},
"assets"
:
[
{
"name"
:
"背景"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/b7708649be2270379bd764e25ee2e783a7d49f7a.jpg"
,
"uuid"
:
"a880ee6b-c6d1-4d8f-8734-367f368a1803"
,
"ext"
:
".jpg"
},
{
"name"
:
"篮板"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/13fd42607d6a79c9a8d0d053962d926fa45fa0c9.png"
,
"uuid"
:
"a1c6f4d9-8f9a-4267-b701-d2a7e9ff5b1b"
,
"ext"
:
".png"
},
{
"name"
:
"球网前"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/6c94fab92bc10e8716a4d90666b96d73603b8e59.png"
,
"uuid"
:
"882618a9-2cc9-498e-a764-268c6cfe6c99"
,
"ext"
:
".png"
},
{
"name"
:
"球网后"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/2a3596dd0291a20fcee55445752dc38634074c59.png"
,
"uuid"
:
"0680dba9-757b-443b-8d0f-0d5811254c7d"
,
"ext"
:
".png"
},
{
"name"
:
"篮球"
,
"url"
:
"//yun.duiba.com.cn/aurora/assets/3dc11f2d91659b7e7e1d06a9853cbc9f818e1ea2.png"
,
"uuid"
:
"270bbac6-b59e-4692-80c9-a95aa0b03c17"
,
"ext"
:
".png"
}
],
"events"
:
{
"in"
:
{
"game-reset"
:
{
"alias"
:
"重置"
},
"game-start"
:
{
"alias"
:
"开始"
,
"data"
:
{
"picUrl"
:
"图片路径"
,
"blockUrl"
:
"blockUrl"
,
"GAME_TIME"
:
"每局的游戏时间"
,
"MAX_ROW"
:
"行"
,
"MAX_COL"
:
"列"
,
"W"
:
"宽"
,
"H"
:
"高"
,
"GAP"
:
"图片间隙"
,
"OFFSET_X"
:
"OFFSET_X"
,
"OFFSET_Y"
:
"OFFSET_Y"
}
},
"game-stop"
:
{
"alias"
:
"停止"
}
},
"out"
:
{
"cloud-time-update"
:
{
"alias"
:
"倒计时更新"
,
"data"
:
{
"time"
:
"剩余时间"
}
},
"cloud-game-fail"
:
{
"alias"
:
"游戏结束"
,
"data"
:
{
"reason"
:
"结束原因(1:时间到了)"
}
},
"cloud-game-success"
:
{
"alias"
:
"游戏成功"
,
"data"
:
{
"time"
:
"游戏消耗时间"
}
}
}
},
"id"
:
"basket"
,
"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.basket = factory(global.tslib));
\n
}(this, (function (tslib) { 'use strict';
\n\n
var GameTest = (function (_super) {
\r\n
tslib.__extends(GameTest, _super);
\r\n
function GameTest() {
\r\n
var _this = _super.call(this) || this;
\r\n
_this.factor = 50;
\r\n
_this.addEventListener(engine.Event.ADDED_TO_STAGE, _this.start, _this);
\r\n
return _this;
\r\n
}
\r\n
GameTest.prototype.start = function () {
\r\n
this.createGameScene();
\r\n
this.addEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this);
\r\n
};
\r\n
GameTest.prototype.createGameScene = function () {
\r\n
var sh = engine.gameStage.stage.width / this.factor;
\r\n
var sw = engine.gameStage.stage.height / this.factor;
\r\n
var p2 = window[
\"
p2
\"
];
\r\n
this.world = new p2.World();
\r\n
this.world.sleepMode = p2.World.BODY_SLEEPING;
\r\n
this.world.defaultContactMaterial.friction = 0.3;
\r\n
this.world.defaultContactMaterial.restitution = 0.6;
\r\n
this.world.setGlobalStiffness(1e5);
\r\n
var materialBall = new p2.Material(1);
\r\n
var materialPoint = new p2.Material(2);
\r\n
var materialBoard = new p2.Material(3);
\r\n
var materialPlane = new p2.Material(4);
\r\n
var contactMaterialBallPoint = new p2.ContactMaterial(materialBall, materialPoint, {
\r\n
friction: 0.3,
\r\n
restitution: 0.5,
\r\n
});
\r\n
var contactMaterialBallBoard = new p2.ContactMaterial(materialBall, materialBoard, {
\r\n
friction: 0.3,
\r\n
restitution: 0.5,
\r\n
});
\r\n
var contactMaterialBallPlane = new p2.ContactMaterial(materialBall, materialPlane, {
\r\n
friction: 0.3,
\r\n
restitution: 0.7,
\r\n
});
\r\n
this.world.addContactMaterial(contactMaterialBallPoint);
\r\n
this.world.addContactMaterial(contactMaterialBallBoard);
\r\n
this.world.addContactMaterial(contactMaterialBallPlane);
\r\n
this.world.gravity = [0, 10];
\r\n
var box = new p2.Box({
\r\n
width: 100,
\r\n
height: 60,
\r\n
});
\r\n
this.boxBody = new p2.Body({
\r\n
mass: 1,
\r\n
position: [375, 1624 / 2],
\r\n
velocity: [0, 10],
\r\n
isDrawAABB: true,
\r\n
});
\r\n
this.boxBody.addShape(box);
\r\n
this.world.addBody(this.boxBody);
\r\n
var boxshape = this.createBox(0xf0f0f0, this.boxBody.position[0], this.boxBody.position[1], 100, 60);
\r\n
this.boxBody.displays = [boxshape];
\r\n
var plane = new p2.Plane();
\r\n
this.planeBody = new p2.Body({
\r\n
position: [0, 1100],
\r\n
isDrawAABB: true,
\r\n
material: materialPlane,
\r\n
});
\r\n
this.planeBody.angle = Math.PI;
\r\n
this.planeBody.addShape(plane);
\r\n
this.world.addBody(this.planeBody);
\r\n
this.plane = this.createPlane(0, 0, engine.gameStage.width, 20);
\r\n
this.planeBody.displays = [this.plane];
\r\n
};
\r\n
GameTest.prototype.onEnterFrame = function () {
\r\n
this.world.step(60 / 1000);
\r\n
var len = this.world.bodies.length;
\r\n
for (var i = 0; i < len; i++) {
\r\n
var body = this.world.bodies[i];
\r\n
var display = body.displays[0];
\r\n
display.x = body.position[0];
\r\n
display.y = body.position[1];
\r\n
}
\r\n
};
\r\n
GameTest.prototype.createPlane = function (x, y, w, h) {
\r\n
var sp = new engine.Shape();
\r\n
sp.beginFill(0x0000ff, 1);
\r\n
sp.drawRect(x, y, w, h);
\r\n
sp.endFill();
\r\n
this.addChild(sp);
\r\n
return sp;
\r\n
};
\r\n
GameTest.prototype.createBall = function (x, y) {
\r\n
var sp = new engine.Shape();
\r\n
sp.beginFill(0xff0000, 0.4);
\r\n
sp.drawCircle(x, y, 60);
\r\n
sp.endFill();
\r\n
this.addChild(sp);
\r\n
return sp;
\r\n
};
\r\n
GameTest.prototype.createBox = function (color, x, y, w, h) {
\r\n
var sp = new engine.Shape();
\r\n
sp.beginFill(color, 1);
\r\n
sp.drawRect(x, y, w, h);
\r\n
sp.endFill();
\r\n
this.addChild(sp);
\r\n
engine.Tween.get(sp, { loop: true }).to({ rotation: 360 }, 5000);
\r\n
return sp;
\r\n
};
\r\n
GameTest.prototype.bindAsset = function (body, assetName) {
\r\n
var offset = [];
\r\n
body.updateAABB();
\r\n
var bodyWidth = body.aabb.upperBound[0] - body.aabb.lowerBound[0];
\r\n
var bodyHeight = body.aabb.upperBound[1] - body.aabb.lowerBound[1];
\r\n
var asset = new engine.BitmapText();
\r\n
asset.scaleX = (bodyWidth * this.factor) / asset.width;
\r\n
asset.scaleY = (bodyHeight * this.factor) / asset.height;
\r\n
this.addChild(asset);
\r\n
p2.vec2.subtract(offset, body.position, body.aabb.lowerBound);
\r\n
asset.anchorOffsetX = (offset[0] / asset.scaleX) * this.factor;
\r\n
asset.anchorOffsetY = (offset[1] / asset.scaleY) * this.factor;
\r\n
body.displays = [asset];
\r\n
};
\r\n
GameTest.prototype.stop = function () { };
\r\n
return GameTest;
\r\n
}(engine.Container));
\n\n
var props = {};
\r\n
function prepareProps() {
\r\n
var metaProps = getProps();
\r\n
engine.injectProp(props, metaProps);
\r\n
}
\r\n
function injectProps(p) {
\r\n
engine.injectProp(props, p);
\r\n
}
\r\n
//# sourceMappingURL=props.js.map
\n\n
var GameWrapper = (function (_super) {
\r\n
tslib.__extends(GameWrapper, _super);
\r\n
function GameWrapper() {
\r\n
var _this = _super.call(this) || this;
\r\n
engine.globalEvent.addEventListener('game-start', _this.start, _this);
\r\n
engine.globalEvent.addEventListener('game-stop', _this.stop, _this);
\r\n
var gameTest = _this._gameTest = new GameTest();
\r\n
_this.addChild(gameTest);
\r\n
return _this;
\r\n
}
\r\n
GameWrapper.prototype.start = function (event) {
\r\n
injectProps(event.data);
\r\n
this._gameTest.start();
\r\n
};
\r\n
GameWrapper.prototype.stop = function (event) {
\r\n
this._gameTest.stop();
\r\n
};
\r\n
return GameWrapper;
\r\n
}(engine.Container));
\r\n
//# sourceMappingURL=GameWrapper.js.map
\n\n
function index (props) {
\r\n
prepareProps();
\r\n
injectProps(props);
\r\n
var instance = new GameWrapper();
\r\n
return instance;
\r\n
}
\r\n
//# sourceMappingURL=index.js.map
\n\n
return index;
\n\n
})));
\n
"
}
src/custom/basket/src/game/GameTest.ts
0 → 100644
View file @
8d59419f
import
{
getTextureByName
,
getTexture
}
from
"./utils"
;
export
default
class
GameTest
extends
engine
.
Container
{
private
world
:
p2
.
World
;
private
planeBody
:
p2
.
Body
;
private
plane
;
private
boxBody
:
p2
.
Body
;
factor
=
50
;
constructor
()
{
super
();
this
.
addEventListener
(
engine
.
Event
.
ADDED_TO_STAGE
,
this
.
start
,
this
);
}
start
()
{
this
.
createGameScene
();
this
.
addEventListener
(
engine
.
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
,
this
);
}
private
createGameScene
()
{
let
sh
=
engine
.
gameStage
.
stage
.
width
/
this
.
factor
;
let
sw
=
engine
.
gameStage
.
stage
.
height
/
this
.
factor
;
var
p2
=
window
[
"p2"
];
this
.
world
=
new
p2
.
World
();
this
.
world
.
sleepMode
=
p2
.
World
.
BODY_SLEEPING
;
this
.
world
.
defaultContactMaterial
.
friction
=
0.3
;
this
.
world
.
defaultContactMaterial
.
restitution
=
0.6
;
this
.
world
.
setGlobalStiffness
(
1
e5
);
//材质
var
materialBall
=
new
p2
.
Material
(
1
);
var
materialPoint
=
new
p2
.
Material
(
2
);
var
materialBoard
=
new
p2
.
Material
(
3
);
var
materialPlane
=
new
p2
.
Material
(
4
);
var
contactMaterialBallPoint
=
new
p2
.
ContactMaterial
(
materialBall
,
materialPoint
,
{
friction
:
0.3
,
restitution
:
0.5
,
// stiffness:0.1,
// relaxation:0
}
);
var
contactMaterialBallBoard
=
new
p2
.
ContactMaterial
(
materialBall
,
materialBoard
,
{
friction
:
0.3
,
restitution
:
0.5
,
// stiffness:0.1,
// relaxation:0
}
);
var
contactMaterialBallPlane
=
new
p2
.
ContactMaterial
(
materialBall
,
materialPlane
,
{
friction
:
0.3
,
restitution
:
0.7
,
// stiffness:0.1,
// relaxation:0
}
);
this
.
world
.
addContactMaterial
(
contactMaterialBallPoint
);
this
.
world
.
addContactMaterial
(
contactMaterialBallBoard
);
this
.
world
.
addContactMaterial
(
contactMaterialBallPlane
);
this
.
world
.
gravity
=
[
0
,
10
];
// 创建矩形
var
box
:
p2
.
Box
=
new
p2
.
Box
({
width
:
100
,
height
:
60
,
});
this
.
boxBody
=
new
p2
.
Body
({
mass
:
1
,
position
:
[
375
,
1624
/
2
],
velocity
:
[
0
,
10
],
isDrawAABB
:
true
,
// angularVelocity:1
});
this
.
boxBody
.
addShape
(
box
);
this
.
world
.
addBody
(
this
.
boxBody
);
// 添加形状
let
boxshape
=
this
.
createBox
(
0xf0f0f0
,
this
.
boxBody
.
position
[
0
],
this
.
boxBody
.
position
[
1
],
100
,
60
);
this
.
boxBody
.
displays
=
[
boxshape
];
// 创建地平面
var
plane
:
p2
.
Plane
=
new
p2
.
Plane
();
this
.
planeBody
=
new
p2
.
Body
({
position
:
[
0
,
1100
],
isDrawAABB
:
true
,
material
:
materialPlane
,
});
this
.
planeBody
.
angle
=
Math
.
PI
;
this
.
planeBody
.
addShape
(
plane
);
this
.
world
.
addBody
(
this
.
planeBody
);
this
.
plane
=
this
.
createPlane
(
0
,
0
,
engine
.
gameStage
.
width
,
20
);
this
.
planeBody
.
displays
=
[
this
.
plane
];
}
private
onEnterFrame
()
{
this
.
world
.
step
(
60
/
1000
);
var
len
:
number
=
this
.
world
.
bodies
.
length
;
for
(
var
i
:
number
=
0
;
i
<
len
;
i
++
)
{
var
body
:
p2
.
Body
=
this
.
world
.
bodies
[
i
];
var
display
:
engine
.
DisplayObject
=
body
.
displays
[
0
];
display
.
x
=
body
.
position
[
0
];
//同步刚体和egret显示对象的位置和旋转角度
display
.
y
=
body
.
position
[
1
];
// display.rotation = (body.angle * 180) / Math.PI;
}
// if (this.boxBody.position[0] < -120) {
// this.boxBody.position[0] = 750;
// }
// if (this.boxBody.position[0] > 750 + 120) {
// this.boxBody.position[0] = - 120;
// }
}
private
createPlane
(
x
,
y
,
w
,
h
)
{
var
sp
=
new
engine
.
Shape
();
sp
.
beginFill
(
0x0000ff
,
1
);
sp
.
drawRect
(
x
,
y
,
w
,
h
);
sp
.
endFill
();
// sp.anchorX = sp.width / 2;
// sp.anchorY = sp.height / 2;
this
.
addChild
(
sp
);
return
sp
;
}
private
createBall
(
x
,
y
)
{
var
sp
=
new
engine
.
Shape
();
sp
.
beginFill
(
0xff0000
,
0.4
);
sp
.
drawCircle
(
x
,
y
,
60
);
sp
.
endFill
();
this
.
addChild
(
sp
);
return
sp
;
}
private
createBox
(
color
,
x
,
y
,
w
,
h
)
{
var
sp
=
new
engine
.
Shape
();
sp
.
beginFill
(
color
,
1
);
sp
.
drawRect
(
x
,
y
,
w
,
h
);
sp
.
endFill
();
// sp.anchorX = w / 2;
// sp.anchorY = h / 2;
return
sp
;
}
private
bindAsset
(
body
:
p2
.
Body
,
assetName
:
string
):
void
{
var
offset
:
number
[]
=
[];
body
.
updateAABB
();
var
bodyWidth
:
number
=
body
.
aabb
.
upperBound
[
0
]
-
body
.
aabb
.
lowerBound
[
0
];
var
bodyHeight
:
number
=
body
.
aabb
.
upperBound
[
1
]
-
body
.
aabb
.
lowerBound
[
1
];
var
asset
:
engine
.
BitmapText
=
new
engine
.
BitmapText
();
// asset.texture = RES.getRes(assetName);
asset
.
scaleX
=
(
bodyWidth
*
this
.
factor
)
/
asset
.
width
;
asset
.
scaleY
=
(
bodyHeight
*
this
.
factor
)
/
asset
.
height
;
this
.
addChild
(
asset
);
p2
.
vec2
.
subtract
(
offset
,
body
.
position
,
body
.
aabb
.
lowerBound
);
asset
.
anchorOffsetX
=
(
offset
[
0
]
/
asset
.
scaleX
)
*
this
.
factor
;
asset
.
anchorOffsetY
=
(
offset
[
1
]
/
asset
.
scaleY
)
*
this
.
factor
;
body
.
displays
=
[
asset
];
}
stop
()
{}
}
src/custom/basket/src/game/GameWrapper.ts
View file @
8d59419f
import
GameView
from
"./GameView"
;
import
GameView
from
"./GameView"
;
import
GameTest
from
'./GameTest'
import
{
injectProps
}
from
"../props"
;
import
{
injectProps
}
from
"../props"
;
...
@@ -7,6 +8,7 @@ import { injectProps } from "../props";
...
@@ -7,6 +8,7 @@ import { injectProps } from "../props";
export
class
GameWrapper
extends
engine
.
Container
{
export
class
GameWrapper
extends
engine
.
Container
{
// private _status;
// private _status;
private
_gameView
:
GameView
;
private
_gameView
:
GameView
;
private
_gameTest
:
GameTest
;
constructor
()
{
constructor
()
{
super
();
super
();
...
@@ -15,8 +17,10 @@ export class GameWrapper extends engine.Container {
...
@@ -15,8 +17,10 @@ export class GameWrapper extends engine.Container {
engine
.
globalEvent
.
addEventListener
(
'game-stop'
,
this
.
stop
,
this
);
engine
.
globalEvent
.
addEventListener
(
'game-stop'
,
this
.
stop
,
this
);
//创建实例
//创建实例
let
gameView
=
this
.
_gameView
=
new
GameView
();
// let gameView = this._gameView = new GameView();
this
.
addChild
(
gameView
);
// this.addChild(gameView);
let
gameTest
=
this
.
_gameTest
=
new
GameTest
();
this
.
addChild
(
gameTest
);
}
}
...
@@ -25,11 +29,13 @@ export class GameWrapper extends engine.Container {
...
@@ -25,11 +29,13 @@ export class GameWrapper extends engine.Container {
// this._status = 1;
// this._status = 1;
this
.
_gameView
.
start
();
// this._gameView.start();
this
.
_gameTest
.
start
();
}
}
stop
(
event
:
engine
.
Event
)
{
stop
(
event
:
engine
.
Event
)
{
this
.
_gameView
.
stop
();
// this._gameView.stop();
this
.
_gameTest
.
stop
();
}
}
// reset(event:engine.Event){
// reset(event:engine.Event){
...
...
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