Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
game-stydy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
谌继荃
game-stydy
Commits
1c1d7c4e
Commit
1c1d7c4e
authored
Nov 19, 2021
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
7c5b7fa5
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
101 additions
and
10 deletions
+101
-10
Hero.ts
src/Hero.ts
+6
-0
addGame.ts
src/addGame.ts
+3
-10
DragDropEvent.ts
src/dragdrop/DragDropEvent.ts
+4
-0
DragDropManager.ts
src/dragdrop/DragDropManager.ts
+40
-0
DragDropable.ts
src/dragdrop/DragDropable.ts
+48
-0
No files found.
src/Hero.ts
0 → 100644
View file @
1c1d7c4e
export
default
class
Hero
extends
FYGE
.
Sprite
{
constructor
()
{
super
();
this
.
texture
=
FYGE
.
Texture
.
fromUrl
(
'//yun.duiba.com.cn/spark/assets/enemy2_fly1.0f4acd3728e90763d98a7328a5a32dbc78ec204e.png'
)
}
}
\ No newline at end of file
src/addGame.ts
View file @
1c1d7c4e
import
Bullet
from
"./Bullet"
;
import
Enemy
from
"./Enemy"
;
import
Hero
from
"./Hero"
;
import
MovableManager
from
"./MovableManager"
;
import
Vector2
from
"./Vector2"
;
export
function
addGame
(
stage
:
FYGE
.
Stage
)
{
const
movableManager
=
new
MovableManager
(
stage
);
//创建管理器
const
bullet
=
stage
.
addChild
(
new
Bullet
());
//创建子弹并设置相关属性
bullet
.
position
.
set
(
0
,
1000
);
bullet
.
velocity
=
new
Vector2
(
0
,
-
8
)
const
enemy
=
stage
.
addChild
(
new
Enemy
());
//创建敌机并设置相关属性
enemy
.
velocity
=
new
Vector2
(
4
,
2
);
movableManager
.
add
(
bullet
);
movableManager
.
add
(
enemy
);
const
hero
=
stage
.
addChild
(
new
Hero
());
}
\ No newline at end of file
src/dragdrop/DragDropEvent.ts
0 → 100644
View file @
1c1d7c4e
export
default
class
DragDropEvent
extends
FYGE
.
Event
{
static
DRAG_START
=
'DRAG_START'
;
static
DRAG_END
=
'DRAG_END'
;
}
\ No newline at end of file
src/dragdrop/DragDropManager.ts
0 → 100644
View file @
1c1d7c4e
import
DragDropable
from
"./DragDropable"
;
import
DragDropEvent
from
"./DragDropEvent"
;
//管理一个拖放实例
export
default
class
DragDropManager
extends
FYGE
.
EventDispatcher
{
//初始化拖放对象事件
public
add
(
item
:
DragDropable
)
{
item
.
addEventListener
(
'DROP'
,
this
.
onDisplayItemDrop
,
this
)
item
.
addEventListener
(
FYGE
.
MouseEvent
.
MOUSE_DOWN
,
this
.
onMouseDown
,
this
)
item
.
once
(
FYGE
.
Event
.
REMOVED_FROM_STAGE
,
this
.
remove
,
this
)
}
remove
=
(
event
:
FYGE
.
Event
)
=>
{
const
item
=
event
.
target
;
item
.
removeEventListener
(
'DROP'
,
this
.
onDisplayItemDrop
,
this
)
item
.
removeEventListener
(
FYGE
.
MouseEvent
.
MOUSE_DOWN
,
this
.
onMouseDown
,
this
)
}
private
onMouseDown
(
event
:
FYGE
.
MouseEvent
)
{
const
item
:
DragDropable
=
event
.
target
;
if
(
!
item
.
checkCanDragDrop
())
return
;
item
.
startDrag
(
event
);
this
.
dispatchEvent
(
DragDropEvent
.
DRAG_START
,
item
);
}
private
onDisplayItemDrop
(
e
:
FYGE
.
Event
)
{
const
drag
:
DragDropable
=
e
.
target
;
drag
.
mouseEnable
=
false
;
const
dragParent
=
drag
.
parent
;
const
drop
:
DragDropable
=
dragParent
.
hitTestPoint
(
new
FYGE
.
Point
(
e
.
data
.
x
/
2
,
e
.
data
.
y
/
2
),
true
);
drag
.
mouseEnable
=
true
;
if
(
drop
)
{
drop
.
onDrop
(
drag
);
}
drag
.
onDragEnd
(
drop
);
this
.
dispatchEvent
(
DragDropEvent
.
DRAG_END
,
{
drop
,
drag
});
}
}
\ No newline at end of file
src/dragdrop/DragDropable.ts
0 → 100644
View file @
1c1d7c4e
export
default
class
DragDropable
extends
FYGE
.
Sprite
{
//图片起始位置
private
_originPos
:
FYGE
.
Point
;
public
get
originPos
()
{
return
this
.
_originPos
}
//鼠标按下起始点
private
_startPoint
:
FYGE
.
Point
;
startDrag
=
(
event
:
FYGE
.
MouseEvent
)
=>
{
this
.
stage
.
addEventListener
(
FYGE
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMouseMove
,
this
);
this
.
stage
.
once
(
FYGE
.
MouseEvent
.
MOUSE_UP
,
this
.
onMouseUp
,
this
);
this
.
_originPos
=
new
FYGE
.
Point
(
this
.
x
,
this
.
y
);
this
.
_startPoint
=
new
FYGE
.
Point
(
event
.
stageX
,
event
.
stageY
);
}
private
onMouseUp
(
event
:
FYGE
.
MouseEvent
)
{
this
.
stage
.
removeEventListener
(
FYGE
.
MouseEvent
.
MOUSE_MOVE
,
this
.
onMouseMove
,
this
);
this
.
dispatchEvent
(
'DROP'
,
this
.
getDropPoint
(
event
));
}
private
onMouseMove
(
event
:
FYGE
.
MouseEvent
)
{
//鼠标当前位置
const
currentPoint
=
{
x
:
event
.
stageX
,
y
:
event
.
stageY
};
//鼠标按下点到鼠标当前点的偏移量
let
mouseOffsetX
=
currentPoint
.
x
-
this
.
_startPoint
.
x
;
let
mouseOffsetY
=
currentPoint
.
y
-
this
.
_startPoint
.
y
;
this
.
x
=
this
.
_originPos
.
x
+
mouseOffsetX
;
this
.
y
=
this
.
_originPos
.
y
+
mouseOffsetY
;
}
checkCanDragDrop
()
{
return
true
;
}
public
onDragEnd
(
drop
:
DragDropable
)
{
throw
new
Error
(
"Method not implemented."
);
}
protected
getDropPoint
(
event
:
FYGE
.
MouseEvent
)
{
throw
new
Error
(
'必须重写此方法'
)
}
public
onDrop
=
(
drag
:
DragDropable
):
void
=>
{
throw
new
Error
(
'必须重写此方法'
)
}
}
\ No newline at end of file
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