Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.59 KB | None | 0 0
  1. package com.slidefuse.MinecraftShootout;
  2.  
  3. import org.anddev.andengine.engine.Engine;
  4. import org.anddev.andengine.engine.camera.Camera;
  5. import org.anddev.andengine.engine.options.EngineOptions;
  6. import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
  7. import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
  8. import org.anddev.andengine.entity.scene.Scene;
  9. import org.anddev.andengine.entity.scene.background.ColorBackground;
  10. import org.anddev.andengine.entity.sprite.Sprite;
  11. import org.anddev.andengine.entity.util.FPSLogger;
  12. import org.anddev.andengine.opengl.texture.Texture;
  13. import org.anddev.andengine.opengl.texture.TextureOptions;
  14. import org.anddev.andengine.opengl.texture.region.TextureRegion;
  15. import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
  16. import org.anddev.andengine.ui.activity.BaseGameActivity;
  17.  
  18. public class MinecraftShootout extends BaseGameActivity {
  19.     // ===========================================================
  20.     // Constants
  21.     // ===========================================================
  22.  
  23.     private static final int CAMERA_WIDTH = 320;
  24.     private static final int CAMERA_HEIGHT = 480;
  25.  
  26.     // ===========================================================
  27.     // Fields
  28.     // ===========================================================
  29.  
  30.     private Camera mCamera;
  31.  
  32.  
  33.     // ===========================================================
  34.     // Constructors
  35.     // ===========================================================
  36.  
  37.     // ===========================================================
  38.     // Getter & Setter
  39.     // ===========================================================
  40.  
  41.     // ===========================================================
  42.     // Methods for/from SuperClass/Interfaces
  43.     // ===========================================================
  44.  
  45.     @Override
  46.     public Engine onLoadEngine() {
  47.         this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
  48.         return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
  49.     }
  50.  
  51.     @Override
  52.     public void onLoadResources() {
  53.         /*this.mTexture = new Texture(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  54.         this.mFaceTextureRegion = TextureRegionFactory.createFromAsset(this.mTexture, this, "default.png", 0, 0);
  55.        
  56.         this.backgroundText = new Texture(320, 480, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  57.         this.backgroundTextReg = TextureRegionFactory.createFromAsset(this.backgroundText, this, "background.png", 0, 0);
  58.  
  59.         this.mEngine.getTextureManager().loadTexture(this.mTexture);
  60.         this.mEngine.getTextureManager().loadTexture(this.backgroundText);*/
  61.     }
  62.  
  63.     @Override
  64.     public Scene onLoadScene() {
  65.         this.mEngine.registerUpdateHandler(new FPSLogger());
  66.  
  67.         final Scene scene = new Scene();
  68.         scene.setBackground(getBackgroundColor(255, 0, 0));
  69.  
  70.         /* Add Background */
  71.         //final Sprite background = new Sprite(0, 0, this.backgroundTextReg);
  72.        
  73.         /* Calculate the coordinates for the face, so its centered on the camera.
  74.         final int centerX = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
  75.         final int centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
  76.  
  77.         /* Create the face and add it to the scene.
  78.         final Sprite face = new Sprite(centerX, centerY, this.mFaceTextureRegion) {
  79.                 @Override
  80.                 public boolean onAreaTouched(TouchEvent e, float localX, float localY) {
  81.                     this.setPosition(e.getX() - this.getWidth()/2, e.getY() - this.getHeight()/2);
  82.                     return true;
  83.                 }
  84.         };
  85.        
  86.         //scene.attachChild(background);
  87.         scene.attachChild(face);
  88.         scene.registerTouchArea(face);*/
  89.         scene.setTouchAreaBindingEnabled(true);
  90.  
  91.         return scene;
  92.     }
  93.  
  94.     @Override
  95.     public void onLoadComplete() {
  96.  
  97.     }
  98.  
  99.     // ===========================================================
  100.     // Methods
  101.     // ===========================================================
  102.  
  103.     private ColorBackground getBackgroundColor(int r, int g, int b) {
  104.         return new ColorBackground(1.0f/r, 1.0f/g, 1.0f/b);
  105.     }
  106.    
  107.     //private void createScene()
  108.    
  109.     private void loadNewTexture(Scene scene, String texturePath, int width, int height, int x, int y) {
  110.         Texture texture = new Texture(width, height, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
  111.         TextureRegion textureReg = TextureRegionFactory.createFromAsset(texture, this, texturePath, 0, 0);
  112.        
  113.         this.mEngine.getTextureManager().loadTexture(texture);
  114.        
  115.         scene.attachChild(new Sprite(x, y, textureReg));
  116.     }
  117.    
  118.     // ===========================================================
  119.     // Inner and Anonymous Classes
  120.     // ===========================================================
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement