Hi,
getBlock is just a simple get from the map array:
public BlankEntity getBlock(int x, int y)
{
return worldMap[x][y];
}
and here is the code for render which does the keyboard input:
@Override
public void render() {
Vector3 poss = new Vector3(camera.position);
poss.y-=8;
// Need to check if not jumping as we need to jump Y amount before any downward force happens
if(!bLeft && !bRight) // this needs fixing as doesn't happen when moving right
{
if(checkCollision(poss))
{
camera.position.y -= 3; // scroll map down
}
}
int fps = Gdx.graphics.getFramesPerSecond();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
cloudBackground.render(0.05f, ambientShader); // render clouds
batch.setProjectionMatrix(camera.combined);
if (Gdx.input.isKeyPressed(Input.Keys.W))
{
removeBlock(camera.position, bDown, bLeft, bRight);
}
if (Gdx.input.isKeyPressed(Input.Keys.R))
camera.zoom = 1;
if (Gdx.input.isKeyPressed(Input.Keys.MINUS))
camera.zoom += 3.0f;
if (Gdx.input.isKeyPressed(Input.Keys.I))
camera.zoom -= 3.0f;
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
bRight = false;
bDown = false;
player.moveRight(1);
Vector3 po = new Vector3(camera.position);
po.x-=2;//TILEWIDTH;
po.y-=4;//TILEHEIGHT/2;
if(checkCollision(po)) {
camera.position.x -= 1; // scroll map left
bLeft = false;
}
else // collision, move up
{
if(displayBlockDiagAbove(false,camera.position))
{
bLeft = true;
camera.position.y += 2;
} else
{
bLeft = false;
}
}
}
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
bLeft = false;
bDown = false;
player.moveRight(1);
Vector3 po = new Vector3(camera.position);
po.y-=4;//TILEHEIGHT/2;
if(checkCollision(po)) {
camera.position.x += 1; // scroll map right
bRight = false;
}
else // collision - how do we go up - go up until no collision
{
// is it clear above block? (water, cave, blank)
if(displayBlockDiagAbove(true,camera.position))
{
bRight = true;
camera.position.y += 2; // scroll map up
}
else
{
bRight = false;
}
}
}
// We need to do a jump - TO DO
if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
}
if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
bDown = true;
bRight = false; bLeft = false;
}
if (Gdx.input.isKeyPressed(Input.Keys.PAGE_UP)) {
camera.position.y += 200; // jump map up
}
if (Gdx.input.isKeyPressed(Input.Keys.PAGE_DOWN)) {
camera.position.y -= 200; // jump map down
}
if (Gdx.input.isKeyPressed(Input.Keys.D)) {
debug = true; // turn debug on - basically draw the whole map
}
if (Gdx.input.isKeyPressed(Input.Keys.F)) {
debug = false; // turn debug off
}
camera.position.set(MathUtils.roundPositive(camera.position.x),
MathUtils.roundPositive(camera.position.y),0);
camera.update();
// Calculate what we should draw
int camX = (int) camera.position.x - SCREENWIDTH / 2;
camX /= TILEWIDTH;
int endX = SCREENWIDTH / TILEHEIGHT + camX;
int camY = (int) camera.position.y - SCREENHEIGHT / 2;
camY /= TILEHEIGHT;
int endY = SCREENHEIGHT / TILEHEIGHT + camY;
batch.setShader(ambientShader);
batch.begin();
// Draw the map - only draw what camera sees
worldMap.drawMap(debug, batch, regions, camX - 2, camY, endX + 2, endY,
WORLDWIDTH, WORLDHEIGHT);
batch.end();
// HUD - Draw hud (in our case some text!)
Matrix4 uiMatrix = hudCamera.combined.cpy();
uiMatrix.setToOrtho2D(0, 0, SCREENWIDTH, SCREENHEIGHT);
batch.setProjectionMatrix(uiMatrix);
hudCamera.update();
// Draw player after we have drawn the world
player.render(0);
batch.begin();
drawCameraPosition(batch, camera.position);
String pos = String.format("SteRraria V1.0");
font.draw(batch, pos, 10, SCREENHEIGHT);
this.drawFps(batch, fps);
batch.end();
}
@Override
public void render() {
Vector3 poss = new Vector3(camera.position);
poss.y-=8;
// Need to check if not jumping as we need to jump Y amount before any downward force happens
if(!bLeft && !bRight) // this needs fixing as doesn't happen when moving right
{
if(checkCollision(poss))
{
camera.position.y -= 3; // scroll map down
}
}
int fps = Gdx.graphics.getFramesPerSecond();
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
cloudBackground.render(0.05f, ambientShader); // render clouds
batch.setProjectionMatrix(camera.combined);
if (Gdx.input.isKeyPressed(Input.Keys.W))
{
removeBlock(camera.position, bDown, bLeft, bRight);
}
if (Gdx.input.isKeyPressed(Input.Keys.R))
camera.zoom = 1;
if (Gdx.input.isKeyPressed(Input.Keys.MINUS))
camera.zoom += 3.0f;
if (Gdx.input.isKeyPressed(Input.Keys.I))
camera.zoom -= 3.0f;
if (Gdx.input.isKeyPressed(Input.Keys.LEFT)) {
bRight = false;
bDown = false;
player.moveRight(1);
Vector3 po = new Vector3(camera.position);
po.x-=2;//TILEWIDTH;
po.y-=4;//TILEHEIGHT/2;
if(checkCollision(po)) {
camera.position.x -= 1; // scroll map left
bLeft = false;
}
else // collision, move up
{
if(displayBlockDiagAbove(false,camera.position))
{
bLeft = true;
camera.position.y += 2;
} else
{
bLeft = false;
}
}
}
if (Gdx.input.isKeyPressed(Input.Keys.RIGHT)) {
bLeft = false;
bDown = false;
player.moveRight(1);
Vector3 po = new Vector3(camera.position);
po.y-=4;//TILEHEIGHT/2;
if(checkCollision(po)) {
camera.position.x += 1; // scroll map right
bRight = false;
}
else // collision - how do we go up - go up until no collision
{
// is it clear above block? (water, cave, blank)
if(displayBlockDiagAbove(true,camera.position))
{
bRight = true;
camera.position.y += 2; // scroll map up
}
else
{
bRight = false;
}
}
}
// We need to do a jump - TO DO
if (Gdx.input.isKeyPressed(Input.Keys.UP)) {
}
if (Gdx.input.isKeyPressed(Input.Keys.DOWN)) {
bDown = true;
bRight = false; bLeft = false;
}
if (Gdx.input.isKeyPressed(Input.Keys.PAGE_UP)) {
camera.position.y += 200; // jump map up
}
if (Gdx.input.isKeyPressed(Input.Keys.PAGE_DOWN)) {
camera.position.y -= 200; // jump map down
}
if (Gdx.input.isKeyPressed(Input.Keys.D)) {
debug = true; // turn debug on - basically draw the whole map
}
if (Gdx.input.isKeyPressed(Input.Keys.F)) {
debug = false; // turn debug off
}
camera.position.set(MathUtils.roundPositive(camera.position.x),
MathUtils.roundPositive(camera.position.y),0);
camera.update();
// Calculate what we should draw
int camX = (int) camera.position.x - SCREENWIDTH / 2;
camX /= TILEWIDTH;
int endX = SCREENWIDTH / TILEHEIGHT + camX;
int camY = (int) camera.position.y - SCREENHEIGHT / 2;
camY /= TILEHEIGHT;
int endY = SCREENHEIGHT / TILEHEIGHT + camY;
batch.setShader(ambientShader);
batch.begin();
// Draw the map - only draw what camera sees
worldMap.drawMap(debug, batch, regions, camX - 2, camY, endX + 2, endY,
WORLDWIDTH, WORLDHEIGHT);
batch.end();
// HUD - Draw hud (in our case some text!)
Matrix4 uiMatrix = hudCamera.combined.cpy();
uiMatrix.setToOrtho2D(0, 0, SCREENWIDTH, SCREENHEIGHT);
batch.setProjectionMatrix(uiMatrix);
hudCamera.update();
// Draw player after we have drawn the world
player.render(0);
batch.begin();
drawCameraPosition(batch, camera.position);
String pos = String.format("SteRraria V1.0");
font.draw(batch, pos, 10, SCREENHEIGHT);
this.drawFps(batch, fps);
batch.end();
}
Maybe I should introduce keys where you can move a rectangle over the block you want to remove?
Sorry, not got all the gfx etc in a repo.
Thanks