Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Y
YM2-30
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
template admin
YM2-30
Commits
244f5e8e
Commit
244f5e8e
authored
Jun 29, 2020
by
范雪寒
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 现在坑与胡萝卜都可以移动了
parent
b46887f3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
131 additions
and
40 deletions
+131
-40
form.component.ts
src/app/form/form.component.ts
+3
-1
DefaultData.ts
src/app/form/game/DefaultData.ts
+31
-20
MyGame.ts
src/app/form/game/MyGame.ts
+81
-13
DefaultData.ts
src/app/play/game/DefaultData.ts
+10
-0
MyGame.ts
src/app/play/game/MyGame.ts
+6
-6
No files found.
src/app/form/form.component.ts
View file @
244f5e8e
...
...
@@ -28,6 +28,8 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
carrotImg
:
''
,
carrotAudio
:
''
,
holeImg
:
''
,
carrotOffset
:
{
x
:
0
,
y
:
0
},
holeOffset
:
{
x
:
0
,
y
:
0
}
});
if
(
saveFlg
)
{
this
.
save
();
...
...
@@ -143,7 +145,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
(
<
any
>
window
).
courseware
.
setData
(
this
.
item
,
null
,
this
.
saveKey
);
this
.
refresh
();
this
.
previewCanvas
.
refresh
(
this
.
item
);
}
/**
...
...
src/app/form/game/DefaultData.ts
View file @
244f5e8e
...
...
@@ -7,29 +7,40 @@ export let defaultData = {
},
carrots
:
[{
carrotImg
:
'
carrot
'
,
holeImg
:
'
hole
'
,
carrotImg
:
'
carrot1
'
,
carrotAudio
:
'
child
'
,
carrotOffset
:
{
x
:
0
,
y
:
0
},
holeImg
:
'
hole1
'
,
holeOffset
:
{
x
:
0
,
y
:
0
}
},
{
carrotImg
:
'
carrot
'
,
holeImg
:
'
hole
'
,
carrotImg
:
'
carrot1
'
,
carrotAudio
:
'
knight
'
,
carrotOffset
:
{
x
:
0
,
y
:
0
},
holeImg
:
'
hole2
'
,
holeOffset
:
{
x
:
0
,
y
:
0
}
},
{
carrotImg
:
'
carrot
'
,
holeImg
:
'
hole
'
,
carrotImg
:
'
carrot2
'
,
carrotAudio
:
'
children
'
,
carrotOffset
:
{
x
:
0
,
y
:
0
},
holeImg
:
'
hole3
'
,
holeOffset
:
{
x
:
0
,
y
:
0
}
},
{
carrotImg
:
'
carrot
'
,
holeImg
:
'
hole
'
,
carrotImg
:
'
carrot1
'
,
carrotAudio
:
'
ddbbbbcccc
'
,
carrotOffset
:
{
x
:
0
,
y
:
0
},
holeImg
:
'
hole4
'
,
holeOffset
:
{
x
:
0
,
y
:
0
}
},
{
carrotImg
:
'
carrot
'
,
holeImg
:
'
hole
'
,
},
{
carrotImg
:
'
carrot
'
,
holeImg
:
'
hole
'
,
},
{
carrotImg
:
'
carrot
'
,
holeImg
:
'
hole
'
,
},
{
carrotImg
:
'
carrot
'
,
holeImg
:
'
hole
'
,
carrotImg
:
'
carrot2
'
,
carrotAudio
:
'
eeebbbbcccc
'
,
carrotOffset
:
{
x
:
0
,
y
:
0
},
holeImg
:
'
hole5
'
,
holeOffset
:
{
x
:
0
,
y
:
0
}
}],
targets
:
[]
targets
:
[{
x
:
-
530
,
y
:
-
270
,
targetImg
:
'
target
'
,
targetAudio
:
'
kn
'
}]
};
\ No newline at end of file
src/app/form/game/MyGame.ts
View file @
244f5e8e
...
...
@@ -195,12 +195,47 @@ export class MyGame extends Game {
this
.
data
.
carrots
.
forEach
((
carrot
,
idx
)
=>
{
let
carrotSp
=
new
TouchSprite
();
carrotSp
.
init
(
this
.
images
.
get
(
carrot
.
carrotImg
));
carrotSp
.
setPositionX
(
this
.
bg
.
width
/
length
*
(
idx
-
(
length
-
1
)
/
2
));
carrotSp
.
setPositionY
(
-
550
);
carrotSp
.
setPositionX
(
this
.
data
.
carrots
[
idx
].
carrotOffset
.
x
+
this
.
bg
.
width
/
length
*
(
idx
-
(
length
-
1
)
/
2
));
carrotSp
.
setPositionY
(
this
.
data
.
carrots
[
idx
].
carrotOffset
.
y
-
550
);
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
()
{
let
screenSize
=
this
.
getScreenSize
();
let
defaultSize
=
this
.
getDefaultScreenSize
();
...
...
@@ -210,12 +245,49 @@ export class MyGame extends Game {
hole
.
init
(
this
.
images
.
get
(
carrot
.
holeImg
));
hole
.
anchorX
=
0.5
;
hole
.
anchorY
=
0
;
hole
.
setPositionX
(
this
.
bg
.
width
/
length
*
(
idx
-
(
length
-
1
)
/
2
));
hole
.
setPositionY
(
-
520
);
hole
.
setPositionX
(
this
.
data
.
carrots
[
idx
].
holeOffset
.
x
+
this
.
bg
.
width
/
length
*
(
idx
-
(
length
-
1
)
/
2
));
hole
.
setPositionY
(
this
.
data
.
carrots
[
idx
].
holeOffset
.
y
-
520
);
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
()
{
let
screenSize
=
this
.
getScreenSize
();
let
defaultSize
=
this
.
getDefaultScreenSize
();
...
...
@@ -226,14 +298,13 @@ export class MyGame extends Game {
targetSp
.
setPositionX
(
targetData
.
x
);
targetSp
.
setPositionY
(
targetData
.
y
);
targetSp
.
addTouchBeganListener
((
{
x
,
y
}
)
=>
{
this
.
onTargetSpTouchBengan
(
{
x
,
y
}
,
targetSp
,
idx
);
targetSp
.
addTouchBeganListener
((
pos
)
=>
{
this
.
onTargetSpTouchBengan
(
pos
,
targetSp
,
idx
);
});
targetSp
.
addTouchMoveListener
((
{
x
,
y
}
)
=>
{
this
.
onTargetSpTouchMoved
(
{
x
,
y
}
,
targetSp
,
idx
);
targetSp
.
addTouchMoveListener
((
pos
)
=>
{
this
.
onTargetSpTouchMoved
(
pos
,
targetSp
,
idx
);
});
targetSp
.
addTouchEndListener
(()
=>
{
targetSp
.
addTouchEndListener
(()
=>
{
this
.
onTargetSpTouchEnded
();
});
...
...
@@ -248,9 +319,6 @@ export class MyGame extends Game {
onTargetSpTouchMoved
({
x
,
y
},
targetSp
,
idx
)
{
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
spritePosY
=
targetSp
.
get
(
'
startPos
'
).
y
+
(
y
-
targetSp
.
get
(
'
touchStartPos
'
).
y
)
/
this
.
_parent
.
mapScale
;
targetSp
.
setPositionX
(
spritePosX
);
...
...
src/app/play/game/DefaultData.ts
View file @
244f5e8e
...
...
@@ -9,23 +9,33 @@ export let defaultData = {
carrots
:
[{
carrotImg
:
'
carrot1
'
,
carrotAudio
:
'
child
'
,
carrotOffset
:
{
x
:
0
,
y
:
0
},
holeImg
:
'
hole1
'
,
holeOffset
:
{
x
:
0
,
y
:
0
}
},
{
carrotImg
:
'
carrot1
'
,
carrotAudio
:
'
knight
'
,
carrotOffset
:
{
x
:
0
,
y
:
0
},
holeImg
:
'
hole2
'
,
holeOffset
:
{
x
:
0
,
y
:
0
}
},
{
carrotImg
:
'
carrot2
'
,
carrotAudio
:
'
children
'
,
carrotOffset
:
{
x
:
0
,
y
:
0
},
holeImg
:
'
hole3
'
,
holeOffset
:
{
x
:
0
,
y
:
0
}
},
{
carrotImg
:
'
carrot1
'
,
carrotAudio
:
'
ddbbbbcccc
'
,
carrotOffset
:
{
x
:
0
,
y
:
0
},
holeImg
:
'
hole4
'
,
holeOffset
:
{
x
:
0
,
y
:
0
}
},
{
carrotImg
:
'
carrot2
'
,
carrotAudio
:
'
eeebbbbcccc
'
,
carrotOffset
:
{
x
:
0
,
y
:
0
},
holeImg
:
'
hole5
'
,
holeOffset
:
{
x
:
0
,
y
:
0
}
}],
targets
:
[{
x
:
-
530
,
...
...
src/app/play/game/MyGame.ts
View file @
244f5e8e
...
...
@@ -64,7 +64,7 @@ export class MyGame extends Game {
preLoadData
(
imgUrlList
,
audioUrlList
)
{
imgUrlList
.
forEach
((
data
)
=>
{
this
.
_parent
.
addUrlToImages
(
data
)
this
.
_parent
.
addUrlToImages
(
data
)
;
});
audioUrlList
.
forEach
((
data
)
=>
{
this
.
_parent
.
addUrlToAudioObj
(
data
);
...
...
@@ -109,7 +109,7 @@ export class MyGame extends Game {
// 背景
let
bg
=
new
TouchSprite
();
bg
.
init
(
this
.
images
.
get
(
'
Img_bg2
'
))
bg
.
init
(
this
.
images
.
get
(
'
Img_bg2
'
))
;
bg
.
setScaleXY
(
this
.
_parent
.
mapScale
);
bg
.
alpha
=
0
;
bg
.
anchorX
=
0.5
;
...
...
@@ -201,8 +201,8 @@ export class MyGame extends Game {
this
.
data
.
carrots
.
forEach
((
carrot
,
idx
)
=>
{
let
carrotSp
=
new
TouchSprite
();
carrotSp
.
init
(
this
.
images
.
get
(
carrot
.
carrotImg
));
carrotSp
.
setPositionX
(
this
.
bg
.
width
/
length
*
(
idx
-
(
length
-
1
)
/
2
));
carrotSp
.
setPositionY
(
-
550
);
carrotSp
.
setPositionX
(
this
.
data
.
carrots
[
idx
].
carrotOffset
.
x
+
this
.
bg
.
width
/
length
*
(
idx
-
(
length
-
1
)
/
2
));
carrotSp
.
setPositionY
(
this
.
data
.
carrots
[
idx
].
carrotOffset
.
y
-
550
);
this
.
bg
.
addChild
(
carrotSp
);
carrotSp
.
addTouchBeganListener
(()
=>
{
...
...
@@ -224,8 +224,8 @@ export class MyGame extends Game {
hole
.
init
(
this
.
images
.
get
(
carrot
.
holeImg
));
hole
.
anchorX
=
0.5
;
hole
.
anchorY
=
0
;
hole
.
setPositionX
(
this
.
bg
.
width
/
length
*
(
idx
-
(
length
-
1
)
/
2
));
hole
.
setPositionY
(
-
520
);
hole
.
setPositionX
(
this
.
data
.
carrots
[
idx
].
holeOffset
.
x
+
this
.
bg
.
width
/
length
*
(
idx
-
(
length
-
1
)
/
2
));
hole
.
setPositionY
(
this
.
data
.
carrots
[
idx
].
holeOffset
.
y
-
520
);
this
.
bg
.
addChild
(
hole
);
});
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment