forked from mp1011/KidChameleonRemake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrizeBlock.cs
86 lines (71 loc) · 2.33 KB
/
PrizeBlock.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Collision;
using Engine;
namespace KidC
{
class PrizeBlock : KCCollidingTile, IBreakableTile
{
private SimpleGraphic mGraphic;
private int mMotion = 2;
private int mRange = 4;
public PrizeBlock(KCTileInstance tile, TileCollisionView collisionView)
: base(tile, collisionView)
{
mGraphic = KidCGraphic.RockBlock.CreateSimpleGraphic(this.Context);
}
protected override SoundResource HitSound
{
get { return Sounds.BlockHit;}
}
protected override SpecialTile? FinalTile
{
get
{
return SpecialTile.Rock;
}
}
protected override bool ShouldInteract(CollisionEvent collision, CollisionResponse response)
{
return this.ShouldBreak;
}
protected override void Update()
{
var initialY = Tile.TileArea.Center.Y;
this.Location = this.Location.Offset(0, mMotion);
if (this.Location.Y > initialY + mRange)
mMotion = -1 * Math.Abs(mMotion);
else if (this.Location.Y < initialY - mRange)
mMotion = Math.Abs(mMotion);
if (this.Age > 30)
{
this.Kill(Engine.ExitCode.Removed);
var puff = KCObjectType.Puff.CreateSpriteInstance(this.TileLayer, this.Context).Sprite;
puff.Location = this.Location.Offset(0, -12);
new CreateObjectWhenDestroyed(puff, this.Prize, RGPointI.Empty);
}
}
private ObjectType Prize
{
get
{
if (this.TileInstance.Prize == PrizeType.None)
return ObjectType.None;
else
return new ObjectType((int)this.TileInstance.Prize, this.TileInstance.Prize.ToString());
}
}
public bool ShouldBreak { get; private set; }
public void Break(CollisionEvent evt)
{
this.ShouldBreak = true;
}
protected override void Draw(Engine.Graphics.Painter p, RGRectangleI canvas)
{
mGraphic.Position = this.Location;
mGraphic.Draw(p, canvas);
}
}
}