Advertisement
UnhandyFir9

Redone

Mar 1st, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.74 KB | None | 0 0
  1. package sollertis.game;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import com.badlogic.gdx.ApplicationAdapter;
  7. import com.badlogic.gdx.Gdx;
  8. import com.badlogic.gdx.Input;
  9. import com.badlogic.gdx.InputAdapter;
  10. import com.badlogic.gdx.graphics.GL20;
  11. import com.badlogic.gdx.graphics.g2d.BitmapFont;
  12. import com.badlogic.gdx.graphics.g2d.SpriteBatch;
  13.  
  14. public class Main extends ApplicationAdapter{
  15.    
  16.     Assets assets;
  17. //  List<Block> blockList;
  18.     Block[][] blockList;
  19.    
  20.     StartBlock startBlock1, startBlock2;
  21.     boolean placedBlock;
  22.     Block block;
  23.  
  24.     //AmountOfMoves
  25.     BitmapFont text;
  26.     int amountOfMoves;
  27.    
  28.     SpriteBatch batch;
  29.    
  30.     public void create(){
  31.         assets = new Assets();
  32.         assets.load();
  33.        
  34. //      blockList = new ArrayList<Block>();    
  35.         blockList = new Block[19][14];
  36.        
  37.         startBlock1 = StartBlock.makeStartBlock();
  38.         startBlock2 = StartBlock.makeStartBlock();
  39.  
  40.         batch = new SpriteBatch();
  41.        
  42.         text = new BitmapFont();
  43.         text.setColor(1, 0, 0, 1);
  44.         text.setScale(2);
  45.         amountOfMoves = 0;
  46.  
  47.         placedBlock = false;
  48.        
  49.         for(int x = 0; x < blockList.length; x++){
  50.             for(int y = 0; y < blockList[x].length; y++){
  51.                 blockList[y][x] = Block.makeBlock();
  52.             }
  53.         }
  54.     }
  55.    
  56.     public void render(){
  57.         Gdx.gl.glClearColor(1f, 1f, 1f, 1f);
  58.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  59.        
  60.         batch.begin();
  61.         batch.draw(assets.grid, 0, 0);
  62.         batch.draw(assets.startBlockBlue1, startBlock1.bounds.x, startBlock1.bounds.y);
  63.         batch.draw(assets.startBlockBlue2, startBlock2.bounds.x, startBlock2.bounds.y);
  64.        
  65. //      for(Block block : blockList){
  66. //          batch.draw(assets.tunnelGreen, block.bounds.x, block.bounds.y );
  67. //      }
  68.        
  69.         text.draw(batch, Integer.toString(amountOfMoves), 10, Gdx.graphics.getHeight() - 10);
  70.         batch.draw(assets.run, Gdx.graphics.getWidth() - 80, Gdx.graphics.getHeight() - 80);
  71.        
  72.         for(int x = 0; x < blockList.length; x++){
  73.             for(int y = 0; y < blockList[x].length; y++){
  74.                     batch.draw(assets.tunnelGreen, blockList[y][x].bounds.x, blockList[y][x].bounds.y);
  75.             }                      
  76.         }
  77.        
  78.         batch.end();
  79.        
  80.         startBlock1.updatePosition(startBlock2, 100, 100);
  81.        
  82.         startBlock1.moveToGrid(startBlock1);
  83.         startBlock1.moveToGrid(startBlock2);
  84.        
  85.         placeBlock();
  86.         blockPosition();
  87.        
  88.         reset();   
  89.     }
  90.    
  91.     public void placeBlock(){
  92.         Gdx.input.setInputProcessor(new InputAdapter(){
  93.             public boolean touchDown(int x, int y, int pointer, int button){
  94.                 if(button == Input.Buttons.LEFT){
  95.  
  96.                     block = Block.makeBlock();
  97.                    
  98.                     amountOfMoves++;
  99.                    
  100.                     block.bounds.x = Gdx.input.getX();
  101.                     block.bounds.y = - Gdx.input.getY() + Gdx.graphics.getHeight();
  102.  
  103.                     if(block.bounds.x % 32 != 0 || block.bounds.y % 32 != 0){
  104.                         block.bounds.x -= block.bounds.x % 32;
  105.                         block.bounds.y -= block.bounds.y % 32;         
  106.                     }
  107.    
  108.                     placedBlock = true;
  109.                    
  110. //                  blockList.add(block);
  111.                     blockList[y][x] = block;
  112.                    
  113.                 }                      
  114.                     if(placedBlock == true){
  115.                         if(button == Input.Buttons.RIGHT){
  116.                             block.bounds.x = 1000;
  117.                         }      
  118.                 }  
  119.                 return true;   
  120.             }
  121.         });
  122.     }
  123.     public void reset(){
  124.  
  125.     }
  126.    
  127.     public void blockPosition(){
  128. //      for(Block block : blockList){
  129. //          if(block.bounds.y < startBlock1.bounds.y && block.bounds.y > startBlock1.bounds.y - 64){
  130. //
  131. //          }
  132. //         
  133. //          if(block.bounds.y > startBlock1.bounds.y && block.bounds.y < startBlock1.bounds.y + 64){
  134. //
  135. //          }
  136. //         
  137. //          if(block.bounds.x < startBlock1.bounds.x && block.bounds.x > startBlock1.bounds.x - 64){
  138. //              System.out.println("test");
  139. //          }
  140. //         
  141. //          if(block.bounds.x > startBlock1.bounds.x && block.bounds.x < startBlock1.bounds.x + 64){
  142. //              System.out.println("test2");
  143. //          }
  144. //      }
  145.     }
  146.    
  147.     public void resize(int width, int height) {
  148.  
  149.     }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement