我该怎么做子弹的旋转图案( java 语)

yuvru6vn  于 2021-07-09  发布在  Java
关注(0)|答案(0)|浏览(191)

因此,我有一个bullet类,其中包含以下代码,我希望能够通过从另一个类创建bullet来实现。我该怎么做呢。目前它看起来wierd而旋转,而不是只是跳转位置错误的旋转模式,我想看看这个正确的旋转模式

  1. public class Bullet extends GameObject{
  2. private Handler handler;
  3. float direction, curve, speed, acceleration;
  4. float dirX, dirY;
  5. public Bullet(int x, int y, ID id, Handler handler, float direction, float speed, float acceleration, float curve) {
  6. super(x, y, id);
  7. this.handler = handler;
  8. this.direction = direction;
  9. this.speed = speed;
  10. this.acceleration = acceleration;
  11. this.curve = curve;
  12. }
  13. public void tick() {
  14. direction = direction + curve;
  15. speed = speed + acceleration;
  16. dirX = (float) xDir(direction);
  17. dirY = (float) yDir(direction);
  18. x = (int) (x + dirX*speed);
  19. y = (int) (y + dirY*speed);
  20. }
  21. public static double xDir(float angle){
  22. double rad = angle * Math.PI/180;
  23. return Math.cos(rad);
  24. }
  25. public static double yDir(float angle){
  26. double rad = angle * Math.PI/180;
  27. return -Math.sin(rad);
  28. }
  29. public void render(Graphics g) {
  30. g.setColor(Color.magenta);
  31. g.fillOval(x, y, 8, 8);
  32. }
  33. public Rectangle getBounds() {
  34. return new Rectangle(x ,y, 8, 8);
  35. }
  36. }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题