Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Physics {
- private int weight;
- private int durability;
- private int xPos;
- private int yPos;
- private int x;
- private int y;
- private Level level;
- int tileWidth = Main.WIDTH / 16;
- int tileHeight = Main.HEIGHT / 16;
- public Physics(Level level){
- this.level = level;
- }
- private void timer(int time) {//this is a subroutine that creates a slight pause
- long currTime = System.currentTimeMillis();//this is getting the current time in miliseconds
- 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
- while(System.currentTimeMillis() < target);//this makes the program idle for the target amount of time
- }
- 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
- if(tile.getType() == TileType.SKY) {//if the tile you clicked on is a sky tile
- 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
- timer(50);//this is the pause time between the block falling one y coordinate down
- 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
- yPos++;//this the increases the y possition by one to foxus on the next block down
- 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
- }
- //if (newblock == true){
- 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
- Tile tile1 = level.tiles[xPos][yPos-1];//it sets the tile were focusing on to the tile above the non skytile
- tile1.setType(tileTypes, weight, durability);//it then sets this tile to the tile you chose from the pallet
- weight = tile1.getWeight();
- durability = tile1.getDurability();
- System.out.println(weight+"kg, "+durability);
- }
- //}
- //if (newblock == false){
- //}
- }
- public void blockDestruction(Tile tile){
- }
- public void tick(int x, int y){
- Tile tile = level.tiles[x][y];
- Tile tile1 = level.tiles[x][y-1];
- TileType tilecheck = tile1.getType();
- if(tile1.getType() != TileType.SKY && tile1.getType() != TileType.GRASS){
- gravity(tile.getWeight(),tile.getDurability(),x,y,tile,tile.getType(),false);
- y = y-1;
- /*for (int i = y-1; i>0;i--){
- if (tilecheck != TileType.SKY){
- tile1 = level.tiles[x][i];
- tilecheck = tile1.getType();
- }else
- tile1 = level.tiles[x][i+1];
- tile1.setType(TileType.SKY);
- }*/
- }
- }
Add Comment
Please, Sign In to add comment