/* PlayerBall class defines behaviours for the player-controlled ball child of Rectangle because that makes it easy to draw and check for collision In 2D GUI, basically everything is a rectangle even if it doesn't look like it! */ import java.awt.*; import java.awt.event.*; import java.io.IOException; public class GenericSprite extends Rectangle{ public double yVelocity; public double xVelocity; public final double SPEED = 20; //movement speed of ball public final double speedCapx = 50; public final double speedCapy = 20; public int WIDTH; //size of ball public int HEIGHT; //size of ball public boolean rightPressed = false; public boolean leftPressed = false; public boolean upPressed= false; public boolean downPressed = false; public boolean isGrounded = false; public boolean isPlayer = false; //constructor creates ball at given location with given dimensions // TODO: reverse order of height and width public GenericSprite(int x, int y, int height, int width){ super(x, y, width, height); WIDTH = width; HEIGHT = height; } //called from GamePanel when any keyboard input is detected //updates the direction of the ball based on user input //if the keyboard input isn't any of the options (d, a, w, s), then nothing happens public void keyPressed(KeyEvent e){ } //called from GamePanel when any key is released (no longer being pressed down) //Makes the ball stop moving in that direction public void keyReleased(KeyEvent e){ } //called from GamePanel whenever a mouse click is detected //changes the current location of the ball to be wherever the mouse is located on the screen public void mousePressed(MouseEvent e){ } public void move() throws IOException { } public void capSpeed(){ if(xVelocity>speedCapx){ xVelocity = speedCapx; } else if(xVelocity<-1*speedCapx) { xVelocity = -1*speedCapx; } if(yVelocity>speedCapy){ yVelocity = speedCapy; } else if(yVelocity<-1*speedCapy) { yVelocity = -1*speedCapy; } } private boolean collide(Tile tile, double x, double y){ if(!tile.collision){ return false; } if(x+WIDTH>tile.x&&x