package au.com.codeka.warworlds.game.wormhole;

import org.andengine.engine.handler.IUpdateHandler;
import org.andengine.entity.Entity;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

/** An entity that represents a star. */
public class WormholeEntity extends Entity {
    private WormholeSceneManager mSceneManager;
    private AnimatedSprite mWormholeSprite;

    public WormholeEntity(WormholeSceneManager sceneManager, ITiledTextureRegion textureRegion,
                          VertexBufferObjectManager vertexBufferObjectManager) {
        super(0.0f, 0.0f, 1.0f, 1.0f);
        mSceneManager = sceneManager;

        float margin = sceneManager.getActivity().getWidth() * 0.5f;
        float size = sceneManager.getActivity().getWidth() * 0.999f;

        float x = margin;
        float y = sceneManager.getActivity().getHeight() - margin;

        mWormholeSprite = new AnimatedSprite(x, y, size, size, textureRegion, vertexBufferObjectManager);
        mWormholeSprite.animate(1000);
        attachChild(mWormholeSprite);

        mSceneManager.getActivity().getEngine().registerUpdateHandler(mWormholeUpdateHandler);
    }

    private IUpdateHandler mWormholeUpdateHandler = new IUpdateHandler() {
        @Override
        public void onUpdate(float dt) {
            float rotation = mWormholeSprite.getRotation() + 15.0f * dt;
            while (rotation > 360.0f) {
                rotation -= 360.0f;
            }
            mWormholeSprite.setRotation(rotation);
        }

        @Override
        public void reset() {
        }
    };
}

@@ -750,20 +750,25 @@
     
-float margin
+int activityWidth
  = s
@@ -807,15 +807,8 @@
 th()
- * 0.5f
 ;%0A  
@@ -817,18 +817,26 @@
     
-float size
+int activityHeight
  = s
@@ -864,23 +864,127 @@
 ty().get
-Width()
+Height();%0A        int activitySize = Math.min(activityWidth, activityHeight);%0A        float size = activitySize
  * 0.999
@@ -1005,22 +1005,36 @@
 oat x = 
-margin
+activityWidth * 0.5f
 ;%0A      
@@ -1049,55 +1049,48 @@
 y = 
-sceneManager.getA
+a
 ctivity
-().get
 Height
-()
  - 
-margin
+(activityHeight * 0.5f)
 ;%0A%0A 

Make sure the wormhole looks good in landscape view, too.