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
1282263e
Commit
1282263e
authored
Nov 20, 2021
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
872e687d
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
105 additions
and
15 deletions
+105
-15
DragDropManager.ts
src/dragdrop/DragDropManager.ts
+6
-2
MovableManager.ts
src/lib/MovableManager.ts
+69
-3
Enemy.ts
src/planewar/Enemy.ts
+9
-3
Hero.ts
src/planewar/Hero.ts
+8
-2
addGame.ts
src/planewar/addGame.ts
+10
-4
Bullet.ts
src/weapon/Bullet.ts
+1
-0
Weapon.ts
src/weapon/Weapon.ts
+2
-1
No files found.
src/dragdrop/DragDropManager.ts
View file @
1282263e
...
...
@@ -7,11 +7,15 @@ 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
.
remov
e
,
this
)
item
.
once
(
FYGE
.
Event
.
REMOVED_FROM_STAGE
,
this
.
onRemoveFromStag
e
,
this
)
}
remov
e
=
(
event
:
FYGE
.
Event
)
=>
{
onRemoveFromStag
e
=
(
event
:
FYGE
.
Event
)
=>
{
const
item
=
event
.
target
;
this
.
remove
(
item
)
}
remove
(
item
)
{
item
.
removeEventListener
(
'DROP'
,
this
.
onDisplayItemDrop
,
this
)
item
.
removeEventListener
(
FYGE
.
MouseEvent
.
MOUSE_DOWN
,
this
.
onMouseDown
,
this
)
}
...
...
src/lib/MovableManager.ts
View file @
1282263e
import
Enemy
from
"../planewar/Enemy"
;
import
Hero
from
"../planewar/Hero"
;
import
Bullet
from
"../weapon/Bullet"
;
import
Movable
from
"./Movable"
;
export
default
class
MovableManager
{
export
default
class
MovableManager
extends
FYGE
.
EventDispatcher
{
private
_stage
:
FYGE
.
Stage
;
private
_movableList
:
Movable
[]
=
[];
hero
:
Hero
;
constructor
(
stage
:
FYGE
.
Stage
)
{
super
();
this
.
_stage
=
stage
;
this
.
_stage
.
addEventListener
(
FYGE
.
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
);
}
...
...
@@ -11,7 +16,67 @@ export default class MovableManager {
onEnterFrame
=
()
=>
{
this
.
step
();
this
.
checkRemove
();
// console.log('移动对象的数量:',this._movableList.length)
this
.
checkHitEnemy
();
this
.
checkHitByBullet
();
this
.
checkHitByEnemy
();
// console.log('移动对象的数量:', this._movableList.length)
}
checkHitByEnemy
()
{
const
enemyList
=
this
.
_movableList
.
filter
(
i
=>
i
instanceof
Enemy
);
for
(
let
i
=
0
;
i
<
enemyList
.
length
;
i
++
)
{
const
oneEnemy
=
enemyList
[
i
];
if
(
this
.
checkHit
(
oneEnemy
,
this
.
hero
))
{
console
.
log
(
'被敌机碰撞了,游戏结束了'
);
this
.
gameOver
()
return
;
}
}
}
private
gameOver
()
{
this
.
_stage
.
removeEventListener
(
FYGE
.
Event
.
ENTER_FRAME
,
this
.
onEnterFrame
);
this
.
dispatchEvent
(
'gameover'
);
}
checkHitByBullet
()
{
const
enemyBulletList
=
this
.
_movableList
.
filter
(
i
=>
i
instanceof
Bullet
&&
i
.
host
instanceof
Enemy
);
for
(
let
j
=
0
;
j
<
enemyBulletList
.
length
;
j
++
)
{
const
bullet
=
enemyBulletList
[
j
];
if
(
this
.
checkHit
(
this
.
hero
,
bullet
))
{
console
.
log
(
'被子弹碰撞了,游戏结束了'
);
this
.
gameOver
()
return
;
}
}
}
private
checkHitEnemy
()
{
const
heroBulletList
=
this
.
_movableList
.
filter
(
i
=>
i
instanceof
Bullet
&&
i
.
host
instanceof
Hero
);
const
enemyList
=
this
.
_movableList
.
filter
(
i
=>
i
instanceof
Enemy
);
for
(
let
i
=
0
;
i
<
enemyList
.
length
;
i
++
)
{
const
oneEnemy
=
enemyList
[
i
];
for
(
let
j
=
0
;
j
<
heroBulletList
.
length
;
j
++
)
{
const
onHeroBullet
=
heroBulletList
[
j
];
if
(
this
.
checkHit
(
oneEnemy
,
onHeroBullet
))
{
this
.
remove
(
oneEnemy
);
this
.
remove
(
onHeroBullet
);
return
;
}
}
}
}
private
checkHit
(
A
:
FYGE
.
DisplayObject
,
B
:
FYGE
.
DisplayObject
)
{
const
pointA
=
[
A
.
x
+
A
.
width
/
2
,
A
.
y
+
A
.
height
/
2
];
const
pointB
=
[
B
.
x
+
B
.
width
/
2
,
B
.
y
+
B
.
height
/
2
];
const
x0
=
Math
.
abs
(
pointA
[
0
]
-
pointB
[
0
]);
const
y0
=
Math
.
abs
(
pointA
[
1
]
-
pointB
[
1
]);
const
x1
=
A
.
width
/
2
+
B
.
width
/
2
;
const
y1
=
A
.
height
/
2
+
B
.
height
/
2
;
return
x0
<
x1
&&
y0
<
y1
;
}
private
calcCanRemove
(
item
:
FYGE
.
DisplayObject
)
{
...
...
@@ -28,7 +93,7 @@ export default class MovableManager {
if
(
this
.
calcCanRemove
(
item
))
{
this
.
_movableList
.
splice
(
index
,
1
);
item
.
parent
&&
item
.
parent
.
removeChild
(
item
);
index
--
;
return
;
}
}
}
...
...
@@ -44,6 +109,7 @@ export default class MovableManager {
remove
(
item
:
Movable
)
{
const
index
=
this
.
_movableList
.
indexOf
(
item
);
this
.
_movableList
.
splice
(
index
,
1
);
item
.
parent
&&
item
.
parent
.
removeChild
(
item
);
}
}
\ No newline at end of file
src/planewar/Enemy.ts
View file @
1282263e
...
...
@@ -13,17 +13,23 @@ export default class Enemy extends Movable implements IWeaponHost {
movableManager
.
add
(
this
);
this
.
texture
=
FYGE
.
Texture
.
fromUrl
(
'//yun.duiba.com.cn/
spark/assets/enemy2_fly1.0f4acd3728e90763d98a7328a5a32dbc78ec204e
.png'
)
this
.
texture
=
FYGE
.
Texture
.
fromUrl
(
'//yun.duiba.com.cn/
aurora/assets/26e1539bb9c5961c693f05186b086c8e04f2f6a2
.png'
)
const
weapon
=
new
Weapon
(
this
);
// const bg = new FYGE.Graphics;
// bg.beginFill(0x00ff00, 0.2)
// bg.drawRect(0, 0, 69, 88)
// bg.endFill()
// this.addChild(bg)
this
.
addEventListener
(
FYGE
.
Event
.
REMOVED_FROM_STAGE
,
()
=>
{
console
.
log
(
'敌人消失了'
)
//
console.log('敌人消失了')
weapon
.
destroy
();
})
}
getShootInterval
()
{
return
100
}
getShootInterval
()
{
return
100
}
getShootVelocity
()
{
return
new
Vector2
(
0
,
10
)
}
...
...
src/planewar/Hero.ts
View file @
1282263e
...
...
@@ -15,9 +15,15 @@ export default class Hero extends DragDropable implements IWeaponHost {
this
.
texture
=
FYGE
.
Texture
.
fromUrl
(
'//yun.duiba.com.cn/spark/assets/hero_fly1.f292cb1c04589c6ee395fe29538d5385540755f7.png'
);
const
weapon
=
new
Weapon
(
this
);
// const bg = new FYGE.Graphics;
// bg.beginFill(0xff0000,0.2)
// bg.drawRect(0,0,99,124)
// bg.endFill()
// this.addChild(bg)
}
getShootInterval
(){
return
1
0
}
getShootVelocity
(){
return
new
Vector2
(
0
,
-
8
)}
getShootInterval
(){
return
5
0
}
getShootVelocity
(){
return
new
Vector2
(
0
,
-
20
)}
getShootPoint
()
{
return
new
FYGE
.
Point
(
this
.
x
+
this
.
width
/
2
,
this
.
y
)
...
...
src/planewar/addGame.ts
View file @
1282263e
import
DragDropable
from
"../dragdrop/DragDropable"
;
import
DragDropManager
from
"../dragdrop/DragDropManager"
;
import
MovableManager
from
"../lib/MovableManager"
;
import
Vector2
from
"../lib/Vector2"
;
import
Enemy
from
"./Enemy"
;
import
EnemyFactory
from
"./EnemyFactory"
;
import
Hero
from
"./Hero"
;
...
...
@@ -11,10 +9,18 @@ export function addGame(stage: FYGE.Stage) {
const
movableManager
=
new
MovableManager
(
stage
);
//创建管理器
const
dragDropManager
=
new
DragDropManager
();
const
hero
=
stage
.
addChild
(
new
Hero
(
movableManager
))
as
DragDropable
;
const
hero
=
stage
.
addChild
(
new
Hero
(
movableManager
));
hero
.
position
.
set
(
300
,
1000
);
const
enemyFactory
=
new
EnemyFactory
(
stage
,
movableManager
);
const
enemyFactory
=
new
EnemyFactory
(
stage
,
movableManager
);
dragDropManager
.
add
(
hero
);
movableManager
.
hero
=
hero
;
function
onGamOver
()
{
dragDropManager
.
remove
(
hero
);
}
movableManager
.
addEventListener
(
'gameover'
,
onGamOver
);
}
\ No newline at end of file
src/weapon/Bullet.ts
View file @
1282263e
import
Movable
from
"../lib/Movable"
;
export
default
class
Bullet
extends
Movable
{
host
;
constructor
()
{
super
();
this
.
texture
=
FYGE
.
Texture
.
fromUrl
(
'//yun.duiba.com.cn/spark/assets/bullet1.63bb85f32cabe5f986366c2d428c5e2aa2435230.png'
)
...
...
src/weapon/Weapon.ts
View file @
1282263e
...
...
@@ -30,7 +30,8 @@ export default class Weapon {
createBullet
=
()
=>
{
// console.log('武器在发射子弹')
const
bullet
:
Movable
=
this
.
_host
.
parent
.
addChild
(
new
Bullet
());
const
bullet
:
Bullet
=
this
.
_host
.
parent
.
addChild
(
new
Bullet
());
bullet
.
host
=
this
.
_host
;
bullet
.
velocity
=
this
.
_host
.
getShootVelocity
();
const
shootPoint
=
this
.
_host
.
getShootPoint
();
bullet
.
position
.
set
(
shootPoint
.
x
,
shootPoint
.
y
);
...
...
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