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