removed inputtransform class, add comments and made smol fixes
This commit is contained in:
@@ -28,6 +28,13 @@ public class MapRenderer implements Renderable {
|
|||||||
private boolean isStarted = false;
|
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) {
|
public MapRenderer(Map map, int tileWidth, SpriteBatch batch, OrthographicCamera camera) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.tileWidth = tileWidth;
|
this.tileWidth = tileWidth;
|
||||||
@@ -37,6 +44,9 @@ public class MapRenderer implements Renderable {
|
|||||||
makeTiles();
|
makeTiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* loads all the images for the tiles and adds all the tiles to the array
|
||||||
|
*/
|
||||||
private void makeTiles() {
|
private void makeTiles() {
|
||||||
Texture texture = new Texture(Gdx.files.internal(tilePath));
|
Texture texture = new Texture(Gdx.files.internal(tilePath));
|
||||||
TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32);
|
TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32);
|
||||||
@@ -103,7 +113,7 @@ public class MapRenderer implements Renderable {
|
|||||||
|
|
||||||
public void resize(int screenWidth, int screenHeight) {
|
public void resize(int screenWidth, int screenHeight) {
|
||||||
cam = new OrthographicCamera(screenWidth, screenHeight);
|
cam = new OrthographicCamera(screenWidth, screenHeight);
|
||||||
cam.translate(screenWidth / 2, screenHeight / 2);
|
cam.translate(screenWidth / 2f, screenHeight / 2f);
|
||||||
cam.update();
|
cam.update();
|
||||||
batch.setProjectionMatrix(cam.combined);
|
batch.setProjectionMatrix(cam.combined);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.badlogic.gdx.math.MathUtils;
|
|||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
import com.badlogic.gdx.utils.TimeUtils;
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
import netwerkprog.game.client.MainGame;
|
import netwerkprog.game.client.MainGame;
|
||||||
import netwerkprog.game.util.application.InputTransform;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -28,6 +27,12 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
private final float CAMERA_MOVE_SPEED = .3f;
|
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) {
|
public GameInputProcessor(OrthographicCamera camera, MainGame game) {
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
this.game = game;
|
this.game = game;
|
||||||
@@ -40,12 +45,6 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
keysList.add(Input.Keys.D);
|
keysList.add(Input.Keys.D);
|
||||||
|
|
||||||
camera.zoom = MathUtils.clamp(camera.zoom, 1.5f, 1.8f);
|
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 row = 0; row < game.mapRenderer.getTiles().length; row++) {
|
||||||
for (int col = 0; col < game.mapRenderer.getTiles()[0].length; col++) {
|
for (int col = 0; col < game.mapRenderer.getTiles()[0].length; col++) {
|
||||||
Tile tile = game.mapRenderer.getTiles()[row][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);
|
System.out.println(tile + " row: " + row + ", col: " + col);
|
||||||
//TODO make stuff happen with the tile
|
//TODO make stuff happen with the tile
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user