Guest User

Untitled

a guest
Mar 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. public class Physics {
  2. private int weight;
  3. private int durability;
  4. private int xPos;
  5. private int yPos;
  6. private int x;
  7. private int y;
  8. private Level level;
  9. int tileWidth = Main.WIDTH / 16;
  10. int tileHeight = Main.HEIGHT / 16;
  11. public Physics(Level level){
  12. this.level = level;
  13. }
  14.  
  15. private void timer(int time) {//this is a subroutine that creates a slight pause
  16. long currTime = System.currentTimeMillis();//this is getting the current time in miliseconds
  17. long target = currTime + time;//this gets the current time and sets the target pause time to the current time plus the time you want to pause for in miliseconds
  18. while(System.currentTimeMillis() < target);//this makes the program idle for the target amount of time
  19. }
  20.  
  21. public void gravity(int weight,int durability, int xPos, int yPos, Tile tile, TileType tileTypes, boolean newblock){//this is the physics subroutine for when you place a block
  22. if(tile.getType() == TileType.SKY) {//if the tile you clicked on is a sky tile
  23. tile.setType(tileTypes, weight, durability);//it sets the new tiles type weight and durability to the ones that were entered dependant on which block the user chose from the pallet
  24. timer(50);//this is the pause time between the block falling one y coordinate down
  25. tile.setType(TileType.SKY, 0, 0);//once the tile is drawn one tile down it changeds the tile above it back to a sky tile
  26. yPos++;//this the increases the y possition by one to foxus on the next block down
  27. gravity(weight,durability, xPos, yPos, level.tiles[xPos][yPos],tileTypes,true);//this then calls the subroutine within itself and this keeps going until it hits the bottom
  28. }
  29. //if (newblock == true){
  30. if(tile.getType() != TileType.SKY){//once the tile below the tile we're focusing on is not a sky tile this if statement is run
  31. Tile tile1 = level.tiles[xPos][yPos-1];//it sets the tile were focusing on to the tile above the non skytile
  32. tile1.setType(tileTypes, weight, durability);//it then sets this tile to the tile you chose from the pallet
  33. weight = tile1.getWeight();
  34. durability = tile1.getDurability();
  35. System.out.println(weight+"kg, "+durability);
  36. }
  37. //}
  38. //if (newblock == false){
  39.  
  40.  
  41.  
  42. //}
  43. }
  44.  
  45. public void blockDestruction(Tile tile){
  46.  
  47.  
  48.  
  49. }
  50.  
  51. public void tick(int x, int y){
  52.  
  53. Tile tile = level.tiles[x][y];
  54. Tile tile1 = level.tiles[x][y-1];
  55. TileType tilecheck = tile1.getType();
  56. if(tile1.getType() != TileType.SKY && tile1.getType() != TileType.GRASS){
  57. gravity(tile.getWeight(),tile.getDurability(),x,y,tile,tile.getType(),false);
  58. y = y-1;
  59.  
  60. /*for (int i = y-1; i>0;i--){
  61. if (tilecheck != TileType.SKY){
  62. tile1 = level.tiles[x][i];
  63. tilecheck = tile1.getType();
  64. }else
  65. tile1 = level.tiles[x][i+1];
  66. tile1.setType(TileType.SKY);
  67. }*/
  68.  
  69. }
  70.  
  71. }
Add Comment
Please, Sign In to add comment