aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/WorldScene.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/WorldScene.java')
-rw-r--r--src/main/java/WorldScene.java84
1 files changed, 53 insertions, 31 deletions
diff --git a/src/main/java/WorldScene.java b/src/main/java/WorldScene.java
index 2c11cba..99ac291 100644
--- a/src/main/java/WorldScene.java
+++ b/src/main/java/WorldScene.java
@@ -1,3 +1,5 @@
+import java.awt.AlphaComposite;
+import java.awt.Composite;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
@@ -6,6 +8,7 @@ import java.awt.Graphics2D;
import java.util.ArrayList;
+
public class WorldScene extends Scene {
private ArrayList<Actor> actors = new ArrayList<Actor>();
@@ -17,45 +20,64 @@ public class WorldScene extends Scene {
this.tileSize = tileSize;
map = new Map(gridSize);
- Player player = new Player("pipo", gridSize);
- this.actors.add(player);
+
+ // TODO remove hardcoded stuff
+ Player player = new Player("pipo", gridSize);
+ this.actors.add(player);
}
@Override
public void render(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
+ // draw tiles
for (Tile tile : this.map.grid) {
- switch (tile.type) {
- case GRASS:
- g2d.setColor(Palette.GREEN);
- break;
- case WATER:
- g2d.setColor(Palette.BLUE);
- break;
- }
- g2d.fillRect(
- this.tileSize * tile.x,
- this.tileSize * tile.y,
- this.tileSize, this.tileSize
- );
+ switch (tile.type) {
+ case GRASS:
+ g2d.setColor(Palette.GREEN);
+ break;
+ case WATER:
+ g2d.setColor(Palette.BLUE);
+ break;
+ }
+
+ g2d.fillRect(
+ this.tileSize * tile.x,
+ this.tileSize * tile.y,
+ this.tileSize, this.tileSize
+ );
+
+ // draw grid
+ // composite (enable alpha)
+ Composite originalComposite = g2d.getComposite();
+ g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f));
+
+ g2d.setPaint(Color.BLACK);
+ g2d.drawRect(
+ this.tileSize * tile.x,
+ this.tileSize * tile.y,
+ this.tileSize, this.tileSize
+ );
+
+ g2d.setComposite(originalComposite);
}
- for (Actor actor : this.actors) {
- switch (actor.type) {
- case PLAYER:
- g2d.setColor(Palette.ORANGE);
- break;
- case ENEMY:
- g2d.setColor(Palette.RED);
- break;
- }
- int gap = this.tileSize/10;
- g2d.fillRect(
- (this.tileSize * actor.x) + gap,
- (this.tileSize * actor.y) + gap,
- this.tileSize-gap, this.tileSize-gap
- );
- }
+ // draw actors
+ for (Actor actor : this.actors) {
+ switch (actor.type) {
+ case PLAYER:
+ g2d.setColor(Palette.ORANGE);
+ break;
+ case ENEMY:
+ g2d.setColor(Palette.RED);
+ break;
+ }
+ int gap = this.tileSize/10;
+ g2d.fillRect(
+ (this.tileSize * actor.x) + gap,
+ (this.tileSize * actor.y) + gap,
+ this.tileSize - gap*2, this.tileSize - gap*2
+ );
+ }
}
}