Commit be5f4ce7 authored by wildfirecode's avatar wildfirecode

1

parent 44a684fb
......@@ -432,6 +432,14 @@
"topline": "entity|9f9bfbf2-4f77-4a1b-b1b5-42b6784e0c8c",
"BallItemPrefab": "res|1de471d9-75ca-4549-aca9-ff3cca9aac08"
}
},
{
"script": "./scripts/scenes/scenePlay/DropManager",
"properties": {
"BlueRocketPrefab": "res|b5185698-ef74-4855-95b9-813e187f6ee7",
"RedFirePrefab": "res|8a61e34c-bdba-4dbe-813a-68c562e7ecbd",
"YellowRocketPrefab": "res|51834a6b-5880-41df-81d9-beaef804a919"
}
}
],
"uuid": "1265b761-1b67-4d76-9526-78c457a8d113",
......
import Body from './Body';
import { DropType } from './scenePlay/DropManager';
export default class RocketItem extends Body {
type: string;
type: DropType;
constructor() {
super();
this.gravity = 1;
this.bounceY = 0.9;
this.gravity = 1.5;
this.bounceY = 0.8;
this.velocityX = 1;
}
reset(){
super.reset();
this.velocityX = 1;
}
}
\ No newline at end of file
import InteractComponent from "scilla-components/src/base/InteractComponent";
import Transform from "scilla-components/src/base/Transform";
import { Entity, instantiate, resource } from "scilla/src";
import { Entity } from "scilla/src";
import { alien } from "../navigator/StackNavigator";
import { INavigatorViewBase } from "../navigator/VirtualNavigator";
import { getX, getY, setX, setXY, getScale } from "../transformUtils";
import { getScale, getX, getY, setX } from "../transformUtils";
import BallItem from "./BallItem";
import Body from "./Body";
import BallManager from "./scenePlay/BallManager";
import CarBulletAni from "./scenePlay/CarBulletAni";
import CarShootAni from "./scenePlay/CarShootAni";
import DropManager from "./scenePlay/DropManager";
import ngameSubmit from "./scenePlay/ngameSubmit";
export default class ScenePlay extends InteractComponent implements INavigatorViewBase {
RedFirePrefab: resource;
BlueRocketPrefab: resource;
YellowRocketPrefab: resource;
bulletNumTxt: Entity;
strengthNumTxt: Entity;
car: Entity;
......@@ -23,11 +19,10 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
score = 0;
drops: Body[];
_carShootAni: CarShootAni;
_bulletManager: CarBulletAni;
_ballManager: BallManager;
_dropManager: DropManager;
private _ngameSubmitApi: ngameSubmit;
......@@ -54,7 +49,31 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
onUpdate() {
this.checkBallCollideGroud();
this.checkDropsCollideGroud();
this.checkBulletCollideBall();
this.checkCarCollideBar();
this.checkCarColliedeDrops();
}
checkCarColliedeDrops() {
for (let i = 0; i < this._dropManager.dropList.length; i++) {
const drop = this._dropManager.dropList[i];
const pic = drop.entity.getChildrenByName('pic')[0];
const r = pic.getComponent(Transform).height / 2;
const x0 = Math.abs(getX(drop) - getX(this.car));
const y0 = Math.abs(getY(drop) - getY(this.car));
const x1 = r + 120 / 2;
const y1 = r + 110 / 2;
if(x0 < x1 && y0 < y1){
this._dropManager.removeDrop(drop);
i--;
}
}
}
checkCarCollideBar() {
}
checkBulletCollideBall() {
......@@ -74,7 +93,7 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
this._bulletManager.removeBullet(bullet);
i--;
if (ball.reduceScore() == 0) { //破裂
this.onBallSplit(ball);
this.checkBallSplit(ball);
}
break;
}
......@@ -82,8 +101,8 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
}
}
onBallSplit(ball: BallItem) {
this._ballManager.onBallSplit(ball);
checkBallSplit(ball: BallItem) {
this._ballManager.checkBallSplit(ball);
}
checkBallCollideGroud() {
......@@ -110,34 +129,37 @@ export default class ScenePlay extends InteractComponent implements INavigatorVi
}
}
}
checkDropsCollideGroud() {
const { dropList } = this._dropManager;
for (let i = 0; i < dropList.length; i++) {
const drop = dropList[i];
const { position } = drop.getComponent(Transform);
const pic = drop.entity.getChildrenByName('pic')[0];
const { height } = pic.getComponent(Transform);
const r = height / 2;//刚体的半径
if (position.y + r > getY(this.bottomline)) {
position.y = getY(this.bottomline) - r;
drop.revertY();
}
if (position.x + r > 375) {
position.x = 375 - r;
drop.revertX();
}
onDrops(ball: Body) {
const ballEntity = ball.entity;
let item;
if (Math.random() > 0.5) {
item = this.getFireItem(this.BlueRocketPrefab);
} else {
item = this.getFireItem(this.RedFirePrefab);
if (position.x - r < -375) {
position.x = -375 + r;
drop.revertX();
}
}
setXY(item, getX(ballEntity), getY(ballEntity));
return item;
}
getFireItem(res: resource) {
const item = instantiate(res);
this.entity.addChild(item);
const body = item.getComponent(Body)
this.drops.push(body);
return item;
}
onAwake() {
super.onAwake();
this.drops = [];
this._carShootAni = this.car.getComponent(CarShootAni);
this._bulletManager = this.car.getComponent(CarBulletAni);
this._ngameSubmitApi = this.getComponent(ngameSubmit);
this._ballManager = this.getComponent(BallManager);
this._dropManager = this.getComponent(DropManager);
}
onDidEnter(last: string, action: alien.NavigatorAction, parameters: any): void {
......
......@@ -8,18 +8,20 @@ import { removeFromList, pickFromList } from '../_';
export default class BallManager extends ScillaComponent {
onBallSplit(ball: BallItem) {
checkBallSplit(ball: BallItem) {
//移除ball
ball.enabled = false;
removeFromList(ball, this.ballList);
this.entity.removeChild(ball.entity);
this._freeBallList.push(ball);
console.log('this.ballList', this.ballList.length, 'this._freeBallList', this._freeBallList.length);
//开始分裂
if (ball.size > BallSizeType.min) {
// console.log('this.ballList', this.ballList.length, 'this._freeBallList', this._freeBallList.length);
if (ball.size > BallSizeType.min) {//开始分裂
const ball1 = this.createSplitedBall(ball);
const ball2 = this.createSplitedBall(ball);
ball1.velocityX = -5;
ball2.velocityX = 5;
} else {//掉落
this.broadcast('createDrop', 1, ball)
}
}
......@@ -46,7 +48,7 @@ export default class BallManager extends ScillaComponent {
}
async createBigBall() {
const score = Math.ceil(20 + Math.random() * 20);
const score = Math.ceil(50 + Math.random() * 20);
const ball = this.getBall();
ball.reset();
ball.resetScore(score);
......@@ -69,7 +71,7 @@ export default class BallManager extends ScillaComponent {
ball = this._freeBallList.pop();
} else {
ball = this.createBall();
console.log('ball created')
// console.log('ball created')
}
return ball;
}
......
......@@ -25,11 +25,10 @@ export default class CarBulletAni extends ScillaComponent {
private _interval = 3;
//等级1 2 3 4
private _lines = 2;
private _lines = 4;
private _offsetList: number[][] = [];
bullets: Body[] = [];
private _freeBullets: Body[];
private _playScene: Entity;
onAwake() {
super.onAwake();
this._freeBullets = [];
......@@ -40,7 +39,6 @@ export default class CarBulletAni extends ScillaComponent {
this._offsetList.push([-36, -18, 0, 18, 36]);
this._offsetList.push([-45, -27, -9, 9, 27, 45]);
this._offsetList.push([-54, -36, -18, 0, 18, 36, 54]);
this._playScene = this.entity.parent;
}
updateLines(X) {
......@@ -60,8 +58,8 @@ export default class CarBulletAni extends ScillaComponent {
}
removeBullet(bullet: Body) {
bullet.entity.enabled = false;
this._playScene.removeChild(bullet.entity);
bullet.enabled = false;
this.scenePlay.removeChild(bullet.entity);
removeFromList(bullet, this.bullets);
this._freeBullets.push(bullet);
}
......@@ -95,7 +93,7 @@ export default class CarBulletAni extends ScillaComponent {
bullet.enabled = false;//先禁用物理
list.push(bullet);
this.bullets.push(bullet);
const targetX = getX(this.entity);
const targetY = getY(this.entity) - 100;
......@@ -104,10 +102,13 @@ export default class CarBulletAni extends ScillaComponent {
tweens.push(tween);
}
Promise.all(tweens).then(() => {
list.forEach(item => item.enabled = true);
list.forEach(item => {
item.enabled = true;
});
});
list.forEach(bullet => {
this.bullets.push(bullet);
this.scenePlay.addChild(bullet.entity);
});
}
......
import { getX, getY, setXY } from 'assets/scripts/transformUtils';
import ScillaComponent from 'components/base/ScillaComponent';
import { instantiate, resource } from 'scilla/src';
import Body from '../Body';
import RocketItem from '../RocketItem';
import { removeFromList } from '../_';
export enum DropType {
red = 'red', blue = 'blue', yellow = 'yellow'
}
export default class DropManager extends ScillaComponent {
RedFirePrefab: resource;
BlueRocketPrefab: resource;
YellowRocketPrefab: resource;
removeDrop(drop: RocketItem) {
this.entity.removeChild(drop.entity);
drop.enabled = false;
removeFromList(drop, this._dropList);
const frees = this._freeDic[drop.type];
frees.push(drop);
for (const key in this._freeDic) {
if (this._freeDic.hasOwnProperty(key)) {
const element = this._freeDic[key];
console.log('free', key, element.length)
}
}
console.log(this.dropList.length)
}
createDrop(ball: Body) {
let item: Body;
if (Math.random() > 0.7) {
item = this.getFireItem(this.BlueRocketPrefab, DropType.blue);
} else {
if (Math.random() > 0.5)
item = this.getFireItem(this.RedFirePrefab, DropType.red);
else
item = this.getFireItem(this.YellowRocketPrefab, DropType.yellow);
}
setXY(item, getX(ball), getY(ball));
return item;
}
getFireItem(res: resource, type: DropType) {
const frees = this._freeDic[type];
let body: RocketItem;
if (frees.length > 0) {
body = frees.pop();
body.enabled = true;
body.reset();
} else {
const item = instantiate(res);
body = item.getComponent(RocketItem);
}
this.entity.addChild(body.entity);
this._dropList.push(body);
return body;
}
private _dropList: RocketItem[];
get dropList() { return this._dropList }
private _freeDic: { [key: string]: RocketItem[]; };
onAwake() {
super.onAwake();
this._dropList = [];
this._freeDic = {
'red': [], 'blue': [], 'yellow': []
};
}
onUpdate(t) {
super.onUpdate(t);
}
}
{"ver":"1.0.1","uuid":"7dbbaba5-b07a-4e4e-a598-dc1de3aca547","subMetas":{},"type":"script"}
......@@ -5,47 +5,47 @@
import {registerDef} from 'scilla'
import component0 from 'components/other/RelativeLayout';
registerDef('components/other/RelativeLayout', component0);
import component0 from 'components/other/CameraController';
registerDef('components/other/CameraController', component0);
import component1 from 'components/base/Transform';
registerDef('components/base/Transform', component1);
import component2 from 'components/renderer/HtmlRenderer';
registerDef('components/renderer/HtmlRenderer', component2);
import component2 from 'components/renderer/TextureRenderer';
registerDef('components/renderer/TextureRenderer', component2);
import component3 from 'components/ui/ScrollView';
registerDef('components/ui/ScrollView', component3);
import component3 from 'components/renderer/TextRenderer';
registerDef('components/renderer/TextRenderer', component3);
import component4 from 'components/other/FullStageSize';
registerDef('components/other/FullStageSize', component4);
import component4 from 'components/animation/TouchZoom';
registerDef('components/animation/TouchZoom', component4);
import component5 from 'components/base/TouchInterrupt';
registerDef('components/base/TouchInterrupt', component5);
import component5 from 'components/ui/Button';
registerDef('components/ui/Button', component5);
import component6 from 'components/renderer/RectRenderer';
registerDef('components/renderer/RectRenderer', component6);
import component6 from 'components/other/FullStageSize';
registerDef('components/other/FullStageSize', component6);
import component7 from 'components/other/CameraController';
registerDef('components/other/CameraController', component7);
import component7 from 'components/other/RelativeLayout';
registerDef('components/other/RelativeLayout', component7);
import component8 from 'components/renderer/TextureRenderer';
registerDef('components/renderer/TextureRenderer', component8);
import component8 from 'components/renderer/RectRenderer';
registerDef('components/renderer/RectRenderer', component8);
import component9 from 'components/renderer/TextRenderer';
registerDef('components/renderer/TextRenderer', component9);
import component9 from 'components/base/TouchInterrupt';
registerDef('components/base/TouchInterrupt', component9);
import component10 from 'components/animation/TouchZoom';
registerDef('components/animation/TouchZoom', component10);
import component10 from 'components/ui/ScrollView';
registerDef('components/ui/ScrollView', component10);
import component11 from 'components/ui/Button';
registerDef('components/ui/Button', component11);
import component11 from 'components/renderer/HtmlRenderer';
registerDef('components/renderer/HtmlRenderer', component11);
import component12 from '../../assets/scripts/dialogs/AlertDialogContent';
registerDef('./scripts/dialogs/AlertDialogContent', component12);
import component12 from '../../assets/scripts/api/SamplePollingApi';
registerDef('./scripts/api/SamplePollingApi', component12);
import component13 from '../../assets/scripts/api/SamplePollingApi';
registerDef('./scripts/api/SamplePollingApi', component13);
import component13 from '../../assets/scripts/scenes/ScenePlay';
registerDef('./scripts/scenes/ScenePlay', component13);
import component14 from '../../assets/scripts/scenes/scenePlay/ngameSubmit';
registerDef('./scripts/scenes/scenePlay/ngameSubmit', component14);
......@@ -53,50 +53,53 @@ registerDef('./scripts/scenes/scenePlay/ngameSubmit', component14);
import component15 from '../../assets/scripts/scenes/scenePlay/BallManager';
registerDef('./scripts/scenes/scenePlay/BallManager', component15);
import component16 from '../../assets/scripts/scenes/SceneStart';
registerDef('./scripts/scenes/SceneStart', component16);
import component16 from '../../assets/scripts/scenes/SceneController';
registerDef('./scripts/scenes/SceneController', component16);
import component17 from '../../assets/scripts/scenes/SceneController';
registerDef('./scripts/scenes/SceneController', component17);
import component17 from '../../assets/scripts/scenes/SceneStart';
registerDef('./scripts/scenes/SceneStart', component17);
import component18 from '../../assets/scripts/scenes/scenePlay/CarBulletAni';
registerDef('./scripts/scenes/scenePlay/CarBulletAni', component18);
import component18 from '../../assets/scripts/MainController';
registerDef('./scripts/MainController', component18);
import component19 from '../../assets/scripts/scenes/scenePlay/CarShootAni';
registerDef('./scripts/scenes/scenePlay/CarShootAni', component19);
import component19 from '../../assets/scripts/scenes/scenePlay/CarBulletAni';
registerDef('./scripts/scenes/scenePlay/CarBulletAni', component19);
import component20 from '../../assets/scripts/popup/Popup';
registerDef('./scripts/popup/Popup', component20);
import component20 from '../../assets/scripts/scenes/scenePlay/CarShootAni';
registerDef('./scripts/scenes/scenePlay/CarShootAni', component20);
import component21 from '../../assets/scripts/navigator/SingleSceneNavigator';
registerDef('./scripts/navigator/SingleSceneNavigator', component21);
import component21 from '../../assets/scripts/popup/Popup';
registerDef('./scripts/popup/Popup', component21);
import component22 from '../../assets/scripts/scenes/ScenePlay';
registerDef('./scripts/scenes/ScenePlay', component22);
import component22 from '../../assets/scripts/api/SampleApi';
registerDef('./scripts/api/SampleApi', component22);
import component23 from '../../assets/scripts/dialogs/RuleDialogContent';
registerDef('./scripts/dialogs/RuleDialogContent', component23);
import component23 from '../../assets/scripts/dialogs/AlertDialogContent';
registerDef('./scripts/dialogs/AlertDialogContent', component23);
import component24 from '../../assets/scripts/api/SampleApi';
registerDef('./scripts/api/SampleApi', component24);
import component24 from '../../assets/scripts/dialogs/RuleDialogContent';
registerDef('./scripts/dialogs/RuleDialogContent', component24);
import component25 from '../../assets/scripts/game/CustomTextRenderer';
registerDef('./scripts/game/CustomTextRenderer', component25);
import component25 from '../../assets/scripts/scenes/BulletItem';
registerDef('./scripts/scenes/BulletItem', component25);
import component26 from '../../assets/scripts/MainController';
registerDef('./scripts/MainController', component26);
import component26 from '../../assets/scripts/game/CustomTextRenderer';
registerDef('./scripts/game/CustomTextRenderer', component26);
import component27 from '../../assets/scripts/dialogs/GameOverPanel';
registerDef('./scripts/dialogs/GameOverPanel', component27);
import component27 from '../../assets/scripts/navigator/SingleSceneNavigator';
registerDef('./scripts/navigator/SingleSceneNavigator', component27);
import component28 from '../../assets/scripts/common/Toast';
registerDef('./scripts/common/Toast', component28);
import component28 from '../../assets/scripts/dialogs/GameOverPanel';
registerDef('./scripts/dialogs/GameOverPanel', component28);
import component29 from '../../assets/scripts/scenes/BallItem';
registerDef('./scripts/scenes/BallItem', component29);
import component29 from '../../assets/scripts/common/Toast';
registerDef('./scripts/common/Toast', component29);
import component30 from '../../assets/scripts/scenes/RocketItem';
registerDef('./scripts/scenes/RocketItem', component30);
import component30 from '../../assets/scripts/scenes/BallItem';
registerDef('./scripts/scenes/BallItem', component30);
import component31 from '../../assets/scripts/scenes/BulletItem';
registerDef('./scripts/scenes/BulletItem', component31);
import component31 from '../../assets/scripts/scenes/RocketItem';
registerDef('./scripts/scenes/RocketItem', component31);
import component32 from '../../assets/scripts/scenes/scenePlay/DropManager';
registerDef('./scripts/scenes/scenePlay/DropManager', component32);
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