Skip to content

Commit a622bce

Browse files
committed
Added angles for projectiles
Calculated the angle the mouse is from the player on screen.
1 parent a334c35 commit a622bce

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/com/redomar/game/MouseHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public int getButton() {
2828
}
2929

3030
public void mouseDragged(MouseEvent e) {
31-
31+
mouseX = e.getX();
32+
mouseY = e.getY();
3233
}
3334

3435
public void mouseMoved(MouseEvent e) {

src/com/redomar/game/entities/Mob.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.redomar.game.level.Node;
88
import com.redomar.game.level.tiles.Tile;
99
import com.redomar.game.lib.utils.Vector2i;
10+
import com.redomar.game.script.PrintTypes;
11+
import com.redomar.game.script.Printing;
1012

1113
public abstract class Mob extends Entity {
1214

@@ -209,6 +211,12 @@ protected void moveMob(double xa, double ya, Mob mob) {
209211
mob.isMoving = false;
210212
}
211213
}
214+
215+
protected void shoot(double x, double y, double dir){
216+
Printing print = new Printing();
217+
dir = dir * (180 /Math.PI);
218+
print.print("Angle: "+ dir, PrintTypes.GAME);
219+
}
212220

213221
public String getName() {
214222
return name;

src/com/redomar/game/entities/Player.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ public void tick() {
5656
xa += speed;
5757
}
5858
}
59+
60+
if (Game.getMouse().getButton() == 1){
61+
double dx = Game.getMouse().getX() - 480/2;
62+
double dy = Game.getMouse().getY() - 320/2;
63+
double dir = Math.atan2(dy, dx);
64+
shoot(x, y, dir);
65+
}
5966

6067
if (xa != 0 || ya != 0) {
6168
move(xa, ya);

0 commit comments

Comments
 (0)