Code to render piecen images and shield image. Updated piecen points to

jive nicely with the tile images. Name changes. Other cleanups.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@521 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2001-12-18 11:58:54 +00:00
parent b8f5028181
commit cd8847afef
10 changed files with 173 additions and 72 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 167 KiB

@@ -1,5 +1,5 @@
//
// $Id: TileGeometryTest.java,v 1.3 2001/10/16 09:31:46 mdb Exp $
// $Id: TileGeometryTest.java,v 1.4 2001/12/18 11:58:53 mdb Exp $
package com.threerings.venison;
@@ -12,6 +12,10 @@ import javax.swing.JPanel;
import com.samskivert.swing.util.SwingUtil;
import com.threerings.resource.ResourceManager;
import com.threerings.media.ImageManager;
import com.threerings.media.tile.TileManager;
/**
* A simple class for testing the tile geometry specifications by drawing
* them.
@@ -22,7 +26,7 @@ public class TileGeometryTest
public TileGeometryTest ()
{
for (int i = 0; i < TILE_TYPES; i++) {
_tiles[i] = new VenisonTile(i+1, false, NORTH, i % 5, i / 5);
_tiles[i] = new VenisonTile(i+1, true, NORTH, i % 5, i / 5);
}
}
@@ -45,6 +49,15 @@ public class TileGeometryTest
public static void main (String[] args)
{
JFrame frame = new JFrame("Tile geometry test");
ResourceManager rmgr = new ResourceManager(null, "rsrc");
ImageManager imgr = new ImageManager(rmgr, frame);
TileManager tmgr = new TileManager(imgr);
VenisonTile.setTileManager(tmgr);
VenisonTile.piecenDebug = true;
PiecenUtil.init(tmgr);
// quit if we're closed
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
TileGeometryTest panel = new TileGeometryTest();
@@ -65,7 +65,7 @@ public class VenisonPanel
JPanel sidePanel = new JPanel(sgl);
// add a big fat label because we love it!
JLabel vlabel = new JLabel("Venison!");
JLabel vlabel = new JLabel("Atlantissonne!");
vlabel.setFont(new Font("Helvetica", Font.BOLD, 24));
vlabel.setForeground(Color.black);
sidePanel.add(vlabel, VGroupLayout.FIXED);
@@ -111,6 +111,7 @@ public class VenisonPanel
ImageManager imgr = new ImageManager(_rmgr, rpane);
TileManager tmgr = new TileManager(imgr);
VenisonTile.setTileManager(tmgr);
PiecenUtil.init(tmgr);
}
public void ancestorMoved (AncestorEvent event) {
}
@@ -1,13 +1,17 @@
//
// $Id: AtlantiTile.java,v 1.12 2001/11/24 04:29:04 mdb Exp $
// $Id: AtlantiTile.java,v 1.13 2001/12/18 11:58:54 mdb Exp $
package com.threerings.venison;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Image;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Polygon;
import java.awt.geom.AffineTransform;
import java.awt.geom.Point2D;
import java.io.IOException;
import java.io.DataInputStream;
@@ -34,6 +38,10 @@ public class VenisonTile
public static final VenisonTile STARTING_TILE =
new VenisonTile(CITY_ONE_ROAD_STRAIGHT, false, NORTH, 0, 0);
/** Activate this to render a piecen on every feature (useful for the
* tile geometry test). */
public static boolean piecenDebug = false;
/** The tile type. */
public int type;
@@ -290,15 +298,45 @@ public class VenisonTile
", img=" + _tileImage + "].");
}
// render our features and piecen
for (int i = 0; i < features.length; i++) {
// paint the feature
// features[i].paint(g, orientation, claims[i]);
// // render our features
// for (int i = 0; i < features.length; i++) {
// // paint the feature
// features[i].paint(g, orientation, claims[i]);
// }
// if we have a piecen on this tile, render it as well
if (piecen != null && piecen.featureIndex == i) {
features[i].paintPiecen(
g, orientation, piecen.owner, piecen.claimGroup);
// if we have a shield, draw a square in the lower right
if (hasShield) {
Point2D sspot = FeatureUtil.getShieldSpot(orientation);
Image image = getShieldImage();
if (image != null) {
int iwidth = image.getWidth(null);
int iheight = image.getHeight(null);
Composite ocomp = g.getComposite();
g.setComposite(ALPHA_PLACING);
g.drawImage(image, (int)(sspot.getX() - iwidth/2),
(int)(sspot.getY() - iheight/2), null);
g.setComposite(ocomp);
} else {
g.setColor(Color.orange);
g.drawRect((int)(sspot.getX()-5),
(int)(sspot.getY()-5), 10, 10);
}
}
// if we have a piecen on this tile, render it as well
if (piecen != null || piecenDebug) {
for (int i = 0; i < features.length; i++) {
if (piecenDebug) {
Image pimg = PiecenUtil.getPiecenImage(0);
features[i].paintPiecen(g, orientation, pimg, 0);
} else if (piecen.featureIndex == i) {
Image pimg = PiecenUtil.getPiecenImage(piecen.owner);
features[i].paintPiecen(
g, orientation, pimg, piecen.claimGroup);
}
}
}
@@ -306,12 +344,6 @@ public class VenisonTile
// g.setColor(Color.black);
// g.drawRect(0, 0, TILE_WIDTH-1, TILE_HEIGHT-1);
// if we have a shield, draw a square in the lower right
if (hasShield) {
g.setColor(Color.orange);
g.drawRect(TILE_WIDTH-15, TILE_HEIGHT-15, 10, 10);
}
// translate back out
g.translate(-sx, -sy);
}
@@ -458,18 +490,53 @@ public class VenisonTile
return null;
}
/**
* Fetches the shield image.
*/
protected static Image getShieldImage ()
{
// load up the tile set if we haven't already
if (_stset == null) {
_stset = new UniformTileSet();
_stset.setTileCount(1);
_stset.setWidth(SHIELD_SIZE);
_stset.setHeight(SHIELD_SIZE);
_stset.setImagePath(SHIELD_IMG_PATH);
_stset.setImageProvider(_tmgr);
}
// fetch the tile
try {
return _stset.getTileImage(0);
} catch (NoSuchTileException nste) {
// fall through
}
Log.warning("Unable to load shield image!");
return null;
}
/** The tile image that we use to render this tile. */
protected Image _tileImage;
/** Our tile manager. */
protected static TileManager _tmgr;
/** Our tileset. */
/** Our tile image tileset. */
protected static UniformTileSet _tset;
/** Our shield image tileset. */
protected static UniformTileSet _stset;
/** The path to our tileset image. */
protected static final String TILES_IMG_PATH = "media/tiles.png";
/** The path to our shield image. */
protected static final String SHIELD_IMG_PATH = "media/shield.png";
/** The size of the shield image (width and height). */
protected static final int SHIELD_SIZE = 17;
/** Three affine transforms for rendering an image in three rotated
* orientations. */
protected static AffineTransform[] _xforms;
@@ -488,4 +555,8 @@ public class VenisonTile
_xforms[orient] = (AffineTransform)xform.clone();
}
}
/** For rendering shields with alpha. */
protected static final Composite ALPHA_PLACING =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
}
@@ -1,10 +1,13 @@
//
// $Id: Feature.java,v 1.3 2001/11/08 08:01:42 mdb Exp $
// $Id: Feature.java,v 1.4 2001/12/18 11:58:53 mdb Exp $
package com.threerings.venison;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Composite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
@@ -55,6 +58,10 @@ public class Feature
py *= -1;
py -= TILE_HEIGHT/8;
}
// oh, just a teeny hack for aesthetic shield placement
if (type == -1) {
px += 2; py += 2;
}
piecenSpots[NORTH] = new Point2D.Float(px, py);
// create our natural feature polygon
@@ -192,34 +199,23 @@ public class Feature
*
* @param g the graphics context to use when painting the feature.
* @param orientation the orientation at which to paint this feature.
* @param color the piecen color to be painted.
* @param image the piecen image to be painted.
* @param claimGroup the claim group to which this piecen belongs (or
* zero if it belongs to no claim group).
*/
public void paintPiecen (Graphics2D g, int orientation, int color,
public void paintPiecen (Graphics2D g, int orientation, Image image,
int claimGroup)
{
// paint a colored circle around the proper piecen spot
Point2D point = piecenSpots[orientation];
double swidth = TILE_WIDTH/5;
double sheight = TILE_HEIGHT/5;
int iwidth = image.getWidth(null);
int iheight = image.getHeight(null);
Shape spot = new RoundRectangle2D.Double(
point.getX()-swidth/2, point.getY()-sheight/2,
swidth, sheight, swidth/4, sheight/4);
g.setColor(PIECEN_COLOR_MAP[color]);
g.fill(spot);
// fucking ridiculous: draw()ing the same shape that was fill()ed
// doesn't generate the same shape. a draw()n shape is one pixel
// larger than a fill()ed shape (probably to account for some
// backwards compatible bad decision), so we have to create a
// whole new shape object to generate the outline. thanks sun
spot = new RoundRectangle2D.Double(
point.getX()-swidth/2, point.getY()-sheight/2,
swidth-1, sheight-1, swidth/4, sheight/4);
g.setColor(Color.black);
g.draw(spot);
// render the piecen image slightly transparent
Composite ocomp = g.getComposite();
g.setComposite(ALPHA_PLACING);
g.drawImage(image, (int)(point.getX() - iwidth/2),
(int)(point.getY() - iheight/2), null);
g.setComposite(ocomp);
// // for now, draw the claim group next to the piecen
// g.drawString(Integer.toString(claimGroup),
@@ -367,4 +363,8 @@ public class Feature
Color.yellow, // YELLOW
Color.green, // GREEN
};
/** For rendering piecens with alpha. */
protected static final Composite ALPHA_PLACING =
AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f);
}
@@ -1,5 +1,5 @@
//
// $Id: TileCodes.java,v 1.8 2001/10/18 20:54:20 mdb Exp $
// $Id: TileCodes.java,v 1.9 2001/12/18 11:58:53 mdb Exp $
package com.threerings.venison;
@@ -120,7 +120,7 @@ public interface TileCodes
/** Human readable names to go along with the feature constants. */
public static final String[] FEATURE_NAMES = {
"city", "farm", "road", "cloister" };
"island", "fishery", "boardwalk", "temple" };
/** A flag used to mark a tile as part of a completed city. */
public static final int COMPLETED_CITY = 0x01;
@@ -1,5 +1,5 @@
//
// $Id: AtlantiManager.java,v 1.20 2001/12/18 10:17:50 mdb Exp $
// $Id: AtlantiManager.java,v 1.21 2001/12/18 11:58:53 mdb Exp $
package com.threerings.venison;
@@ -307,7 +307,7 @@ public class VenisonManager
// deliver a chat notification to tell the
// players about the score
String message = _players[p.owner] + " scored " +
score + " points for " + qual + " cloister.";
score + " points for " + qual + " temple.";
ChatProvider.sendSystemMessage(
_venobj.getOid(), message);
@@ -455,7 +455,7 @@ public class VenisonManager
if (cityScores[i] > 0) {
_venobj.scores[i] += cityScores[i];
String message = _players[i] + " scores " + cityScores[i] +
" points for farmed cities.";
" points for fisheries.";
ChatProvider.sendSystemMessage(_venobj.getOid(), message);
}
}
@@ -1,8 +1,10 @@
//
// $Id: FeatureUtil.java,v 1.4 2001/10/18 21:52:01 mdb Exp $
// $Id: FeatureUtil.java,v 1.5 2001/12/18 11:58:53 mdb Exp $
package com.threerings.venison;
import java.awt.geom.Point2D;
/**
* Feature related constants and utility functions.
*/
@@ -110,6 +112,15 @@ public class FeatureUtil implements TileCodes
return features;
}
/**
* Returns the position of the shield on a tile of the given
* orientation.
*/
public static Point2D getShieldSpot (int orientation)
{
return _shieldFeature.piecenSpots[orientation];
}
/**
* Returns a string describing the supplied type code.
*/
@@ -223,7 +234,7 @@ public class FeatureUtil implements TileCodes
{ CITY, EAST_F|WEST_F, // EW_CITY
2,2, 0,0, 1,1, 3,1, 4,0, 4,4, 3,3, 1,3, 0,4 },
{ CITY, NORTH_F|WEST_F, // NW_CITY
1,1, 0,0, 4,0, 0,4 },
1,2, 0,0, 4,0, 0,4 },
{ CITY, NORTH_F, // N_CITY
2,-1, 0,0, 1,1, 3,1, 4,0 },
{ CITY, EAST_F, // E_CITY
@@ -239,11 +250,16 @@ public class FeatureUtil implements TileCodes
{ GRASS, SOUTH_F, // S_GRASS
2,-4, 0,4, 1,3, 3,3, 4,4 },
{ GRASS, ESE_F|SSE_F, // SE_GRASS
3,3, 2,2, 4,2, 4,4, 2,4 },
-4,-4, 2,2, 4,2, 4,4, 2,4 },
{ GRASS, WSW_F|SSW_F, // SW_GRASS
1,3, 0,2, 2,2, 2,4, 0,4 },
-1,-4, 0,2, 2,2, 2,4, 0,4 },
};
/** A feature that is used to obtain the position information for
* rendering shields on city tiles that use shields. */
protected static final int[] SHIELD_FEATURE = new int[]
{ -1, NORTH_F|WEST_F, -1,-1, 0,0, 4,0, 0,4 };
/** A table describing the features of each tile. */
protected static final int[][][] TILE_FEATURES = new int[][][] {
// one must offset tile type by one when indexing into this array
@@ -254,15 +270,15 @@ public class FeatureUtil implements TileCodes
{ S_GRASS } },
{ { NEW_CITY }, // CITY_THREE_ROAD
{ GRASS, SSW_F, -2,-4, 0,4, 1,3, 2,3, 2,4 },
{ GRASS, SSE_F, -3,-4, 2,4, 2,3, 3,3, 4,4 },
{ GRASS, SSW_F, 1,-4, 0,4, 1,3, 2,3, 2,4 },
{ GRASS, SSE_F, 3,-4, 2,4, 2,3, 3,3, 4,4 },
{ ROAD, SOUTH_F, 2,-4, 2,3, 2,4 } },
{ { NW_CITY }, // CITY_TWO
{ GRASS, EAST_F|SOUTH_F, 3,3, 0,4, 4,0, 4,4 } },
{ GRASS, EAST_F|SOUTH_F, 3,-4, 0,4, 4,0, 4,4 } },
{ { NW_CITY }, // CITY_TWO_ROAD
{ GRASS, ENE_F|SSW_F, -3,-3, 0,4, 4,0, 4,2, 2,4 },
{ GRASS, ENE_F|SSW_F, -3,-2, 0,4, 4,0, 4,2, 2,4 },
{ GRASS, ESE_F|SSE_F, -4,-4, 2,4, 4,2, 4,4 },
{ ROAD, EAST_F|SOUTH_F, 3,3, 2,4, 4,2 } },
@@ -270,25 +286,20 @@ public class FeatureUtil implements TileCodes
{ GRASS, NORTH_F, 2,-1, 0,0, 1,1, 3,1, 4,0 },
{ S_GRASS } },
// { { GRASS, WEST_F|SOUTH_F, // TWO_CITY_TWO
// 2,2, 0,0, 1,1, 3,1, 3,3, 4,4, 0,4 },
// { N_CITY },
// { E_CITY } },
{ { GRASS, WEST_F|SOUTH_F, // TWO_CITY_TWO
2,2, 0,0, 4,0, 4,4, 0,4 },
-1,-3, 0,0, 4,0, 4,4, 0,4 },
{ CITY, NORTH_F,
2,-1, 0,0, 2,1, 4,0 },
{ CITY, EAST_F,
-4,2, 4,0, 3,2, 4,4 } },
{ { GRASS, NORTH_F|SOUTH_F, // TWO_CITY_TWO_ACROSS
2,2, 0,0, 4,0, 3,1, 3,3, 4,4, 0,4, 1,3, 1,1 },
2,-4, 0,0, 4,0, 3,1, 3,3, 4,4, 0,4, 1,3, 1,1 },
{ W_CITY },
{ E_CITY } },
{ { GRASS, EAST_F|SOUTH_F|WEST_F, // CITY_ONE
2,2, 0,0, 1,1, 3,1, 4,0, 4,4, 0,4 },
2,-3, 0,0, 1,1, 3,1, 4,0, 4,4, 0,4 },
{ N_CITY } },
{ { GRASS, ENE_F|SSW_F|WEST_F, // CITY_ONE_ROAD_RIGHT
@@ -304,7 +315,7 @@ public class FeatureUtil implements TileCodes
{ N_CITY } },
{ { GRASS, ENE_F|WNW_F, // CITY_ONE_ROAD_TEE
2,-2, 0,0, 1,1, 3,1, 4,0, 4,2, 0,2 },
-1,1, 0,0, 1,1, 3,1, 4,0, 4,2, 0,2 },
{ SE_GRASS },
{ SW_GRASS },
{ E_ROAD },
@@ -313,23 +324,23 @@ public class FeatureUtil implements TileCodes
{ N_CITY } },
{ { GRASS, ENE_F|WNW_F, // CITY_ONE_ROAD_STRAIGHT
2,-2, 0,0, 1,1, 3,1, 4,0, 4,2, 0,2 },
-1,1, 0,0, 1,1, 3,1, 4,0, 4,2, 0,2 },
{ GRASS, ESE_F|SOUTH_F|WSW_F, 2,3, 0,2, 4,2, 4,4, 0,4 },
{ ROAD, EAST_F|WEST_F, 2,2, 0,2, 4,2 },
{ N_CITY } },
{ { GRASS, NORTH_F|EAST_F|SOUTH_F|WEST_F, // CLOISTER_PLAIN
1,1, 0,0, 4,0, 4,4, 0,4 },
-1,-1, 0,0, 4,0, 4,4, 0,4 },
{ CLOISTER, 0, 2,2, 1,1, 3,1, 3,3, 1,3 } },
{ { GRASS, NORTH_F|EAST_F|WEST_F|SSE_F|SSW_F, // CLOISTER_ROAD
1,1, 0,0, 4,0, 4,4, 0,4 },
-1,-1, 0,0, 4,0, 4,4, 0,4 },
{ CLOISTER, 0, 2,2, 1,1, 3,1, 3,3, 1,3 },
{ ROAD, SOUTH_F, 2,-4, 2,3, 2,4 } },
{ { GRASS, WNW_F|NNW_F, // FOUR_WAY_ROAD
1,1, 0,0, 2,0, 2,2, 0,2 },
{ GRASS, NNE_F|ENE_F, 3,1, 2,0, 4,0, 4,2, 2,2 },
-1,-1, 0,0, 2,0, 2,2, 0,2 },
{ GRASS, NNE_F|ENE_F, -4,-1, 2,0, 4,0, 4,2, 2,2 },
{ SE_GRASS },
{ SW_GRASS },
{ ROAD, NORTH_F, 2,1, 2,0, 2,2 },
@@ -338,7 +349,7 @@ public class FeatureUtil implements TileCodes
{ W_ROAD } },
{ { GRASS, WNW_F|NORTH_F|ENE_F, // THREE_WAY_ROAD
2,1, 0,0, 4,0, 4,2, 0,2 },
2,-1, 0,0, 4,0, 4,2, 0,2 },
{ SE_GRASS },
{ SW_GRASS },
{ E_ROAD },
@@ -346,8 +357,8 @@ public class FeatureUtil implements TileCodes
{ W_ROAD } },
{ { GRASS, NNW_F|WEST_F|SSW_F, // STRAIGHT_ROAD
1,2, 0,0, 2,0, 2,4, 0,4 },
{ GRASS, SSE_F|EAST_F|NNE_F, 3,2, 2,0, 4,0, 4,4, 2,4 },
-1,2, 0,0, 2,0, 2,4, 0,4 },
{ GRASS, SSE_F|EAST_F|NNE_F, -4,2, 2,0, 4,0, 4,4, 2,4 },
{ ROAD, NORTH_F|SOUTH_F, 2,2, 2,0, 2,4 } },
{ { GRASS, WNW_F|NORTH_F|EAST_F|SSE_F, // CURVED_ROAD
@@ -371,11 +382,16 @@ public class FeatureUtil implements TileCodes
/** A table of features that are used on more than one tile. */
protected static Feature[] _reusedFeatures;
/** The feature that provides the location information for shield
* rendering. */
protected static Feature _shieldFeature;
// create our reused features table
static {
_reusedFeatures = new Feature[FEATURES.length];
for (int i = 0; i < FEATURES.length; i++) {
_reusedFeatures[i] = new Feature(FEATURES[i]);
}
_shieldFeature = new Feature(SHIELD_FEATURE);
}
}