001 /**
002 *
003 */
004 package components;
005
006 import java.util.HashMap;
007 import java.util.HashSet;
008 import java.util.Map;
009 import java.util.Set;
010
011 import physics3d.Angle;
012 import physics3d.Shape;
013 import physics3d.Vect3;
014
015 /**
016 * <p>
017 * Wall is a mutable object that specifies the outside boundaries of a GameSpace.
018 * Wall extends GameObject
019 * <br>
020 * Walls are inserted by the GameSpace itself, and are created in no other way.
021 * </p>
022 * @specfield length : int
023 * @specfield width : int
024 */
025
026 /*
027 * Abstraction Function
028 * AF(r) = a Wall, w, such that
029 * w.length = r.length
030 * w.width = r.width
031 */
032
033 /*
034 * Rep Invariant
035 * length, width > 0
036 */
037
038 public class Wall extends GameObject {
039
040 //fields
041 int length; //length in L
042 int width; //width in L
043
044 /**
045 * @param tlf - the top left corner of the wall
046 * @param ov - the normal vector to the wall
047 * @param oa - tilt around ov
048 * @param name - a name
049 * @param g - the gamespace this wall is for
050 * @effects creates a new Wall
051 */
052 public Wall(Vect3 tlf, int length, int width, Vect3 ov, Angle oa, boolean visible, String name, GameSpace g) {
053 super(tlf, ov, oa, name, g);
054
055 this.length = length;
056 this.width = width;
057 shape = Shape.getWallShape(length, width);
058 this.visible = visible;
059 this.frozen = true;
060 this.center = tlf.plus(new Vect3(width/2.0, length/2.0, 0) );
061 this.coRef = 1.0;
062 }
063
064 public Wall(Map<String, String> props, GameSpace g) {
065 super (props, g);
066 }
067
068 @Override
069 public Vect3 getDiff() {
070 return new Vect3(width/2.0, height/2.0, 0);
071 }
072
073 /**
074 * @return the GameObjectClassification of this object
075 */
076 public GameObjectClassification getGOClassification() {
077 return GameObjectClassification.WALL;
078 }
079
080 @Override
081 protected Shape shape() {
082 return Shape.getWallShape(length, width);
083 }
084
085 @Override
086 protected Map<String, String> defaults() {
087 Map<String, String> smap = super.defaults();
088 smap.put("visible", "false");
089 return smap;
090 }
091
092 /**
093 * @return a vect3 not in the GameSpace
094 */
095 public Set<Vect3> getOccupiedPositions() {
096 Set<Vect3> ops = new HashSet<Vect3>();
097 ops.add(new Vect3(-1, -1, -1)); //returns a spot not in the GameSpace
098 return ops;
099 }
100 }