Package net.bytten.metazelda.util

Examples of net.bytten.metazelda.util.Coords


            IDungeon dungeon, Room room) {
        g.setColor(Color.BLACK);
       
        for (Edge edge: room.getEdges()) {
            Room nextRoom = dungeon.get(edge.getTargetRoomId());
            Coords coords = room.getCenter(),
                   nextCoords = nextRoom.getCenter();
           
            if (nextRoom.getParent() == room) {
                drawParentEdge(g, scale, roomSize, room, nextRoom);
            }
               
            double x1 = coords.x*scale + roomSize*scale,
                   y1 = coords.y*scale + roomSize*scale,
                   x2 = nextCoords.x*scale + roomSize*scale,
                   y2 = nextCoords.y*scale + roomSize*scale;
            double sdy = Math.signum(y2-y1), sdx = Math.signum(x2-x1);
            y1 += sdy * scale*roomSize/2;
            y2 -= sdy * scale*roomSize/2;
            x1 += sdx * scale*roomSize/2;
            x2 -= sdx * scale*roomSize/2;

            if (nextRoom != null && Symbol.equals(edge.getSymbol(),
                    nextRoom.getEdge(room.id).getSymbol())) {
                // Bidirectional edge
                // avoid drawing twice:
                if (coords.compareTo(nextCoords) > 0) continue;
               
                g.drawLine((int)x1, (int)y1, (int)x2, (int)y2);
               
                double midx = (x1+x2)/2,
                       midy = (y1+y2)/2;
View Full Code Here


                   
                    BufferedImage img = ImageIO.read(new File(getArg("space")));
                    for (int x = 0; x < img.getWidth(); ++x)
                    for (int y = 0; y < img.getHeight(); ++y) {
                        if ((img.getRGB(x,y) & 0xFFFFFF) != 0) {
                            spaceMap.set(new Coords(x,y), true);
                        }
                    }
                   
                    cons = new SpaceConstraints(spaceMap);
                   
View Full Code Here

       
        int x = 0, y = 0;
        for (Coords xy: coords) {
            x += xy.x; y += xy.y;
        }
        center = new Coords(x/coords.size(), y/coords.size());
    }
View Full Code Here

                Group group = groups.get(val);
                if (group == null) {
                    group = new Group(val);
                    groups.put(val, group);
                }
                group.coords.add(new Coords(x,y));
            }
        System.out.println(groups.size() + " groups");
       
        for (Group group: groups.values()) {
            for (Coords xy: group.coords) {
                for (Direction d: Direction.values()) {
                    Coords neighbor = xy.add(d.x, d.y);
                    if (group.coords.contains(neighbor)) continue;
                    Integer val = colorMap.get(neighbor.x, neighbor.y);
                    if (val != null && allowRoomsToBeAdjacent(group.id, val)) {
                        group.adjacentGroups.add(val);
                    }
View Full Code Here

        ymin = xmin = Integer.MAX_VALUE;
        ymax = xmax = Integer.MIN_VALUE;
    }
   
    public void set(int x, int y, int color) {
        Coords xy = new Coords(x,y);
        if (map.get(xy) == null) {
            xsum += x;
            ysum += y;
        }
        map.put(xy, color);
View Full Code Here

        if (y < ymin) ymin = y;
        if (y > ymax) ymax = y;
    }
   
    public Integer get(int x, int y) {
        return map.get(new Coords(x,y));
    }
View Full Code Here

    public Integer get(int x, int y) {
        return map.get(new Coords(x,y));
    }
   
    public Coords getCenter() {
        return new Coords(xsum/map.size(), ysum/map.size());
    }
View Full Code Here

        // Do a breadth first search starting at the top left to check if
        // every position is reachable.
        Set<Coords> world = new TreeSet<Coords>(map.keySet()),
                    queue = new TreeSet<Coords>();
       
        Coords first = world.iterator().next();
        world.remove(first);
        queue.add(first);
       
        while (!queue.isEmpty()) {
            Coords pos = queue.iterator().next();
            queue.remove(pos);
           
            for (Direction d: Direction.values()) {
                Coords neighbor = pos.add(d.x,d.y);
               
                if (world.contains(neighbor)) {
                    world.remove(neighbor);
                    queue.add(neighbor);
                }
View Full Code Here

        this.maxKeys = maxKeys;
        this.maxSwitches = maxSwitches;

        gridCoords = new IntMap<Coords>();
        roomIds = new CoordsMap<Integer>();
        Coords first = new Coords(0,0);
        firstRoomId = getRoomId(first);
    }
View Full Code Here

        return c.y <= 0;
    }
   
    @Override
    public List<Pair<Double,Integer>> getAdjacentRooms(int id, int keyLevel) {
        Coords xy = gridCoords.get(id);
        List<Pair<Double,Integer>> ids = new ArrayList<Pair<Double,Integer>>();
        for (Direction d: Direction.values()) {
            Coords neighbor = xy.add(d.x, d.y);
            if (validRoomCoords(neighbor)) ids.add(
                    new Pair<Double,Integer>(1.0,getRoomId(neighbor)));
        }
        return ids;
    }
View Full Code Here

TOP

Related Classes of net.bytten.metazelda.util.Coords

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.