Commit ca6a8d11 authored by Tt's avatar Tt

位移和碰撞处理完成

parent 8fe40ab4
...@@ -133,12 +133,73 @@ cc.Class({ ...@@ -133,12 +133,73 @@ cc.Class({
//---------------------------------项目代码开始--------------------------------- //---------------------------------项目代码开始---------------------------------
loadEnd() { loadEnd() {
this.initData(); // this.initData();
this.initSingleData(); // this.initSingleData();
this.initAudio(); // this.initAudio();
this.initView(); // this.initView();
// this.initListener(); this.initButton();
},
initButton() {
//触碰判断
let item = pg.view.find(this, "items/item");
item.on(cc.Node.EventType.TOUCH_START, this.onStartItem, this);
item.on(cc.Node.EventType.TOUCH_END, this.onEndItem, this);
item.on(cc.Node.EventType.TOUCH_MOVE, this.onMoveItem, this);
item.on(cc.Node.EventType.TOUCH_CANCEL, this.onCancelItem, this);
},
onStartItem(touch) {
this._startPos = cc.v2(touch.target.x, touch.target.y);
let touchPos = touch.getLocation();
touch.target.x = touchPos.x - 1280 / 2;
touch.target.y = touchPos.y - 720 / 2;
},
onEndItem(touch) {
let box_0 = pg.view.find(this, "box/box_0");
//检测碰撞
if (this.checkCollider(touch.target, box_0)) {
} else {
//碰撞失败退回原位置
touch.target.x = this._startPos.x;
touch.target.y = this._startPos.y;
}
},
onMoveItem(touch) {
//获取到的location是 当前点击的位置 而不是按钮原本应该所在的位置。
let touchPos = touch.getLocation();
touch.target.x = touchPos.x - 1280 / 2;
touch.target.y = touchPos.y - 720 / 2;
},
onCancelItem(touch) {
console.log(touch);
}, },
checkCollider(item, box) {
return item.x > box.x - box.width / 2
&& item.x < box.x + box.width / 2
&& item.y > box.y - box.height / 2
&& item.y < box.y + box.height / 2;
},
//全局游戏 //全局游戏
_gameCode: null, _gameCode: null,
initData() { initData() {
......
//底部items
class Card {
constructor(picItem, cardId) {
this.cardId = cardId;
this.type = GameManager.TYPE_NULL;
if (picItem.radioValue == "A" && picItem.title) {
this.txt = picItem.title;
this.type = GameManager.TYPE_TXT;
} else if (picItem.radioValue == "B" && picItem.pic_url) {
this.img = picItem.pic_url;
this.type = GameManager.TYPE_IMG;
} else if (picItem.radioValue == "C" && picItem.audio_url) {
this.audio = picItem.audio_url;
this.type = GameManager.TYPE_MP3;
}
}
}
class defClass {
constructor(id, name, dep) {
this.id = id;
this.dep = dep;
this.name = name;
this.child = [];
}
addChild(child) {
this.child.push(child);
}
isChild(childId) {
return this.child.some(ch => ch.id == childId);
}
}
// class MainClass extends defaultClass {
// constructor(id, name) {
// this.id = id;
// this.name = name;
// }
// parseData() {
// }
// }
class GameManager {
static TYPE_NULL = 0;
static TYPE_TXT = 1;
static TYPE_IMG = 2;
static TYPE_MP3 = 3;
static instance;
static getIns() {
if (!GameManager.instance) GameManager.instance = new GameManager();
return GameManager.instance;
}
constructor() {
//主类 1
this._allClass = [];
this._sonArray = [];//卡片数据解析
this._cardArray = [];//卡片数据解析
}
init() {
console.log(`init`);
this.parseData();
}
parseData() {
let obj = [{
id: 0, name: "zhulei", child: [
{
id: 10,
name: "fenlei1",
child: [
{
id: 101,
name: "sonlei1",
child: [
{
id: 1001,
name: "card1",
title: "卡片1001",
radioValue: "A"
},
{
id: 1002,
name: "card2",
title: "卡片1002",
radioValue: "A"
},
{
id: 1003,
name: "card3",
title: "卡片1003",
radioValue: "A"
},
{
id: 1004,
name: "card4",
title: "卡片1004",
radioValue: "A"
}
]
}
]
}
]
}];
let fenId = 1;
let sonId = 100;
let cardId = 1000;
for (let i = 0; i < obj.length; i++) {
let zhulei = obj[i];
let zhuleiClass = new defClass(zhulei.id, zhulei.name, 0);
for (let a = 0; a < zhulei.child.length; a++) {
let fenlei = zhulei.child[a];
let fenleiClass = new defClass(fenId, fenlei.name, 1);
fenId++;//只有1和2
for (let b = 0; b < fenlei.child.length; b++) {
sonId++;
let sonlei = fenlei.child[b];
let sonleiClass = new defClass(sonId, sonlei.name, 2);
for (let c = 0; c < sonlei.child.length; c++) {
let card = sonlei.child[c];
cardId++;
let cardClass = new Card(card, cardId);
sonleiClass.addChild(cardClass);
this._cardArray.push(cardClass);
}
fenleiClass.addChild(sonleiClass);
}
sonId += 100;
zhuleiClass.addChild(fenleiClass);
}
this._allClass.push(zhuleiClass);
}
console.log(this._allClass);
}
getZhuClass() {
return this._allClass[0];
}
getFenClass(id) {
return this._allClass[0].filter(fen => fen.id == id)[0];
}
getSonClass(id) {
return this._sonArray.filter(son => son.id == id)[0];
}
getCards() {
//基础卡片列表
return this._cardArray;
}
compareCard(cardId, sonId) {
let sonClass = this.getSonClass(sonId);
return sonClass.isChild(cardId);
}
}
// []zhuclass
// [] []fenclass
//[] [] [] [] [] []sonclass
//[] [] [] [] [] []sonclass
//() () () () () () () ()card
//() () () () () () () ()
//() () () () () () () ()
\ No newline at end of file
{
"ver": "1.0.8",
"uuid": "2f000cc9-5e11-497b-b268-3dced7dde2a9",
"isPlugin": false,
"loadPluginInWeb": true,
"loadPluginInNative": true,
"loadPluginInEditor": false,
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "0b2e3cdb-a1d7-4020-aa87-b561d2e12959",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "616558ee-72d8-4979-a2ee-83d2f5ae7600",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{ {
"ver": "2.3.5", "ver": "2.3.5",
"uuid": "6ba0ab66-ad01-4b87-bb56-5966ab7f5744", "uuid": "94e8fd64-848f-4ab0-aeb5-6e25fe1b7fe8",
"type": "sprite", "type": "sprite",
"wrapMode": "clamp", "wrapMode": "clamp",
"filterMode": "bilinear", "filterMode": "bilinear",
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
"height": 720, "height": 720,
"platformSettings": {}, "platformSettings": {},
"subMetas": { "subMetas": {
"bg_bg": { "invalid-name": {
"ver": "1.0.4", "ver": "1.0.4",
"uuid": "d60de1cb-9c7d-4e45-8fa8-c10404cdfefd", "uuid": "f5df3f59-f45c-4611-84bf-7b3708bec211",
"rawTextureUuid": "6ba0ab66-ad01-4b87-bb56-5966ab7f5744", "rawTextureUuid": "94e8fd64-848f-4ab0-aeb5-6e25fe1b7fe8",
"trimType": "auto", "trimType": "auto",
"trimThreshold": 1, "trimThreshold": 1,
"rotated": false, "rotated": false,
......
{
"ver": "2.3.5",
"uuid": "dd0dc7c5-e5a6-4242-bad2-3dbe9c26da5a",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1280,
"height": 629,
"platformSettings": {},
"subMetas": {
"invalid-name_2": {
"ver": "1.0.4",
"uuid": "01d5767c-e6fc-48d5-a05b-ef680212f0d9",
"rawTextureUuid": "dd0dc7c5-e5a6-4242-bad2-3dbe9c26da5a",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1280,
"height": 629,
"rawWidth": 1280,
"rawHeight": 629,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "a3541557-1475-4a71-8809-44f8262ec2f2",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 502,
"height": 115,
"platformSettings": {},
"subMetas": {
"title_bg": {
"ver": "1.0.4",
"uuid": "ca14e2fd-63e3-4c46-8eec-91fd20af5f60",
"rawTextureUuid": "a3541557-1475-4a71-8809-44f8262ec2f2",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 502,
"height": 115,
"rawWidth": 502,
"rawHeight": 115,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "1.1.2",
"uuid": "137087ea-eeb7-4679-ae78-2658af9840cf",
"isBundle": false,
"bundleName": "",
"priority": 1,
"compressionType": {},
"optimizeHotUpdate": {},
"inlineSpriteFrames": {},
"isRemoteBundle": {},
"subMetas": {}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "3dfdbb29-4a4a-4c0e-bdc5-1154dde83d4e",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 430,
"height": 68,
"platformSettings": {},
"subMetas": {
"combined-shape_3": {
"ver": "1.0.4",
"uuid": "39ce2398-164a-4dba-829f-646ed523cd4a",
"rawTextureUuid": "3dfdbb29-4a4a-4c0e-bdc5-1154dde83d4e",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 430,
"height": 68,
"rawWidth": 430,
"rawHeight": 68,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "86783601-f1d7-434c-8992-48c6fbd2eff7",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 470,
"height": 68,
"platformSettings": {},
"subMetas": {
"combined-shape_4": {
"ver": "1.0.4",
"uuid": "577b0319-8a9a-4503-ab96-f3dd5b000a53",
"rawTextureUuid": "86783601-f1d7-434c-8992-48c6fbd2eff7",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 470,
"height": 68,
"rawWidth": 470,
"rawHeight": 68,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "5957cfce-76c9-4a29-9dc4-428c42ee8b0a",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 163,
"height": 185,
"platformSettings": {},
"subMetas": {
"group-4-copy-2": {
"ver": "1.0.4",
"uuid": "7cffa85e-7b5a-48a2-b387-48ae1288c639",
"rawTextureUuid": "5957cfce-76c9-4a29-9dc4-428c42ee8b0a",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 163,
"height": 185,
"rawWidth": 163,
"rawHeight": 185,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "3091ec1a-b7a4-45eb-b256-d8c2a193ebee",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 80,
"height": 48,
"platformSettings": {},
"subMetas": {
"icon": {
"ver": "1.0.4",
"uuid": "405a5ae7-9f20-4d23-8681-455a17ac3514",
"rawTextureUuid": "3091ec1a-b7a4-45eb-b256-d8c2a193ebee",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 80,
"height": 48,
"rawWidth": 80,
"rawHeight": 48,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "b11d8ba1-b5ee-4501-8494-40c16bf1fff0",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 208,
"height": 88,
"platformSettings": {},
"subMetas": {
"oval-18": {
"ver": "1.0.4",
"uuid": "817eb1a2-dace-4cc4-8f23-4a03b692dbb6",
"rawTextureUuid": "b11d8ba1-b5ee-4501-8494-40c16bf1fff0",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 208,
"height": 88,
"rawWidth": 208,
"rawHeight": 88,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "ca8e8657-8ded-4f81-a171-239170e223f4",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 186,
"height": 75,
"platformSettings": {},
"subMetas": {
"oval-2-copy-10": {
"ver": "1.0.4",
"uuid": "49454315-2fbc-49d7-980b-03990d784088",
"rawTextureUuid": "ca8e8657-8ded-4f81-a171-239170e223f4",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 186,
"height": 75,
"rawWidth": 186,
"rawHeight": 75,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "25b579dd-7802-4de9-a253-282c55d5fa76",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 186,
"height": 75,
"platformSettings": {},
"subMetas": {
"oval-2-copy-9": {
"ver": "1.0.4",
"uuid": "43bb4581-6acd-4928-9a46-b10ee983cb60",
"rawTextureUuid": "25b579dd-7802-4de9-a253-282c55d5fa76",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 186,
"height": 75,
"rawWidth": 186,
"rawHeight": 75,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "02d43794-a798-430f-96e6-82162b8f8f3d",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 154,
"height": 86,
"platformSettings": {},
"subMetas": {
"oval-2-copy": {
"ver": "1.0.4",
"uuid": "14e8da8f-dacf-4974-a738-0b9bc5747dac",
"rawTextureUuid": "02d43794-a798-430f-96e6-82162b8f8f3d",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 154,
"height": 86,
"rawWidth": 154,
"rawHeight": 86,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
{
"ver": "2.3.5",
"uuid": "90223791-6f4b-48c5-84ba-379025b709bf",
"type": "sprite",
"wrapMode": "clamp",
"filterMode": "bilinear",
"premultiplyAlpha": false,
"genMipmaps": false,
"packable": true,
"width": 1201,
"height": 679,
"platformSettings": {},
"subMetas": {
"view": {
"ver": "1.0.4",
"uuid": "59ca3150-1f56-4f3e-908c-3c22e870861c",
"rawTextureUuid": "90223791-6f4b-48c5-84ba-379025b709bf",
"trimType": "auto",
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1201,
"height": 679,
"rawWidth": 1201,
"rawHeight": 679,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"subMetas": {}
}
}
}
\ No newline at end of file
This diff is collapsed.
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