prepare for hexagon display & other models
- display cell as hexagon is Display.mHexagon if set ( not default ) will need a checkbox to set this - various new models preparation...
This commit is contained in:
@@ -50,6 +50,7 @@ implements StatusListener
|
||||
|
||||
boolean statusEnable = true;
|
||||
boolean mGrow = false;
|
||||
boolean mHexagon = false;
|
||||
|
||||
JTextField statusField = null;
|
||||
|
||||
@@ -101,7 +102,8 @@ implements StatusListener
|
||||
}
|
||||
|
||||
private MazeComponent createMazeComponent(LabyModel model, int W, int H) {
|
||||
MazeCellParameters cp = new MazeCellParameters(model.getWidth(), model.getHeight(), W, H, 0, 0);
|
||||
|
||||
MazeCellParameters cp = mHexagon ? new HexagonCell(model.getWidth(), model.getHeight(), W, H, 0, 0) : new MazeCellParameters(model.getWidth(), model.getHeight(), W, H, 0, 0);
|
||||
MazeComponent comp = new MazeComponent(model, cp, this);
|
||||
Xpm xpm = new Xpm();
|
||||
try {
|
||||
|
||||
90
java/org/artisanlogiciel/games/maze/gui/HexagonCell.java
Normal file
90
java/org/artisanlogiciel/games/maze/gui/HexagonCell.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package org.artisanlogiciel.games.maze.gui;
|
||||
|
||||
import org.artisanlogiciel.games.maze.Brick;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* draw cell as an hexagon
|
||||
* using a square model ( LEFT UP only).
|
||||
*/
|
||||
|
||||
public class HexagonCell
|
||||
extends MazeCellParameters
|
||||
{
|
||||
public final static int SUBCELL = 4;
|
||||
|
||||
public HexagonCell(int mapw, int maph, int W, int H, int x, int y) {
|
||||
super(mapw, maph, W, H, x, y);
|
||||
}
|
||||
|
||||
void drawLine(Graphics g, int refx, int refy, int x, int y, int a, int b) {
|
||||
g.drawLine(
|
||||
(int) ((refx + x) * getWidth() / SUBCELL), (int) ((refy + y) * getHeight() / SUBCELL),
|
||||
(int) ((refx + a) * getWidth() / SUBCELL),(int) ((refy + b) * getHeight() / SUBCELL));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(Graphics g, int pX, int pY, short walls) {
|
||||
UV uv= new UV(pX,pY);
|
||||
int x = offsetX + (int) (uv.getX() * width / SUBCELL);
|
||||
int y = offsetY + (int) (uv.getY() * height / SUBCELL);
|
||||
Color savecolor = g.getColor();
|
||||
int greylevel = walls << 2;
|
||||
g.setColor(getGreyedColor(savecolor,greylevel));
|
||||
//g.fillRect(x+1,y+1,((int)width) -1,((int)height) - 1);
|
||||
g.fillRect(x,y,((int)width),((int)height));
|
||||
}
|
||||
|
||||
class UV
|
||||
{
|
||||
int u;
|
||||
int v;
|
||||
|
||||
UV(int u, int v)
|
||||
{
|
||||
this.u=u;
|
||||
this.v=v;
|
||||
}
|
||||
|
||||
int getX()
|
||||
{
|
||||
return u*4 + 2*(v%2);
|
||||
}
|
||||
|
||||
int getY()
|
||||
{
|
||||
return 3*v;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawWalls(Graphics g, int pX, int pY, short walls) {
|
||||
drawHalfNW(g, pX, pY, walls);
|
||||
}
|
||||
|
||||
void drawHalfNW(Graphics g, int refx, int refy, short walls)
|
||||
{
|
||||
UV uv= new UV(refx,refy);
|
||||
int x = uv.getX();
|
||||
int y = uv.getY();
|
||||
// NW : (0,1) - (2,0)
|
||||
if (Brick.isFlagSet( Brick.UP, walls))
|
||||
drawLine(g,x, y, 0,1,2,0);
|
||||
// W : (0,1) - (0,3)
|
||||
if (Brick.isFlagSet( Brick.LEFT, walls))
|
||||
drawLine(g,x,y,0,1,0,3);
|
||||
// NE : (2,0) - (4,1)
|
||||
// if (Brick.isFlagSet( Brick.NE, walls))
|
||||
drawLine(g,x,y,2,0,4,1);
|
||||
}
|
||||
|
||||
void drawHalfSW(Graphics g)
|
||||
{
|
||||
// SW : (0,3) - (2,4)
|
||||
// SE : (2,4) - (4,3)
|
||||
// E : (4,3) - (4,1)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -94,13 +94,13 @@ public class MazeCellParameters {
|
||||
public void drawWalls(Graphics g, int pX, int pY, short walls) {
|
||||
int x = offsetX + (int) (pX * width);
|
||||
int y = offsetY + (int) (pY * height);
|
||||
if ((pY == 0) && ((walls & Brick.UP) == Brick.UP))
|
||||
if ((pY == 0) && ( Brick.isFlagSet( Brick.UP, walls)))
|
||||
g.drawLine(x, y, x + (int) width, y);
|
||||
if ((walls & Brick.DOWN) == Brick.DOWN)
|
||||
if (Brick.isFlagSet( Brick.DOWN, walls))
|
||||
g.drawLine(x, y + (int) height, x + (int) width, y + (int) height);
|
||||
if ((walls & Brick.RIGHT) == Brick.RIGHT)
|
||||
if (Brick.isFlagSet( Brick.RIGHT, walls))
|
||||
g.drawLine(x + (int) width, y, x + (int) width, y + (int) height);
|
||||
if ((pX == 0) && ((walls & Brick.LEFT) == Brick.LEFT))
|
||||
if ((pX == 0) && (Brick.isFlagSet( Brick.LEFT, walls)))
|
||||
g.drawLine(x, y, x, y + (int) height);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user