Exemplo n.º 1
0
 /**
  * This method will do the actual removing and adding of GameObjects at the end of a gameloop
  * pass.
  */
 private void cleanupObjectlists() {
   Iterator<GameObject> it = items.iterator();
   while (it.hasNext()) {
     GameObject go = it.next();
     if (!go.isActive()) {
       deleteObjectAlarms(go);
       it.remove();
     }
   }
   for (int i = 0; i < newItems.size(); i++) {
     // note: always moving the first element of newItems ensures same
     // order
     GameObject item = newItems.remove(0);
     if (item.getDepth() > 0) {
       float d = item.getDepth();
       // move index to position of first element having smaller depth
       int index = 0;
       while (index < items.size()) {
         if (items.get(index).getDepth() < d) {
           break;
         }
         index++;
       }
       items.add(index, item);
     } else {
       // just add to the back of the list
       items.add(item);
     }
   }
 }
Exemplo n.º 2
0
 /** Calculates if a GameObject is outside the world or not. */
 private void calculateOutsideWorld(GameObject go) {
   if (go instanceof MoveableGameObject) {
     if (!go.isActive()) {
       return;
     }
     if (go.getX() - go.getFrameWidth() < 0
         || go.getX() > mapWidth
         || go.getY() - go.getFrameHeight() < 0
         || go.getY() > mapHeight) {
       ((MoveableGameObject) go).outsideWorld();
     }
   }
 }