Hjälp med förklaring i C#
Hej jag håller på att göra ett BreakOut spel med hjälp av denna guide: http://csharpskolan.se/showarticle.php?id=56
Den har 5 delar och det där är bara en av dem. Men jag behöver hjälp med att få en sak förklarad.
Detta är koden för att få bollen att studsa på själva plattan.
Rectangle BallBox = new Rectangle((int)ball_position.X, (int)ball_position.Y, 12 ,12);
Rectangle PaddelBox = new Rectangle((int)paddel_position.X, (int)paddel_position.Y, 90, 17);
if (PaddelBox.Intersects(BallBox) && ball_speed.Y > 0)
{
if (ball_position.X + 6 >= paddel_position.X && ball_position.X + 6 <= (paddel_position.X + 15))
{
ball_speed = new Vector2(-2.5F, -1.5F);
}
if(ball_position.X + 6 >= paddel_position.X + 16 && ball_position.X + 6 <= (paddel_position.X + 31))
{
if(ball_speed.X > 0)
{
ball_speed.X = -ball_speed.X;
ball_speed.Y = -ball_speed.Y;
}
}
if(ball_position.X + 6 >= paddel_position.X + 59 && ball_position.X + 6 <= paddel_position.X + 74)
{
if(ball_speed.X < 0)
{
ball_speed.X = -ball_speed.X;
ball_speed.Y = -ball_speed.Y;
}
}
if(ball_position.X + 6 >= paddel_position.X + 75 && ball_position.X + 6 <= paddel_position.X + 90)
{
ball_speed = new Vector2(-2.5F, -1.5F);
}
if(ball_position.X + 6 >= paddel_position.X + 32 && ball_position.X + 6 <= paddel_position.X + 58)
{
ball_speed.Y = -ball_speed.Y;
}
}
Kan någon hjälpa mig och förklara ingående hur det fungerar?