removed inputtransform class, add comments and made smol fixes

This commit is contained in:
Sem van der Hoeven
2020-05-25 20:55:02 +02:00
parent 75f1c26349
commit d4c6d76aea
3 changed files with 18 additions and 21 deletions

View File

@@ -28,6 +28,13 @@ public class MapRenderer implements Renderable {
private boolean isStarted = false;
/**
* makea a new mapRenderer object
* @param map the map object
* @param tileWidth the width of the tile
* @param batch the batch object so no new ones have to be made
* @param camera the camera object
*/
public MapRenderer(Map map, int tileWidth, SpriteBatch batch, OrthographicCamera camera) {
this.map = map;
this.tileWidth = tileWidth;
@@ -37,6 +44,9 @@ public class MapRenderer implements Renderable {
makeTiles();
}
/**
* loads all the images for the tiles and adds all the tiles to the array
*/
private void makeTiles() {
Texture texture = new Texture(Gdx.files.internal(tilePath));
TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32);
@@ -103,7 +113,7 @@ public class MapRenderer implements Renderable {
public void resize(int screenWidth, int screenHeight) {
cam = new OrthographicCamera(screenWidth, screenHeight);
cam.translate(screenWidth / 2, screenHeight / 2);
cam.translate(screenWidth / 2f, screenHeight / 2f);
cam.update();
batch.setProjectionMatrix(cam.combined);
}

View File

@@ -8,7 +8,6 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.utils.TimeUtils;
import netwerkprog.game.client.MainGame;
import netwerkprog.game.util.application.InputTransform;
import java.util.ArrayList;
import java.util.Arrays;
@@ -28,6 +27,12 @@ public class GameInputProcessor implements InputProcessor {
private final float CAMERA_MOVE_SPEED = .3f;
/**
* makes a new game input processor
*
* @param camera the camera object to use
* @param game the game object to get objects from
*/
public GameInputProcessor(OrthographicCamera camera, MainGame game) {
this.camera = camera;
this.game = game;
@@ -40,12 +45,6 @@ public class GameInputProcessor implements InputProcessor {
keysList.add(Input.Keys.D);
camera.zoom = MathUtils.clamp(camera.zoom, 1.5f, 1.8f);
//
// float effectiveViewportWidth = camera.viewportWidth * camera.zoom;
// float effectiveViewportHeight = camera.viewportHeight * camera.zoom;
//
// camera.position.x = MathUtils.clamp(camera.position.x, effectiveViewportWidth / 2f, game.getScreenWidth() - effectiveViewportWidth / 2f);
// camera.position.y = MathUtils.clamp(camera.position.y, effectiveViewportHeight / 2f, game.getScreenHeight() - effectiveViewportHeight / 2f);
}
@@ -129,7 +128,7 @@ public class GameInputProcessor implements InputProcessor {
for (int row = 0; row < game.mapRenderer.getTiles().length; row++) {
for (int col = 0; col < game.mapRenderer.getTiles()[0].length; col++) {
Tile tile = game.mapRenderer.getTiles()[row][col];
if (tile.contains(touchPoint.x,touchPoint.y)) {
if (tile.contains(touchPoint.x, touchPoint.y)) {
System.out.println(tile + " row: " + row + ", col: " + col);
//TODO make stuff happen with the tile
return true;

View File

@@ -1,12 +0,0 @@
package netwerkprog.game.util.application;
public class InputTransform {
public static float getCursorToModelX(int screenwidth, int screenX, int cursorX) {
return (((float) cursorX) * screenwidth) / ((float) screenX);
}
public static float getCursorToModelY(int screenHeight, int screenY, int cursorY) {
return ((float) (screenY - cursorY)) * screenHeight / ((float) screenY);
}
}