Commit 0dca725c authored by wildfirecode's avatar wildfirecode

1

parent 1e3632af
...@@ -3,14 +3,24 @@ import { Transform } from 'scilla-components/src'; ...@@ -3,14 +3,24 @@ import { Transform } from 'scilla-components/src';
import { gravityY } from './gameconst'; import { gravityY } from './gameconst';
export default class BallItem extends ScillaComponent { export default class BallItem extends ScillaComponent {
private _speedY = 0; private _bounceY = 0;
private _velocityY = 0;
onUpdate() { onUpdate() {
const { entity } = this; const { entity } = this;
this._speedY += gravityY; this._velocityY += gravityY;
entity.getComponent(Transform).position.y += this._speedY; entity.getComponent(Transform).position.y += this._velocityY;
} }
bounceY(){ revertY() {
this._speedY *= -1; this._velocityY *= -1 * this._bounceY;
console.log(this._velocityY)
}
set bounceY(val: number) {
this._bounceY = val;
}
get bounceY() {
return this._bounceY;
} }
} }
\ No newline at end of file
...@@ -23,6 +23,7 @@ export default class ScenePlay extends ScillaComponent implements INavigatorView ...@@ -23,6 +23,7 @@ export default class ScenePlay extends ScillaComponent implements INavigatorView
this.entity.addChild(ball); this.entity.addChild(ball);
this.ballList.push(ball); this.ballList.push(ball);
console.log(ball.getComponent(Transform).position.y); console.log(ball.getComponent(Transform).position.y);
(ball.getComponent(BallItem) as BallItem).bounceY = 0.99;
} }
onAwake() { onAwake() {
...@@ -33,10 +34,9 @@ export default class ScenePlay extends ScillaComponent implements INavigatorView ...@@ -33,10 +34,9 @@ export default class ScenePlay extends ScillaComponent implements INavigatorView
onUpdate() { onUpdate() {
for (const ball of this.ballList) { for (const ball of this.ballList) {
const { position } = ball.getComponent(Transform); const { position } = ball.getComponent(Transform);
console.log(position.y)
if (position.y > GROUND_Y) { if (position.y > GROUND_Y) {
position.y = GROUND_Y; position.y = GROUND_Y;
(ball.getComponent(BallItem) as BallItem).bounceY(); (ball.getComponent(BallItem) as BallItem).revertY();
} }
} }
} }
......
{"ver":"1.0.1","uuid":"157cb7f7-3398-47d4-ade4-59d4de30f839","subMetas":{},"type":"script"}
...@@ -349,33 +349,33 @@ ...@@ -349,33 +349,33 @@
return false; return false;
}; };
Component.prototype.broadcast = function (method, level) { Component.prototype.broadcast = function (method, level) {
var _a;
if (level === void 0) { level = -1; } if (level === void 0) { level = -1; }
var params = []; var params = [];
for (var _i = 2; _i < arguments.length; _i++) { for (var _i = 2; _i < arguments.length; _i++) {
params[_i - 2] = arguments[_i]; params[_i - 2] = arguments[_i];
} }
var _a;
(_a = this.entity).broadcast.apply(_a, __spread([method, level], params)); (_a = this.entity).broadcast.apply(_a, __spread([method, level], params));
}; };
Component.prototype.bubbling = function (method) { Component.prototype.bubbling = function (method) {
var _a;
var params = []; var params = [];
for (var _i = 1; _i < arguments.length; _i++) { for (var _i = 1; _i < arguments.length; _i++) {
params[_i - 1] = arguments[_i]; params[_i - 1] = arguments[_i];
} }
var _a;
(_a = this.entity).bubbling.apply(_a, __spread([method], params)); (_a = this.entity).bubbling.apply(_a, __spread([method], params));
}; };
return Component; return Component;
}(HashObject)); }(HashObject));
function traverse(target, hitChild, level, includeSelf, fullCallback) { function traverse(target, hitChild, level, includeSelf, fullCallback) {
var e_1, _a;
if (level === void 0) { level = -1; } if (level === void 0) { level = -1; }
if (includeSelf === void 0) { includeSelf = false; } if (includeSelf === void 0) { includeSelf = false; }
var params = []; var params = [];
for (var _i = 5; _i < arguments.length; _i++) { for (var _i = 5; _i < arguments.length; _i++) {
params[_i - 5] = arguments[_i]; params[_i - 5] = arguments[_i];
} }
var e_1, _a;
if (includeSelf) { if (includeSelf) {
hitChild.apply(void 0, __spread([target], params)); hitChild.apply(void 0, __spread([target], params));
} }
...@@ -2093,11 +2093,11 @@ ...@@ -2093,11 +2093,11 @@
return !!this.findListener(callback); return !!this.findListener(callback);
}; };
ScillaEvent.prototype.invoke = function () { ScillaEvent.prototype.invoke = function () {
var e_1, _a;
var paramsNew = []; var paramsNew = [];
for (var _i = 0; _i < arguments.length; _i++) { for (var _i = 0; _i < arguments.length; _i++) {
paramsNew[_i] = arguments[_i]; paramsNew[_i] = arguments[_i];
} }
var e_1, _a;
var _subscribers = this._subscribers; var _subscribers = this._subscribers;
_subscribers.sort(function (a, b) { _subscribers.sort(function (a, b) {
return a.priority - b.priority; return a.priority - b.priority;
...@@ -2516,8 +2516,8 @@ ...@@ -2516,8 +2516,8 @@
return begin + distance * t * sign; return begin + distance * t * sign;
} }
function lerpObj(begin, end, t, fields, allowOutOfBounds) { function lerpObj(begin, end, t, fields, allowOutOfBounds) {
if (allowOutOfBounds === void 0) { allowOutOfBounds = false; }
var e_1, _a; var e_1, _a;
if (allowOutOfBounds === void 0) { allowOutOfBounds = false; }
var type = typeof begin; var type = typeof begin;
if (type !== typeof end) { if (type !== typeof end) {
console.error('begin and end need same type'); console.error('begin and end need same type');
...@@ -7089,17 +7089,29 @@ ...@@ -7089,17 +7089,29 @@
__extends(BallItem, _super); __extends(BallItem, _super);
function BallItem() { function BallItem() {
var _this = _super !== null && _super.apply(this, arguments) || this; var _this = _super !== null && _super.apply(this, arguments) || this;
_this._speedY = 0; _this._bounceY = 0;
_this._velocityY = 0;
return _this; return _this;
} }
BallItem.prototype.onUpdate = function () { BallItem.prototype.onUpdate = function () {
var entity = this.entity; var entity = this.entity;
this._speedY += gravityY; this._velocityY += gravityY;
entity.getComponent(Transform).position.y += this._speedY; entity.getComponent(Transform).position.y += this._velocityY;
}; };
BallItem.prototype.bounceY = function () { BallItem.prototype.revertY = function () {
this._speedY *= -1; this._velocityY *= -1 * this._bounceY;
console.log(this._velocityY);
}; };
Object.defineProperty(BallItem.prototype, "bounceY", {
get: function () {
return this._bounceY;
},
set: function (val) {
this._bounceY = val;
},
enumerable: true,
configurable: true
});
return BallItem; return BallItem;
}(ScillaComponent)); }(ScillaComponent));
...@@ -7114,6 +7126,7 @@ ...@@ -7114,6 +7126,7 @@
this.entity.addChild(ball); this.entity.addChild(ball);
this.ballList.push(ball); this.ballList.push(ball);
console.log(ball.getComponent(Transform).position.y); console.log(ball.getComponent(Transform).position.y);
ball.getComponent(BallItem).bounceY = 0.99;
}; };
ScenePlay.prototype.onAwake = function () { ScenePlay.prototype.onAwake = function () {
_super.prototype.onAwake.call(this); _super.prototype.onAwake.call(this);
...@@ -7125,10 +7138,9 @@ ...@@ -7125,10 +7138,9 @@
for (var _b = __values(this.ballList), _c = _b.next(); !_c.done; _c = _b.next()) { for (var _b = __values(this.ballList), _c = _b.next(); !_c.done; _c = _b.next()) {
var ball = _c.value; var ball = _c.value;
var position = ball.getComponent(Transform).position; var position = ball.getComponent(Transform).position;
console.log(position.y);
if (position.y > GROUND_Y) { if (position.y > GROUND_Y) {
position.y = GROUND_Y; position.y = GROUND_Y;
ball.getComponent(BallItem).bounceY(); ball.getComponent(BallItem).revertY();
} }
} }
} }
......
This diff is collapsed.
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
* Created by rockyl on 2019-04-17. * Created by rockyl on 2019-04-17.
*/ */
import { Component } from 'scilla' import {Component} from 'scilla'
import Transform from "./Transform"; import Transform from "./Transform";
export default class ScillaComponent extends Component { export default class ScillaComponent extends Component{
get transform(): Transform { get transform():Transform {
return this.entity.getComponentByName('components/base/Transform'); return this.entity.getComponentByName('components/base/Transform');
} }
} }
import {registerDef} from "scilla" import {registerDef} from "scilla"
import ScillaComponent from './base/ScillaComponent';
import BounceZoom from './animation/BounceZoom'; import BounceZoom from './animation/BounceZoom';
import Fade from './animation/Fade'; import Fade from './animation/Fade';
import Rotation from './animation/Rotation'; import Rotation from './animation/Rotation';
...@@ -10,6 +9,7 @@ import TouchZoom from './animation/TouchZoom'; ...@@ -10,6 +9,7 @@ import TouchZoom from './animation/TouchZoom';
import Wave from './animation/Wave'; import Wave from './animation/Wave';
import ZoomLoop from './animation/ZoomLoop'; import ZoomLoop from './animation/ZoomLoop';
import InteractComponent from './base/InteractComponent'; import InteractComponent from './base/InteractComponent';
import ScillaComponent from './base/ScillaComponent';
import TouchInterrupt from './base/TouchInterrupt'; import TouchInterrupt from './base/TouchInterrupt';
import Transform from './base/Transform'; import Transform from './base/Transform';
import AjaxElementComponent from './net/api/hdtool/base/AjaxElementComponent'; import AjaxElementComponent from './net/api/hdtool/base/AjaxElementComponent';
......
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