diff --git a/app/src/main/java/com/example/a8_bitinvader/Joystick.java b/app/src/main/java/com/example/a8_bitinvader/Joystick.java index 40b54f5a4fd90bcdfadc4e0b693e8b2b50057d1b..27370fb1dce6f8ff0f50675fae5f19ef83490b96 100644 --- a/app/src/main/java/com/example/a8_bitinvader/Joystick.java +++ b/app/src/main/java/com/example/a8_bitinvader/Joystick.java @@ -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; } diff --git a/app/src/main/res/drawable/axolotel.png b/app/src/main/res/drawable/axolotel.png new file mode 100644 index 0000000000000000000000000000000000000000..a95c70d87b88cfb741ea358759da6c7c2e16cb10 Binary files /dev/null and b/app/src/main/res/drawable/axolotel.png differ diff --git a/app/src/main/res/drawable/bullet.png b/app/src/main/res/drawable/bullet.png new file mode 100644 index 0000000000000000000000000000000000000000..ee172dc46e184a1a99b566a2dbd156a9b8872495 Binary files /dev/null and b/app/src/main/res/drawable/bullet.png differ diff --git a/app/src/main/res/drawable/enemy1.png b/app/src/main/res/drawable/enemy1.png new file mode 100644 index 0000000000000000000000000000000000000000..145dbb3fc9fa179929f4be206c8213f37b006431 Binary files /dev/null and b/app/src/main/res/drawable/enemy1.png differ diff --git a/app/src/main/res/drawable/player.png b/app/src/main/res/drawable/player.png new file mode 100644 index 0000000000000000000000000000000000000000..85a80706d0e412ce7c66ce4b15661177b592ded6 Binary files /dev/null and b/app/src/main/res/drawable/player.png differ