-
Notifications
You must be signed in to change notification settings - Fork 0
Creating blocks
Agzam4 edited this page Nov 11, 2021
·
2 revisions
All classes must inherit extends the game.Block.java
public class MyBlock extends Block {
public Wires() {
super(...);
}
}
You can also inherit your class from other Block-classes (see blocks Types
)
Use: Transparent - can the block transmit light:
@Override
public boolean isTransparent() {
return isTransparent;
}
Draw - block drawing:
@Override
public void draw(Graphics2D g, Game game, int x, int y) {
super.draw(g, game, x, y); // Default draw
}
Update - block updating:
@Override
public void update(Game game, int x, int y) {
super.update(game,x,y); // <- this is line is important. It is better not to delete it
...
}
mechanism.Mechanism.java
public class MyBlock extends Block {
public Wires() {
super(...);
}
}
Has 4 constructors:
Block(Color color, boolean isVoid)
Block(Color color, boolean isVoid, boolean isFixed)
Block(Color color, Color light, boolean isVoid)
Block(Color color, Color light, boolean isVoid, boolean isFixed)
color
- Block color
light
- Block light color
isVoid
- It is better to set false
:D
isFixed
- Can the block fall (false
- falling, true
- fixed)
mechanism.Mechanism.java
public class MyMechanism extends Mechanism {
...
}
Blocks inherited from Mechanism:
- Will have a white border (1px)
- Method
isMechanism()
will returntrue
- will be updated first (See
game.Game.update()
)
public class MyMechanism extends Mechanism {
...
}
wires.Wires.java
public class MyMechanism extends Wires {
...
}
Has 2 constructors:
-
Wires()
-color = Color.WHITE
light = Color.BLACK
Wires(Color color, Color light)
Blocks inherited from Wires:
- Method
isTransparent()
will returntrue
- Method
isWiretype()
will returntrue
To user can use your block, add it to enum game.Game.Blocks
:
public enum Blocks {
<other enum-fields>
MY_BLOCK (new MyBlock()), // <--- add here
<enum-field>;
<methods>
}
enum Blocks constructor:
Blocks(Block block)