001    package components;
002    
003    import java.util.HashSet;
004    import java.util.Map;
005    import java.util.Set;
006    
007    import physics3d.Angle;
008    import physics3d.GameConstants;
009    import physics3d.Shape;
010    import physics3d.Vect3;
011    
012    /**
013     * a SquareBumper is a mutable object that represents a cube shaped bumper.
014     */
015    
016    /*
017     * Abstraction Function
018     * AF(r) = a SquareBumper, sb
019     */
020    
021    /*
022     * Representation Invariant
023     * The SquareBumper stays in within the boundaries of its GameSpace, as specified by the
024     * walls of the GameSpace
025     */
026    
027    public class SquareBumper extends GameObject {
028    
029            /**
030             * @effects creates a new SquareBumper 
031             */
032            public SquareBumper(Vect3 tlf, Vect3 ov, Angle oa, String name, GameSpace g) {
033                    super(tlf,ov,oa,name,g);
034                    this.shape = Shape.getSqBumperShape();
035                    double x = 0.5;
036                    this.center = tlf.plus(new Vect3(x, x, x));
037            }
038            
039            /**
040             * @effects creates a new SquareBumper
041             */
042            public SquareBumper(Vect3 tlf, String name, GameSpace g) {
043                    this(tlf, Vect3.Z_HAT, Angle.ZERO, name, g);
044            }
045            
046            /**
047             * @effects creates a new SquareBumper
048             */
049            public SquareBumper(Map<String, String> p, GameSpace g) {
050                    super(p, g);
051            }
052    
053            /**
054             * @return the GameObjectClassification of this object
055             */
056            public GameObjectClassification getGOClassification() {
057                    return GameObjectClassification.SQUAREBUMPER;
058            }
059    
060            @Override
061            protected Shape shape() {
062                    return Shape.getSqBumperShape();
063            }
064            
065            //See super class
066            public void getBasicPropertyMap(Map<String,String> m) {
067                    if (this.orientAngle.degrees() == -90) {
068                            m.put("orientation", "270");
069                    } else {
070                            m.put("orientation", Integer.toString((int)Math.round(this.orientAngle.degrees())));
071                    }
072                    super.getBasicPropertyMap(m);
073            }
074            
075            /**
076             * @return the top left front corners of the grid locations occupied by the bumper,
077             * where the x grid positions go from 0-20, y from 0-20, and z from 0-10
078             */
079            public Set<Vect3> getOccupiedPositions() {
080                    Set<Vect3> ops = new HashSet<Vect3>();
081                    ops.add(getTLF());
082                    return ops;
083            }
084            
085    }