Commit 244f5e8e authored by 范雪寒's avatar 范雪寒

feat: 现在坑与胡萝卜都可以移动了

parent b46887f3
...@@ -28,6 +28,8 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -28,6 +28,8 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
carrotImg: '', carrotImg: '',
carrotAudio: '', carrotAudio: '',
holeImg: '', holeImg: '',
carrotOffset: { x: 0, y: 0 },
holeOffset: { x: 0, y: 0 }
}); });
if (saveFlg) { if (saveFlg) {
this.save(); this.save();
......
...@@ -7,29 +7,40 @@ export let defaultData = { ...@@ -7,29 +7,40 @@ export let defaultData = {
}, },
carrots: [{ carrots: [{
carrotImg: 'carrot', carrotImg: 'carrot1',
holeImg: 'hole', carrotAudio: 'child',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole1',
holeOffset: { x: 0, y: 0 }
}, { }, {
carrotImg: 'carrot', carrotImg: 'carrot1',
holeImg: 'hole', carrotAudio: 'knight',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole2',
holeOffset: { x: 0, y: 0 }
}, { }, {
carrotImg: 'carrot', carrotImg: 'carrot2',
holeImg: 'hole', carrotAudio: 'children',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole3',
holeOffset: { x: 0, y: 0 }
}, { }, {
carrotImg: 'carrot', carrotImg: 'carrot1',
holeImg: 'hole', carrotAudio: 'ddbbbbcccc',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole4',
holeOffset: { x: 0, y: 0 }
}, { }, {
carrotImg: 'carrot', carrotImg: 'carrot2',
holeImg: 'hole', carrotAudio: 'eeebbbbcccc',
}, { carrotOffset: { x: 0, y: 0 },
carrotImg: 'carrot', holeImg: 'hole5',
holeImg: 'hole', holeOffset: { x: 0, y: 0 }
}, {
carrotImg: 'carrot',
holeImg: 'hole',
}, {
carrotImg: 'carrot',
holeImg: 'hole',
}], }],
targets: [] targets: [{
x: -530,
y: -270,
targetImg: 'target',
targetAudio: 'kn'
}]
}; };
\ No newline at end of file
...@@ -195,10 +195,45 @@ export class MyGame extends Game { ...@@ -195,10 +195,45 @@ export class MyGame extends Game {
this.data.carrots.forEach((carrot, idx) => { this.data.carrots.forEach((carrot, idx) => {
let carrotSp = new TouchSprite(); let carrotSp = new TouchSprite();
carrotSp.init(this.images.get(carrot.carrotImg)); carrotSp.init(this.images.get(carrot.carrotImg));
carrotSp.setPositionX(this.bg.width / length * (idx - (length - 1) / 2)); carrotSp.setPositionX(this.data.carrots[idx].carrotOffset.x + this.bg.width / length * (idx - (length - 1) / 2));
carrotSp.setPositionY(-550); carrotSp.setPositionY(this.data.carrots[idx].carrotOffset.y - 550);
this.bg.addChild(carrotSp); this.bg.addChild(carrotSp);
carrotSp.addTouchBeganListener((pos) => {
this.onCarrotSpTouchBengan(pos, carrotSp, idx);
});
carrotSp.addTouchMoveListener((pos) => {
this.onCarrotSpTouchMoved(pos, carrotSp, idx);
});
carrotSp.addTouchEndListener(() => {
this.onCarrotSpTouchEnded();
}); });
});
}
onCarrotSpTouchBengan({ x, y }, carrotSp, idx) {
carrotSp.set('touchStartPos', { x, y });
carrotSp.set('startPos', { x: carrotSp.x, y: carrotSp.y });
carrotSp.set('startOffset', {
x: this.data.carrots[idx].carrotOffset.x,
y: this.data.carrots[idx].carrotOffset.y,
});
}
onCarrotSpTouchMoved({ x, y }, carrotSp, idx) {
if (this._editMode) {
let spritePosX = carrotSp.get('startPos').x + (x - carrotSp.get('touchStartPos').x) / this._parent.mapScale;
let spritePosY = carrotSp.get('startPos').y + (y - carrotSp.get('touchStartPos').y) / this._parent.mapScale;
carrotSp.setPositionX(spritePosX);
carrotSp.setPositionY(spritePosY);
this.data.carrots[idx].carrotOffset.x = spritePosX - carrotSp.get('startPos').x + carrotSp.get('startOffset').x;
this.data.carrots[idx].carrotOffset.y = spritePosY - carrotSp.get('startPos').y + carrotSp.get('startOffset').y;
}
}
onCarrotSpTouchEnded() {
if (this._editMode) {
this._save();
}
} }
createHoles() { createHoles() {
...@@ -210,10 +245,47 @@ export class MyGame extends Game { ...@@ -210,10 +245,47 @@ export class MyGame extends Game {
hole.init(this.images.get(carrot.holeImg)); hole.init(this.images.get(carrot.holeImg));
hole.anchorX = 0.5; hole.anchorX = 0.5;
hole.anchorY = 0; hole.anchorY = 0;
hole.setPositionX(this.bg.width / length * (idx - (length - 1) / 2)); hole.setPositionX(this.data.carrots[idx].holeOffset.x + this.bg.width / length * (idx - (length - 1) / 2));
hole.setPositionY(-520); hole.setPositionY(this.data.carrots[idx].holeOffset.y - 520);
this.bg.addChild(hole); this.bg.addChild(hole);
hole.addTouchBeganListener((pos) => {
this.onHoleTouchBengan(pos, hole, idx);
});
hole.addTouchMoveListener((pos) => {
this.onHoleTouchMoved(pos, hole, idx);
});
hole.addTouchEndListener(() => {
this.onHoleTouchEnded();
}); });
});
}
onHoleTouchBengan({ x, y }, hole, idx) {
hole.set('touchStartPos', { x, y });
hole.set('startPos', { x: hole.x, y: hole.y });
hole.set('startOffset', {
x: this.data.carrots[idx].holeOffset.x,
y: this.data.carrots[idx].holeOffset.y,
});
}
onHoleTouchMoved({ x, y }, hole, idx) {
if (this._editMode) {
let spritePosX = hole.get('startPos').x + (x - hole.get('touchStartPos').x) / this._parent.mapScale;
let spritePosY = hole.get('startPos').y + (y - hole.get('touchStartPos').y) / this._parent.mapScale;
hole.setPositionX(spritePosX);
hole.setPositionY(spritePosY);
this.data.carrots[idx].holeOffset.x = spritePosX - hole.get('startPos').x + hole.get('startOffset').x;;
this.data.carrots[idx].holeOffset.y = spritePosY - hole.get('startPos').y + hole.get('startOffset').y;;
}
}
onHoleTouchEnded() {
if (this._editMode) {
this._save();
}
} }
createWords() { createWords() {
...@@ -226,14 +298,13 @@ export class MyGame extends Game { ...@@ -226,14 +298,13 @@ export class MyGame extends Game {
targetSp.setPositionX(targetData.x); targetSp.setPositionX(targetData.x);
targetSp.setPositionY(targetData.y); targetSp.setPositionY(targetData.y);
targetSp.addTouchBeganListener(({ x, y }) => { targetSp.addTouchBeganListener((pos) => {
this.onTargetSpTouchBengan({ x, y }, targetSp, idx); this.onTargetSpTouchBengan(pos, targetSp, idx);
}); });
targetSp.addTouchMoveListener(({ x, y }) => { targetSp.addTouchMoveListener((pos) => {
this.onTargetSpTouchMoved({ x, y }, targetSp, idx); this.onTargetSpTouchMoved(pos, targetSp, idx);
}); });
targetSp.addTouchEndListener(() => {
targetSp.addTouchEndListener(()=>{
this.onTargetSpTouchEnded(); this.onTargetSpTouchEnded();
}); });
...@@ -248,9 +319,6 @@ export class MyGame extends Game { ...@@ -248,9 +319,6 @@ export class MyGame extends Game {
onTargetSpTouchMoved({ x, y }, targetSp, idx) { onTargetSpTouchMoved({ x, y }, targetSp, idx) {
if (this._editMode) { if (this._editMode) {
let screenSize = this.getScreenSize();
let defaultSize = this.getDefaultScreenSize();
let spritePosX = targetSp.get('startPos').x + (x - targetSp.get('touchStartPos').x) / this._parent.mapScale; let spritePosX = targetSp.get('startPos').x + (x - targetSp.get('touchStartPos').x) / this._parent.mapScale;
let spritePosY = targetSp.get('startPos').y + (y - targetSp.get('touchStartPos').y) / this._parent.mapScale; let spritePosY = targetSp.get('startPos').y + (y - targetSp.get('touchStartPos').y) / this._parent.mapScale;
targetSp.setPositionX(spritePosX); targetSp.setPositionX(spritePosX);
......
...@@ -9,23 +9,33 @@ export let defaultData = { ...@@ -9,23 +9,33 @@ export let defaultData = {
carrots: [{ carrots: [{
carrotImg: 'carrot1', carrotImg: 'carrot1',
carrotAudio: 'child', carrotAudio: 'child',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole1', holeImg: 'hole1',
holeOffset: { x: 0, y: 0 }
}, { }, {
carrotImg: 'carrot1', carrotImg: 'carrot1',
carrotAudio: 'knight', carrotAudio: 'knight',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole2', holeImg: 'hole2',
holeOffset: { x: 0, y: 0 }
}, { }, {
carrotImg: 'carrot2', carrotImg: 'carrot2',
carrotAudio: 'children', carrotAudio: 'children',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole3', holeImg: 'hole3',
holeOffset: { x: 0, y: 0 }
}, { }, {
carrotImg: 'carrot1', carrotImg: 'carrot1',
carrotAudio: 'ddbbbbcccc', carrotAudio: 'ddbbbbcccc',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole4', holeImg: 'hole4',
holeOffset: { x: 0, y: 0 }
}, { }, {
carrotImg: 'carrot2', carrotImg: 'carrot2',
carrotAudio: 'eeebbbbcccc', carrotAudio: 'eeebbbbcccc',
carrotOffset: { x: 0, y: 0 },
holeImg: 'hole5', holeImg: 'hole5',
holeOffset: { x: 0, y: 0 }
}], }],
targets: [{ targets: [{
x: -530, x: -530,
......
...@@ -64,7 +64,7 @@ export class MyGame extends Game { ...@@ -64,7 +64,7 @@ export class MyGame extends Game {
preLoadData(imgUrlList, audioUrlList) { preLoadData(imgUrlList, audioUrlList) {
imgUrlList.forEach((data) => { imgUrlList.forEach((data) => {
this._parent.addUrlToImages(data) this._parent.addUrlToImages(data);
}); });
audioUrlList.forEach((data) => { audioUrlList.forEach((data) => {
this._parent.addUrlToAudioObj(data); this._parent.addUrlToAudioObj(data);
...@@ -109,7 +109,7 @@ export class MyGame extends Game { ...@@ -109,7 +109,7 @@ export class MyGame extends Game {
// 背景 // 背景
let bg = new TouchSprite(); let bg = new TouchSprite();
bg.init(this.images.get('Img_bg2')) bg.init(this.images.get('Img_bg2'));
bg.setScaleXY(this._parent.mapScale); bg.setScaleXY(this._parent.mapScale);
bg.alpha = 0; bg.alpha = 0;
bg.anchorX = 0.5; bg.anchorX = 0.5;
...@@ -201,8 +201,8 @@ export class MyGame extends Game { ...@@ -201,8 +201,8 @@ export class MyGame extends Game {
this.data.carrots.forEach((carrot, idx) => { this.data.carrots.forEach((carrot, idx) => {
let carrotSp = new TouchSprite(); let carrotSp = new TouchSprite();
carrotSp.init(this.images.get(carrot.carrotImg)); carrotSp.init(this.images.get(carrot.carrotImg));
carrotSp.setPositionX(this.bg.width / length * (idx - (length - 1) / 2)); carrotSp.setPositionX(this.data.carrots[idx].carrotOffset.x + this.bg.width / length * (idx - (length - 1) / 2));
carrotSp.setPositionY(-550); carrotSp.setPositionY(this.data.carrots[idx].carrotOffset.y - 550);
this.bg.addChild(carrotSp); this.bg.addChild(carrotSp);
carrotSp.addTouchBeganListener(() => { carrotSp.addTouchBeganListener(() => {
...@@ -224,8 +224,8 @@ export class MyGame extends Game { ...@@ -224,8 +224,8 @@ export class MyGame extends Game {
hole.init(this.images.get(carrot.holeImg)); hole.init(this.images.get(carrot.holeImg));
hole.anchorX = 0.5; hole.anchorX = 0.5;
hole.anchorY = 0; hole.anchorY = 0;
hole.setPositionX(this.bg.width / length * (idx - (length - 1) / 2)); hole.setPositionX(this.data.carrots[idx].holeOffset.x + this.bg.width / length * (idx - (length - 1) / 2));
hole.setPositionY(-520); hole.setPositionY(this.data.carrots[idx].holeOffset.y - 520);
this.bg.addChild(hole); this.bg.addChild(hole);
}); });
} }
......
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