forked from mp1011/KidChameleonRemake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMushroomBlock.cs
104 lines (89 loc) · 3.07 KB
/
MushroomBlock.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
using Engine;
using Engine.Collision;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace KidC
{
class MushroomBlock : KCCollidingTile
{
enum MushroomState
{
Solid,
Growing,
Shrinking
}
protected override SpecialTile? FinalTile
{
get
{
if (mState == MushroomState.Shrinking)
return null;
else
return SpecialTile.Mushroom;
}
}
private SimpleAnimation mAnimation;
private MushroomState mState = MushroomState.Solid;
public MushroomBlock(KCTileInstance tile, TileCollisionView collisionView)
: base(tile, collisionView)
{
mAnimation = KidCGraphic.Mushroom.CreateSimpleAnimation(this.Context);
}
protected override SoundResource HitSound
{
get { return Sounds.None; }
}
protected override bool ShouldInteract(CollisionEvent collision, CollisionResponse response)
{
return collision == null || collision.CollisionSide == Side.Bottom;
}
protected override void OnEntrance()
{
if (mState == MushroomState.Solid)
{
var aboveLeft = this.Tile.GetAdjacentTile(-1, -1) as KCTileInstance;
var above = this.Tile.GetAdjacentTile(0, -1) as KCTileInstance;
var aboveRight = this.Tile.GetAdjacentTile(1, -1) as KCTileInstance;
if (!GrowBlockIfEmpty(aboveLeft) & !GrowBlockIfEmpty(above) & !GrowBlockIfEmpty(aboveRight))
{
mAnimation = KidCGraphic.MushroomShrink.CreateSimpleAnimation(this.Context);
mState = MushroomState.Shrinking;
}
}
base.OnEntrance();
}
private bool GrowBlockIfEmpty(KCTileInstance tile)
{
if (tile.TileDef.IsBlank)
{
var cv = new TileCollisionView();
cv.Instance = tile;
cv.Layer = this.CollisionView.Layer;
cv.CollisionInfo = this.CollisionView.CollisionInfo;
var block = new MushroomBlock(tile, cv);
block.mState = MushroomState.Growing;
block.mAnimation = KidCGraphic.MushroomGrow.CreateSimpleAnimation(this.Context);
this.TileLayer.AddObject(block);
return true;
}
else
return false;
}
protected override void Update()
{
if (mState == MushroomState.Solid)
this.Kill(ExitCode.Finished);
else if (this.Age > 30)
this.Kill(Engine.ExitCode.Finished);
}
protected override void Draw(Engine.Graphics.Painter p, RGRectangleI canvas)
{
if (mAnimation == null)
return;
mAnimation.Location = this.Location;
mAnimation.Draw(p, canvas);
}
}
}