forked from mp1011/KidChameleonRemake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRubberBlock.cs
106 lines (90 loc) · 3.37 KB
/
RubberBlock.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Collision;
using Engine;
namespace KidC
{
class RubberBlock : KCCollidingTile
{
private SimpleAnimation mAnimation;
public bool DoBounce { get; set; }
public RubberBlock(KCTileInstance tile, TileCollisionView collisionView)
: base(tile, collisionView)
{
mAnimation = KidCGraphic.RubberBlockBounce.CreateSimpleAnimation(this.Context);
}
protected override SoundResource HitSound
{
get { return Sounds.RubberBounce; }
}
protected override SpecialTile? FinalTile
{
get
{
return SpecialTile.Rubber;
}
}
protected override bool ShouldInteract(CollisionEvent collision, CollisionResponse response)
{
// response.AddInteraction(new PlayerBounce(collision.Invert()), this);
return DoBounce;
}
protected override void Draw(Engine.Graphics.Painter p, RGRectangleI canvas)
{
mAnimation.Location = this.Location;
mAnimation.Draw(p, canvas);
}
protected override void Update()
{
if (this.Age >= 30)
this.Kill(Engine.ExitCode.Removed);
}
}
class PlayerBounceController : ITypedCollisionResponder<RubberBlock>
{
private PlatformerPlayerController mPlatformCtl;
private TransformationStats Stats { get { return mPlatformCtl.MotionStats; } }
private DirectedMotion mHorizontalBounce;
public PlayerBounceController(Sprite s, PlatformerPlayerController platformCtl)
{
this.RegisterTypedCollider(s);
mPlatformCtl = platformCtl;
}
public void HandleCollision(RubberBlock rubberBlock, CollisionEvent collision, CollisionResponse response)
{
if(mHorizontalBounce == null)
{
mHorizontalBounce = new DirectedMotion("Horizontal Bounce");
mHorizontalBounce.Inactive=true;
mHorizontalBounce.Decel = this.Stats.SideBounceDecel;
mPlatformCtl.Sprite.MotionManager.AddComponent(mHorizontalBounce);
}
if (collision.CollisionSide == Side.Bottom)
{
var ySpeed = collision.CollisionSpeed.Y;
if (ySpeed <= .5)
return;
mPlatformCtl.DoBounce((Math.Min(ySpeed, this.Stats.VerticalBounceStrength)));
rubberBlock.DoBounce = true;
}
else if (collision.CollisionSide == Side.Left)
{
rubberBlock.DoBounce = true;
mHorizontalBounce.Inactive = false;
mHorizontalBounce.Direction = Direction.Right;
mHorizontalBounce.TargetSpeed = 0;
mHorizontalBounce.CurrentSpeed = this.Stats.SideBounceSpeed;
}
else if (collision.CollisionSide == Side.Right)
{
rubberBlock.DoBounce = true;
mHorizontalBounce.Inactive = false;
mHorizontalBounce.Direction = Direction.Left;
mHorizontalBounce.TargetSpeed = 0;
mHorizontalBounce.CurrentSpeed = this.Stats.SideBounceSpeed;
}
}
}
}