Commit be5f4ce7 authored by wildfirecode's avatar wildfirecode

1

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