Commit 28f9308b authored by wildfirecode's avatar wildfirecode

1

parent 42d0ce01
......@@ -6,10 +6,11 @@ import { TextRenderer } from 'scilla-components/src';
export default class BallItem extends Body {
score = 0;
scoreTxt: Entity;
isBig = true;
constructor() {
super();
this.gravity = gravityY;
this.rotationSpeed = 0.5 * 2;
this.rotationSpeed = 0.5;
}
onAwake() {
......@@ -22,6 +23,7 @@ export default class BallItem extends Body {
if (this.score < 0)
this.score = 0;
this.updateScoreTxt();
return this.score;
}
updateScoreTxt() {
......
......@@ -74,16 +74,28 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
super.onAwake();
this.ballList = [];
this.bodys = [];
this.toRmoveBallList = [];
}
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++) {
const body = this.bodys[i];
const { position } = body.getComponent(Transform);
const pic = body.getChildrenByName('pic')[0];
const { height, width } = pic.getComponent(Transform);
const r = height / 2;//刚体的半径
const { height, width, scale } = pic.getComponent(Transform);
const r = height / 2 * scale.y;//刚体的半径
if (position.y + r > GROUND_Y) {
position.y = GROUND_Y - r;
body.getComponent(Body).revertY();
......@@ -121,24 +133,36 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
i--;
} else {
//子弹和ball处理
// console.log(body.getComponent(Transform))
try {
for (const ball of this.ballList) {
const x0 = Math.abs(getX(body) - getX(ball));
const y0 = Math.abs(getY(body) - getY(ball));
const ballT = ball.getComponent(Transform);
const { height: ballH } = ball.getChildrenByName('pic')[0].getComponent(Transform);
const x1 = width / 2 + ballH / 2;
const y1 = height / 2 + ballH / 2;
const x1 = width / 2 + ballH / 2 * ballT.scale.x;
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) {
console.log(this.bodys.length)
// console.log(this.bodys.length)
body.removeAllComponents();
const index = this.bodys.indexOf(body);
if (index == -1) return;
......@@ -166,10 +190,24 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
onBallSplit(body: Entity) {
//球分裂
const ball1 = this.getBallItem(100);
// const ball2 = this.getBallItem();
const ball1 = this.createSmallBalls(body);
const ball2 = this.createSmallBalls(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) {
......@@ -187,7 +225,7 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
}
async createBigBall() {
const ball = this.getBallItem(100);
const ball = this.getBallItem(20);
setXY(ball, -375, -400);
const body = ball.getComponent(Body);
body.enabled = false;
......
export const gravityY= .7;
\ No newline at end of file
export const gravityY= .5;
\ No newline at end of file
......@@ -8,6 +8,7 @@ export const setY = (entity: Entity, y) => {
entity.getComponent(Transform).position.y = y;
}
export const getX = (entity: Entity) => {
// if(!entity.getComponent(Transform))debugger
return entity.getComponent(Transform).position.x
}
export const getY = (entity: Entity) => {
......
......@@ -7019,15 +7019,16 @@
return Body;
}(ScillaComponent));
var gravityY = .7;
var gravityY = .5;
var BallItem = (function (_super) {
__extends(BallItem, _super);
function BallItem() {
var _this = _super.call(this) || this;
_this.score = 0;
_this.isBig = true;
_this.gravity = gravityY;
_this.rotationSpeed = 0.5 * 2;
_this.rotationSpeed = 0.5;
return _this;
}
BallItem.prototype.onAwake = function () {
......@@ -7039,6 +7040,7 @@
if (this.score < 0)
this.score = 0;
this.updateScoreTxt();
return this.score;
};
BallItem.prototype.updateScoreTxt = function () {
var tr = this.scoreTxt.getComponent(TextRenderer);
......@@ -7125,15 +7127,26 @@
_super.prototype.onAwake.call(this);
this.ballList = [];
this.bodys = [];
this.toRmoveBallList = [];
};
ScenePlay.prototype.onUpdate = function () {
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++) {
var body = this.bodys[i];
var position = body.getComponent(Transform).position;
var pic = body.getChildrenByName('pic')[0];
var _b = pic.getComponent(Transform), height = _b.height, width = _b.width;
var r = height / 2;
var _b = pic.getComponent(Transform), height = _b.height, width = _b.width, scale = _b.scale;
var r = height / 2 * scale.y;
if (position.y + r > GROUND_Y) {
position.y = GROUND_Y - r;
body.getComponent(Body).revertY();
......@@ -7165,17 +7178,22 @@
i--;
}
else {
try {
try {
for (var _d = __values(this.ballList), _e = _d.next(); !_e.done; _e = _d.next()) {
var ball = _e.value;
var x0_1 = Math.abs(getX(body) - getX(ball));
var y0_1 = Math.abs(getY(body) - getY(ball));
var ballT = ball.getComponent(Transform);
var ballH = ball.getChildrenByName('pic')[0].getComponent(Transform).height;
var x1_1 = width / 2 + ballH / 2;
var y1_1 = height / 2 + ballH / 2;
var x1_1 = width / 2 + ballH / 2 * ballT.scale.x;
var y1_1 = height / 2 + ballH / 2 * ballT.scale.x;
if (x0_1 < x1_1 && y0_1 < y1_1) {
this.removeBullet(body);
i--;
if (ball.getComponent(BallItem).reduceScore() == 0) {
this.toRmoveBallList.push(ball);
}
}
}
}
......@@ -7187,11 +7205,13 @@
finally { if (e_1) throw e_1.error; }
}
}
catch (error) {
}
}
}
}
};
ScenePlay.prototype.removeBullet = function (body) {
console.log(this.bodys.length);
body.removeAllComponents();
var index = this.bodys.indexOf(body);
if (index == -1)
......@@ -7217,9 +7237,23 @@
this.entity.removeChild(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));
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) {
return __awaiter(this, void 0, void 0, function () {
......@@ -7262,7 +7296,7 @@
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
ball = this.getBallItem(100);
ball = this.getBallItem(20);
setXY(ball, -375, -400);
body = ball.getComponent(Body);
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