Advertisement
Guest User

Untitled

a guest
Jan 17th, 2013
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.11 KB | None | 0 0
  1. package com.detourgames.raw.Menu;
  2.  
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.graphics.Texture;
  5. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  6. import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
  7. import com.detourgames.raw.Camera;
  8. import com.detourgames.raw.EventQueue;
  9. import com.detourgames.raw.HUD;
  10. import com.detourgames.raw.LevelLoader;
  11.  
  12. public class MenuManager {
  13.  
  14.     private static MenuManager gameManager = new MenuManager();
  15.  
  16.     private Camera mCamera;
  17.     private MenuHUD mHUD;
  18.     // Input input;
  19.     // HUD mHUD;
  20.  
  21.     MenuLevel mLevel;
  22.  
  23.     Texture texture;
  24.     MenuLoader levelLoader;
  25.     SpriteBatch spriteBatch;
  26.     Box2DDebugRenderer debug;
  27.    
  28.     boolean levelLoaded = false;
  29.  
  30.     private MenuManager() {
  31.         // input = new Input(this);
  32.         // camera = new Camera();
  33.         // mHUD = new HUD(camera);
  34.        
  35.     }
  36.  
  37.     public static MenuManager getGameManager() { // TODO synchronized?
  38.         return gameManager;
  39.     }
  40.  
  41.     public void update(long nanoTime) {
  42.         if (levelLoaded) {
  43.             // (float)mLevel.getHero().getY());
  44.             // mHUD.update();
  45.             EventQueue.getEventQueue().processAndRemoveAllEvents();
  46.             mLevel.update(nanoTime, 8, 3);
  47.             // TODO update camera AFTER level?
  48.         }
  49.     }
  50.    
  51.     public void draw(long nanoTime) {
  52.        
  53.         if (levelLoaded) {
  54.             spriteBatch.setProjectionMatrix(mCamera.getCamera().combined);
  55.             spriteBatch.begin();
  56.             // mHUD.draw(spriteBatch);
  57.             mLevel.draw(spriteBatch, nanoTime);
  58.             //mHUD.draw(spriteBatch, nanoTime);
  59.             spriteBatch.end();
  60.            
  61.             spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
  62.             spriteBatch.begin();
  63.             spriteBatch.draw(texture, 0, 0);
  64.             spriteBatch.end();
  65.             debug.render(mLevel.getWorld(), mCamera.getCamera().combined);
  66.             //mLevel.drawDebug(mCamera);
  67.         }
  68.  
  69.     }
  70.  
  71.     public void loadMenu() {
  72.  
  73.         levelLoaded = false;
  74.  
  75.         mLevel = new MenuLevel();
  76.         spriteBatch = new SpriteBatch(1600);
  77.  
  78.         //mHeroTexture = new TextureAtlas();// new Texture(context,
  79.                                             // Animation.HERO_TEXTURE, 3, new
  80.                                             // int[]{3,1,5}, new
  81.                                             // int[]{8,8,4,0,7,16,16,16,16}, new
  82.                                             // int[]{128,1024,64}, new
  83.                                             // int[]{128,320,64});
  84.         // mHeroTexture.
  85.         if (!levelLoaded) {
  86.             levelLoader = new MenuLoader(mLevel);
  87.             //levelLoader.createLevelFromFile(level);
  88.  
  89.             // spriteBatch = new SpriteBatch(1600, SpriteBatch.SPRITE_SHADER,
  90.             // context, camera);
  91.  
  92.             levelLoaded = true;
  93.         }
  94.        
  95.         debug = new Box2DDebugRenderer(true, true, true, true, true);
  96.         texture = new Texture(Gdx.files.internal("sprite_sheet_w1_v3.png"));
  97.  
  98.         // System.gc();
  99.     }
  100.  
  101.     /*
  102.      * return mHUD; }
  103.      *
  104.      * public Input getInput(){ return input; }
  105.      *
  106.      * public Camera getCamera(){ return camera; }
  107.      */
  108.  
  109.     public MenuLevel getLevel() {
  110.         return mLevel;
  111.     }
  112.    
  113.     public void createCamera(float viewportWidth, float viewportHeight, int pixelWidth, int pixelHeight){
  114.         mCamera = new Camera(viewportWidth, viewportHeight);
  115.         mCamera.setScreenSizePixels(pixelWidth, pixelHeight);
  116.         mHUD = new MenuHUD(mCamera);
  117.     }
  118.    
  119.     public Camera getCamera(){
  120.         return mCamera;
  121.     }
  122.    
  123.     public MenuHUD getHUD(){
  124.         return mHUD;
  125.     }
  126.    
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement