I am writing a platformer and just programmed this class for a bullet. I am getting an NPE in the constructor and I can't see what is wrong, here is my code:
package com.ncom.src.entity;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;
import com.ncom.src.Camera;
import com.ncom.src.world.World;
public class Bullet extends HealthEntity {
public Vector2f velocity;
public double angle;
private int timeout = 0;
public Bullet(int lx, int ly, World w, float x, float y) {
super(lx, ly, 5, 5, w, 0);
double hyp = Math.sqrt((x - 600) * (x - 600) + (y - 400) * (y - 400));
angle = Math.asin(y - 400/ hyp);
velocity.y = (float) Math.sin(angle) * 0.4f;
velocity.x = (float) Math.cos(angle) * 0.4f;
}
@Override
public void render(Graphics g, Camera c) throws SlickException {
g.drawImage(new Image("res/actors/bullet.png"), locationX + c.camModX, locationY + c.camModY);
}
@Override
public void update(GameContainer gc, int delta) throws SlickException {
if (timeout > 400) {
this.dead = true;
}
else {
locationX += velocity.x;
locationY += velocity.y;
timeout += 0.4f;
}
}
}
I am basically trying to calculate the x component and the y component of a vector to move the bullet by. The x and y in the constructor stand for where the mouse was clicked.