Search in sources :

Example 1 with LockedDoor

use of com.agorria.shootandmove.entities.LockedDoor in project ShootAndRun by IonAgorria.

the class World method load.

/**
 * Loads level as current world
 *
 * @param level to load
 * @param clear state
 */
void load(Integer level, boolean clear) {
    // Store player relative data if any
    float playerDirection = Constants.HALF_PI;
    Vector3f playerPreviousPosition = null;
    if (clear) {
        playerPosition = null;
        walked = 0;
    }
    if (!clear && player != null) {
        playerDirection = player.getDirection();
        playerPreviousPosition = player.getPreviousPosition().sub(player.getPosition(), new Vector3f());
    }
    // Reset stuff
    cameraPosition = new Vector3f(0, 0, 0);
    cameraRotation = new Vector3f(0, 0, 0);
    batches.clear();
    entities.clear();
    entitiesNext.clear();
    collisions.clear();
    doors.clear();
    player = null;
    requestedLevel = null;
    robots = 0;
    // Use loader if none or different name
    if (level == null) {
        throw new RuntimeException("No level to load");
    }
    if (loader == null || !level.equals(loader.level)) {
        loader = new WorldLoader(level, view);
    }
    // Load the world collisions
    collisions.addAll(loader.collisions);
    // Load world entities from spawns
    entities.clear();
    for (WorldLoader.EntitySpawn spawn : loader.entities) {
        Vector3f position = new Vector3f(spawn.position);
        Vector3f size = spawn.size == null ? null : new Vector3f(spawn.size);
        switch(spawn.name) {
            case "Player":
                // Restore old player position
                if (playerPosition != null) {
                    position.add(playerPosition);
                }
                player = new Player(this, position, playerDirection);
                // Restore old previous position
                if (playerPreviousPosition != null) {
                    player.getPosition().add(playerPreviousPosition, player.getPreviousPosition());
                }
                entities.add(player);
                break;
            case "Robot":
                entities.add(new Robot(this, position, spawn.type));
                robots++;
                break;
            case "Pistol":
                entities.add(new Item(this, position, Item.ItemType.Pistol));
                break;
            case "Plasma":
                entities.add(new Item(this, position, Item.ItemType.Plasma));
                break;
            case "Missile":
                entities.add(new Item(this, position, Item.ItemType.Missile));
                break;
            case "Health":
                entities.add(new Item(this, position, Item.ItemType.Health));
                break;
            case "Door":
                Door door = new Door(this, position, size, spawn.type);
                entities.add(door);
                doors.add(door);
                break;
            case "LockedDoor":
                LockedDoor lockedDoor = new LockedDoor(this, position, size, spawn.type);
                entities.add(lockedDoor);
                doors.add(lockedDoor);
                break;
            case "Warp":
                entities.add(new Warp(this, position, spawn.type));
                break;
            default:
                throw new IllegalArgumentException("Unknown object name");
        }
    }
    // Update camera before batch
    updateCamera();
    // Create the batch, use depth as world has no transparency
    DrawableBatch batch = view.createBatch(DrawableBatch.SLOT.World, DrawableBatch.MODE.PerspectiveDepth, loader.planes, cameraPosition, cameraRotation, Color.WHITE);
    view.submitBatch(batch);
    batches.add(batch);
}
Also used : Warp(com.agorria.shootandmove.entities.Warp) Player(com.agorria.shootandmove.entities.Player) LockedDoor(com.agorria.shootandmove.entities.LockedDoor) Door(com.agorria.shootandmove.entities.Door) Item(com.agorria.shootandmove.entities.Item) Vector3f(com.agorria.shootandmove.math.Vector3f) LockedDoor(com.agorria.shootandmove.entities.LockedDoor) DrawableBatch(com.agorria.shootandmove.graphics.DrawableBatch) Robot(com.agorria.shootandmove.entities.Robot)

Aggregations

Door (com.agorria.shootandmove.entities.Door)1 Item (com.agorria.shootandmove.entities.Item)1 LockedDoor (com.agorria.shootandmove.entities.LockedDoor)1 Player (com.agorria.shootandmove.entities.Player)1 Robot (com.agorria.shootandmove.entities.Robot)1 Warp (com.agorria.shootandmove.entities.Warp)1 DrawableBatch (com.agorria.shootandmove.graphics.DrawableBatch)1 Vector3f (com.agorria.shootandmove.math.Vector3f)1