Skip to content

Commit

Permalink
use x and y coordinates instead of absolute directions
Browse files Browse the repository at this point in the history
  • Loading branch information
UninterestinAcc committed Oct 24, 2017
1 parent 8d79820 commit b5b1c44
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions src/me/vrekt/lunar/physics/Velocity.java
Original file line number Diff line number Diff line change
@@ -1,39 +1,61 @@
package me.vrekt.lunar.physics;

import me.vrekt.lunar.world.dir.Direction;
import java.util.Optional;

// This can potentially relocate into {project}.world.physics.* if we end up using this solely in World.

/**
* This object can potentially be passed into World and create custom variable velocity.
*
* X and Y velocites should be <i>per second</i> or <i>per tick</i>, we should decide on that perhapes...
*/
public class Velocity {
private Direction direction;
// If these optionals are not set then y velocity is not touched. x==0 would be down and y==0 would be left and so on... These velocity values should be absolute and not relative, and should not be update every tick, or decay.
// Technically we can use null but using null to represent something is really icky for me
private Optional<Double> directionX;
private Optional<Double> directionY;

private float magnitude;

/**
* Creates velocity object based on the direction and magnitude.
* Creates velocity object based on the direction (x and y) and magnitude.
*/
public Velocity(Direction direction, float magnitude) {
this.direction = direction;
public Velocity(Optional<Double> directionX, Optional<Double> directionY, float magnitude) {
this.directionX = directionX;
this.directionY = directionY;
this.magnitude = magnitude;
}

/**
* Gets the direction velocity is currently pointing at.
* Gets the X component of the velocity.
*/
public Optional<Double> getDirectionX() {
return directionX;
}

/**
* Sets the X component of the velocity.
*/
public void setDirectionX(Optional<Double> directionX) {
this.directionX = directionX;
}

/**
* Gets the Y component of the velocity.
*/
public Direction getDirection() {
return direction;
public Optional<Double> getDirectionY() {
return directionY;
}

/**
* Sets the direction that the game's velocity will point at.
* Sets the Y component of the velocity.
*/
public void setDirection(Direction direction) {
this.direction = direction;
public void setDirectionY(Optional<Double> directionY) {
this.directionY = directionY;
}

/**
* Gets the acceleration constant of velocity.
* Gets the magnitude of velocity.
*/
public float getMagnitude() {
return magnitude;
Expand Down

0 comments on commit b5b1c44

Please sign in to comment.