Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @author rowbottom
- * Block version 1.0- drops from the top and falls until it stacks onto another block
- **/
- class Block {
- float floor = height;
- PVector pos;
- PVector vel;
- PVector acc;
- PVector siz;
- float g = 0.01;
- ArrayList<Block> blocks;// = new ArrayList<Block>();;
- PImage img;
- public Block (ArrayList<Block> b) {
- blocks = b;
- siz = new PVector(50, 50);
- vel = new PVector(0, 4);
- acc = new PVector (0, g);
- pos = new PVector(width/2, -500);
- // pos = new PVector(width/2, width - siz.y/2); //starts at the bottom
- }
- public Block (ArrayList<Block> b, PVector startingPos) {
- blocks = b;
- siz = new PVector(50, 50);
- vel = new PVector(0, 4);
- acc = new PVector (0, g);
- pos = startingPos;
- // pos = new PVector(width/2, width - siz.y/2); //starts at the bottom
- }
- public Block (ArrayList<Block> b, PVector startingPos, float _floor) {
- blocks = b;
- siz = new PVector(50, 50);
- vel = new PVector(0, 4);
- acc = new PVector (0, g);
- pos = startingPos;
- floor = _floor;
- }
- public Block (ArrayList<Block> b, PVector startingPos, float _floor, PImage _img) {
- blocks = b;
- siz = new PVector(50, 50);
- vel = new PVector(0, 10);
- acc = new PVector (0, g);
- pos = startingPos;
- floor = _floor;
- img = _img;
- }
- void update() {
- vel.add(acc);
- pos.add(vel);
- // 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
- }
- void check() {
- if ((pos.y+(siz.y/2))>floor) {
- pos.y=floor-siz.y/2;
- blocks.remove(this);
- }
- //new system
- }
- void ballReflection(PVector bPos, PVector bSiz) {
- //check to see if they are overlapping
- if (abs(bPos.x - pos.x) < bSiz.x/2 + siz.x/2 &&abs(bPos.y - pos.y) < bSiz.y/2 + siz.y/2) {
- blocks.remove(this);
- }
- }
- void lazer(PVector bPos, PVector bSiz) {
- //check to see if they are overlapping
- if (abs(bPos.x - pos.x) < bSiz.x/2 + siz.x/2 && bPos.y>pos.y ) {
- blocks.remove(this);
- }
- }
- boolean hitSore(PVector bPos, PVector bSiz) {
- //check to see if they are overlapping
- if (abs(bPos.x - pos.x) < bSiz.x/2 + siz.x/2 &&abs(bPos.y - pos.y) < bSiz.y/2 + siz.y/2) {
- return true;
- } else {
- return false;
- }
- }
- boolean shipCollision(PVector bPos, PVector bSiz) {
- //check to see if they are overlapping
- if (abs(bPos.x - pos.x) < bSiz.x/2 + siz.x/2 &&abs(bPos.y - pos.y) < bSiz.y/2 + siz.y/2) {
- blocks.remove(this);
- return false;
- } else {
- return true;
- }
- }
- void draw() {
- if (img==null) {
- fill(255, 0, 0);
- rect(pos.x, pos.y, siz.x, siz.y, 2);
- fill(0);
- text(""+blocks.indexOf(this), pos.x, pos.y);
- } else {
- image(img, pos.x, pos.y, siz.x, siz.y);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement