The function get(int) does not exist (solved)
in
Programming Questions
•
1 year ago
- float proClock = 0;
- ArrayList danmaku;
- float zeroClock = 0;
- void setup() {
- size(800, 800);
- danmaku = new ArrayList();
- danmaku.add(new Projectile(400, 200, 0, 0, 0, 5, 15, color(255, 0, 255), random(100)));
- }
- void draw() {
- background(0);
- zeroClock = zeroClock + 1;
- if (zeroClock%120 == 0 && zeroClock%240 !=0) {
- for (int i = 0; i < 20; i++)
- danmaku.add(new Projectile(400, 200, 360*float(i)/20, 2/(proClock+1), 0.2/(proClock+1), 5, 15, color(255, 0, 0), random(100)));
- }
- if (zeroClock%240 == 0) {
- for (int i = 0; i < 20; i++)
- danmaku.add(new Projectile(400, 200, 360*float(i)/20, 2/(proClock+1), -0.2/(proClock+1), 5, 15, color(0, 0, 255), random(100)));
- }
- for (int i = danmaku.size()-1; i > 0; i--) {
- Projectile danmaku = (Projectile) danmaku.get(i);
- danmaku.displace();
- danmaku.display();
- }
- }
- class Projectile {
- color col; // Color
- float dim; // Size
- float xpos; // Current horizontal position
- float ypos; // Current vertical position
- float radialSpeed; // Radial speed
- float angularSpeed; // Angular speed
- float hitBox; // Lethal range
- float x0; // Original horizontal position
- float y0; // Original verical position
- float initialAngle; // Original angle
- float identifier; // For transformations
- float proClock; // The projectile's clock
- // Constructor
- Projectile(float x, float y, float a0, float r, float a, float h, float s, color c, float i) {
- col = c;
- xpos = x;
- ypos = y;
- initialAngle = a0;
- radialSpeed = r;
- angularSpeed = a;
- hitBox = h;
- dim = s;
- x0 = x;
- y0 = y;
- identifier = i;
- proClock = 0;
- }
- // Display the projectile
- void display() {
- noStroke();
- fill(col);
- ellipseMode(CENTER);
- ellipse(xpos, ypos, dim, dim);
- fill(255);
- ellipse(xpos, ypos, 0.9*dim, 0.9*dim);
- }
- // Displace the projectile
- void displace() {
- proClock = proClock + 1;
- xpos = x0 + cos(radians(initialAngle + proClock*angularSpeed)) * radialSpeed * proClock;
- ypos = y0 + sin(radians(initialAngle + proClock*angularSpeed)) * radialSpeed * proClock;
- }
- // To implement: one less life
- /*
- void collide() {
- if (dist(charX, charY, xpos, ypos) < hitBox) {
- }
- }
- */
- // To implement: transformation into another projectile
- void transform() {
- }
- }
I reckon it's a problem with my danmaku ArrayList... but, being a beginning coder and having Googled the problem, I didn't manage to debug this.
The only think I did find on Google was this. I haven't been able to figure out whether it was relevant.
EDIT:
Showed this to a friend, she debugged it.
The problem lied in
- Projectile danmaku = danmaku.get(i);
1