Closed tsuikit159 closed 10 months ago
I have tried to amend the code in the video u provided in order to make it work.
Currently when the player collide with another object, the object will disappear and the player will slowly grow bigger.
I will publish the code after I have figured out all the mechanisms.
private async void Collide(string Dir)
{
foreach(var x in GameScreen.Children.OfType
if(PlayerHB.IntersectsWith(ToCollide))
{
Canvas.SetTop(Player, Canvas.GetTop(Player) + SpeedY);
SpeedY = 0;
GameScreen.Children.Remove(x);
for (int i = 0; i < 10; i++)
{
Player.Width += 2;
Player.Height += 2;
await Task.Delay(50);
}
}
}
}
}
Great, I have also improved the precision with this function, which calculates the position and size of the circle and checks if they are overlapping.
public static bool CheckCollision(Ellipse e1, Ellipse e2) { var r1 = e1.ActualWidth / 2; var x1 = Canvas.GetLeft(e1) + r1; var y1 = Canvas.GetTop(e1) + r1; var r2 = e2.ActualWidth / 2; var x2 = Canvas.GetLeft(e2) + r2; var y2 = Canvas.GetTop(e2) + r2; var d = new Vector(x2 - x1, y2 - y1); return d.Length <= r1 + r2; } here is my version of collide().
public void collide()
{
foreach (var x in GameScreen.Children.OfType
}
else if (CheckCollision(Player, Sun))
{
MessageBox.Show("Game Over");
this.Close();
}
}
}
TODO: make the collision work. Then Follow the project instructions. When the collision occurs, The player wins when its size is larger than the threshold specified in the stage. The player loses when it is completely absorbed by the other orbs.
Reference video : https://www.youtube.com/watch?v=VYXuGTefEFs&t=10s&ab_channel=FriendlyNeighborhoodProgrammer