Commit 42d0ce01 authored by wildfirecode's avatar wildfirecode

1

parent 96b63c4f
{"currentScene":"assets/prefabs/BallItem.pfb"}
\ No newline at end of file
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
}, },
{ {
"script": "./scripts/scenes/BallItem", "script": "./scripts/scenes/BallItem",
"properties": {} "properties": {
"scoreTxt": "entity|8abfc716-7017-4834-a7fa-5ca6c2ce4b3e"
}
} }
], ],
"children": [ "children": [
...@@ -42,7 +44,7 @@ ...@@ -42,7 +44,7 @@
"uuid": "fb53fa37-a942-4474-901a-582dccd14c93" "uuid": "fb53fa37-a942-4474-901a-582dccd14c93"
}, },
{ {
"name": "Label", "name": "txt",
"components": [ "components": [
{ {
"script": "components/base/Transform", "script": "components/base/Transform",
...@@ -54,7 +56,7 @@ ...@@ -54,7 +56,7 @@
"text": "1111", "text": "1111",
"fillColor": "rgba(255, 255, 255, 1)", "fillColor": "rgba(255, 255, 255, 1)",
"textStyle": { "textStyle": {
"fontSize": 40 "fontSize": 100
} }
} }
} }
...@@ -65,5 +67,7 @@ ...@@ -65,5 +67,7 @@
} }
] ]
}, },
"entity-cache": [] "entity-cache": [
"8abfc716-7017-4834-a7fa-5ca6c2ce4b3e"
]
} }
\ No newline at end of file
{
"name": "bullet",
"root": {
"uuid": "20190301114308",
"components": [
{
"script": "components/base/Transform"
},
{
"script": "components/other/CameraController"
}
],
"children": [
{
"uuid": "20190301114245",
"name": "bullet",
"components": [
{
"script": "components/base/Transform",
"properties": {}
},
{
"script": "./scripts/scenes/BulletItem",
"properties": {}
}
],
"children": [
{
"name": "pic",
"components": [
{
"script": "components/base/Transform",
"properties": {}
},
{
"script": "components/renderer/TextureRenderer",
"properties": {
"texture": "res|31e8f381-78e1-4972-9271-d05a927dda6a"
}
}
],
"uuid": "bd27ee5e-6f76-49cb-8e10-5ae807e0d000"
}
]
}
]
},
"entity-cache": []
}
\ No newline at end of file
{"ver":"1.0.1","uuid":"2d853f74-b511-4edf-9bbd-ac02ae1fc075","subMetas":{},"type":"prefab"}
...@@ -67,7 +67,8 @@ ...@@ -67,7 +67,8 @@
"BallItemPrefab": "res|8ebdfe78-ea44-445d-8bbe-02a22874e896", "BallItemPrefab": "res|8ebdfe78-ea44-445d-8bbe-02a22874e896",
"RedFirePrefab": "res|83d50df9-266c-478f-bf01-21d478abe049", "RedFirePrefab": "res|83d50df9-266c-478f-bf01-21d478abe049",
"BlueRocketPrefab": "res|9a8fe57a-ff20-44e7-89bf-cdc95e80e1ea", "BlueRocketPrefab": "res|9a8fe57a-ff20-44e7-89bf-cdc95e80e1ea",
"car": "entity|ebfde024-e9b9-40cb-a866-c0b194446b35" "car": "entity|ebfde024-e9b9-40cb-a866-c0b194446b35",
"BulletItemPrefab": "res|2d853f74-b511-4edf-9bbd-ac02ae1fc075"
} }
} }
], ],
...@@ -220,7 +221,7 @@ ...@@ -220,7 +221,7 @@
"script": "components/base/Transform", "script": "components/base/Transform",
"properties": { "properties": {
"position": { "position": {
"x": 2.5, "x": -207.5,
"y": 340, "y": 340,
"_type_": "scilla/support/Vector2D" "_type_": "scilla/support/Vector2D"
} }
...@@ -732,6 +733,10 @@ ...@@ -732,6 +733,10 @@
"uuid": "9a8fe57a-ff20-44e7-89bf-cdc95e80e1ea", "uuid": "9a8fe57a-ff20-44e7-89bf-cdc95e80e1ea",
"url": "prefabs/BlueRocket.pfb" "url": "prefabs/BlueRocket.pfb"
}, },
{
"uuid": "2d853f74-b511-4edf-9bbd-ac02ae1fc075",
"url": "prefabs/bullet.pfb"
},
{ {
"uuid": "83d50df9-266c-478f-bf01-21d478abe049", "uuid": "83d50df9-266c-478f-bf01-21d478abe049",
"url": "prefabs/RedFire.pfb" "url": "prefabs/RedFire.pfb"
...@@ -796,6 +801,10 @@ ...@@ -796,6 +801,10 @@
{ {
"name": "red20.png", "name": "red20.png",
"uuid": "1dd2cb82-b58a-49d5-9e87-a585b1d44d2d" "uuid": "1dd2cb82-b58a-49d5-9e87-a585b1d44d2d"
},
{
"name": "子弹-1.png",
"uuid": "31e8f381-78e1-4972-9271-d05a927dda6a"
} }
] ]
} }
......
{"ver":"1.0.1","uuid":"993ff88e-547e-4a0f-90ed-d7e49dc86ae7","subMetas":{},"type":"script"}
import Body from './Body'; import Body from './Body';
import { gravityY } from './gameconst';
import { Entity } from 'scilla/src';
import { TextRenderer } from 'scilla-components/src';
export default class BallItem extends Body { export default class BallItem extends Body {
score = 0;
scoreTxt: Entity;
constructor() {
super();
this.gravity = gravityY;
this.rotationSpeed = 0.5 * 2;
}
onAwake() {
super.onAwake();
this.updateScoreTxt();
}
reduceScore() {
this.score--;
if (this.score < 0)
this.score = 0;
this.updateScoreTxt();
}
updateScoreTxt() {
const tr = this.scoreTxt.getComponent(TextRenderer);
tr.text = this.score.toString();
}
} }
\ No newline at end of file
import Body from './Body'; import Body from './Body';
import { gravityY } from './gameconst';
export default class BlueRocketItem extends Body { export default class BlueRocketItem extends Body {
constructor() { constructor() {
super(); super();
this.gravity = gravityY;
this.bounceY = 0.9; this.bounceY = 0.9;
} }
} }
\ No newline at end of file
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 Body extends ScillaComponent { export default class Body extends ScillaComponent {
bounceY = 1; bounceY = 1;
...@@ -8,12 +7,13 @@ export default class Body extends ScillaComponent { ...@@ -8,12 +7,13 @@ export default class Body extends ScillaComponent {
velocityY = 0; velocityY = 0;
velocityX = 0; velocityX = 0;
rotationSpeed = 0.5; rotationSpeed = 0.5;
gravity=0;
private _counter = 0; private _counter = 0;
onUpdate() { onUpdate() {
this._counter++; this._counter++;
const { entity } = this; const { entity } = this;
this.velocityY += gravityY; this.velocityY += this.gravity;
entity.getComponent(Transform).position.y += this.velocityY; entity.getComponent(Transform).position.y += this.velocityY;
entity.getComponent(Transform).position.x += this.velocityX; entity.getComponent(Transform).position.x += this.velocityX;
// console.log(entity.getComponent(Transform).position.y) // console.log(entity.getComponent(Transform).position.y)
......
import Body from './Body';
export default class BulletItem extends Body {
constructor() {
super();
this.gravity = 0;
this.velocityY = -10;
this.rotationSpeed= 0;
}
}
\ No newline at end of file
{"ver":"1.0.1","uuid":"34860dfb-2353-4c40-8fd5-e3b42c7a18c7","subMetas":{},"type":"script"}
import Body from './Body'; import Body from './Body';
import { gravityY } from './gameconst';
export default class RedFireItem extends Body { export default class RedFireItem extends Body {
constructor() { constructor() {
super(); super();
this.gravity = gravityY;
this.bounceY = 0.9; this.bounceY = 0.9;
} }
} }
\ No newline at end of file
...@@ -2,36 +2,39 @@ ...@@ -2,36 +2,39 @@
* Created by rockyl on 2019-04-09. * Created by rockyl on 2019-04-09.
*/ */
import InteractComponent from 'components/base/InteractComponent'; import InteractComponent from 'components/base/InteractComponent';
import { createTween, Entity, instantiate, resource, Ease } from "scilla"; import { Entity, instantiate, resource } from "scilla";
import { Transform } from 'scilla-components/src'; import { Transform } from 'scilla-components/src';
import { getTween } from '../getTween';
import { alien } from "../navigator/StackNavigator"; import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator"; import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { getX, getY, setXY, setX } from '../transform';
import BallItem from './BallItem';
import BlueRocketItem from './BlueRocketItem'; import BlueRocketItem from './BlueRocketItem';
import Body from './Body'; import Body from './Body';
import BulletItem from './BulletItem';
import RedFireItem from './RedFireItem'; import RedFireItem from './RedFireItem';
import { getTween } from '../getTween';
import BallItem from './BallItem';
const GROUND_Y = 350 + 40; //碰到地板时,球的中心点的y const GROUND_Y = 350 + 40; //碰到地板时,球的中心点的y
export default class ScenePlay extends InteractComponent implements INavigatorViewBase { export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
BallItemPrefab: resource; BallItemPrefab: resource;
BulletItemPrefab: resource;
RedFirePrefab: resource; RedFirePrefab: resource;
BlueRocketPrefab: resource; BlueRocketPrefab: resource;
bulletNumTxt: Entity; bulletNumTxt: Entity;
strengthNumTxt: Entity; strengthNumTxt: Entity;
car: Entity; car: Entity;
// ballList: Entity[]; ballList: Entity[];
// redFireList: Entity[]; // redFireList: Entity[];
bodys: Entity[]; bodys: Entity[];
onGlobalTouchBegin(e): any { onGlobalTouchBegin(e): any {
this.car.getComponent(Transform).position.x = e.x - 375; setX(this.car, e.x - 375);
return super.onGlobalTouchBegin(e); return super.onGlobalTouchBegin(e);
} }
onGlobalTouchMove(e: { x, y }) { onGlobalTouchMove(e: { x, y }) {
this.car.getComponent(Transform).position.x = e.x - 375; setX(this.car, e.x - 375);
return super.onGlobalTouchMove(e); return super.onGlobalTouchMove(e);
} }
...@@ -51,28 +54,36 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi ...@@ -51,28 +54,36 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
item.getComponent(BlueRocketItem).velocityX = 1; item.getComponent(BlueRocketItem).velocityX = 1;
} }
getBallItem() { getBallItem(score: number) {
const ball = instantiate(this.BallItemPrefab); const ball = instantiate(this.BallItemPrefab);
ball.getComponent(Transform).position.y = -300; ball.getComponent(BallItem).score = score;
this.bodys.push(ball); this.bodys.push(ball);
this.entity.addChild(ball); this.entity.addChild(ball);
// this.ballList.push(ball); this.ballList.push(ball);
return ball;
}
createBullet() {
const item = instantiate(this.BulletItemPrefab);
this.entity.addChild(item);
this.bodys.push(item);
setXY(item, getX(this.car), getY(this.car) - 100);
} }
onAwake() { onAwake() {
super.onAwake(); super.onAwake();
// this.ballList = []; this.ballList = [];
this.bodys = []; this.bodys = [];
} }
onUpdate() { onUpdate() {
for (const body of this.bodys) { //所有的刚体检查,包括子弹、掉落
for (let i = 0; i < this.bodys.length; i++) {
const body = this.bodys[i];
const { position } = body.getComponent(Transform); const { position } = body.getComponent(Transform);
const pic = body.getChildrenByName('pic')[0]; const pic = body.getChildrenByName('pic')[0];
const { height, width } = pic.getComponent(Transform); const { height, width } = pic.getComponent(Transform);
const r = height / 2;//刚体的半径 const r = height / 2;//刚体的半径
// console.log(position.x);
// console.log(position.y + r)
if (position.y + r > GROUND_Y) { if (position.y + r > GROUND_Y) {
position.y = GROUND_Y - r; position.y = GROUND_Y - r;
body.getComponent(Body).revertY(); body.getComponent(Body).revertY();
...@@ -87,32 +98,80 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi ...@@ -87,32 +98,80 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
position.x = -375 + r; position.x = -375 + r;
body.getComponent(Body).revertX(); body.getComponent(Body).revertX();
} }
const { x: carX, y: carY } = this.car.getComponent(Transform).position; const { x: carX, y: carY } = this.car.getComponent(Transform).position;
//判断car与body的碰撞 //判断car与body的碰撞
const x0 = Math.abs(position.x - carX); const x0 = Math.abs(position.x - carX);
const y0 = Math.abs(position.y - carY); const y0 = Math.abs(position.y - carY);
const x1 = r + 120 / 2; const x1 = r + 120 / 2;
const y1 = r + 110 / 2; const y1 = r + 110 / 2;
const t = body.getComponent(Body);
if (x0 < x1 && y0 < y1) { if (x0 < x1 && y0 < y1) {
console.log('碰撞了'); console.log('碰撞了');
const t = body.getComponent(Body);
if (t instanceof BallItem) if (t instanceof BallItem)
this.onCarCollideBall(body); this.onCarCollideBall(body);
else else if (t instanceof BlueRocketItem || t instanceof RedFireItem)
this.onCarCollideDrops(body); this.onCarCollideDrops(body);
} }
//子弹处理
if (t instanceof BulletItem) {
if (position.y < -1624 / 2) { //子弹失效
this.removeBullet(body);
i--;
} else {
//子弹和ball处理
for (const ball of this.ballList) {
const x0 = Math.abs(getX(body) - getX(ball));
const y0 = Math.abs(getY(body) - getY(ball));
const { height: ballH } = ball.getChildrenByName('pic')[0].getComponent(Transform);
const x1 = width / 2 + ballH / 2;
const y1 = height / 2 + ballH / 2;
if (x0 < x1 && y0 < y1) { //子弹和球碰撞了
this.removeBullet(body);
i--;
}
}
}
}
} }
} }
removeBullet(body: Entity) {
console.log(this.bodys.length)
body.removeAllComponents();
const index = this.bodys.indexOf(body);
if (index == -1) return;
this.bodys.splice(index, 1);
this.entity.removeChild(body);
}
/** 车碰球 */ /** 车碰球 */
async onCarCollideBall(body: Entity) { async onCarCollideBall(body: Entity) {
this.removeBall(body);
console.log('on game over')
}
removeBall(body: Entity) {
const index = this.bodys.indexOf(body); const index = this.bodys.indexOf(body);
if (index == -1) return;
this.bodys.splice(index, 1); this.bodys.splice(index, 1);
const index2 = this.ballList.indexOf(body);
this.ballList.splice(index2, 1);
body.removeComponent(body.getComponent(Body)); body.removeComponent(body.getComponent(Body));
this.entity.removeChild(body); this.entity.removeChild(body);
} }
onBallSplit(body: Entity) {
//球分裂
const ball1 = this.getBallItem(100);
// const ball2 = this.getBallItem();
setXY(ball1, getX(body), getY(body));
ball1.getComponent(Body).velocityY = -45;
}
async onCarCollideDrops(body: Entity) { async onCarCollideDrops(body: Entity) {
const index = this.bodys.indexOf(body); const index = this.bodys.indexOf(body);
if (index == -1) return; if (index == -1) return;
...@@ -127,11 +186,26 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi ...@@ -127,11 +186,26 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
await getTween(this, transform, { y: transform.position.y - 200, alpha: 0 }, 1000); await getTween(this, transform, { y: transform.position.y - 200, alpha: 0 }, 1000);
} }
async createBigBall() {
const ball = this.getBallItem(100);
setXY(ball, -375, -400);
const body = ball.getComponent(Body);
body.enabled = false;
await getTween(this, ball.getComponent(Transform), { x: -375 + 200 }, 1000);
body.velocityX = 5;
body.enabled = true;
}
onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void { onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void {
(this.entity.getComponent(Transform) as Transform).alpha = 1; (this.entity.getComponent(Transform) as Transform).alpha = 1;
this.getBallItem();
this.getRedFireItem(); this.createBigBall();
this.getBlueRocketItem();
// this.getRedFireItem();
// this.getBlueRocketItem();
setInterval(() => { this.createBullet() }, 1000 / 15);
} }
onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void { onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void {
......
export const gravityY= 1.5; export const gravityY= .7;
\ No newline at end of file \ No newline at end of file
import { Entity } from 'scilla/src';
import { Transform } from 'scilla-components/src';
export const setX = (entity: Entity, x) => {
entity.getComponent(Transform).position.x = x;
}
export const setY = (entity: Entity, y) => {
entity.getComponent(Transform).position.y = y;
}
export const getX = (entity: Entity) => {
return entity.getComponent(Transform).position.x
}
export const getY = (entity: Entity) => {
return entity.getComponent(Transform).position.y;
}
export const setXY = (entity: Entity,x, y) => {
setX(entity,x);
setY(entity,y);
}
\ No newline at end of file
{"ver":"1.0.1","uuid":"b80459a5-8236-4358-8919-7fb88410a25b","subMetas":{},"type":"script"}
{"ver":"1.0.1","uuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","subMetas":{"火-1.png":{"ver":"1.0.1","uuid":"94680781-2b1b-432e-9858-4ff21dd04d0c","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"火箭-1.png":{"ver":"1.0.1","uuid":"2f8360c7-b059-4f1e-b651-37a32eb4a247","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"发弹雾气-1.png":{"ver":"1.0.1","uuid":"f67e2e09-e0f4-4aea-8243-8d86a4ded38a","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"1-1-1.png":{"ver":"1.0.1","uuid":"cb4651fa-3d76-43c6-89a9-d06ddda3c110","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"大炮板子-1.png":{"ver":"1.0.1","uuid":"abdded14-a2d2-4000-b264-9ff47c843149","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"大炮的头-1.png":{"ver":"1.0.1","uuid":"ade44f23-754d-4923-a713-76f4207c3bde","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"淡蓝-1.png":{"ver":"1.0.1","uuid":"2952264c-5a8b-4eda-9a15-812e4e7738ae","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"紫-1.png":{"ver":"1.0.1","uuid":"60460a1c-e1b6-45c6-a905-f1233ffd0853","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"红-1.png":{"ver":"1.0.1","uuid":"98d8e939-fbfb-46fa-9622-60164aa8aa4b","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"绿-1.png":{"ver":"1.0.1","uuid":"8babbf6b-a2a2-4fc0-a634-4268607cbf9c","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"蓝-1.png":{"ver":"1.0.1","uuid":"b664db72-fb4f-45fb-8f50-908f3d133bdc","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"黄-1.png":{"ver":"1.0.1","uuid":"4db8fa73-7721-42e3-bf6c-d4665dbbfe32","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"淡蓝火箭-1.png":{"ver":"1.0.1","uuid":"aa4bc010-fa6b-4194-8795-8321390f0ff4","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"red20.png":{"ver":"1.0.1","uuid":"1dd2cb82-b58a-49d5-9e87-a585b1d44d2d","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"}},"type":"sheet"} {"ver":"1.0.1","uuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","subMetas":{"火-1.png":{"ver":"1.0.1","uuid":"94680781-2b1b-432e-9858-4ff21dd04d0c","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"火箭-1.png":{"ver":"1.0.1","uuid":"2f8360c7-b059-4f1e-b651-37a32eb4a247","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"发弹雾气-1.png":{"ver":"1.0.1","uuid":"f67e2e09-e0f4-4aea-8243-8d86a4ded38a","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"1-1-1.png":{"ver":"1.0.1","uuid":"cb4651fa-3d76-43c6-89a9-d06ddda3c110","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"大炮板子-1.png":{"ver":"1.0.1","uuid":"abdded14-a2d2-4000-b264-9ff47c843149","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"大炮的头-1.png":{"ver":"1.0.1","uuid":"ade44f23-754d-4923-a713-76f4207c3bde","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"淡蓝-1.png":{"ver":"1.0.1","uuid":"2952264c-5a8b-4eda-9a15-812e4e7738ae","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"紫-1.png":{"ver":"1.0.1","uuid":"60460a1c-e1b6-45c6-a905-f1233ffd0853","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"红-1.png":{"ver":"1.0.1","uuid":"98d8e939-fbfb-46fa-9622-60164aa8aa4b","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"绿-1.png":{"ver":"1.0.1","uuid":"8babbf6b-a2a2-4fc0-a634-4268607cbf9c","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"蓝-1.png":{"ver":"1.0.1","uuid":"b664db72-fb4f-45fb-8f50-908f3d133bdc","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"黄-1.png":{"ver":"1.0.1","uuid":"4db8fa73-7721-42e3-bf6c-d4665dbbfe32","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"淡蓝火箭-1.png":{"ver":"1.0.1","uuid":"aa4bc010-fa6b-4194-8795-8321390f0ff4","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"red20.png":{"ver":"1.0.1","uuid":"1dd2cb82-b58a-49d5-9e87-a585b1d44d2d","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"},"子弹-1.png":{"ver":"1.0.1","uuid":"31e8f381-78e1-4972-9271-d05a927dda6a","rawTextureUuid":"e00fab97-a62c-459b-a61b-a9d7a1e10a21","type":"texture"}},"type":"sheet"}
...@@ -6958,7 +6958,36 @@ ...@@ -6958,7 +6958,36 @@
return ThroughSubmitComponent; return ThroughSubmitComponent;
}(SampleApi)); }(SampleApi));
var gravityY = 1.5; var getTween = function (context, target, obj, duration, ease$$1) {
return new Promise(function (r) {
var postionObj = {};
for (var key in obj) {
if (key == 'x' || key == 'y') {
postionObj[key] = obj[key];
delete obj[key];
}
}
createTween(context, target.position, true).to(postionObj, duration, ease$$1);
createTween(context, target, true).to(obj, duration, ease$$1).call(r);
});
};
var setX = function (entity, x) {
entity.getComponent(Transform).position.x = x;
};
var setY = function (entity, y) {
entity.getComponent(Transform).position.y = y;
};
var getX = function (entity) {
return entity.getComponent(Transform).position.x;
};
var getY = function (entity) {
return entity.getComponent(Transform).position.y;
};
var setXY = function (entity, x, y) {
setX(entity, x);
setY(entity, y);
};
var Body = (function (_super) { var Body = (function (_super) {
__extends(Body, _super); __extends(Body, _super);
...@@ -6969,13 +6998,14 @@ ...@@ -6969,13 +6998,14 @@
_this.velocityY = 0; _this.velocityY = 0;
_this.velocityX = 0; _this.velocityX = 0;
_this.rotationSpeed = 0.5; _this.rotationSpeed = 0.5;
_this.gravity = 0;
_this._counter = 0; _this._counter = 0;
return _this; return _this;
} }
Body.prototype.onUpdate = function () { Body.prototype.onUpdate = function () {
this._counter++; this._counter++;
var entity = this.entity; var entity = this.entity;
this.velocityY += gravityY; this.velocityY += this.gravity;
entity.getComponent(Transform).position.y += this.velocityY; entity.getComponent(Transform).position.y += this.velocityY;
entity.getComponent(Transform).position.x += this.velocityX; entity.getComponent(Transform).position.x += this.velocityX;
entity.getComponent(Transform).rotation = this._counter * .7 * this.rotationSpeed; entity.getComponent(Transform).rotation = this._counter * .7 * this.rotationSpeed;
...@@ -6989,48 +7019,68 @@ ...@@ -6989,48 +7019,68 @@
return Body; return Body;
}(ScillaComponent)); }(ScillaComponent));
var gravityY = .7;
var BallItem = (function (_super) {
__extends(BallItem, _super);
function BallItem() {
var _this = _super.call(this) || this;
_this.score = 0;
_this.gravity = gravityY;
_this.rotationSpeed = 0.5 * 2;
return _this;
}
BallItem.prototype.onAwake = function () {
_super.prototype.onAwake.call(this);
this.updateScoreTxt();
};
BallItem.prototype.reduceScore = function () {
this.score--;
if (this.score < 0)
this.score = 0;
this.updateScoreTxt();
};
BallItem.prototype.updateScoreTxt = function () {
var tr = this.scoreTxt.getComponent(TextRenderer);
tr.text = this.score.toString();
};
return BallItem;
}(Body));
var BlueRocketItem = (function (_super) { var BlueRocketItem = (function (_super) {
__extends(BlueRocketItem, _super); __extends(BlueRocketItem, _super);
function BlueRocketItem() { function BlueRocketItem() {
var _this = _super.call(this) || this; var _this = _super.call(this) || this;
_this.gravity = gravityY;
_this.bounceY = 0.9; _this.bounceY = 0.9;
return _this; return _this;
} }
return BlueRocketItem; return BlueRocketItem;
}(Body)); }(Body));
var BulletItem = (function (_super) {
__extends(BulletItem, _super);
function BulletItem() {
var _this = _super.call(this) || this;
_this.gravity = 0;
_this.velocityY = -10;
_this.rotationSpeed = 0;
return _this;
}
return BulletItem;
}(Body));
var RedFireItem = (function (_super) { var RedFireItem = (function (_super) {
__extends(RedFireItem, _super); __extends(RedFireItem, _super);
function RedFireItem() { function RedFireItem() {
var _this = _super.call(this) || this; var _this = _super.call(this) || this;
_this.gravity = gravityY;
_this.bounceY = 0.9; _this.bounceY = 0.9;
return _this; return _this;
} }
return RedFireItem; return RedFireItem;
}(Body)); }(Body));
var getTween = function (context, target, obj, duration, ease$$1) {
return new Promise(function (r) {
var postionObj = {};
for (var key in obj) {
if (key == 'x' || key == 'y') {
postionObj[key] = obj[key];
delete obj[key];
}
}
createTween(context, target.position, true).to(postionObj, duration, ease$$1);
createTween(context, target, true).to(obj, duration, ease$$1).call(r);
});
};
var BallItem = (function (_super) {
__extends(BallItem, _super);
function BallItem() {
return _super !== null && _super.apply(this, arguments) || this;
}
return BallItem;
}(Body));
var GROUND_Y = 350 + 40; var GROUND_Y = 350 + 40;
var ScenePlay = (function (_super) { var ScenePlay = (function (_super) {
__extends(ScenePlay, _super); __extends(ScenePlay, _super);
...@@ -7038,11 +7088,11 @@ ...@@ -7038,11 +7088,11 @@
return _super !== null && _super.apply(this, arguments) || this; return _super !== null && _super.apply(this, arguments) || this;
} }
ScenePlay.prototype.onGlobalTouchBegin = function (e) { ScenePlay.prototype.onGlobalTouchBegin = function (e) {
this.car.getComponent(Transform).position.x = e.x - 375; setX(this.car, e.x - 375);
return _super.prototype.onGlobalTouchBegin.call(this, e); return _super.prototype.onGlobalTouchBegin.call(this, e);
}; };
ScenePlay.prototype.onGlobalTouchMove = function (e) { ScenePlay.prototype.onGlobalTouchMove = function (e) {
this.car.getComponent(Transform).position.x = e.x - 375; setX(this.car, e.x - 375);
return _super.prototype.onGlobalTouchMove.call(this, e); return _super.prototype.onGlobalTouchMove.call(this, e);
}; };
ScenePlay.prototype.getRedFireItem = function () { ScenePlay.prototype.getRedFireItem = function () {
...@@ -7057,74 +7107,120 @@ ...@@ -7057,74 +7107,120 @@
this.bodys.push(item); this.bodys.push(item);
item.getComponent(BlueRocketItem).velocityX = 1; item.getComponent(BlueRocketItem).velocityX = 1;
}; };
ScenePlay.prototype.getBallItem = function () { ScenePlay.prototype.getBallItem = function (score) {
var ball = instantiate(this.BallItemPrefab); var ball = instantiate(this.BallItemPrefab);
ball.getComponent(Transform).position.y = -300; ball.getComponent(BallItem).score = score;
this.bodys.push(ball); this.bodys.push(ball);
this.entity.addChild(ball); this.entity.addChild(ball);
this.ballList.push(ball);
return ball;
};
ScenePlay.prototype.createBullet = function () {
var item = instantiate(this.BulletItemPrefab);
this.entity.addChild(item);
this.bodys.push(item);
setXY(item, getX(this.car), getY(this.car) - 100);
}; };
ScenePlay.prototype.onAwake = function () { ScenePlay.prototype.onAwake = function () {
_super.prototype.onAwake.call(this); _super.prototype.onAwake.call(this);
this.ballList = [];
this.bodys = []; this.bodys = [];
}; };
ScenePlay.prototype.onUpdate = function () { ScenePlay.prototype.onUpdate = function () {
var e_1, _a; var e_1, _a;
try { for (var i = 0; i < this.bodys.length; i++) {
for (var _b = __values(this.bodys), _c = _b.next(); !_c.done; _c = _b.next()) { var body = this.bodys[i];
var body = _c.value; var position = body.getComponent(Transform).position;
var position = body.getComponent(Transform).position; var pic = body.getChildrenByName('pic')[0];
var pic = body.getChildrenByName('pic')[0]; var _b = pic.getComponent(Transform), height = _b.height, width = _b.width;
var _d = pic.getComponent(Transform), height = _d.height, width = _d.width; var r = height / 2;
var r = height / 2; if (position.y + r > GROUND_Y) {
if (position.y + r > GROUND_Y) { position.y = GROUND_Y - r;
position.y = GROUND_Y - r; body.getComponent(Body).revertY();
body.getComponent(Body).revertY(); }
} if (position.x + r > 375) {
if (position.x + r > 375) { position.x = 375 - r;
position.x = 375 - r; body.getComponent(Body).revertX();
body.getComponent(Body).revertX(); }
} if (position.x - r < -375) {
if (position.x - r < -375) { position.x = -375 + r;
position.x = -375 + r; body.getComponent(Body).revertX();
body.getComponent(Body).revertX(); }
var _c = this.car.getComponent(Transform).position, carX = _c.x, carY = _c.y;
var x0 = Math.abs(position.x - carX);
var y0 = Math.abs(position.y - carY);
var x1 = r + 120 / 2;
var y1 = r + 110 / 2;
var t = body.getComponent(Body);
if (x0 < x1 && y0 < y1) {
console.log('碰撞了');
if (t instanceof BallItem)
this.onCarCollideBall(body);
else if (t instanceof BlueRocketItem || t instanceof RedFireItem)
this.onCarCollideDrops(body);
}
if (t instanceof BulletItem) {
if (position.y < -1624 / 2) {
this.removeBullet(body);
i--;
} }
var _e = this.car.getComponent(Transform).position, carX = _e.x, carY = _e.y; else {
var x0 = Math.abs(position.x - carX); try {
var y0 = Math.abs(position.y - carY); for (var _d = __values(this.ballList), _e = _d.next(); !_e.done; _e = _d.next()) {
var x1 = r + 120 / 2; var ball = _e.value;
var y1 = r + 110 / 2; var x0_1 = Math.abs(getX(body) - getX(ball));
if (x0 < x1 && y0 < y1) { var y0_1 = Math.abs(getY(body) - getY(ball));
console.log('碰撞了'); var ballH = ball.getChildrenByName('pic')[0].getComponent(Transform).height;
var t = body.getComponent(Body); var x1_1 = width / 2 + ballH / 2;
if (t instanceof BallItem) var y1_1 = height / 2 + ballH / 2;
this.onCarCollideBall(body); if (x0_1 < x1_1 && y0_1 < y1_1) {
else this.removeBullet(body);
this.onCarCollideDrops(body); i--;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
}
finally { if (e_1) throw e_1.error; }
}
} }
} }
} }
catch (e_1_1) { e_1 = { error: e_1_1 }; } };
finally { ScenePlay.prototype.removeBullet = function (body) {
try { console.log(this.bodys.length);
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); body.removeAllComponents();
} var index = this.bodys.indexOf(body);
finally { if (e_1) throw e_1.error; } if (index == -1)
} return;
this.bodys.splice(index, 1);
this.entity.removeChild(body);
}; };
ScenePlay.prototype.onCarCollideBall = function (body) { ScenePlay.prototype.onCarCollideBall = function (body) {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var index;
return __generator(this, function (_a) { return __generator(this, function (_a) {
index = this.bodys.indexOf(body); this.removeBall(body);
if (index == -1) console.log('on game over');
return [2];
this.bodys.splice(index, 1);
body.removeComponent(body.getComponent(Body));
this.entity.removeChild(body);
return [2]; return [2];
}); });
}); });
}; };
ScenePlay.prototype.removeBall = function (body) {
var index = this.bodys.indexOf(body);
this.bodys.splice(index, 1);
var index2 = this.ballList.indexOf(body);
this.ballList.splice(index2, 1);
body.removeComponent(body.getComponent(Body));
this.entity.removeChild(body);
};
ScenePlay.prototype.onBallSplit = function (body) {
var ball1 = this.getBallItem(100);
setXY(ball1, getX(body), getY(body));
ball1.getComponent(Body).velocityY = -45;
};
ScenePlay.prototype.onCarCollideDrops = function (body) { ScenePlay.prototype.onCarCollideDrops = function (body) {
return __awaiter(this, void 0, void 0, function () { return __awaiter(this, void 0, void 0, function () {
var index; var index;
...@@ -7160,11 +7256,31 @@ ...@@ -7160,11 +7256,31 @@
}); });
}); });
}; };
ScenePlay.prototype.createBigBall = function () {
return __awaiter(this, void 0, void 0, function () {
var ball, body;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
ball = this.getBallItem(100);
setXY(ball, -375, -400);
body = ball.getComponent(Body);
body.enabled = false;
return [4, getTween(this, ball.getComponent(Transform), { x: -375 + 200 }, 1000)];
case 1:
_a.sent();
body.velocityX = 5;
body.enabled = true;
return [2];
}
});
});
};
ScenePlay.prototype.onDidEnter = function (last, action, parameters) { ScenePlay.prototype.onDidEnter = function (last, action, parameters) {
var _this = this;
this.entity.getComponent(Transform).alpha = 1; this.entity.getComponent(Transform).alpha = 1;
this.getBallItem(); this.createBigBall();
this.getRedFireItem(); setInterval(function () { _this.createBullet(); }, 1000 / 15);
this.getBlueRocketItem();
}; };
ScenePlay.prototype.onDidLeave = function (next, action, parameters) { ScenePlay.prototype.onDidLeave = function (next, action, parameters) {
this.entity.getComponent(Transform).alpha = 0; this.entity.getComponent(Transform).alpha = 0;
...@@ -7580,7 +7696,8 @@ ...@@ -7580,7 +7696,8 @@
registerDef('./scripts/dialogs/RulePanel', RulePanel); registerDef('./scripts/dialogs/RulePanel', RulePanel);
registerDef('./scripts/scenes/BallItem', BallItem); registerDef('./scripts/scenes/BallItem', BallItem);
registerDef('./scripts/scenes/BlueRocketItem', BlueRocketItem); registerDef('./scripts/scenes/BlueRocketItem', BlueRocketItem);
registerDef('./scripts/scenes/SceneStart', SceneStart); registerDef('./scripts/scenes/SceneStart', SceneStart);
registerDef('./scripts/scenes/BulletItem', BulletItem);
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.
...@@ -58,3 +58,6 @@ registerDef('./scripts/scenes/BlueRocketItem', component16); ...@@ -58,3 +58,6 @@ registerDef('./scripts/scenes/BlueRocketItem', component16);
import component17 from '../../assets/scripts/scenes/SceneStart'; import component17 from '../../assets/scripts/scenes/SceneStart';
registerDef('./scripts/scenes/SceneStart', component17); registerDef('./scripts/scenes/SceneStart', component17);
import component18 from '../../assets/scripts/scenes/BulletItem';
registerDef('./scripts/scenes/BulletItem', component18);
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