-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFigure.java
More file actions
135 lines (112 loc) · 4.35 KB
/
Copy pathFigure.java
File metadata and controls
135 lines (112 loc) · 4.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
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
135
package coloris;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javafx.scene.input.KeyCode;
public class Figure implements Sprite
{
public static final List<KeyCode> MOVES_LEFT = Arrays.asList(new KeyCode[] {KeyCode.A, KeyCode.LEFT, KeyCode.KP_LEFT});
public static final List<KeyCode> MOVES_RIGHT = Arrays.asList(new KeyCode[] {KeyCode.D, KeyCode.RIGHT, KeyCode.KP_RIGHT});
public static final List<KeyCode> INCREMENTS_VELOCITY = Arrays.asList(new KeyCode[] {KeyCode.S, KeyCode.DOWN, KeyCode.KP_DOWN});
public static final List<KeyCode> DECREMENTS_VELOCITY = Arrays.asList(new KeyCode[] {KeyCode.W, KeyCode.UP, KeyCode.KP_UP});
public static final List<KeyCode> SLIDES_UP = Arrays.asList(new KeyCode[] {KeyCode.SPACE, KeyCode.ENTER});
private static final int NO_TILES = 3;
private static final int INITIAL_COLUMN = 3;
private static final int NO_COLUMNS = 7;
private final double width;
private final double height;
private int column;
private boolean awake;
private double velocity;
private double minVelocity;
private double maxVelocity;
private double velocityIncrement;
private final ArrayList<Tile> tiles;
public Figure(double dimension, double minVelocity, double maxVelocity, double velocityIncrement) //namesti u konstruktoru adekvatne y koordinate za tile-ove
{
width = dimension;
height = dimension * NO_TILES;
column = INITIAL_COLUMN;
awake = true;
velocity = minVelocity;
this.minVelocity = minVelocity;
this.maxVelocity = maxVelocity;
this.velocityIncrement = velocityIncrement;
tiles = new ArrayList<>();
for(int i = 0; i < NO_TILES; i++)
{
Tile tile = new Tile(dimension);
tile.setTranslateY(i * width);
tiles.add(tile);
}
}
public void slideUp()
{
double temp = tiles.get(0).getTranslateY();
double temp1 = tiles.get(1).getTranslateY();
tiles.get(1).setTranslateY(temp);
tiles.get(0).setTranslateY(tiles.get(2).getTranslateY());
tiles.get(2).setTranslateY(temp1);
Tile bottomNext = tiles.get(0);
tiles.remove(0);
tiles.add(bottomNext);
}
public void moveLeft()
{
Board board = (Board)tiles.get(0).getParent();
if(column > 0 && getTranslateY() + getHeight() < board.getFreeSpaceInColumn(column - 1))
{
for(Tile tile : tiles)
tile.setTranslateX(tile.getTranslateX() - getWidth());
column--;
}
}
public void moveRight()
{
Board board = (Board)tiles.get(0).getParent();
if (column < NO_COLUMNS - 1 && getTranslateY() + getHeight() < board.getFreeSpaceInColumn(column + 1))
{
for(Tile tile : tiles)
tile.setTranslateX(tile.getTranslateX() + getWidth());
column++;
}
}
public void incrementVelocity() {if (velocity < maxVelocity) velocity += velocityIncrement;}
public void decrementVelocity() {if (velocity > minVelocity) velocity -= velocityIncrement;}
@Override
public void update()
{
Board board = (Board)tiles.get(0).getParent();
if (getTranslateY() + getHeight() + velocity < board.getFreeSpaceInColumn(column))
{
setTranslateY(getTranslateY() + velocity);
}
else
{
setTranslateY(board.getFreeSpaceInColumn(column) - getHeight());
awake = false;
}
}
public int getColumn() {return column;}
public ArrayList<Tile> getTiles() {return tiles;}
public double getWidth() {return width;}
public double getHeight() {return height;}
public void setTranslateX(double x)
{
for(Tile tile : tiles)
{
tile.setTranslateX(x);
}
}
public double getTranslateX() {return tiles.get(0).getTranslateX();}
public void setTranslateY(double y)
{
for(int i = 0; i < NO_TILES; i++)
{
Tile tile = tiles.get(i);
tile.setTranslateY(y + i * width);
}
}
public double getTranslateY() {return tiles.get(0).getTranslateY();}
public boolean isAwake() {return awake;}
}