Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Vector2D class
- public class Vector2D {
- double x, y;
- Vector2D(){
- x = y = 0;
- };
- Vector2D(double _x, double _y){
- x = _x;
- y = _y;
- };
- double Length(){
- return Math.sqrt(x*x + y*y);
- };
- Vector2D add(Vector2D v) {
- return new Vector2D(x + v.x, y + v.y);
- };
- Vector2D minus(Vector2D v) {
- return new Vector2D(x - v.x, y - v.y);
- };
- void normalize(){
- double len = Length();
- if( len != 0 )
- {
- x /= len;
- y /= len;
- }
- };
- void setLength(double value)
- {
- normalize();
- x *= value;
- y *= value;
- };
- void scale(double f)
- {
- double x2 = x;
- double y2 = y;
- normalize();
- x = x2*f;
- y = y2*f;
- };
- void rotate(double theta, double cx, double cy)
- {
- double sin = Math.sin(theta);
- double cos = Math.cos(theta);
- double dx = x-cx;
- double dy = y-cy;
- x = cx+(dx)*cos-(dy)*sin;
- y = cy+(dy)*cos+(dx)*sin;
- };
- Vector2D normal()
- {
- return new Vector2D(x,-y);
- };
- // the dot product implemented as class function
- static double dot(Vector2D v1, Vector2D v2)
- {
- return v1.x*v2.x+v1.y*v2.y;
- };
- };
- // Player class
- public class Player{
- // variables
- //What i did was to create a private variable from the class above ^
- private Vector2D playerPosition;
- public Vector2D getPlayerPosition(){
- return playerPosition;
- };
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement