- package com.dungeon.architect.screens;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Screen;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.OrthographicCamera;
- import com.badlogic.gdx.graphics.g2d.TextureAtlas;
- import com.badlogic.gdx.maps.MapObject;
- import com.badlogic.gdx.maps.objects.RectangleMapObject;
- import com.badlogic.gdx.maps.tiled.TiledMap;
- import com.badlogic.gdx.maps.tiled.TmxMapLoader;
- import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
- import com.badlogic.gdx.math.Rectangle;
- import com.badlogic.gdx.math.Vector2;
- import com.badlogic.gdx.physics.box2d.Body;
- import com.badlogic.gdx.physics.box2d.BodyDef;
- import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
- import com.badlogic.gdx.physics.box2d.FixtureDef;
- import com.badlogic.gdx.physics.box2d.PolygonShape;
- import com.badlogic.gdx.physics.box2d.World;
- import com.badlogic.gdx.utils.viewport.FitViewport;
- import com.badlogic.gdx.utils.viewport.Viewport;
- import com.dungeon.architect.GameBase;
- import com.dungeon.architect.engine.Physics;
- import com.dungeon.architect.entities.Hero;
- import com.dungeon.architect.scenes.HUD;
- /**
- * Created by Adam on 25/10/2015.
- */
- public class GameScreen implements Screen{
- //base game variables
- private GameBase game;
- private OrthographicCamera gamecam;
- private Viewport viewport;
- private HUD hud;
- private Hero player;
- //map variables
- private TmxMapLoader maploader;
- private TiledMap map;
- private OrthogonalTiledMapRenderer renderer;
- //box2d physics
- private World world;
- private Box2DDebugRenderer b2dr;
- //sprites
- private TextureAtlas atlas;
- public GameScreen(GameBase game)
- {
- atlas = new TextureAtlas("atlases/test.pack");
- this.game = game;
- gamecam = new OrthographicCamera();
- viewport = new FitViewport(GameBase.WIDTH / GameBase.PPM,GameBase.HEIGHT / GameBase.PPM ,gamecam);
- hud = new HUD(game.batch);
- //create tile map and renderer
- maploader = new TmxMapLoader();
- map = maploader.load("maps/test.tmx");
- renderer = new OrthogonalTiledMapRenderer(map, 1 / GameBase.PPM);
- //center the camera to the middle of the world
- gamecam.position.set(viewport.getWorldWidth() / 2, viewport.getWorldHeight() / 2,0);
- world = new World(new Vector2(0,0), true);
- b2dr = new Box2DDebugRenderer();
- //initialize world physics
- new Physics(world,map);
- //create the Hero
- player = new Hero(world,this);
- }
- public TextureAtlas getAtlas(){
- return atlas;
- }
- @Override
- public void show() {
- }
- public void handleInput(float dt){
- }
- public void update(float dt){
- handleInput(dt);
- world.step(1 / 60f, 6, 2);
- //update player
- player.update(dt);
- gamecam.position.x = player.b2body.getPosition().x;
- gamecam.position.y = player.b2body.getPosition().y;
- gamecam.update();
- renderer.setView(gamecam);
- }
- @Override
- public void render(float delta) {
- update(delta);
- Gdx.gl.glClearColor(0, 0, 0, 1);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- //render the tilemap
- renderer.render();
- //render physics
- b2dr.render(world, gamecam.combined);
- game.batch.setProjectionMatrix(gamecam.combined);
- game.batch.begin();
- //draw here
- player.draw(game.batch);
- game.batch.end();
- //draw HUD
- game.batch.setProjectionMatrix(hud.stage.getCamera().combined);
- hud.stage.draw();
- }
- @Override
- public void resize(int width, int height) {
- viewport.update(width, height);
- }
- @Override
- public void pause() {
- }
- @Override
- public void resume() {
- }
- @Override
- public void hide() {
- }
- @Override
- public void dispose() {
- map.dispose();
- renderer.dispose();
- world.dispose();
- b2dr.dispose();
- hud.dispose();
- }
- }
SHARE
TWEET
no render
a guest
Oct 27th, 2015
113
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

