-
Notifications
You must be signed in to change notification settings - Fork 0
/
Monster.cs
117 lines (105 loc) · 3.08 KB
/
Monster.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
using System;
using SplashKitSDK;
public class Monster : GamePiece
{
private const int Speed = 3;
private const int TimeTillNewDirectionMin = 150;
private const int TimeTillNewDirectionMax = 250;
public double x {get; set;}
public double y {get; set;}
private int timeTillNewDirection;
public Bitmap bitmap {get; set;}
private Vector2D velocity;
private Window gameWindow;
public Monster(Window gamewindow)
{
int monsterGenerator = SplashKit.Rnd(0, 10);
if (monsterGenerator >= 3)
{
bitmap = new Bitmap("Monster", "Monster.png");
}
else
{
bitmap = new Bitmap("Monster2", "Monster2.png");
}
x = SplashKit.Rnd(0, gamewindow.Width - bitmap.Width);
y = SplashKit.Rnd(0, gamewindow.Height - bitmap.Height);
this.gameWindow = gamewindow;
SetNewDirection();
}
public void SetNewDirection()
{
velocity.X = SplashKit.Rnd(-Speed, Speed);
velocity.Y = SplashKit.Rnd(-Speed, Speed);
timeTillNewDirection = SplashKit.Rnd(TimeTillNewDirectionMin, TimeTillNewDirectionMax);
}
public bool CollidesWith(GamePiece gamePiece)
{
return SplashKit.BitmapCollision(this.bitmap, x, y, gamePiece.bitmap, gamePiece.x, gamePiece.y);
}
public void BounceOff()
{
velocity.X = -velocity.X;
velocity.Y = -velocity.Y;
}
public void Update()
{
x += velocity.X;
y += velocity.Y;
timeTillNewDirection -= 1;
if (timeTillNewDirection == 0)
{
SetNewDirection();
}
if (x < 0 || x > gameWindow.Width - bitmap.Width)
{
velocity.X = -velocity.X;
}
if (y < 0 || y > gameWindow.Height - bitmap.Height)
{
velocity.Y = -velocity.Y;
}
}
public void Draw()
{
bitmap.Draw(x, y);
}
// public void StayOnWindow(Window gamewindow)
// {
// if (X < 0)
// {
// X = 0;
// }
// if (X > gamewindow.Width - Width)
// {
// X = gamewindow.Width - Width;
// }
// if (Y < 0)
// {
// Y = 0;
// }
// if (Y > gamewindow.Height - Height)
// {
// Y = gamewindow.Height - Height;
// }
// }
// private void SetNewDestination()
// {
// int destinationX = SplashKit.Rnd(0, (gameWindow.Width - alienBitmap.Width));
// int destinationY = SplashKit.Rnd(0, (gameWindow.Height - alienBitmap.Height));
// destinationCircle = SplashKit.CircleAt(destinationX, destinationY, DestinationRadius);
// Point2D fromPT = new Point2D()
// {
// X = this.x,
// Y = this.y
// };
// Point2D toPT = new Point2D()
// {
// X = destinationX,
// Y = destinationY
// };
// Vector2D dir;
// dir = SplashKit.UnitVector(SplashKit.VectorPointToPoint(fromPT, toPT));
// velocity = SplashKit.VectorMultiply(dir, Speed);
// }
}