Commit 0dca725c authored by wildfirecode's avatar wildfirecode

1

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