I have imported the following Vec2 class into my project:
http://www.johnloomis.org/ece538/notes/java1/Vec2.java.html
I’m currently playing with the use of vectors as I am new to them.
I can’t seem to get the vector to draw using the Vec2.draw() method unless it is left in it’s constructed default position (0,0).
This is my code:
public class Avatar extends Sprite
{
protected int hitPoints;
protected int attackTime = 100; //ms
protected int strength;
protected boolean isAttack = false;
Vec2 normal = new Vec2(posX, posY);
public Avatar (int x, int y, int w, int h, int s, int hp, int str){
super(w/2, h/2, w, h, s);
hitPoints = hp;
strength = str;
}
public void moveLeft()
{posX-=step;}
public void moveRight()
{posX+=step;}
public void moveUp()
{posY-=step;}
public void moveDown()
{posY+=step;}
public void attack(){
if(isAttack)
{isAttack = false;}
else
isAttack = true;
System.out.println(normal.length());
}
public void isHit(int str){
hitPoints-=str;
if(hitPoints<= 0){
this.dead();
}//endif
}
public void dead(){
//called when player hp <=0
}
@Override
public void drawSprite(Graphics g){
if(isAttack){
g.setColor(Color.blue);
g.fillOval(posX - 10, posY - 10, 30, 30);
g.setColor(Color.black);
}
if(isActive()){
g.setColor(Color.orange);
g.fillOval(posX, posY, 10, 10);
g.setColor(Color.black);
}
normal.draw(g);
}
}
I have checked its length with a print line and it returns two every time but does not draw to the canvas, I called its draw() method last to ensure it is drawn last (on top), but that doesn’t seem to make a difference.
Any help would be much appreciated