Commit 27ae58d9 authored by 李维's avatar 李维

dev commit

parent a1c07225
...@@ -6,7 +6,9 @@ import { ...@@ -6,7 +6,9 @@ import {
Input, Input,
OnDestroy, OnDestroy,
HostListener HostListener
} from "@angular/core"; } from "@angular/core";
import { UUID } from 'angular2-uuid';
import { import {
MySprite, MySprite,
...@@ -27,7 +29,9 @@ import { ...@@ -27,7 +29,9 @@ import {
scaleItem, scaleItem,
showBlingBling, showBlingBling,
waterWave, waterWave,
jelly jelly,
getAngleByPos,
getPosDistance
} from "./Unit"; } from "./Unit";
import { localImages, localAudios } from "./resources"; import { localImages, localAudios } from "./resources";
...@@ -40,6 +44,9 @@ import TWEEN from "@tweenjs/tween.js"; ...@@ -40,6 +44,9 @@ import TWEEN from "@tweenjs/tween.js";
import defauleFormData from '../../assets/play/default/formData/defaultData.js' import defauleFormData from '../../assets/play/default/formData/defaultData.js'
const zIndexMap = { const zIndexMap = {
cutter: 130,
dot: 120,
line: 115,
longAudioPlay: 110, longAudioPlay: 110,
cardUp: 110, cardUp: 110,
lianzi: 100, lianzi: 100,
...@@ -110,7 +117,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -110,7 +117,7 @@ export class PlayComponent implements OnInit, OnDestroy {
// ------------ 游戏逻辑数据 ------------ // ------------ 游戏逻辑数据 ------------
m_currentSelectedCard = ""
// ------------------------------------ // ------------------------------------
...@@ -184,6 +191,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -184,6 +191,7 @@ export class PlayComponent implements OnInit, OnDestroy {
this.initShowWindow(); this.initShowWindow();
this.initCard_up(); this.initCard_up();
this.initCard_down(); this.initCard_down();
this.initCutter()
} }
cleanGameVar(){ cleanGameVar(){
...@@ -646,6 +654,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -646,6 +654,7 @@ export class PlayComponent implements OnInit, OnDestroy {
let A1 = [] let A1 = []
let A2 = [] let A2 = []
let A3 = [] let A3 = []
let A4 = []
cardAll.forEach((card, index)=>{ cardAll.forEach((card, index)=>{
let pos = {x:0, y:0} let pos = {x:0, y:0}
if(index!=0){ if(index!=0){
...@@ -664,6 +673,7 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -664,6 +673,7 @@ export class PlayComponent implements OnInit, OnDestroy {
A1.push(temp.e1) A1.push(temp.e1)
A2.push(temp.e2) A2.push(temp.e2)
A3.push(temp.e3) A3.push(temp.e3)
A4.push(temp.e4)
}) })
let movedDis =this.alignCenter(A1) let movedDis =this.alignCenter(A1)
A2.forEach(item=>{ A2.forEach(item=>{
...@@ -672,6 +682,9 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -672,6 +682,9 @@ export class PlayComponent implements OnInit, OnDestroy {
A3.forEach(item=>{ A3.forEach(item=>{
item.x = item.x + movedDis item.x = item.x + movedDis
}) })
A4.forEach(item=>{
item.x = item.x + movedDis
})
} }
createCardUp(index, label, pos){ createCardUp(index, label, pos){
...@@ -690,6 +703,32 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -690,6 +703,32 @@ export class PlayComponent implements OnInit, OnDestroy {
} }
}) })
// 连接节点
let dot = this.g_cartoon.createImage("icon_dian1", (w, h)=>{
return {
sx: 37*this.g_mapScale / w,
sy: 37*this.g_mapScale / h
}
}, (w, h)=>{
return {
x: card.ref.x,
y: card.ref.y + 84*this.g_mapScale / 2
}
})
dot.visible = false;
this.render(dot, zIndexMap.dot);
card.ref.dot = dot;
card.showHideDoc = (status)=>{
if(status){
this.showItemDot(card.ref)
}else {
if(!card.lined){
this.hideItemDot(card.ref)
}
}
}
let panzi = this.g_cartoon.createImage("pan_zi", (w, h)=>{ let panzi = this.g_cartoon.createImage("pan_zi", (w, h)=>{
return { return {
sx: 98*this.g_mapScale / w, sx: 98*this.g_mapScale / w,
...@@ -705,13 +744,41 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -705,13 +744,41 @@ export class PlayComponent implements OnInit, OnDestroy {
card.text = label; card.text = label;
card.panzi = panzi; card.panzi = panzi;
card.lined = false;
this.subscribeMapDownEvent(card.id, ()=>{
if(this.m_currentSelectedCard == card.id){
this.g_enableMapDown = true;
return
}
card.showHideDoc(true)
if(this.m_currentSelectedCard){
if(this.m_currentSelectedCard.indexOf("down")!=-1){
this.lineTo(this.m_currentSelectedCard, card.id, false, ()=>{
this.g_cartoon.getCartoonElement(this.m_currentSelectedCard).showHideDoc(false)
card.showHideDoc(false)
this.m_currentSelectedCard = null
this.g_enableMapDown = true;
})
}else{
this.g_cartoon.getCartoonElement(this.m_currentSelectedCard).showHideDoc(false)
this.m_currentSelectedCard = card.id
this.g_enableMapDown = true;
}
}else{
this.m_currentSelectedCard = card.id
this.g_enableMapDown = true;
}
})
this.render(panzi, zIndexMap.cardUp) this.render(panzi, zIndexMap.cardUp)
this.render(card.ref, zIndexMap.cardUp) this.render(card.ref, zIndexMap.cardUp)
this.render(label, zIndexMap.cardUp) this.render(label, zIndexMap.cardUp)
return { return {
e1: card.ref, e1: card.ref,
e2: panzi, e2: panzi,
e3: label e3: label,
e4: dot
} }
} }
...@@ -753,8 +820,8 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -753,8 +820,8 @@ export class PlayComponent implements OnInit, OnDestroy {
let cardX = 0 let cardX = 0
let A1 = [] let A1 = []
let A2 = [] let A2 = []
let A3 = []
cardAll.forEach((card, index)=>{ cardAll.forEach((card, index)=>{
console.log("===>" + cardX)
let pos = {x:0, y:0} let pos = {x:0, y:0}
if(index!=0){ if(index!=0){
pos = { pos = {
...@@ -771,11 +838,15 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -771,11 +838,15 @@ export class PlayComponent implements OnInit, OnDestroy {
let temp = this.createCardDown(index, card, pos) let temp = this.createCardDown(index, card, pos)
A1.push(temp.e1) A1.push(temp.e1)
A2.push(temp.e2) A2.push(temp.e2)
A3.push(temp.e3)
}) })
let movedDis = this.alignCenter(A1) let movedDis = this.alignCenter(A1)
A2.forEach(item=>{ A2.forEach(item=>{
item.x = item.x + movedDis item.x = item.x + movedDis
}) })
A3.forEach(item=>{
item.x = item.x + movedDis
})
} }
createCardDown(index, label, pos){ createCardDown(index, label, pos){
...@@ -795,12 +866,66 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -795,12 +866,66 @@ export class PlayComponent implements OnInit, OnDestroy {
}) })
card.text = label; card.text = label;
// 连接节点
let dot = this.g_cartoon.createImage("icon_dian2", (w, h)=>{
return {
sx: 37*this.g_mapScale / w,
sy: 37*this.g_mapScale / h
}
}, (w, h)=>{
return {
x: card.ref.x,
y: card.ref.y - 84*this.g_mapScale / 2
}
})
dot.visible = false;
this.render(dot, zIndexMap.dot);
card.ref.dot = dot;
card.showHideDoc = (status)=>{
if(status){
this.showItemDot(card.ref)
}else {
if(!card.lined){
this.hideItemDot(card.ref)
}
}
}
card.lined = false;
this.subscribeMapDownEvent(card.id, ()=>{
if(this.m_currentSelectedCard == card.id){
this.g_enableMapDown = true;
return
}
card.showHideDoc(true)
if(this.m_currentSelectedCard){
if(this.m_currentSelectedCard.indexOf("up")!=-1){
this.lineTo(this.m_currentSelectedCard, card.id, false, ()=>{
this.g_cartoon.getCartoonElement(this.m_currentSelectedCard).showHideDoc(false)
card.showHideDoc(false)
this.m_currentSelectedCard = null
this.g_enableMapDown = true;
})
}else{
this.g_cartoon.getCartoonElement(this.m_currentSelectedCard).showHideDoc(false)
this.m_currentSelectedCard = card.id
this.g_enableMapDown = true;
}
}else{
this.m_currentSelectedCard = card.id
this.g_enableMapDown = true;
}
})
this.render(card.ref, zIndexMap.cardUp) this.render(card.ref, zIndexMap.cardUp)
this.render(label, zIndexMap.cardUp) this.render(label, zIndexMap.cardUp)
return { return {
e1: card.ref, e1: card.ref,
e2: label e2: label,
e3: dot
} }
} }
...@@ -827,8 +952,152 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -827,8 +952,152 @@ export class PlayComponent implements OnInit, OnDestroy {
return moveDis * this.g_mapScale return moveDis * this.g_mapScale
} }
lineTo(T1, T2, isCorrect, callback?){
let color = ""
if(isCorrect){
color = "line_6"
}else{
color = "line_7"
}
const line_1 = new MySprite();
line_1.init(this.g_cartoon.images.get(color));
line_1.setScaleXY(this.g_mapScale)
line_1.anchorX = (line_1.width - line_1.height / 2) / line_1.width;
line_1.anchorY = 0;
line_1.id = UUID.UUID();
const line_2 = new MySprite();
line_2.init(this.g_cartoon.images.get(color));
line_2.setScaleXY(this.g_mapScale)
line_2.anchorX = (line_2.width - line_2.height / 2) / line_2.width;
line_2.anchorY = 0;
line_2.id = UUID.UUID();
let target_1 = this.g_cartoon.getCartoonElement(T1).ref.dot
let target_2 = this.g_cartoon.getCartoonElement(T2).ref.dot
if(isCorrect){
this.g_cartoon.getCartoonElement(T1).lined = true
this.g_cartoon.getCartoonElement(T2).lined = true
}
let middlePos = {
x: (target_1.x + target_2.x) / 2,
y: (target_1.y + target_2.y) / 2
}
line_1.x = target_2.x;
line_1.y = target_2.y;
line_2.x = target_1.x;
line_2.y = target_1.y;
this.render(line_1, zIndexMap.line);
this.render(line_2, zIndexMap.line);
if (middlePos.x < line_1.x) {
line_1.scaleX *= -1;
}
if (middlePos.x < line_2.x) {
line_2.scaleX *= -1;
}
const angle_1 = getAngleByPos(line_1.x, line_1.y, middlePos.x, middlePos.y);
line_1.rotation = angle_1 + 180;
const distance_1 = getPosDistance(line_1.x, line_1.y, middlePos.x, middlePos.y);
const targetS_1 = distance_1 / line_1.height;
tweenChange( line_1, { scaleY: targetS_1 }, 1, () => {}, TWEEN.Easing.Sinusoidal.Out);
const angle_2 = getAngleByPos(line_2.x, line_2.y, middlePos.x, middlePos.y);
line_2.rotation = angle_2 + 180;
const distance_2 = getPosDistance(line_2.x, line_2.y, middlePos.x, middlePos.y);
const targetS_2 = distance_2 / line_2.height;
tweenChange( line_2, { scaleY: targetS_2 }, 1, () => {
if(isCorrect){
callback && callback(line_1, line_2)
}else{
this.cutLine(line_1, line_2, ()=>{
callback && callback(line_1, line_2)
})
}
}, TWEEN.Easing.Sinusoidal.Out);
}
// 生长连接点
showItemDot(item) {
if (item.sTween) {
item.sTween.stop();
}
const dot = item.dot;
dot.visible = true;
dot.setScaleXY(0);
item.sTween = scaleItem(
dot,
this.g_mapScale,
0.3,
() => {
item.sTween = null;
},
TWEEN.Easing.Cubic.Out
);
}
// 隐藏连接点
hideItemDot(item) {
if (item.sTween) {
item.sTween.stop();
}
const dot = item.dot;
dot.visible = true;
item.sTween = scaleItem(
dot,
0,
0.3,
() => {
item.sTween = null;
},
TWEEN.Easing.Cubic.Out
);
}
initCutter(){
let element =this.g_cartoon.createCartoonElementImageFunc(`cutter`, "icon_jian", (w, h)=>{
return {
sx: 138 *this.g_mapScale / w,
sy: 146 * this.g_mapScale / h
}
}, (w, h)=>{
return {
x: -138 * this.g_mapScale,
y: this.g_canvasWidth + 146 *this.g_mapScale,
}
})
element.ref.visible = false
this.render(element.ref, zIndexMap.cutter)
}
cutLine(line1, line2, callback?){
let cutter = this.g_cartoon.getCartoonElement("cutter")
let middlePos = {
x: (line1.x + line2.x) / 2 - (cutter.ref.width * this.g_mapScale) / 2 * 0.8,
y: (line1.y + line2.y) / 2 + (cutter.ref.height * this.g_mapScale) / 2 * 0.8
}
cutter.ref.visible = true
tweenChange(cutter.ref, middlePos, 1, ()=>{
console.log(line1.rotation, line2.rotation)
cutter.ref.visible = false
cutter.ref.x = cutter.initX
cutter.ref.y = cutter.initY
tweenChange(line1, {rotation: 360}, 0.5, TWEEN.Easing.Cubic.In)
tweenChange(line2, {rotation: 360}, 0.5, ()=>{
this.m_setTimeoutIDs.push(setTimeout(() => {
this.deleteElementInRender(line1.id)
this.deleteElementInRender(line2.id)
callback && callback()
}, 200))
}, TWEEN.Easing.Cubic.In)
},TWEEN.Easing.Cubic.Out)
}
......
...@@ -66,7 +66,8 @@ const localImages = { ...@@ -66,7 +66,8 @@ const localImages = {
'bg_card_down': 'assets/play/bg_card_down.png', 'bg_card_down': 'assets/play/bg_card_down.png',
'border_left': 'assets/play/border_left.png', 'border_left': 'assets/play/border_left.png',
'border_right': 'assets/play/border_right.png', 'border_right': 'assets/play/border_right.png',
'line_6': "assets/play/6.png",
'line_7': "assets/play/7.png",
'bg_star (1)': 'assets/play/frame/bg_star (1).png', 'bg_star (1)': 'assets/play/frame/bg_star (1).png',
'bg_star (10)': 'assets/play/frame/bg_star (10).png', 'bg_star (10)': 'assets/play/frame/bg_star (10).png',
'bg_star (11)': 'assets/play/frame/bg_star (11).png', 'bg_star (11)': 'assets/play/frame/bg_star (11).png',
......
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