merge Implement mapdrawing into master #3
@@ -39,8 +39,6 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
screenHeight = Gdx.graphics.getHeight();
|
screenHeight = Gdx.graphics.getHeight();
|
||||||
frameRate = new FrameRate();
|
frameRate = new FrameRate();
|
||||||
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
camera.translate(0, 0);
|
|
||||||
camera.update();
|
|
||||||
|
|
||||||
|
|
||||||
String[] strings = new String[]{
|
String[] strings = new String[]{
|
||||||
@@ -62,7 +60,10 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
gameInputProcessor = new GameInputProcessor(camera, this);
|
gameInputProcessor = new GameInputProcessor(camera, this);
|
||||||
Gdx.input.setInputProcessor(gameInputProcessor);
|
Gdx.input.setInputProcessor(gameInputProcessor);
|
||||||
mapRenderer = new MapRenderer(map, 32, batch, camera);
|
mapRenderer = new MapRenderer(map, 32, batch, camera);
|
||||||
camera.translate(screenWidth/2,screenHeight/2);
|
camera.position.set(screenWidth/2,screenHeight/2,0);
|
||||||
|
camera.viewportWidth = screenWidth / 2;
|
||||||
|
camera.viewportHeight = screenHeight / 2;
|
||||||
|
camera.update();
|
||||||
|
|
||||||
|
|
||||||
// playSong();
|
// playSong();
|
||||||
@@ -130,7 +131,19 @@ public class MainGame extends ApplicationAdapter {
|
|||||||
batch.dispose();
|
batch.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void keyDown() {
|
public float getScreenWidth() {
|
||||||
|
return screenWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getScreenHeight() {
|
||||||
|
return screenHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVerticalTileAmount() {
|
||||||
|
return map.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHorizontalTileAmount() {
|
||||||
|
return map.getWidth();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package netwerkprog.game.client.map;
|
|||||||
import com.badlogic.gdx.Input;
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.InputProcessor;
|
import com.badlogic.gdx.InputProcessor;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.utils.TimeUtils;
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
import netwerkprog.game.MainGame;
|
import netwerkprog.game.MainGame;
|
||||||
|
|
||||||
@@ -35,6 +36,14 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
keysList.add(Input.Keys.S);
|
keysList.add(Input.Keys.S);
|
||||||
keysList.add(Input.Keys.D);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isWPressed() {
|
public boolean isWPressed() {
|
||||||
@@ -79,6 +88,7 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyUp(int keycode) {
|
public boolean keyUp(int keycode) {
|
||||||
|
System.out.println(camera.position.x + " , " + camera.position.y);
|
||||||
if (keysList.contains(keycode)) {
|
if (keysList.contains(keycode)) {
|
||||||
if (keycode == keysList.get(0)) {
|
if (keycode == keysList.get(0)) {
|
||||||
this.isWPressed = false;
|
this.isWPressed = false;
|
||||||
@@ -96,6 +106,7 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
this.isDPressed = false;
|
this.isDPressed = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -128,23 +139,34 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean scrolled(int amount) {
|
public boolean scrolled(int amount) {
|
||||||
|
float nextZoom = camera.zoom + amount / 5f;
|
||||||
|
if (nextZoom >= 0.5 && nextZoom <= 2.5) {
|
||||||
|
camera.zoom += amount / 2f;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
long delta = TimeUtils.timeSinceMillis(lastTimeCounted);
|
long delta = TimeUtils.timeSinceMillis(lastTimeCounted);
|
||||||
lastTimeCounted = TimeUtils.millis();
|
lastTimeCounted = TimeUtils.millis();
|
||||||
if (isWPressed()) {
|
if (camera.position.x > 5 * game.getHorizontalTileAmount())
|
||||||
camera.position.add(0, -CAMERA_MOVE_SPEED * delta, 0);
|
if (isAPressed()) {
|
||||||
}
|
camera.position.add(-CAMERA_MOVE_SPEED * delta, 0, 0);
|
||||||
if (isSPressed()) {
|
}
|
||||||
camera.position.add(0, CAMERA_MOVE_SPEED * delta, 0);
|
if (camera.position.y < 30 * game.getVerticalTileAmount())
|
||||||
}
|
if (isWPressed()) {
|
||||||
if (isAPressed()) {
|
camera.position.add(0, CAMERA_MOVE_SPEED * delta, 0);
|
||||||
camera.position.add(CAMERA_MOVE_SPEED * delta, 0, 0);
|
}
|
||||||
}
|
|
||||||
if (isDPressed()) {
|
if (camera.position.y > 5 * game.getVerticalTileAmount())
|
||||||
camera.position.add(-CAMERA_MOVE_SPEED * delta, 0, 0);
|
if (isSPressed()) {
|
||||||
}
|
camera.position.add(0, -CAMERA_MOVE_SPEED * delta, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (camera.position.x < game.getScreenWidth() / 2 + 5 * game.getHorizontalTileAmount())
|
||||||
|
if (isDPressed()) {
|
||||||
|
camera.position.add(CAMERA_MOVE_SPEED * delta, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user