Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. /**
  2. * @author rowbottom
  3. * Block version 1.0- drops from the top and falls until it stacks onto another block
  4. **/
  5.  
  6. class Block {
  7. float floor = height;
  8. PVector pos;
  9. PVector vel;
  10. PVector acc;
  11. PVector siz;
  12. float g = 0.01;
  13. ArrayList<Block> blocks;// = new ArrayList<Block>();;
  14. PImage img;
  15.  
  16. public Block (ArrayList<Block> b) {
  17. blocks = b;
  18. siz = new PVector(50, 50);
  19. vel = new PVector(0, 4);
  20. acc = new PVector (0, g);
  21. pos = new PVector(width/2, -500);
  22.  
  23.  
  24. // pos = new PVector(width/2, width - siz.y/2); //starts at the bottom
  25. }
  26.  
  27. public Block (ArrayList<Block> b, PVector startingPos) {
  28. blocks = b;
  29. siz = new PVector(50, 50);
  30. vel = new PVector(0, 4);
  31. acc = new PVector (0, g);
  32. pos = startingPos;
  33.  
  34. // pos = new PVector(width/2, width - siz.y/2); //starts at the bottom
  35. }
  36. public Block (ArrayList<Block> b, PVector startingPos, float _floor) {
  37. blocks = b;
  38. siz = new PVector(50, 50);
  39. vel = new PVector(0, 4);
  40. acc = new PVector (0, g);
  41. pos = startingPos;
  42. floor = _floor;
  43. }
  44. public Block (ArrayList<Block> b, PVector startingPos, float _floor, PImage _img) {
  45. blocks = b;
  46. siz = new PVector(50, 50);
  47. vel = new PVector(0, 10);
  48. acc = new PVector (0, g);
  49. pos = startingPos;
  50. floor = _floor;
  51. img = _img;
  52. }
  53. void update() {
  54. vel.add(acc);
  55. pos.add(vel);
  56. // pos = new PVector(width/2, height - (blocks.size() - blocks.indexOf(this)-1)* siz.y - siz.y/2); //handles adding blocks from the bottom on top of each other
  57. }
  58.  
  59. void check() {
  60.  
  61. if ((pos.y+(siz.y/2))>floor) {
  62. pos.y=floor-siz.y/2;
  63. blocks.remove(this);
  64. }
  65. //new system
  66. }
  67.  
  68.  
  69. void ballReflection(PVector bPos, PVector bSiz) {
  70.  
  71. //check to see if they are overlapping
  72. if (abs(bPos.x - pos.x) < bSiz.x/2 + siz.x/2 &&abs(bPos.y - pos.y) < bSiz.y/2 + siz.y/2) {
  73. blocks.remove(this);
  74. }
  75. }
  76. void lazer(PVector bPos, PVector bSiz) {
  77.  
  78. //check to see if they are overlapping
  79. if (abs(bPos.x - pos.x) < bSiz.x/2 + siz.x/2 && bPos.y>pos.y ) {
  80. blocks.remove(this);
  81. }
  82. }
  83. boolean hitSore(PVector bPos, PVector bSiz) {
  84.  
  85. //check to see if they are overlapping
  86. if (abs(bPos.x - pos.x) < bSiz.x/2 + siz.x/2 &&abs(bPos.y - pos.y) < bSiz.y/2 + siz.y/2) {
  87. return true;
  88. } else {
  89. return false;
  90. }
  91. }
  92. boolean shipCollision(PVector bPos, PVector bSiz) {
  93.  
  94. //check to see if they are overlapping
  95. if (abs(bPos.x - pos.x) < bSiz.x/2 + siz.x/2 &&abs(bPos.y - pos.y) < bSiz.y/2 + siz.y/2) {
  96. blocks.remove(this);
  97.  
  98. return false;
  99. } else {
  100. return true;
  101. }
  102. }
  103. void draw() {
  104. if (img==null) {
  105. fill(255, 0, 0);
  106. rect(pos.x, pos.y, siz.x, siz.y, 2);
  107. fill(0);
  108. text(""+blocks.indexOf(this), pos.x, pos.y);
  109. } else {
  110. image(img, pos.x, pos.y, siz.x, siz.y);
  111. }
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement