<commit_before>package com.mygdx.game.stages;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.mygdx.game.managers.GameStateManager;
import com.mygdx.game.managers.LevelManager;
import com.mygdx.game.utils.Tile;
import com.mygdx.game.utils.TileType;

public class GameStage extends Stage implements InputProcessor{
	private GameStateManager gsm;
	private OrthogonalTiledMapRenderer renderer;
	private ShapeRenderer shapeRenderer;
	private int xDir = 0;
	private int yDir = 0;
	public GameStage(GameStateManager gsm) {
		this.gsm = gsm;
		LevelManager.loadLevel("maps/simple-map.tmx");
		renderer = new OrthogonalTiledMapRenderer(LevelManager.tiledMap);
		shapeRenderer = new ShapeRenderer();
		shapeRenderer.setAutoShapeType(true);
	}
	
	@Override
	public void draw() {
		Gdx.gl.glClearColor(.25f, .25f, .25f, 1f);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        renderer.setView(gsm.game().getCamera());
        shapeRenderer.setProjectionMatrix(gsm.game().getCamera().combined);
        renderer.render();
        drawTiles();
	}
	
	/** for debugging **/
	@SuppressWarnings("unused")
	private void drawTiles(){
        for (int row = 0; row < LevelManager.tiles.length; row++) {
            for (int col = 0; col < LevelManager.tiles[0].length; col++) {

                Tile tile = LevelManager.getTile(row , col);
                @SuppressWarnings("ConstantConditions")
                TileType type = tile.getType();
                shapeRenderer.begin();
                // ritar tile grid , och fyller med vit färg där fiender inte kan gå
                if(type == TileType.FLOOR){
                    shapeRenderer.setColor(1,1,1,.2f);
                    shapeRenderer.rect(tile.getCords().x , tile.getCords().y , tile.getTileWidth() , tile.getTileHeight());
                }else {
                    shapeRenderer.set(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(.8f,0,0,.2f);
                    shapeRenderer.rect(tile.getCords().x , tile.getCords().y , tile.getTileWidth() , tile.getTileHeight());
                }
                shapeRenderer.end();
            }
        }
    }
	
	@Override
	public void act() {
		moveCamera(Gdx.graphics.getDeltaTime());
		super.act();
	}
	
	@Override
	public void dispose() {
        renderer.dispose();
        LevelManager.tiledMap.dispose();
	}
	
	private void moveCamera(float delta){
        final float cameraSpeed = 10f;
        gsm.game().getCamera().viewportWidth = Gdx.graphics.getWidth() / 2;
        gsm.game().getCamera().viewportHeight = Gdx.graphics.getHeight() / 2;
        float cameraPosX = gsm.game().getCamera().position.x;
        float cameraPosY =  gsm.game().getCamera().position.y;
        gsm.game().getCamera().position.set((int)cameraPosX+ xDir * cameraSpeed , (int) cameraPosY + yDir * cameraSpeed , 0);
        gsm.game().getCamera().update();
        float startX = gsm.game().getCamera().viewportWidth / 2;
        float startY = gsm.game().getCamera().viewportWidth / 2;
        setCameraBoundary(gsm.game().getCamera() , startX , startY , LevelManager.mapPixelWidth - (startX * 2), LevelManager.mapPixelHeight  - (startY * 2));


	}
	
	  @Override
	    public boolean keyDown(int keycode) {
	        switch (keycode){
	            case Input.Keys.W:
	                yDir = 1;
	                break;
	            case Input.Keys.S:
	                yDir = -1;
	                break;
	            case Input.Keys.A:
	                xDir = -1;
	                break;
	            case Input.Keys.D:
	                xDir = 1;
	                break;
	            default: break;
	        }
	        return false;
	    }
	
	  @Override
	    public boolean keyUp(int keycode) {
	        switch (keycode){
	            case Input.Keys.W:
	                yDir = 0;
	                break;
	            case Input.Keys.S:
	                yDir = 0;
	                break;
	            case Input.Keys.A:
	                xDir = 0;
	                break;
	            case Input.Keys.D:
	                xDir = 0;
	                break;
	            default: break;
	        }
	        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) {
		    /*
	        System.out.println(screenX );
	        if(screenX > Gdx.graphics.getWidth() - 15f){
		        xDir = 1;
	        }else if(screenX < 15f){
	            xDir = -1;
	        }else {
	            xDir = 0;
	        }
	        if (screenY > Gdx.graphics.getHeight() - 15f){
	            yDir = -1;
	        }else if(screenY < 15f){
	            yDir = 1;
	        }else {
	            yDir = 0;
	        }
	        */
	        return false;
	    }

	    @Override
	    public boolean scrolled(int amount) {
	        return false;
	    }

	    private void setCameraBoundary(Camera camera , float startX , float startY , float width , float height){
            Vector3 position = camera.position;
            if(position.x < startX ){
                position.x = startX;
            }
            if(position.y < startY){
                position.y = startY;
            }
            if(position.x > startX + width){
                position.x = startX + width;
            }
            if(position.y > startY + height){
                position.y = startY + height;
            }
            camera.position.set(position);
            camera.update();
        }
	
}<commit_msg>camera set boundary is now working correctly<commit_after>package com.mygdx.game.stages;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.mygdx.game.managers.GameStateManager;
import com.mygdx.game.managers.LevelManager;
import com.mygdx.game.utils.Tile;
import com.mygdx.game.utils.TileType;

public class GameStage extends Stage implements InputProcessor{
	private GameStateManager gsm;
	private OrthogonalTiledMapRenderer renderer;
	private ShapeRenderer shapeRenderer;
	private int xDir = 0;
	private int yDir = 0;
	public GameStage(GameStateManager gsm) {
		this.gsm = gsm;
		LevelManager.loadLevel("maps/simple-map.tmx");
		renderer = new OrthogonalTiledMapRenderer(LevelManager.tiledMap);
		shapeRenderer = new ShapeRenderer();
		shapeRenderer.setAutoShapeType(true);
	}
	
	@Override
	public void draw() {
		Gdx.gl.glClearColor(.25f, .25f, .25f, 1f);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        renderer.setView(gsm.game().getCamera());
        shapeRenderer.setProjectionMatrix(gsm.game().getCamera().combined);
        renderer.render();
        drawTiles();
	}
	
	/** for debugging **/
	@SuppressWarnings("unused")
	private void drawTiles(){
        for (int row = 0; row < LevelManager.tiles.length; row++) {
            for (int col = 0; col < LevelManager.tiles[0].length; col++) {

                Tile tile = LevelManager.getTile(row , col);
                @SuppressWarnings("ConstantConditions")
                TileType type = tile.getType();
                shapeRenderer.begin();
                // ritar tile grid , och fyller med vit färg där fiender inte kan gå
                if(type == TileType.FLOOR){
                    shapeRenderer.setColor(1,1,1,.2f);
                    shapeRenderer.rect(tile.getCords().x , tile.getCords().y , tile.getTileWidth() , tile.getTileHeight());
                }else {
                    shapeRenderer.set(ShapeRenderer.ShapeType.Filled);
                    shapeRenderer.setColor(.8f,0,0,.2f);
                    shapeRenderer.rect(tile.getCords().x , tile.getCords().y , tile.getTileWidth() , tile.getTileHeight());
                }
                shapeRenderer.end();
            }
        }
    }
	
	@Override
	public void act() {
		moveCamera(Gdx.graphics.getDeltaTime());
		super.act();
	}
	
	@Override
	public void dispose() {
        renderer.dispose();
        LevelManager.tiledMap.dispose();
	}
	
	private void moveCamera(float delta){
        final float cameraSpeed = 10f;
        gsm.game().getCamera().viewportWidth = Gdx.graphics.getWidth() / 3;
        gsm.game().getCamera().viewportHeight = Gdx.graphics.getHeight() / 3;
		float cameraPosX = gsm.game().getCamera().position.x;
		float cameraPosY =  gsm.game().getCamera().position.y;
		gsm.game().getCamera().position.set((int)cameraPosX+ xDir * cameraSpeed , (int) cameraPosY + yDir * cameraSpeed , 0);
		gsm.game().getCamera().update();
		float startX = gsm.game().getCamera().viewportWidth / 2;
		float startY = gsm.game().getCamera().viewportHeight / 2;
		float width = startX *2;
		float height = startY *2;
		setCameraBoundary(gsm.game().getCamera() , startX , startY , LevelManager.mapPixelWidth - width , LevelManager.mapPixelHeight - height);
	}
	
	  @Override
	    public boolean keyDown(int keycode) {
	        switch (keycode){
	            case Input.Keys.W:
	                yDir = 1;
	                break;
	            case Input.Keys.S:
	                yDir = -1;
	                break;
	            case Input.Keys.A:
	                xDir = -1;
	                break;
	            case Input.Keys.D:
	                xDir = 1;
	                break;
	            default: break;
	        }
	        return false;
	    }
	
	  @Override
	    public boolean keyUp(int keycode) {
	        switch (keycode){
	            case Input.Keys.W:
	                yDir = 0;
	                break;
	            case Input.Keys.S:
	                yDir = 0;
	                break;
	            case Input.Keys.A:
	                xDir = 0;
	                break;
	            case Input.Keys.D:
	                xDir = 0;
	                break;
	            default: break;
	        }
	        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) {
		    /*
	        System.out.println(screenX );
	        if(screenX > Gdx.graphics.getWidth() - 15f){
		        xDir = 1;
	        }else if(screenX < 15f){
	            xDir = -1;
	        }else {
	            xDir = 0;
	        }
	        if (screenY > Gdx.graphics.getHeight() - 15f){
	            yDir = -1;
	        }else if(screenY < 15f){
	            yDir = 1;
	        }else {
	            yDir = 0;
	        }
	        */
	        return false;
	    }

	    @Override
	    public boolean scrolled(int amount) {
	        return false;
	    }

	    private void setCameraBoundary(Camera camera , float startX , float startY , float width , float height){
            Vector3 position = camera.position;
            if(position.x < startX ){
                position.x = startX;
            }
            if(position.y < startY){
                position.y = startY;
            }
            if(position.x > startX + width){
                position.x = startX + width;
            }
            if(position.y > startY + height){
                position.y = startY + height;
			}
            camera.position.set(position);
            camera.update();
        }
	
}
{'fraction_non_alphanumeric': 0.11172557505810692, 'fraction_numerical': 0.009297106676284363, 'mean_word_length': 1.8514625228519195, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5991722', 'n_tokens_mistral': 4059, 'n_tokens_neox': 3662, 'n_words': 772}