-
Notifications
You must be signed in to change notification settings - Fork 0
/
GamePoint.cs
111 lines (104 loc) · 3.99 KB
/
GamePoint.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
using System;
using Android.Graphics;
using Android.Views.Animations;
namespace Segmentus
{
class GamePoint : DrawablePart
{
const int TouchRadius = 50;
const int OutRadius = 30;
const int InRadius = 20;
const int CoreRadius = 15;
const float GrowthFactor = 1.3f;
const int GrowthTime = 500;
const int BirthDuration = 700;
const int MaxBirthDelay = 800;
public enum PointState {Normal, Selected, Highlighted,
UsedByPlayer, UsedByCompetitor};
static Random random = new Random();
static Paint paint = new Paint(PaintFlags.AntiAlias);
public Rect bounds;
float birthScaleFactor = 0;
float BirthScaleFactor
{
get { return birthScaleFactor; }
set
{
birthScaleFactor = value;
OnAppearanceChanged();
}
}
float scaleFactor = 1;
float scaleTime = 0;
float ScaleTime
{
get { return scaleTime; }
set
{
scaleTime = value;
scaleFactor = 1 + (GrowthFactor - 1) * scaleTime / GrowthTime;
OnAppearanceChanged();
}
}
HandyAnimator anim;
PointState state = PointState.Normal;
public PointState State
{
get { return state; }
set
{
state = value;
if (anim != null)
anim.core.Cancel();
switch (state)
{
case PointState.Selected:
anim = HandyAnimator.OfFloat(ScaleTime, GrowthTime,
(int)(GrowthTime - ScaleTime));
SoundMaster.PlaySound(SoundMaster.PointChosenSound);
break;
case PointState.Highlighted:
anim = HandyAnimator.OfFloat(0, GrowthTime, GrowthTime);
anim.core.RepeatCount = -1;
anim.core.RepeatMode = Android.Animation.ValueAnimatorRepeatMode.Reverse;
anim.core.StartDelay = random.Next(GrowthTime);
break;
default:
anim = HandyAnimator.OfFloat(ScaleTime, 0, (int)ScaleTime);
break;
}
anim.Update += (val) => ScaleTime = (float)val;
anim.core.Start();
}
}
public GamePoint(Pivot parentPivot, int x, int y)
: base(parentPivot, x, y)
{
int r = (int)(TouchRadius * GameView.scaleFactor);
bounds = new Rect(-r + x, -r + y, r + x, r + y);
}
public void AnimateAppearance()
{
HandyAnimator apAnim = HandyAnimator.OfFloat(0, 1, BirthDuration);
apAnim.core.SetInterpolator(new OvershootInterpolator(2));
apAnim.core.StartDelay = (int)(random.NextDouble() * MaxBirthDelay);
apAnim.Update += (value) => BirthScaleFactor = (float)value;
apAnim.core.AnimationStart += (sender, e)
=> SoundMaster.PlaySound(SoundMaster.PointBornSound);
apAnim.core.Start();
}
protected override void Draw(Canvas canvas)
{
float factor = GameView.scaleFactor * scaleFactor * BirthScaleFactor;
paint.Color = ColorBank.GetColor(ColorBank.Red);
canvas.DrawCircle(0, 0, OutRadius * factor, paint);
paint.Color = ColorBank.GetColor(ColorBank.Background);
canvas.DrawCircle(0, 0, InRadius * factor, paint);
if (State == PointState.Selected || State == PointState.UsedByPlayer)
paint.Color = ColorBank.GetColor(ColorBank.Yellow);
if (State == PointState.UsedByCompetitor)
paint.Color = ColorBank.GetColor(ColorBank.Blue);
canvas.DrawCircle(0, 0, CoreRadius * factor, paint);
}
}
}