-
Notifications
You must be signed in to change notification settings - Fork 0
/
Robot.cs
180 lines (152 loc) · 4.87 KB
/
Robot.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
using System;
using SplashKitSDK;
namespace RobotDodge
{
public abstract class Robot
{
public Color MainColor { get; set; }
public double X { get; set; }
public double Y { get; set; }
public Vector2D Velocity { get; set; }
public int Width
{
get
{
return 50;
}
}
public int Height
{
get
{
return 50;
}
}
public Circle CollisionCircle
{
get
{
double centerX = X + (Width / 2);
double centerY = Y + (Height / 2);
return SplashKit.CircleAt(centerX, centerY, 20);
}
}
public Robot(Window gameWindow, Player player)
{
// Lets test with starting at top left... for now
X = 0;
Y = 0;
if (SplashKit.Rnd() < 0.5)
{
X = SplashKit.Rnd(gameWindow.Width);
if (SplashKit.Rnd() < 0.5)
Y = -Height;
else
Y = gameWindow.Height;
}
else
{
Y = SplashKit.Rnd(gameWindow.Height);
if (SplashKit.Rnd() < 0.5)
X = -Width;
else
X = gameWindow.Width;
}
const int SPEED = 2;//Change the speed for recording purpose
// Get a Point for the Robot
Point2D fromPt = new Point2D()
{
X = X,
Y = Y
};
// Get a Point for the Player
Point2D toPt = new Point2D()
{
X = player.X,
Y = player.Y
};
// Calculate the direction to head.
Vector2D dir;
dir = SplashKit.UnitVector(SplashKit.VectorPointToPoint(fromPt, toPt));
// Set the speed and assign to the Velocity
Velocity = SplashKit.VectorMultiply(dir, SPEED);
MainColor = Color.RandomRGB(200);
}
public abstract void Draw();
public void Update()
{
X += Velocity.X;
Y += Velocity.Y;
}
public bool IsOffscreen(Window screen)
{
return X < -Width || X > screen.Width || Y < -Height || Y > screen.Height;
}
}
public class Boxy : Robot
{
public Boxy(Window gameWindow, Player player) : base(gameWindow, player)
{
}
public override void Draw()
{
double leftX;
double rightX;
double eyeX;
double mouthY;
leftX = X + 12;
rightX = X + 27;
eyeX = Y + 10;
mouthY = Y + 30;
SplashKit.FillRectangle(Color.Gray, X, Y, Width, Height);
SplashKit.FillRectangle(MainColor, leftX, eyeX, 10, 10);
SplashKit.FillRectangle(MainColor, rightX, eyeX, 10, 10);
SplashKit.FillRectangle(MainColor, leftX, mouthY, 25, 10);
SplashKit.FillRectangle(MainColor, leftX + 2, mouthY + 2, 21, 6);
}
}
public class Roundy : Robot
{
public Roundy(Window gameWindow, Player player) : base(gameWindow, player)
{
}
public override void Draw()
{
double leftX, midX, rightX;
double midY, eyeY, mouthY;
leftX = X + 17;
midX = X + 25;
rightX = X + 33;
midY = Y + 25;
eyeY = Y + 20;
mouthY = Y + 35;
SplashKit.FillCircle(Color.White, midX, midY, 25);
SplashKit.DrawCircle(Color.Gray, midX, midY, 25);
SplashKit.FillCircle(MainColor, leftX, eyeY, 5);
SplashKit.FillCircle(MainColor, rightX, eyeY, 5);
SplashKit.FillEllipse(Color.Gray, X, eyeY, 50, 30);
SplashKit.DrawLine(Color.Black, X, mouthY, X + 50, Y + 35);
}
}
public class Swingy : Robot
{
public Swingy(Window gameWindow, Player player) : base(gameWindow, player)
{
}
public override void Draw()
{
double centerX, centerY;
double eyeX, mouthY;
centerX = X + (Width / 2);
centerY = Y + (Height / 2);
eyeX = centerX - 5;
mouthY = centerY + 10;
SplashKit.FillTriangle(Color.Gray, centerX, Y, X, centerY, X + Width, centerY);
SplashKit.FillTriangle(Color.Gray, centerX, Y + Height, X, centerY, X + Width, centerY);
SplashKit.FillCircle(MainColor, eyeX, centerY - 5, 10);
SplashKit.FillCircle(MainColor, eyeX + 10, centerY - 5, 10);
// Draw the mouth as a rectangle (you can modify this)
SplashKit.FillCircle(MainColor, eyeX, mouthY, 5);
}
}
}