And here’s the code for the actual tiles. The forum software wouldn’t let me post the code altogether.
package sydneyengine.shooter;
import sydneyengine.shooter.maths.*;
import sydneyengine.shooter.vectorgraphics.*;
import sydneyengine.*;
import sydneyengine.superserializable.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.net.*;
import javax.imageio.*;
/**
*
* @author Keith W
*/
public class TileImage extends SSAdapter implements RenderArea{
VolatileImage vImage;
boolean initialised = false;
TileGrid tileGrid;
int w;
int h;
int x;
int y;
int indexX, indexY;
Point2D.Double viewCenterInWorldCoords;
BBox viewRectInWorldCoords = new BBox();
Graphics2D backImageGraphics2D;
public TileImage(){
}
public TileImage(TileGrid tileGrid, int indexX, int indexY, int x, int y, int width, int height){
setStats(tileGrid, indexX, indexY, x, y, width, height);
}
public void setStats(TileGrid tileGrid, int indexX, int indexY, int x, int y, int width, int height){
initialised = true;
this.tileGrid = tileGrid;
this.indexX = indexX;
this.indexY = indexY;
this.x = x;
this.y = y;
this.w = width;
this.h = height;
if (viewCenterInWorldCoords == null){
viewCenterInWorldCoords = new Point2D.Double(x + (width/2f), y + (height/2f));
}else{
viewCenterInWorldCoords.x = x + (width/2f);
viewCenterInWorldCoords.y = y + (height/2f);
}
viewRectInWorldCoords.x = x;
viewRectInWorldCoords.y = y;
viewRectInWorldCoords.w = w;
viewRectInWorldCoords.h = h;
}
protected VolatileImage createVolatileImage() {
//System.out.println(TileImage.class.getSimpleName() + ": calling createVolatileImage(...)");
VolatileImage volatileImage = ImageBank.createVolatileImage(getW(), getH(), Transparency.OPAQUE);
Graphics2D g = (Graphics2D)volatileImage.getGraphics();
// g.setColor(Color.RED);
// g.fillOval(x, y, w, h);
return volatileImage;
}
public void render(ViewPane v){
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
if (vImage == null || getW() != vImage.getWidth() || getH() != vImage.getHeight() || vImage.validate(gc) != VolatileImage.IMAGE_OK) {
vImage = createVolatileImage();
drawOntoImage();
}
do {
int valid = vImage.validate(gc);
if (valid == VolatileImage.IMAGE_INCOMPATIBLE) {
vImage = createVolatileImage();
drawOntoImage();
}
} while (vImage.contentsLost());
Graphics2D viewPaneGraphics = v.getBackImageGraphics2D();
viewPaneGraphics.setTransform(v.getPlayerCenteredATRounded());
// viewPaneGraphics.setColor(Color.MAGENTA);
// viewPaneGraphics.drawLine(0, 0, w, h);
viewPaneGraphics.drawImage(vImage, x, y, null);
// viewPaneGraphics.setColor(Color.MAGENTA);
// viewPaneGraphics.drawString("x == "+this.getIndexX()+", y == "+this.getIndexY(), x+10, y+20);
// viewPaneGraphics.drawString("x"+this.x+", y"+this.y, x+10, y+40);
// viewPaneGraphics.drawString("w"+this.w+", h"+this.h, x+10, y+60);
}
protected void drawOntoImage(){
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
if (vImage == null || getW() != vImage.getWidth() || getH() != vImage.getHeight() || vImage.validate(gc) != VolatileImage.IMAGE_OK) {
vImage = createVolatileImage();
}
backImageGraphics2D = vImage.createGraphics();
backImageGraphics2D.translate(-x, -y);
ViewPane.setGraphicsHints(backImageGraphics2D);
for (int i = 0; i < getWorld().getEnvironment().getFloors().size(); i++) {
getWorld().getEnvironment().getFloors().get(i).render(this);
}
for (int i = 0; i < getWorld().getEnvironment().getPaths().size(); i++) {
getWorld().getEnvironment().getPaths().get(i).render(this);
}
for (int i = 0; i < getWorld().getEnvironment().getRiverBeds().size(); i++) {
getWorld().getEnvironment().getRiverBeds().get(i).render(this);
}
for (int i = 0; i < getWorld().getEnvironment().getRivers().size(); i++) {
getWorld().getEnvironment().getRivers().get(i).render(this);
}
// If there is no map-making happening, render the below things onto this unchanging tile image.
// Otherwise the GameWorld will render it so, for example, it changes position after it's moved around.
if (GameFrame.getStaticGameFrame().getScriptFrame() == null){
for (int i = 0; i < getWorld().getEnvironment().getEditableImages().size(); i++) {
getWorld().getEnvironment().getEditableImages().get(i).render(this);
}
for (int i = 0; i < getWorld().getEnvironment().getEditableObstacles().size(); i++) {
getWorld().getEnvironment().getEditableObstacles().get(i).render(this);
}
}
// backImageGraphics2D.setColor(Color.BLACK);
// backImageGraphics2D.drawLine(x, y, x+w, y);
// backImageGraphics2D.drawLine(x+w, y, x+w, y+h);
// backImageGraphics2D.drawLine(x, y, x, y+h);
// backImageGraphics2D.drawLine(x, y+h, x+w, y+h);
backImageGraphics2D.dispose();
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public int getW(){
return w;
}
public int getH(){
return h;
}
public int getIndexX() {
return indexX;
}
public int getIndexY() {
return indexY;
}
public Graphics2D getBackImageGraphics2D() {
return backImageGraphics2D;
}
public BBox getViewRectInWorldCoords() {
return viewRectInWorldCoords;
}
public Point2D.Double getViewCenterInWorldCoords() {
return viewCenterInWorldCoords;
}
public boolean isInitialised() {
return initialised;
}
public TileGrid getTileGrid() {
return tileGrid;
}
public GameWorld getWorld() {
return getTileGrid().getWorld();
}
}