Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zeroing-libs
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
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
劳工
zeroing-libs
Commits
9b7b3989
Commit
9b7b3989
authored
Dec 24, 2019
by
XieChuanJin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更新mgr、pool机制
parent
78b9c9db
Changes
25
Show whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
341 additions
and
660 deletions
+341
-660
shoot-planet.json
dist/customs/shoot-planet.json
+1
-1
FrameAnimation.ts
src/custom/shoot-planet/Component/FrameAnimation.ts
+35
-28
MTween.ts
src/custom/shoot-planet/Component/MTween.ts
+22
-85
Pool.ts
src/custom/shoot-planet/Component/Pool.ts
+3
-3
Ball.ts
src/custom/shoot-planet/Game/Ball.ts
+9
-25
BoomEffect.ts
src/custom/shoot-planet/Game/BoomEffect.ts
+0
-181
Bullet.ts
src/custom/shoot-planet/Game/Bullet.ts
+9
-19
Car.ts
src/custom/shoot-planet/Game/Car.ts
+3
-11
Drop.ts
src/custom/shoot-planet/Game/Drop.ts
+8
-10
Game.ts
src/custom/shoot-planet/Game/Game.ts
+104
-51
SpBoomEffect.ts
src/custom/shoot-planet/Game/SpBoomEffect.ts
+19
-31
MTimer.ts
src/custom/shoot-planet/Global/MTimer.ts
+7
-0
DropBlinkMgr.ts
src/custom/shoot-planet/Mgr/DropBlinkMgr.ts
+6
-18
EffectMgr.ts
src/custom/shoot-planet/Mgr/EffectMgr.ts
+0
-68
GameMgr.ts
src/custom/shoot-planet/Mgr/GameMgr.ts
+15
-0
TextureMgr.ts
src/custom/shoot-planet/Mgr/TextureMgr.ts
+6
-6
Collider.ts
src/custom/shoot-planet/Phycics/Collider.ts
+4
-3
PhycicsSystem.ts
src/custom/shoot-planet/Phycics/PhycicsSystem.ts
+17
-33
Physics.ts
src/custom/shoot-planet/Phycics/Physics.ts
+3
-2
AnimationPool.ts
src/custom/shoot-planet/Pools/AnimationPool.ts
+36
-0
BallPool.ts
src/custom/shoot-planet/Pools/BallPool.ts
+6
-5
BoomEffectPool.ts
src/custom/shoot-planet/Pools/BoomEffectPool.ts
+0
-35
BulletPool.ts
src/custom/shoot-planet/Pools/BulletPool.ts
+5
-6
DropPool.ts
src/custom/shoot-planet/Pools/DropPool.ts
+6
-7
ShootPlanet.ts
src/custom/shoot-planet/ShootPlanet.ts
+17
-32
No files found.
dist/customs/shoot-planet.json
View file @
9b7b3989
This source diff could not be displayed because it is too large. You can
view the blob
instead.
src/custom/shoot-planet/Component/FrameAnimation.ts
View file @
9b7b3989
import
GameMgr
from
"../Mgr/GameMgr"
;
import
{
DataMgr
}
from
"../Mgr/DataMgr"
;
/* type AltaData = {
key: string,
frameRate: number,
...
...
@@ -15,7 +18,36 @@ interface Frame {
texture
:
engine
.
Texture
}
export
class
FrameAnimationMgr
extends
GameMgr
{
constructor
()
{
super
(
"FrameAnimationMgr"
)
}
public
playingAnimations
:
FrameAnimation
[]
=
[];
protected
onUpdate
()
{
if
(
this
.
pause
)
return
;
const
filters
:
FrameAnimation
[]
=
[];
let
anim
:
FrameAnimation
=
null
;
for
(
let
i
=
0
;
i
<
this
.
playingAnimations
.
length
;
i
++
)
{
anim
=
this
.
playingAnimations
[
i
];
anim
.
onUpdate
();
if
(
anim
.
curPos
>=
anim
.
frameCount
)
{
anim
.
onCompleted
&&
anim
.
onCompleted
();
}
else
{
filters
.
push
(
anim
);
}
}
this
.
playingAnimations
=
filters
;
}
}
export
default
class
FrameAnimation
extends
engine
.
Container
{
private
frames
:
Frame
[]
=
[];
public
frameCount
:
number
=
0
;
public
curPos
:
number
=
0
;
private
frameTimer
:
number
=
0
;
private
frameRate
:
number
=
60
;
private
sprite
:
engine
.
Sprite
=
new
engine
.
Sprite
;
private
static
caches
:
{
[
key
:
string
]:
{
frameCount
:
number
,
...
...
@@ -23,6 +55,7 @@ export default class FrameAnimation extends engine.Container {
frames
:
Frame
[]
}
}
=
{};
public
static
loadRes
(
texture
:
engine
.
Texture
,
egretData
:
any
)
{
let
name
:
string
=
null
;
const
mc
=
egretData
.
mc
;
...
...
@@ -55,21 +88,6 @@ export default class FrameAnimation extends engine.Container {
}
}
private
static
playingAnimations
:
FrameAnimation
[]
=
[];
public
static
onUpdate
()
{
const
list
=
FrameAnimation
.
playingAnimations
;
for
(
let
i
=
0
;
i
<
list
.
length
;
i
++
)
{
list
[
i
].
onUpdate
();
}
}
private
frames
:
Frame
[]
=
[];
private
frameCount
:
number
=
0
;
public
curPos
:
number
=
0
;
private
frameTimer
:
number
=
0
;
private
frameRate
:
number
=
60
;
private
sprite
:
engine
.
Sprite
=
new
engine
.
Sprite
;
constructor
(
key
:
string
)
{
super
();
if
(
!
FrameAnimation
.
caches
[
key
])
{
...
...
@@ -77,16 +95,6 @@ export default class FrameAnimation extends engine.Container {
return
;
}
/* for (let i = 0; i < FrameAnimation.caches[key].frameCount; i++) {
let frame = engine.Texture.from(key + "_" + i);
if (frame) {
this.frames.push(frame);
} else {
console.error(`can not find frame ${i} of ${key}`);
return;
}
} */
this
.
frames
=
FrameAnimation
.
caches
[
key
].
frames
;
this
.
frameCount
=
Object
.
keys
(
this
.
frames
).
length
;
this
.
frameRate
=
FrameAnimation
.
caches
[
key
].
frameRate
;
...
...
@@ -96,8 +104,7 @@ export default class FrameAnimation extends engine.Container {
onUpdate
()
{
if
(
this
.
frameTimer
>=
60
/
this
.
frameRate
)
{
if
(
this
.
curPos
>=
this
.
frameCount
)
{
this
.
onCompleted
&&
this
.
onCompleted
();
FrameAnimation
.
playingAnimations
.
splice
(
FrameAnimation
.
playingAnimations
.
indexOf
(
this
),
1
);
return
;
}
else
{
const
frameData
=
this
.
frames
[
this
.
curPos
];
this
.
sprite
.
texture
=
frameData
.
texture
;
...
...
@@ -112,7 +119,7 @@ export default class FrameAnimation extends engine.Container {
}
play
()
{
FrameAnimation
.
playingAnimations
.
push
(
this
);
DataMgr
.
game
.
_animationMgr
.
playingAnimations
.
push
(
this
);
}
onCompleted
:
()
=>
void
;
...
...
src/custom/shoot-planet/Component/MTween.ts
View file @
9b7b3989
import
{
MUtils
}
from
"../Global/MUtils"
;
import
MTimer
from
"../Global/MTimer"
;
import
GameMgr
from
"../Mgr/GameMgr"
;
class
MTweenObject
{
public
static
readonly
frameRate
=
60
;
...
...
@@ -145,57 +146,39 @@ class CallbackTween extends MTweenBase {
this
.
callback
=
null
;
}
}
export
namespace
MTween
{
export
let
pause
:
boolean
=
false
;
let
tweenObjectList
:
MTweenObject
[]
=
[];
// let tweenAnimationList: TweenAnimation[] = [];
let
removeQueue
:
any
[]
=
[];
let
isTraversing
=
false
;
export
function
init
()
{
// engine.gameStage.addEventListener(engine.Event.ENTER_FRAME, update, this);
MTimer
.
onFrame
(
"MTween"
,
update
,
this
)
}
/* export function destroy() {
engine.gameStage.removeEventListener(engine.Event.ENTER_FRAME, update, this);
} */
export
function
removeTweens
(
target
:
object
)
{
if
(
isTraversing
)
{
removeQueue
.
push
(
target
);
export
class
MTween
extends
GameMgr
{
constructor
()
{
super
(
"TweenMgr"
)
}
private
tweenObjectList
:
MTweenObject
[]
=
[];
private
removeQueue
:
any
[]
=
[];
private
isTraversing
=
false
;
public
removeTweens
(
target
:
object
)
{
if
(
this
.
isTraversing
)
{
this
.
removeQueue
.
push
(
target
);
}
else
{
t
weenObjectList
=
tweenObjectList
.
filter
(
e
=>
e
.
target
!==
target
);
t
his
.
tweenObjectList
=
this
.
tweenObjectList
.
filter
(
e
=>
e
.
target
!==
target
);
}
}
export
function
get
(
target
:
object
)
{
public
get
(
target
:
object
)
{
let
tween
=
new
MTweenObject
(
target
);
tweenObjectList
.
push
(
tween
);
t
his
.
t
weenObjectList
.
push
(
tween
);
return
tween
;
}
/* export function createAnimation(target: object) {
return new TweenAnimation(target);
} */
public
onUpdate
()
{
if
(
this
.
pause
)
return
;
function
update
()
{
if
(
pause
)
return
;
isTraversing
=
true
;
for
(
let
i
=
0
;
i
<=
tweenObjectList
.
length
-
1
;
i
++
)
{
tweenObjectList
[
i
].
update
();
this
.
isTraversing
=
true
;
for
(
let
i
=
0
;
i
<=
this
.
tweenObjectList
.
length
-
1
;
i
++
)
{
this
.
tweenObjectList
[
i
].
update
();
}
isTraversing
=
false
;
this
.
isTraversing
=
false
;
t
weenObjectList
=
tweenObjectList
.
filter
((
tween
)
=>
{
t
his
.
tweenObjectList
=
this
.
tweenObjectList
.
filter
((
tween
)
=>
{
if
(
tween
.
currentTween
==
null
)
return
false
;
for
(
let
removeTarget
of
removeQueue
)
{
for
(
let
removeTarget
of
this
.
removeQueue
)
{
if
(
removeTarget
===
tween
.
target
)
{
return
false
;
}
...
...
@@ -204,53 +187,7 @@ export namespace MTween {
return
true
;
});
removeQueue
=
[];
/* const filter: TweenAnimation[] = [];
let temp: TweenAnimation = null;
for (let i = 0; i < tweenAnimationList.length; i++) {
temp = tweenAnimationList[i];
temp.update();
if (temp.currentTween != null) {
filter.push(temp);
}
}
tweenAnimationList = filter; */
}
/* export class TweenAnimation extends MTweenObject {
protected addTween(tween: MTweenBase) {
this.tweenList.push(tween);
}
private pos: number = 0;
this
.
removeQueue
=
[];
public update() {
if (!this.isPlaying) return;
this.currentTween.apply(MTimer.dtFactor);
if (this.currentTween.frameCount <= 0) {
this.pos++;
if (this.pos < this.tweenList.length) {
this.currentTween = this.tweenList[this.pos];
} else {
this.isPlaying = false;
this.currentTween = null;
}
}
}
public play() {
if (this.isPlaying) return;
this.isPlaying = true;
this.pos = 0;
this.currentTween = this.tweenList[0];
tweenAnimationList.push(this);
}
// public onCompleted: () => void;
private isPlaying: boolean = false;
// private inited: boolean = false;
} */
}
src/custom/shoot-planet/Component/Pool.ts
View file @
9b7b3989
import
{
MUtils
}
from
"../Global/MUtils"
;
import
{
MTween
}
from
"./MTween"
;
export
abstract
class
PoolGroup
<
T
extends
PoolElement
>
{
constructor
(
protected
layer
:
engine
.
Container
)
{
}
protected
data
:
{
[
key
:
string
]:
Pool
<
T
>
}
=
{}
public
recycle
(
key
:
string
,
element
:
T
)
{
this
.
data
[
key
].
recycle
(
element
);
...
...
@@ -11,6 +9,8 @@ export abstract class PoolGroup<T extends PoolElement>{
}
export
abstract
class
Pool
<
T
extends
PoolElement
>
{
constructor
(
protected
layer
:
engine
.
Container
)
{
}
protected
data
:
T
[]
=
[];
public
recycle
(
element
:
T
)
{
...
...
src/custom/shoot-planet/Game/Ball.ts
View file @
9b7b3989
...
...
@@ -8,13 +8,7 @@ import Drop from "./Drop";
import
Bullet
from
"./Bullet"
;
import
{
MUtils
}
from
"../Global/MUtils"
;
import
SoundMgr
from
"../Mgr/SoundMgr"
;
import
Game
from
"./Game"
;
import
BoomEffect
from
"./BoomEffect"
;
import
ballPool
from
"../Pools/BallPool"
;
import
dropPool
from
"../Pools/DropPool"
;
import
{
EffectMgr
}
from
"../Mgr/EffectMgr"
;
import
{
DataMgr
}
from
"../Mgr/DataMgr"
;
import
SpriteFontLabel
,
{
SpriteFont
}
from
"../Component/SpriteFont"
;
import
GuideMgr
from
"../Mgr/GuideMgr"
;
import
MTimer
from
"../Global/MTimer"
;
...
...
@@ -61,12 +55,12 @@ export default class Ball extends MoveObjcet implements PoolElement {
this
.
_score
=
v
;
}
private
static
ballTextures
:
engine
.
Texture
[]
=
[];
public
static
loadTextures
()
{
//
private static ballTextures: engine.Texture[] = [];
/*
public static loadTextures() {
for (let i in imageNames) {
Ball.ballTextures[i] = RES.getRes(imageNames[i]);
}
}
}
*/
private
onScoreIsZero
()
{
if
(
GuideMgr
.
instance
.
guideFlag
==
true
)
{
...
...
@@ -79,9 +73,9 @@ export default class Ball extends MoveObjcet implements PoolElement {
}
}
EffectMgr
.
playBoomEffect
(
this
.
position
,
this
.
scaleRatio
);
DataMgr
.
game
.
_
playBoomEffect
(
this
.
position
,
this
.
scaleRatio
);
SoundMgr
.
instance
.
playEffect
(
"boom"
);
ballPoo
l
.
recycle
(
this
.
poolKey
,
this
);
DataMgr
.
game
.
_pool
.
bal
l
.
recycle
(
this
.
poolKey
,
this
);
}
constructor
(
sizeIndex
:
number
)
{
...
...
@@ -122,7 +116,7 @@ export default class Ball extends MoveObjcet implements PoolElement {
init
(
colorIndex
:
number
,
direction
:
1
|
-
1
,
score
:
number
):
Ball
{
this
.
colorIndex
=
colorIndex
;
this
.
initColorIndex
=
colorIndex
;
this
.
bitmap
.
texture
=
Ball
.
ballTextures
[
colorIndex
]
;
this
.
bitmap
.
texture
=
RES
.
getRes
(
imageNames
[
colorIndex
])
;
this
.
initScore
=
score
;
this
.
score
=
score
;
...
...
@@ -131,13 +125,6 @@ export default class Ball extends MoveObjcet implements PoolElement {
}
startBornStage
(
dir
:
1
|
-
1
)
{
/* this.x = 200;
this.y = 200;
EffectMgr.playBoomEffect(this.position, this.scaleRatio);
return; */
this
.
isBornStage
=
true
;
if
(
dir
==
1
)
{
this
.
x
=
0
-
this
.
width
/
2
-
10
;
...
...
@@ -188,7 +175,7 @@ export default class Ball extends MoveObjcet implements PoolElement {
this
.
physics
.
velocity
.
y
=
-
(
MConst
.
BallVelocityY
*
(
1
+
((
1
/
this
.
scaleRatio
)
-
1
)
*
MUtils
.
random
(
0
,
MConst
.
BallVelocityYRandomFactor
)));
//播放灰尘动画
const
clip
=
EffectMgr
.
createAnimation
(
"duang"
);
const
clip
=
DataMgr
.
game
.
_
createAnimation
(
"duang"
);
clip
.
x
=
this
.
x
-
140
*
this
.
scaleRatio
;
clip
.
y
=
this
.
y
-
50
*
this
.
scaleRatio
;
clip
.
scaleX
=
clip
.
scaleY
=
this
.
scaleRatio
;
...
...
@@ -236,8 +223,7 @@ export default class Ball extends MoveObjcet implements PoolElement {
let
colorIndex
=
Math
.
max
(
this
.
initColorIndex
-
1
,
0
);
let
callback
=
(
direction
:
1
|
-
1
)
=>
{
let
ball
=
ballPool
.
spwan
(
sizeIndex
).
init
(
colorIndex
,
direction
,
score
);
DataMgr
.
game
.
addGameObject
(
ball
,
"Ball"
);
let
ball
=
DataMgr
.
game
.
_pool
.
ball
.
spwan
(
sizeIndex
).
init
(
colorIndex
,
direction
,
score
);
ball
.
x
=
this
.
x
;
ball
.
y
=
this
.
y
;
ball
.
startGravityStage
(
direction
);
...
...
@@ -302,9 +288,7 @@ export default class Ball extends MoveObjcet implements PoolElement {
let
drops
:
Drop
[]
=
[];
for
(
let
id
of
dropIds
)
{
let
drop
=
dropPool
.
spwan
(
id
.
toString
());
DataMgr
.
game
.
addGameObject
(
drop
,
"Drop"
);
drops
.
push
(
drop
);
drops
.
push
(
DataMgr
.
game
.
_pool
.
drop
.
spwan
(
id
.
toString
()));
}
let
dir
=
this
.
x
>
MConst
.
DesignResolution
.
width
/
2
?
-
1
:
1
;
...
...
src/custom/shoot-planet/Game/BoomEffect.ts
View file @
9b7b3989
import
{
MConst
}
from
"../Global/MConst"
;
import
{
MUtils
}
from
"../Global/MUtils"
;
import
{
MTween
}
from
"../Component/MTween"
;
import
{
TextureMgr
}
from
"../Mgr/TextureMgr"
;
import
{
PoolElement
,
Pool
,
PoolGroup
}
from
"../Component/Pool"
;
const
BoomEffectDuration
=
400
;
const
DefaultRingWidth
=
672
;
export
default
class
BoomEffect
{
constructor
(
position
:
engine
.
Point
,
parent
:
engine
.
Container
,
colorIndex
:
number
,
size
:
number
)
{
let
range
=
MConst
.
DefaultBallWidth
*
1.5
*
size
;
for
(
let
i
=
0
;
i
<=
7
;
i
++
)
{
const
star
=
spritePool
.
spwan
(
"star"
,
colorIndex
);
parent
.
addChild
(
star
);
const
randomMax
=
0.5
+
(
size
-
0.3125
)
/
2
;
const
scale
=
MUtils
.
random
(
randomMax
-
0.64
*
size
,
randomMax
);
star
.
width
=
MConst
.
DefaultStarSize
.
width
*
scale
;
star
.
height
=
MConst
.
DefaultStarSize
.
height
*
scale
;
star
.
x
=
position
.
x
;
star
.
y
=
position
.
y
;
MTween
.
get
(
star
)
.
to
({
x
:
position
.
x
+
MUtils
.
random
(
-
1
,
1
)
*
range
-
star
.
width
/
2
,
y
:
position
.
y
+
MUtils
.
random
(
-
1
,
1
)
*
range
-
star
.
height
/
2
,
alpha
:
0
},
BoomEffectDuration
,
false
)
.
call
(()
=>
{
spritePool
.
recycle
(
star
.
poolKey
,
star
);
});
}
//环
for
(
let
i
=
0
;
i
<=
2
;
i
++
)
{
let
ring
=
spritePool
.
spwan
(
"ring"
,
colorIndex
);
parent
.
addChild
(
ring
);
ring
.
scaleX
=
ring
.
scaleY
=
0.186
*
(
i
+
1
)
*
size
;
ring
.
x
=
position
.
x
-
DefaultRingWidth
/
2
;
ring
.
y
=
position
.
y
-
DefaultRingWidth
/
2
;
ring
.
anchorX
=
(
DefaultRingWidth
/
2
);
ring
.
anchorY
=
(
DefaultRingWidth
/
2
);
let
tween
=
MTween
.
get
(
ring
)
.
to
({
scaleX
:
ring
.
scaleX
*
1.4
,
scaleY
:
ring
.
scaleY
*
1.4
,
alpha
:
0
},
BoomEffectDuration
+
(
i
-
1
)
*
BoomEffectDuration
*
0.33
,
false
)
if
(
i
==
2
)
{
tween
.
call
(()
=>
{
spritePool
.
recycle
(
ring
.
poolKey
,
ring
);
});
}
else
{
tween
.
call
(()
=>
{
spritePool
.
recycle
(
ring
.
poolKey
,
ring
);
});
}
}
}
onElementInit
()
{
}
onElementRecycle
()
{
}
}
export
class
BoomEffectSprite
extends
engine
.
Sprite
implements
PoolElement
{
constructor
(
type
:
"star"
|
"ring"
,
colorIndex
:
number
)
{
super
(
TextureMgr
.
get
(
type
,
colorIndex
));
}
poolKey
:
string
;
onElementInit
()
{
this
.
alpha
=
1
;
this
.
visible
=
true
;
}
onElementRecycle
()
{
this
.
visible
=
false
;
}
}
/* class Ring extends BoomEffectSprite {
constructor(type: "star" | "ring", colorIndex: number) {
super(type, colorIndex);
this.anchorX = (DefaultRingWidth / 2);
this.anchorY = (DefaultRingWidth / 2);
}
} */
class
SpritePool
extends
Pool
<
BoomEffectSprite
>
{
public
spwan
(
type
:
"star"
|
"ring"
,
colorIndex
:
number
):
BoomEffectSprite
{
if
(
this
.
data
.
length
>
0
)
{
const
element
=
this
.
data
.
shift
();
element
.
onElementInit
();
return
element
;
}
else
{
return
new
BoomEffectSprite
(
type
,
colorIndex
);
}
}
}
class
SpritePoolGroup
extends
PoolGroup
<
BoomEffectSprite
>
{
public
spwan
(
type
:
"star"
|
"ring"
,
colorIndex
:
number
)
{
const
key
=
type
+
colorIndex
;
if
(
!
this
.
data
[
key
])
{
this
.
data
[
key
]
=
new
SpritePool
();
}
const
element
=
this
.
data
[
key
].
spwan
(
type
,
colorIndex
);
element
.
poolKey
=
key
;
return
element
;
}
}
const
spritePool
=
new
SpritePoolGroup
();
/* class RingPool extends Pool<Ring> {
public spwan(color: number): Ring {
if (this.data.length > 0) {
const element = this.data.shift();
element.onElementInit();
return element;
} else {
return new Ring(color);
}
}
}
class RingPoolGroup extends PoolGroup<Ring> {
public spwan(color: number) {
const key = color.toString();
if (!this.data[key]) {
this.data[key] = new RingPool();
}
const element = this.data[key].spwan(color);
element.poolKey = key;
return element;
}
}
const ringPool = new RingPoolGroup(); */
/* class BoomEffectPool extends Pool<BoomEffect> {
public spwan(color: number, size: number): BoomEffect {
if (this.data.length > 0) {
const element = this.data.shift();
element.onElementInit();
return element;
} else {
return new BoomEffect(color, size);
}
}
}
class BoomEffectPoolGroup extends PoolGroup<BoomEffect> {
public spwan(color: number, size: number) {
const key = color.toString() + size.toString();
if (!this.data[key]) {
this.data[key] = new BoomEffectPool()
}
const element = this.data[key].spwan(color, size);
element.poolKey = key;
return element;
}
}
let boomEffectPool = new BoomEffectPoolGroup();
export default boomEffectPool; */
\ No newline at end of file
src/custom/shoot-planet/Game/Bullet.ts
View file @
9b7b3989
...
...
@@ -5,8 +5,8 @@ import GameObject from "./GameObject";
import
Collider
,
{
CircleCollider
,
ColliderGroup
,
PointCollider
}
from
"../Phycics/Collider"
;
import
Game
from
"./Game"
;
import
{
DataMgr
}
from
"../Mgr/DataMgr"
;
import
bulletPool
from
"../Pools/BulletPool"
;
import
MTimer
from
"../Global/MTimer"
;
import
GameMgr
from
"../Mgr/GameMgr"
;
const
bulletSpeedValue
=
20
;
/**顾名思义 */
...
...
@@ -41,7 +41,7 @@ export default class Bullet extends MoveObjcet implements PoolElement {
onCollisionEnter
(
other
:
Collider
)
{
if
(
other
.
group
==
ColliderGroup
.
Ball
||
other
.
group
==
ColliderGroup
.
Top
)
{
bulletPool
.
recycle
(
this
);
DataMgr
.
game
.
_pool
.
bullet
.
recycle
(
this
);
}
}
}
...
...
@@ -51,17 +51,16 @@ export class BulletGroup {
public
restFrameCountThatBulletsMoveInX
:
number
=
frameCountThatBulletsMoveInX
;
constructor
(
position
:
engine
.
Point
,
rowBulletNum
:
number
)
{
for
(
let
i
=
0
;
i
<
rowBulletNum
;
i
++
)
{
const
bullet
=
bulletPool
.
spwan
().
init
(
Math
.
floor
(
DataMgr
.
game
.
powerScore
/
100
));
DataMgr
.
game
.
addGameObject
(
bullet
,
"Bullet"
);
const
bullet
=
DataMgr
.
game
.
_pool
.
bullet
.
spwan
().
init
(
Math
.
floor
(
DataMgr
.
game
.
powerScore
/
100
));
bullet
.
x
=
position
.
x
-
bullet
.
width
/
2
;
bullet
.
y
=
position
.
y
+
bullet
.
height
/
2
;
this
.
moveDatas
.
push
({
bullet
:
bullet
,
frameOffset
:
((
i
-
(
rowBulletNum
-
1
)
/
2
)
*
(
bullet
.
width
+
2
))
/
frameCountThatBulletsMoveInX
frameOffset
:
((
i
-
(
rowBulletNum
-
1
)
/
2
)
*
(
bullet
.
width
+
3
))
/
frameCountThatBulletsMoveInX
});
}
HorizontalMoveMgr
.
instance
.
movingList
.
push
(
this
);
DataMgr
.
game
.
_horizontalMoveMgr
.
movingList
.
push
(
this
);
}
public
onUpdate
()
{
...
...
@@ -74,20 +73,11 @@ export class BulletGroup {
}
}
class
HorizontalMoveMgr
{
private
static
_instance
:
HorizontalMoveMgr
=
null
;
public
static
get
instance
():
HorizontalMoveMgr
{
if
(
!
HorizontalMoveMgr
.
_instance
)
{
const
instance
=
new
HorizontalMoveMgr
();
HorizontalMoveMgr
.
_instance
=
instance
;
MTimer
.
onFrame
(
"HorizontalMoveMgr"
,
instance
.
onUpdate
,
instance
);
//单例注册回调
}
return
HorizontalMoveMgr
.
_instance
;
}
export
class
HorizontalMoveMgr
extends
GameMgr
{
constructor
()
{
super
(
"HorizontalMoveMgr"
)
}
public
movingList
:
BulletGroup
[]
=
[];
public
onUpdate
()
{
protected
onUpdate
()
{
if
(
this
.
pause
)
return
;
for
(
let
i
=
0
;
i
<
this
.
movingList
.
length
;
i
++
)
{
this
.
movingList
[
i
].
onUpdate
();
}
...
...
src/custom/shoot-planet/Game/Car.ts
View file @
9b7b3989
...
...
@@ -2,12 +2,10 @@ import GameObject from "./GameObject";
import
Collider
,
{
RectCollider
,
ColliderGroup
}
from
"../Phycics/Collider"
;
import
{
MConst
}
from
"../Global/MConst"
;
import
Bullet
,
{
BulletGroup
}
from
"./Bullet"
;
import
{
MTween
}
from
"../Component/MTween"
;
import
SoundMgr
from
"../Mgr/SoundMgr"
;
import
MTimer
from
"../Global/MTimer"
;
import
Game
from
"./Game"
;
import
{
DataMgr
}
from
"../Mgr/DataMgr"
;
import
bulletPool
from
"../Pools/BulletPool"
;
...
...
@@ -47,8 +45,6 @@ export default class Car extends GameObject {
let
collider
=
this
.
addComponent
<
RectCollider
>
(
RectCollider
);
collider
.
setData
(
41
,
13
,
65
,
129
);
collider
.
group
=
ColliderGroup
.
Car
;
this
.
addEventListener
(
engine
.
Event
.
REMOVED_FROM_STAGE
,
this
.
onDestroy
,
this
);
}
/* private createPart(source: string, x: number, y: number) {
...
...
@@ -96,7 +92,7 @@ export default class Car extends GameObject {
}
private
onceBlink
()
{
MTween
.
get
(
this
)
DataMgr
.
game
.
_tweenMgr
.
get
(
this
)
.
to
({
alpha
:
0
},
1
,
true
)
.
wait
(
2
)
.
to
({
alpha
:
1
},
1
,
true
)
...
...
@@ -106,12 +102,12 @@ export default class Car extends GameObject {
revive
()
{
this
.
invincibleDuration
=
MConst
.
ReviveInvincibleDuration
*
1000
;
MTween
.
removeTweens
(
this
);
DataMgr
.
game
.
_tweenMgr
.
removeTweens
(
this
);
this
.
onceBlink
();
MTimer
.
setFrameTimer
(
MConst
.
ReviveInvincibleDuration
*
60
,
()
=>
{
//无敌结束
this
.
alpha
=
1
;
MTween
.
removeTweens
(
this
);
DataMgr
.
game
.
_tweenMgr
.
removeTweens
(
this
);
});
}
...
...
@@ -162,8 +158,4 @@ export default class Car extends GameObject {
this
.
fireParticleTimer
++
;
}
onDestroy
()
{
MTween
.
removeTweens
(
this
);
}
}
\ No newline at end of file
src/custom/shoot-planet/Game/Drop.ts
View file @
9b7b3989
import
MoveObjcet
from
"./MoveObject"
;
import
{
MConfigs
}
from
"../Global/MConfigs"
;
import
Collider
,
{
ColliderGroup
,
PointCollider
}
from
"../Phycics/Collider"
;
import
{
MTween
}
from
"../Component/MTween"
;
import
SoundMgr
from
"../Mgr/SoundMgr"
;
import
Game
from
"./Game"
;
import
{
PoolElement
}
from
"../Component/Pool"
;
import
dropPool
from
"../Pools/DropPool"
;
import
{
DataMgr
}
from
"../Mgr/DataMgr"
;
import
DropBlinkMgr
from
"../Mgr/DropBlinkMgr"
;
const
dropImgNames
=
[
"f7221f86-f376-40ce-b0e8-f7ea573ec780"
,
...
...
@@ -65,7 +61,7 @@ export default class Drop extends MoveObjcet implements PoolElement {
private
eated
()
{
SoundMgr
.
instance
.
playEffect
(
"collect"
);
this
.
physics
.
rotateVelocity
=
0
;
D
ropBlinkMgr
.
instance
.
remove
(
this
);
D
ataMgr
.
game
.
_dropBlinkMgr
.
remove
(
this
);
this
.
visible
=
true
;
this
.
rotation
=
0
;
this
.
physics
.
enabled
=
false
;
...
...
@@ -77,12 +73,14 @@ export default class Drop extends MoveObjcet implements PoolElement {
DataMgr
.
game
.
_PowerScore
+=
this
.
scoreValue
;
}
MTween
.
removeTweens
(
this
);
MTween
.
get
(
this
)
const
tweenMgr
=
DataMgr
.
game
.
_tweenMgr
;
tweenMgr
.
removeTweens
(
this
);
tweenMgr
.
get
(
this
)
.
to
({
y
:
this
.
y
-
200
,
alpha
:
0
},
1000
,
false
)
.
call
(()
=>
{
dropPool
.
recycle
(
this
.
id
.
toString
(),
this
);
MTween
.
removeTweens
(
this
);
DataMgr
.
game
.
_pool
.
drop
.
recycle
(
this
.
id
.
toString
(),
this
);
tweenMgr
.
removeTweens
(
this
);
});
}
...
...
@@ -112,7 +110,7 @@ export default class Drop extends MoveObjcet implements PoolElement {
this
.
physics
.
velocity
.
y
=
0
;
this
.
physics
.
acceleration
.
y
=
0
;
this
.
physics
.
velocity
.
x
*=
0.5
;
D
ropBlinkMgr
.
instance
.
add
(
this
);
D
ataMgr
.
game
.
_dropBlinkMgr
.
add
(
this
);
this
.
physics
.
rotateVelocity
=
this
.
physics
.
velocity
.
x
*
(
180
/
(
Math
.
PI
*
13
));
}
...
...
src/custom/shoot-planet/Game/Game.ts
View file @
9b7b3989
...
...
@@ -6,19 +6,26 @@ import Physics from "../Phycics/Physics";
import
GameObject
from
"./GameObject"
;
import
{
RectCollider
,
ColliderGroup
}
from
"../Phycics/Collider"
;
import
{
MConfigs
}
from
"../Global/MConfigs"
;
import
{
MTween
}
from
"../Component/MTween"
;
import
{
MTween
as
TweenMgr
}
from
"../Component/MTween"
;
import
Drop
from
"./Drop"
;
import
{
MUtils
}
from
"../Global/MUtils"
;
import
{
arrayRemove
,
getBallScore
}
from
"../Global/GUtils"
;
import
MTimer
from
"../Global/MTimer"
;
import
PhycicsSystem
from
"../Phycics/PhycicsSystem"
;
import
Bullet
from
"./Bullet"
;
import
ballPool
from
"../Pools/BallPool"
;
import
{
EffectMgr
}
from
"../Mgr/EffectMgr
"
;
import
FrameAnimation
from
"../Component/FrameAnimation"
;
import
Bullet
,
{
HorizontalMoveMgr
}
from
"./Bullet"
;
import
{
BallPoolGroup
}
from
"../Pools/BallPool"
;
import
AnimationPoolGroup
from
"../Pools/AnimationPool
"
;
import
FrameAnimation
,
{
FrameAnimationMgr
}
from
"../Component/FrameAnimation"
;
import
{
DuangAltaData
,
NumFontData
,
BoomAnimationData
}
from
"../Global/JsonData"
;
import
SpriteFontLabel
,
{
SpriteFont
}
from
"../Component/SpriteFont"
;
import
GuideMgr
from
"../Mgr/GuideMgr"
;
import
{
Pool
,
PoolGroup
,
PoolElement
}
from
"../Component/Pool"
;
import
{
BulletPool
}
from
"../Pools/BulletPool"
;
import
SpBoomEffectPoolGroup
,
{
SpBoomEffectMgr
}
from
"./SpBoomEffect"
;
import
DropPoolGroup
from
"../Pools/DropPool"
;
import
DropBlinkMgr
from
"../Mgr/DropBlinkMgr"
;
import
GameMgr
from
"../Mgr/GameMgr"
;
import
{
DataMgr
}
from
"../Mgr/DataMgr"
;
type
LayerName
=
"Bullet"
|
"Ball"
|
"Drop"
|
"Effect"
;
...
...
@@ -62,8 +69,10 @@ export default class Game {
this
.
_pause
=
v
;
this
.
timing
=
!
this
.
_pause
;
//取反
PhycicsSystem
.
instance
.
pause
=
this
.
_pause
;
MTween
.
pause
=
this
.
_pause
;
for
(
let
mgr
of
this
.
mgrs
)
{
mgr
.
pause
=
this
.
_pause
;
}
}
public
get
pause
()
{
return
this
.
_pause
;
...
...
@@ -83,11 +92,22 @@ export default class Game {
this
.
pause
=
false
;
}
/**
结束
游戏 */
/**
销毁
游戏 */
public
destroy
()
{
this
.
node
.
destroy
();
PhycicsSystem
.
instance
.
enabled
=
false
;
for
(
let
mgr
of
this
.
mgrs
)
{
mgr
.
onDestroy
();
}
MTimer
.
removeOnFrame
(
"Game"
);
MTimer
.
removeOnFrame
(
"Car"
);
}
private
mgrs
:
GameMgr
[]
=
[];
public
_tweenMgr
:
TweenMgr
=
new
TweenMgr
();
public
_phycicsSystem
:
PhycicsSystem
=
new
PhycicsSystem
();
public
_boomEffectMgr
:
SpBoomEffectMgr
=
new
SpBoomEffectMgr
();
public
_animationMgr
:
FrameAnimationMgr
=
new
FrameAnimationMgr
();
public
_horizontalMoveMgr
:
HorizontalMoveMgr
=
new
HorizontalMoveMgr
();
private
loadRes
()
{
FrameAnimation
.
loadRes
(
RES
.
getRes
(
"217164f4-a185-429c-8706-818137a4e438"
),
DuangAltaData
);
...
...
@@ -95,14 +115,26 @@ export default class Game {
FrameAnimation
.
loadRes
(
RES
.
getRes
(
"53c65221-3fbc-41d9-8cef-8a846876fe06"
),
BoomAnimationData
);
}
private
initMgrs
()
{
this
.
mgrs
=
[
this
.
_dropBlinkMgr
,
this
.
_tweenMgr
,
this
.
_phycicsSystem
,
this
.
_boomEffectMgr
,
this
.
_animationMgr
,
this
.
_horizontalMoveMgr
];
for
(
let
mgr
of
this
.
mgrs
)
{
mgr
.
onInit
();
}
}
constructor
(
parent
:
engine
.
Container
)
{
Ball
.
loadTextures
()
;
PhycicsSystem
.
instance
.
enabled
=
true
;
DataMgr
.
game
=
this
;
this
.
initMgrs
()
;
this
.
pause
=
false
;
this
.
loadRes
();
//创建墙和地面
this
.
createWall
();
parent
.
addChild
(
this
.
node
);
this
.
node
.
width
=
MConst
.
DesignResolution
.
width
;
...
...
@@ -112,7 +144,7 @@ export default class Game {
bg
.
y
=
-
10
;
this
.
node
.
addChild
(
bg
);
//子弹层
this
.
node
.
addChild
(
this
.
layers
[
"Bullet"
]
);
this
.
node
.
addChild
(
this
.
layers
.
bullet
);
//炮车
let
car
=
new
Car
();
car
.
x
=
this
.
node
.
width
/
2
-
car
.
width
/
2
;
...
...
@@ -124,30 +156,20 @@ export default class Game {
};
this
.
_car
=
car
;
let
rect
=
new
GameObject
();
rect
.
width
=
100
;
rect
.
height
=
100
;
this
.
node
.
addChild
(
rect
);
//球的层
this
.
node
.
addChild
(
this
.
layers
[
"Ball"
]);
this
.
node
.
addChild
(
this
.
layers
.
ball
);
//掉落物层
this
.
node
.
addChild
(
this
.
layers
[
"Drop"
]);
this
.
node
.
addChild
(
this
.
layers
.
drop
);
//特效层
this
.
node
.
addChild
(
this
.
layers
.
effect
);
//动画层
this
.
node
.
addChild
(
this
.
layers
[
"Effect"
]);
EffectMgr
.
init
(
this
.
layers
[
"Effect"
]);
this
.
node
.
addChild
(
this
.
layers
.
animation
);
//禁用层级交互事件
this
.
layers
[
"Bullet"
].
mouseChildren
=
false
;
this
.
layers
[
"Bullet"
].
mouseEnabled
=
false
;
this
.
layers
[
"Ball"
].
mouseChildren
=
false
;
this
.
layers
[
"Ball"
].
mouseEnabled
=
false
;
this
.
layers
[
"Drop"
].
mouseChildren
=
false
;
this
.
layers
[
"Drop"
].
mouseEnabled
=
false
;
this
.
layers
[
"Effect"
].
mouseChildren
=
false
;
this
.
layers
[
"Effect"
].
mouseEnabled
=
false
;
for
(
let
k
in
this
.
layers
)
{
this
.
layers
[
k
].
mouseChildren
=
false
;
this
.
layers
[
k
].
mouseEnabled
=
false
;
}
//玩家控制器
let
playerController
=
new
PlayerController
();
...
...
@@ -161,6 +183,11 @@ export default class Game {
//添加监听器
MTimer
.
onFrame
(
"Game"
,
this
.
onUpdate
,
this
);
this
.
createPools
();
//创建墙和地面
this
.
createWall
();
//开始倒计时
this
.
timing
=
true
;
...
...
@@ -168,11 +195,6 @@ export default class Game {
// this._PowerScore = 2000;
}
public
addGameObject
(
gameObject
:
GameObject
,
layer
:
LayerName
)
{
this
.
layers
[
layer
].
addChild
(
gameObject
);
}
/****** private method ******/
...
...
@@ -229,8 +251,7 @@ export default class Game {
size
=
3
;
}
let
color
=
MUtils
.
randomInt
(
size
,
MConst
.
MaxColorIndex
);
let
ball
=
ballPool
.
spwan
(
size
);
this
.
addGameObject
(
ball
,
"Ball"
);
let
ball
=
this
.
_pool
.
ball
.
spwan
(
size
);
let
dir
:
1
|
-
1
=
Math
.
random
()
>
0.5
?
-
1
:
1
;
const
score
=
getBallScore
(
this
.
_BulletScore
,
this
.
_PowerScore
,
color
);
ball
.
init
(
color
,
dir
,
score
);
...
...
@@ -294,7 +315,7 @@ export default class Game {
* 不建议调用
*/
public
_shake
()
{
MTween
.
removeTweens
(
this
.
node
);
this
.
_tweenMgr
.
removeTweens
(
this
.
node
);
let
count
=
0
;
let
callback
=
()
=>
{
...
...
@@ -302,7 +323,7 @@ export default class Game {
count
++
;
this
.
node
.
x
=
10
;
MTween
.
get
(
this
.
node
)
this
.
_tweenMgr
.
get
(
this
.
node
)
.
wait
(
1
,
true
)
.
to
({
x
:
0
,
y
:
-
10
},
1
,
true
)
.
to
({
x
:
-
10
,
y
:
0
},
1
,
true
)
...
...
@@ -314,16 +335,48 @@ export default class Game {
callback
();
}
public
_pool
:
{
ball
:
BallPoolGroup
,
bullet
:
BulletPool
,
boomEffect
:
SpBoomEffectPoolGroup
animation
:
AnimationPoolGroup
,
drop
:
DropPoolGroup
}
=
null
;
private
createPools
()
{
this
.
_pool
=
{
ball
:
new
BallPoolGroup
(
this
.
layers
.
ball
),
bullet
:
new
BulletPool
(
this
.
layers
.
bullet
),
animation
:
new
AnimationPoolGroup
(
this
.
layers
.
animation
),
boomEffect
:
new
SpBoomEffectPoolGroup
(
this
.
layers
.
effect
),
drop
:
new
DropPoolGroup
(
this
.
layers
.
drop
)
};
}
public
_playBoomEffect
(
position
:
engine
.
Point
,
size
:
number
)
{
const
effect
=
this
.
_pool
.
boomEffect
.
spwan
(
MUtils
.
randomInt
(
0
,
3
),
size
);
effect
.
position
=
position
;
}
public
_createAnimation
(
key
:
string
)
{
const
clip
=
this
.
_pool
.
animation
.
spwan
(
key
);
clip
.
onCompleted
=
()
=>
{
this
.
_pool
.
animation
.
recycle
(
key
,
clip
);
}
return
clip
;
}
/****** private field ******/
private
layers
:
{
[
key
in
LayerName
]:
engine
.
Container
}
=
{
"Bullet"
:
new
engine
.
Container
(),
"Ball"
:
new
engine
.
Container
(),
"Drop"
:
new
engine
.
Container
(),
"Effect"
:
new
engine
.
Container
()
public
_dropBlinkMgr
=
new
DropBlinkMgr
();
private
layers
=
{
bullet
:
new
engine
.
Container
(),
ball
:
new
engine
.
Container
(),
drop
:
new
engine
.
Container
(),
effect
:
new
engine
.
Container
(),
animation
:
new
engine
.
Container
()
};
/**不建议使用 */
public
get
_score
():
number
{
...
...
src/custom/shoot-planet/Game/SpBoomEffect.ts
View file @
9b7b3989
...
...
@@ -2,6 +2,8 @@ import { TextureMgr } from "../Mgr/TextureMgr";
import
{
MUtils
}
from
"../Global/MUtils"
;
import
MTimer
from
"../Global/MTimer"
;
import
{
Pool
,
PoolGroup
,
PoolElement
}
from
"../Component/Pool"
;
import
{
DataMgr
}
from
"../Mgr/DataMgr"
;
import
GameMgr
from
"../Mgr/GameMgr"
;
const
InitSpeedValue
:
number
=
0.08
;
...
...
@@ -18,16 +20,7 @@ class Line {
const
sprite
=
new
engine
.
Sprite
(
TextureMgr
.
get
((
"fireworks_line_"
+
type
)
as
any
,
color
));
parent
.
addChild
(
sprite
);
sprite
.
anchorX
=
sprite
.
width
/
2
;
// sprite.y = -sprite.height;
/* let mask = new engine.Graphics();
mask.beginFill(0xffffff);
mask.drawRect(0, 0, sprite.width, 200);
mask.endFill();
parent.addChild(mask);
sprite.mask = mask; */
sprite
.
rotation
=
rotation
;
// mask.rotation = rotation;
// mask.anchorX = sprite.anchorX;
this
.
sprite
=
sprite
;
//计算方向
...
...
@@ -54,31 +47,27 @@ class Line {
}
this
.
frameTimer
++
;
/* if (this.speedValue < InitSpeedValue * 0.4) {
} */
/* this.speedValue += InitAcceleration * dt;
if (this.speedValue < 0) {
this.speedValue = 0;
} */
}
}
export
namespace
SpBoomEffect
Mgr
{
export
let
list
:
SpBoomEffect
[]
=
[];
export
class
SpBoomEffectMgr
extends
Game
Mgr
{
constructor
()
{
super
(
"SpBoomEffectMgr"
)
}
export
function
onUpdate
(
dt
:
number
)
{
public
list
:
SpBoomEffect
[]
=
[];
protected
onUpdate
(
dt
:
number
)
{
if
(
this
.
pause
)
return
;
let
filter
:
SpBoomEffect
[]
=
[];
for
(
let
i
of
list
)
{
for
(
let
i
of
this
.
list
)
{
if
(
i
.
onUpdate
(
dt
))
{
filter
.
push
(
i
);
}
}
list
=
filter
;
this
.
list
=
filter
;
}
}
class
SpBoomEffect
extends
engine
.
Container
implements
PoolElement
{
private
lines
:
Line
[]
=
[];
public
onUpdate
(
dt
:
number
)
{
...
...
@@ -87,7 +76,7 @@ class SpBoomEffect extends engine.Container implements PoolElement {
}
if
(
this
.
lines
[
0
].
sprite
.
alpha
<=
0
)
{
spBoomEffectPool
.
recycle
(
this
.
poolKey
,
this
);
DataMgr
.
game
.
_pool
.
boomEffect
.
recycle
(
this
.
poolKey
,
this
);
return
false
;
}
return
true
;
...
...
@@ -100,7 +89,7 @@ class SpBoomEffect extends engine.Container implements PoolElement {
let
line
=
new
Line
(
this
,
i
%
2
,
color
,
i
*
22.5
);
this
.
lines
.
push
(
line
);
}
SpB
oomEffectMgr
.
list
.
push
(
this
);
DataMgr
.
game
.
_b
oomEffectMgr
.
list
.
push
(
this
);
}
onElementInit
()
{
...
...
@@ -109,7 +98,7 @@ class SpBoomEffect extends engine.Container implements PoolElement {
for
(
let
i
of
this
.
lines
)
{
i
.
init
();
}
SpB
oomEffectMgr
.
list
.
push
(
this
);
DataMgr
.
game
.
_b
oomEffectMgr
.
list
.
push
(
this
);
}
onElementRecycle
()
{
...
...
@@ -127,16 +116,18 @@ class SpBoomEffectPool extends Pool<SpBoomEffect> {
element
.
onElementInit
();
return
element
;
}
else
{
return
new
SpBoomEffect
(
color
,
size
);
const
e
=
new
SpBoomEffect
(
color
,
size
);
this
.
layer
.
addChild
(
e
);
return
e
;
}
}
}
class
SpBoomEffectPoolGroup
extends
PoolGroup
<
SpBoomEffect
>
{
export
default
class
SpBoomEffectPoolGroup
extends
PoolGroup
<
SpBoomEffect
>
{
public
spwan
(
color
:
number
,
size
:
number
)
{
const
key
=
color
.
toString
()
+
size
;
if
(
!
this
.
data
[
key
])
{
this
.
data
[
key
]
=
new
SpBoomEffectPool
()
this
.
data
[
key
]
=
new
SpBoomEffectPool
(
this
.
layer
)
}
const
element
=
this
.
data
[
key
].
spwan
(
color
,
size
);
element
.
poolKey
=
key
;
...
...
@@ -144,6 +135,3 @@ class SpBoomEffectPoolGroup extends PoolGroup<SpBoomEffect> {
}
}
let
spBoomEffectPool
:
SpBoomEffectPoolGroup
=
new
SpBoomEffectPoolGroup
();
export
default
spBoomEffectPool
;
src/custom/shoot-planet/Global/MTimer.ts
View file @
9b7b3989
...
...
@@ -49,6 +49,13 @@ export default class MTimer {
_onFrame
.
add
(
callback
,
thisObj
);
}
public
static
removeOnFrame
(
key
:
string
)
{
if
(
onFrameCaches
[
key
])
{
_onFrame
.
remove
(
onFrameCaches
[
key
].
callback
,
onFrameCaches
[
key
].
thisObj
);
delete
onFrameCaches
[
key
];
}
}
/**
* 设置帧计时器
*/
...
...
src/custom/shoot-planet/Mgr/DropBlinkMgr.ts
View file @
9b7b3989
import
Drop
from
"../Game/Drop"
;
import
MTimer
from
"../Global/MTimer"
;
import
GameMgr
from
"./GameMgr"
;
export
default
class
DropBlinkMgr
{
private
static
_instance
:
DropBlinkMgr
=
null
;
public
static
get
instance
():
DropBlinkMgr
{
if
(
!
this
.
_instance
)
{
this
.
_instance
=
new
DropBlinkMgr
();
export
default
class
DropBlinkMgr
extends
GameMgr
{
constructor
()
{
super
(
"DropBlinkMgr"
);
}
return
this
.
_instance
;
}
private
list
:
{
drop
:
Drop
,
count
:
number
...
...
@@ -25,18 +20,11 @@ export default class DropBlinkMgr {
this
.
list
=
this
.
list
.
filter
(
e
=>
e
.
drop
!==
drop
);
}
public
static
init
()
{
MTimer
.
onFrame
(
"DropBlinkMgr"
,
DropBlinkMgr
.
instance
.
onUpdate
,
DropBlinkMgr
.
instance
);
// engine.gameStage.addEventListener(engine.Event.ENTER_FRAME, DropBlinkMgr.instance.onUpdate, DropBlinkMgr.instance);
}
/* public static destroy() {
engine.gameStage.addEventListener(engine.Event.ENTER_FRAME, DropBlinkMgr.instance.onUpdate, DropBlinkMgr.instance);
} */
private
frameTimer
:
number
=
0
;
public
onUpdate
()
{
if
(
this
.
pause
)
return
;
if
(
this
.
frameTimer
%
BlinkDuration
==
0
)
{
let
temp
:
{
drop
:
Drop
,
...
...
src/custom/shoot-planet/Mgr/EffectMgr.ts
deleted
100644 → 0
View file @
78b9c9db
import
{
MUtils
}
from
"../Global/MUtils"
;
import
BoomEffect
from
"../Game/BoomEffect"
;
import
FrameAnimation
from
"../Component/FrameAnimation"
;
import
{
Pool
,
PoolGroup
,
PoolElement
}
from
"../Component/Pool"
;
import
SpBoomEffect
from
"../Game/SpBoomEffect"
;
import
spBoomEffectPool
from
"../Game/SpBoomEffect"
;
export
namespace
EffectMgr
{
let
effectLayer
:
engine
.
Container
=
null
;
let
layers
:
engine
.
Container
[]
=
[];
export
function
init
(
effectLayer
:
engine
.
Container
)
{
this
.
effectLayer
=
effectLayer
;
layers
[
0
]
=
new
engine
.
Container
();
layers
[
1
]
=
new
engine
.
Container
();
effectLayer
.
addChild
(
layers
[
0
]);
effectLayer
.
addChild
(
layers
[
1
]);
}
export
function
playBoomEffect
(
position
:
engine
.
Point
,
size
:
number
)
{
const
colorIndex
=
MUtils
.
randomInt
(
0
,
5
);
// new BoomEffect(position, layers[1], colorIndex, size);
let
effect
=
spBoomEffectPool
.
spwan
(
MUtils
.
randomInt
(
0
,
3
),
size
);
layers
[
1
].
addChild
(
effect
);
effect
.
position
=
position
;
}
export
function
createAnimation
(
key
:
string
):
Animation
{
let
clip
=
animationPool
.
spwan
(
key
);
layers
[
0
].
addChild
(
clip
);
clip
.
onCompleted
=
()
=>
{
animationPool
.
recycle
(
key
,
clip
);
}
return
clip
;
}
}
class
Animation
extends
FrameAnimation
implements
PoolElement
{
onElementInit
()
{
this
.
visible
=
true
;
this
.
curPos
=
0
;
}
onElementRecycle
()
{
this
.
visible
=
false
;
}
}
class
AnimationPool
extends
Pool
<
Animation
>
{
public
spwan
(
key
:
string
):
Animation
{
if
(
this
.
data
.
length
>
0
)
{
const
element
=
this
.
data
.
shift
();
element
.
onElementInit
();
return
element
;
}
else
{
return
new
Animation
(
key
);
}
}
}
class
AnimationPoolGroup
extends
PoolGroup
<
Animation
>
{
public
spwan
(
key
:
string
)
{
if
(
!
this
.
data
[
key
])
{
this
.
data
[
key
]
=
new
AnimationPool
()
as
Pool
<
Animation
>
;
}
const
element
=
this
.
data
[
key
].
spwan
(
key
);
return
element
;
}
}
const
animationPool
=
new
AnimationPoolGroup
();
src/custom/shoot-planet/Mgr/GameMgr.ts
0 → 100644
View file @
9b7b3989
import
MTimer
from
"../Global/MTimer"
;
export
default
abstract
class
GameMgr
{
constructor
(
private
name
:
string
)
{
}
public
onInit
():
void
{
MTimer
.
onFrame
(
this
.
name
,
this
.
onUpdate
,
this
);
}
public
onDestroy
()
{
MTimer
.
removeOnFrame
(
this
.
name
);
}
protected
onUpdate
(
dt
:
number
)
{
}
public
pause
:
boolean
=
false
}
\ No newline at end of file
src/custom/shoot-planet/Mgr/TextureMgr.ts
View file @
9b7b3989
...
...
@@ -34,15 +34,15 @@ export namespace TextureMgr {
]
}
const
caches
:
{
/*
const caches: {
[uuid: string]: engine.Texture
}
=
{};
} = {};
*/
export
function
get
(
type
:
ImgType
,
index
:
number
)
{
const
uuid
=
uuids
[
type
][
index
];
if
(
!
caches
[
uuid
])
{
caches
[
uuid
]
=
RES
.
getRes
(
uuid
)
;
}
return
caches
[
uuid
]
;
/*
if (!caches[uuid]) {
caches[uuid] = ;
}
*/
return
RES
.
getRes
(
uuid
)
;
}
}
\ No newline at end of file
src/custom/shoot-planet/Phycics/Collider.ts
View file @
9b7b3989
...
...
@@ -2,6 +2,7 @@ import GameComponent from "../Game/GameComponent";
import
GameObject
from
"../Game/GameObject"
;
import
PhycicsSystem
from
"./PhycicsSystem"
;
import
Physics
from
"./Physics"
;
import
{
DataMgr
}
from
"../Mgr/DataMgr"
;
export
default
abstract
class
Collider
extends
GameComponent
{
public
physics
:
Physics
=
null
;
...
...
@@ -9,7 +10,7 @@ export default abstract class Collider extends GameComponent {
set
group
(
group
:
ColliderGroup
)
{
if
(
this
.
_group
==
null
)
{
this
.
_group
=
group
;
PhycicsSystem
.
instance
.
addCollider
(
this
);
DataMgr
.
game
.
_phycicsSystem
.
addCollider
(
this
);
}
else
{
this
.
_group
=
group
;
}
...
...
@@ -27,7 +28,7 @@ export default abstract class Collider extends GameComponent {
onEnabled
()
{
//自动设置物理组件
if
(
this
.
group
)
PhycicsSystem
.
instance
.
addCollider
(
this
);
DataMgr
.
game
.
_phycicsSystem
.
addCollider
(
this
);
let
physics
=
this
.
owner
.
getComponent
<
Physics
>
(
Physics
);
if
(
physics
)
{
this
.
physics
=
physics
;
...
...
@@ -40,7 +41,7 @@ export default abstract class Collider extends GameComponent {
abstract
getWorldPosition
(
out
:
number
[]):
void
;
onDisabled
()
{
PhycicsSystem
.
instance
.
removeCollider
(
this
);
DataMgr
.
game
.
_phycicsSystem
.
removeCollider
(
this
);
}
/**获取碰撞器的中心的节点坐标 */
...
...
src/custom/shoot-planet/Phycics/PhycicsSystem.ts
View file @
9b7b3989
...
...
@@ -3,31 +3,12 @@ import Collider, { CircleCollider, RectCollider, ColliderType, ColliderGroup, Po
import
{
arrayRemove
}
from
"../Global/GUtils"
;
import
MTimer
from
"../Global/MTimer"
;
import
DebugMgr
from
"../Mgr/DebugMgr"
;
import
GameMgr
from
"../Mgr/GameMgr"
;
let
instanceId1
:
number
=
null
;
let
instanceId2
:
number
=
null
;
export
default
class
PhycicsSystem
{
private
static
_instance
:
PhycicsSystem
=
null
;
public
static
get
instance
():
PhycicsSystem
{
if
(
!
PhycicsSystem
.
_instance
)
{
PhycicsSystem
.
_instance
=
new
PhycicsSystem
();
}
return
PhycicsSystem
.
_instance
;
}
public
static
init
()
{
const
ins
=
PhycicsSystem
.
instance
;
// engine.gameStage.addEventListener(engine.Event.ENTER_FRAME, ins.onUpdate, ins);
MTimer
.
onFrame
(
"PhycicsSystem"
,
ins
.
onUpdate
,
ins
);
}
/* public static destroy() {
const ins = PhycicsSystem.instance;
engine.gameStage.removeEventListener(engine.Event.ENTER_FRAME, ins.onUpdate, ins)
} */
private
_enabled
:
boolean
=
false
;
export
default
class
PhycicsSystem
extends
GameMgr
{
/* private _enabled: boolean = false;
public set enabled(v: boolean) {
this._enabled = v;
...
...
@@ -38,25 +19,30 @@ export default class PhycicsSystem {
}
public get enabled() {
return this._enabled;
}
public
pause
:
boolean
=
false
;
} */
constructor
()
{
super
(
"PhycicsSystem"
);
}
private
phycicsList
:
Physics
[]
=
[];
private
clear
()
{
onInit
()
{
super
.
onInit
();
for
(
let
i
=
0
;
i
<=
GroupMaxIndex
;
i
++
)
{
this
.
colliderList
[
i
]
=
[];
}
}
public
onDestroy
()
{
super
.
onDestroy
();
for
(
let
i
=
0
;
i
<=
GroupMaxIndex
;
i
++
)
{
this
.
colliderList
[
i
]
=
[];
}
this
.
phycicsList
=
[];
}
pr
ivate
onUpdate
()
{
pr
otected
onUpdate
()
{
if
(
this
.
pause
)
return
;
for
(
let
i
of
PhycicsSystem
.
instance
.
phycicsList
)
{
if
(
this
.
enabled
==
false
)
return
;
for
(
let
i
of
this
.
phycicsList
)
{
i
.
onFixedUpdate
(
MTimer
.
dtFactor
);
}
...
...
@@ -118,7 +104,6 @@ export default class PhycicsSystem {
}
} */
//查找所有碰撞
let
i
=
0
,
j
=
0
,
...
...
@@ -130,12 +115,11 @@ export default class PhycicsSystem {
for
(
i
=
0
;
i
<=
length
-
1
;
i
++
)
{
for
(
j
=
i
+
1
;
j
<=
length
-
1
;
j
++
)
{
if
(
CollisionMap
[
i
]
&
1
<<
j
)
{
if
(
this
.
enabled
==
false
)
return
;
group1
=
this
.
colliderList
[
i
];
group2
=
this
.
colliderList
[
j
];
for
(
m
=
0
;
m
<=
group1
.
length
-
1
;
m
++
)
{
for
(
n
=
0
;
n
<=
group2
.
length
-
1
;
n
++
)
{
// if (this.enabled == false) return;
this
.
detectTraverse
(
group1
[
m
],
group2
[
n
]);
}
}
...
...
src/custom/shoot-planet/Phycics/Physics.ts
View file @
9b7b3989
...
...
@@ -2,6 +2,7 @@ import GameComponent from "../Game/GameComponent";
import
GameObject
from
"../Game/GameObject"
;
import
PhycicsSystem
from
"./PhycicsSystem"
;
import
Collider
from
"./Collider"
;
import
{
DataMgr
}
from
"../Mgr/DataMgr"
;
export
default
class
Physics
extends
GameComponent
{
/**旋转速度
...
...
@@ -61,10 +62,10 @@ export default class Physics extends GameComponent {
public
onMoved
:
(
owner
:
GameObject
)
=>
void
;
protected
onDisabled
()
{
PhycicsSystem
.
instance
.
remove
(
this
);
DataMgr
.
game
.
_phycicsSystem
.
remove
(
this
);
}
protected
onEnabled
()
{
PhycicsSystem
.
instance
.
add
(
this
);
DataMgr
.
game
.
_phycicsSystem
.
add
(
this
);
}
public
onColliderResize
(
collider
:
Collider
)
{
...
...
src/custom/shoot-planet/Pools/AnimationPool.ts
0 → 100644
View file @
9b7b3989
import
FrameAnimation
from
"../Component/FrameAnimation"
;
import
{
Pool
,
PoolGroup
,
PoolElement
}
from
"../Component/Pool"
;
export
class
PoolFrameAnimation
extends
FrameAnimation
implements
PoolElement
{
onElementInit
()
{
this
.
visible
=
true
;
this
.
curPos
=
0
;
}
onElementRecycle
()
{
this
.
visible
=
false
;
}
}
class
AnimationPool
extends
Pool
<
PoolFrameAnimation
>
{
public
spwan
(
key
:
string
):
PoolFrameAnimation
{
if
(
this
.
data
.
length
>
0
)
{
const
element
=
this
.
data
.
shift
();
element
.
onElementInit
();
return
element
;
}
else
{
let
anim
=
new
PoolFrameAnimation
(
key
);
this
.
layer
.
addChild
(
anim
);
return
anim
;
}
}
}
export
default
class
AnimationPoolGroup
extends
PoolGroup
<
PoolFrameAnimation
>
{
public
spwan
(
key
:
string
)
{
if
(
!
this
.
data
[
key
])
{
this
.
data
[
key
]
=
new
AnimationPool
(
this
.
layer
);
}
const
element
=
this
.
data
[
key
].
spwan
(
key
);
return
element
;
}
}
\ No newline at end of file
src/custom/shoot-planet/Pools/BallPool.ts
View file @
9b7b3989
...
...
@@ -10,6 +10,7 @@ class BallPool extends Pool<Ball>{
element
.
onElementInit
();
}
else
{
element
=
new
Ball
(
sizeIndex
);
this
.
layer
.
addChild
(
element
);
}
DataMgr
.
game
.
_ballList
.
push
(
element
);
return
element
;
...
...
@@ -21,16 +22,16 @@ class BallPool extends Pool<Ball>{
}
};
class
BallPoolGroup
extends
PoolGroup
<
Ball
>
{
export
class
BallPoolGroup
extends
PoolGroup
<
Ball
>
{
public
spwan
(
sizeIndex
:
number
)
{
const
key
=
sizeIndex
.
toString
();
if
(
!
this
.
data
[
key
])
{
this
.
data
[
key
]
=
new
BallPool
()
const
ball
=
this
.
data
[
key
]
=
new
BallPool
(
this
.
layer
)
}
let
element
=
this
.
data
[
key
].
spwan
(
sizeIndex
);
element
.
poolKey
=
key
;
return
element
;
}
}
\ No newline at end of file
let
ballPool
:
BallPoolGroup
=
new
BallPoolGroup
();
export
default
ballPool
;
\ No newline at end of file
src/custom/shoot-planet/Pools/BoomEffectPool.ts
View file @
9b7b3989
import
{
Pool
,
PoolElement
,
PoolGroup
}
from
"../Component/Pool"
;
import
{
BoomEffectSprite
}
from
"../Game/BoomEffect"
;
/* import BoomEffect from "../BoomEffect";
import { Pool, PoolGroup } from "../Pool";
class BoomEffectPool extends Pool<BoomEffect> {
public spwan(color: number, size: number): BoomEffect {
if (this.data.length > 0) {
const element = this.data.shift();
element.onElementInit();
return element;
} else {
return new BoomEffect(color, size);
}
}
}
class BoomEffectPoolGroup extends PoolGroup<BoomEffect> {
public spwan(color: number, size: number) {
const key = color.toString() + size.toString();
if (!this.data[key]) {
this.data[key] = new BoomEffectPool()
}
const element = this.data[key].spwan(color, size);
element.poolKey = key;
return element;
}
}
let boomEffectPool = new BoomEffectPoolGroup();
export default boomEffectPool;
*/
src/custom/shoot-planet/Pools/BulletPool.ts
View file @
9b7b3989
import
Bullet
from
"../Game/Bullet"
;
import
{
Pool
}
from
"../Component/Pool"
;
class
BulletPool
extends
Pool
<
Bullet
>
{
export
class
BulletPool
extends
Pool
<
Bullet
>
{
public
spwan
()
{
if
(
this
.
data
.
length
>
0
)
{
const
element
=
this
.
data
.
shift
();
element
.
onElementInit
();
return
element
;
}
else
{
return
new
Bullet
();
const
b
=
new
Bullet
();
this
.
layer
.
addChild
(
b
);
return
b
;
}
}
}
\ No newline at end of file
let
bulletPool
:
BulletPool
=
new
BulletPool
();
export
default
bulletPool
;
\ No newline at end of file
src/custom/shoot-planet/Pools/DropPool.ts
View file @
9b7b3989
...
...
@@ -8,19 +8,18 @@ class DropPool extends Pool<Drop> {
element
.
onElementInit
();
return
element
;
}
else
{
return
new
Drop
(
id
);
const
d
=
new
Drop
(
id
);
this
.
layer
.
addChild
(
d
);
return
d
;
}
}
}
class
DropPoolGroup
extends
PoolGroup
<
Drop
>
{
export
default
class
DropPoolGroup
extends
PoolGroup
<
Drop
>
{
public
spwan
(
id
:
string
)
{
if
(
!
this
.
data
[
id
])
{
this
.
data
[
id
]
=
new
DropPool
(
)
this
.
data
[
id
]
=
new
DropPool
(
this
.
layer
);
}
return
this
.
data
[
id
].
spwan
(
id
);
}
}
\ No newline at end of file
let
dropPool
:
DropPoolGroup
=
new
DropPoolGroup
();
export
default
dropPool
;
\ No newline at end of file
src/custom/shoot-planet/ShootPlanet.ts
View file @
9b7b3989
import
Game
from
"./Game/Game"
;
import
PhycicsSystem
from
"./Phycics/PhycicsSystem"
;
import
MTimer
from
"./Global/MTimer"
;
import
{
MTween
}
from
"./Component/MTween"
;
import
DropBlinkMgr
from
"./Mgr/DropBlinkMgr"
;
import
Ball
from
"./Game/Ball"
;
import
MEvent
from
"./Component/MEvent"
;
import
{
DataMgr
}
from
"./Mgr/DataMgr"
;
import
DebugMgr
from
"./Mgr/DebugMgr"
;
import
FrameAnimation
from
"./Component/FrameAnimation"
;
import
Drop
from
"./Game/Drop"
;
import
{
SpBoomEffectMgr
}
from
"./Game/SpBoomEffect"
;
import
GuideMask
from
"./Game/GuideMask"
;
import
GuideMgr
from
"./Mgr/GuideMgr"
;
import
{
MConst
}
from
"./Global/MConst"
;
import
{
NetUtils
}
from
"./Global/NetUtils"
;
import
Net
from
"./Global/Net"
;
import
Loading
from
"./Global/Loading"
;
import
{
initNECaptcha
}
from
"./Component/InitNECaptcha"
;
import
SoundMgr
from
"./Mgr/SoundMgr"
;
/**
* Created by rockyl on 2019-11-22.
*/
export
class
ShootPlanet
extends
engine
.
Container
{
p
ublic
game
:
Game
=
null
;
p
rivate
game
:
Game
=
null
;
private
isSubmited
=
false
;
private
constantSubmitSeq
=
1
;
private
needSubmitCount
=
0
;
//实际分数减去ConstantSubmitScoreNum的次数
private
isSubmiting
=
false
;
public
startId
:
number
=
null
;
public
startId
:
number
=
0
;
private
_localScore
:
number
=
0
;
public
get
localScore
():
number
{
...
...
@@ -48,42 +39,36 @@ export class ShootPlanet extends engine.Container {
}
}
constructor
()
{
super
();
public
onSleep
()
{
this
.
game
.
destroy
();
this
.
game
=
null
;
}
this
.
customProperty
();
public
onActive
()
{
this
.
game
=
new
Game
(
this
);
//监听游戏分数变化
this
.
game
.
onScoreChange
=
(
delta
:
number
)
=>
{
this
.
localScore
+=
delta
;
}
this
.
width
=
750
;
this
.
height
=
1624
;
this
.
addEventListener
(
engine
.
Event
.
REMOVED_FROM_STAGE
,
this
.
onDestroy
,
this
);
this
.
init
();
};
if
(
GuideMgr
.
instance
.
guideFlag
==
true
)
{
const
car
=
this
.
game
.
_car
;
GuideMgr
.
instance
.
runGuide
(
0
,
car
.
x
+
car
.
width
/
2
,
car
.
y
+
car
.
height
/
2
/* - 130 */
);
}
}
constructor
()
{
super
();
this
.
customProperty
();
this
.
width
=
750
;
this
.
height
=
1624
;
this
.
init
();
}
private
init
()
{
engine
.
env
.
soundEnabled
=
true
;
PhycicsSystem
.
init
();
MTimer
.
init
();
MTween
.
init
();
DropBlinkMgr
.
init
();
DataMgr
.
game
=
this
.
game
;
DebugMgr
.
instance
.
init
(
this
);
MTimer
.
onFrame
(
"FrameAnimation"
,
FrameAnimation
.
onUpdate
,
FrameAnimation
);
MTimer
.
onFrame
(
"SpBoomEffectMgr"
,
SpBoomEffectMgr
.
onUpdate
,
SpBoomEffectMgr
);
}
private
onDestroy
()
{
MTimer
.
destroy
();
}
private
customProperty
()
{
...
...
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