Commit b3120308 authored by Derek Xu's avatar Derek Xu
Browse files

Add sprites in res/drawable and javadocs for joystick

parent 9e1f3f98
Loading
Loading
Loading
Loading
+55 −6
Original line number Diff line number Diff line
@@ -23,6 +23,13 @@ public class Joystick {
    public double XVelocity;
    public double YVelocity;

    /**
     * Constructs a Joystick instance
     * @param CenterPositionX X position of the joystick
     * @param CenterPositionY Y position of the joystick
     * @param outerCircleRad Radius of outer circle of joystick
     * @param innerCircleRad Radius of inner circle of joystick
     */
    public Joystick(int CenterPositionX, int CenterPositionY, int outerCircleRad, int innerCircleRad){
        outerCircleCenterX = CenterPositionX;
        outerCircleCenterY = CenterPositionY;
@@ -40,6 +47,10 @@ public class Joystick {
        innerCirclePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    }

    /**
     * Draws the joystick onto the given canvas
     * @param canvas The canvas object to draw on
     */
    public void draw(Canvas canvas) {
        //outer
        canvas.drawCircle(
@@ -57,35 +68,62 @@ public class Joystick {
        );
    }

    /**
     * Updates the given joystick and updates the x and y velocities that are outputted from user input
     * @param joystick Joystick instance to update
     */
    public void update(Joystick joystick) {
        XVelocity = joystick.getActuatorX() * MAX_SPEED;
        YVelocity = joystick.getActuatorY() * MAX_SPEED;
        updateInnerCirclePosition();
    }

    /**
     * Updates the inner circle of the joystick
     */
    public void updateInnerCirclePosition() {
        innerCircleCenterX = (int) (outerCircleCenterX + actuatorX * outerCircleRadii);
        innerCircleCenterY = (int) (outerCircleCenterY + actuatorY * outerCircleRadii);
    }

    public boolean isPressed(double TouchPosx,double TouchPosy) {
        joystickCenterToTouchDistance = Math.sqrt(Math.pow(outerCircleCenterX-TouchPosx,2) +
                Math.pow(outerCircleCenterY-TouchPosy,2)
    /**
     * Checks whether the joystick has been touched by the user
     * @param TouchPosX X position of the user's touch
     * @param TouchPosY Y position of the user's touch
     * @return True if the joystick has been pressed
     */
    public boolean isPressed(double TouchPosX,double TouchPosY) {
        joystickCenterToTouchDistance = Math.sqrt(Math.pow(outerCircleCenterX-TouchPosX,2) +
                Math.pow(outerCircleCenterY-TouchPosY,2)
        );
        return  joystickCenterToTouchDistance < outerCircleRadii;
    }

    /**
     * Set the joystick to be pressed or not pressed
     * @param isPressed Boolean for whether the joystick is pressed
     */
    public void setIsPressed(boolean isPressed) {
        this.isPressed = isPressed;
    }

    /**
     *
     * @return True if the joystick is pressed
     */
    public boolean getIsPressed() {
        return isPressed;
    }

    public void setActuator(double TouchPosx,double TouchPosy) {
        double deltaX = TouchPosx - outerCircleCenterX;
        double deltaY = TouchPosy - outerCircleCenterY;
    /**
     * Sets the value of actuation depending on how far away the user touches from the center
     * of the joystick.
     * @param TouchPosX X position of the user touch
     * @param TouchPosY Y position of the user touch
     */
    public void setActuator(double TouchPosX,double TouchPosY) {
        double deltaX = TouchPosX - outerCircleCenterX;
        double deltaY = TouchPosY - outerCircleCenterY;
        double deltaDistance = Math.sqrt(Math.pow(deltaX, 2) + Math.pow(deltaY,2));

        if(deltaDistance < outerCircleRadii) {
@@ -98,15 +136,26 @@ public class Joystick {

    }

    /**
     * Resets the value of actuation to 0
     */
    public void resetActuator() {
        actuatorX = 0.0;
        actuatorY = 0.0;
    }

    /**
     *
     * @return The x value of actuation
     */
    public double getActuatorX() {
        return actuatorX;
    }

    /**
     *
     * @return The Y value of actuation
     */
    public double getActuatorY() {
        return actuatorY;
    }
+378 B
Loading image diff...
+179 B
Loading image diff...
+399 B
Loading image diff...
+321 B
Loading image diff...