Advertisement
Guest User

Untitled

a guest
Jun 13th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. //written by jake t
  2. ArrayList<block> blocks= new ArrayList<block>();
  3. ArrayList<cannonball> cbs = new ArrayList<cannonball>();
  4.  
  5. void setup() {
  6. size(500, 500);
  7. cbs.add(new cannonball(0, 0, 0));
  8. }
  9. void draw() {
  10. background(0, 0, 170);
  11. //props
  12. fill(0, 200, 0);
  13. rect(0, 400, 500, 500);
  14. fill(0);
  15. ellipse(50, 350, 50, 50);
  16. rect(50, 325, 100, 50);
  17. if (mousePressed) {
  18. if (mouseButton == LEFT) {
  19. cbs.remove(0);
  20. cbs.add(new cannonball(75, 350, 20));
  21. }
  22. if (mouseButton == RIGHT)bspawn();
  23. }
  24. for (block i : blocks) {
  25. i.drawblock();
  26. }
  27. for (cannonball i : cbs) {
  28. i.drawcb();
  29. }
  30. }
  31. void bspawn() {
  32. blocks.add(new block(250, 0));
  33. blocks.add(new block(250, 25));
  34. blocks.add(new block(250, 50));
  35. blocks.add(new block(300, 0));
  36. blocks.add(new block(300, 25));
  37. blocks.add(new block(300, 50));
  38. }
  39. class block {
  40. float bx, by, VelD, VelU, VelR, VelL;
  41. block(int _bx, int _by) {
  42. bx=_bx;
  43. by=_by;
  44. VelD = 0;
  45. VelU = 0;
  46. VelL = 0;
  47. VelR = 0;
  48. }
  49. void drawblock() {
  50. for (int i=0; i<blocks.size(); i++) {
  51. block sb=blocks.get(i);
  52. if (sb.by<by+25&&sb.by+25>by&&(sb.bx+25>bx||cbs.get(0).cx>bx)) {
  53. //left
  54. println("left");
  55. }
  56. if (sb.by<by+25&&sb.by+25>by&&(sb.bx<bx+25||cbs.get(0).cx>bx)) {
  57. //right
  58. println("right");
  59. }
  60. if (sb.bx+25>bx&&sb.bx<bx+25&&(sb.by+25>by||cbs.get(0).cx>bx)) {
  61. //top
  62. println("top");
  63. }
  64. if (sb.bx+25>bx&&sb.bx<bx+25&&(sb.by<by||cbs.get(0).cx>bx)) {
  65. //bottom
  66. println("bottom");
  67. } else {
  68. if (by<400) {
  69. VelD+=.98;
  70. by+=VelD;
  71. }
  72. }
  73. }
  74.  
  75. //if();
  76. fill(117, 118, 29);
  77. rect(bx, by, 25, 25);
  78. }
  79. }
  80. class cannonball {
  81. float cx, cy, VelD, VelU, VelR, VelL;
  82. cannonball(int _cx, int _cy, int _v) {
  83. cx=_cx;
  84. cy=_cy;
  85. VelD = 0;
  86. VelU = 0;
  87. VelL = 0;
  88. VelR = _v;
  89. }
  90. void drawcb() {
  91. fill(0);
  92. ellipse(cx, cy, 5, 5);
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement