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