diff options
author | mafaldo <mafaldo@heavyhammer.home> | 2018-02-11 12:21:15 +0100 |
---|---|---|
committer | mafaldo <mafaldo@heavyhammer.home> | 2018-02-11 12:21:15 +0100 |
commit | a9a5bc0189d316de863bbdc8c3a425706b6ade84 (patch) | |
tree | e92db501cfa040cad315b535cb326abb3f086348 /src/main/java/WorldScene.java | |
parent | tiles bound to actors, remove Player and Enemy (diff) | |
download | Subconscious-old-a9a5bc0189d316de863bbdc8c3a425706b6ade84.tar.gz Subconscious-old-a9a5bc0189d316de863bbdc8c3a425706b6ade84.zip |
add pan, add zoom, add weapon
Diffstat (limited to 'src/main/java/WorldScene.java')
-rw-r--r-- | src/main/java/WorldScene.java | 60 |
1 files changed, 44 insertions, 16 deletions
diff --git a/src/main/java/WorldScene.java b/src/main/java/WorldScene.java index 7d08077..7888d6a 100644 --- a/src/main/java/WorldScene.java +++ b/src/main/java/WorldScene.java @@ -14,15 +14,24 @@ public class WorldScene extends Scene { private Map map; private int tileSize; + private int panX; + private int panY; public WorldScene(Dimension gridSize, int tileSize) { this.tileSize = tileSize; map = new Map(gridSize); + this.panX = 0; + this.panY = 0; // TODO remove hardcoded stuff Actor player = new Actor("pipo", 100, Actor.Type.PLAYER, gridSize); + player.equipWeapon(new Weapon(1000, 10, 1, 0)); + Actor enemy = new Actor("marco", 100, Actor.Type.ENEMY, gridSize); + enemy.move(5, 5); + this.actors.add(player); + this.actors.add(enemy); } private Composite makeAlpha(Graphics2D g2d, float alpha) { @@ -33,6 +42,19 @@ public class WorldScene extends Scene { } @Override + public void zoom(int value) { + if (this.tileSize > 5 || value > 0) { + this.tileSize = this.tileSize + value; + } + } + + @Override + public void pan(int x, int y) { + this.panX = this.panX + x; + this.panY = this.panY + y; + } + + @Override public void render(Graphics g) { Graphics2D g2d = (Graphics2D) g; @@ -48,8 +70,8 @@ public class WorldScene extends Scene { } g2d.fillRect( - this.tileSize * tile.x, - this.tileSize * tile.y, + this.tileSize * tile.x + this.panX, + this.tileSize * tile.y + this.panY, this.tileSize, this.tileSize ); @@ -58,8 +80,8 @@ public class WorldScene extends Scene { if (tile.selected) { g2d.setColor(Palette.RED); g2d.fillRect( - this.tileSize * tile.x, - this.tileSize * tile.y, + this.tileSize * tile.x + this.panX, + this.tileSize * tile.y + this.panY, this.tileSize, this.tileSize ); } @@ -67,8 +89,8 @@ public class WorldScene extends Scene { // draw grid (with composite) g2d.setPaint(Palette.BLACK); g2d.drawRect( - this.tileSize * tile.x, - this.tileSize * tile.y, + this.tileSize * tile.x + this.panX, + this.tileSize * tile.y + this.panY, this.tileSize, this.tileSize ); @@ -79,11 +101,7 @@ public class WorldScene extends Scene { for (Actor actor : this.actors) { switch (actor.type) { case PLAYER: - if (actor.isAlive()) { - g2d.setColor(Palette.ORANGE); - } else { - g2d.setColor(Palette.BLUE); - } + g2d.setColor(Palette.ORANGE); break; case ENEMY: g2d.setColor(Palette.RED); @@ -91,26 +109,36 @@ public class WorldScene extends Scene { } int gap = this.tileSize / 10; g2d.fillRect( - (this.tileSize * actor.getX()) + gap, - (this.tileSize * actor.getY()) + gap, + (this.tileSize * actor.getX()) + gap + this.panX, + (this.tileSize * actor.getY()) + gap + this.panY, this.tileSize - gap * 2, this.tileSize - gap * 2 ); + if (!actor.isAlive()) { + g2d.setColor(Palette.BLUE); + g2d.fillRect( + (this.tileSize * actor.getX()) + gap + this.panX, + (this.tileSize * actor.getY()) + this.tileSize/4 + this.panY, + this.tileSize - gap * 2, this.tileSize/4 + ); + } } } @Override public void mouseClicked(int x, int y) { + //TODO fix mouse tracking with pan this.updateTiles(); Tile tile = map.getTile( - (int) (x/(double)this.tileSize) + sceneXOffset, - (int) (y/(double)this.tileSize) + sceneYOffset + (int) ((x+this.panX)/(double)this.tileSize) + this.sceneXOffset, + (int) ((y+this.panY)/(double)this.tileSize) + this.sceneYOffset ); //TODO remove test stuff if (tile.getActor() != null) { Actor actor = tile.getActor(); - actor.damage(1000); + Actor player = this.actors.get(0); + player.shoot(actor, 1); } } |