<UserControl x:Class="CatGame.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="480" d:DesignWidth="640" KeyDown="UserControl_KeyDown">
<Canvas x:Name="LayoutRoot" Background="white">
<Image Source="level1.jpg"></Image>
<TextBlock FontSize="24" Canvas.Left="700" Canvas.Top="90" Name="score">/TextBlock>
</Canvas>
</UserControl>
if (DetectCollisionZero(myCat, myZero))
{
int scoreAsInt;
if (Int32.TryParse(score.Text, out scoreAsInt) != null)
{
scoreAsInt = scoreAsInt + 1;
score.Text = scoreAsInt.ToString();
}
LayoutRoot.Children.Remove(myZero);
}
public bool DetectCollisionZero(ContentControl myCat, ContentControl myZero)
{
Rect myCatRect = new Rect(
new Point(Convert.ToDouble(myCat.GetValue(Canvas.LeftProperty)),
Convert.ToDouble(myCat.GetValue(Canvas.TopProperty))),
new Point((Convert.ToDouble(myCat.GetValue(Canvas.LeftProperty)) + myCat.ActualWidth),
(Convert.ToDouble(myCat.GetValue(Canvas.TopProperty)) + myCat.ActualHeight))
);
Rect myZeroRect = new Rect(
new Point(Convert.ToDouble(myZero.GetValue(Canvas.LeftProperty)),
Convert.ToDouble(myZero.GetValue(Canvas.TopProperty))),
new Point((Convert.ToDouble(myZero.GetValue(Canvas.LeftProperty)) + myZero.ActualWidth),
(Convert.ToDouble(myZero.GetValue(Canvas.TopProperty)) + myZero.ActualHeight))
);
myCatRect.Intersect(myZeroRect);
return !(myCatRect == Rect.Empty);
}
기본적으로 고양이는 개체 (myZero)와 충돌하며 내 점수는 +1해야합니다. myZero)가 삭제되면 사용자는 여전히 객체가 있던 위치로 이동하여 더 많은 포인트를받을 수 있습니다.충돌 감지가 +1을 한 번만 추가하면 개체가 여러 번 충돌 함
어떻게하면 1 포인트 만 추가 할 수 있습니까?
코드를 게시하지 않은 DetectCollisionLeft의 버그와 비슷합니다. –
죄송합니다. 지금 업데이트하십시오. – Lokie
제목에 "C# XAML"을 넣을 필요가 없습니다. 태그에 그대로 두십시오. –