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 @@
},
{
"script": "./scripts/scenes/BallItem",
"properties": {}
"properties": {
"scoreTxt": "entity|8abfc716-7017-4834-a7fa-5ca6c2ce4b3e"
}
}
],
"children": [
......@@ -42,7 +44,7 @@
"uuid": "fb53fa37-a942-4474-901a-582dccd14c93"
},
{
"name": "Label",
"name": "txt",
"components": [
{
"script": "components/base/Transform",
......@@ -54,7 +56,7 @@
"text": "1111",
"fillColor": "rgba(255, 255, 255, 1)",
"textStyle": {
"fontSize": 40
"fontSize": 100
}
}
}
......@@ -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 @@
"BallItemPrefab": "res|8ebdfe78-ea44-445d-8bbe-02a22874e896",
"RedFirePrefab": "res|83d50df9-266c-478f-bf01-21d478abe049",
"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 @@
"script": "components/base/Transform",
"properties": {
"position": {
"x": 2.5,
"x": -207.5,
"y": 340,
"_type_": "scilla/support/Vector2D"
}
......@@ -732,6 +733,10 @@
"uuid": "9a8fe57a-ff20-44e7-89bf-cdc95e80e1ea",
"url": "prefabs/BlueRocket.pfb"
},
{
"uuid": "2d853f74-b511-4edf-9bbd-ac02ae1fc075",
"url": "prefabs/bullet.pfb"
},
{
"uuid": "83d50df9-266c-478f-bf01-21d478abe049",
"url": "prefabs/RedFire.pfb"
......@@ -796,6 +801,10 @@
{
"name": "red20.png",
"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 { gravityY } from './gameconst';
import { Entity } from 'scilla/src';
import { TextRenderer } from 'scilla-components/src';
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 { gravityY } from './gameconst';
export default class BlueRocketItem extends Body {
constructor() {
super();
this.gravity = gravityY;
this.bounceY = 0.9;
}
}
\ No newline at end of file
import ScillaComponent from 'components/base/ScillaComponent';
import { Transform } from 'scilla-components/src';
import { gravityY } from './gameconst';
export default class Body extends ScillaComponent {
bounceY = 1;
......@@ -8,12 +7,13 @@ export default class Body extends ScillaComponent {
velocityY = 0;
velocityX = 0;
rotationSpeed = 0.5;
gravity=0;
private _counter = 0;
onUpdate() {
this._counter++;
const { entity } = this;
this.velocityY += gravityY;
this.velocityY += this.gravity;
entity.getComponent(Transform).position.y += this.velocityY;
entity.getComponent(Transform).position.x += this.velocityX;
// 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 { gravityY } from './gameconst';
export default class RedFireItem extends Body {
constructor() {
super();
this.gravity = gravityY;
this.bounceY = 0.9;
}
}
\ No newline at end of file
......@@ -2,36 +2,39 @@
* Created by rockyl on 2019-04-09.
*/
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 { getTween } from '../getTween';
import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { getX, getY, setXY, setX } from '../transform';
import BallItem from './BallItem';
import BlueRocketItem from './BlueRocketItem';
import Body from './Body';
import BulletItem from './BulletItem';
import RedFireItem from './RedFireItem';
import { getTween } from '../getTween';
import BallItem from './BallItem';
const GROUND_Y = 350 + 40; //碰到地板时,球的中心点的y
export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
BallItemPrefab: resource;
BulletItemPrefab: resource;
RedFirePrefab: resource;
BlueRocketPrefab: resource;
bulletNumTxt: Entity;
strengthNumTxt: Entity;
car: Entity;
// ballList: Entity[];
ballList: Entity[];
// redFireList: Entity[];
bodys: Entity[];
onGlobalTouchBegin(e): any {
this.car.getComponent(Transform).position.x = e.x - 375;
setX(this.car, e.x - 375);
return super.onGlobalTouchBegin(e);
}
onGlobalTouchMove(e: { x, y }) {
this.car.getComponent(Transform).position.x = e.x - 375;
setX(this.car, e.x - 375);
return super.onGlobalTouchMove(e);
}
......@@ -51,28 +54,36 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
item.getComponent(BlueRocketItem).velocityX = 1;
}
getBallItem() {
getBallItem(score: number) {
const ball = instantiate(this.BallItemPrefab);
ball.getComponent(Transform).position.y = -300;
ball.getComponent(BallItem).score = score;
this.bodys.push(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() {
super.onAwake();
// this.ballList = [];
this.ballList = [];
this.bodys = [];
}
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 pic = body.getChildrenByName('pic')[0];
const { height, width } = pic.getComponent(Transform);
const r = height / 2;//刚体的半径
// console.log(position.x);
// console.log(position.y + r)
if (position.y + r > GROUND_Y) {
position.y = GROUND_Y - r;
body.getComponent(Body).revertY();
......@@ -87,32 +98,80 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
position.x = -375 + r;
body.getComponent(Body).revertX();
}
const { x: carX, y: carY } = this.car.getComponent(Transform).position;
//判断car与body的碰撞
const x0 = Math.abs(position.x - carX);
const y0 = Math.abs(position.y - carY);
const x1 = r + 120 / 2;
const y1 = r + 110 / 2;
const t = body.getComponent(Body);
if (x0 < x1 && y0 < y1) {
console.log('碰撞了');
const t = body.getComponent(Body);
if (t instanceof BallItem)
this.onCarCollideBall(body);
else
else if (t instanceof BlueRocketItem || t instanceof RedFireItem)
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) {
this.removeBall(body);
console.log('on game over')
}
removeBall(body: Entity) {
const index = this.bodys.indexOf(body);
if (index == -1) return;
this.bodys.splice(index, 1);
const index2 = this.ballList.indexOf(body);
this.ballList.splice(index2, 1);
body.removeComponent(body.getComponent(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) {
const index = this.bodys.indexOf(body);
if (index == -1) return;
......@@ -127,11 +186,26 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
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 {
(this.entity.getComponent(Transform) as Transform).alpha = 1;
this.getBallItem();
this.getRedFireItem();
this.getBlueRocketItem();
this.createBigBall();
// this.getRedFireItem();
// this.getBlueRocketItem();
setInterval(() => { this.createBullet() }, 1000 / 15);
}
onDidLeave(next: string, action: alien.NavigatorAction, parameters: any): void {
......
export const gravityY= 1.5;
\ No newline at end of file
export const gravityY= .7;
\ 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"}
This diff is collapsed.
This diff is collapsed.
......@@ -58,3 +58,6 @@ registerDef('./scripts/scenes/BlueRocketItem', component16);
import component17 from '../../assets/scripts/scenes/SceneStart';
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