Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. package Weapons;
  2.  
  3.  
  4. import Game.Game;
  5. import org.newdawn.slick.*;
  6. import org.newdawn.slick.geom.Rectangle;
  7. import Graphics.TextureLoader;
  8. import org.newdawn.slick.Image;
  9.  
  10. /**
  11. * Created by Haveit on 10/23/2014.
  12. */
  13.  
  14. public class Arrow extends Projectiles{
  15. private float positionX, positionY;
  16. private Rectangle shape;
  17. private Image image;
  18. private float width = 20, height = 20;
  19. private float velocityX, velocityY;
  20. private float gravity = 0.1f;
  21. private float airResitance = 0.01f;
  22. private float angle;
  23.  
  24. public Rectangle getShape() {
  25. return shape;
  26. }
  27.  
  28. public Image getImage() {
  29. return image;
  30. }
  31.  
  32.  
  33. public float getAngle() {
  34. return angle;
  35. }
  36.  
  37. public float getPositionX() {
  38. return positionX;
  39. }
  40.  
  41. public float getPositionY() {
  42. return positionY;
  43. }
  44.  
  45. public Arrow(float arX, float arY, float mouseX, float mouseY, long speed) {
  46. super(arX, arY, mouseX, mouseY, speed);
  47. this.shape = new Rectangle(this.positionX, this.positionY,this.width, this.height);
  48. image = new Image(TextureLoader.getInstance().getInstance().arrow);
  49. /*speed /= 50;
  50. if(speed > 15)
  51. speed=15;
  52. System.out.println(speed);
  53. this.positionX = arX;
  54. this.positionY = arY;
  55. this.velocityX = - (float) ((-(mouseX-arX))/(Math.sqrt((mouseX-arX)*(mouseX-arX) + (mouseY-arY)*(mouseY-arY))));
  56. this.velocityY = Math.abs((1 - Math.abs(velocityX))*(mouseY-arY))/(mouseY-arY);
  57. velocityX *= speed;
  58. velocityY *= speed;
  59. *//*
  60. if(velocityX > speed)
  61. velocityX = speed;
  62. if(velocityY > speed)
  63. velocityY = speed;*//*
  64. if(velocityX>0)
  65. this.airResitance = -airResitance;
  66. this.shape = new Rectangle(positionX, positionY, width, height);
  67. *//* System.out.println(-Math.abs(mouseY - arY) / (mouseY - arY) * Math.toDegrees(Math.PI / 2 + Math.PI / 2 * (-(mouseX - arX)) / (Math.sqrt((mouseX - arX) * (mouseX - arX) + (mouseY - arY) * (mouseY - arY)))) + " degrees");
  68. System.out.println(velocityX + " ; " + velocityY);*/
  69.  
  70. }
  71.  
  72. public void update(long deltaTime) {
  73. // System.out.println(velocityX + ";" +velocityY +";" +positionX +";" +positionY);
  74. if(velocityY != 0) {
  75. Collisions();
  76. if (velocityX == 0) {
  77. } else if (velocityX > 0 && airResitance > 0) {
  78. velocityX = 0;
  79. } else if (velocityX < 0 && airResitance < 0) {
  80. velocityX = 0;
  81. } else
  82. velocityX += airResitance * deltaTime;
  83. if (velocityY != 0)
  84. velocityY += gravity * deltaTime;
  85. positionX += velocityX * deltaTime;
  86. positionY += velocityY * deltaTime;
  87.  
  88. shape.setX(positionX);
  89. shape.setY(positionY);
  90. }
  91. }
  92.  
  93. private void Collisions() {
  94. if(Game.getInstance().getBlocks().size() != 0) {
  95. for (int i = 0; i < Game.getInstance().getBlocks().size(); i++) {
  96. if (Game.getInstance().getBlocks().get(i).getShape().contains(positionX, positionY) || Game.getInstance().getBlocks().get(i).getShape().includes(positionX, positionY)) {
  97. velocityY = 0;
  98. velocityX = 0;
  99. break;
  100. }
  101. }
  102. }
  103. }
  104.  
  105. public void render(Graphics gr) {
  106. gr.translate(69,87);
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement