class BasicBullet { Vector2D position; Vector2D velocity; float angle; float size = 3; float speed = 3; int lifeCount; int strength = 10; int type = 0; int maxLifeCount = 10; public BasicBullet(Vector2D position_, float angle_, int type_) { position = position_; angle = angle_; type = type_; if (type == 0) //flamer { angle += random(radians(-10), radians(10)); speed = 6; //= random(1, 2); strength = 8; maxLifeCount = 10; } else if (type == 1) //defender { angle += random(-1.6, 1.6); speed = 2.7; strength = 19; maxLifeCount = 7; } else if (type == 2) //machinegun { angle += random(-0.1, 0.1); speed = 6; // + random(0, 1); strength = 4; maxLifeCount = 22 + int(random(0, 4)); } else if (type == 3) //fargun { speed = 7; strength = 130; maxLifeCount = 40; } velocity = new Vector2D(speed, 0); velocity.rotateTo(angle); } void update() { position.add(velocity); /*float x = position.getX(); float y = position.getY(); if (x > 500) position.setX(0); if (y > 400) position.setY(0); if (x < 0) position.setX(500); if (y < 0) position.setY(400);*/ lifeCount ++; } int clean(int i) { if (lifeCount > maxLifeCount) { bullets = removeArrayItem(i, bullets); return 1; } return 0; } void draw() { pushMatrix(); translate(position.getX(), position.getY()); rotate(angle); if (type == 0) { noStroke(); fill(color(180 - (16*(lifeCount)), 70 - (5*(lifeCount)), 30 - (1*(lifeCount)))); rect (5, -5, 10, 10); //fill(color(200, 160, 50)); //rect (7, -3, 6 * (10-lifeCount)/10, 6 * (10-lifeCount)/10); } else if (type == 1) { noStroke(); fill(255, 240, 0); rect (5, -2, 4, 4); } else if (type == 2) { noStroke(); fill(255, 240, 0); rect (5, -1, 5, 2); } else if (type == 3) { noStroke(); fill(255, 255, 255); rect (5, -1, 9, 2); } popMatrix(); } } public BasicBullet[] removeArrayItem(int index, BasicBullet[] bullets) { if(index < bulletsCount) { bullets[index] = null; for(int i = index + 1;i < bulletsCount; i++) { bullets[i - 1] = bullets[i]; } bulletsCount--; } return bullets; }