Commit a871575a authored by Tt's avatar Tt

完成

parent d1638871
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class NewClass extends cc.Component { export default class boatmove extends cc.Component {
@property @property
firstUp: boolean = true; firstUp: boolean = true;
......
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
const { ccclass, property } = cc._decorator;
@ccclass
export default class cloundmove extends cc.Component {
@property
toLeft: boolean = true;
// LIFE-CYCLE CALLBACKS:
onLoad() {
if (this.toLeft) {
cc.tween(this.node).by(500 + Math.random() * 100, { x: -2000 }).start();
} else {
cc.tween(this.node).by(500 + Math.random() * 100, { x: 2000 }).start();
}
}
}
{ {
"ver": "1.0.8", "ver": "1.0.8",
"uuid": "e9a1cc04-7df7-49fa-8978-99f9f4a7568b", "uuid": "aaac548b-f788-42d3-ab99-3108750b719b",
"isPlugin": false, "isPlugin": false,
"loadPluginInWeb": true, "loadPluginInWeb": true,
"loadPluginInNative": true, "loadPluginInNative": true,
......
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import Game, { FISH_OUT, GAME_STATE, Option } from "../tool/Game";
import pg from "../tool/pg";
const { ccclass, property } = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Node)
res: cc.Node = null;
@property(cc.Node)
item_left: cc.Node = null;
@property(cc.Node)
item_right: cc.Node = null;
onLoad() {
pg.event.on("game_start", () => {
this.gameStart();
})
pg.event.on("game_time_over", () => {
this.roundOver();
})
}
private count: number;
private list: Option[];
private fishs: cc.Node[];
gameStart() {
//游戏开始。允许出鱼
// let page = Game.getIns().getCurrentPage();
// let list = page.optionList.concat();
// list = JSON.parse(JSON.stringify(list));
// list.sort((A, B) => { return Math.random() < 0.5 });
// this.list = list;
// this.count = 0;
// this.lastCount = null;
// this.fishs = [];
// this.viewFishs = [];
// this.touchFishs = [];
//根据顺序生成对应的鱼。
//顺序根据时间来进行跳动。当顺序跳动之后,就会产生新的鱼。
}
roundOver() {
//当前的鱼都不能点击并且消失
this.viewFishs.forEach(data => {
cc.tween(data.fish.node).to(0.3, { opacity: 0 }).start();
})
}
private lastCount: number;
private viewFishs: Option[];
private touchFishs: Option[];
getFishByCount(count) {
if (count <= this.lastCount) return null;
if (!this.list) return;
if (this.list.length == this.touchFishs.length) {
Game.getIns().state = GAME_STATE.OVER;
return pg.event.emit("game_time_over");
}
let list = this.list.filter((li) => this.touchFishs.every(t => t.id != li.id));
if (list.every(li => !li.right)) {
Game.getIns().state = GAME_STATE.OVER;
return pg.event.emit("game_time_over");
}
this.lastCount = count;
list = list.filter((li) => this.viewFishs.every(v => v.id != li.id));
if (list.length == 0) return null;
let data = JSON.parse(JSON.stringify(list[count % list.length]));
data.fish.isLeft = Math.random() < 0.5;
let item_base = data.fish.isLeft ? this.item_left : this.item_right;
let item = cc.instantiate(item_base);
this.updateFish(item, data);
this.viewFishs.push(data);
return item;
}
private fishCount: number;
private lastY: number;
updateFish(item, data: Option) {
pg.view.touchOn(item, this.onTouchItem, this);
if (!this.fishCount) this.fishCount = 0;
let id = this.fishCount % 5 + 1;
this.fishCount++;
pg.view.visible(pg.view.find(item, 'fish/icon_fish1'), id == 1);
pg.view.visible(pg.view.find(item, 'fish/icon_fish2'), id == 2);
pg.view.visible(pg.view.find(item, 'fish/icon_fish3'), id == 3);
pg.view.visible(pg.view.find(item, 'fish/icon_fish4'), id == 4);
pg.view.visible(pg.view.find(item, 'fish/icon_fish5'), id == 5);
item.parent = this.node;
item.data = data;
data.fish.node = item;
//渲染部分
if (data.type == "txt") {
pg.view.visible(pg.view.find(item, 'layout_text'), true);
pg.view.visible(pg.view.find(item, 'layout_img'), false);
pg.view.setString(pg.view.find(item, "layout_text/text"), data.txt);
} else {
pg.view.visible(pg.view.find(item, 'layout_text'), false);
pg.view.visible(pg.view.find(item, 'layout_img'), true);
pg.view.setNetImg(pg.view.find(item, 'layout_img/img'), data.picUrl, { w: 118, h: 110 })
}
//x y 起始点 和终点 进行 随机
cc.Tween.stopAllByTarget(item);
let random = 0;
do {
random = Math.floor(Math.random() * 8)
} while (random == this.lastY)
this.lastY = random;
if (data.fish.isLeft) {
//左往右
item.x = -(1334 / 2 + Math.random() * 200)
item.y = -290 + random * 60;//
cc.tween(item).to(7 + Math.random() * 8, { x: 1500 }).call(() => {
data.fish.isOut = FISH_OUT.OUT;
this.viewFishs = this.viewFishs.filter(v => v.id != data.id);
}).start();
} else {
//右往左
item.x = (1334 / 2) + Math.random() * 200;
item.y = -290 + random * 60;
cc.tween(item).to(7 + Math.random() * 8, { x: -1500 }).call(() => {
data.fish.isOut = FISH_OUT.OUT;
this.viewFishs = this.viewFishs.filter(v => v.id != data.id);
}).start();
}
}
private touching: boolean;
private fishAudioId;
fishingRight(item, layout, data: Option) {
return new Promise(async (resolve, reject) => {
let wave = pg.view.find(layout, 'wave')
wave.active = true;
let text = pg.view.find(layout, "text");
text.active = true;
pg.audio.stopAudio(this.fishAudioId);
if (data.audioUrl)
this.fishAudioId = await pg.audio.playAudioByUrl(data.audioUrl)
cc.tween(item)
.to(1, { x: layout.x, y: layout.y + wave.y, scaleX: item.scaleX * 0.1, scaleY: item.scaleY * 0.1 }).call(() => {
//处理内容
data.fish.isOut = FISH_OUT.OUT;
wave.active = false;
text.active = false;
this.touching = false;
item.active = false;
resolve('');
}).start();
});
}
fishingError(item, layout, data) {
return new Promise((resolve, reject) => {
pg.audio.playLocalAudio(pg.view.find(this.res, "audio/error"))
if (data.fish.isLeft) {
//左往右
cc.tween(item).to(3, { x: 1500 }).call(() => {
data.fish.isOut = FISH_OUT.OUT;
item.active = false;
setTimeout(() => { item.parent = null; }, 1000);
if (this.touchFishs.every(fish => fish.id != data.id)) {
resolve('');
}
}).start();
} else {
//右往左
cc.tween(item).to(3, { x: -1500 }).call(() => {
data.fish.isOut = FISH_OUT.OUT;
item.active = false;
setTimeout(() => { item.parent = null; }, 1000);
if (this.touchFishs.every(fish => fish.id != data.id)) {
resolve('');
}
}).start();
}
setTimeout(() => { this.touching = false; }, 500);
});
}
fishing(item, layout) {
return new Promise(async (resolve, reject) => {
let data = item.data;
//item停止动画并
cc.Tween.stopAllByTarget(item);
if (data.right) {
await this.fishingRight(item, layout, data);
} else {
await this.fishingError(item, layout, data);
}
this.touchFishs.push(data);
return resolve(data.right);
});
}
//开始点击 点击角色
async onTouchItem(e) {
if (this.touching) return;
// this.touching = true;
let item = e.target;
let data = item.data;
if (this.touchFishs.some(fish => fish.id == data.id)) return;
if (data.fish.isOut != FISH_OUT.RUNNING) return;
data.fish.isOut = FISH_OUT.TOUCH;
// let isRight = await this.fishing(item, this.layout_player);
// isRight && Game.getIns().player.addScore();
// !isRight && Game.getIns().player.addError();
}
get fishLen() {
if (!this.fishs) return 999;
let arr = this.fishs.filter(item => {
let data: Option = item.data;
return data.fish.isOut == FISH_OUT.RUNNING;
})
this.fishs = arr;
return this.fishs.length;
}
private updateTime: number;
private updateCratTime: number;
update(dt) {
let nowTime = new Date().getTime();
if (!this.updateTime) this.updateTime = nowTime;
if (nowTime - this.updateTime < 1000) return;
this.updateTime = nowTime;
if (Game.getIns().state != GAME_STATE.RUNNING) return;
if (this.fishLen < 5) this.count++;
if (!this.updateCratTime) this.updateCratTime = nowTime - 3000;
if (nowTime - this.updateCratTime < 3000) return;
let fish = this.getFishByCount(this.count);
if (fish) this.fishs.push(fish);
}
}
// Learn TypeScript:
// - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
// - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
// - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
import Game, { GAME_STATE } from "../tool/Game";
import pg from "../tool/pg";
pg.event.clear();
const { ccclass, property } = cc._decorator;
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
private btn_laba: cc.Node;
private countDown: number = 999;
@property
text: string = 'hello';
// LIFE-CYCLE CALLBACKS:
onLoad() {
this.initView();
this.initEvent();
}
private initEvent() {
pg.event.on("game_start", () => {
this.gameStart();
});
this.btn_laba.on(cc.Node.EventType.TOUCH_END, this.playLaba, this);
}
private gameStart() {
// this.showRound();
this.playLaba();
}
private initView() {
this.btn_laba = cc.find("btn_laba", this.node);
}
private intervalId;
private playing: boolean;
private playLaba() {
if (this.playing) return;
this.playing = true;
let btn_kaba2 = this.btn_laba.getChildByName("btn_laba2");
let btn_kaba3 = this.btn_laba.getChildByName("btn_laba3");
btn_kaba2.active = true;
btn_kaba3.active = true;
let count = 0;
if (this.intervalId) clearInterval(this.intervalId);
let stop = false;
this.intervalId = setInterval(() => {
count++;
btn_kaba2.active = count % 3 == 1;
btn_kaba3.active = count % 3 == 2;
if (stop && count % 3 == 2) {
this.playing = false;
clearInterval(this.intervalId);
}
}, 150);
pg.audio.playAudioByUrlThen(Game.getIns().getCurrentPage().audio).then(() => {
stop = true;
})
}
update(dt) { }
}
{
"ver": "1.0.8",
"uuid": "949481d6-a62e-404e-add4-b946b4083d14",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
const { ccclass, property } = cc._decorator; const { ccclass, property } = cc._decorator;
@ccclass @ccclass
export default class NewClass extends cc.Component { export default class netscale extends cc.Component {
@property @property
firstUp: boolean = true; firstUp: boolean = true;
......
This diff is collapsed.
...@@ -46,6 +46,7 @@ export default class SceneComponent extends MyCocosSceneComponent { ...@@ -46,6 +46,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
Game.getIns().init(this.data); Game.getIns().init(this.data);
Game.getIns().reset(); Game.getIns().reset();
this.touching = null; this.touching = null;
pg.event.emit('mouse_05_num', Game.getIns().getFishList().length)
} }
private audioId: any; private audioId: any;
async initView() { async initView() {
......
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