Commit 87ed75e2 authored by wildfirecode's avatar wildfirecode

1

parent f6ab2664
File added
......@@ -4,15 +4,19 @@ import { gravityY } from './gameconst';
export default class Body extends ScillaComponent {
bounceY = 0;
private _velocityY = 0;
velocityY = 0;
velocityX = 0;
onUpdate() {
const { entity } = this;
this._velocityY += gravityY;
entity.getComponent(Transform).position.y += this._velocityY;
this.velocityY += gravityY;
entity.getComponent(Transform).position.y += this.velocityY;
entity.getComponent(Transform).position.x += this.velocityX;
}
revertY() {
this._velocityY *= -1 * this.bounceY;
console.log(this._velocityY)
this.velocityY *= -1 * this.bounceY;
}
revertX() {
this.velocityX*= -1 * this.bounceY;
}
}
\ No newline at end of file
import Body from './Body';
import ScillaComponent from 'scilla-components/src/base/ScillaComponent';
export default class RedFireItem extends ScillaComponent {
constructor() {
super();
}
export default class RedFireItem extends Body {
}
\ No newline at end of file
......@@ -7,43 +7,49 @@ import ScillaComponent from 'scilla-components/src/base/ScillaComponent';
import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import BallItem from './BallItem';
import RedFireItem from './RedFireItem';
import Body from './Body';
const GROUND_Y = 250; //碰到地板时,球的中心点的y
export default class ScenePlay extends ScillaComponent implements INavigatorViewBase {
BallItemPrefab: resource;
RedFirePrefab: resource;
bulletNumTxt: Entity;
strengthNumTxt: Entity;
ballList: Entity[];
redFireList: Entity[];
// ballList: Entity[];
// redFireList: Entity[];
bodys: Entity[];
getRedFireItem() {
const redFire = instantiate(this.RedFirePrefab);
this.entity.addChild(redFire);
this.redFireList.push(redFire);
// (redFire.getComponent(RedFireItem) as RedFireItem).bounceY = 0.9;
this.bodys.push(redFire);
// this.redFireList.push(redFire);
redFire.getComponent(RedFireItem).bounceY = 0.9;
// redFire.getComponent(RedFireItem).
}
getBallItem() {
const ball = instantiate(this.BallItemPrefab);
this.entity.addChild(ball);
this.ballList.push(ball);
console.log(ball.getComponent(Transform).position.y);
(ball.getComponent(BallItem) as BallItem).bounceY = 1;
// this.ballList.push(ball);
this.bodys.push(ball);
ball.getComponent(BallItem).bounceY = 1;
}
onAwake() {
super.onAwake();
this.ballList = [];
// this.ballList = [];
this.bodys = [];
}
onUpdate() {
for (const ball of this.ballList) {
const { position } = ball.getComponent(Transform);
for (const body of this.bodys) {
const { position } = body.getComponent(Transform);
if (position.y > GROUND_Y) {
position.y = GROUND_Y;
(ball.getComponent(BallItem) as BallItem).revertY();
body.getComponent(Body).revertY();
}
}
}
......
......@@ -7090,17 +7090,21 @@
function Body() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.bounceY = 0;
_this._velocityY = 0;
_this.velocityY = 0;
_this.velocityX = 0;
return _this;
}
Body.prototype.onUpdate = function () {
var entity = this.entity;
this._velocityY += gravityY;
entity.getComponent(Transform).position.y += this._velocityY;
this.velocityY += gravityY;
entity.getComponent(Transform).position.y += this.velocityY;
entity.getComponent(Transform).position.x += this.velocityX;
};
Body.prototype.revertY = function () {
this._velocityY *= -1 * this.bounceY;
console.log(this._velocityY);
this.velocityY *= -1 * this.bounceY;
};
Body.prototype.revertX = function () {
this.velocityX *= -1 * this.bounceY;
};
return Body;
}(ScillaComponent));
......@@ -7113,6 +7117,14 @@
return BallItem;
}(Body));
var RedFireItem = (function (_super) {
__extends(RedFireItem, _super);
function RedFireItem() {
return _super !== null && _super.apply(this, arguments) || this;
}
return RedFireItem;
}(Body));
var GROUND_Y = 250;
var ScenePlay = (function (_super) {
__extends(ScenePlay, _super);
......@@ -7122,28 +7134,28 @@
ScenePlay.prototype.getRedFireItem = function () {
var redFire = instantiate(this.RedFirePrefab);
this.entity.addChild(redFire);
this.redFireList.push(redFire);
this.bodys.push(redFire);
redFire.getComponent(RedFireItem).bounceY = 0.9;
};
ScenePlay.prototype.getBallItem = function () {
var ball = instantiate(this.BallItemPrefab);
this.entity.addChild(ball);
this.ballList.push(ball);
console.log(ball.getComponent(Transform).position.y);
this.bodys.push(ball);
ball.getComponent(BallItem).bounceY = 1;
};
ScenePlay.prototype.onAwake = function () {
_super.prototype.onAwake.call(this);
this.ballList = [];
this.bodys = [];
};
ScenePlay.prototype.onUpdate = function () {
var e_1, _a;
try {
for (var _b = __values(this.ballList), _c = _b.next(); !_c.done; _c = _b.next()) {
var ball = _c.value;
var position = ball.getComponent(Transform).position;
for (var _b = __values(this.bodys), _c = _b.next(); !_c.done; _c = _b.next()) {
var body = _c.value;
var position = body.getComponent(Transform).position;
if (position.y > GROUND_Y) {
position.y = GROUND_Y;
ball.getComponent(BallItem).revertY();
body.getComponent(Body).revertY();
}
}
}
......@@ -7445,14 +7457,6 @@
return testC;
}(ScillaComponent));
var RedFireItem = (function (_super) {
__extends(RedFireItem, _super);
function RedFireItem() {
return _super.call(this) || this;
}
return RedFireItem;
}(ScillaComponent));
registerDef('components/animation/TouchZoom', TouchZoom);
registerDef('components/base/Transform', Transform);
registerDef('components/renderer/RectRenderer', RectRenderer);
......
This diff is collapsed.
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