Search in sources :

Example 36 with PointF

use of com.watabou.utils.PointF in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Chains method update.

@Override
public void update() {
    if ((spent += Game.elapsed) > duration) {
        killAndErase();
        if (callback != null) {
            callback.call();
        }
    } else {
        float dx = to.x - from.x;
        float dy = to.y - from.y;
        for (int i = 0; i < chains.length; i++) {
            chains[i].center(new PointF(from.x + ((dx * (i / (float) chains.length)) * (spent / duration)), from.y + ((dy * (i / (float) chains.length)) * (spent / duration))));
        }
    }
}
Also used : PointF(com.watabou.utils.PointF)

Example 37 with PointF

use of com.watabou.utils.PointF in project shattered-pixel-dungeon-gdx by 00-Evan.

the class CellEmitter method center.

public static Emitter center(int cell) {
    PointF p = DungeonTilemap.tileToWorld(cell);
    Emitter emitter = GameScene.emitter();
    emitter.pos(p.x + DungeonTilemap.SIZE / 2, p.y + DungeonTilemap.SIZE / 2);
    return emitter;
}
Also used : Emitter(com.watabou.noosa.particles.Emitter) PointF(com.watabou.utils.PointF)

Example 38 with PointF

use of com.watabou.utils.PointF in project shattered-pixel-dungeon-gdx by 00-Evan.

the class Builder method placeRoom.

// Attempts to place a room such that the angle between the center of the previous room
// and it matches the given angle ([0-360), where 0 is straight up) as closely as possible.
// Note that getting an exactly correct angle is harder the closer that angle is to diagonal.
// Returns the exact angle between the centerpoints of the two rooms, or -1 if placement fails.
protected static float placeRoom(ArrayList<Room> collision, Room prev, Room next, float angle) {
    // wrap angle around to always be [0-360)
    angle %= 360f;
    if (angle < 0) {
        angle += 360f;
    }
    PointF prevCenter = new PointF((prev.left + prev.right) / 2f, (prev.top + prev.bottom) / 2f);
    // calculating using y = mx+b, straight line formula
    double m = Math.tan(angle / A + Math.PI / 2.0);
    double b = prevCenter.y - m * prevCenter.x;
    // using the line equation, we find the point along the prev room where the line exists
    Point start;
    int direction;
    if (Math.abs(m) >= 1) {
        if (angle < 90 || angle > 270) {
            direction = Room.TOP;
            start = new Point((int) Math.round((prev.top - b) / m), prev.top);
        } else {
            direction = Room.BOTTOM;
            start = new Point((int) Math.round((prev.bottom - b) / m), prev.bottom);
        }
    } else {
        if (angle < 180) {
            direction = Room.RIGHT;
            start = new Point(prev.right, (int) Math.round(m * prev.right + b));
        } else {
            direction = Room.LEFT;
            start = new Point(prev.left, (int) Math.round(m * prev.left + b));
        }
    }
    // cap it to a valid connection point for most rooms
    if (direction == Room.TOP || direction == Room.BOTTOM) {
        start.x = (int) GameMath.gate(prev.left + 1, start.x, prev.right - 1);
    } else {
        start.y = (int) GameMath.gate(prev.top + 1, start.y, prev.bottom - 1);
    }
    // space checking
    Rect space = findFreeSpace(start, collision, Math.max(next.maxWidth(), next.maxHeight()));
    if (!next.setSizeWithLimit(space.width() + 1, space.height() + 1)) {
        return -1;
    }
    // find the ideal center for this new room using the line equation and known dimensions
    PointF targetCenter = new PointF();
    if (direction == Room.TOP) {
        targetCenter.y = prev.top - (next.height() - 1) / 2f;
        targetCenter.x = (float) ((targetCenter.y - b) / m);
        next.setPos(Math.round(targetCenter.x - (next.width() - 1) / 2f), prev.top - (next.height() - 1));
    } else if (direction == Room.BOTTOM) {
        targetCenter.y = prev.bottom + (next.height() - 1) / 2f;
        targetCenter.x = (float) ((targetCenter.y - b) / m);
        next.setPos(Math.round(targetCenter.x - (next.width() - 1) / 2f), prev.bottom);
    } else if (direction == Room.RIGHT) {
        targetCenter.x = prev.right + (next.width() - 1) / 2f;
        targetCenter.y = (float) (m * targetCenter.x + b);
        next.setPos(prev.right, Math.round(targetCenter.y - (next.height() - 1) / 2f));
    } else if (direction == Room.LEFT) {
        targetCenter.x = prev.left - (next.width() - 1) / 2f;
        targetCenter.y = (float) (m * targetCenter.x + b);
        next.setPos(prev.left - (next.width() - 1), Math.round(targetCenter.y - (next.height() - 1) / 2f));
    }
    // perform connection bounds and target checking, move the room if necessary
    if (direction == Room.TOP || direction == Room.BOTTOM) {
        if (next.right < prev.left + 2)
            next.shift(prev.left + 2 - next.right, 0);
        else if (next.left > prev.right - 2)
            next.shift(prev.right - 2 - next.left, 0);
        if (next.right > space.right)
            next.shift(space.right - next.right, 0);
        else if (next.left < space.left)
            next.shift(space.left - next.left, 0);
    } else {
        if (next.bottom < prev.top + 2)
            next.shift(0, prev.top + 2 - next.bottom);
        else if (next.top > prev.bottom - 2)
            next.shift(0, prev.bottom - 2 - next.top);
        if (next.bottom > space.bottom)
            next.shift(0, space.bottom - next.bottom);
        else if (next.top < space.top)
            next.shift(0, space.top - next.top);
    }
    // attempt to connect, return the result angle if successful.
    if (next.connect(prev)) {
        return angleBetweenRooms(prev, next);
    } else {
        return -1;
    }
}
Also used : Rect(com.watabou.utils.Rect) PointF(com.watabou.utils.PointF) Point(com.watabou.utils.Point) Point(com.watabou.utils.Point)

Example 39 with PointF

use of com.watabou.utils.PointF in project shattered-pixel-dungeon-gdx by 00-Evan.

the class LoopBuilder method randomBranchAngle.

@Override
protected float randomBranchAngle(Room r) {
    if (loopCenter == null)
        return super.randomBranchAngle(r);
    else {
        // generate four angles randomly and return the one which points closer to the center
        float toCenter = angleBetweenPoints(new PointF((r.left + r.right) / 2f, (r.top + r.bottom) / 2f), loopCenter);
        if (toCenter < 0)
            toCenter += 360f;
        float currAngle = Random.Float(360f);
        for (int i = 0; i < 4; i++) {
            float newAngle = Random.Float(360f);
            if (Math.abs(toCenter - newAngle) < Math.abs(toCenter - currAngle)) {
                currAngle = newAngle;
            }
        }
        return currAngle;
    }
}
Also used : PointF(com.watabou.utils.PointF)

Example 40 with PointF

use of com.watabou.utils.PointF in project shattered-pixel-dungeon-gdx by 00-Evan.

the class LoopBuilder method build.

@Override
public ArrayList<Room> build(ArrayList<Room> rooms) {
    setupRooms(rooms);
    if (entrance == null) {
        return null;
    }
    entrance.setSize();
    entrance.setPos(0, 0);
    float startAngle = Random.Float(0, 360);
    ArrayList<Room> loop = new ArrayList<>();
    int roomsOnLoop = (int) (multiConnections.size() * pathLength) + Random.chances(pathLenJitterChances);
    roomsOnLoop = Math.min(roomsOnLoop, multiConnections.size());
    roomsOnLoop++;
    float[] pathTunnels = pathTunnelChances.clone();
    for (int i = 0; i < roomsOnLoop; i++) {
        if (i == 0)
            loop.add(entrance);
        else
            loop.add(multiConnections.remove(0));
        int tunnels = Random.chances(pathTunnels);
        if (tunnels == -1) {
            pathTunnels = pathTunnelChances.clone();
            tunnels = Random.chances(pathTunnels);
        }
        pathTunnels[tunnels]--;
        for (int j = 0; j < tunnels; j++) {
            loop.add(ConnectionRoom.createRoom());
        }
    }
    if (exit != null)
        loop.add((loop.size() + 1) / 2, exit);
    Room prev = entrance;
    float targetAngle;
    for (int i = 1; i < loop.size(); i++) {
        Room r = loop.get(i);
        targetAngle = startAngle + targetAngle(i / (float) loop.size());
        if (placeRoom(rooms, prev, r, targetAngle) != -1) {
            prev = r;
            if (!rooms.contains(prev))
                rooms.add(prev);
        } else {
            // FIXME this is lazy, there are ways to do this without relying on chance
            return null;
        }
    }
    // should just write a general function for stitching two rooms together in builder
    while (!prev.connect(entrance)) {
        ConnectionRoom c = ConnectionRoom.createRoom();
        if (placeRoom(loop, prev, c, angleBetweenRooms(prev, entrance)) == -1) {
            return null;
        }
        loop.add(c);
        rooms.add(c);
        prev = c;
    }
    loopCenter = new PointF();
    for (Room r : loop) {
        loopCenter.x += (r.left + r.right) / 2f;
        loopCenter.y += (r.top + r.bottom) / 2f;
    }
    loopCenter.x /= loop.size();
    loopCenter.y /= loop.size();
    if (shop != null) {
        float angle;
        int tries = 10;
        do {
            angle = placeRoom(loop, entrance, shop, Random.Float(360f));
            tries--;
        } while (angle == -1 && tries >= 0);
        if (angle == -1)
            return null;
    }
    ArrayList<Room> branchable = new ArrayList<>(loop);
    ArrayList<Room> roomsToBranch = new ArrayList<>();
    roomsToBranch.addAll(multiConnections);
    roomsToBranch.addAll(singleConnections);
    weightRooms(branchable);
    createBranches(rooms, branchable, roomsToBranch, branchTunnelChances);
    findNeighbours(rooms);
    for (Room r : rooms) {
        for (Room n : r.neigbours) {
            if (!n.connected.containsKey(r) && Random.Float() < extraConnectionChance) {
                r.connect(n);
            }
        }
    }
    return rooms;
}
Also used : ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom) PointF(com.watabou.utils.PointF) ArrayList(java.util.ArrayList) Room(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room) ConnectionRoom(com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom)

Aggregations

PointF (com.watabou.utils.PointF)56 Emitter (com.watabou.noosa.particles.Emitter)9 ScaleTweener (com.watabou.noosa.tweeners.ScaleTweener)5 Point (com.watabou.utils.Point)5 RectF (android.graphics.RectF)3 PosTweener (com.watabou.noosa.tweeners.PosTweener)3 ArrayList (java.util.ArrayList)2 Char (com.shatteredpixel.shatteredpixeldungeon.actors.Char)1 Lightning (com.shatteredpixel.shatteredpixeldungeon.effects.Lightning)1 Heap (com.shatteredpixel.shatteredpixeldungeon.items.Heap)1 Crossbow (com.shatteredpixel.shatteredpixeldungeon.items.weapon.melee.Crossbow)1 Dart (com.shatteredpixel.shatteredpixeldungeon.items.weapon.missiles.darts.Dart)1 Room (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room)1 ConnectionRoom (com.shatteredpixel.shatteredpixeldungeon.levels.rooms.connection.ConnectionRoom)1 CharSprite (com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite)1 NoosaInputProcessor (com.watabou.input.NoosaInputProcessor)1 ColorBlock (com.watabou.noosa.ColorBlock)1 Image (com.watabou.noosa.Image)1 TextureFilm (com.watabou.noosa.TextureFilm)1 TouchArea (com.watabou.noosa.TouchArea)1