Commit e2806289 authored by wildfirecode13's avatar wildfirecode13

1

parent 2533efe0
...@@ -45,10 +45,16 @@ ...@@ -45,10 +45,16 @@
}, },
"assets": [ "assets": [
{ {
"name": "遮罩", "name": "block",
"url": "//yun.duiba.com.cn/aurora/assets/5b3e30496b2d9fdafb0cf3835fd6704ce10e45b4.png", "url": "//yun.duiba.com.cn/aurora/assets/f91184b338ef9540b167eebe7d58e71402e8d9d9.png",
"uuid": "888", "uuid": "888",
"ext": ".png" "ext": ".png"
},
{
"name": "ball",
"url": "//yun.duiba.com.cn/aurora/assets/3dc11f2d91659b7e7e1d06a9853cbc9f818e1ea2.png",
"uuid": "999",
"ext": ".png"
} }
], ],
"events": { "events": {
...@@ -89,5 +95,5 @@ ...@@ -89,5 +95,5 @@
} }
}, },
"id": "p2demo", "id": "p2demo",
"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" "code": "(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :\n\ttypeof 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\tfunction getTexture(uuid) {\n\t return engine.Texture.from(getAssetByUUID(uuid).uuid);\n\t}\n\tfunction getTextureByName(name) {\n\t return getTexture(engine.getAssetByName(name).uuid);\n\t}\n\tvar OptionState;\n\t(function (OptionState) {\n\t OptionState[OptionState[\"CHOICE_RIGHT\"] = 0] = \"CHOICE_RIGHT\";\n\t OptionState[OptionState[\"CHOICE_WRONG\"] = 1] = \"CHOICE_WRONG\";\n\t OptionState[OptionState[\"CHOICE_SELECT\"] = 2] = \"CHOICE_SELECT\";\n\t})(OptionState || (OptionState = {}));\n\tvar GameState;\n\t(function (GameState) {\n\t GameState[GameState[\"STATE_START\"] = 0] = \"STATE_START\";\n\t GameState[GameState[\"STATE_END\"] = 1] = \"STATE_END\";\n\t})(GameState || (GameState = {}));\n\t//# sourceMappingURL=utils.js.map\n\n\tvar GameView = (function (_super) {\n\t tslib.__extends(GameView, _super);\n\t function GameView() {\n\t var _this = _super.call(this) || this;\n\t _this.factor = 10;\n\t _this.isDebug = 0;\n\t _this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);\n\t return _this;\n\t }\n\t GameView.prototype.createBall = function (r) {\n\t var shape = new engine.Shape();\n\t shape.beginFill(0xfff000);\n\t shape.drawCircle(0, 0, r);\n\t shape.endFill();\n\t return shape;\n\t };\n\t GameView.prototype.start = function () {\n\t console.log('start');\n\t this.stage.addEventListener(engine.MouseEvent.CLICK, this.onClick, this);\n\t };\n\t GameView.prototype.createBitmapByName = function (name) {\n\t var imgContainer = new engine.Sprite();\n\t var img = new engine.Sprite(getTextureByName(name));\n\t img.anchorX = img.width / 2;\n\t img.anchorY = img.height / 2;\n\t img.x = -img.width / 2;\n\t img.y = -img.height / 2;\n\t imgContainer.addChild(img);\n\t return imgContainer;\n\t };\n\t GameView.prototype.createBox = function (width, height) {\n\t var shape = new engine.Shape();\n\t shape.beginFill(0xfff000);\n\t shape.drawRect(-width / 2, -height / 2, width, height);\n\t shape.endFill();\n\t return shape;\n\t };\n\t GameView.prototype.onClick = function (e) {\n\t var _a = this, world = _a.world, factor = _a.factor;\n\t var positionX = (e.stageX / factor);\n\t var positionY = ((engine.gameStage.stage.height - e.stageY) / factor);\n\t var display;\n\t if (Math.random() > .5) {\n\t var boxShape = new p2.Box({ width: 306 / factor, height: 172 / factor });\n\t var boxBody = new p2.Body({ mass: 1, position: [positionX, positionY], angularVelocity: 1 });\n\t boxBody.addShape(boxShape);\n\t world.addBody(boxBody);\n\t if (this.isDebug) {\n\t display = this.createBox(boxShape.width * factor, boxShape.height * factor);\n\t }\n\t else {\n\t display = this.createBitmapByName(\"block\");\n\t }\n\t }\n\t else {\n\t var boxShape = new p2.Circle({ radius: 120 / 2 / factor });\n\t var boxBody = new p2.Body({ mass: 1, position: [positionX, positionY] });\n\t boxBody.addShape(boxShape);\n\t world.addBody(boxBody);\n\t if (this.isDebug) {\n\t display = this.createBall(boxShape.radius * factor);\n\t }\n\t else {\n\t display = this.createBitmapByName(\"ball\");\n\t }\n\t }\n\t boxBody.displays = [display];\n\t this.addChild(display);\n\t };\n\t GameView.prototype.setup = function () {\n\t console.log('setup');\n\t var world = new p2.World({});\n\t world.sleepMode = p2.World.BODY_SLEEPING;\n\t var planeShape = new p2.Plane();\n\t var planeBody = new p2.Body();\n\t planeBody.addShape(planeShape);\n\t planeBody.displays = [];\n\t world.addBody(planeBody);\n\t this.world = world;\n\t this.stage.addEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this);\n\t };\n\t GameView.prototype.onEnterFrame = function () {\n\t var _a = this, world = _a.world, factor = _a.factor;\n\t world.step(60 / 1000);\n\t var stageHeight = engine.gameStage.stage.height;\n\t var l = world.bodies.length;\n\t for (var i = 0; i < l; i++) {\n\t var boxBody = world.bodies[i];\n\t var box = boxBody.displays[0];\n\t if (box) {\n\t box.x = boxBody.position[0] * factor;\n\t box.y = stageHeight - boxBody.position[1] * factor;\n\t box.rotation = 360 - (boxBody.angle + boxBody.shapes[0].angle) * 180 / Math.PI;\n\t if (boxBody.sleepState == p2.Body.SLEEPING) {\n\t box.alpha = 0.5;\n\t }\n\t else {\n\t box.alpha = 1;\n\t }\n\t }\n\t }\n\t };\n\t return GameView;\n\t}(engine.Container));\n\n\tvar props = {};\n\tfunction prepareProps() {\n\t var metaProps = getProps();\n\t engine.injectProp(props, metaProps);\n\t}\n\tfunction injectProps(p) {\n\t engine.injectProp(props, p);\n\t}\n\t//# sourceMappingURL=props.js.map\n\n\tvar 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 };\n\t return GameWrapper;\n\t}(engine.Container));\n\t//# sourceMappingURL=GameWrapper.js.map\n\n\tfunction index (props) {\n\t prepareProps();\n\t injectProps(props);\n\t var instance = new GameWrapper();\n\t return instance;\n\t}\n\t//# sourceMappingURL=index.js.map\n\n\treturn index;\n\n})));\n"
} }
...@@ -46,13 +46,7 @@ function launchWithCustomModule(customModule) { ...@@ -46,13 +46,7 @@ function launchWithCustomModule(customModule) {
}, 100); }, 100);
setTimeout(() => { setTimeout(() => {
engine.globalEvent.dispatchEvent('pictures-start', { engine.globalEvent.dispatchEvent('pictures-start', { });
picUrl: "http://yun.duiba.com.cn/aurora/assets/e1593b97c27077b85b92f7eaaeae1ed64a1eb79a.png",
blockUrl: "888",
column:"2",
row:"2",
gameTime:"50"
});
const d = engine.gameStage.sceneContainer.getChildAt(0); const d = engine.gameStage.sceneContainer.getChildAt(0);
......
(function (global, factory) { (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) : typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('tslib')) :
typeof define === 'function' && define.amd ? define(['tslib'], factory) : typeof define === 'function' && define.amd ? define(['tslib'], factory) :
(global = global || self, global.p2demo = factory(global.tslib)); (global = global || self, global.p2demo = factory(global.tslib));
}(this, (function (tslib) { 'use strict'; }(this, (function (tslib) { 'use strict';
var GameView = (function (_super) { function getTexture(uuid) {
tslib.__extends(GameView, _super); return engine.Texture.from(getAssetByUUID(uuid).uuid);
function GameView() { }
var _this = _super.call(this) || this; function getTextureByName(name) {
_this.factor = 10; return getTexture(engine.getAssetByName(name).uuid);
_this.isDebug = 1; }
_this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this); var OptionState;
return _this; (function (OptionState) {
} OptionState[OptionState["CHOICE_RIGHT"] = 0] = "CHOICE_RIGHT";
GameView.prototype.createBall = function (r) { OptionState[OptionState["CHOICE_WRONG"] = 1] = "CHOICE_WRONG";
var shape = new engine.Shape(); OptionState[OptionState["CHOICE_SELECT"] = 2] = "CHOICE_SELECT";
shape.beginFill(0xfff000); })(OptionState || (OptionState = {}));
shape.drawCircle(0, 0, r); var GameState;
shape.endFill(); (function (GameState) {
return shape; GameState[GameState["STATE_START"] = 0] = "STATE_START";
}; GameState[GameState["STATE_END"] = 1] = "STATE_END";
GameView.prototype.start = function () { })(GameState || (GameState = {}));
console.log('start'); //# sourceMappingURL=utils.js.map
this.stage.addEventListener(engine.MouseEvent.CLICK, this.onClick, this);
};
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);
}
}
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);
}
}
boxBody.displays = [display];
this.addChild(display);
};
GameView.prototype.setup = function () {
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.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;
}
else {
box.alpha = 1;
}
}
}
};
return GameView;
}(engine.Container));
var props = {}; var GameView = (function (_super) {
function prepareProps() { tslib.__extends(GameView, _super);
var metaProps = getProps(); function GameView() {
engine.injectProp(props, metaProps); var _this = _super.call(this) || this;
} _this.factor = 10;
function injectProps(p) { _this.isDebug = 0;
engine.injectProp(props, p); _this.once(engine.Event.ADDED_TO_STAGE, _this.setup, _this);
} return _this;
//# sourceMappingURL=props.js.map }
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 () {
console.log('start');
this.stage.addEventListener(engine.MouseEvent.CLICK, this.onClick, this);
};
GameView.prototype.createBitmapByName = function (name) {
var imgContainer = new engine.Sprite();
var img = new engine.Sprite(getTextureByName(name));
img.anchorX = img.width / 2;
img.anchorY = img.height / 2;
img.x = -img.width / 2;
img.y = -img.height / 2;
imgContainer.addChild(img);
return imgContainer;
};
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: 306 / factor, height: 172 / 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);
}
else {
display = this.createBitmapByName("block");
}
}
else {
var boxShape = new p2.Circle({ radius: 120 / 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);
}
else {
display = this.createBitmapByName("ball");
}
}
boxBody.displays = [display];
this.addChild(display);
};
GameView.prototype.setup = function () {
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.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;
}
else {
box.alpha = 1;
}
}
}
};
return GameView;
}(engine.Container));
var GameWrapper = (function (_super) { var props = {};
tslib.__extends(GameWrapper, _super); function prepareProps() {
function GameWrapper() { var metaProps = getProps();
var _this = _super.call(this) || this; engine.injectProp(props, metaProps);
engine.globalEvent.addEventListener('pictures-start', _this.start, _this); }
engine.globalEvent.addEventListener('pictures-stop', _this.stop, _this); function injectProps(p) {
var gameView = _this._gameView = new GameView(); engine.injectProp(props, p);
_this.addChild(gameView); }
return _this; //# sourceMappingURL=props.js.map
}
GameWrapper.prototype.start = function (event) {
injectProps(event.data);
this._gameView.start();
};
GameWrapper.prototype.stop = function (event) {
};
return GameWrapper;
}(engine.Container));
//# sourceMappingURL=GameWrapper.js.map
function index (props) { var GameWrapper = (function (_super) {
prepareProps(); tslib.__extends(GameWrapper, _super);
injectProps(props); function GameWrapper() {
var instance = new GameWrapper(); var _this = _super.call(this) || this;
return instance; engine.globalEvent.addEventListener('pictures-start', _this.start, _this);
} engine.globalEvent.addEventListener('pictures-stop', _this.stop, _this);
//# sourceMappingURL=index.js.map var gameView = _this._gameView = new GameView();
_this.addChild(gameView);
return _this;
}
GameWrapper.prototype.start = function (event) {
injectProps(event.data);
this._gameView.start();
};
GameWrapper.prototype.stop = function (event) {
};
return GameWrapper;
}(engine.Container));
//# sourceMappingURL=GameWrapper.js.map
return index; function index (props) {
prepareProps();
injectProps(props);
var instance = new GameWrapper();
return instance;
}
//# sourceMappingURL=index.js.map
return index;
}))); })));
......
{"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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C/BwB,KAAK;MAC7B,YAAY,EAAE,CAAC;MACf,WAAW,CAAC,KAAK,CAAC,CAAC;MAEnB,IAAI,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC;MAEjC,OAAO,QAAQ,CAAC;EACjB,CAAC;;;;;;;;;"} {"version":3,"file":"index.js","sources":["src/custom/answer-game/src/game/utils.ts","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":["\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 getStage(){\n\treturn engine.gameStage.stage;\n}\n\n\nexport enum OptionState{\n\tCHOICE_RIGHT,//选对\n\tCHOICE_WRONG,//选错\n\tCHOICE_SELECT,//选中\n}\n\nexport enum GameState{\n\tSTATE_START,//开始 选择中\n\tSTATE_END,//倒计时结束\n}","import { Tool } from \"../../../seabed-game/src/game/Tools\";\nimport { getTextureByName } from \"../../../answer-game/src/game/utils\";\n\nexport default class GameView extends engine.Container {\n world: p2.World;\n factor: number = 10;\n isDebug = 0;\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 createBitmapByName(name) {\n const imgContainer = new engine.Sprite();\n const img = new engine.Sprite(getTextureByName(name));\n img.anchorX = img.width / 2;\n img.anchorY = img.height / 2;\n img.x = -img.width / 2;\n img.y = -img.height / 2;\n imgContainer.addChild(img);\n return imgContainer\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\n // const ball = this.createBitmapByName('ball');\n // this.addChild(ball);\n // engine.Tween.get(ball, { loop: true }).to({ rotation: 360 }, 1000);\n // return;\n\n // const box = this.createBitmapByName('block');\n // this.addChild(box);\n // engine.Tween.get(box, { loop: true }).to({ rotation: 360 }, 1000);\n // return;\n\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: 306 / factor, height: 172 / 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 = this.createBitmapByName(\"block\");\n }\n }\n else {\n //添加圆形刚体\n var boxShape: p2.Shape = new p2.Circle({ radius: 120 / 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 = this.createBitmapByName(\"ball\");\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":";;;;;;UAKgB,UAAU,CAAC,IAAI;KAC9B,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;CACvD,CAAC;UAEe,gBAAgB,CAAC,IAAI;KACpC,OAAO,UAAU,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC;CACrD,CAAC;CAUD,IAAY,WAIX;CAJD,WAAY,WAAW;KACtB,6DAAY,CAAA;KACZ,6DAAY,CAAA;KACZ,+DAAa,CAAA;CACd,CAAC,EAJW,WAAW,KAAX,WAAW,QAItB;CAED,IAAY,SAGX;CAHD,WAAY,SAAS;KACpB,uDAAW,CAAA;KACX,mDAAS,CAAA;CACV,CAAC,EAHW,SAAS,KAAT,SAAS,QAGpB;;;CC3BD;KAAsCA,kCAAgB;KAIpD;SAAA,YACE,iBAAO,SAER;SALD,YAAM,GAAW,EAAE,CAAC;SACpB,aAAO,GAAG,CAAC,CAAC;SAGV,KAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,KAAI,CAAC,KAAK,EAAE,KAAI,CAAC,CAAC;;MAC1D;KAEO,6BAAU,GAAlB,UAAmB,CAAS;SAC1B,IAAI,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;SAC/B,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;SAC1B,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE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,CAAC,CAAC,CAAC;CAC7B,CAAC;;;CCND;KAAiCA,qCAAgB;KAQhD;SAAA,YACC,iBAAO,SASP;SAPA,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,KAAI,CAAC,KAAK,EAAE,KAAI,CAAC,CAAC;SACxE,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,eAAe,EAAE,KAAI,CAAC,IAAI,EAAE,KAAI,CAAC,CAAC;SAGtE,IAAI,QAAQ,GAAG,KAAI,CAAC,SAAS,GAAG,IAAI,QAAQ,EAAE,CAAC;SAC/C,KAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;;MAExB;KAED,2BAAK,GAAL,UAAM,KAAmB;SACxB,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SAIxB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;MACvB;KACD,0BAAI,GAAJ,UAAK,KAAmB;MAEvB;KACF,kBAAC;CAAD,CAAC,CA9BgC,MAAM,CAAC,SAAS,GA8BhD;;;iBC/BwB,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 \ No newline at end of file
...@@ -46,10 +46,16 @@ ...@@ -46,10 +46,16 @@
}, },
"assets": [ "assets": [
{ {
"name": "遮罩", "name": "block",
"url": "//yun.duiba.com.cn/aurora/assets/5b3e30496b2d9fdafb0cf3835fd6704ce10e45b4.png", "url": "//yun.duiba.com.cn/aurora/assets/f91184b338ef9540b167eebe7d58e71402e8d9d9.png",
"uuid": "888", "uuid": "888",
"ext": ".png" "ext": ".png"
},
{
"name": "ball",
"url": "//yun.duiba.com.cn/aurora/assets/3dc11f2d91659b7e7e1d06a9853cbc9f818e1ea2.png",
"uuid": "999",
"ext": ".png"
} }
], ],
"events": { "events": {
......
import { Tool } from "../../../seabed-game/src/game/Tools";
import { getTextureByName } from "../../../answer-game/src/game/utils";
export default class GameView extends engine.Container { export default class GameView extends engine.Container {
world: p2.World; world: p2.World;
factor: number = 10; factor: number = 10;
isDebug = 1; isDebug = 0;
constructor() { constructor() {
super(); super();
this.once(engine.Event.ADDED_TO_STAGE, this.setup, this); this.once(engine.Event.ADDED_TO_STAGE, this.setup, this);
...@@ -20,6 +23,17 @@ export default class GameView extends engine.Container { ...@@ -20,6 +23,17 @@ export default class GameView extends engine.Container {
this.stage.addEventListener(engine.MouseEvent.CLICK, this.onClick, this); this.stage.addEventListener(engine.MouseEvent.CLICK, this.onClick, this);
} }
createBitmapByName(name) {
const imgContainer = new engine.Sprite();
const img = new engine.Sprite(getTextureByName(name));
img.anchorX = img.width / 2;
img.anchorY = img.height / 2;
img.x = -img.width / 2;
img.y = -img.height / 2;
imgContainer.addChild(img);
return imgContainer
}
private createBox(width: number, height: number): engine.Shape { private createBox(width: number, height: number): engine.Shape {
var shape = new engine.Shape(); var shape = new engine.Shape();
shape.beginFill(0xfff000); shape.beginFill(0xfff000);
...@@ -29,6 +43,17 @@ export default class GameView extends engine.Container { ...@@ -29,6 +43,17 @@ export default class GameView extends engine.Container {
} }
onClick(e: engine.MouseEvent) { onClick(e: engine.MouseEvent) {
// const ball = this.createBitmapByName('ball');
// this.addChild(ball);
// engine.Tween.get(ball, { loop: true }).to({ rotation: 360 }, 1000);
// return;
// const box = this.createBitmapByName('block');
// this.addChild(box);
// engine.Tween.get(box, { loop: true }).to({ rotation: 360 }, 1000);
// return;
// const box = this.createBox(750, 100) // const box = this.createBox(750, 100)
// this.addChild(box); // this.addChild(box);
// box.x = 750/2; // box.x = 750/2;
...@@ -48,7 +73,7 @@ export default class GameView extends engine.Container { ...@@ -48,7 +73,7 @@ export default class GameView extends engine.Container {
if (Math.random() > .5) { if (Math.random() > .5) {
//添加方形刚体 //添加方形刚体
var boxShape: p2.Shape = new p2.Box({ width: 200/factor, height: 100/factor }); var boxShape: p2.Shape = new p2.Box({ width: 306 / factor, height: 172 / factor });
var boxBody: p2.Body = new p2.Body({ mass: 1, position: [positionX, positionY], angularVelocity: 1 }); var boxBody: p2.Body = new p2.Body({ mass: 1, position: [positionX, positionY], angularVelocity: 1 });
boxBody.addShape(boxShape); boxBody.addShape(boxShape);
world.addBody(boxBody); world.addBody(boxBody);
...@@ -56,14 +81,12 @@ export default class GameView extends engine.Container { ...@@ -56,14 +81,12 @@ export default class GameView extends engine.Container {
if (this.isDebug) { if (this.isDebug) {
display = this.createBox((<p2.Box>boxShape).width * factor, (<p2.Box>boxShape).height * factor); display = this.createBox((<p2.Box>boxShape).width * factor, (<p2.Box>boxShape).height * factor);
} else { } else {
// display = self.createBitmapByName("rect"); display = this.createBitmapByName("block");
// display.width = (<p2.Box>boxShape).width * factor;
// display.height = (<p2.Box>boxShape).height * factor;
} }
} }
else { else {
//添加圆形刚体 //添加圆形刚体
var boxShape: p2.Shape = new p2.Circle({ radius: 200 / 2 / factor }); var boxShape: p2.Shape = new p2.Circle({ radius: 120 / 2 / factor });
var boxBody: p2.Body = new p2.Body({ mass: 1, position: [positionX, positionY] }); var boxBody: p2.Body = new p2.Body({ mass: 1, position: [positionX, positionY] });
boxBody.addShape(boxShape); boxBody.addShape(boxShape);
world.addBody(boxBody); world.addBody(boxBody);
...@@ -71,7 +94,7 @@ export default class GameView extends engine.Container { ...@@ -71,7 +94,7 @@ export default class GameView extends engine.Container {
if (this.isDebug) { if (this.isDebug) {
display = this.createBall((<p2.Circle>boxShape).radius * factor); display = this.createBall((<p2.Circle>boxShape).radius * factor);
} else { } else {
// display = self.createBitmapByName("circle"); display = this.createBitmapByName("ball");
} }
// display.width = (<p2.Circle>boxShape).radius * 2 * factor; // display.width = (<p2.Circle>boxShape).radius * 2 * factor;
......
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