public RCar(int x, int y, possibleDirections dir) { this.x = x; this.y = y; this.imagePath = "rcar.png"; this.ID = possibleCars.rcar; this.velocity = 18; this.mainVelocity = velocity; this.direction = dir; this.mainDirection = dir; this.rectangle = new Rectangle(x, y, Image.FromFile(imagePath).Width - 10, Image.FromFile(imagePath).Height - 10); }
public Motorcycle(int x, int y, possibleDirections dir) { this.x = x; this.y = y; this.imagePath = "motorcycle.png"; this.ID = possibleCars.motorcycle; this.velocity = 23; this.mainVelocity = velocity; this.direction = dir; this.mainDirection = dir; this.rectangle = new Rectangle(x, y, Image.FromFile(imagePath).Width - 5, Image.FromFile(imagePath).Height - 5); }
/*movement based on car's direction */ public void move() { switch (direction) { case possibleDirections.up: y -= velocity; rectangle.Y -= velocity; if (mainDirection == possibleDirections.right) { x += littleConst; rectangle.X += littleConst; if (y <= upperMiddle) //go up until you reach the middle { y = upperMiddle; rectangle.Y = upperMiddle; goToTheMiddle = false; direction = mainDirection; } } else { x += littleConst; rectangle.X += littleConst; if (y <= lowerMiddle) { y = lowerMiddle; rectangle.Y = lowerMiddle; goToTheMiddle = false; direction = mainDirection; } } break; case possibleDirections.down: y += velocity; rectangle.Y += velocity; if (mainDirection == possibleDirections.right) { x -= littleConst; rectangle.X -= littleConst; if (y >= upperMiddle) { y = upperMiddle; rectangle.Y = upperMiddle; goToTheMiddle = false; direction = mainDirection; } } else { x -= littleConst; rectangle.X -= littleConst; if (y >= lowerMiddle) { y = lowerMiddle; rectangle.Y = lowerMiddle; goToTheMiddle = false; direction = mainDirection; } } break; case possibleDirections.left: x -= velocity; rectangle.X -= velocity; break; case possibleDirections.right: x += velocity; rectangle.X += velocity; break; default: break; } }