Search in sources :

Example 1 with LineWall

use of src.model.board.LineWall in project Labyrinthe3d by FauconFan.

the class Init method makeWalls.

/**
 * Dessine les murs du Maze
 * @return Le groupe contenant les murs
 */
public static Group makeWalls(Scale sc, MainMaze maze) {
    Material mat;
    try {
        String texturePath = maze.getContentMazeCurrentLevel().getTexturePath();
        if (texturePath == null) {
            // Default
            texturePath = "assets/Brick_wall_002_COLOR.jpg";
        }
        Image img = new Image(new FileInputStream(texturePath), 400, 400, true, false);
        mat = new PhongMaterial(Color.WHITE, img, null, null, null);
    } catch (Exception e) {
        mat = new PhongMaterial(Color.GREEN);
    }
    Group walls = new Group();
    // On scale les murs
    walls.getTransforms().add(sc);
    final float delta = 0.001f;
    ContentMaze[] cms = maze.getContentMaze();
    for (int i = 0; i < cms.length; i++) {
        for (LineWall l : cms[i].getLineWalls()) {
            LineWall[] broken = LineWall.breakWallsIntoSimpleOnes(l);
            for (int j = 0; j < broken.length; j++) {
                Box w = new Box();
                Consumer<Float> setEpais;
                Consumer<Float> setLarg;
                float largeur;
                double trX;
                double trZ;
                float isStart = (j == 0) ? broken[j].getEpaisseur() / 2 - delta : 0;
                float isEnd = (j == broken.length - 1) ? broken[j].getEpaisseur() / 2 - delta : 0;
                if (// Mur "vertical" dans le plan
                !broken[j].isHorizontal()) {
                    largeur = broken[j].getY2() - broken[j].getY1();
                    setLarg = w::setDepth;
                    setEpais = w::setWidth;
                    trX = broken[j].getX1();
                    trZ = broken[j].getY1() + largeur / 2.0;
                } else // Mur horizontal
                {
                    largeur = broken[j].getX2() - broken[j].getX1();
                    setLarg = w::setWidth;
                    setEpais = w::setDepth;
                    trX = broken[j].getX1() + largeur / 2.0;
                    trZ = broken[j].getY1();
                }
                w.setHeight(1);
                setEpais.accept(broken[j].getEpaisseur());
                setLarg.accept(largeur + isStart + isEnd);
                w.setTranslateX(trX);
                w.setTranslateZ(trZ);
                w.setTranslateY(-i - 0.5);
                w.setMaterial(mat);
                walls.getChildren().add(w);
            }
        }
    }
    return (walls);
}
Also used : Group(javafx.scene.Group) Material(javafx.scene.paint.Material) PhongMaterial(javafx.scene.paint.PhongMaterial) LineWall(src.model.board.LineWall) Box(javafx.scene.shape.Box) Image(javafx.scene.image.Image) ContentMaze(src.model.ContentMaze) FileInputStream(java.io.FileInputStream) View(src.view.View) PhongMaterial(javafx.scene.paint.PhongMaterial)

Example 2 with LineWall

use of src.model.board.LineWall in project Labyrinthe3d by FauconFan.

the class DisplayMazeConsole method displayMazeSingle.

/**
 * Affiche le labyrinthe dans la console
 * @param cm Labyrinthe a affiché
 * @param reverse Sens d'affichage par rapport aux ordonnées
 */
private static void displayMazeSingle(ContentMaze cm, boolean reverse) {
    int xStart = 0;
    int yStart = 0;
    int xEnd = 0;
    int yEnd = 0;
    LineWall[] walls = cm.getLineWalls();
    for (LineWall lw : walls) {
        xStart = Math.min(Math.min(lw.getX1(), lw.getX2()), xStart);
        xEnd = Math.max(Math.max(lw.getX1(), lw.getX2()), xEnd);
        yStart = Math.min(Math.min(lw.getY1(), lw.getY2()), yStart);
        yEnd = Math.max(Math.max(lw.getY1(), lw.getY2()), yEnd);
    }
    charWall[][] maze = new charWall[yEnd - yStart + 1][xEnd - xStart + 1];
    for (LineWall lw : walls) {
        int xRef = Math.min(lw.getX1(), lw.getX2()) - xStart;
        int yRef = Math.min(lw.getY1(), lw.getY2()) - yStart;
        int distanceWall = Math.max(Math.abs(lw.getX1() - lw.getX2()), Math.abs(lw.getY1() - lw.getY2()));
        boolean isHorizontal = lw.isHorizontal();
        for (int d = 0; d < distanceWall; d++) {
            if (maze[yRef][xRef] != null && ((maze[yRef][xRef].equals(charWall.HORIZONTAL) && !isHorizontal) || (maze[yRef][xRef].equals(charWall.VERTICAL) && isHorizontal))) {
                maze[yRef][xRef] = charWall.INTERSECTION;
            } else if (maze[yRef][xRef] == null) {
                maze[yRef][xRef] = (isHorizontal) ? charWall.HORIZONTAL : charWall.VERTICAL;
            }
            if (isHorizontal) {
                xRef++;
            } else {
                yRef++;
            }
        }
    }
    int i = (reverse) ? maze.length - 1 : 0;
    for (int index = 0; index < maze.length; index++) {
        for (int j = 0; j < maze[index].length; j++) {
            boolean haut, bas;
            if (reverse) {
                bas = (i > 0 && maze[i - 1][j] != null && (maze[i - 1][j].equals(charWall.VERTICAL) || maze[i - 1][j].equals(charWall.INTERSECTION)));
                haut = (maze[i][j] != null && (maze[i][j].equals(charWall.VERTICAL) || maze[i][j].equals(charWall.INTERSECTION)));
            } else {
                haut = (i > 0 && maze[i - 1][j] != null && (maze[i - 1][j].equals(charWall.VERTICAL) || maze[i - 1][j].equals(charWall.INTERSECTION)));
                bas = (maze[i][j] != null && (maze[i][j].equals(charWall.VERTICAL) || maze[i][j].equals(charWall.INTERSECTION)));
            }
            boolean gauche = (j > 0 && maze[i][j - 1] != null && (maze[i][j - 1].equals(charWall.HORIZONTAL) || maze[i][j - 1].equals(charWall.INTERSECTION)));
            boolean droit = (maze[i][j] != null && (maze[i][j].equals(charWall.HORIZONTAL) || maze[i][j].equals(charWall.INTERSECTION)));
            if ((droit && gauche && !haut && !bas)) {
                System.out.print(charWall.HORIZONTAL);
            } else if ((droit && !gauche && !bas && !haut)) {
                System.out.print(charWall.HORIZONTALRIGHT);
            } else if ((!droit && gauche && !bas && !haut)) {
                System.out.print(charWall.HORIZONTALLEFT);
            } else if ((bas && haut && !droit && !gauche)) {
                System.out.print(charWall.VERTICAL);
            } else if ((bas && !haut && !gauche && !droit)) {
                System.out.print(charWall.VERTICALDOWN);
            } else if ((haut && !bas && !gauche && !droit)) {
                System.out.print(charWall.VERTICALUP);
            } else if (haut && droit && bas && gauche) {
                System.out.print(charWall.INTERSECTION);
            } else if (droit && gauche && haut && !bas) {
                System.out.print(charWall.HORIZONTALTOP);
            } else if (droit && gauche && !haut && bas) {
                System.out.print(charWall.HORIZONTALBOTTOM);
            } else if (haut && gauche && bas && !droit) {
                System.out.print(charWall.VERTICALLEFT);
            } else if (haut && droit && bas && !gauche) {
                System.out.print(charWall.VERTICALRIGHT);
            } else if (haut && gauche && !bas && !droit) {
                System.out.print(charWall.CORNERTOPLEFT);
            } else if (haut && !gauche && !bas && droit) {
                System.out.print(charWall.CORNERTOPRIGHT);
            } else if (!haut && gauche && bas && !droit) {
                System.out.print(charWall.CORNERBOTTOMLEFT);
            } else if (!haut && !gauche && bas && droit) {
                System.out.print(charWall.CORNERBOTTOMRIGHT);
            } else {
                System.out.print(" ");
            }
        }
        i += (reverse) ? -1 : 1;
        System.out.println();
    }
}
Also used : LineWall(src.model.board.LineWall)

Example 3 with LineWall

use of src.model.board.LineWall in project Labyrinthe3d by FauconFan.

the class ContentMazeFactory method normalizeEachDimension.

private void normalizeEachDimension(HashMap<Integer, ArrayList<LineWall>> content, HashMap<Integer, ArrayList<LineWall>> list_doors) {
    ArrayList<LineWall> normalized;
    ArrayList<LineWall> doors;
    ArrayList<LineWall> tmp;
    ArrayList<LineWall> res_tmp;
    int old_size;
    for (Map.Entry<Integer, ArrayList<LineWall>> entry : content.entrySet()) {
        normalized = this.normalizeList(entry.getValue());
        doors = list_doors.get(entry.getKey());
        if (doors != null) {
            res_tmp = new ArrayList<>();
            for (LineWall wall : normalized) {
                tmp = new ArrayList<>();
                tmp.add(wall);
                while (true) {
                    old_size = tmp.size();
                    for (int i = 0; i < tmp.size(); i++) {
                        for (LineWall door : doors) {
                            ArrayList<LineWall> ahah = LineWallUtils.except(tmp.get(i), door);
                            tmp.addAll(ahah);
                            tmp.remove(i);
                        }
                    }
                    if (old_size == tmp.size()) {
                        break;
                    }
                }
                res_tmp.addAll(tmp);
            }
            normalized = res_tmp;
        }
        content.put(entry.getKey(), normalized);
    }
}
Also used : ArrayList(java.util.ArrayList) LineWall(src.model.board.LineWall) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with LineWall

use of src.model.board.LineWall in project Labyrinthe3d by FauconFan.

the class ContentMazeFactory method normalizeList.

private ArrayList<LineWall> normalizeList(ArrayList<LineWall> list) {
    ArrayList<LineWall> res = new ArrayList<>();
    boolean modeX;
    if (list.size() == 0) {
        return (res);
    }
    modeX = (list.get(0).getX1() == list.get(0).getX2());
    while (list.size() != 0) {
        LineWall actu;
        int maxActu;
        int minActu;
        boolean isFinished;
        actu = list.get(0);
        list.remove(0);
        maxActu = ((modeX) ? Math.max(actu.getY1(), actu.getY2()) : Math.max(actu.getX1(), actu.getX2()));
        minActu = ((modeX) ? Math.min(actu.getY1(), actu.getY2()) : Math.min(actu.getX1(), actu.getX2()));
        isFinished = false;
        while (isFinished == false) {
            isFinished = true;
            for (int i = 0; i < list.size(); i++) {
                LineWall tested;
                int maxTested;
                int minTested;
                tested = list.get(i);
                maxTested = ((modeX) ? Math.max(tested.getY1(), tested.getY2()) : Math.max(tested.getX1(), tested.getX2()));
                minTested = ((modeX) ? Math.min(tested.getY1(), tested.getY2()) : Math.min(tested.getX1(), tested.getX2()));
                if ((maxTested >= minActu && maxTested <= maxActu) || (minTested >= minActu && minTested <= maxActu)) {
                    isFinished = false;
                    LineWall fusion;
                    if (modeX) {
                        fusion = new LineWall(actu.getX1(), Math.min(minTested, minActu), actu.getX2(), Math.max(maxTested, maxActu), Math.max(actu.getEpaisseur(), tested.getEpaisseur()));
                    } else {
                        fusion = new LineWall(Math.min(minTested, minActu), actu.getY1(), Math.max(maxTested, maxActu), actu.getY2(), Math.max(actu.getEpaisseur(), tested.getEpaisseur()));
                    }
                    actu = fusion;
                    list.remove(i);
                    i--;
                }
            }
        }
        res.add(actu);
    }
    return (res);
}
Also used : ArrayList(java.util.ArrayList) LineWall(src.model.board.LineWall)

Example 5 with LineWall

use of src.model.board.LineWall in project Labyrinthe3d by FauconFan.

the class MapIntro1 method buildOneSquareLabyrinthe.

private RectMaze buildOneSquareLabyrinthe() {
    RectMaze rl;
    ArrayList<LineWall> listWalls;
    listWalls = new ArrayList<>();
    listWalls.add(new LineWall(0, 0, 0, size_y));
    listWalls.add(new LineWall(size_x, size_y, size_x, 0));
    listWalls.add(new LineWall(0, 0, size_x, 0));
    listWalls.add(new LineWall(0, size_y, size_x, size_y));
    rl = new RectMaze(new ContentMazeEgg(new Case[0], listWalls.toArray(new LineWall[0])), size_x, size_y);
    return (rl);
}
Also used : LineWall(src.model.board.LineWall) ContentMazeEgg(src.model.gen.ContentMazeEgg) RectMaze(src.model.gen.RectMaze)

Aggregations

LineWall (src.model.board.LineWall)18 RectMaze (src.model.gen.RectMaze)8 ContentMazeEgg (src.model.gen.ContentMazeEgg)7 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Group (javafx.scene.Group)2 ContentMaze (src.model.ContentMaze)2 FileInputStream (java.io.FileInputStream)1 Map (java.util.Map)1 Random (java.util.Random)1 AmbientLight (javafx.scene.AmbientLight)1 Image (javafx.scene.image.Image)1 Material (javafx.scene.paint.Material)1 PhongMaterial (javafx.scene.paint.PhongMaterial)1 Box (javafx.scene.shape.Box)1 Line (javafx.scene.shape.Line)1 Case (src.model.board.Case)1 EndCase (src.model.board.EndCase)1 JumpCase (src.model.board.JumpCase)1 SpeedCase (src.model.board.SpeedCase)1