Advertisement
Guest User

Blackout problem

a guest
Jan 29th, 2014
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.20 KB | None | 0 0
  1. package com.weebly.chemicalstudios.levels;
  2.  
  3. import tk.sketchistgames.entities.Block;
  4. import tk.sketchistgames.entities.Hazard;
  5. import tk.sketchistgames.entities.Player;
  6. import tk.sketchistgames.squares.SquaresGame;
  7. import tk.sketchistgames.utils.TextWrapper;
  8.  
  9. import com.badlogic.gdx.Gdx;
  10. import com.badlogic.gdx.Input.Keys;
  11. import com.badlogic.gdx.InputProcessor;
  12. import com.badlogic.gdx.graphics.Color;
  13. import com.badlogic.gdx.graphics.FPSLogger;
  14. import com.badlogic.gdx.graphics.GL10;
  15. import com.badlogic.gdx.graphics.Texture;
  16. import com.badlogic.gdx.graphics.g2d.BitmapFont;
  17. import com.badlogic.gdx.graphics.g2d.Sprite;
  18. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  19. import com.badlogic.gdx.math.Vector2;
  20.  
  21. public class Level implements InputProcessor {
  22.  
  23.     SquaresGame game;
  24.  
  25.     //Death Counters
  26.     String levelCount;
  27.     String deathCount;
  28.     String levelDeathCount;
  29.     public static int deaths;
  30.    
  31.     //Level
  32.     static int level;
  33.    
  34.     //Textures and Text
  35.     public SpriteBatch batch = new SpriteBatch();
  36.     Texture hazardTexture[] = new Texture[20];
  37.     Sprite hazardSprite[] = new Sprite[20];
  38.  
  39.     Texture blockTexture[] = new Texture[10];
  40.     Sprite blockSprite[] = new Sprite[10];
  41.  
  42.     Texture playerTexture;
  43.     Sprite playerSprite;
  44.     protected BitmapFont font = new BitmapFont(
  45.             Gdx.files.internal("data/coolvetica.fnt"),
  46.             Gdx.files.internal("data/coolvetica.png"), false);
  47.     private TextWrapper totalDeathText = new TextWrapper(deathCount, new Vector2(150, 32));
  48.     private TextWrapper tutText  = new TextWrapper("Press Space to start!",
  49.             new Vector2(250, 432));
  50.     private TextWrapper LevelText  = new TextWrapper(levelCount + " fps: "
  51.             + Gdx.graphics.getFramesPerSecond(), new Vector2(100, 480));
  52.     private TextWrapper warning = new TextWrapper(
  53.             "And now it gets hard... good luck!", new Vector2(300, 400));
  54.     private TextWrapper paused = new TextWrapper(
  55.             "Paused. Press \"P\" to unpause.", new Vector2(450, 250));
  56.     private TextWrapper levelDeaths = new TextWrapper(levelDeathCount, new Vector2(150, 64));
  57.  
  58.    
  59.     protected Hazard[] hazard = new Hazard[0];
  60.     protected Block[] block = new Block[0];
  61.     protected Player player;
  62.  
  63.    
  64.    
  65.    
  66.  
  67.     //Background
  68.     Texture bg1t = new Texture("data/bgOne.png");
  69.     Sprite bg1s = new Sprite(bg1t);
  70.    
  71.     Color playerColor = Color.GREEN;
  72.     public static boolean started = (level == 1);
  73.    
  74.     FPSLogger fps = new FPSLogger(); // TODO Remove FPS
  75.    
  76.     public void universalRender() {
  77.        
  78.         Gdx.gl.glClearColor(0, 0, 0, 1);
  79.         Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
  80.  
  81.  
  82.         Gdx.input.setInputProcessor(this);
  83.        
  84.         playerSprite.setColor(Color.valueOf("40F73A"));
  85.        
  86.  
  87.  
  88.  
  89.         if (!SquaresGame.paused) {
  90.             deathCount = "Total Deaths: " + deaths;
  91.             levelDeathCount = " Level " + game.level + " Deaths: "
  92.                     + player.deathsThisLevel;
  93.             levelCount = "Level: " + level;
  94.             if (started)
  95.                 player.update(hazard, block);
  96.  
  97.             if (Gdx.input.isKeyPressed(Keys.SPACE)) {
  98.                 if (!started) {
  99.                     started = true;
  100.                     player.jump(player.jumpMomentum);
  101.                 }
  102.                 player.jump(player.jumpMomentum);
  103.             }
  104.         }
  105.  
  106.         /* DRAWING BATCH */
  107.         batch.begin();
  108.        
  109.         bg1s.setSize(900 * 2, 600);
  110.         bg1s.setPosition(-1 * (player.getSprite().getX() / 8),
  111.                 -(player.getSprite().getY() / 32));
  112.        
  113.         bg1s.draw(batch);
  114.        
  115.         playerSprite.draw(batch);
  116.         for (int i = 0; i < hazard.length; i++) {
  117.             hazardSprite[i].draw(batch);
  118.         }
  119.         if (blockSprite.length > 0) {
  120.             for (int i = 0; i < block.length; i++) {
  121.                 blockSprite[i].draw(batch);
  122.             }
  123.         }
  124.         totalDeathText.setText(deathCount);
  125.         totalDeathText.setPosition(new Vector2(150, 32));
  126.        
  127.        
  128.         levelDeaths.setText(levelDeathCount);
  129.         levelDeaths.setPosition(new Vector2(150, 64));
  130.        
  131.        
  132.         tutText.setText("Press Space to start!");
  133.         tutText.setPosition(new Vector2(250, 432));
  134.         LevelText.setText(levelCount + " fps: "
  135.                 + Gdx.graphics.getFramesPerSecond());
  136.         LevelText.setPosition(new Vector2(100, 480)); // TODO remove fps
  137.                                                                                
  138.  
  139.        
  140.         totalDeathText.draw(batch, font);
  141.         levelDeaths.draw(batch, font);
  142.         LevelText.draw(batch, font);
  143.         if (!started) {
  144.             tutText.draw(batch, font);
  145.             SquaresGame.makeMusic("play");
  146.         }
  147.         if (game.level == 3) {
  148.             warning.draw(batch, font);
  149.         }
  150.  
  151.         if (SquaresGame.paused) {
  152.             paused.draw(batch, font);
  153.         }
  154.  
  155.         batch.end();
  156.  
  157.     }
  158.  
  159.     @Override
  160.     public boolean keyDown(int keycode) {
  161.         if (keycode == Keys.M) {
  162.             if (SquaresGame.getMusicPlayStatus()) {
  163.                 SquaresGame.makeMusic("stop");
  164.             } else {
  165.                 SquaresGame.makeMusic("play");
  166.             }
  167.         }
  168.         if (keycode == Keys.P) {
  169.             SquaresGame.paused = !SquaresGame.paused;
  170.         }
  171.         return false;
  172.     }
  173.  
  174.     @Override
  175.     public boolean keyUp(int keycode) {
  176.         return false;
  177.     }
  178.  
  179.     @Override
  180.     public boolean keyTyped(char character) {
  181.         return false;
  182.     }
  183.  
  184.     @Override
  185.     public boolean touchDown(int screenX, int screenY, int pointer, int button) {
  186.         return false;
  187.     }
  188.  
  189.     @Override
  190.     public boolean touchUp(int screenX, int screenY, int pointer, int button) {
  191.         return false;
  192.     }
  193.  
  194.     @Override
  195.     public boolean touchDragged(int screenX, int screenY, int pointer) {
  196.         return false;
  197.     }
  198.  
  199.     @Override
  200.     public boolean mouseMoved(int screenX, int screenY) {
  201.         return false;
  202.     }
  203.  
  204.     @Override
  205.     public boolean scrolled(int amount) {
  206.         return false;
  207.     }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement