This repository was archived by the owner on Jul 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMisc.cs
More file actions
61 lines (54 loc) · 1.35 KB
/
Copy pathMisc.cs
File metadata and controls
61 lines (54 loc) · 1.35 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
using System;
namespace HatlessEngine
{
public static class Misc
{
/// <summary>
/// Whether to show a messagebox when an unhandled exception is thrown.
/// Crashlog will be written regardless of this setting.
/// This is disabled by default when DEBUG is defined, but can be changed at will.
/// </summary>
#if DEBUG
public static bool ExceptionErrorMessageEnabled = false;
#else
public static bool ExceptionErrorMessageEnabled = true;
#endif
/// <summary>
/// Returns whether a random chance is met.
/// Explained: chance in values (e.g. 3 in 100) chance of returning true
/// </summary>
public static bool Chance(int values, int chance = 1)
{
int result = new Random().Next(values);
return result < chance;
}
/// <summary>
/// Returns the angle to or from angle1 to angle2 from -180f to 180f.
/// </summary>
public static float GetRelativeAngle(float angle1, float angle2)
{
float diff = angle2 - angle1;
if (diff > 180f)
diff -= 360;
if (diff < -180f)
diff += 360;
return diff;
}
public static int Modulus(int a, int n)
{
int result = a % n;
if (a < 0 && n > 0
|| a > 0 && n < 0)
result += n;
return result;
}
public static float Modulus(float a, float n)
{
float result = a % n;
if (a < 0 && n > 0
|| a > 0 && n < 0)
result += n;
return result;
}
}
}