Commit 7da17f99 authored by 汪欢's avatar 汪欢

a

parent d3d3c9d7
......@@ -114,8 +114,14 @@
_this.toRo = 180 / Math.PI;
_this.loopMark = false;
_this.guideMark = false;
_this.ballAddSpeedX = 1.2;
_this.ballAddSpeedY = 5.3;
_this.inPointMark = false;
_this.outPointMark = false;
_this.boardMark = false;
_this.pointMark = false;
_this.planeMark = false;
_this.stringMark = "";
_this.ballAddSpeedX = -40;
_this.ballAddSpeedY = -80;
_this.gravity = -5;
_this.stepSpeed = [0.5, 3.5];
_this.detaTimeEf = _this.stepSpeed[1];
......@@ -130,7 +136,27 @@
_this.clickMark = false;
_this.once(engine.Event.ADDED_TO_STAGE, _this.start, _this);
var p2 = window["p2"];
var materialBall = new p2.Material(1);
_this.world = new p2.World();
_this.world.sleepMode = p2.World.BODY_SLEEPING;
_this.world.gravity = [0, 10];
var box = new p2.Box({
width: 20,
height: 200,
material: materialBoard,
});
_this.boxBody = new p2.Body({
mass: 0,
type: p2.Body.STATIC,
position: [20, 400],
});
_this.boxBody.addShape(box);
_this.box = _this.createBox(0, -100, 20, 200);
_this.boxBody.displays = [_this.box];
_this.world.addBody(_this.boxBody);
_this.world.defaultContactMaterial.friction = 0.1;
_this.world.defaultContactMaterial.restitution = 1;
_this.world.setGlobalStiffness(1e5);
var materialBall = new p2.Material(2);
var materialPoint = new p2.Material(2);
var materialBoard = new p2.Material(2);
var materialPlane = new p2.Material(2);
......@@ -139,50 +165,77 @@
restitution: 0.5,
});
var contactMaterialBallBoard = new p2.ContactMaterial(materialBall, materialBoard, {
friction: 0.3,
restitution: 0.5,
friction: 0.1,
restitution: 1,
});
var contactMaterialBallPlane = new p2.ContactMaterial(materialBall, materialPlane, {
friction: 0.3,
restitution: 0.7,
friction: 0.1,
restitution: 1,
});
_this.world = new p2.World();
_this.world.sleepMode = p2.World.BODY_SLEEPING;
_this.world.gravity = [0, 10];
var box = new p2.Box({ width: _this.config.boardBody.width, height: _this.config.boardBody.height, material: materialBoard });
_this.boxBody = new p2.Body({ mass: 0, type: p2.Body.STATIC, position: [20, 200] });
_this.boxBody.addShape(box);
var display = new engine.Texture(getTextureByName('篮板'));
var displays = new engine.Sprite(display);
_this.addChild(displays);
_this.boxBody.displays = [displays];
_this.world.addBody(_this.boxBody);
_this.world.defaultContactMaterial.friction = 0.3;
_this.world.defaultContactMaterial.restitution = 0.6;
_this.world.setGlobalStiffness(1e5);
_this.world.addContactMaterial(contactMaterialBallPoint);
_this.world.addContactMaterial(contactMaterialBallBoard);
_this.world.addContactMaterial(contactMaterialBallPlane);
var ball = new p2.Circle({ radius: 60 });
_this.basketball = new p2.Body({
var circleShape = new p2.Circle({
radius: 1,
material: materialPoint,
});
var circleBody = _this.circleBody = new p2.Body({
mass: 0,
position: [60, 500],
type: p2.Body.STATIC,
});
circleBody.addShape(circleShape);
_this.world.addBody(circleBody);
var ellipse = _this.createBox(0, 0, 20, 20);
circleBody.displays = [ellipse];
var circleShape1 = new p2.Circle({
radius: 1,
material: materialPoint,
});
var circleBody1 = _this.circleBody1 = new p2.Body({
mass: 0,
position: [200, 500],
type: p2.Body.STATIC,
});
circleBody1.addShape(circleShape1);
_this.world.addBody(circleBody1);
var ellipse2 = _this.createBox(0, 0, 20, 20);
circleBody1.displays = [ellipse2];
var ball = new p2.Circle({ radius: 60 });
var basketball = _this.basketball = new p2.Body({
mass: 1,
position: [300, 250],
velocity: [-40, 0],
material: materialBall
velocity: [0, 40],
material: materialBall,
});
_this.basketball.addShape(ball);
_this.world.addBody(_this.basketball);
var balldisplay = new engine.Texture(getTextureByName('篮球'));
var balldisplays = new engine.Sprite(balldisplay);
_this.addChild(balldisplays);
_this.basketball.displays = [balldisplays];
_this.ball = _this.createCircle();
_this.basketball.displays = [_this.ball];
var stringMark = _this.stringMark;
var self = _this;
var plane = new p2.Plane();
_this.planeBody = new p2.Body({ position: [engine.gameStage.width / 2, engine.gameStage.height - 100] });
_this.planeBody = new p2.Body({
position: [engine.gameStage.width, engine.gameStage.height - 200],
material: materialPlane,
});
_this.planeBody.angle = Math.PI;
_this.planeBody.addShape(plane);
_this.world.addBody(_this.planeBody);
_this.plane = _this.createPlane();
_this.planeBody.displays = [_this.plane];
_this.world.on('beginContact', function (e) {
if (e.bodyA == circleBody || e.bodyA == circleBody1) {
if (basketball.position[0] > circleBody.position[0] &&
basketball.position[0] < circleBody1.position[0]) {
if (basketball.position[1] > circleBody.position[1] || basketball.position[1] > circleBody1.position[1]) {
console.log("上往下");
self.isRight = !self.isRight;
self.changePosition();
}
}
}
});
_this.addEventListener(engine.Event.ENTER_FRAME, _this.onEnterFrame, _this);
return _this;
}
......@@ -194,21 +247,30 @@
var display = body.displays[0];
display.x = body.position[0];
display.y = body.position[1];
display.rotation = body.angle * 180 / Math.PI;
display.rotation = (body.angle * 180) / Math.PI;
}
if (this.basketball.position[0] < -120) {
this.basketball.position[0] = 750;
}
if (this.basketball.position[0] > 750 + 120) {
this.basketball.position[0] = -120;
}
};
GameView.prototype.createBox = function () {
GameView.prototype.createBox = function (x, y, w, h) {
var sp = new engine.Shape();
sp.beginFill(0x0000ff);
sp.drawRect(0, 0, 50, 50);
sp.drawRect(x, y, w, h);
sp.endFill();
sp.anchorX = sp.width / 2;
sp.anchorY = sp.height / 2;
this.addChild(sp);
return sp;
};
GameView.prototype.createPlane = function () {
var sp = new engine.Shape();
sp.beginFill(0x0000ff, 1);
sp.moveTo(0, 0);
sp.lineTo(engine.gameStage.width, 0);
sp.drawRect(0, -10, engine.gameStage.width, 10);
sp.endFill();
sp.anchorX = sp.width / 2;
sp.anchorY = sp.height / 2;
this.addChild(sp);
......@@ -217,17 +279,46 @@
GameView.prototype.createCircle = function () {
var sp = new engine.Shape();
sp.beginFill(0xff0000, 0.7);
sp.drawCircle(200, 150, 60);
sp.drawCircle(0, 0, 60);
sp.endFill();
sp.anchorX = sp.width / 2;
sp.anchorY = sp.height / 2;
this.addChild(sp);
return sp;
};
GameView.prototype.createEclipse = function () {
var sp = new engine.Shape();
sp.beginFill(0x00ff00, 0.4);
sp.drawEllipse(0, 0, 200, 80);
sp.endFill();
this.addChild(sp);
return sp;
};
GameView.prototype.changePosition = function () {
this.boxBody.position[0] = 740;
this.boxBody.position[1] = 400;
this.circleBody.position[0] = 540;
this.circleBody.position[1] = 400;
this.circleBody1.position[0] = 700;
this.circleBody1.position[1] = 400;
};
GameView.prototype.onMouseDown = function (e) {
var direction = this.isRight ? -1 : 1;
this.basketball.velocity[0] = this.ballAddSpeedX * direction;
this.basketball.velocity[1] = this.ballAddSpeedY;
this.basketball.angularVelocity = -2 * direction;
};
GameView.prototype.addEvent = function () {
this.addEventListener(engine.Event.ENTER_FRAME, (this.onEnterFrameBind = this.onEnterFrame.bind(this)));
};
GameView.prototype.removeEvent = function () {
this.removeEventListener(engine.Event.ENTER_FRAME, this.onEnterFrameBind);
};
GameView.prototype.start = function () {
this.stage.addEventListener(engine.MouseEvent.CLICK, this.onMouseDown, this);
console.log(this.world);
};
GameView.prototype.stop = function () { };
GameView.prototype.addEvent = function () { };
return GameView;
}(engine.Container));
......
{"version":3,"file":"index.js","sources":["src/custom/basket/src/game/utils.ts","src/custom/basket/src/game/basketBoard.ts","src/custom/basket/src/game/GameView.ts","src/custom/basket/src/props.ts","src/custom/basket/src/game/GameWrapper.ts","src/custom/basket/src/index.ts"],"sourcesContent":["/**\r\n * Created by rockyl on 2020-01-21.\r\n */\r\n\r\nexport function getTexture(uuid) {\r\n\treturn engine.Texture.from(getAssetByUUID(uuid).uuid);\r\n}\r\n\r\nexport function getTextureByName(name) {\r\n\treturn getTexture(engine.getAssetByName(name).uuid);\r\n}\r\n\r\nexport function playSound(name) {\r\n\tengine.playSound(engine.getAssetByName(name).uuid, {keep: true});\r\n}\r\nexport function createSvga(name, anchorName?) {\r\n\tlet inst = new svga.Svga();\r\n\tinst.source = 'asset://' + engine.getAssetByName(name).uuid;\r\n\treturn inst;\r\n}\r\n\r\n\r\n\r\nexport function getIndexFromRC(row,col,maxCol){\r\n\tlet index;\r\n\tindex = row * maxCol + col ;\r\n\treturn index\r\n}\r\n\r\n\r\n\r\n\r\nexport function getRandomArray(array){\r\n\tarray.sort(function() {\r\n\t\treturn .5 - Math.random();\r\n\t});\r\n}","import {getTextureByName} from './utils'\r\n\r\nexport default class BasketBoard extends engine.Container{\r\n board:engine.Sprite = new engine.Sprite(getTextureByName('篮板'));\r\n netFront:engine.Sprite = new engine.Sprite(getTextureByName('球网前'));\r\n netBack:engine.Sprite = new engine.Sprite(getTextureByName('球网后'));\r\n\r\n // 篮筐传感,圆环\r\n private config = {\r\n boardBody:{\r\n x:0,\r\n y:0,\r\n width:0.3,\r\n height:2\r\n },\r\n insidePointBody: {\r\n x: 15,\r\n y: 65,\r\n radius: 0.07\r\n },\r\n outsidePointBody: {\r\n x: 180,\r\n y: 65,\r\n radius: 0.05\r\n },\r\n upSensorBody: {\r\n x: 100,\r\n y: 65,\r\n radius: 0.05\r\n },\r\n downSensorBody: {\r\n x: 100,\r\n y: 65 + 80,\r\n radius: 0.05\r\n }\r\n }\r\n\r\n \r\n\r\n constructor(){\r\n super();\r\n this.addChild(this.board);\r\n\r\n // 椭圆\r\n let shape = new engine.Shape();\r\n shape.beginFill(0xff0000,0.5);\r\n shape.drawEllipse(50,150,200,80);\r\n shape.endFill();\r\n\r\n this.board.addChild(shape)\r\n\r\n\r\n \r\n }\r\n\r\n setPosition(x,y){\r\n this.x = x;\r\n this.y = y;\r\n }\r\n\r\n}","import { getTextureByName, getTexture } from \"./utils\";\r\nimport BasketBoard from \"./basketBoard\";\r\nimport Basketball from \"./Basketball\";\r\nexport default class GameView extends engine.Container {\r\n\r\n private world:p2.World;\r\n private boxBody:p2.Body;\r\n private planeBody:p2.Body;\r\n private basketball:p2.Body;\r\n private ball:engine.Sprite;\r\n private plane:engine.Sprite;\r\n\r\n basketBoard: BasketBoard = new BasketBoard();\r\n\r\n\r\n private pool = {};\r\n private horizontal = [74, 676]; //二值\r\n private verticalArea = [200, 600]; //范围\r\n\r\n private verticalInit = 462 - 45;\r\n private positionInitBall = {\r\n x: 551,\r\n y: 805,\r\n };\r\n private vertical = this.verticalInit;\r\n private isRight = false;\r\n private saleX = this.isRight ? 1 : -1;\r\n\r\n private config = {\r\n net: {\r\n x: 9.5,\r\n y: 19 + 45,\r\n },\r\n insidePointBody: {\r\n x: 15,\r\n y: 65,\r\n radius: 0.07,\r\n },\r\n outsidePointBody: {\r\n x: 180,\r\n y: 65,\r\n radius: 0.05,\r\n },\r\n boardBody: {\r\n x: 0,\r\n y: 0,\r\n // length: 2,\r\n // radius: 0.1,\r\n width: 0.3,\r\n height: 2,\r\n },\r\n upSensorBody: {\r\n x: 100,\r\n y: 65,\r\n radius: 0.05,\r\n },\r\n downSensorBody: {\r\n x: 100,\r\n y: 65 + 80,\r\n radius: 0.05,\r\n },\r\n };\r\n private view;\r\n // private basketball;\r\n private direction;\r\n private toRo = 180 / Math.PI;\r\n private loopMark = false;\r\n private guideMark = false;\r\n\r\n private ballAddSpeedX = 1.2;\r\n private ballAddSpeedY = 5.3;\r\n private gravity = -5;\r\n private stepSpeed = [0.5, 3.5]; //3.5正常速度,2慢速播放\r\n private detaTimeEf = this.stepSpeed[1];\r\n private ballSpeedLimitX = 3;\r\n private planeHeight = 1100;\r\n\r\n private brokeMark = false;\r\n private doubleHit = 0;\r\n private timeLimit = window[\"timeLimit\"] ? window[\"timeLimit\"] : 5;\r\n private timeMark = false;\r\n private timeCount = this.timeLimit;\r\n private timeSpeed = 1 / 60;\r\n\r\n private clickMark = false;\r\n\r\n constructor() {\r\n super();\r\n this.once(engine.Event.ADDED_TO_STAGE, this.start, this);\r\n\r\n var p2 = window[\"p2\"];\r\n\r\n \r\n\r\n // material\r\n var materialBall = new p2.Material(1); //参数id:number\r\n var materialPoint = new p2.Material(2);\r\n var materialBoard = new p2.Material(2);\r\n var materialPlane = new p2.Material(2);\r\n\r\n // 不同material碰撞系数\r\n var contactMaterialBallPoint = new p2.ContactMaterial(\r\n materialBall,\r\n materialPoint,\r\n {\r\n friction: 0.3,\r\n restitution: 0.5,\r\n }\r\n );\r\n var contactMaterialBallBoard = new p2.ContactMaterial(\r\n materialBall,\r\n materialBoard,\r\n {\r\n friction: 0.3,\r\n restitution: 0.5,\r\n }\r\n );\r\n var contactMaterialBallPlane = new p2.ContactMaterial(\r\n materialBall,\r\n materialPlane,\r\n {\r\n friction: 0.3,\r\n restitution: 0.7,\r\n }\r\n );\r\n \r\n\r\n this.world = new p2.World();\r\n this.world.sleepMode = p2.World.BODY_SLEEPING;\r\n\r\n this.world.gravity = [0,10];\r\n // this.world.gravity = [0,-5];\r\n //创建box\r\n // var box:p2.Box = new p2.Box({width:100, height:100});\r\n var box:p2.Box = new p2.Box({width:this.config.boardBody.width, height:this.config.boardBody.height,material:materialBoard});\r\n // this.boxBody = new p2.Body({mass:10, angularVelocity:1, position:[200,200]});\r\n\r\n this.boxBody = new p2.Body({mass:0, type:p2.Body.STATIC, position:[20,200]});\r\n this.boxBody.addShape(box);\r\n // 添加图片\r\n\r\n let display = new engine.Texture(getTextureByName('篮板'));\r\n let displays = new engine.Sprite(display)\r\n this.addChild(displays)\r\n this.boxBody.displays = [displays];\r\n\r\n this.world.addBody(this.boxBody);\r\n // 设置摩擦和回弹系数\r\n this.world.defaultContactMaterial.friction = 0.3;\r\n this.world.defaultContactMaterial.restitution = 0.6;\r\n this.world.setGlobalStiffness(1e5);\r\n\r\n this.world.addContactMaterial(contactMaterialBallPoint);\r\n this.world.addContactMaterial(contactMaterialBallBoard);\r\n this.world.addContactMaterial(contactMaterialBallPlane);\r\n \r\n\r\n // 球体\r\n var ball = new p2.Circle({radius:60});\r\n this.basketball = new p2.Body({\r\n mass:0,\r\n position:[300,250],\r\n velocity:[-40,0],\r\n // type:p2.Body.DYNAMIC,\r\n material:materialBall\r\n })\r\n this.basketball.addShape(ball);\r\n this.world.addBody(this.basketball);\r\n\r\n // this.ball = this.createCircle();\r\n\r\n let balldisplay = new engine.Texture(getTextureByName('篮球'));\r\n let balldisplays = new engine.Sprite(balldisplay);\r\n this.addChild(balldisplays)\r\n this.basketball.displays = [balldisplays];\r\n\r\n\r\n\r\n //创建plane Plane shape class. The plane is facing in the Y direction.\r\n var plane:p2.Plane = new p2.Plane();\r\n this.planeBody = new p2.Body({position:[engine.gameStage.width/2, engine.gameStage.height - 100]}); //GameConst.stage保存全局静态变量stage\r\n this.planeBody.angle = Math.PI;\r\n\r\n this.planeBody.addShape(plane);\r\n\r\n this.world.addBody(this.planeBody);\r\n this.plane = this.createPlane();\r\n this.planeBody.displays = [this.plane];\r\n //每帧更新\r\n this.addEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this);\r\n\r\n }\r\n\r\n private onEnterFrame(){\r\n //更新物理世界\r\n this.world.step(60/1000);\r\n var len:number = this.world.bodies.length;\r\n for(var i: number = 0;i < len;i++) {\r\n var body: p2.Body = this.world.bodies[i];\r\n var display: engine.DisplayObject = body.displays[0];\r\n display.x = body.position[0]; //同步刚体和egret显示对象的位置和旋转角度\r\n display.y = body.position[1];\r\n display.rotation = body.angle * 180 / Math.PI;\r\n }\r\n }\r\n private createBox(){\r\n // var sp:engine.Sprite = new engine.Sprite();\r\n var sp = new engine.Shape();\r\n sp.beginFill(0x0000ff);\r\n sp.drawRect(0,0,50,50);\r\n sp.endFill();\r\n // sp.anchorX = sp.width/2;\r\n // sp.anchorY = sp.height/2;\r\n return sp;\r\n }\r\n private createPlane(){\r\n // var sp:engine.Sprite = new engine.Sprite();\r\n var sp = new engine.Shape();\r\n // sp.lineStyle(10, 0x00ff00);\r\n sp.beginFill(0x0000ff,1)\r\n sp.moveTo(0, 0);\r\n sp.lineTo(engine.gameStage.width,0);\r\n sp.anchorX = sp.width/2;\r\n sp.anchorY = sp.height/2;\r\n this.addChild(sp);\r\n return sp;\r\n }\r\n\r\n private createCircle(){\r\n var sp = new engine.Shape();\r\n sp.beginFill(0xff0000,0.7);\r\n sp.drawCircle(200,150,60);\r\n sp.endFill();\r\n sp.anchorX = sp.width/2;\r\n sp.anchorY = sp.height/2;\r\n return sp;\r\n }\r\n \r\n start() {\r\n\r\n // let gameBg = new engine.Sprite(\r\n // getTexture(\"a880ee6b-c6d1-4d8f-8734-367f368a1803\")\r\n // );\r\n // this.addChild(gameBg);\r\n // this.createWorld()\r\n // this.createPlane();\r\n console.log(this.world)\r\n\r\n \r\n\r\n\r\n // this.addChild(this.world)\r\n /* var fixedTimeStep = 1 / 60; // seconds\r\n var maxSubSteps = 10; // Max sub steps to catch up with the wall clock\r\n var lastTime;\r\n\r\n // Animation loop\r\n function animate(time) {\r\n requestAnimationFrame(animate);\r\n\r\n var deltaTime = lastTime ? (time - lastTime) / 1000 : 0;\r\n\r\n this.world.step(fixedTimeStep, deltaTime, maxSubSteps);\r\n\r\n // Render the circle at the current interpolated position\r\n // renderCircleAtPosition(circleBody.interpolatedPosition);\r\n\r\n lastTime = time;\r\n }\r\n\r\n // Start the animation loop\r\n requestAnimationFrame(animate); */\r\n\r\n\r\n // this.basketBoard.setPosition(0,100);\r\n // this.addChild(this.basketBoard)\r\n // console.log('1')\r\n\r\n // this.basketball.initPos(400,200);\r\n // this.addChild(this.basketball);\r\n\r\n \r\n }\r\n\r\n stop() {}\r\n\r\n addEvent() {}\r\n}\r\n","\r\n\r\nexport let props: any = {};\r\n\r\nexport function prepareProps() {\r\n\tlet metaProps = getProps();\r\n\r\n\tengine.injectProp(props, metaProps);\r\n}\r\n\r\nexport function injectProps(p) {\r\n\tengine.injectProp(props, p);\r\n}\r\n","\r\nimport GameView from \"./GameView\";\r\n\r\nimport { injectProps } from \"../props\";\r\n\r\n\r\nexport class GameWrapper extends engine.Container {\r\n\t// private _status;\r\n\tprivate _gameView: GameView;\r\n\r\n\tconstructor() {\r\n\t\tsuper();\r\n\r\n\t\tengine.globalEvent.addEventListener('game-start', this.start, this);\r\n\t\tengine.globalEvent.addEventListener('game-stop', this.stop, this);\r\n\r\n\t\t//创建实例\r\n\t\tlet gameView = this._gameView = new GameView();\r\n\t\tthis.addChild(gameView);\r\n\r\n\t}\r\n\r\n\tstart(event: engine.Event) {\r\n\t\tinjectProps(event.data);\r\n\r\n\t\t// this._status = 1;\r\n\r\n\t\tthis._gameView.start();\r\n\t}\r\n\tstop(event: engine.Event) {\r\n\t\t\r\n\t\tthis._gameView.stop();\r\n\t}\r\n\r\n\t// reset(event:engine.Event){\r\n\t// \tthis._gameView.reset();\r\n\t// }\r\n}\r\n","\r\n\r\nimport {GameWrapper} from \"./game/GameWrapper\";\r\nimport {injectProps, prepareProps} from \"./props\";\r\n\r\nexport default function (props) {\r\n\tprepareProps();\r\n\tinjectProps(props);\r\n\r\n\tlet instance = new GameWrapper();\r\n\t\r\n\treturn instance;\r\n}\r\n"],"names":["__extends"],"mappings":";;;;;;UAIgB,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;;;CCRD;KAAyCA,qCAAgB;KAqCrD;SAAA,YACI,iBAAO,SAaV;SAlDD,WAAK,GAAiB,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;SAChE,cAAQ,GAAiB,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;SACpE,aAAO,GAAiB,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;SAG3D,YAAM,GAAG;aACb,SAAS,EAAC;iBACN,CAAC,EAAC,CAAC;iBACH,CAAC,EAAC,CAAC;iBACH,KAAK,EAAC,GAAG;iBACT,MAAM,EAAC,CAAC;cACX;aACD,eAAe,EAAE;iBACb,CAAC,EAAE,EAAE;iBACL,CAAC,EAAE,EAAE;iBACL,MAAM,EAAE,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AE3B,UAAgB,YAAY;KAC3B,IAAI,SAAS,GAAG,QAAQ,EAAE,CAAC;KAE3B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;CACrC,CAAC;AAED,UAAgB,WAAW,CAAC,CAAC;KAC5B,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;CAC7B,CAAC;;;CCND;KAAiCA,qCAAgB;KAIhD;SAAA,YACC,iBAAO,SASP;SAPA,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,YAAY,EAAE,KAAI,CAAC,KAAK,EAAE,KAAI,CAAC,CAAC;SACpE,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,WAAW,EAAE,KAAI,CAAC,IAAI,EAAE,KAAI,CAAC,CAAC;SAGlE,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;SAEvB,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;MACtB;KAKF,kBAAC;CAAD,CAAC,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/basket/src/game/utils.ts","src/custom/basket/src/game/basketBoard.ts","src/custom/basket/src/game/GameView.ts","src/custom/basket/src/props.ts","src/custom/basket/src/game/GameWrapper.ts","src/custom/basket/src/index.ts"],"sourcesContent":["/**\r\n * Created by rockyl on 2020-01-21.\r\n */\r\n\r\nexport function getTexture(uuid) {\r\n\treturn engine.Texture.from(getAssetByUUID(uuid).uuid);\r\n}\r\n\r\nexport function getTextureByName(name) {\r\n\treturn getTexture(engine.getAssetByName(name).uuid);\r\n}\r\n\r\nexport function playSound(name) {\r\n\tengine.playSound(engine.getAssetByName(name).uuid, {keep: true});\r\n}\r\nexport function createSvga(name, anchorName?) {\r\n\tlet inst = new svga.Svga();\r\n\tinst.source = 'asset://' + engine.getAssetByName(name).uuid;\r\n\treturn inst;\r\n}\r\n\r\n\r\n\r\nexport function getIndexFromRC(row,col,maxCol){\r\n\tlet index;\r\n\tindex = row * maxCol + col ;\r\n\treturn index\r\n}\r\n\r\n\r\n\r\n\r\nexport function getRandomArray(array){\r\n\tarray.sort(function() {\r\n\t\treturn .5 - Math.random();\r\n\t});\r\n}","import {getTextureByName} from './utils'\r\n\r\nexport default class BasketBoard extends engine.Container{\r\n board:engine.Sprite = new engine.Sprite(getTextureByName('篮板'));\r\n netFront:engine.Sprite = new engine.Sprite(getTextureByName('球网前'));\r\n netBack:engine.Sprite = new engine.Sprite(getTextureByName('球网后'));\r\n\r\n // 篮筐传感,圆环\r\n private config = {\r\n boardBody:{\r\n x:0,\r\n y:0,\r\n width:0.3,\r\n height:2\r\n },\r\n insidePointBody: {\r\n x: 15,\r\n y: 65,\r\n radius: 0.07\r\n },\r\n outsidePointBody: {\r\n x: 180,\r\n y: 65,\r\n radius: 0.05\r\n },\r\n upSensorBody: {\r\n x: 100,\r\n y: 65,\r\n radius: 0.05\r\n },\r\n downSensorBody: {\r\n x: 100,\r\n y: 65 + 80,\r\n radius: 0.05\r\n }\r\n }\r\n\r\n \r\n\r\n constructor(){\r\n super();\r\n this.addChild(this.board);\r\n\r\n // 椭圆\r\n let shape = new engine.Shape();\r\n shape.beginFill(0xff0000,0.5);\r\n shape.drawEllipse(50,150,200,80);\r\n shape.endFill();\r\n\r\n this.board.addChild(shape)\r\n\r\n\r\n \r\n }\r\n\r\n setPosition(x,y){\r\n this.x = x;\r\n this.y = y;\r\n }\r\n\r\n}","import { getTextureByName, getTexture } from \"./utils\";\r\nimport BasketBoard from \"./basketBoard\";\r\nimport Basketball from \"./Basketball\";\r\nexport default class GameView extends engine.Container {\r\n private world: p2.World;\r\n private boxBody: p2.Body;\r\n private planeBody: p2.Body;\r\n private basketball: p2.Body;\r\n private ball: engine.Sprite;\r\n private plane: engine.Sprite;\r\n private box: engine.Sprite;\r\n\r\n private circleBody:p2.Body;\r\n private circleBody1:p2.Body;\r\n\r\n basketBoard: BasketBoard = new BasketBoard();\r\n\r\n private pool = {};\r\n private horizontal = [74, 676]; //二值\r\n private verticalArea = [200, 600]; //范围\r\n\r\n private verticalInit = 462 - 45;\r\n private positionInitBall = {\r\n x: 551,\r\n y: 805,\r\n };\r\n private vertical = this.verticalInit;\r\n private isRight = false;\r\n private saleX = this.isRight ? 1 : -1;\r\n\r\n private config = {\r\n net: {\r\n x: 9.5,\r\n y: 19 + 45,\r\n },\r\n insidePointBody: {\r\n x: 15,\r\n y: 65,\r\n radius: 0.07,\r\n },\r\n outsidePointBody: {\r\n x: 180,\r\n y: 65,\r\n radius: 0.05,\r\n },\r\n boardBody: {\r\n x: 0,\r\n y: 0,\r\n // length: 2,\r\n // radius: 0.1,\r\n width: 0.3,\r\n height: 2,\r\n },\r\n upSensorBody: {\r\n x: 100,\r\n y: 65,\r\n radius: 0.05,\r\n },\r\n downSensorBody: {\r\n x: 100,\r\n y: 65 + 80,\r\n radius: 0.05,\r\n },\r\n };\r\n private onEnterFrameBind: Function;\r\n\r\n private view;\r\n // private basketball;\r\n private direction;\r\n private toRo = 180 / Math.PI;\r\n private loopMark = false;\r\n private guideMark = false;\r\n\r\n //碰撞标志位\r\n private inPointMark = false;\r\n private outPointMark = false;\r\n private boardMark = false;\r\n private pointMark = false;\r\n private planeMark = false;\r\n private stringMark = \"\";\r\n\r\n private ballAddSpeedX = -40;\r\n private ballAddSpeedY = -80;\r\n private gravity = -5;\r\n private stepSpeed = [0.5, 3.5]; //3.5正常速度,2慢速播放\r\n private detaTimeEf = this.stepSpeed[1];\r\n private ballSpeedLimitX = 3;\r\n private planeHeight = 1100;\r\n\r\n private brokeMark = false;\r\n private doubleHit = 0;\r\n private timeLimit = window[\"timeLimit\"] ? window[\"timeLimit\"] : 5;\r\n private timeMark = false;\r\n private timeCount = this.timeLimit;\r\n private timeSpeed = 1 / 60;\r\n\r\n private clickMark = false;\r\n\r\n constructor() {\r\n super();\r\n this.once(engine.Event.ADDED_TO_STAGE, this.start, this);\r\n\r\n var p2 = window[\"p2\"];\r\n\r\n this.world = new p2.World();\r\n this.world.sleepMode = p2.World.BODY_SLEEPING;\r\n\r\n this.world.gravity = [0, 10];\r\n // this.world.gravity = [0,-5];\r\n //创建box\r\n var box: p2.Box = new p2.Box({\r\n width: 20,\r\n height: 200,\r\n material: materialBoard,\r\n });\r\n // var box:p2.Box = new p2.Box({width:this.config.boardBody.width, height:this.config.boardBody.height,material:materialBoard});\r\n // this.boxBody = new p2.Body({mass:10, angularVelocity:1, position:[200,200]});\r\n\r\n this.boxBody = new p2.Body({\r\n mass: 0,\r\n type: p2.Body.STATIC,\r\n position: [20, 400],\r\n });\r\n this.boxBody.addShape(box);\r\n // 添加图片\r\n this.box = this.createBox(0, -100, 20, 200);\r\n this.boxBody.displays = [this.box];\r\n\r\n // let display = new engine.Texture(getTextureByName('篮板'));\r\n // let displays = new engine.Sprite(display)\r\n // this.addChild(displays)\r\n // this.boxBody.displays = [displays];\r\n\r\n this.world.addBody(this.boxBody);\r\n // 设置摩擦和回弹系数\r\n this.world.defaultContactMaterial.friction = 0.1;\r\n this.world.defaultContactMaterial.restitution = 1;\r\n this.world.setGlobalStiffness(1e5);\r\n\r\n // material\r\n var materialBall = new p2.Material(2); //参数id:number\r\n var materialPoint = new p2.Material(2);\r\n var materialBoard = new p2.Material(2);\r\n var materialPlane = new p2.Material(2);\r\n\r\n // 不同material碰撞系数\r\n var contactMaterialBallPoint = new p2.ContactMaterial(\r\n materialBall,\r\n materialPoint,\r\n {\r\n friction: 0.3,\r\n restitution: 0.5,\r\n }\r\n );\r\n var contactMaterialBallBoard = new p2.ContactMaterial(\r\n materialBall,\r\n materialBoard,\r\n {\r\n friction: 0.1,\r\n restitution: 1,\r\n }\r\n );\r\n var contactMaterialBallPlane = new p2.ContactMaterial(\r\n materialBall,\r\n materialPlane,\r\n {\r\n friction: 0.1,\r\n restitution: 1,\r\n }\r\n );\r\n this.world.addContactMaterial(contactMaterialBallPoint);\r\n this.world.addContactMaterial(contactMaterialBallBoard);\r\n this.world.addContactMaterial(contactMaterialBallPlane);\r\n\r\n // 框点\r\n var circleShape = new p2.Circle({\r\n // radius: this.config.outsidePointBody.radius,\r\n radius: 1,\r\n material: materialPoint,\r\n });\r\n var circleBody = this.circleBody = new p2.Body({\r\n mass: 0,\r\n // position: [5.65, -5.5],\r\n position: [60, 500],\r\n type: p2.Body.STATIC,\r\n });\r\n circleBody.addShape(circleShape);\r\n this.world.addBody(circleBody);\r\n var ellipse = this.createBox(0, 0, 20, 20);\r\n circleBody.displays = [ellipse];\r\n\r\n var circleShape1 = new p2.Circle({\r\n // radius: this.config.insidePointBody.radius,\r\n radius: 1,\r\n material: materialPoint,\r\n });\r\n var circleBody1 = this.circleBody1 = new p2.Body({\r\n mass: 0,\r\n // position: [5.65, -5.5],\r\n position: [200, 500],\r\n type: p2.Body.STATIC,\r\n });\r\n circleBody1.addShape(circleShape1);\r\n this.world.addBody(circleBody1);\r\n var ellipse2 = this.createBox(0, 0, 20, 20);\r\n circleBody1.displays = [ellipse2];\r\n\r\n // 球体\r\n var ball = new p2.Circle({ radius: 60 });\r\n var basketball = this.basketball = new p2.Body({\r\n mass: 1,\r\n position: [300, 250],\r\n velocity: [0, 40],\r\n // type:p2.Body.DYNAMIC,\r\n material: materialBall,\r\n });\r\n this.basketball.addShape(ball);\r\n this.world.addBody(this.basketball);\r\n\r\n this.ball = this.createCircle();\r\n this.basketball.displays = [this.ball];\r\n\r\n // let balldisplay = new engine.Texture(getTextureByName('篮球'));\r\n // let balldisplays = new engine.Sprite(balldisplay);\r\n // balldisplays.width = 120;\r\n // balldisplays.height = 120\r\n // this.addChild(balldisplays)\r\n // this.basketball.displays = [balldisplays];\r\n\r\n //进球感应区域\r\n // var sensorShape = new p2.Circle({\r\n // radius: this.config.upSensorBody.radius\r\n // });\r\n // sensorShape.sensor = true;\r\n // var sensorBody = new p2.Body({\r\n // position: [this.config.upSensorBody.x, this.config.upSensorBody.y]\r\n // });\r\n // sensorBody.damping = 0;\r\n // sensorBody.addShape(sensorShape);\r\n // this.world.addBody(sensorBody);\r\n\r\n // var sensorShape1 = new p2.Circle({\r\n // radius: this.config.downSensorBody.radius\r\n // });\r\n // sensorShape1.sensor = true;\r\n // var sensorBody1 = new p2.Body({\r\n // position: [this.config.downSensorBody.x, this.config.downSensorBody.y]\r\n // });\r\n // sensorBody1.damping = 0;\r\n // sensorBody1.addShape(sensorShape1);\r\n // this.world.addBody(sensorBody1);\r\n\r\n //contactPointA 相对于bodyA的碰撞点位置,\r\n //contactPointB 相对于bodyB的碰撞点位置,\r\n\r\n let stringMark = this.stringMark;\r\n let self = this;\r\n let boardMarkSetTime;\r\n let pointMarkSetTime;\r\n\r\n //创建plane Plane shape class. The plane is facing in the Y direction.\r\n var plane: p2.Plane = new p2.Plane();\r\n this.planeBody = new p2.Body({\r\n position: [engine.gameStage.width, engine.gameStage.height - 200],\r\n material: materialPlane,\r\n }); //GameConst.stage保存全局静态变量stage\r\n this.planeBody.angle = Math.PI;\r\n\r\n this.planeBody.addShape(plane);\r\n\r\n this.world.addBody(this.planeBody);\r\n this.plane = this.createPlane();\r\n this.planeBody.displays = [this.plane];\r\n\r\n // 碰撞\r\n this.world.on('beginContact',function(e){\r\n // let direction = self.isRight ? 1 : -1;\r\n \r\n if(e.bodyA == circleBody || e.bodyA == circleBody1){\r\n if (\r\n basketball.position[0] > circleBody.position[0] &&\r\n basketball.position[0] < circleBody1.position[0]\r\n ) {\r\n if (basketball.position[1] > circleBody.position[1] || basketball.position[1] > circleBody1.position[1]) {\r\n console.log(\"上往下\");\r\n self.isRight = !self.isRight;\r\n // 移动刚体\r\n self.changePosition()\r\n }\r\n }\r\n }\r\n \r\n\r\n })\r\n\r\n //每帧更新\r\n this.addEventListener(\r\n engine.Event.ENTER_FRAME,\r\n this.onEnterFrame,\r\n this\r\n );\r\n }\r\n\r\n private onEnterFrame() {\r\n // this.basketball.position[0] = this.basketball.interpolatedPosition[0] * 100;\r\n // this.basketball.position[1] = -this.basketball.interpolatedPosition[1] * 100;\r\n // this.basketball.rotation = -this.basketball.interpolatedAngle * this.toRo;\r\n\r\n //更新物理世界\r\n this.world.step(60 / 1000);\r\n var len: number = this.world.bodies.length;\r\n for (var i: number = 0; i < len; i++) {\r\n var body: p2.Body = this.world.bodies[i];\r\n var display: engine.DisplayObject = body.displays[0];\r\n display.x = body.position[0]; //同步刚体和egret显示对象的位置和旋转角度\r\n display.y = body.position[1];\r\n display.rotation = (body.angle * 180) / Math.PI;\r\n }\r\n\r\n if (this.basketball.position[0] < -120) {\r\n this.basketball.position[0] = 750;\r\n }\r\n if (this.basketball.position[0] > 750 + 120) {\r\n this.basketball.position[0] = - 120;\r\n }\r\n\r\n }\r\n private createBox(x, y, w, h) {\r\n // var sp:engine.Sprite = new engine.Sprite();\r\n var sp = new engine.Shape();\r\n sp.beginFill(0x0000ff);\r\n sp.drawRect(x, y, w, h);\r\n sp.endFill();\r\n sp.anchorX = sp.width / 2;\r\n sp.anchorY = sp.height / 2;\r\n this.addChild(sp);\r\n return sp;\r\n }\r\n private createPlane() {\r\n // var sp:engine.Sprite = new engine.Sprite();\r\n var sp = new engine.Shape();\r\n // sp.lineStyle(10, 0x00ff00);\r\n sp.beginFill(0x0000ff, 1);\r\n // sp.moveTo(0, 0);\r\n // sp.lineTo(engine.gameStage.width,0);\r\n sp.drawRect(0, -10, engine.gameStage.width, 10);\r\n sp.endFill();\r\n sp.anchorX = sp.width / 2;\r\n sp.anchorY = sp.height / 2;\r\n this.addChild(sp);\r\n return sp;\r\n }\r\n\r\n private createCircle() {\r\n var sp = new engine.Shape();\r\n sp.beginFill(0xff0000, 0.7);\r\n sp.drawCircle(0, 0, 60);\r\n sp.endFill();\r\n sp.anchorX = sp.width / 2;\r\n sp.anchorY = sp.height / 2;\r\n this.addChild(sp);\r\n return sp;\r\n }\r\n\r\n private createEclipse() {\r\n var sp = new engine.Shape();\r\n sp.beginFill(0x00ff00, 0.4);\r\n sp.drawEllipse(0, 0, 200, 80);\r\n sp.endFill();\r\n this.addChild(sp);\r\n return sp;\r\n }\r\n\r\n changePosition(){\r\n this.boxBody.position[0] = 740;\r\n this.boxBody.position[1] = 400;\r\n\r\n this.circleBody.position[0] = 540;\r\n this.circleBody.position[1] = 400;\r\n this.circleBody1.position[0] = 700;\r\n this.circleBody1.position[1] = 400;\r\n\r\n }\r\n\r\n onMouseDown(e: engine.MouseEvent) {\r\n var direction = this.isRight ? -1 : 1;\r\n this.basketball.velocity[0] = this.ballAddSpeedX * direction;\r\n this.basketball.velocity[1] = this.ballAddSpeedY;\r\n this.basketball.angularVelocity = -2 * direction;\r\n }\r\n\r\n addEvent() {\r\n this.addEventListener(\r\n engine.Event.ENTER_FRAME,\r\n (this.onEnterFrameBind = this.onEnterFrame.bind(this))\r\n );\r\n }\r\n removeEvent() {\r\n this.removeEventListener(\r\n engine.Event.ENTER_FRAME,\r\n this.onEnterFrameBind\r\n );\r\n }\r\n\r\n start() {\r\n // let gameBg = new engine.Sprite(\r\n // getTexture(\"a880ee6b-c6d1-4d8f-8734-367f368a1803\")\r\n // );\r\n // this.addChild(gameBg);\r\n\r\n this.stage.addEventListener(\r\n engine.MouseEvent.CLICK,\r\n this.onMouseDown,\r\n this\r\n );\r\n\r\n console.log(this.world);\r\n\r\n // this.basketBoard.setPosition(0,100);\r\n // this.addChild(this.basketBoard)\r\n // console.log('1')\r\n\r\n // this.basketball.initPos(400,200);\r\n // this.addChild(this.basketball);\r\n }\r\n\r\n stop() {}\r\n}\r\n","\r\n\r\nexport let props: any = {};\r\n\r\nexport function prepareProps() {\r\n\tlet metaProps = getProps();\r\n\r\n\tengine.injectProp(props, metaProps);\r\n}\r\n\r\nexport function injectProps(p) {\r\n\tengine.injectProp(props, p);\r\n}\r\n","\r\nimport GameView from \"./GameView\";\r\n\r\nimport { injectProps } from \"../props\";\r\n\r\n\r\nexport class GameWrapper extends engine.Container {\r\n\t// private _status;\r\n\tprivate _gameView: GameView;\r\n\r\n\tconstructor() {\r\n\t\tsuper();\r\n\r\n\t\tengine.globalEvent.addEventListener('game-start', this.start, this);\r\n\t\tengine.globalEvent.addEventListener('game-stop', this.stop, this);\r\n\r\n\t\t//创建实例\r\n\t\tlet gameView = this._gameView = new GameView();\r\n\t\tthis.addChild(gameView);\r\n\r\n\t}\r\n\r\n\tstart(event: engine.Event) {\r\n\t\tinjectProps(event.data);\r\n\r\n\t\t// this._status = 1;\r\n\r\n\t\tthis._gameView.start();\r\n\t}\r\n\tstop(event: engine.Event) {\r\n\t\t\r\n\t\tthis._gameView.stop();\r\n\t}\r\n\r\n\t// reset(event:engine.Event){\r\n\t// \tthis._gameView.reset();\r\n\t// }\r\n}\r\n","\r\n\r\nimport {GameWrapper} from \"./game/GameWrapper\";\r\nimport {injectProps, prepareProps} from \"./props\";\r\n\r\nexport default function (props) {\r\n\tprepareProps();\r\n\tinjectProps(props);\r\n\r\n\tlet instance = new GameWrapper();\r\n\t\r\n\treturn instance;\r\n}\r\n"],"names":["__extends"],"mappings":";;;;;;UAIgB,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,CAA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CAAC,CAAC,CAAC;CAC7B,CAAC;;;CCND;KAAiCA,qCAAgB;KAIhD;SAAA,YACC,iBAAO,SASP;SAPA,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,YAAY,EAAE,KAAI,CAAC,KAAK,EAAE,KAAI,CAAC,CAAC;SACpE,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,WAAW,EAAE,KAAI,CAAC,IAAI,EAAE,KAAI,CAAC,CAAC;SAGlE,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;SAEvB,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC;MACtB;KAKF,kBAAC;CAAD,CAAC,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
......@@ -2,17 +2,19 @@ import { getTextureByName, getTexture } from "./utils";
import BasketBoard from "./basketBoard";
import Basketball from "./Basketball";
export default class GameView extends engine.Container {
private world: p2.World;
private boxBody: p2.Body;
private planeBody: p2.Body;
private basketball: p2.Body;
private ball: engine.Sprite;
private plane: engine.Sprite;
private box: engine.Sprite;
private world:p2.World;
private boxBody:p2.Body;
private planeBody:p2.Body;
private basketball:p2.Body;
private ball:engine.Sprite;
private plane:engine.Sprite;
private circleBody:p2.Body;
private circleBody1:p2.Body;
basketBoard: BasketBoard = new BasketBoard();
private pool = {};
private horizontal = [74, 676]; //二值
private verticalArea = [200, 600]; //范围
......@@ -60,6 +62,8 @@ export default class GameView extends engine.Container {
radius: 0.05,
},
};
private onEnterFrameBind: Function;
private view;
// private basketball;
private direction;
......@@ -67,8 +71,16 @@ export default class GameView extends engine.Container {
private loopMark = false;
private guideMark = false;
private ballAddSpeedX = 1.2;
private ballAddSpeedY = 5.3;
//碰撞标志位
private inPointMark = false;
private outPointMark = false;
private boardMark = false;
private pointMark = false;
private planeMark = false;
private stringMark = "";
private ballAddSpeedX = -40;
private ballAddSpeedY = -80;
private gravity = -5;
private stepSpeed = [0.5, 3.5]; //3.5正常速度,2慢速播放
private detaTimeEf = this.stepSpeed[1];
......@@ -90,10 +102,43 @@ export default class GameView extends engine.Container {
var p2 = window["p2"];
this.world = new p2.World();
this.world.sleepMode = p2.World.BODY_SLEEPING;
this.world.gravity = [0, 10];
// this.world.gravity = [0,-5];
//创建box
var box: p2.Box = new p2.Box({
width: 20,
height: 200,
material: materialBoard,
});
// var box:p2.Box = new p2.Box({width:this.config.boardBody.width, height:this.config.boardBody.height,material:materialBoard});
// this.boxBody = new p2.Body({mass:10, angularVelocity:1, position:[200,200]});
this.boxBody = new p2.Body({
mass: 0,
type: p2.Body.STATIC,
position: [20, 400],
});
this.boxBody.addShape(box);
// 添加图片
this.box = this.createBox(0, -100, 20, 200);
this.boxBody.displays = [this.box];
// let display = new engine.Texture(getTextureByName('篮板'));
// let displays = new engine.Sprite(display)
// this.addChild(displays)
// this.boxBody.displays = [displays];
this.world.addBody(this.boxBody);
// 设置摩擦和回弹系数
this.world.defaultContactMaterial.friction = 0.1;
this.world.defaultContactMaterial.restitution = 1;
this.world.setGlobalStiffness(1e5);
// material
var materialBall = new p2.Material(1); //参数id:number
var materialBall = new p2.Material(2); //参数id:number
var materialPoint = new p2.Material(2);
var materialBoard = new p2.Material(2);
var materialPlane = new p2.Material(2);
......@@ -111,74 +156,114 @@ export default class GameView extends engine.Container {
materialBall,
materialBoard,
{
friction: 0.3,
restitution: 0.5,
friction: 0.1,
restitution: 1,
}
);
var contactMaterialBallPlane = new p2.ContactMaterial(
materialBall,
materialPlane,
{
friction: 0.3,
restitution: 0.7,
friction: 0.1,
restitution: 1,
}
);
this.world = new p2.World();
this.world.sleepMode = p2.World.BODY_SLEEPING;
this.world.gravity = [0,10];
// this.world.gravity = [0,-5];
//创建box
// var box:p2.Box = new p2.Box({width:100, height:100});
var box:p2.Box = new p2.Box({width:this.config.boardBody.width, height:this.config.boardBody.height,material:materialBoard});
// this.boxBody = new p2.Body({mass:10, angularVelocity:1, position:[200,200]});
this.boxBody = new p2.Body({mass:0, type:p2.Body.STATIC, position:[20,200]});
this.boxBody.addShape(box);
// 添加图片
let display = new engine.Texture(getTextureByName('篮板'));
let displays = new engine.Sprite(display)
this.addChild(displays)
this.boxBody.displays = [displays];
this.world.addBody(this.boxBody);
// 设置摩擦和回弹系数
this.world.defaultContactMaterial.friction = 0.3;
this.world.defaultContactMaterial.restitution = 0.6;
this.world.setGlobalStiffness(1e5);
this.world.addContactMaterial(contactMaterialBallPoint);
this.world.addContactMaterial(contactMaterialBallBoard);
this.world.addContactMaterial(contactMaterialBallPlane);
// 框点
var circleShape = new p2.Circle({
// radius: this.config.outsidePointBody.radius,
radius: 1,
material: materialPoint,
});
var circleBody = this.circleBody = new p2.Body({
mass: 0,
// position: [5.65, -5.5],
position: [60, 500],
type: p2.Body.STATIC,
});
circleBody.addShape(circleShape);
this.world.addBody(circleBody);
var ellipse = this.createBox(0, 0, 20, 20);
circleBody.displays = [ellipse];
var circleShape1 = new p2.Circle({
// radius: this.config.insidePointBody.radius,
radius: 1,
material: materialPoint,
});
var circleBody1 = this.circleBody1 = new p2.Body({
mass: 0,
// position: [5.65, -5.5],
position: [200, 500],
type: p2.Body.STATIC,
});
circleBody1.addShape(circleShape1);
this.world.addBody(circleBody1);
var ellipse2 = this.createBox(0, 0, 20, 20);
circleBody1.displays = [ellipse2];
// 球体
var ball = new p2.Circle({radius:60});
this.basketball = new p2.Body({
mass:0,
position:[300,250],
velocity:[-40,0],
var ball = new p2.Circle({ radius: 60 });
var basketball = this.basketball = new p2.Body({
mass: 1,
position: [300, 250],
velocity: [0, 40],
// type:p2.Body.DYNAMIC,
material:materialBall
})
material: materialBall,
});
this.basketball.addShape(ball);
this.world.addBody(this.basketball);
// this.ball = this.createCircle();
let balldisplay = new engine.Texture(getTextureByName('篮球'));
let balldisplays = new engine.Sprite(balldisplay);
this.addChild(balldisplays)
this.basketball.displays = [balldisplays];
this.ball = this.createCircle();
this.basketball.displays = [this.ball];
// let balldisplay = new engine.Texture(getTextureByName('篮球'));
// let balldisplays = new engine.Sprite(balldisplay);
// balldisplays.width = 120;
// balldisplays.height = 120
// this.addChild(balldisplays)
// this.basketball.displays = [balldisplays];
//进球感应区域
// var sensorShape = new p2.Circle({
// radius: this.config.upSensorBody.radius
// });
// sensorShape.sensor = true;
// var sensorBody = new p2.Body({
// position: [this.config.upSensorBody.x, this.config.upSensorBody.y]
// });
// sensorBody.damping = 0;
// sensorBody.addShape(sensorShape);
// this.world.addBody(sensorBody);
// var sensorShape1 = new p2.Circle({
// radius: this.config.downSensorBody.radius
// });
// sensorShape1.sensor = true;
// var sensorBody1 = new p2.Body({
// position: [this.config.downSensorBody.x, this.config.downSensorBody.y]
// });
// sensorBody1.damping = 0;
// sensorBody1.addShape(sensorShape1);
// this.world.addBody(sensorBody1);
//contactPointA 相对于bodyA的碰撞点位置,
//contactPointB 相对于bodyB的碰撞点位置,
let stringMark = this.stringMark;
let self = this;
let boardMarkSetTime;
let pointMarkSetTime;
//创建plane Plane shape class. The plane is facing in the Y direction.
var plane:p2.Plane = new p2.Plane();
this.planeBody = new p2.Body({position:[engine.gameStage.width/2, engine.gameStage.height - 100]}); //GameConst.stage保存全局静态变量stage
var plane: p2.Plane = new p2.Plane();
this.planeBody = new p2.Body({
position: [engine.gameStage.width, engine.gameStage.height - 200],
material: materialPlane,
}); //GameConst.stage保存全局静态变量stage
this.planeBody.angle = Math.PI;
this.planeBody.addShape(plane);
......@@ -186,91 +271,150 @@ export default class GameView extends engine.Container {
this.world.addBody(this.planeBody);
this.plane = this.createPlane();
this.planeBody.displays = [this.plane];
//每帧更新
this.addEventListener(engine.Event.ENTER_FRAME, this.onEnterFrame, this);
// 碰撞
this.world.on('beginContact',function(e){
// let direction = self.isRight ? 1 : -1;
if(e.bodyA == circleBody || e.bodyA == circleBody1){
if (
basketball.position[0] > circleBody.position[0] &&
basketball.position[0] < circleBody1.position[0]
) {
if (basketball.position[1] > circleBody.position[1] || basketball.position[1] > circleBody1.position[1]) {
console.log("上往下");
self.isRight = !self.isRight;
// 移动刚体
self.changePosition()
}
}
}
})
//每帧更新
this.addEventListener(
engine.Event.ENTER_FRAME,
this.onEnterFrame,
this
);
}
private onEnterFrame(){
private onEnterFrame() {
// this.basketball.position[0] = this.basketball.interpolatedPosition[0] * 100;
// this.basketball.position[1] = -this.basketball.interpolatedPosition[1] * 100;
// this.basketball.rotation = -this.basketball.interpolatedAngle * this.toRo;
//更新物理世界
this.world.step(60/1000);
var len:number = this.world.bodies.length;
for(var i: number = 0;i < len;i++) {
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;
display.rotation = (body.angle * 180) / Math.PI;
}
if (this.basketball.position[0] < -120) {
this.basketball.position[0] = 750;
}
if (this.basketball.position[0] > 750 + 120) {
this.basketball.position[0] = - 120;
}
}
private createBox(){
private createBox(x, y, w, h) {
// var sp:engine.Sprite = new engine.Sprite();
var sp = new engine.Shape();
sp.beginFill(0x0000ff);
sp.drawRect(0,0,50,50);
sp.drawRect(x, y, w, h);
sp.endFill();
// sp.anchorX = sp.width/2;
// sp.anchorY = sp.height/2;
sp.anchorX = sp.width / 2;
sp.anchorY = sp.height / 2;
this.addChild(sp);
return sp;
}
private createPlane(){
private createPlane() {
// var sp:engine.Sprite = new engine.Sprite();
var sp = new engine.Shape();
// sp.lineStyle(10, 0x00ff00);
sp.beginFill(0x0000ff,1)
sp.moveTo(0, 0);
sp.lineTo(engine.gameStage.width,0);
sp.anchorX = sp.width/2;
sp.anchorY = sp.height/2;
sp.beginFill(0x0000ff, 1);
// sp.moveTo(0, 0);
// sp.lineTo(engine.gameStage.width,0);
sp.drawRect(0, -10, engine.gameStage.width, 10);
sp.endFill();
sp.anchorX = sp.width / 2;
sp.anchorY = sp.height / 2;
this.addChild(sp);
return sp;
}
private createCircle(){
private createCircle() {
var sp = new engine.Shape();
sp.beginFill(0xff0000,0.7);
sp.drawCircle(200,150,60);
sp.beginFill(0xff0000, 0.7);
sp.drawCircle(0, 0, 60);
sp.endFill();
sp.anchorX = sp.width/2;
sp.anchorY = sp.height/2;
sp.anchorX = sp.width / 2;
sp.anchorY = sp.height / 2;
this.addChild(sp);
return sp;
}
start() {
// let gameBg = new engine.Sprite(
// getTexture("a880ee6b-c6d1-4d8f-8734-367f368a1803")
// );
// this.addChild(gameBg);
// this.createWorld()
// this.createPlane();
console.log(this.world)
// this.addChild(this.world)
/* var fixedTimeStep = 1 / 60; // seconds
var maxSubSteps = 10; // Max sub steps to catch up with the wall clock
var lastTime;
private createEclipse() {
var sp = new engine.Shape();
sp.beginFill(0x00ff00, 0.4);
sp.drawEllipse(0, 0, 200, 80);
sp.endFill();
this.addChild(sp);
return sp;
}
// Animation loop
function animate(time) {
requestAnimationFrame(animate);
changePosition(){
this.boxBody.position[0] = 740;
this.boxBody.position[1] = 400;
var deltaTime = lastTime ? (time - lastTime) / 1000 : 0;
this.circleBody.position[0] = 540;
this.circleBody.position[1] = 400;
this.circleBody1.position[0] = 700;
this.circleBody1.position[1] = 400;
this.world.step(fixedTimeStep, deltaTime, maxSubSteps);
}
// Render the circle at the current interpolated position
// renderCircleAtPosition(circleBody.interpolatedPosition);
onMouseDown(e: engine.MouseEvent) {
var direction = this.isRight ? -1 : 1;
this.basketball.velocity[0] = this.ballAddSpeedX * direction;
this.basketball.velocity[1] = this.ballAddSpeedY;
this.basketball.angularVelocity = -2 * direction;
}
lastTime = time;
addEvent() {
this.addEventListener(
engine.Event.ENTER_FRAME,
(this.onEnterFrameBind = this.onEnterFrame.bind(this))
);
}
removeEvent() {
this.removeEventListener(
engine.Event.ENTER_FRAME,
this.onEnterFrameBind
);
}
// Start the animation loop
requestAnimationFrame(animate); */
start() {
// let gameBg = new engine.Sprite(
// getTexture("a880ee6b-c6d1-4d8f-8734-367f368a1803")
// );
// this.addChild(gameBg);
this.stage.addEventListener(
engine.MouseEvent.CLICK,
this.onMouseDown,
this
);
console.log(this.world);
// this.basketBoard.setPosition(0,100);
// this.addChild(this.basketBoard)
......@@ -278,11 +422,7 @@ export default class GameView extends engine.Container {
// this.basketball.initPos(400,200);
// this.addChild(this.basketball);
}
stop() {}
addEvent() {}
}
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