Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Drawing;
- namespace AnimatedBalls
- {
- /// <summary>
- /// Enumerated values for the direction of the ball
- /// </summary>
- public enum Direction
- {
- LEFT, RIGHT, UP, DOWN, UP_LEFT, UP_RIGHT, DOWN_LEFT, DOWN_RIGHT
- }
- /// <summary>
- /// The ball class
- /// </summary>
- public class Ball
- {
- #region Private Variables
- private Color _ballColor;
- private int _x;
- private int _y;
- private int _height;
- private int _width;
- private Direction _xDirection;
- private Direction _yDirection;
- private Direction _ballDirection;
- private int _speed;
- #endregion
- #region Properties
- public Color BallColor
- {
- set
- {
- _ballColor = value;
- }
- get
- {
- return _ballColor;
- }
- }
- public int X
- {
- set
- {
- _x = value;
- }
- get
- {
- return _x;
- }
- }
- public int Y
- {
- set
- {
- _y = value;
- }
- get
- {
- return _y;
- }
- }
- public int Height
- {
- set
- {
- _height = value;
- }
- get
- {
- return _height;
- }
- }
- public int Width
- {
- set
- {
- _width = value;
- }
- get
- {
- return _width;
- }
- }
- public Direction XDirection
- {
- set
- {
- _xDirection = value;
- }
- get
- {
- return _xDirection;
- }
- }
- public Direction YDirection
- {
- set
- {
- _yDirection = value;
- }
- get
- {
- return _yDirection;
- }
- }
- public Direction BallDirection
- {
- set
- {
- _ballDirection = value;
- }
- get
- {
- return _ballDirection;
- }
- }
- public int Speed
- {
- set
- {
- _speed = value;
- }
- get
- {
- return _speed;
- }
- }
- #endregion
- public Ball()
- {
- //
- // Constructor
- //
- }
- public void DrawBall(Graphics g)
- {
- g.DrawEllipse(new Pen(_ballColor), _x, _y, _width, _height);
- // Create solid brush.
- SolidBrush redBrush = new SolidBrush(_ballColor);
- // Fill ellipse on screen.
- g.FillEllipse(redBrush, _x, _y, _width, _height);
- // for (int conta = 0; conta < 600000; conta++)
- // for (int conta1 = 0; conta1 < 500; conta1++) ;
- }
- public void DrawBall(Graphics g, int move_x, int move_y)
- {
- _x = move_x;
- _y = move_y;
- DrawBall(g);
- }
- public void MoveBall(Ball ball, int screenHeight, int screenWidth)
- {
- // Check Boundary
- // Check Direction
- // if ball hits boundary
- // check direction
- switch (ball._ballDirection)
- {
- case Direction.UP:
- ball._y = ball._y - ball._speed;
- break;
- case Direction.DOWN:
- ball._y = ball._y + ball._speed;
- break;
- case Direction.LEFT:
- ball._x = ball._x - ball._speed;
- break;
- case Direction.RIGHT:
- ball._x = ball._x + ball._speed;
- break;
- case Direction.DOWN_RIGHT:
- ball._x = ball._x + ball._speed;
- ball._y = ball._y + ball._speed;
- break;
- case Direction.UP_LEFT:
- ball._x = ball._x - ball._speed;
- ball._y = ball._y - ball._speed;
- break;
- case Direction.UP_RIGHT:
- ball._x = ball._x + ball._speed;
- ball._y = ball._y - ball._speed;
- break;
- case Direction.DOWN_LEFT:
- ball._x = ball._x - ball._speed;
- ball._y = ball._y + ball._speed;
- break;
- }
- // if ball hits any border then change direction
- // Ball touches TOP
- if (ball._y <= 0)
- {
- //ball._speed++;
- //ball._speed--;
- switch (ball._ballDirection)
- {
- case Direction.UP:
- ball._ballDirection = Direction.DOWN;
- break;
- case Direction.UP_RIGHT:
- ball._ballDirection = Direction.DOWN_RIGHT;
- break;
- case Direction.UP_LEFT:
- ball._ballDirection = Direction.DOWN_LEFT;
- break;
- }
- }
- // Ball Touches Bottom
- if (ball._y >= screenHeight - ball._height)
- {
- switch (ball._ballDirection)
- {
- case Direction.DOWN:
- ball._ballDirection = Direction.UP;
- break;
- case Direction.DOWN_RIGHT:
- ball._ballDirection = Direction.UP_RIGHT;
- break;
- case Direction.DOWN_LEFT:
- ball._ballDirection = Direction.UP_LEFT;
- break;
- }
- }
- // Ball Touches Right
- if (ball._x >= screenWidth - ball._width)
- {
- switch (ball._ballDirection)
- {
- case Direction.RIGHT:
- ball._ballDirection = Direction.LEFT;
- break;
- case Direction.UP_RIGHT:
- ball._ballDirection = Direction.UP_LEFT;
- break;
- case Direction.DOWN_RIGHT:
- ball._ballDirection = Direction.DOWN_LEFT;
- break;
- }
- }
- // Ball Touches left
- if (ball._x <= 0)
- {
- switch (ball._ballDirection)
- {
- case Direction.LEFT:
- ball._ballDirection = Direction.RIGHT;
- break;
- case Direction.DOWN_LEFT:
- ball._ballDirection = Direction.DOWN_RIGHT;
- break;
- case Direction.UP_LEFT:
- ball._ballDirection = Direction.UP_RIGHT;
- break;
- case Direction .DOWN_RIGHT :
- ball.BallDirection = Direction.DOWN_LEFT;
- break;
- case Direction .UP_RIGHT :
- ball.BallDirection = Direction.UP_LEFT;
- break;
- }
- }
- } // end MOVEBALL
- //
- //*****************************************************************************************
- //*****************************************************************************************
- //********************************** C O M P A R A ********************************
- //*****************************************************************************************
- //*****************************************************************************************
- public void Compara(Ball bola1, Ball bola2)
- {
- int xDiff = bola1._x - bola2._x;
- int yDiff = bola1._y - bola2._y;
- double distancia = Math.Sqrt(xDiff * xDiff + yDiff * yDiff);
- if(distancia <= 50)
- switch (bola1._ballDirection)
- {
- case Direction.UP:
- switch (bola2._ballDirection)
- {
- case Direction.UP_LEFT:
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.UP;
- }
- break;
- case Direction.UP:
- if ((bola1._y < bola2._y) && (bola1._speed < bola2._speed))
- bola1._speed += bola2._speed;
- break;
- case Direction.DOWN:
- if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.UP;
- }
- break;
- case Direction.UP_RIGHT:
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.UP;
- }
- break;
- case Direction.RIGHT:
- if (bola1._x > bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.LEFT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_RIGHT;
- bola2._ballDirection = Direction.DOWN_RIGHT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- else
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_RIGHT;
- bola2._ballDirection = Direction.DOWN_RIGHT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.LEFT:
- if (bola1._x < bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- else
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN_RIGHT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- break;
- case Direction.DOWN_RIGHT:
- if (bola1._y >= bola2._y)
- if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- break;
- case Direction.DOWN_LEFT:
- if (bola1._y > bola2._y)
- {
- if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- else if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.LEFT;
- }
- }
- else if (bola1._y == bola2._y)
- if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.DOWN;
- }
- break;
- } //fin Switch(bola2)
- break; // de case UP ********************************************************
- //
- //*********************************************************************************
- //************************ CASE D O W N ***************************************
- //*********************************************************************************
- case Direction.UP_RIGHT :
- switch (bola2._ballDirection)
- {
- case Direction.UP_LEFT:
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.UP:
- if ((bola1._y < bola2._y) && (bola1._speed < bola2._speed))
- {
- bola1._speed += bola2._speed;
- bola1._ballDirection = Direction.UP_LEFT ;
- bola2._ballDirection = Direction.DOWN ;
- }
- break;
- case Direction.DOWN:
- if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.UP;
- bola2._ballDirection = Direction.DOWN_RIGHT ;
- }
- break;
- case Direction.UP_RIGHT:
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.DOWN_LEFT ;
- }
- break;
- case Direction.RIGHT:
- if (bola1._x > bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT ;
- bola2._ballDirection = Direction.DOWN;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.LEFT:
- if (bola1._x < bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.UP_LEFT ;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- break;
- case Direction.DOWN_RIGHT:
- if (bola1._y >= bola2._y)
- if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN_LEFT ;
- }
- else if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- break;
- case Direction.DOWN_LEFT:
- if (bola1._y > bola2._y)
- {
- if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- else if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.LEFT;
- }
- }
- else if (bola1._y == bola2._y)
- if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.DOWN;
- }
- break;
- } //fin Switch(bola2)
- break;
- case Direction.UP_LEFT :
- switch (bola2._ballDirection)
- {
- case Direction.UP_LEFT:
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.UP:
- if ((bola1._y < bola2._y) && (bola1._speed < bola2._speed))
- {
- bola1._speed += bola2._speed;
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.UP_RIGHT ;
- }
- break;
- case Direction.DOWN:
- if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.UP;
- bola2._ballDirection = Direction.DOWN;
- }
- break;
- case Direction.UP_RIGHT:
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- break;
- case Direction.RIGHT:
- if (bola1._x > bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_RIGHT;
- bola2._ballDirection = Direction.DOWN_RIGHT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.LEFT:
- if (bola1._x >= bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.LEFT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_RIGHT ;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- break;
- case Direction.DOWN_RIGHT:
- if (bola1._y >= bola2._y)
- if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT ;
- bola2._ballDirection = Direction.UP_LEFT ;
- }
- else if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.DOWN ;
- bola2._ballDirection = Direction.RIGHT;
- }
- break;
- case Direction.DOWN_LEFT:
- if (bola1._y > bola2._y)
- {
- if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- else if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.LEFT;
- }
- }
- else if (bola1._y == bola2._y)
- if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.DOWN;
- }
- break;
- } //fin Switch(bola2)
- break;
- case Direction.RIGHT :
- switch (bola2._ballDirection)
- {
- case Direction.UP_LEFT:
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.UP:
- if ((bola1._y < bola2._y) && (bola1._speed < bola2._speed))
- {
- bola1._speed += bola2._speed;
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- break;
- case Direction.DOWN:
- if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.UP;
- bola2._ballDirection = Direction.DOWN_RIGHT;
- }
- break;
- case Direction.UP_RIGHT:
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.UP;
- }
- break;
- case Direction.RIGHT:
- if (bola1._x > bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_RIGHT;
- bola2._ballDirection = Direction.DOWN_RIGHT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.LEFT:
- if (bola1._x >= bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- break;
- case Direction.DOWN_RIGHT:
- if (bola1._y >= bola2._y)
- if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN;
- }
- else if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- break;
- case Direction.DOWN_LEFT:
- if (bola1._y > bola2._y)
- {
- if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- else if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.UP_RIGHT ;
- bola2._ballDirection = Direction.LEFT;
- }
- }
- else if (bola1._y == bola2._y)
- if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.DOWN;
- }
- break;
- } //fin Switch(bola2)
- break;
- case Direction.LEFT :
- switch (bola2._ballDirection)
- {
- case Direction.UP_LEFT:
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.UP:
- if ((bola1._y < bola2._y) && (bola1._speed < bola2._speed))
- {
- bola1._speed += bola2._speed;
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.DOWN_LEFT ;
- }
- break;
- case Direction.DOWN:
- if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.UP;
- bola2._ballDirection = Direction.RIGHT ;
- }
- break;
- case Direction.UP_RIGHT:
- {
- bola1._ballDirection = Direction.UP_RIGHT ;
- bola2._ballDirection = Direction.LEFT ;
- }
- break;
- case Direction.RIGHT:
- if (bola1._x > bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_RIGHT;
- bola2._ballDirection = Direction.DOWN_RIGHT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.LEFT:
- if (bola1._x >= bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.DOWN_LEFT ;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.UP_RIGHT ;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- break;
- case Direction.DOWN_RIGHT:
- if (bola1._y >= bola2._y)
- if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT ;
- bola2._ballDirection = Direction.UP_LEFT ;
- }
- else if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- break;
- case Direction.DOWN_LEFT:
- if (bola1._y > bola2._y)
- {
- if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- else if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.LEFT;
- }
- }
- else if (bola1._y == bola2._y)
- if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.DOWN;
- }
- break;
- } //fin Switch(bola2)
- break;
- case Direction.DOWN_RIGHT :
- switch (bola2._ballDirection)
- {
- case Direction.UP_LEFT:
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.UP:
- if ((bola1._y < bola2._y) && (bola1._speed < bola2._speed))
- {
- bola1._speed += bola2._speed;
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.LEFT ;
- }
- break;
- case Direction.DOWN:
- if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.UP;
- bola2._ballDirection = Direction.UP_LEFT ;
- }
- break;
- case Direction.UP_RIGHT:
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.DOWN ;
- }
- break;
- case Direction.RIGHT:
- if (bola1._x > bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_RIGHT;
- bola2._ballDirection = Direction.UP ;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.LEFT:
- if (bola1._x >= bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_LEFT ;
- bola2._ballDirection = Direction.DOWN_RIGHT ;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- break;
- case Direction.DOWN_RIGHT:
- if (bola1._y >= bola2._y)
- if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.UP ;
- }
- else if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- break;
- case Direction.DOWN_LEFT:
- if (bola1._y > bola2._y)
- {
- if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- else if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.LEFT;
- }
- }
- else if (bola1._y == bola2._y)
- if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.DOWN;
- }
- break;
- } //fin Switch(bola2)
- break;
- case Direction.DOWN_LEFT :
- switch (bola2._ballDirection)
- {
- case Direction.UP_LEFT:
- {
- bola1._ballDirection = Direction.UP ;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.UP:
- if ((bola1._y < bola2._y) && (bola1._speed < bola2._speed))
- {
- bola1._speed += bola2._speed;
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.DOWN_LEFT ;
- }
- break;
- case Direction.DOWN:
- if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.UP;
- bola2._ballDirection = Direction.DOWN_RIGHT;
- }
- break;
- case Direction.UP_RIGHT:
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.UP;
- }
- break;
- case Direction.RIGHT:
- if (bola1._x > bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_RIGHT;
- bola2._ballDirection = Direction.DOWN_RIGHT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.LEFT:
- if (bola1._x >= bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.UP_RIGHT ;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- break;
- case Direction.DOWN_RIGHT:
- if (bola1._y >= bola2._y)
- if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN;
- }
- else if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- break;
- case Direction.DOWN_LEFT:
- if (bola1._y > bola2._y)
- {
- if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.DOWN;
- bola2._ballDirection = Direction.LEFT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.UP ;
- bola2._ballDirection = Direction.RIGHT;
- }
- else if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.LEFT;
- }
- }
- else if (bola1._y == bola2._y)
- if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.DOWN;
- }
- break;
- } //fin Switch(bola2)
- break;
- case Direction.DOWN:
- switch (bola2._ballDirection)
- {
- case Direction.UP_LEFT :
- if (bola1._y < bola2._y)
- {
- if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.UP_LEFT;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.UP;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.LEFT;
- }
- }
- else if(bola1._y == bola2._y)
- if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.UP_RIGHT:
- if (bola1._y < bola2._y)
- {
- if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- else if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.UP;
- bola2._ballDirection = Direction.DOWN;
- }
- else if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.UP_RIGHT;
- bola2._ballDirection = Direction.DOWN_RIGHT;
- }
- }
- else if (bola1._y == bola2._y)
- if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.UP;
- }
- break;
- case Direction.UP:
- if (bola1._y < bola2._y)
- {
- if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.UP;
- bola2._ballDirection = Direction.DOWN;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- else if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- }
- break;
- case Direction.DOWN:
- if ((bola1._y > bola2._y) && (bola1._speed < bola2._speed))
- {
- bola1._speed += bola2._speed;
- if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- }
- }
- break;
- case Direction.RIGHT:
- if (bola1._x > bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.DOWN_RIGHT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.UP_RIGHT;
- }
- break;
- case Direction.LEFT:
- if (bola1._x < bola2._x)
- if (bola1._y == bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.RIGHT;
- }
- else if (bola1._y < bola2._y)
- {
- bola1._ballDirection = Direction.LEFT;
- bola2._ballDirection = Direction.DOWN_LEFT;
- }
- else if (bola1._y > bola2._y)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.UP_LEFT;
- }
- break;
- case Direction.DOWN_RIGHT:
- if (bola1._y >= bola2._y)
- if (bola1._x > bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_RIGHT;
- bola2._ballDirection = Direction.RIGHT;
- }
- else if (bola1._x == bola2._x)
- {
- bola1._ballDirection = Direction.RIGHT;
- bola2._ballDirection = Direction.DOWN;
- }
- else if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.UP_RIGHT;
- bola2._ballDirection = Direction.DOWN;
- }
- break;
- case Direction.DOWN_LEFT:
- if (bola1._y > bola2._y)
- {
- if (bola1._x <= bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.LEFT;
- }
- }
- else if (bola1._y == bola2._y)
- if (bola1._x < bola2._x)
- {
- bola1._ballDirection = Direction.DOWN_LEFT;
- bola2._ballDirection = Direction.DOWN;
- }
- break;
- } //fin Switch(bola2)
- break; // de case DOWN ********************************************************
- } //fin Switch(bola1)
- } // end Compara
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement