Commit 87ed75e2 authored by wildfirecode's avatar wildfirecode

1

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