Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //written by jake t
- ArrayList<block> blocks= new ArrayList<block>();
- ArrayList<cannonball> cbs = new ArrayList<cannonball>();
- void setup() {
- size(500, 500);
- cbs.add(new cannonball(0, 0, 0));
- }
- void draw() {
- background(0, 0, 170);
- //props
- fill(0, 200, 0);
- rect(0, 400, 500, 500);
- fill(0);
- ellipse(50, 350, 50, 50);
- rect(50, 325, 100, 50);
- if (mousePressed) {
- if (mouseButton == LEFT) {
- cbs.remove(0);
- cbs.add(new cannonball(75, 350, 20));
- }
- if (mouseButton == RIGHT)bspawn();
- }
- for (block i : blocks) {
- i.drawblock();
- }
- for (cannonball i : cbs) {
- i.drawcb();
- }
- }
- void bspawn() {
- blocks.add(new block(250, 0));
- blocks.add(new block(250, 25));
- blocks.add(new block(250, 50));
- blocks.add(new block(300, 0));
- blocks.add(new block(300, 25));
- blocks.add(new block(300, 50));
- }
- class block {
- float bx, by, VelD, VelU, VelR, VelL;
- block(int _bx, int _by) {
- bx=_bx;
- by=_by;
- VelD = 0;
- VelU = 0;
- VelL = 0;
- VelR = 0;
- }
- void drawblock() {
- for (int i=0; i<blocks.size(); i++) {
- block sb=blocks.get(i);
- if (sb.by<by+25&&sb.by+25>by&&(sb.bx+25>bx||cbs.get(0).cx>bx)) {
- //left
- println("left");
- }
- if (sb.by<by+25&&sb.by+25>by&&(sb.bx<bx+25||cbs.get(0).cx>bx)) {
- //right
- println("right");
- }
- if (sb.bx+25>bx&&sb.bx<bx+25&&(sb.by+25>by||cbs.get(0).cx>bx)) {
- //top
- println("top");
- }
- if (sb.bx+25>bx&&sb.bx<bx+25&&(sb.by<by||cbs.get(0).cx>bx)) {
- //bottom
- println("bottom");
- } else {
- if (by<400) {
- VelD+=.98;
- by+=VelD;
- }
- }
- }
- //if();
- fill(117, 118, 29);
- rect(bx, by, 25, 25);
- }
- }
- class cannonball {
- float cx, cy, VelD, VelU, VelR, VelL;
- cannonball(int _cx, int _cy, int _v) {
- cx=_cx;
- cy=_cy;
- VelD = 0;
- VelU = 0;
- VelL = 0;
- VelR = _v;
- }
- void drawcb() {
- fill(0);
- ellipse(cx, cy, 5, 5);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement