こんにちは、基本的にこれはゾンビが歩くためのコードです。私がやりたいのは、ゾンビをクリックすると消えることです。どうすればそれを行うことができますか? または、ゾンビが別の画像と衝突したときに歩いているゾンビが消える場合はどうすればよいですか? 弾丸が彼らに当たったときのように。
public class Gaston {
public double X { get; set; }
public double Y { get; set; }
public Image Image { get; set; }
public int Colspan { get; set; }
public int Rowspan { get; set; }
}
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
DispatcherTimer dispatcherTimer;
List<Gaston> Gastons;
int timesTicked = 0;
int timesToTick = 10;
Image zombieImg;
public MainPage()
{
this.InitializeComponent();
Gastons = new List<Gaston>();
DispatcherTimerSetup();
Zombie();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
private void Zombie()
{
Gaston newGaston = new Gaston
{
Colspan = -10,
Image = new Image(),
Rowspan = -10,
X = -10,
Y = -10
};
BitmapImage bmp;
bmp = new BitmapImage(new Uri (this.BaseUri, "/Assets/zombie.png"));
newGaston.Image.Source = bmp;
Gastons.Add(newGaston);
Grid.Children.Add(newGaston.Image);
}
private void ZombieWalks()
{
foreach (Gaston me in Gastons)
{
me.Image.Margin = new Thickness(me.Image.Margin.Left - 10, me.Image.Margin.Bottom - 10, me.Image.Margin.Right + 10, me.Image.Margin.Top + 10);
}
}
public void DispatcherTimerSetup()
{
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
}
void dispatcherTimer_Tick(object sender, object e)
{
AddZombie();
timesTicked++;
ZombieWalks();
if (timesTicked > timesToTick)
{
}
}
private void AddZombie()
{
if (timesTicked == 5)
{
Zombie();
DispatcherTimerSetup();
}
}
}
}