static void RUN() //开始运行函数,在配置完成后使用 { /// ! 开始运行 ! /// //Thread.Sleep(500); //正式启动前最好暂停一小会等待数据加载 //演示一段预渲染画面,按Esc跳过 //Parallel.Invoke(() => Window.Show_Prerendered_Frame("Prerendered_Frame1.txt", 10, "Press esc to exit..."), () => KeyBoard.Start_Up()); //播放背景音乐 //Music.Play_Music("地上bgm"); //启动 -> 显示器 物理效果 键盘输入 Parallel.Invoke(() => Window.Start_Up(), () => Physics.Start_Up(), () => KeyBoard.Start_Up()); /// ! 结束 ! /// }
static void G() { //初始化显示器 Window.Loading(126, 31); //加载图像 Graph.Loading(@"C:\Users\liush\source\repos\Physics_Engine\Graph\"); Graph.Add_File_To_Graphs("封面.txt"); Graph.Show_Look(Graph.All_Graphs["Feng0"]); Thread.Sleep(500); //正式启动前最好暂停一小会等待数据加载 //欢迎画面 Window.Show_Prerendered_Frame("开始.txt", 25); Window.Show_Prerendered_Frame("开始.txt", 25); Graph.Add_File_To_Graphs("马里奥.txt"); Graph.Add_File_To_Graphs("环境组件.txt"); //加载音乐 Music.Loading(@"C:\Users\liush\source\repos\Physics_Engine\Music\"); //载入物体 Window.Loading(130, 50); GameOBJ.Made_Obj("O", 0, 0, 8, 1, Graph.All_Graphs["WORD"]); GameOBJ.Change_Obj_Physics_S("O", false, false); GameOBJ.Made_Obj("Mario", 20, 40, 8, 6, Graph.All_Graphs["StandSmall"]); GameOBJ.Change_Obj_Physics("Mario", 1f, 0, 0, 0, 0, 0.01f, 0.8f); GameOBJ.Change_Obj_Physics_S("Mario", true, true); GameOBJ.Made_Obj("FD", 10, 45, 100, 3, Graph.All_Graphs["Heng"]); GameOBJ.Change_Obj_Physics("FD", 1f, 0, 0, 0, 0, 0.01f, 1); GameOBJ.Change_Obj_Physics_S("FD", false, true); GameOBJ.Made_Obj("FR", 110, 13, 3, 32, Graph.All_Graphs["Shu"]); GameOBJ.Change_Obj_Physics("FR", 1f, 0, 0, 0, 0, 1, 1); GameOBJ.Change_Obj_Physics_S("FR", false, true); //设置物理环境 Physics.Global_GY = 50; //全局重力 Physics.Global_GX = 0; Physics.Global_Max_Speed = 40f; //全局最大速度 //键盘绑定物体 KeyBoard.Control_Obj("Mario"); //参数是被控制物体的名称 //注册事件 Physics.Touched += new Physics.OBJTouch_Events(Get_Touched); //碰撞事件 Physics.Out_Of_Bounds += new Physics.OBJOut_Events(Out_Border); //物体超出屏幕事件 Physics.Alarm_Clock += new Physics.Alarm_Events(Alarm); //闹钟响应事件 KeyBoard.KeyDowm += new KeyBoard.KeyDowm_Events(Key_Down); //按键响应事件 //物理演算主循环的特殊效果延迟ms PS:闹钟、动画... Physics.Main_Loop_Sleep = 10; //加载动画(一个文件一个动画) //Graph.Load_Animation("An1", "封面.txt"); //Graph.Binding_Animation_To_Obj("An1", "A"); Graph.Start_Animation();//启动动画系统 //预渲染画面并保存到文件 Out_Prerendered_Frame(文件名,总渲染帧数) 与Physics.Start_Up()同时运行才有物理效果 //Parallel.Invoke(() => Window.Out_Prerendered_Frame("123.txt", 30), () => Physics.Start_Up(), () => KeyBoard.Start_Up()); //播放背景音乐 Music.Play_Music("地上bgm"); //启动 -> 显示器 物理效果 键盘输入 Parallel.Invoke(() => Window.Start_Up(), () => Physics.Start_Up(), () => KeyBoard.Start_Up()); }
static void Key_Down(string Pressed_Key) //键盘按下事件 Pressed_Key为键值 { if (KeyBoard.Is_Control_Obj) //绑定了物体 { switch (Pressed_Key) { case "0": break; case "UpArrow": if (Is_Land && KeyBoard.Controlling_Obj.Speed_Y > -Physics.Global_Max_Speed) { Is_Land = false; KeyBoard.Controlling_Obj.Speed_Y += -20; } break; case "DownArrow": if (KeyBoard.Controlling_Obj.Speed_Y < Physics.Global_Max_Speed) { if (Is_Land) { //这里应该蹲下 } else { KeyBoard.Controlling_Obj.Speed_Y += 10; } } //KeyBoard.Controlling_Obj.Move(0, 1); break; case "LeftArrow": if (KeyBoard.Controlling_Obj.Speed_X > 0) { KeyBoard.Controlling_Obj.Speed_X = -20; } else if (KeyBoard.Controlling_Obj.Speed_X > -Physics.Global_Max_Speed) { KeyBoard.Controlling_Obj.Speed_X -= 10; } //KeyBoard.Controlling_Obj.Move(-1, 0); break; case "RightArrow": if (KeyBoard.Controlling_Obj.Speed_X < 0) { KeyBoard.Controlling_Obj.Speed_X = 20; } else if (KeyBoard.Controlling_Obj.Speed_X < Physics.Global_Max_Speed) { KeyBoard.Controlling_Obj.Speed_X += 10; } //KeyBoard.Controlling_Obj.Move(1, 0); break; case "S": Physics.Restart_Physics(); break; case "D": Physics.Stop_Physics(); break; case "F": Graph.Start_Animation(); break; case "G": Graph.Close_Animation(); break; case "A": Physics.Restart_Game_Time(); break; case "Escape": if (Window.If_Show_Prerendered_Frame) { //结束预渲染 Window.Stop_Prerendered(); KeyBoard.Close(); } else { //结束全部进程 Physics.Close(); Window.Close(); KeyBoard.Close(); } break; default: break; } } else //没绑定物体 { switch (Pressed_Key) { case "0": break; default: break; } } }