-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util.pde
112 lines (103 loc) · 4.13 KB
/
Util.pde
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
/**********************************************************************************
* Class: Util
*
* Authors: Adam Austin
*
* Function: Utility class for common tools and variables used throughout the program
*
* Imports: None
*
* Methods: numberToCoord() - Converts a tile address to a coordinate value
* coordToNumber() - Converts a coordinate value to a tile address
*
**********************************************************************************/
static class Util {
// Utility class for common tools
static int tileSize = 30; // Tiles size for walls
static boolean onMenu = true; // Wether or not the menu is active or not
static String IP = ""; //The IP address for server address
static boolean networkSetup = false; // Wether or not the network has been setup for multiplayer
static boolean setup = true; // Wether the setup has completesd in the draw loop
static String hostname = ""; //The hostname for server address
/**********************************************************************************
* Method: numberToCoord()
*
* Author(s): Adam Austin
*
* Function: Converts a tile address to a coordinate value
*
* Parameters: num - The address of the tile in question
* tilesAcross - How many tiles fit across the screen
* tileSize - How big each tile is in pixels
*
* Return values: PVector - The coordinate value of the tile
*
**********************************************************************************/
static PVector numberToCoord(int num, float tilesAcross, float tileSize) {
float tileX = (num % tilesAcross ) * tileSize;
float tileY;
if (num >= tilesAcross) {
tileY = floor(num / tilesAcross) * tileSize;
} else {
tileY = 0;
}
return new PVector(tileX, tileY);
}
/**********************************************************************************
* Method: numberToCoord()
*
* Author(s): Adam Austin
*
* Function: Converts a tile address to a coordinate value
*
* Parameters: num - The coods of the tile in question
*
* Return values: PVector - The coordinate value of the tile
*
**********************************************************************************/
static PVector numberToCoord(int num) {
float tile_Size = 30;
float tiles_Across = 1050/tile_Size;
return numberToCoord(num, tiles_Across, tile_Size);
}
/**********************************************************************************
* Method: coordToNumber()
*
* Author(s): Adam Austin
*
* Function: Converts a tile address to a coordinate value
*
* Parameters: position - The coods of the tile in question
* tilesAcross - How many tiles fit across the screen
* tileSize - How big each tile is in pixels
*
* Return values: Int - address of the tile represented by the coordinates
*
**********************************************************************************/
static int coordToNumber(PVector position, float tilesAcross, float tileSize) {
int x = floor(position.x);
int y = floor(position.y);
int numX = floor(x / tileSize);
int numY = floor(y / tileSize);
return numX + floor( numY * tilesAcross);
}
/**********************************************************************************
* Method: coordToNumber()
*
* Author(s): Adam Austin
*
* Function: Converts a tile address to a coordinate value
*
* Parameters: position - The coods of the tile in question
*
* Return values: Int - address of the tile represented by the coordinates
*
* Notes: Overloaded method, passes the values to the first coordToNumber method
*
**********************************************************************************/
static int coordToNumber(PVector position) {
float tile_Size = 30;
float tiles_Across = 1050/tile_Size;
return coordToNumber(position, tiles_Across, tile_Size);
}
}