Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.collzi.pong.view;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.graphics.Color;
- import com.badlogic.gdx.graphics.FPSLogger;
- import com.badlogic.gdx.graphics.GL10;
- import com.badlogic.gdx.graphics.OrthographicCamera;
- import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
- import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
- import com.badlogic.gdx.math.Rectangle;
- import com.collzi.pong.model.Ball;
- import com.collzi.pong.model.Player;
- import com.collzi.pong.model.World;
- public class WorldRenderer {
- private static final float CAMERA_WIDTH = 10f;
- private static final float CAMERA_HEIGHT = 7f;
- private World world;
- private OrthographicCamera cam;
- ShapeRenderer shapeRenderer = new ShapeRenderer();
- Rectangle playerShape = new Rectangle();
- Rectangle ballShape = new Rectangle();
- Rectangle topBounds = new Rectangle();
- Rectangle bottomBounds = new Rectangle();
- private int width, height;
- //private float ppuX, ppuY;
- private FPSLogger fpsLogger;
- public void setSize(int w, int h) {
- this.width = w;
- this.height = h;
- //ppuX = (float)width / CAMERA_WIDTH;
- //ppuY = (float)height / CAMERA_HEIGHT;
- }
- public WorldRenderer(World world) {
- this.world = world;
- this.cam = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT);
- this.cam.position.set(CAMERA_WIDTH / 2f, CAMERA_HEIGHT / 2f, 0);
- this.cam.update();
- fpsLogger = new FPSLogger();
- }
- public void render() {
- Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
- Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
- drawBall();
- drawPlayer();
- drawBot();
- drawWorld();
- fpsLogger.log();
- }
- private void drawWorld() {
- topBounds = world.getTopBounds();
- bottomBounds = world.getBottomBounds();
- shapeRenderer.begin(ShapeType.Filled);
- shapeRenderer.setColor(new Color(1, 1, 1, 1));
- shapeRenderer.rect(topBounds.x, topBounds.y, topBounds.width, topBounds.height);
- shapeRenderer.rect(bottomBounds.x, bottomBounds.y, bottomBounds.width, bottomBounds.height);
- shapeRenderer.end();
- }
- private void drawPlayer() {
- Player player = world.getPlayer();
- playerShape = player.getBounds();
- shapeRenderer.begin(ShapeType.Filled);
- shapeRenderer.setColor(new Color(1, 1, 1, 1));
- shapeRenderer.rect(playerShape.x, playerShape.y, playerShape.width, playerShape.height);
- shapeRenderer.end();
- }
- private void drawBot() {
- Player bot = world.getBot();
- playerShape = bot.getBounds();
- shapeRenderer.begin(ShapeType.Filled);
- shapeRenderer.setColor(new Color(1, 1, 1, 1));
- shapeRenderer.rect(playerShape.x, playerShape.y, playerShape.width, playerShape.height);
- shapeRenderer.end();
- }
- private void drawBall() {
- Ball ball = world.getBall();
- ballShape = ball.getBounds();
- shapeRenderer.begin(ShapeType.Filled);
- shapeRenderer.setColor(new Color(1, 1, 1, 1));
- shapeRenderer.rect(ballShape.x, ballShape.y, ballShape.width, ballShape.height);
- shapeRenderer.end();
- }
- public void dispose() {
- shapeRenderer.dispose();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement