/// <summary> /// 移除该控件并发送消息 /// </summary> /// <param name="cs"></param> /// <param name="ste">0初始化 1 未被敲击 2 被敲中</param> /// <param name="ht"></param> private void RemoveAndSendMsg(CadenceSign cs, byte ste, HitType ht) { LayoutRoot.Children.Remove(cs.currentSign); indexActual++; cs.state = ste; HitArgs ha = new HitArgs(); ha.HitType = ht; OnHit(this, ha); }
/// <summary> /// 判断按键是否符合游戏规则 /// </summary> private bool KnockKeyIsCodex(CadenceSign cs, DrumType k) { bool isCodex = false; if (k == cs.drumType) isCodex = true; if (k == DrumType.LeftSide && cs.drumType == DrumType.RightSide) isCodex = true; if (k == DrumType.RightSide && cs.drumType == DrumType.LeftSide) isCodex = true; if (k == DrumType.LeftFace && cs.drumType == DrumType.RightFace) isCodex = true; if (k == DrumType.RightFace && cs.drumType == DrumType.LeftFace) isCodex = true; return isCodex; }
/// <summary> /// 加载一个歌曲数据并解析 /// </summary> /// <param name="sc"></param> private void Load(MusicInfo mi) { speed = mi.Speed; //计算到敲击点延迟 CalcDelayOffset(); //解析实体类 string[] datas = mi.MusicData.Split(','); CadenceSigns = new CadenceSign[datas.Length]; string temp = string.Empty; int delaytime = 0; int ttime = 0; int i = 0; foreach (string t in datas) { temp = t.Substring(0, 2); ttime = int.Parse(t.Substring(3, t.Length - 3)); delaytime += ttime; CadenceSign cs = new CadenceSign(); cs.drumType = CommHelper.DrumTypeToKeyCode(temp); cs.DelayTimeMill = delaytime; //图像 Image img = new Image(); if (cs.drumType == DrumType.FaceAll) { img.Width = 45; img.Height = 45; img.Source = ResourceMgr.SignimgBgCache[1]; } else if (cs.drumType == DrumType.SideAll) { img.Width = 45; img.Height = 45; img.Source = ResourceMgr.SignimgBgCache[3]; } else if (cs.drumType == DrumType.RightFace || cs.drumType == DrumType.LeftFace) { img.Width = 35; img.Height = 35; img.Source = ResourceMgr.SignimgBgCache[0]; } else { img.Width = 35; img.Height = 35; img.Source = ResourceMgr.SignimgBgCache[2]; } //img.Visibility = System.Windows.Visibility.Collapsed; //TranslateTransform ttf = new TranslateTransform(); //ttf.X = 0; ttf.Y = 0; //img.RenderTransform = new TranslateTransform(); img.RenderTransform = null; img.Effect = null; img.CacheMode = new BitmapCache(); if (cs.drumType == DrumType.RightFace || cs.drumType == DrumType.LeftFace || cs.drumType == DrumType.RightSide || cs.drumType == DrumType.LeftSide) { Canvas.SetLeft(img, signLeftLocation); Canvas.SetTop(img, 33); } else { Canvas.SetLeft(img, signLeftLocation); Canvas.SetTop(img, 28); } cs.currentSign = img; CadenceSigns[i] = cs; i++; } //添入显示控件 foreach (CadenceSign cs in CadenceSigns) { LayoutRoot.Children.Add(cs.currentSign); } AddLastBecloud(); firstlongTime = CadenceSigns[0].DelayTimeMill; signCount = CadenceSigns.Length; }
private void DisplayDrumImg(CadenceSign cs, BitmapImage[] bi) { if (isStart && cs.currentSign != null) { if (cs.drumType == DrumType.FaceAll) { cs.currentSign.Dispatcher.BeginInvoke(delegate() { cs.currentSign.Source = bi[1]; }); } else if (cs.drumType == DrumType.SideAll) { cs.currentSign.Dispatcher.BeginInvoke(delegate() { cs.currentSign.Source = bi[3]; }); } else if (cs.drumType == DrumType.LeftFace || cs.drumType == DrumType.RightFace) { cs.currentSign.Dispatcher.BeginInvoke(delegate() { cs.currentSign.Source = bi[0]; }); } else { cs.currentSign.Dispatcher.BeginInvoke(delegate() { cs.currentSign.Source = bi[2]; }); } } }