Android Open Source - Station42 Room






From Project

Back to project page Station42.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUC...

If you think the Android project Station42 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.station42.world;
/*from w w w  . j av a2 s . c o  m*/
import java.util.ArrayList;

import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.station42.base.Engine;
import com.station42.base.Entity;
import com.station42.optimizations.RoomResident;

public class Room {
  public static final int ROOM_SIZE = 256;
  public static Entity spawn(Engine engine, Rectangle bounds, 
      boolean up, boolean right, boolean down, boolean left, Object... otherComponents) {
    Room room = new Room(bounds, up, right, down, left);
    Entity roomEntity = new Entity("Room", otherComponents);
    roomEntity.setComponent(Room.class, room);
    engine.spawnEntity(roomEntity);
    for (Entity wall : room.walls) {
      for (Object component : otherComponents) {
        wall.setComponent(component.getClass(), component);
      }
      engine.spawnEntity(wall);
    }
    return roomEntity;
  }
  public Rectangle bounds;
  ArrayList<Entity> walls = new ArrayList<Entity>();
  public ArrayList<Entity> residents = new ArrayList<Entity>();
  public void clearResidents() {
    for (int i = residents.size() - 1;i >= 0;i--) {
      removeResident(residents.get(i));
    }
  }
  public void addResident(Entity resident) {
    residents.add(resident);
    RoomResident residential = resident.getComponent(RoomResident.class);
    if (residential != null) {
      residential.addRoom(this);
    }
  }
  public void removeResident(Entity resident) {
    residents.remove(resident);
    RoomResident residential = resident.getComponent(RoomResident.class);
    if (residential != null) {
      residential.removeRoom(this);
    }
  }
  public Room(Rectangle bounds, boolean upClosed, boolean rightClosed, boolean bottomClosed, boolean leftClosed) {
    this.bounds = bounds;
    addWall(bounds, 
        0, upClosed);
    addWall(bounds, 
        1, rightClosed);
    addWall(bounds, 
        2, bottomClosed);
    addWall(bounds, 
        3, leftClosed);
  }
  private void addWall(Rectangle bounds, int direction, boolean closed) {
    int minX = (int)bounds.x;
    int minY = (int)bounds.y;
    int maxX = (int)(bounds.x + bounds.width);
    int maxY = (int)(bounds.y + bounds.height);
    int xMod, yMod;
    int x0, x1, y0, y1;
    Vector2 in;
    switch (direction) {
    case 0: // Top wall
      x0 = minX;
      x1 = maxX;
      y0 = maxY;
      y1 = maxY;
      xMod = 64;
      yMod = 0;
      in = new Vector2(0, -1);
      break;
    case 1: // Right wall
      x0 = maxX;
      x1 = maxX;
      y0 = maxY;
      y1 = minY;
      xMod = 0;
      yMod = -64;
      in = new Vector2(-1, 0);
      break;
    case 2: // Bottom wall
      x1 = minX;
      x0 = maxX;
      y0 = minY;
      y1 = minY;
      xMod = -64;
      yMod = 0;
      in = new Vector2(0, 1);
      break;
    case 3: // Left wall
      x0 = minX;
      x1 = minX;
      y0 = minY;
      y1 = maxY;
      xMod = 0;
      yMod = 64;
      in = new Vector2(1, 0);
      break;
    default:
      throw new RuntimeException("BAD VALUE");
    }
    if (closed) {
      walls.add(new Entity("Room wall", new Wall(this, new Vector2(x0, y0), 
          new Vector2(x1, y1),
          in)));
    } else {
      walls.add(new Entity("Room wall", new Wall(this, new Vector2(x0, y0), 
          new Vector2((x0 + x1) / 2 - xMod, (y0 + y1) / 2 - yMod),
          in)));
      walls.add(new Entity("Room wall", new Wall(this, new Vector2((x0 + x1) / 2 + xMod, (y0 + y1) / 2 + yMod),
          new Vector2(x1, y1),
          in)));
    }
  }
  public ArrayList<Entity> getWalls() {
    return walls;
  }
  public int getCenterX() {
    return (int) (bounds.x + bounds.width / 2);
  }
  public int getCenterY() {
    return (int) (bounds.y + bounds.height / 2);
  }
}




Java Source Code List

com.station40.game.IOSLauncher.java
com.station40.game.android.AndroidLauncher.java
com.station40.game.android.OuyaMenuScreen.java
com.station40.game.android.OuyaPlayerJoiner.java
com.station40.game.client.HtmlLauncher.java
com.station40.game.desktop.DesktopLauncher.java
com.station42.base.EngineMessageListener.java
com.station42.base.EngineRenderer.java
com.station42.base.EngineUpdateListener.java
com.station42.base.Engine.java
com.station42.base.Entity.java
com.station42.basic.EntityFacing.java
com.station42.basic.EntityLocation.java
com.station42.basic.EntityRenderer.java
com.station42.basic.EntitySprite.java
com.station42.bullet.BulletCollisionSystem.java
com.station42.bullet.BulletRenderer.java
com.station42.bullet.BulletSpawner.java
com.station42.bullet.BulletUpdateSystem.java
com.station42.bullet.Bullet.java
com.station42.death.BulletDamageMessage.java
com.station42.death.BulletDamageSystem.java
com.station42.death.DeathMessage.java
com.station42.death.HealthRenderer.java
com.station42.death.Health.java
com.station42.death.PlayerRespawnSystem.java
com.station42.death.SpawnRoom.java
com.station42.faction.EntityFaction.java
com.station42.game.GameScreen.java
com.station42.game.Levels.java
com.station42.game.MainMenuScreen.java
com.station42.game.MatchSystem.java
com.station42.game.ScoringPortalHackingSystem.java
com.station42.game.ScoringPortalRenderer.java
com.station42.game.ScoringPortal.java
com.station42.game.Station40Game.java
com.station42.hacking.Hackable.java
com.station42.hacking.HackingActionParticles.java
com.station42.hacking.HackingActionRenderer.java
com.station42.hacking.HackingActionUpdater.java
com.station42.hacking.HackingAction.java
com.station42.hacking.HackingSystem.java
com.station42.hacking.HackingUI.java
com.station42.hacking.PlayerHacker.java
com.station42.hopping.HoppingAction.java
com.station42.hopping.HoppingSystem.java
com.station42.hopping.HoppingUI.java
com.station42.hopping.OffensiveHackingSystem.java
com.station42.hopping.PlayerHopper.java
com.station42.input.MouseAndKeyboardController.java
com.station42.loot.HealthBoost.java
com.station42.loot.LootDropSystem.java
com.station42.loot.LootDrop.java
com.station42.loot.LootPickupSystem.java
com.station42.loot.Loot.java
com.station42.loot.Looter.java
com.station42.loot.PointBoost.java
com.station42.loot.SpeedBoost.java
com.station42.loot.WorldSwap.java
com.station42.optimizations.CroppingHelper.java
com.station42.optimizations.RoomResidentSystem.java
com.station42.optimizations.RoomResident.java
com.station42.player.PlayerTrackingCameraSystem.java
com.station42.player.mouse.EntityMouseState.java
com.station42.player.mouse.PlayerActionStateSetter.java
com.station42.player.mouse.PlayerClientGunSystem.java
com.station42.player.mouse.PlayerControllerMouseStateSetter.java
com.station42.player.mouse.PlayerGunSystem.java
com.station42.player.mouse.PlayerMouseStateSetter.java
com.station42.player.move.EntityMoveState.java
com.station42.player.move.PlayerControllerMoveStateSetter.java
com.station42.player.move.PlayerMoveStateSetter.java
com.station42.player.move.PlayerWalker.java
com.station42.sentries.FactionSentrySystem.java
com.station42.sentries.SentryHackingSystem.java
com.station42.sentries.SentrySpawner.java
com.station42.sentries.Sentry.java
com.station42.server.BulletRequest.java
com.station42.server.ProtocolSetup.java
com.station42.server.Station40Client.java
com.station42.server.Station40Server.java
com.station42.server.serializers.EntitySerializer.java
com.station42.world.RoomRenderer.java
com.station42.world.Room.java
com.station42.world.WallCollisionSystem.java
com.station42.world.WallRenderer.java
com.station42.world.Wall.java
com.station42.world.WorldUI.java
com.station42.world.World.java