-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPainting.java
134 lines (117 loc) · 3.34 KB
/
Painting.java
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
import javafx.scene.image.Image;
/**
* Created by Mushra on 2017-09-11.
*/
public class Painting extends Grid {
int[][][] tilesetPos;
public Painting(int width, int height, Tile wallpaper) {
super(width, height);
tilesetPos = new int[width][height][2];
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
tilesetPos[x][y][0] = - 1;
tilesetPos[x][y][1] = - 1;
setTile(x, y, wallpaper);
}
}
}
@Override
public void setTile(int x, int y, Tile newTile) {
map[x][y] = new Tile(newTile, 3);
}
public int[] getTilesetPos() {
return tilesetPos[sel_x][sel_y];
}
public int[] getSpecificTilesetPos(int x, int y) {
return tilesetPos[x][y];
}
public void setTilesetPos(int x, int y, int a, int b) {
if (x < 34 && x >= 0 && y < 15 && y >= 0) {
tilesetPos[x][y][0] = a;
tilesetPos[x][y][1] = b;
}
}
public void setTilesetPos(int x, int y) {
tilesetPos[sel_x][sel_y][0] = x;
tilesetPos[sel_x][sel_y][1] = y;
}
public void rotateLeft() {
// moving of the tiles
Tile[] temp = map[0];
for (int i = 0; i < map.length - 1; i++) {
map[i] = map[i + 1];
}
map[map.length - 1] = temp;
// moving of the init grid
int[][] temp2 = tilesetPos[0];
for (int i = 0; i < tilesetPos.length - 1; i++) {
tilesetPos[i] = tilesetPos[i + 1];
}
tilesetPos[tilesetPos.length - 1] = temp2;
}
public void rotateRight() {
// moving of the tiles
Tile[] temp = map[map.length - 1];
for (int i = map.length - 1; i > 0; i--) {
map[i] = map[i - 1];
}
map[0] = temp;
// moving of the init grid
int[][] temp2 = tilesetPos[tilesetPos.length - 1];
for (int i = tilesetPos.length - 1; i > 0; i--) {
tilesetPos[i] = tilesetPos[i - 1];
}
tilesetPos[0] = temp2;
}
public void rotateUp() {
// moving of the tiles
Tile[][] newMap = new Tile[map.length][map[0].length];
for (int x = 0; x < map.length; x++) {
for (int y = 0; y < map[0].length; y++) {
newMap[x][(y + map[0].length - 1) % map[0].length] = map[x][y];
}
}
map = newMap;
// moving of the init grid
int[][][] newtilesetPos = new int[tilesetPos.length][tilesetPos[0].length][2];
for (int x = 0; x < tilesetPos.length; x++) {
for (int y = 0; y < tilesetPos[0].length; y++) {
newtilesetPos[x][(y + tilesetPos[0].length - 1) % tilesetPos[0].length] = tilesetPos[x][y];
}
}
tilesetPos = newtilesetPos;
}
public void rotateDown() {
// moving of the tiles
Tile[][] newMap = new Tile[map.length][map[0].length];
for (int x = 0; x < map.length; x++) {
for (int y = - 1; y < map[0].length - 1; y++) {
newMap[x][y + 1] = map[x][(y + map[0].length) % map[0].length];
}
}
map = newMap;
// moving of the init grid
int[][][] newtilesetPos = new int[tilesetPos.length][tilesetPos[0].length][2];
for (int x = 0; x < tilesetPos.length; x++) {
for (int y = - 1; y < tilesetPos[0].length - 1; y++) {
newtilesetPos[x][y + 1] = tilesetPos[x][(y + tilesetPos[0].length) % tilesetPos[0].length];
}
}
tilesetPos = newtilesetPos;
}
public void resetFromTilesetPos(Tileset tileset) {
int a, b;
for (int x = 0; x < 34; x++) {
for (int y = 0; y < 15; y++) {
if (tilesetPos[x][y][0] == - 1 || tilesetPos[x][y][1] == - 1) {
a = 0;
b = 0;
} else {
a = tilesetPos[x][y][0];
b = tilesetPos[x][y][1];
}
setTile(x, y, tileset.getTile(a, b));
}
}
}
}