- display cell as hexagon is Display.mHexagon if set ( not default ) will need a checkbox to set this - various new models preparation...
91 lines
2.2 KiB
Java
91 lines
2.2 KiB
Java
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)
|
|
}
|
|
|
|
}
|