Commit c55a89be authored by Tt's avatar Tt

项目一级完成

parent a423628a
This diff is collapsed.
......@@ -2,9 +2,17 @@ import { asyncDelay, onHomeworkFinish } from "../script/util";
import { MyCocosSceneComponent } from "../script/MyCocosSceneComponent";
import { Item, Part, Game } from "./model/game";
import pg from "./pg";
import Ani from "./ani";
const { ccclass, property } = cc._decorator;
enum STATE {
WAITING,
AUDIOING,
GUIDING,
AUDIOED,
GAMING,
GAMED
}
@ccclass
export default class SceneComponent extends MyCocosSceneComponent {
......@@ -47,10 +55,16 @@ export default class SceneComponent extends MyCocosSceneComponent {
}
onBtnStart() {
let btn_start: cc.Node = pg.view.find(this, "btn_start");
//执行开始单个游戏开始
cc.tween(btn_start).by(0.3, { x: 1500 }).call(() => {
this.updateState(1);
}).start();
}
nextPart() {
Game.getIns().current++;
this.updateState(1);
}
updateState(state) {
switch (state) {
case 0:
......@@ -71,66 +85,91 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.updatePartPercent();
}
private part: Part;
private playing: number;
initPartData() {
this.part = Game.getIns().part;
this.playing = STATE.WAITING;
}
updatePart() {
if (!this.part) return;
pg.view.visible(pg.view.find(this, "btn_start"), false);
pg.view.visible(pg.view.find(this, "panel_gary"), false);
pg.view.visible(pg.view.find(this, "btn_stem/icon_hand"), true);
this.updatePartPercent();
this.updateBtnStem();
this.updateList();
this.updatePerson();
}
updateBtnStem() {
updateBtnStem(isPlay: boolean = false) {
let btn_stem: cc.Node = pg.view.find(this, "btn_stem");
pg.view.visible(btn_stem, true);
let btn_stem_audio: cc.Node = pg.view.find(this, "btn_stem_ani");
pg.view.visible(btn_stem, !isPlay);
pg.view.visible(btn_stem_audio, isPlay);
}
private a;
onBtnStem() {
if (this.playing != STATE.WAITING) return;
//播放音效,允许后续操作。
this.playing = STATE.AUDIOING;
let btn_stem: cc.Node = pg.view.find(this, "btn_stem");
pg.view.visible(pg.view.find(btn_stem, "icon_hand"), false);
this.updateBtnStem(true);
pg.audio.playAudioByUrl(this.part.stemAudio).then(() => {
if (!this.a) {
this.a = true;
this.playing = STATE.GUIDING;
this.updatePersonGuide();
} else {
this.playing = STATE.AUDIOED;
}
this.updateBtnStem(false);
})
}
updateList() {
pg.view.visible(pg.view.find(this, "layout_items"), true)
//根据partlist渲染svt内容
// let scroll = pg.view.find(this.shop, "scrollview");
// let svt = scroll.getComponent("svt");
// let list = kitchen.getListByType(this.shopType);
// svt.list = list;
// svt.updateItem = this.updateShopItems;
// svt.target = this;
// svt.addNum = 4;
// svt.flush();
let layout_items = pg.view.find(this, "layout_items");
let items = layout_items.children;
items.sort((A, B) => {
return A.x - B.x;
})
let list = this.part.list;
for (let i = 0; i < items.length; i++) {
let item = items[i];
let data = list[i];
if (!data) {
item.active = false;
continue;
} else {
this.updateShopItem(item, data);
}
}
layout_items.y += 1000;
cc.tween(layout_items).by(0.3, { y: -1000 }).start();
}
updateShopItem(item, data: Item) {
// item.active = true;
// let growth = pg.view.find(item, "growth");
// let txt = pg.view.find(item, "txt");
// let name = pg.view.find(item, "name");
// let icon = pg.view.find(item, "icon");
// let discount = pg.view.find(item, "discount");
// let btn_buy = pg.view.find(item, "btn_buy");
// pg.view.setString(txt, `可增加 个成长值`)
// pg.view.setString(growth, data.growthValue)
// pg.view.setString(name, data.name)
// icon.getComponent(cc.Sprite).spriteFrame = this[data.icon];
// let dis = Math.round((1 - data.discount) * 100);
// if (dis > 0) {
// pg.view.setString(discount, `${dis}%`)
// pg.view.visible(pg.view.find(item, "bg_sale"), true);
// pg.view.visible(pg.view.find(item, "discount"), true);
// } else {
// pg.view.visible(pg.view.find(item, "bg_sale"), false);
// pg.view.visible(pg.view.find(item, "discount"), false);
// }
// pg.view.setString(pg.view.find(btn_buy, "num"), data.cost)
// pg.view.touchOn(btn_buy, this.onTouchShopItem, this);
// item.data = data;
item.active = true;
let bg_board = pg.view.find(item, "bg_board");
let bg_board_down = pg.view.find(item, "bg_board_down");
let icon_arrow = pg.view.find(item, "icon_arrow");
let img_pic = pg.view.find(item, "img_pic");
let label_percent = pg.view.find(item, "label_percent");
pg.view.visible(bg_board, true);
pg.view.visible(bg_board_down, false);
pg.view.visible(icon_arrow, false);
if (data.type == "pic") {
pg.view.visible(img_pic, true);
pg.view.visible(label_percent, false);
pg.view.setNetImg(img_pic, data.pic, { w: 350, h: 240 })
} else {
pg.view.visible(img_pic, false);
pg.view.visible(label_percent, true);
pg.view.setString(label_percent, data.text);
}
item.data = data;
}
updatePerson() {
let img_person: cc.Node = pg.view.find(this, "img_person");
......@@ -141,8 +180,26 @@ export default class SceneComponent extends MyCocosSceneComponent {
img_person.on(cc.Node.EventType.TOUCH_MOVE, this.onImgPersonMove, this);
img_person.on(cc.Node.EventType.TOUCH_END, this.onImgPersonEnd, this);
img_person.y -= 1000;
cc.tween(img_person).by(0.3, { y: 1000 }).start();
}
updatePersonGuide() {
let img_person: cc.Node = pg.view.find(this, "img_person");
img_person.active = true;
img_person.x = 0;
img_person.y = -300;
img_person.scale = 1;
pg.view.visible(pg.view.find(img_person, "icon_hand"), true);
cc.tween(img_person).by(0.7, { x: -600 }).by(0.7, { x: 600 }).call(() => {
pg.view.visible(pg.view.find(img_person, "icon_hand"), false);
this.playing = STATE.AUDIOED;
}).start();
}
onImgPersonMove(e) {
if (this.playing != STATE.AUDIOED) return;
let currentTouch = e.currentTouch;
let pos = currentTouch.getLocation();
//移动效果
......@@ -158,14 +215,18 @@ export default class SceneComponent extends MyCocosSceneComponent {
pg.view.visible(pg.view.find(item, "icon_arrow"), true);
}
onImgPersonEnd(e) {
//结束判断
let item: Item = Game.getIns().part.getItemByX(e.x);
if (item.right) {
if (this.playing != STATE.AUDIOED) return;
let currentTouch = e.currentTouch;
let pos = currentTouch.getLocation();
let img_person: cc.Node = pg.view.find(this, "img_person");
img_person.x = pos.x - (cc.winSize.width / 2);
let item: any = this.getItemByX(img_person.x);
if (item.data.right) {
//处理正确
this.itemRight(item);
} else {
//处理错误
this.itemError(item);
}
}
updateArrow(x) {
......@@ -178,11 +239,44 @@ export default class SceneComponent extends MyCocosSceneComponent {
img_arrow.active = true;
}
itemRight(item) {
let img_person: cc.Node = pg.view.find(this, "img_person");
cc.tween(img_person).to(1, {
scale: 0.8, x: item.x, y: -0
}).delay(0.1).call(() => {
let layout_items = pg.view.find(this, "layout_items");
layout_items.active = false;
}).start();
setTimeout(() => {
let bg_board = pg.view.find(item, "bg_board");
let bg_board_down = pg.view.find(item, "bg_board_down");
let icon_arrow = pg.view.find(item, "icon_arrow");
let img_pic = pg.view.find(item, "img_pic");
let label_percent = pg.view.find(item, "label_percent");
pg.view.visible(bg_board, false);
pg.view.visible(bg_board_down, true);
pg.view.visible(icon_arrow, false);
pg.view.visible(img_pic, false);
pg.view.visible(label_percent, false);
}, 700);
setTimeout(() => {
this.nextPart();
}, 1700);
}
itemError(item) {
Ani.shake(item)
let bg_board = pg.view.find(item, "bg_board");
let bg_board_down = pg.view.find(item, "bg_board_down");
let icon_arrow = pg.view.find(item, "icon_arrow");
let img_pic = pg.view.find(item, "img_pic");
let label_percent = pg.view.find(item, "label_percent");
pg.view.visible(icon_arrow, false);
}
updatePartPercent() {
let label_percent: cc.Node;
let label_percent: cc.Node = pg.view.find(this, "panel_percent/label_percent");
pg.view.setString(label_percent, `${Game.getIns().part.id + 1} / ${Game.getIns().list.length}`);
}
......@@ -226,7 +320,6 @@ export default class SceneComponent extends MyCocosSceneComponent {
playLocalAudio(audioName) {
const audio = cc.find(`Canvas/res/audio/${audioName}`).getComponent(cc.AudioSource);
return new Promise((resolve, reject) => {
......
class Ani {
//抖动效果
static shake(item) {
// alert("抖动效果");
let tween = cc.tween(item);
tween.to(0.06, { angle: 10 })
.to(0.06, { angle: 0 })
.to(0.06, { angle: -10 })
.to(0.06, { angle: 0 });
tween.repeat(4);
tween.start();
}
static scaleOut(item) {
return new Promise<void>((resolve) => {
let tween = cc.tween(item);
tween.to(0.2, { scaleX: 0, scaleY: 0 })
.call(() => { resolve() });
tween.start();
})
}
static scaleIn(item) {
return new Promise<void>((resolve) => {
item.scaleX = 0;
item.scaleY = 0;
let tween = cc.tween(item);
tween.to(0.2, { scaleX: 1, scaleY: 1 })
.call(() => { resolve() });
tween.start();
})
}
static flipX0(item) {
return new Promise<void>((resolve) => {
let itemScale = item.scaleY;
item.scaleX = itemScale;
let tween = cc.tween(item);
tween.to(0.2, { scaleX: 0 })
.call(() => { resolve() });
tween.start();
})
}
static flipX1(item) {
return new Promise<void>((resolve) => {
let itemScale = item.scaleY;
item.scaleX = 0;
let tween = cc.tween(item);
tween.to(0.2, { scaleX: itemScale })
.call(() => { resolve() });
tween.start();
})
}
}
export default Ani;
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "272bbc82-f59c-4e0c-bb1c-4bfb2f73d7eb",
"uuid": "64eb8107-35f5-4a7b-b757-eec007f52ca4",
"isPlugin": false,
"loadPluginInWeb": 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
const { ccclass, property } = cc._decorator;
import pg from "./pg";
@ccclass
export default class NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
// LIFE-CYCLE CALLBACKS:
private count = 0;
onLoad() {
this.count = 0;
}
start() {
}
update(dt) {
this.count++;
this.updateItems();
}
updateItems() {
let cur = Math.floor(this.count / 30) % 4
for (let i = 0; i < 4; i++) {
let item = pg.view.find(this, "btn_audio" + i);
item.active = cur == i;
}
}
}
{
"ver": "1.0.8",
"uuid": "37c492e3-1b92-4db5-b6be-802ecc1c0ecb",
"uuid": "aec14924-cd0c-4952-ac8e-0d100cc6bc07",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
......
{
"ver": "1.1.2",
"uuid": "93a9f04e-84ed-4b5f-99fd-17fcb6abe8ca",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
const ITEMS = [
{
id: 1001,
type: 1,//食物
name: "苹果",
icon: "icon_1",
growthValue: 10,
cost: 100,
discount: 0.8,
num: 3,
levelLimite: 1,
},
{
id: 1002,
type: 1,//食物
name: "香蕉",
icon: "icon_2",
growthValue: 15,
cost: 120,
discount: 1,
num: 5,
levelLimite: 2,
}, {
id: 1003,
type: 1,//食物
name: "面包",
icon: "icon_3",
growthValue: 20,
cost: 150,
discount: 1,
num: 8,
levelLimite: 1,
}, {
id: 1004,
type: 1,//食物
name: "胡萝卜",
icon: "icon_4",
growthValue: 30,
cost: 200,
discount: 1,
num: 9,
levelLimite: 1,
}, {
id: 1005,
type: 1,//食物
name: "奶酪",
icon: "icon_5",
growthValue: 40,
cost: 230,
discount: 1,
num: 13,
levelLimite: 1,
}, {
id: 1006,
type: 1,//食物
name: "橙子",
icon: "icon_6",
growthValue: 50,
cost: 270,
discount: 1,
num: 1,
levelLimite: 1,
}, {
id: 1007,
type: 1,//食物
name: "披萨",
icon: "icon_7",
growthValue: 90,
cost: 400,
discount: 1,
num: 0,
levelLimite: 1,
}, {
id: 1008,
type: 1,//食物
name: "西红柿",
icon: "icon_8",
growthValue: 100,
cost: 600,
discount: 1,
num: 0,
levelLimite: 1,
}
]
const LEVEL = {
level_1: {
growth: 100,
},
level_2: {
growth: 300,
},
level_3: {
growth: 600,
},
level_4: {
growth: 1000,
},
level_5: {
growth: 1500,
},
level_6: {
growth: 2100,
}
}
const USER = {
name: "小小香香",
coin: 100023,
level: 2,
growth: 30,
growthDaily: 0,
growthDailyMax: 100,
eatTime: new Date().getTime(),
useFurniture: [],
useClothes: [],
mood: "开心"
}
enum ITEM_TYPE {
FOOD = 1,
HOUSE = 2,
CLOTHES = 3
}
export { USER, LEVEL, ITEMS, ITEM_TYPE }
\ No newline at end of file
// 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 NewClass extends cc.Component {
@property(cc.Label)
label: cc.Label = null;
@property
text: string = 'hello';
// LIFE-CYCLE CALLBACKS:
// onLoad () {}
start() {
this.showAni();
}
showAni() {
this.node.x += 400;
this.node.y -= 200;
cc.tween(this.node).by(0.3, { x: -400, y: 200 }).start();
setTimeout(() => {
this.showAni();
}, 2000);
}
// update (dt) {}
}
{
"ver": "1.0.8",
"uuid": "c7a342c3-a336-4d8a-aada-d97dc59c1ae2",
"uuid": "464949cc-399a-4fbc-833b-1d269aca1069",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
......
......@@ -66,19 +66,16 @@ export class Game {
return Game.instance;
}
private _list: Array<any>;
private _current: number;
public current: number;
constructor() {
this._list = [];
this._current = 0;
this.current = 0;
}
public init(data) {
this.list = data.list;
}
public get part(): Part {
return this.list[this._current];
}
public set current(val) {
this._current = val;
return this.list[this.current];
}
public set list(val) {
this._list = val.map(li => {
......
class Item {
public id: number;//id
public type: number;//商品类型
public name: string;//商品名称
public icon: string;//商品图片--可用type生成
public growthValue: number;//生长值
public cost: number;//费用
public discount: number;//折扣
public num: number;//拥有数量
public levelLimite: number;//等级限制
constructor(obj: any) {
this.id = obj.id;
this.type = obj.type;
this.name = obj.name;
this.icon = obj.icon;
this.growthValue = obj.growthValue;
this.cost = obj.cost;
this.discount = obj.discount;
this.num = obj.num;
this.levelLimite = obj.levelLimite;
}
}
export default Item;
\ No newline at end of file
import Item from "./item"
class Kitchen {
private _list: Array<Item>
constructor() {
this._list = [];
}
use(id) {
this._list = this._list.map(li => {
if (li.id == id) li.num -= 1;
return li;
})
}
buy(id) {
this._list = this._list.map(li => {
if (li.id == id) li.num += 1;
return li;
})
}
getListByType(type: number) {
return this._list.filter(li => li.type == type)
}
parse(list: any) {
if (!list) return;
this._list = list.map(li => { return new Item(li); })
}
get list() {
return this._list;
}
}
let kitchen = new Kitchen();
export default kitchen;
{
"ver": "1.0.8",
"uuid": "1ab727dc-af13-4539-a98a-4ec85d8981c9",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
import Item from "./item"
class Shop {
public _list: Array<Item>
constructor() {
this._list = [];
}
parse(list: any) {
if (!list) return;
this._list = list.map(li => {
return new Item(li);
})
}
get list() {
return this._list;
}
}
export default Shop;
import { LEVEL } from "../config/config";
class User {
public name: string;
public coin: number;
public level: number;
public growth: number;//当前成长值
public growthDaily: number;
public growthDailyMax: number;
public eatTime: number;
public useFurniture: Array<number>;
public useClothes: Array<number>;
public mood: number;//0开心 1不开心
constructor() {
}
parse(data) {
this.name = data.name;
this.coin = data.coin;
this.level = data.level;
this.growth = data.growth;
this.growthDaily = data.growthDaily;
this.growthDailyMax = data.growthDailyMax;
this.eatTime = data.eatTime;
this.useFurniture = data.useFurniture;
this.useClothes = data.useClothes;
this.mood = 1;
}
isDailyMax() {
return this.growthDailyMax >= this.growthDaily
}
addGrowth(val) {
this.growth += val;
this.growthDaily += val;
user.mood = 0;
}
useCoin(val) {
this.coin -= val;
}
//当前等级成长值最大值
public get growthLevel(): number {
let max = 1;
for (let i = 1; i < 100; i++) {
let val = LEVEL[`level_${i}`].growth;
if (this.growth < val) {
max = val
break;
}
}
return max
}
}
let user = new User();
export default user;
// 游戏 : {
// 角色信息:{
// 名字
// 心情:开心|饥饿
// 金币
// 等级
// 成长值
// 每日成长值
// 每日成长值上限
// 上次吃东西的时间
// 当前使用的家具:[书柜,地毯,,,,,]对应的物品id
// 当前穿戴的服饰:[衣服,裤子,,,] 对应的物品id
// }
// 仓库:[
// {
// 物品id
// 物品类型
// 物品数量
// },
// {
// 物品id
// 物品类型
// 物品数量
// }
// ]
// 商城信息:[
// {
// 物品id
// 物品类型
// 名字
// 价格
// 特价
// 等级限制
// },
// ]
// 常量:{
// 物品列表:[
// 物品id
// 物品类型
// 名字
// 图片
// ]
// 等级经验表:{
// 等级
// 所需成长值
// 每日成长上限
// }
// }
// }
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "b09ecb5b-593a-4b9c-aaeb-67e8efc7ebd4",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "bb7f614f-8b91-48f3-a3d2-154872aa3a36",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
import pg from "../pg";
import { ITEMS, USER } from "../config/config"
import user from "../model/user";
import kitchen from "../model/kitchen";
//获取信息,购买物品,使用物品(吃东西),穿戴衣服/更换家具
class Api {
static askUser() {
return new Promise((resolve, reject) => {
pg.http.send("GET", "http://www.baidu.com", {}).then((data: any) => {
let userInfo = USER;
user.parse(userInfo);
let kitchenInfo = ITEMS;
kitchen.parse(kitchenInfo);
resolve('');
})
});
}
static askUseItem(data) {
return new Promise((resolve, reject) => {
pg.http.send("GET", "http://www.baidu.com", {}).then((data: any) => {
user.addGrowth(data.growthValue);
kitchen.use(data.id);
resolve('');
})
});
}
static askBuyItem(data) {
return new Promise((resolve, reject) => {
data.id;
data.type;
pg.http.send("GET", "http://www.baidu.com", {}).then((data: any) => {
user.useCoin(data.cost * data.discount);
kitchen.buy(data.id);
resolve('');
})
});
}
}
export default Api;
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "cc085a9d-0b38-4bde-a0eb-316c806a0a58",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
......@@ -130,7 +130,7 @@ let pg = {
})
})
},
setNetImg(item, res) {
setNetImg(item, res, { w, h }) {
return new Promise((resolve, reject) => {
if (!item) return pg.logger.w("图片更换失败,传入了错误的item");
let node = item.node ? item.node : item;
......@@ -140,8 +140,6 @@ let pg = {
}
if (!node) return pg.logger.w("图片更换失败,传入了错误的item");
if (node.net_url == res) return;
let w = node.width;
let h = node.height;
node.active = false;//
pg.load.loadNetImg(res).then((texture: cc.Texture2D) => {
if (!cc.isValid(node)) return pg.logger.i("节点已销毁");
......@@ -151,13 +149,14 @@ let pg = {
let spriteFrame = new cc.SpriteFrame(texture);
component.spriteFrame = spriteFrame;
node.net_url = res;
// setTimeout(() => {
if (!cc.isValid(node)) return pg.logger.i("节点已销毁");
if (!node) return pg.logger.w("节点已销毁");
node.width = w;
node.height = h;
let scaleX = w / nw;
let scaleY = h / nh;
let scale = scaleX <= scaleY ? scaleX : scaleY;
node.width = nw * scale;
node.height = nh * scale;
node.active = true;
// }, 30);
resolve({ w: nw, h: nh });
})
})
......@@ -351,5 +350,18 @@ let pg = {
}
},
audio: {
playAudioByUrl(audio_url) {
return new Promise((resolve, reject) => {
if (!audio_url) return resolve(null);
cc.assetManager.loadRemote(audio_url, (err, audioClip: cc.AudioClip) => {
const audioId = cc.audioEngine.play(audioClip, false, 0.8);
cc.audioEngine.setFinishCallback(audioId, () => {
resolve(audioClip);
});
});
});
}
}
};
export default pg;
\ No newline at end of file
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