Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.weebly.chemicalstudios.levels;
- import tk.sketchistgames.entities.Block;
- import tk.sketchistgames.entities.Hazard;
- import tk.sketchistgames.entities.Player;
- import tk.sketchistgames.squares.SquaresGame;
- import tk.sketchistgames.utils.TextWrapper;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Input.Keys;
- import com.badlogic.gdx.InputProcessor;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.FPSLogger;
- import com.badlogic.gdx.graphics.GL10;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.g2d.BitmapFont;
- import com.badlogic.gdx.graphics.g2d.Sprite;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.math.Vector2;
- public class Level implements InputProcessor {
- SquaresGame game;
- //Death Counters
- String levelCount;
- String deathCount;
- String levelDeathCount;
- public static int deaths;
- //Level
- static int level;
- //Textures and Text
- public SpriteBatch batch = new SpriteBatch();
- Texture hazardTexture[] = new Texture[20];
- Sprite hazardSprite[] = new Sprite[20];
- Texture blockTexture[] = new Texture[10];
- Sprite blockSprite[] = new Sprite[10];
- Texture playerTexture;
- Sprite playerSprite;
- protected BitmapFont font = new BitmapFont(
- Gdx.files.internal("data/coolvetica.fnt"),
- Gdx.files.internal("data/coolvetica.png"), false);
- private TextWrapper totalDeathText = new TextWrapper(deathCount, new Vector2(150, 32));
- private TextWrapper tutText = new TextWrapper("Press Space to start!",
- new Vector2(250, 432));
- private TextWrapper LevelText = new TextWrapper(levelCount + " fps: "
- + Gdx.graphics.getFramesPerSecond(), new Vector2(100, 480));
- private TextWrapper warning = new TextWrapper(
- "And now it gets hard... good luck!", new Vector2(300, 400));
- private TextWrapper paused = new TextWrapper(
- "Paused. Press \"P\" to unpause.", new Vector2(450, 250));
- private TextWrapper levelDeaths = new TextWrapper(levelDeathCount, new Vector2(150, 64));
- protected Hazard[] hazard = new Hazard[0];
- protected Block[] block = new Block[0];
- protected Player player;
- //Background
- Texture bg1t = new Texture("data/bgOne.png");
- Sprite bg1s = new Sprite(bg1t);
- Color playerColor = Color.GREEN;
- public static boolean started = (level == 1);
- FPSLogger fps = new FPSLogger(); // TODO Remove FPS
- public void universalRender() {
- Gdx.gl.glClearColor(0, 0, 0, 1);
- Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
- Gdx.input.setInputProcessor(this);
- playerSprite.setColor(Color.valueOf("40F73A"));
- if (!SquaresGame.paused) {
- deathCount = "Total Deaths: " + deaths;
- levelDeathCount = " Level " + game.level + " Deaths: "
- + player.deathsThisLevel;
- levelCount = "Level: " + level;
- if (started)
- player.update(hazard, block);
- if (Gdx.input.isKeyPressed(Keys.SPACE)) {
- if (!started) {
- started = true;
- player.jump(player.jumpMomentum);
- }
- player.jump(player.jumpMomentum);
- }
- }
- /* DRAWING BATCH */
- batch.begin();
- bg1s.setSize(900 * 2, 600);
- bg1s.setPosition(-1 * (player.getSprite().getX() / 8),
- -(player.getSprite().getY() / 32));
- bg1s.draw(batch);
- playerSprite.draw(batch);
- for (int i = 0; i < hazard.length; i++) {
- hazardSprite[i].draw(batch);
- }
- if (blockSprite.length > 0) {
- for (int i = 0; i < block.length; i++) {
- blockSprite[i].draw(batch);
- }
- }
- totalDeathText.setText(deathCount);
- totalDeathText.setPosition(new Vector2(150, 32));
- levelDeaths.setText(levelDeathCount);
- levelDeaths.setPosition(new Vector2(150, 64));
- tutText.setText("Press Space to start!");
- tutText.setPosition(new Vector2(250, 432));
- LevelText.setText(levelCount + " fps: "
- + Gdx.graphics.getFramesPerSecond());
- LevelText.setPosition(new Vector2(100, 480)); // TODO remove fps
- totalDeathText.draw(batch, font);
- levelDeaths.draw(batch, font);
- LevelText.draw(batch, font);
- if (!started) {
- tutText.draw(batch, font);
- SquaresGame.makeMusic("play");
- }
- if (game.level == 3) {
- warning.draw(batch, font);
- }
- if (SquaresGame.paused) {
- paused.draw(batch, font);
- }
- batch.end();
- }
- @Override
- public boolean keyDown(int keycode) {
- if (keycode == Keys.M) {
- if (SquaresGame.getMusicPlayStatus()) {
- SquaresGame.makeMusic("stop");
- } else {
- SquaresGame.makeMusic("play");
- }
- }
- if (keycode == Keys.P) {
- SquaresGame.paused = !SquaresGame.paused;
- }
- return false;
- }
- @Override
- public boolean keyUp(int keycode) {
- return false;
- }
- @Override
- public boolean keyTyped(char character) {
- return false;
- }
- @Override
- public boolean touchDown(int screenX, int screenY, int pointer, int button) {
- return false;
- }
- @Override
- public boolean touchUp(int screenX, int screenY, int pointer, int button) {
- return false;
- }
- @Override
- public boolean touchDragged(int screenX, int screenY, int pointer) {
- return false;
- }
- @Override
- public boolean mouseMoved(int screenX, int screenY) {
- return false;
- }
- @Override
- public boolean scrolled(int amount) {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement