Ejemplo n.º 1
0
 private void MoveOfPerson( MyPerson person )
 {
     Point p2 = new Point( ( person.position.X ) * gridSize, ( person.position.Y ) * gridSize );
     Storyboard storyboard = new Storyboard();
     //创建X轴方向动画
     DoubleAnimation doubleAnimation = new DoubleAnimation(
     person.X, p2.X, new Duration( TimeSpan.FromMilliseconds( person.xspeed ) ) );
     Storyboard.SetTarget( doubleAnimation, person );
     Storyboard.SetTargetProperty( doubleAnimation, new PropertyPath( "X" ) );
     storyboard.Children.Add( doubleAnimation );
     //创建Y轴方向动画
     doubleAnimation = new DoubleAnimation(
       person.Y, p2.Y, new Duration( TimeSpan.FromMilliseconds( person.yspeed ) ) );
     Storyboard.SetTarget( doubleAnimation, person );
     Storyboard.SetTargetProperty( doubleAnimation, new PropertyPath( "Y" ) );
     storyboard.Children.Add( doubleAnimation );
     //将动画动态加载进资源内
     if ( !Resources.Contains( "rectAnimation" ) )
         Resources.Add( "rectAnimation", storyboard );
     //动画播放
     storyboard.Completed += ( object sender, EventArgs e ) =>
     {
         person.action = MyPerson.Actions.stand;
     };
     person.action = MyPerson.Actions.step;
     Canvas.SetZIndex( person, person.position.Y );
     if ( testMap.blocks[person.position.Y, person.position.X].isExistProp )
     {
         person.hp += testMap.blocks[person.position.Y, person.position.X].HPrecover;
         person.mp += testMap.blocks[person.position.Y, person.position.X].MPrecover;
         testMap.blocks[person.position.Y, person.position.X].isExistProp = false;
         testMap.blocks[person.position.Y, person.position.X].HPrecover = 0;
         testMap.blocks[person.position.Y, person.position.X].MPrecover = 0;
         source.musicsource.Recover.Stop();
         source.musicsource.Recover.Play();
         Carrier.Children.Remove( testMap.blocks[person.position.Y, person.position.X].Drug );
     }
     storyboard.Begin();
 }
Ejemplo n.º 2
0
 private void LoadPerson( MyPerson person )
 {
     Carrier.Children.Add( person );
     Binding bid = new Binding( "X" );
     bid.Source = person;
     bid.Mode = BindingMode.TwoWay;
     person.SetBinding( Canvas.LeftProperty, bid );
     bid = new Binding( "Y" );
     bid.Source = person;
     bid.Mode = BindingMode.TwoWay;
     person.SetBinding( Canvas.TopProperty, bid );
     Canvas.SetLeft( person, person.position.X * gridSize );
     Canvas.SetTop( person, person.position.Y * gridSize );
     Canvas.SetZIndex( person, person.Zindex );
 }
Ejemplo n.º 3
0
 private void LoadElements()
 {
     this.gridSize = Carrier.Width / numX;//确定地图格子大小
     Bomb.gridSize = this.gridSize;//
     testMap = new MyMap( numX, numY, (int)Carrier.Width, (int)Carrier.Height );
     person1 = new MyPerson( gridSize, source.personsource1.body, new System.Drawing.Point( 0, 0 ), testMap );
     testMap.personBlocks.Add( person1 );
     person2 = new MyPerson( gridSize, source.personsource2.body, new System.Drawing.Point( 15, 15 ), testMap );
     testMap.personBlocks.Add( person2 );
     person1.Width = person1.Height = gridSize;
     person2.Width = person2.Width = gridSize;
     person2.Faction.Fill = new SolidColorBrush( Colors.Blue );
     person2.Faction.Text = "主角2";
     LoadMap();//加载地图
     LoadPerson( person1 );
     person1.xspeed = 400;
     person1.yspeed = 400;
     LoadPerson( person2 );
     person2.xspeed = 400;
     person2.yspeed = 400;//加载人物
 }
Ejemplo n.º 4
0
 private System.Drawing.Point getExactPosition( MyPerson person )
 {
     int x = (int)( Canvas.GetLeft( person ) / gridSize );
     int y = (int)( Canvas.GetTop( person ) / gridSize );
     return new System.Drawing.Point( x, y );
 }
Ejemplo n.º 5
0
 private void Confirm_Click_join( object sender, RoutedEventArgs e )
 {
     joinGameDialog.Close();
     networkcontrol.StartMessageQueue_client();
     MainPerson = person2;
     networkcontrol.NewCommand += networkcontrol_NewCommand;
     this.isServer = false;
     networkcontrol.AddGameRequest( "ready;" );
     ///开始游戏
 }
Ejemplo n.º 6
0
 void Confirm_Click( object sender, RoutedEventArgs e )
 {
     creatGameDialog.Close();
     MainPerson = person1;
     this.isServer = true;
     networkcontrol.AddGameCommand( "start!" );
     GameInit();//开始游戏
 }