-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.java
More file actions
63 lines (57 loc) · 1.58 KB
/
Block.java
File metadata and controls
63 lines (57 loc) · 1.58 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
package game;
import javafx.geometry.Rectangle2D;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
/**
* cut blocks from sprite list
*
* @author FerrariHD
*
*/
public class Block extends Pane {
ImageView block;
public enum BlockType {
BRICK, WALL, GRASS, WATER, BONUS
}
/**
*
* @param blockType
* @param x = setTranslateX
* @param y = setTranslateY
*/
public Block(BlockType blockType, int x, int y, Image blocksImg) {
block = new ImageView(blocksImg);
block.setFitWidth(Game.BLOCK_SIZE);
block.setFitHeight(Game.BLOCK_SIZE);
setTranslateX(x);
setTranslateY(y);
switch (blockType) {
case WALL:
block.setViewport(
new Rectangle2D(512, 32, Game.BLOCK_SIZE, Game.BLOCK_SIZE));
Game.platforms.add(this);
break;
case BRICK:
block.setViewport(
new Rectangle2D(512, 0, Game.BLOCK_SIZE, Game.BLOCK_SIZE));
Game.platforms.add(this);
break;
case WATER:
block.setViewport(
new Rectangle2D(512, 64, Game.BLOCK_SIZE, Game.BLOCK_SIZE));
break;
case GRASS:
block.setViewport(
new Rectangle2D(545, 64, Game.BLOCK_SIZE, Game.BLOCK_SIZE));
break;
case BONUS:
block.setViewport(
new Rectangle2D(672, 222, Game.BLOCK_SIZE, Game.BLOCK_SIZE));
Game.bonuses.add(this);
break;
}
getChildren().add(block);
Game.gameRoot.getChildren().add(this);
}
}