Commit 1e3632af authored by wildfirecode's avatar wildfirecode

1

parent bbbdbae3
{
"name": "test",
"root": {
"uuid": "20190301114308",
components: [
{
"script": "components/base/Transform"
},
{
"script": "components/other/CameraController"
},
],
"children": [
{
"uuid": "20190301114245",
"name": "test",
"components": [
{
"script": "components/base/Transform",
"properties": {}
},
]
}
]
},
"entity-cache": []
}
\ No newline at end of file
{"ver":"1.0.1","uuid":"07c47af5-c5fc-4d7f-ad55-b30a06453b34","subMetas":{},"type":"prefab"}
import ScillaComponent from 'components/base/ScillaComponent'; import ScillaComponent from 'components/base/ScillaComponent';
import { Transform } from 'scilla-components/src'; import { Transform } from 'scilla-components/src';
import { gravityY } from './gameconst';
export default class BallItem extends ScillaComponent { export default class BallItem extends ScillaComponent {
private _speed = 0; private _speedY = 0;
onUpdate() { onUpdate() {
const { entity } = this; const { entity } = this;
this._speed += 1.5; this._speedY += gravityY;
entity.getComponent(Transform).position.y += this._speed; entity.getComponent(Transform).position.y += this._speedY;
console.log('BallItem onUpdate') }
bounceY(){
this._speedY *= -1;
} }
} }
\ No newline at end of file
...@@ -7,6 +7,7 @@ import { alien } from "../navigator/StackNavigator"; ...@@ -7,6 +7,7 @@ import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator"; import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { Transform } from 'scilla-components/src'; import { Transform } from 'scilla-components/src';
import ScillaComponent from 'scilla-components/src/base/ScillaComponent'; import ScillaComponent from 'scilla-components/src/base/ScillaComponent';
import BallItem from './BallItem';
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 {
...@@ -30,14 +31,14 @@ export default class ScenePlay extends ScillaComponent implements INavigatorView ...@@ -30,14 +31,14 @@ export default class ScenePlay extends ScillaComponent implements INavigatorView
} }
onUpdate() { onUpdate() {
// for (const ball of this.ballList) { for (const ball of this.ballList) {
// ball.getComponent(Transform).position.y += 1; const { position } = ball.getComponent(Transform);
// const y = ball.getComponent(Transform).position.y; console.log(position.y)
// console.log(ball.getComponent(Transform).position.y); if (position.y > GROUND_Y) {
// if (y > GROUND_Y) { position.y = GROUND_Y;
(ball.getComponent(BallItem) as BallItem).bounceY();
// } }
// } }
} }
onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void { onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void {
......
export const gravityY= 1.5;
\ No newline at end of file
...@@ -7083,6 +7083,27 @@ ...@@ -7083,6 +7083,27 @@
return Popup; return Popup;
}(Component)); }(Component));
var gravityY = 1.5;
var BallItem = (function (_super) {
__extends(BallItem, _super);
function BallItem() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._speedY = 0;
return _this;
}
BallItem.prototype.onUpdate = function () {
var entity = this.entity;
this._speedY += gravityY;
entity.getComponent(Transform).position.y += this._speedY;
};
BallItem.prototype.bounceY = function () {
this._speedY *= -1;
};
return BallItem;
}(ScillaComponent));
var GROUND_Y = 250;
var ScenePlay = (function (_super) { var ScenePlay = (function (_super) {
__extends(ScenePlay, _super); __extends(ScenePlay, _super);
function ScenePlay() { function ScenePlay() {
...@@ -7099,6 +7120,25 @@ ...@@ -7099,6 +7120,25 @@
this.ballList = []; this.ballList = [];
}; };
ScenePlay.prototype.onUpdate = function () { 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;
console.log(position.y);
if (position.y > GROUND_Y) {
position.y = GROUND_Y;
ball.getComponent(BallItem).bounceY();
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
}; };
ScenePlay.prototype.onDidEnter = function (last, action, parameters) { ScenePlay.prototype.onDidEnter = function (last, action, parameters) {
this.entity.getComponent(Transform).alpha = 1; this.entity.getComponent(Transform).alpha = 1;
...@@ -7389,7 +7429,8 @@ ...@@ -7389,7 +7429,8 @@
registerDef('./scripts/popup/Popup', Popup); registerDef('./scripts/popup/Popup', Popup);
registerDef('./scripts/scenes/ScenePlay', ScenePlay); registerDef('./scripts/scenes/ScenePlay', ScenePlay);
registerDef('./scripts/navigator/SingleSceneNavigator', SingleSceneNavigator); registerDef('./scripts/navigator/SingleSceneNavigator', SingleSceneNavigator);
registerDef('./scripts/dialogs/RulePanel', RulePanel); registerDef('./scripts/dialogs/RulePanel', RulePanel);
registerDef('./scripts/scenes/BallItem', BallItem);
modifyEngineConfig({ modifyEngineConfig({
lineHeightRatio: 1.2, lineHeightRatio: 1.2,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -49,3 +49,6 @@ registerDef('./scripts/navigator/SingleSceneNavigator', component13); ...@@ -49,3 +49,6 @@ registerDef('./scripts/navigator/SingleSceneNavigator', component13);
import component14 from '../../assets/scripts/dialogs/RulePanel'; import component14 from '../../assets/scripts/dialogs/RulePanel';
registerDef('./scripts/dialogs/RulePanel', component14); registerDef('./scripts/dialogs/RulePanel', component14);
import component15 from '../../assets/scripts/scenes/BallItem';
registerDef('./scripts/scenes/BallItem', component15);
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