Commit 28f9308b authored by wildfirecode's avatar wildfirecode

1

parent 42d0ce01
...@@ -6,10 +6,11 @@ import { TextRenderer } from 'scilla-components/src'; ...@@ -6,10 +6,11 @@ import { TextRenderer } from 'scilla-components/src';
export default class BallItem extends Body { export default class BallItem extends Body {
score = 0; score = 0;
scoreTxt: Entity; scoreTxt: Entity;
isBig = true;
constructor() { constructor() {
super(); super();
this.gravity = gravityY; this.gravity = gravityY;
this.rotationSpeed = 0.5 * 2; this.rotationSpeed = 0.5;
} }
onAwake() { onAwake() {
...@@ -22,6 +23,7 @@ export default class BallItem extends Body { ...@@ -22,6 +23,7 @@ export default class BallItem extends Body {
if (this.score < 0) if (this.score < 0)
this.score = 0; this.score = 0;
this.updateScoreTxt(); this.updateScoreTxt();
return this.score;
} }
updateScoreTxt() { updateScoreTxt() {
......
...@@ -74,16 +74,28 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi ...@@ -74,16 +74,28 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
super.onAwake(); super.onAwake();
this.ballList = []; this.ballList = [];
this.bodys = []; this.bodys = [];
this.toRmoveBallList = [];
} }
onUpdate() { onUpdate() {
for (let i = 0; i < this.toRmoveBallList.length; i++) {
const element = this.toRmoveBallList[i];
const bc = element.getComponent(BallItem);
this.toRmoveBallList.splice(i, 1);
i--;
this.removeBall(element);
if (bc.isBig) {
this.onBallSplit(element);
}
}
//所有的刚体检查,包括子弹、掉落 //所有的刚体检查,包括子弹、掉落
for (let i = 0; i < this.bodys.length; i++) { for (let i = 0; i < this.bodys.length; i++) {
const body = this.bodys[i]; const body = this.bodys[i];
const { position } = body.getComponent(Transform); const { position } = body.getComponent(Transform);
const pic = body.getChildrenByName('pic')[0]; const pic = body.getChildrenByName('pic')[0];
const { height, width } = pic.getComponent(Transform); const { height, width, scale } = pic.getComponent(Transform);
const r = height / 2;//刚体的半径 const r = height / 2 * scale.y;//刚体的半径
if (position.y + r > GROUND_Y) { if (position.y + r > GROUND_Y) {
position.y = GROUND_Y - r; position.y = GROUND_Y - r;
body.getComponent(Body).revertY(); body.getComponent(Body).revertY();
...@@ -121,24 +133,36 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi ...@@ -121,24 +133,36 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
i--; i--;
} else { } else {
//子弹和ball处理 //子弹和ball处理
for (const ball of this.ballList) { // console.log(body.getComponent(Transform))
const x0 = Math.abs(getX(body) - getX(ball)); try {
const y0 = Math.abs(getY(body) - getY(ball)); for (const ball of this.ballList) {
const { height: ballH } = ball.getChildrenByName('pic')[0].getComponent(Transform); const x0 = Math.abs(getX(body) - getX(ball));
const x1 = width / 2 + ballH / 2; const y0 = Math.abs(getY(body) - getY(ball));
const y1 = height / 2 + ballH / 2; const ballT = ball.getComponent(Transform);
if (x0 < x1 && y0 < y1) { //子弹和球碰撞了 const { height: ballH } = ball.getChildrenByName('pic')[0].getComponent(Transform);
this.removeBullet(body); const x1 = width / 2 + ballH / 2 * ballT.scale.x;
i--; const y1 = height / 2 + ballH / 2 * ballT.scale.x;
// console.log(ballT.scale.x)
if (x0 < x1 && y0 < y1) { //子弹和球碰撞了
this.removeBullet(body);
i--;
if (ball.getComponent(BallItem).reduceScore() == 0) { //破裂
this.toRmoveBallList.push(ball);
}
}
} }
} catch (error) {
} }
} }
} }
} }
} }
toRmoveBallList: Entity[];
removeBullet(body: Entity) { removeBullet(body: Entity) {
console.log(this.bodys.length) // console.log(this.bodys.length)
body.removeAllComponents(); body.removeAllComponents();
const index = this.bodys.indexOf(body); const index = this.bodys.indexOf(body);
if (index == -1) return; if (index == -1) return;
...@@ -166,10 +190,24 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi ...@@ -166,10 +190,24 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
onBallSplit(body: Entity) { onBallSplit(body: Entity) {
//球分裂 //球分裂
const ball1 = this.getBallItem(100); const ball1 = this.createSmallBalls(body);
// const ball2 = this.getBallItem(); const ball2 = this.createSmallBalls(body);
setXY(ball1, getX(body), getY(body)); setXY(ball1, getX(body), getY(body));
ball1.getComponent(Body).velocityY = -45; setXY(ball2, getX(body), getY(body));
ball1.getComponent(Body).velocityY = -10;
ball1.getComponent(Body).velocityX = -5;
ball2.getComponent(Body).velocityY = -10;
ball2.getComponent(Body).velocityX = 5;
}
createSmallBalls(parentBall: Entity) {
const ball = this.getBallItem(10);
const ballc = ball.getComponent(BallItem);
const tras = ball.getComponent(Transform);
tras.scale.x = 0.6;
tras.scale.y = 0.6;
ballc.isBig = false;
return ball;
} }
async onCarCollideDrops(body: Entity) { async onCarCollideDrops(body: Entity) {
...@@ -187,7 +225,7 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi ...@@ -187,7 +225,7 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
} }
async createBigBall() { async createBigBall() {
const ball = this.getBallItem(100); const ball = this.getBallItem(20);
setXY(ball, -375, -400); setXY(ball, -375, -400);
const body = ball.getComponent(Body); const body = ball.getComponent(Body);
body.enabled = false; body.enabled = false;
......
export const gravityY= .7; export const gravityY= .5;
\ No newline at end of file \ No newline at end of file
...@@ -8,6 +8,7 @@ export const setY = (entity: Entity, y) => { ...@@ -8,6 +8,7 @@ export const setY = (entity: Entity, y) => {
entity.getComponent(Transform).position.y = y; entity.getComponent(Transform).position.y = y;
} }
export const getX = (entity: Entity) => { export const getX = (entity: Entity) => {
// if(!entity.getComponent(Transform))debugger
return entity.getComponent(Transform).position.x return entity.getComponent(Transform).position.x
} }
export const getY = (entity: Entity) => { export const getY = (entity: Entity) => {
......
...@@ -7019,15 +7019,16 @@ ...@@ -7019,15 +7019,16 @@
return Body; return Body;
}(ScillaComponent)); }(ScillaComponent));
var gravityY = .7; var gravityY = .5;
var BallItem = (function (_super) { var BallItem = (function (_super) {
__extends(BallItem, _super); __extends(BallItem, _super);
function BallItem() { function BallItem() {
var _this = _super.call(this) || this; var _this = _super.call(this) || this;
_this.score = 0; _this.score = 0;
_this.isBig = true;
_this.gravity = gravityY; _this.gravity = gravityY;
_this.rotationSpeed = 0.5 * 2; _this.rotationSpeed = 0.5;
return _this; return _this;
} }
BallItem.prototype.onAwake = function () { BallItem.prototype.onAwake = function () {
...@@ -7039,6 +7040,7 @@ ...@@ -7039,6 +7040,7 @@
if (this.score < 0) if (this.score < 0)
this.score = 0; this.score = 0;
this.updateScoreTxt(); this.updateScoreTxt();
return this.score;
}; };
BallItem.prototype.updateScoreTxt = function () { BallItem.prototype.updateScoreTxt = function () {
var tr = this.scoreTxt.getComponent(TextRenderer); var tr = this.scoreTxt.getComponent(TextRenderer);
...@@ -7125,15 +7127,26 @@ ...@@ -7125,15 +7127,26 @@
_super.prototype.onAwake.call(this); _super.prototype.onAwake.call(this);
this.ballList = []; this.ballList = [];
this.bodys = []; this.bodys = [];
this.toRmoveBallList = [];
}; };
ScenePlay.prototype.onUpdate = function () { ScenePlay.prototype.onUpdate = function () {
var e_1, _a; var e_1, _a;
for (var i = 0; i < this.toRmoveBallList.length; i++) {
var element = this.toRmoveBallList[i];
var bc = element.getComponent(BallItem);
this.toRmoveBallList.splice(i, 1);
i--;
this.removeBall(element);
if (bc.isBig) {
this.onBallSplit(element);
}
}
for (var i = 0; i < this.bodys.length; i++) { for (var i = 0; i < this.bodys.length; i++) {
var body = this.bodys[i]; var body = this.bodys[i];
var position = body.getComponent(Transform).position; var position = body.getComponent(Transform).position;
var pic = body.getChildrenByName('pic')[0]; var pic = body.getChildrenByName('pic')[0];
var _b = pic.getComponent(Transform), height = _b.height, width = _b.width; var _b = pic.getComponent(Transform), height = _b.height, width = _b.width, scale = _b.scale;
var r = height / 2; var r = height / 2 * scale.y;
if (position.y + r > GROUND_Y) { if (position.y + r > GROUND_Y) {
position.y = GROUND_Y - r; position.y = GROUND_Y - r;
body.getComponent(Body).revertY(); body.getComponent(Body).revertY();
...@@ -7166,32 +7179,39 @@ ...@@ -7166,32 +7179,39 @@
} }
else { else {
try { try {
for (var _d = __values(this.ballList), _e = _d.next(); !_e.done; _e = _d.next()) { try {
var ball = _e.value; for (var _d = __values(this.ballList), _e = _d.next(); !_e.done; _e = _d.next()) {
var x0_1 = Math.abs(getX(body) - getX(ball)); var ball = _e.value;
var y0_1 = Math.abs(getY(body) - getY(ball)); var x0_1 = Math.abs(getX(body) - getX(ball));
var ballH = ball.getChildrenByName('pic')[0].getComponent(Transform).height; var y0_1 = Math.abs(getY(body) - getY(ball));
var x1_1 = width / 2 + ballH / 2; var ballT = ball.getComponent(Transform);
var y1_1 = height / 2 + ballH / 2; var ballH = ball.getChildrenByName('pic')[0].getComponent(Transform).height;
if (x0_1 < x1_1 && y0_1 < y1_1) { var x1_1 = width / 2 + ballH / 2 * ballT.scale.x;
this.removeBullet(body); var y1_1 = height / 2 + ballH / 2 * ballT.scale.x;
i--; if (x0_1 < x1_1 && y0_1 < y1_1) {
this.removeBullet(body);
i--;
if (ball.getComponent(BallItem).reduceScore() == 0) {
this.toRmoveBallList.push(ball);
}
}
} }
} }
} catch (e_1_1) { e_1 = { error: e_1_1 }; }
catch (e_1_1) { e_1 = { error: e_1_1 }; } finally {
finally { try {
try { if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
if (_e && !_e.done && (_a = _d.return)) _a.call(_d); }
finally { if (e_1) throw e_1.error; }
} }
finally { if (e_1) throw e_1.error; } }
catch (error) {
} }
} }
} }
} }
}; };
ScenePlay.prototype.removeBullet = function (body) { ScenePlay.prototype.removeBullet = function (body) {
console.log(this.bodys.length);
body.removeAllComponents(); body.removeAllComponents();
var index = this.bodys.indexOf(body); var index = this.bodys.indexOf(body);
if (index == -1) if (index == -1)
...@@ -7217,9 +7237,23 @@ ...@@ -7217,9 +7237,23 @@
this.entity.removeChild(body); this.entity.removeChild(body);
}; };
ScenePlay.prototype.onBallSplit = function (body) { ScenePlay.prototype.onBallSplit = function (body) {
var ball1 = this.getBallItem(100); var ball1 = this.createSmallBalls(body);
var ball2 = this.createSmallBalls(body);
setXY(ball1, getX(body), getY(body)); setXY(ball1, getX(body), getY(body));
ball1.getComponent(Body).velocityY = -45; setXY(ball2, getX(body), getY(body));
ball1.getComponent(Body).velocityY = -10;
ball1.getComponent(Body).velocityX = -5;
ball2.getComponent(Body).velocityY = -10;
ball2.getComponent(Body).velocityX = 5;
};
ScenePlay.prototype.createSmallBalls = function (parentBall) {
var ball = this.getBallItem(10);
var ballc = ball.getComponent(BallItem);
var tras = ball.getComponent(Transform);
tras.scale.x = 0.6;
tras.scale.y = 0.6;
ballc.isBig = false;
return ball;
}; };
ScenePlay.prototype.onCarCollideDrops = function (body) { ScenePlay.prototype.onCarCollideDrops = function (body) {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
...@@ -7262,7 +7296,7 @@ ...@@ -7262,7 +7296,7 @@
return __generator(this, function (_a) { return __generator(this, function (_a) {
switch (_a.label) { switch (_a.label) {
case 0: case 0:
ball = this.getBallItem(100); ball = this.getBallItem(20);
setXY(ball, -375, -400); setXY(ball, -375, -400);
body = ball.getComponent(Body); body = ball.getComponent(Body);
body.enabled = false; body.enabled = false;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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