Repository navigation
Expand file tree
/
Copy pathRobot.cs
More file actions
164 lines (138 loc) · 3.85 KB
/
Copy pathRobot.cs
File metadata and controls
164 lines (138 loc) · 3.85 KB
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
using System;
using SplashKitSDK;
public abstract class Robot
{
//velocity property in vector
private Vector2D Velocity { get; set; }
public double X { get; set; }
public double Y { get; set; }
public Color MainColor { get; set; }
public int Width
{
get { return 50; }
}
public int Height
{
get { return 50; }
}
public Circle CollisionCircle
{
get { return SplashKit.CircleAt(X, Y, 20); }
}
public Robot(Window gameWindow, Player player)
{
if (SplashKit.Rnd() < 0.5)
{
//We picked...Top/Bottom
//Start by picking the random position left to right (X)
X = SplashKit.Rnd(gameWindow.Width);
//Now work out if we are top or bottom?
if (SplashKit.Rnd() < 0.5)
{
Y = -Height; //Top...so above top
}
else
{
Y = gameWindow.Height; //Bottom so below bottom
}
}
else
{
//We picked..Left // Right
Y = SplashKit.Rnd(gameWindow.Height);
if (SplashKit.Rnd() < 0.5)
{
X = -Width;
}
else
{
X = gameWindow.Width;
}
}
//adding velocity to robot
const int SPEED = 4;
//Get a point from Robot
Point2D fromPt = new Point2D()
{
X = X,
Y = Y
};
//Get a point from 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 the velocity
Velocity = SplashKit.VectorMultiply(dir, SPEED);
MainColor = Color.RandomRGB(200);
}
public void Update()
{
X = X + Velocity.X;
Y = Y + Velocity.Y;
}
abstract public void Draw();
//To check whether a robot is off screen
public bool IsOffscreen(Window screen)
{
return (X < -Width || X > screen.Width || Y < -Height || Y > screen.Height);
}
}
class Boxy : Robot
{
public Boxy(Window gameWindow, Player player) : base(gameWindow, player)
{
}
override public void Draw()
{
double leftX, rightX, eyeY, mouthY;
leftX = X + 12;
rightX = X + 27;
eyeY = Y + 10;
mouthY = Y + 30;
SplashKit.FillRectangle(Color.Gray, X, Y, 50, 50);
SplashKit.FillRectangle(MainColor, leftX, eyeY, 10, 10);
SplashKit.FillRectangle(MainColor, rightX, eyeY, 10, 10);
SplashKit.FillRectangle(MainColor, leftX, mouthY, 25, 10);
SplashKit.FillRectangle(MainColor, leftX + 2, mouthY + 2, 21, 6);
}
}
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);
}
}
class Octopus : Robot
{
public Octopus(Window gameWindow, Player player) : base(gameWindow, player)
{
}
public override void Draw()
{
Bitmap RoboBitmap;
RoboBitmap = new Bitmap("robo", "robo.png");
SplashKit.DrawBitmap(RoboBitmap, X, Y);
}
}