public void testDetach() { EntityManager em = getOrCreateEntityManager(); em.getTransaction().begin(); Tooth tooth = new Tooth(); Mouth mouth = new Mouth(); em.persist(mouth); em.persist(tooth); tooth.mouth = mouth; mouth.teeth = new ArrayList<Tooth>(); mouth.teeth.add(tooth); em.getTransaction().commit(); em.close(); em = getOrCreateEntityManager(); em.getTransaction().begin(); mouth = em.find(Mouth.class, mouth.id); assertNotNull(mouth); assertEquals(1, mouth.teeth.size()); tooth = mouth.teeth.iterator().next(); em.detach(mouth); assertFalse(em.contains(tooth)); em.getTransaction().commit(); em.close(); em = getOrCreateEntityManager(); em.getTransaction().begin(); em.remove(em.find(Mouth.class, mouth.id)); em.getTransaction().commit(); em.close(); }
public void update() { if (getJustDied()) { // for loop to give out lots of food and to take away a body part FoodEntityLevel1 entity = new FoodEntityLevel1( getXFromCenterToRear(TAIL_DISTANCE * 5), getYFromCenterToRear(TAIL_DISTANCE * 5)); NonHostileAIController controller = new NonHostileAIController(entity); entity.setController(controller); entity.setWorld(getWorld()); getWorld().addEntity(entity); setJustDied(false); } if (!checkDead()) { super.update(); Entity inFront = this; Entity temp; for (int i = 0; i < getBodyParts().size(); i++) { temp = getBodyParts().get(i); temp.setTarget(inFront.getRearX(), inFront.getRearY()); temp.setAngle(temp.getTargetAngle()); temp.setMaxVelocity(inFront.getMaxVelocity()); temp.setVelocity(inFront.getVelocity()); if (inFront.getDistance(temp) >= FAT_DISTANCE) temp.update(); inFront = temp; } } else if (getController().getType() == Controller.PLAYER) { setJustDied(true); setDead(false); addValue(50); LevelChangerEntity entity = new LevelChangerEntity(getX(), getY()); entity.setValue(-1); entity.setDead(true); entity.setWorld(getWorld()); getWorld().addEntity(entity); } if (digesting) { currTime = timer.milliTime(); accumulator += currTime - prevTime; prevTime = currTime; if (digesting && (accumulator > TIME_TO_DIGEST)) { digesting = false; mouth.setClosed(false); timer.reset(); accumulator = 0; getWorld().checkCollisions(this); } } else getWorld().checkCollisions(this); if (enlargedMouth) { if (mouthTimer.milliTime() > MOUTH_TIME) shrinkMouth(); } mouth.update(); }
public void collision(Entity entity) { if (entity.getType() == LEVEL_CHANGER && getController() instanceof PlayerController) { getWorld().changeLevel(entity.getValue()); digesting = true; mouth.setClosed(true); timer.start(); prevTime = timer.milliTime(); } for (int x = 0; x < getBodyParts().size(); x++) if (entity == getBodyParts().get(x)) return; if (entity.getType() == FAT) { addValue(entity.removeValue()); setValue(getValue()); digesting = true; mouth.setClosed(true); timer.start(); prevTime = timer.milliTime(); } else if (entity.getType() == FOOD) { addValue(entity.removeValue()); setValue(getValue()); digesting = true; mouth.setClosed(true); timer.start(); prevTime = timer.milliTime(); } else if (entity.getType() == EVOLVER) { if (entity.getValue() == EvolverEntity.EVOLVER_VAL) evolve(); else if (entity.getValue() == EvolverEntity.MOUTH_VAL) enlargeMouth(); } }
/** Enlarges the Eel's mouth. */ public void enlargeMouth() { if (enlargedMouth) return; mouthTimer.reset(); mouthTimer.start(); mouth.setMaxWidth(MOUTH_WIDTH * 2); mouth.setHeight(MOUTH_HEIGHT * 2); mouth.setClosed(false); this.setRadius(getRadius() * 2); enlargedMouth = true; }
public void render(Renderer renderer) { Stroke stroke = new BasicStroke(2); renderer.setStroke(stroke); renderer.rotate(getX(), getY(), -getAngle()); renderer.drawCircle(getX(), getY(), NECK_RADIUS, getColor()); mouth.render( renderer, getX(), getY() + PIXEL_BUFFER + NECK_RADIUS + MOUTH_HEIGHT / 2, getColor()); // renderer.drawArc(getX(), getY() + PIXEL_BUFFER + NECK_RADIUS // + MOUTH_HEIGHT / 2, MOUTH_WIDTH, MOUTH_HEIGHT, 0, 90, // getColor()); // // renderer.drawArc(getX(), getY() + PIXEL_BUFFER + NECK_RADIUS // + MOUTH_HEIGHT / 2, MOUTH_WIDTH, MOUTH_HEIGHT, 180, -90, // getColor()); renderer.rotate(getX(), getY(), getAngle()); renderer.rotate( getXFromCenterToRear(NECK_RADIUS + TAIL_DISTANCE), getYFromCenterToRear(NECK_RADIUS + TAIL_DISTANCE), -getAngle()); renderer.fillRect( getXFromCenterToRear(NECK_RADIUS + TAIL_DISTANCE), getYFromCenterToRear(NECK_RADIUS + TAIL_DISTANCE), TAIL_RADIUS * 2, TAIL_RADIUS * 2, getColor()); renderer.rotate( getXFromCenterToRear(NECK_RADIUS + TAIL_DISTANCE), getYFromCenterToRear(NECK_RADIUS + TAIL_DISTANCE), getAngle()); for (int x = 0; x < getBodyParts().size(); x++) getBodyParts().get(x).render(renderer); }
/** Shrinks the Eel's mouth. */ public void shrinkMouth() { mouth.setMaxWidth(MOUTH_WIDTH); mouth.setHeight(MOUTH_HEIGHT); this.setRadius(getRadius() / 2); enlargedMouth = false; }