Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sollertis.game;
- import java.util.ArrayList;
- import java.util.List;
- import com.badlogic.gdx.ApplicationAdapter;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Input;
- import com.badlogic.gdx.InputAdapter;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.g2d.BitmapFont;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- public class Main extends ApplicationAdapter{
- Assets assets;
- // List<Block> blockList;
- Block[][] blockList;
- StartBlock startBlock1, startBlock2;
- boolean placedBlock;
- Block block;
- //AmountOfMoves
- BitmapFont text;
- int amountOfMoves;
- SpriteBatch batch;
- public void create(){
- assets = new Assets();
- assets.load();
- // blockList = new ArrayList<Block>();
- blockList = new Block[19][14];
- startBlock1 = StartBlock.makeStartBlock();
- startBlock2 = StartBlock.makeStartBlock();
- batch = new SpriteBatch();
- text = new BitmapFont();
- text.setColor(1, 0, 0, 1);
- text.setScale(2);
- amountOfMoves = 0;
- placedBlock = false;
- for(int x = 0; x < blockList.length; x++){
- for(int y = 0; y < blockList[x].length; y++){
- blockList[y][x] = Block.makeBlock();
- }
- }
- }
- public void render(){
- Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
- batch.begin();
- batch.draw(assets.grid, 0, 0);
- batch.draw(assets.startBlockBlue1, startBlock1.bounds.x, startBlock1.bounds.y);
- batch.draw(assets.startBlockBlue2, startBlock2.bounds.x, startBlock2.bounds.y);
- // for(Block block : blockList){
- // batch.draw(assets.tunnelGreen, block.bounds.x, block.bounds.y );
- // }
- text.draw(batch, Integer.toString(amountOfMoves), 10, Gdx.graphics.getHeight() - 10);
- batch.draw(assets.run, Gdx.graphics.getWidth() - 80, Gdx.graphics.getHeight() - 80);
- for(int x = 0; x < blockList.length; x++){
- for(int y = 0; y < blockList[x].length; y++){
- batch.draw(assets.tunnelGreen, blockList[y][x].bounds.x, blockList[y][x].bounds.y);
- }
- }
- batch.end();
- startBlock1.updatePosition(startBlock2, 100, 100);
- startBlock1.moveToGrid(startBlock1);
- startBlock1.moveToGrid(startBlock2);
- placeBlock();
- blockPosition();
- reset();
- }
- public void placeBlock(){
- Gdx.input.setInputProcessor(new InputAdapter(){
- public boolean touchDown(int x, int y, int pointer, int button){
- if(button == Input.Buttons.LEFT){
- block = Block.makeBlock();
- amountOfMoves++;
- block.bounds.x = Gdx.input.getX();
- block.bounds.y = - Gdx.input.getY() + Gdx.graphics.getHeight();
- if(block.bounds.x % 32 != 0 || block.bounds.y % 32 != 0){
- block.bounds.x -= block.bounds.x % 32;
- block.bounds.y -= block.bounds.y % 32;
- }
- placedBlock = true;
- // blockList.add(block);
- blockList[y][x] = block;
- }
- if(placedBlock == true){
- if(button == Input.Buttons.RIGHT){
- block.bounds.x = 1000;
- }
- }
- return true;
- }
- });
- }
- public void reset(){
- }
- public void blockPosition(){
- // for(Block block : blockList){
- // if(block.bounds.y < startBlock1.bounds.y && block.bounds.y > startBlock1.bounds.y - 64){
- //
- // }
- //
- // if(block.bounds.y > startBlock1.bounds.y && block.bounds.y < startBlock1.bounds.y + 64){
- //
- // }
- //
- // if(block.bounds.x < startBlock1.bounds.x && block.bounds.x > startBlock1.bounds.x - 64){
- // System.out.println("test");
- // }
- //
- // if(block.bounds.x > startBlock1.bounds.x && block.bounds.x < startBlock1.bounds.x + 64){
- // System.out.println("test2");
- // }
- // }
- }
- public void resize(int width, int height) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement