/
EnemyTurtle.cs
155 lines (132 loc) · 4.56 KB
/
EnemyTurtle.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using Sce.PlayStation.Core;
using Sce.PlayStation.HighLevel.GameEngine2D;
using System;
namespace kabuto
{
public class EnemyBase : GameEntity {
}
public class EnemyTurtle : EnemyBase
{
public Sce.PlayStation.HighLevel.GameEngine2D.SpriteTile Sprite { get; set; }
public Vector2 Velocity = Vector2.Zero;
public Vector2 MaximumVelocity = Vector2.Zero;
public Vector2 MinimumVelocity = Vector2.Zero;
Vector2 Direction = Vector2.One;
int GroundPingPongCount { get; set; }
int WallPingPongCount { get; set; }
public EnemyTurtle()
{
// Logger.Debug("EnemyTurtle Construct begin");
Sprite = Support.TiledSpriteFromFile("/Application/assets/koumori.png", 3, 4);
// Sprite = Support.TiledSpriteFromFile("/Application/assets/bat_frames.png", 2, 2);
AddChild(Sprite);
const float SingleFrame = 1.0f / 60.0f;
AddAnimation("Fly", new Support.AnimationAction(Sprite, 9, 11, SingleFrame * 30, looping: true));
SetAnimation(Sprite, "Fly");
CollisionDatas.Add(new EntityCollider.CollisionEntry() {
type = EntityCollider.CollisionEntityType.Enemy,
owner = this,
collider = Sprite,
center = () => GetCollisionCenter(Sprite) + new Vector2( 0, 10 ),
radius = () => 20.0f,
});
this.Scale *= 2;
MaximumVelocity = new Vector2( 300, 300 );
MinimumVelocity = new Vector2( 30, 30 );
// Logger.Debug("EnemyTurtle Construct end");
}
public override void Tick(float dt)
{
Sprite.Visible = false;
Game.Instance.SpriteBatch.Register(
SpriteBatchType.Bat,
this.Position,
Sprite.TileIndex2D,
Sprite.FlipU,
Vector2.One * 2
);
base.Tick(dt);
if (InvincibleTime > 0.0f)
return;
//add gravity
Velocity += Vector2.UnitY * -200.0f * dt;
//reduce velocity
// Velocity *= 0.99f;
//clamp velocity
// Velocity = Vector2.Clamp( Velocity, MaximumVelocity * -1, MaximumVelocity );
// if( GroundPingPongCount>0 ) {
// if(Velocity.X>=-MinimumVelocity.X && Velocity.X<=MinimumVelocity.X) {
// Velocity.X = MinimumVelocity.X * (Velocity.X<0 ? -1 : 1);
// }
// if(Velocity.Y>=-MinimumVelocity.Y && Velocity.X<=MinimumVelocity.Y) {
// Velocity.Y = MinimumVelocity.Y * (Velocity.Y<0 ? -1 : 1);
// }
// }
Position += Velocity * dt;
//ping pong
var newPos = Position;
float minY = Game.Instance.FloorHeight;
if( newPos.Y<minY ) {
newPos.Y = minY;
Velocity.Y = Velocity.Y<0 ? -Velocity.Y : Velocity.Y;
GroundPingPongCount ++ ;
//reduce velocity
Velocity *= 0.95f;
}
float leftX = 0;
if( newPos.X<leftX ) {//LeftWall
newPos.X = leftX;
Velocity.X = Velocity.X<0 ? -Velocity.X : Velocity.X;
WallPingPongCount ++ ;
}
float rightX = Game.Instance.ScreenSize.X;
if( newPos.X>rightX ) {
newPos.X = rightX;
Velocity.X = Velocity.X<0 ? Velocity.X : -Velocity.X;
WallPingPongCount ++ ;
}
Position = newPos;
}
public override void CollideFrom(GameEntity owner, Node collider)
{
base.CollideFrom(owner, collider);
var enemyKiller = owner as EnemyKiller;
if (enemyKiller!=null)
{
// Logger.Debug("[PlayerBullet] Collied from PlayerBullet");
CollisionDatas.RemoveAll( (x) => x.owner==this );
Velocity *= 0.0f;
//spawn pieces
{
int nextKillerGen = enemyKiller.Generation + 1;
int pieceCount = GlobalParams.EnemyPieceCount;
for(int i=0; i<pieceCount; i++) {
var pos = Position;
var targetPos = pos + Game.Instance.Random.NextVector2( GlobalParams.EnemyPieceMoveLength );
var enemyPiece = new EnemyPiece(
pos,
targetPos,
GlobalParams.EnemyPieceLifeTime
);
enemyPiece.Generation = nextKillerGen;
Game.Instance.AddQueue.Add(enemyPiece);
}
}
//add score
Game.Instance.ScoreManager.AddScore(2, enemyKiller.Generation);
Game.Instance.EnemySpawner.EnemyDeadCountTotal ++ ;
Game.Instance.RemoveQueue.Add(this);
}
}
public override void Die(Vector2? source, float damage)
{
base.Die(source, damage);
// Vector2 offset = (GetCollisionCenter(Sprite) - (Vector2)source);
// if (offset.LengthSquared() > 0.0f)
// offset = offset.Normalize() * 4.0f;
// Game.Instance.ParticleEffects.AddParticlesTile("EnemyBat", Support.GetTileIndex(Sprite), Sprite.FlipU, GetCollisionCenter(Sprite), offset + Vector2.UnitY * 4.0f, damage * 2.0f);
// Support.SoundSystem.Instance.PlayNoClobber("bat_die.wav");
// DropCoinsWithAChanceOfHeart(GetCollisionCenter(Sprite), 5);
}
}
}