From b3120308d66e099a8b462be72f2a4f6c4a4f0265 Mon Sep 17 00:00:00 2001 From: DerekXu Date: Thu, 13 Apr 2023 21:46:18 -0400 Subject: [PATCH] Add sprites in res/drawable and javadocs for joystick --- .../com/example/a8_bitinvader/Joystick.java | 61 ++++++++++++++++-- app/src/main/res/drawable/axolotel.png | Bin 0 -> 378 bytes app/src/main/res/drawable/bullet.png | Bin 0 -> 179 bytes app/src/main/res/drawable/enemy1.png | Bin 0 -> 399 bytes app/src/main/res/drawable/player.png | Bin 0 -> 321 bytes 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 app/src/main/res/drawable/axolotel.png create mode 100644 app/src/main/res/drawable/bullet.png create mode 100644 app/src/main/res/drawable/enemy1.png create mode 100644 app/src/main/res/drawable/player.png 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 40b54f5..27370fb 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 GIT binary patch literal 378 zcmV-=0fqjFP)pSG-u+?#=D0JsQ|Yi0nsxAtKd+y&MJ*1k6Y z)qb7R!TA{Vhi+Z(Ho4`%``jJS4=|C@foK3M;ZY1AV$i|NC=I`3{(z)(sEx0)KCM%CIgiPU{ycw^LNG9 z43q|d9b5C<7YMhxsf22J`Ch0}z`x63R8-^&h&c_T0SKiy)GqkHVd#Zs4HV_r*H3f? Yp2Qwr!01dnumAu607*qoM6N<$g4af=RR910 literal 0 HcmV?d00001 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 GIT binary patch literal 179 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=ffJDo+>3kO=qWlm!BR>`(lYzsceD zdw$On3C~GMIc)t_4et~i@)Q^TP@AIW;m5p~PohR~!B-hm$(YG54=>yC_E#>KW9tRZpVyKn6!o8xrBr&akkKQL(b?Hgk)Pf{Ohs1_ptN6^aHP SO=Un=FnGH9xvXj1)puud%Pf~!KIZ4D%YaVL=6FN3T)z&*?WFw;ULqtW(xjH))1&%0h_r% zV6j`9omo!i=2v+@;YknFmH<~CANHp5a5Vm@L}?0CP5?~Nay;XU5@6hv2fPvB#8JPS z7;?As(U9f#<1WA=bVH{{Ggcn@n*xc3|kt?ukoRxqw84|Gj0mz4$QjEJK trGR$=in;BQ%IjR?o#%inpc=WVuqXYUJy1a^2MGWG002ovPDHLkV1nwYtMLE; literal 0 HcmV?d00001 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 GIT binary patch literal 321 zcmV-H0lxl;P))dyn-XnL7Y$4R?JFRNi~@7s6D