//************************************************************************************* //************************************************************************************* //*************************** Ball Class ********************************************* //************************************************************************************* //************************************************************************************* class Ball { private int width; private int height; private int delta_x = 1; //The delta value of the ball(speed and direction) private int delta_y = 1; public int pos_x; //The current position of the upper left corner of the ball public int pos_y; public int last_pos_x; //The current position of the upper left corner of the ball public int last_pos_y; public int top_edge; //The y value of the top edge of this ball public int bottom_edge; //The y value of the bottom edge of this balll public int left_edge; //The x value of the left edge of this ball public int right_edge; //The x value of the right edge of this ball //********************* Constructor ************************************ Ball(int width, int height) { this.width = width; this.height = height; } //*************************** move_ball ************************************ public void move() { last_pos_x = pos_x; last_pos_y = pos_y; pos_x += delta_x; pos_y += delta_y; calc_edges(); } //********************* flip_horz_dir *********************************** public void flip_horz_direction() { delta_x *= -1; pos_x += delta_x; } //********************* flip_vert_dir *********************************** public void flip_vert_direction() { delta_y *= -1; pos_y += delta_y; } //********************* set_speed *********************************** public void set_speed(int ball_speed) { // Ball delta = sign of ball delta (-/+) * the new ball speed delta_x = (delta_x / Math.abs(delta_x) ) * ball_speed; delta_y = (delta_y / Math.abs(delta_y) ) * ball_speed; } //********************* jump_to *********************************** public void jump_to(int x, int y) { pos_x = x; pos_y = y; calc_edges(); } //********************* calc_edges *********************************** public void calc_edges() { top_edge = pos_y; bottom_edge = pos_y + height; left_edge = pos_x; right_edge = pos_x + width; } } //******** End of Ball Object *****************************************************