Math for Game Developers - Character Movement (Points and Vectors)
package learn.mathforgame.PointsandVectors;
public class Main {
public static void main(String[] args) {
Point p = new Point(1, 0);
Vector v = new Vector(2, 3);
Point p2 = p.addVector(v);
System.out.println("Result: "+p2);
}
}
Point class:
package learn.mathforgame.PointsandVectors;
public class Point {
private int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public Point addVector(Vector v) {
return new Point(x + v.getX(), y+v.getY());
}
@Override
public String toString() {
return x +", "+y;
}
}
Vector class:
package learn.mathforgame.PointsandVectors;
public class Vector {
private int x, y;
public Vector(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
}
No comments:
Post a Comment