public Game(CanvasHelper cv_) { cv = cv_; cv.MouseLeftButtonUp += Canvas_MouseLeftButtonUp; cv.KeyDown += CanvasKeyDown; cv.KeyUp += Canvas_KeyUp; nowstate = state.Menu; }
private void canvas_Loaded(object sender, RoutedEventArgs e) { canvas.Focus(); cv = new CanvasHelper(canvas); game = new Game(cv); game.initialze(); loop = new Thread(new ThreadStart(Loop)); loop.Start(); }
/*ESC:返回上一个菜单 * DFJK:4K按键 * `(~):重新开始游戏 * P:结算游戏*/ public void OnDraw(CanvasHelper cv, ref bool redraw) { if (redraw) { cv.cv.Children.Clear(); cv.Image(0, 0, 640, 480, Helper.LoadImage("Skins/GameHelper.png")); cv.Rectangle(0, 0, 640, 50, 1, Helper.Color("#fff"), Helper.Color("#FFC0CB", 0.4)); cv.Text(10, 12, 40, "帮助", Helper.Color("#fff")); //返回菜单 cv.Rectangle(253, 350, 128, 40, 3, Helper.Color("#aef"), Helper.Color("#000", 0.3)); cv.Text(253, 350, 50, "返回主页面"); //开始游戏 cv.Rectangle(253 + 120 + 50, 350, 115, 40, 3, Helper.Color("#aef"), Helper.Color("#000", 0.3)); cv.Text(253 + 120 + 50, 350, 50, "开始游戏"); //cv.Text(cv.width / 2, cv.height / 2, 50, "GameHelper",Helper.Color("#000")); redraw = false; } }
public void OnDraw(ref CanvasHelper cv, ref bool redraw, SongResources song) { if (redraw) { cv.cv.Children.Clear(); cv.Image(0, 0, cv.width, cv.height, summaryim); cv.Image(0, 50, stage, 480, song.picture); //SUMMARY cv.Rectangle(0, 0, 640, 50, 0, null, Helper.Color("#FFC0CB", 0.4)); cv.Text(10, 12, 40, "Summary", Helper.Color("#fff")); summarysong = Helper.LoadMusic("Skins/result.mp3"); summarysong.Play(); redraw = false; } //绘制分数,score += combo + note.status cv.Text(stage, 50 + 0, 40, "SCORE", Helper.Color("#fff", 0.8)); DrawScore(ref cv, 600, 50, 25, 25, score); //绘制hit { double op = 0.2; do { cv.Image(stage, 50 + 35, 65, 30, (Brush)resources["img-hit-300g"], op); cv.Image(stage, 50 + 2 * 35, 65, 30, (Brush)resources["img-hit-300"], op); cv.Image(stage, 50 + 3 * 35, 65, 30, (Brush)resources["img-hit-200"], op); cv.Image(stage, 50 + 4 * 35, 65, 30, (Brush)resources["img-hit-50"], op); cv.Image(stage, 50 + 5 * 35, 65, 30, (Brush)resources["img-hit-0"], op); op += 0.1; } while (op == 0.8); DrawScore(ref cv, 600, 50 + 35, 25, 25, statenum[0]); DrawScore(ref cv, 600, 50 + 35 * 2, 25, 25, statenum[1]); DrawScore(ref cv, 600, 50 + 35 * 3, 25, 25, statenum[2]); DrawScore(ref cv, 600, 50 + 35 * 4, 25, 25, statenum[3]); DrawScore(ref cv, 600, 50 + 35 * 5, 25, 25, statenum[4]); } if (summarysong != null && summarysong.NaturalDuration.HasTimeSpan && summarysong.Position.TotalSeconds >= summarysong.NaturalDuration.TimeSpan.TotalSeconds - 1) { summarysong.Position = TimeSpan.Zero; } }
private void DrawScore(ref CanvasHelper cv, double x1, double x2, int width_, int height_, int score) { int s = score; int n = 0; do { s /= 10; n++; } while (s != 0); s = score; int i = 0; do { cv.Image(x1 - 25 * i, x2, width_, height_, (Brush)resources["img-score-" + s % 10]);// +12 * n ++i; s /= 10; } while (s != 0); }
public bool Draw(CanvasHelper cv, decimal now, double[] segments, Dictionary <string, object> resources, double factor = 0.7) { if (!OnScreen(now, factor)) { return(false); } if (type == Type.Tap) { if (status == Status.Free) { if (column == 0 || column == 3) { cv.Image(GetNoteX(segments), GetNoteY(time, now, factor), GetNoteWidth(segments), GetNoteLength(factor), (Brush)resources["img-note1"]); } else { cv.Image(GetNoteX(segments), GetNoteY(time, now, factor), GetNoteWidth(segments), GetNoteLength(factor), (Brush)resources["img-note2"]); } } } else { Brush b = null; if (column == 0 || column == 3) { b = (Brush)resources["img-note1L"]; } else { b = (Brush)resources["img-note2L"]; } if (status == Status.Miss || endstatus == Status.Miss) { b = b.Clone(); b.Opacity = 0.6; } cv.Image(GetNoteX(segments), GetNoteY(endtime, now, factor), GetNoteWidth(segments), GetNoteLength(factor), b); } return(true); }
public void OnDraw(CanvasHelper cv, ref bool redraw) { if (redraw) { cv.cv.Children.Clear(); bgim = Helper.LoadImage("Skins/bg.jpg"); cv.Image(0, 0, cv.width, cv.height, bgim); cv.Image(cv.width / 2 - 100, cv.height / 2 - 100, 200, 200, Helper.LoadImage("start_btn.png")); //cv.Rectangle(200, 50, 100, 100); //cv.Text(cv.width/2, 0,30,"MENU",Helper.Color("#fff")); //cv.Rectangle(300, 50, 100, 100); //cv.Text(cv.width / 2, cv.height /2, 30, "Start", Helper.Color("#fff")); bgsong = Helper.LoadMusic("Skins/startup.mp3"); bgsong.Play(); redraw = false; } if (bgsong != null && bgsong.NaturalDuration.HasTimeSpan && bgsong.Position.TotalSeconds >= bgsong.NaturalDuration.TimeSpan.TotalSeconds - 5) { bgsong.Position = TimeSpan.Zero; } cv.Text(0, 430, 30, "按下Tab键,查看帮助\n按下Space or Enter进入游戏", Helper.Color("#fff"), 640); }
public void OnDraw(CanvasHelper cv, ref bool redraw, ref Game.state state) { if (redraw) { cv.cv.Children.Clear(); GameStart(); song.bgm.Position = TimeSpan.Zero; //idx = 0; redraw = false; } cv.cv.Children.Clear(); cv.Image(0, 0, cv.width, cv.height, song.picture); //cv.Image(stageOffset, 0, 203, 480,(Brush) resources["img-stage"]); cv.Rectangle(28, 0, 162 - 28, 480, 1, Helper.Color("#fff", 0.1), Helper.Color("#000", 0.1)); foreach (double x in segments) { cv.line(x, 0, x, 406); } for (int i = 0; i < song.notes.Count; i++) { song.notes[i].Draw(cv, t, segments, resources, factor); } t = Convert.ToDecimal(song.bgm.Position.TotalMilliseconds); //绘制轨道光 for (int i = 0; i < 4; ++i) { if ((keyPressed & (1 << i)) > 0) { cv.Image(segments[i], 406 - 350, segments[i + 1] - segments[i], 350, (Brush)resources["img-light"]); if (i == 0 || i == 3) { cv.Image(segments[i], 413, segments[i + 1] - segments[i], 480 - 413, (Brush)resources["img-key1D"]); } else { cv.Image(segments[i], 413, segments[i + 1] - segments[i], 480 - 413, (Brush)resources["img-key2D"]); } } else { if (i == 0 || i == 3) { cv.Image(segments[i], 413, segments[i + 1] - segments[i], 480 - 413, (Brush)resources["img-key1"]); } else { cv.Image(segments[i], 413, segments[i + 1] - segments[i], 480 - 413, (Brush)resources["img-key2"]); } } } //绘制combo { int c = combo; //求总位数算位置 int n = 0; do { c /= 10; n++; } while (c != 0); c = combo; int i = 0; do { cv.Image(segments[2] - 22 + 12 * n - 25 * i, 70, 25, 25, (Brush)resources["img-score-" + c % 10]); ++i; c /= 10; } while (c != 0); } //绘制分数,score += combo + note.status { int s = score; int n = 0; do { s /= 10; n++; } while (s != 0); s = score; int i = 0; do { cv.Image(350 + 12 * n - 25 * i, 50, 25, 25, (Brush)resources["img-score-" + s % 10]); ++i; s /= 10; } while (s != 0); } //Miss判定逻辑 foreach (Note note in song.notes) { if (note.status == Note.Status.Free) { if (note.time < t - 200) { note.status = Note.Status.Miss; note.endstatus = Note.Status.Miss; judgeUI = "0"; combo = 0; } } else if (note.type == Note.Type.Hold && note.endstatus == Note.Status.Free) { if (note.endtime < t - 200) { note.endstatus = Note.Status.Miss; judgeUI = "0"; combo = 0; } } } //绘制判定UI if (judgeUI != null) { double x1 = segments[1] - (segments[2] - segments[1]) / 2; Brush b = ((Brush)resources["img-hit-" + judgeUI]).Clone(); b.Opacity = (double)judgeUITimeout / 10; double scale = judgeUITimeout; Console.WriteLine(judgeUI); cv.Image(x1 - scale, 300 - scale, (segments[4] + segments[3]) / 2 - x1 + 2 * scale, 20 + 2 * scale, b); if (--judgeUITimeout < 5) { ResetJudgeUI(); } } if (song.bgm != null && song.bgm.NaturalDuration.HasTimeSpan && song.bgm.Position.TotalSeconds >= song.bgm.NaturalDuration.TimeSpan.TotalSeconds) { Thread.Sleep(3000); state = Game.state.Summary; redraw = true; } }
public void OnDraw(ref CanvasHelper cv, ref bool redraw) { if (redraw) { redraw = false; cv.cv.Children.Clear(); cv.Image(0, 0, cv.width, cv.height, (Brush)Helper.LoadImage("Skins/bg-black.png")); if (songList.Count == 0) { cv.Text(320 - 80, 240 - 40, 80, "没有发现任何歌曲"); return; } //fade表示切歌了,重新载入song和bgm if (fade) { if (player != null) { player.Stop(); } song = songList[selectIndex]; song.picture.Opacity = 0.2; fade = false; song.Load(difficultyIndex); player = null; } //歌曲名字 cv.Text(0, 50, 30, song.name, Helper.Color("#fff"), 640); //歌曲picture cv.Text(208 - 40, 100 + 80 - 10, 40, "◀", Helper.Color("#ddd"), 40); cv.Image(208, 100, 224, 160, song.picture); cv.Text(208 + 224, 100 + 80 - 10, 40, "▶", Helper.Color("#ddd"), 40); //选择歌曲 cv.Rectangle(0, 0, 640, 50, 0, null, Helper.Color("#FFC0CB", 0.4)); cv.Text(10, 12, 40, "选择歌曲", Helper.Color("#fff")); //方块下落速度 cv.Ellipse(640 - 75, 180 - 65, 150, 150, 1, null, Helper.Color("#fff")); cv.Ellipse(600, 180 - 30, 80, 80, 1, null, Helper.Color("#FFC0CB")); cv.Text(600 + 20, 100 + 80 - 60, 40, "+", Helper.Color("#FFC0CB")); cv.Text(600 + 5, 100 + 80 - 5, 35, factor.ToString(), Helper.Color("#fff"), 40); cv.Text(600 + 20 + 5, 100 + 70 + 80 - 15, 40, "-", Helper.Color("#FFC0CB")); //歌曲数量 cv.Text(640 - 80, 15, 30, string.Format("({0} / {1}) ", selectIndex + 1, songList.Count), Helper.Color("#fff")); //难度名显示 for (int i = 0; i < song.difficuties.Count; ++i) { string dname = song.difficuties[i].Name; if (i == difficultyIndex) { cv.Text(100, 480 - 220 + 10 + 20 * i, 20, dname.Substring(0, dname.Length - 4), Helper.Color("#fff"), 640 - 200); } else { cv.Text(100, 480 - 220 + 10 + 20 * i, 20, dname.Substring(0, dname.Length - 4), Helper.Color("#666"), 640 - 200); } } //开始按钮 cv.Rectangle(260, 380, 120, 40, 3, Helper.Color("#aef"), Helper.Color("#000", 0.3)); cv.Text(260, 385, 40, "Start!", Helper.Color("#fff"), 120); } if (player == null && song.bgm.NaturalDuration.HasTimeSpan) { song.bgm.Position = TimeSpan.FromSeconds(song.bgm.NaturalDuration.TimeSpan.TotalSeconds / 4); song.bgm.Play(); player = song.bgm; } if (player != null && player.Position.TotalSeconds >= player.NaturalDuration.TimeSpan.TotalSeconds - 5) { player.Position = TimeSpan.FromSeconds(player.NaturalDuration.TimeSpan.TotalSeconds / 4); } //歌曲封面图淡入画面 if (song.picture.Opacity < 0.8) { song.picture.Opacity += 0.05; } }