Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Weapons;
- import Game.Game;
- import org.newdawn.slick.*;
- import org.newdawn.slick.geom.Rectangle;
- import Graphics.TextureLoader;
- import org.newdawn.slick.Image;
- /**
- * Created by Haveit on 10/23/2014.
- */
- public class Arrow extends Projectiles{
- private float positionX, positionY;
- private Rectangle shape;
- private Image image;
- private float width = 20, height = 20;
- private float velocityX, velocityY;
- private float gravity = 0.1f;
- private float airResitance = 0.01f;
- private float angle;
- public Rectangle getShape() {
- return shape;
- }
- public Image getImage() {
- return image;
- }
- public float getAngle() {
- return angle;
- }
- public float getPositionX() {
- return positionX;
- }
- public float getPositionY() {
- return positionY;
- }
- public Arrow(float arX, float arY, float mouseX, float mouseY, long speed) {
- super(arX, arY, mouseX, mouseY, speed);
- this.shape = new Rectangle(this.positionX, this.positionY,this.width, this.height);
- image = new Image(TextureLoader.getInstance().getInstance().arrow);
- /*speed /= 50;
- if(speed > 15)
- speed=15;
- System.out.println(speed);
- this.positionX = arX;
- this.positionY = arY;
- this.velocityX = - (float) ((-(mouseX-arX))/(Math.sqrt((mouseX-arX)*(mouseX-arX) + (mouseY-arY)*(mouseY-arY))));
- this.velocityY = Math.abs((1 - Math.abs(velocityX))*(mouseY-arY))/(mouseY-arY);
- velocityX *= speed;
- velocityY *= speed;
- *//*
- if(velocityX > speed)
- velocityX = speed;
- if(velocityY > speed)
- velocityY = speed;*//*
- if(velocityX>0)
- this.airResitance = -airResitance;
- this.shape = new Rectangle(positionX, positionY, width, height);
- *//* 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");
- System.out.println(velocityX + " ; " + velocityY);*/
- }
- public void update(long deltaTime) {
- // System.out.println(velocityX + ";" +velocityY +";" +positionX +";" +positionY);
- if(velocityY != 0) {
- Collisions();
- if (velocityX == 0) {
- } else if (velocityX > 0 && airResitance > 0) {
- velocityX = 0;
- } else if (velocityX < 0 && airResitance < 0) {
- velocityX = 0;
- } else
- velocityX += airResitance * deltaTime;
- if (velocityY != 0)
- velocityY += gravity * deltaTime;
- positionX += velocityX * deltaTime;
- positionY += velocityY * deltaTime;
- shape.setX(positionX);
- shape.setY(positionY);
- }
- }
- private void Collisions() {
- if(Game.getInstance().getBlocks().size() != 0) {
- for (int i = 0; i < Game.getInstance().getBlocks().size(); i++) {
- if (Game.getInstance().getBlocks().get(i).getShape().contains(positionX, positionY) || Game.getInstance().getBlocks().get(i).getShape().includes(positionX, positionY)) {
- velocityY = 0;
- velocityX = 0;
- break;
- }
- }
- }
- }
- public void render(Graphics gr) {
- gr.translate(69,87);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement