//************************************************************************************* //********************** Paddle Object************************************************ //************************************************************************************* class Paddle { private int width; private int height; private int speed; //The speed that the paddle moves at private int paddle_delta; //How much to move the paddle +speed, -speed or zero private int table_top_edge; //Top edge of the playing "table" private int table_bottom_edge; //Top edge of the playing "table" public int pos_x; //The current position of the upper left corner of the paddle public int pos_y; public int last_pos_x; //The last position of the upper left corner of the paddle public int last_pos_y; public int top_edge; //The y value of the top edge of this paddle public int bottom_edge; //The y value of the bottom edge of this paddle public int left_edge; //The x value of the left edge of this paddle public int right_edge; //The x value of the right edge of this paddle //********************* Constructor ************************************ Paddle (int width, int height, int table_top_edge, int table_bottom_edge) { this.width = width; this.height = height; this.table_top_edge = table_top_edge; this.table_bottom_edge = table_bottom_edge; } //*************************** move_paddle ************************************ public void move() { last_pos_x = pos_x; last_pos_y = pos_y; pos_y += paddle_delta; calc_edges(); if ( (bottom_edge > table_bottom_edge) || (top_edge < table_top_edge) ) pos_y = last_pos_y; } //********************* set_paddle_delta *************************** public void set_paddle_direction(int direction) { paddle_delta = (speed * direction); } //********************* set_speed *********************************** public void set_speed(int speed) { this.speed = speed; } //********************* jump_to *********************************** public void jump_to(int x, int y) { pos_x = x; pos_y = y; calc_edges(); } //********************* center *********************************** public void center() { pos_y = (table_bottom_edge/2)-(height/2); 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 Paddle Object *****************************************************