Advertisement
wreed12345

Untitled

Jun 10th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.49 KB | None | 0 0
  1. package com.reed.birdseye;
  2.  
  3. import box2dLight.RayHandler;
  4.  
  5. import com.badlogic.gdx.Application.ApplicationType;
  6. import com.badlogic.gdx.Game;
  7. import com.badlogic.gdx.Gdx;
  8. import com.badlogic.gdx.Input;
  9. import com.badlogic.gdx.Screen;
  10. import com.badlogic.gdx.graphics.GL20;
  11. import com.badlogic.gdx.graphics.OrthographicCamera;
  12. import com.badlogic.gdx.graphics.g2d.BitmapFont;
  13. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  14. import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
  15. import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
  16. import com.badlogic.gdx.math.Vector2;
  17. import com.badlogic.gdx.physics.box2d.World;
  18.  
  19. public class GameScreen implements Screen {
  20.     Game game;
  21.     // static for getting / setting position
  22.     static OrthographicCamera camera;
  23.     OrthographicCamera mapCamera;
  24.     OrthogonalTiledMapRenderer mapRenderer;
  25.     SpriteBatch batch;
  26.     ShapeRenderer shapeRenderer;
  27.     BitmapFont currentFont;
  28.     Farm farm;
  29.     Level level;
  30.     Player player;
  31.     // TEMP use arrayList for random or static assigned rocks
  32.     Resource resource;
  33.     ArrayListsz arrays;
  34.     // Crafting craft = new Crafting();
  35.     TopMenu topMenu;
  36.     Iron iron;
  37.     Inventory inv;
  38.     Copper copper;
  39.     CollisionDetection collision;
  40.     Android android;
  41.     Points points;
  42.     Messages message;
  43.     SwordShop swordShop;
  44.     Fishing fishing;
  45.     TradeShop trade;
  46.     World world;
  47.     RayHandler rayHandler;
  48.  
  49.     public GameScreen(Game game) {
  50.         this.game = game;
  51.         float w = Gdx.graphics.getWidth();
  52.         float h = Gdx.graphics.getHeight();
  53.  
  54.         camera = new OrthographicCamera(w, h);
  55.         mapCamera = new OrthographicCamera(w, h);
  56.         camera.update();
  57.         mapCamera.update();
  58.  
  59.         batch = new SpriteBatch();
  60.         mapRenderer = new OrthogonalTiledMapRenderer(Assets.mainTiledMap);
  61.  
  62.         shapeRenderer = new ShapeRenderer();
  63.         level = new Level();
  64.         player = new Player();
  65.         resource = new Resource();
  66.         arrays = new ArrayListsz();
  67.         topMenu = new TopMenu();
  68.         iron = new Iron();
  69.         inv = new Inventory();
  70.         // collision detection problem?
  71.         android = new Android();
  72.         points = new Points();
  73.         collision = new CollisionDetection();
  74.  
  75.         message = new Messages();
  76.         swordShop = new SwordShop();
  77.         fishing = new Fishing();
  78.         trade = new TradeShop();
  79.         arrays.treeArrayEstablisher();
  80.  
  81.         if (Gdx.app.getType() == ApplicationType.Android) {
  82.             currentFont = Assets.cgfFont;
  83.         } else
  84.             currentFont = new BitmapFont();
  85.  
  86.         world = new World(new Vector2(0, 0), true);
  87.  
  88.         rayHandler = new RayHandler(world);
  89.         Time.createLights(rayHandler);
  90.  
  91.         /*
  92.          * int[] maxTextureSize = new int[1]; IntBuffer buf =
  93.          * BufferUtils.newIntBuffer(16);
  94.          * Gdx.gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, buf); int result =
  95.          * buf.get(); System.out.println(result); int result2 = buf.get();
  96.          * System.out.println(result);
  97.          */
  98.     }
  99.  
  100.     int lightX = 400, lightY = 400;
  101.  
  102.     final int offsetX = -958;
  103.     final int offsetY = -3316;
  104.  
  105.     public void update(float deltaTime) {
  106.         // can be changed anytime in time class
  107.         player.setSprites();
  108.         player.move();
  109.         player.input();
  110.         topMenu.input();
  111.         inv.input();
  112.         points.updateLevel();
  113.         level.update();
  114.         Messages.update();
  115.         message.removeOldMessages();
  116.         swordShop.textSetter();
  117.         swordShop.update();
  118.         swordShop.handleInput();
  119.         collision.doCollision();
  120.         inv.input();
  121.         fishing.update();
  122.         fishing.fishCaught();
  123.         trade.textSetter();
  124.         trade.update();
  125.         trade.handleInput();
  126.         // fps.log();
  127.         Time.update(rayHandler);
  128.  
  129.         mapCamera.position.x = camera.position.x + offsetX;
  130.         mapCamera.position.y = camera.position.y + offsetY;
  131.  
  132.     }
  133.  
  134.     public static float xRate = 0;
  135.     public static float yRate = 0;
  136.  
  137.     public void draw(float deltaTime) {
  138.         Gdx.gl.glClearColor(255f, 255f, 255f, 1);
  139.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  140.  
  141.         camera.translate(xRate, yRate);
  142.         camera.update();
  143.         mapCamera.update();
  144.         mapRenderer.setView(mapCamera);
  145.        
  146.         batch.begin();
  147.         // sets camera for drawing static items
  148.         batch.setProjectionMatrix(camera.projection.cpy().translate(
  149.                 -(Gdx.graphics.getWidth() / 2),
  150.                 -(Gdx.graphics.getHeight() / 2), 0));
  151.  
  152.         level.draw(batch);
  153.        
  154.         // set camera for drawing moving items.
  155.         batch.setProjectionMatrix(camera.combined);
  156.         mapRenderer.render();
  157.         swordShop.draw(batch);
  158.         trade.draw(batch);
  159.         arrays.drawTreeTrunk(batch);
  160.  
  161.         player.draw(batch, currentFont);
  162.         arrays.drawBrush(batch, currentFont);
  163.  
  164.         batch.end();
  165.         rayHandler.setCombinedMatrix(camera.combined);
  166.         rayHandler.updateAndRender();
  167.         batch.begin();
  168.  
  169.         // more static items
  170.         batch.setProjectionMatrix(camera.projection.cpy().translate(
  171.                 -(Gdx.graphics.getWidth() / 2),
  172.                 -(Gdx.graphics.getHeight() / 2), 0));
  173.         player.drawTools(batch);
  174.         topMenu.draw(batch, currentFont);
  175.         player.drawTools(batch);
  176.         points.draw(batch);
  177.         message.drawText(currentFont, batch);
  178.         inv.draw(batch, currentFont);
  179.         swordShop.drawInputText(batch, currentFont);
  180.         trade.drawInputText(batch, currentFont);
  181.  
  182.         batch.end();
  183.  
  184.         points.drawBars(shapeRenderer);
  185.  
  186.     }
  187.  
  188.     @Override
  189.     public void render(float delta) {
  190.         update(delta);
  191.         draw(delta);
  192.         handleInput();
  193.     }
  194.  
  195.     private void handleInput() {
  196.         if (Gdx.input.isKeyPressed(Input.Keys.O)) {
  197.             camera.zoom += 0.02;
  198.         }
  199.         if (Gdx.input.isKeyPressed(Input.Keys.I)) {
  200.             camera.zoom -= 0.02;
  201.         }
  202.     }
  203.  
  204.     @Override
  205.     public void resize(int width, int height) {
  206.     }
  207.  
  208.     @Override
  209.     public void show() {
  210.     }
  211.  
  212.     @Override
  213.     public void hide() {
  214.     }
  215.  
  216.     @Override
  217.     public void pause() {
  218.     }
  219.  
  220.     @Override
  221.     public void resume() {
  222.     }
  223.  
  224.     @Override
  225.     public void dispose() {
  226.     }
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement