Loading...
Logo
Processing Forum
Copy code
  1. float proClock = 0;
  2. ArrayList danmaku;
  3. float zeroClock = 0;
  4. void setup() {
  5.   size(800, 800);
  6.   danmaku = new ArrayList();
  7.   danmaku.add(new Projectile(400, 200, 0, 0, 0, 5, 15, color(255, 0, 255), random(100)));
  8. }
  9. void draw() {
  10.   background(0);
  11.   zeroClock = zeroClock + 1;
  12.   if (zeroClock%120 == 0 && zeroClock%240 !=0) {
  13.     for (int i = 0; i < 20; i++)
  14.       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)));
  15.   }
  16.   if (zeroClock%240 == 0) {
  17.     for (int i = 0; i < 20; i++)
  18.       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)));
  19.   }
  20.   for (int i = danmaku.size()-1; i > 0; i--) {
  21.     Projectile danmaku = (Projectile) danmaku.get(i);
  22.     danmaku.displace();
  23.     danmaku.display();
  24.   }
  25. }
  26. class Projectile {
  27.   color col; // Color
  28.   float dim; // Size
  29.   float xpos; // Current horizontal position
  30.   float ypos; // Current vertical position
  31.   float radialSpeed; // Radial speed
  32.   float angularSpeed; // Angular speed
  33.   float hitBox; // Lethal range
  34.   float x0; // Original horizontal position
  35.   float y0; // Original verical position
  36.   float initialAngle; // Original angle
  37.   float identifier; // For transformations
  38.   float proClock; // The projectile's clock
  39.     // Constructor
  40.   Projectile(float x, float y, float a0, float r, float a, float h, float s, color c, float i) {
  41.     col = c;
  42.     xpos = x;
  43.     ypos = y;
  44.     initialAngle = a0;
  45.     radialSpeed = r;
  46.     angularSpeed = a;
  47.     hitBox = h;
  48.     dim = s;
  49.     x0 = x;
  50.     y0 = y;
  51.     identifier = i;
  52.     proClock = 0;
  53.   }
  54.   // Display the projectile
  55.   void display() {
  56.     noStroke();
  57.     fill(col);
  58.     ellipseMode(CENTER);
  59.     ellipse(xpos, ypos, dim, dim);
  60.     fill(255);
  61.     ellipse(xpos, ypos, 0.9*dim, 0.9*dim);
  62.   }
  63.   // Displace the projectile
  64.   void displace() {
  65.     proClock = proClock + 1;
  66.     xpos = x0 + cos(radians(initialAngle + proClock*angularSpeed)) * radialSpeed * proClock;
  67.     ypos = y0 + sin(radians(initialAngle + proClock*angularSpeed)) * radialSpeed * proClock;
  68.   }
  69.   // To implement: one less life
  70.   /*
  71.   void collide() {
  72.    if (dist(charX, charY, xpos, ypos) < hitBox) {
  73.    }
  74.    }
  75.    */
  76.   // To implement: transformation into another projectile
  77.   void transform() {
  78.   }
  79. }
A priori, the Projectile class works fine. However, when I run this code, Line 21: "The function get(int) does not exist."
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
Copy code
  1. Projectile danmaku = danmaku.get(i);
(variable and ArrayList sharing the same name).