You can better NOT follow tutorials in my opinion. You should try to make it from scratch. Much better that way. This way you will learn how you can start a project, what is needed, and how it should work (draw it out on paper, helps!). And just google as much as you can, this is the way im making my towerdefence. I've just started with java 1-2 weeks as well, but at least i know exactly what im doing, and thus can fine tune it much more, and make it much more to my liking.
Also dont just give up when people help you so much. These are the moments where you build personality. You find a problem, solve it. Dont dodge it!
how ive done it:
first i calculate the angle, using the coordinates where my arrow has to go to (This should be your enemy's coordinates) which i give in my constructor:
1
| this.angle = Math.atan2(toY-Y_Position, toX-X_Position); |
Then in my draw function:
1 2 3 4 5 6 7
| public void draw(Graphics g){ Graphics2D g2d = (Graphics2D)g; g2d.rotate(angle-Math.toDegrees(90), getX_Position(), getY_Position()); g2d.drawImage(image,getX_Position(),getY_Position(),null); g2d.rotate(-angle+Math.toDegrees(90), getX_Position(), getY_Position()); } |
i do the -90 because of the way my image is turned (its looking up) and then i invoke the function g2d.rotate one more time so everything else in my game draws using the right rotation.