I have imported the following Vec2 class into my project:
http://www.johnloomis.org/ece538/notes/java1/Vec2.java.htmlI'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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| public class Avatar extends Sprite { protected int hitPoints; protected int attackTime = 100; 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(); } }
public void dead(){ } @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
