0

I have a Java final, and I would like to make a bullet hell type game, but what I'm stumped on is how to make the projectiles move. My first idea would be to constantly update the projectile; I just don't know how to do that. Any ideas?

//outer polygon
g.setColor(Color.ORANGE);
Polygon projectile = new Polygon();
projectile.addPoint(220,100);
projectile.addPoint(224,106);
projectile.addPoint(227,110);
projectile.addPoint(227,128);
projectile.addPoint(222,140);
projectile.addPoint(216,140);
projectile.addPoint(208,128);
projectile.addPoint(208,110);
projectile.addPoint(213,104);
projectile.addPoint(215,100);
g.fillPolygon(projectile);

//inner polygon, like a highlight
g.setColor(Color.CYAN);
Polygon innerColor = new Polygon();
int scaleFactor = 80; 
double scale = scaleFactor / 100.0;
for (int i = 0; i < projectile.npoints; i++) {
    int smallX = (int) ((projectile.xpoints[i] - 220) * scale);
    int smallY = (int) ((projectile.ypoints[i] - 120) * scale);
    int x = 220 + smallX;
    int y = 120 + smallY;
    innerColor.addPoint(x, y);
}
g.fillPolygon(innerColor);
camickr
  • 321,443
  • 19
  • 166
  • 288
shge
  • 21
  • 7
  • Check out: https://stackoverflow.com/a/54028681/131872 for an example to get you started. It uses a Swing Timer to animate multiple objects. You will be able to simplify the logic. Note that your Polygon object should be created relative to offset (0, 0). Then in the painting method you would use the g.translate(...) method to move the object to its new location. Maybe you would even want to paint the projectile to a BufferedImage, then you can simply paint the image at its new location each time the Timer fires. This will be more efficient. – camickr May 23 '23 at 02:17
  • For [example](https://stackoverflow.com/questions/41785697/graphics-stuttering-in-java-space-invaders/41787291#41787291); [example](https://stackoverflow.com/questions/72411743/how-to-move-paint-graphics-along-slope/72412859#72412859); [example](https://stackoverflow.com/questions/35003520/program-not-painting-screen-properly/35004777#35004777); – MadProgrammer May 23 '23 at 03:03

0 Answers0