/
Helpers.cs
73 lines (58 loc) · 1.45 KB
/
Helpers.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
/*
* Miscellaneous helper functions.
*/
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace Flyatron
{
class Helper
{
public static Random RANDOM = new Random();
public Helper()
{
}
public static int Rng(int a)
{
return RANDOM.Next(a);
}
public static int Rng2(int a, int b)
{
return RANDOM.Next(a, b);
}
public static bool SquareCollision(Rectangle a, Rectangle b)
{
// Generic collisions.
if (a.Intersects(b))
return true;
return false;
}
public static bool CircleCollision(Rectangle a, Rectangle b, float multiplier1 = 1F, float multiplier2 = 1F)
{
// Circular generic collisions.
if (Math.Sqrt((b.X - a.X) * (b.X - a.X) + (b.Y - a.Y) * (b.Y - a.Y)) < ((a.Width * multiplier1) / 2 + (b.Width * multiplier2) / 2))
return true;
return false;
}
public static bool LeftClick()
{
// Left mouse click.
if ((Game.MOUSE.LeftButton == ButtonState.Released) && (Game.PREV_MOUSE.LeftButton == ButtonState.Pressed))
return true;
else return false;
}
public static bool RightClick()
{
// Right mouse click.
if ((Game.MOUSE.RightButton == ButtonState.Released) && (Game.PREV_MOUSE.RightButton == ButtonState.Pressed))
return true;
else return false;
}
public static bool Keypress(Keys inputKey)
{
if (Game.KEYBOARD.IsKeyUp(inputKey) && (Game.PREV_KEYBOARD.IsKeyDown(inputKey)))
return true;
return false;
}
}
}