资源简介
玩家1,按W、A、S、D
玩家2 按上、下、左、右
分辨率800*600,自行修改设置
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using dinput = Microsoft.DirectX.DirectInput;
namespace Snake3D
{
public class Game : Form
{
dinput.Device input;
Device device;
Microsoft.DirectX.Direct3D.Font font12;
Microsoft.DirectX.Direct3D.Font font36;
Microsoft.DirectX.Direct3D.Font font24;
const bool FullScreen = true;
const bool AntiAlias = true;
const bool ShowFPS = true;
float ElapsedTime, UpdateTime, AppTime;
private float speed = 0.25f;
Intro intro;
Arena arena;
EventKey Escape, Return;
Level level;
Player[] players = new Player[2];
Random rnd = new Random(Environment.TickCount);
bool IntroPlaying = true;
bool GameFinished = false;
Vector3 ZoomInPoint;
float z = 0f;
public static Vector3 CamPos = new Vector3(40,40,14);
Vector3 UpVector;
static void Main()
{
using (Game frm = new Game())
{
frm.Show();
Application.Run(frm);
}
}
public Game()
{
this.Size = new Size(800,600);
this.StartPosition = FormStartPosition.CenterScreen;
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
this.InitializeInput();
this.InitializeGraphics();
}
private void InitializeInput()
{
dinput.CooperativeLevelFlags coopFlags;
coopFlags = dinput.CooperativeLevelFlags.NonExclusive;
coopFlags |= dinput.CooperativeLevelFlags.Background;
input = new dinput.Device(dinput.SystemGuid.Keyboard);
input.SetCooperativeLevel(this,coopFlags);
input.Acquire();
Escape = new EventKey(dinput.Key.Escape,input);
Escape.KeyUp = new EventHandler(Escape_KeyUp);
Return = new EventKey(dinput.Key.Return,input);
Return.KeyUp = new EventHandler(Return_KeyUp);
}
private void GetInput()
{
dinput.KeyboardState kstate = null;
kstate = input.GetCurrentKeyboardState();
Escape.Process();
Return.Process();
for ( int i = 0; i < players.Length; i )
players[i].CheckKeys(kstate);
}
protected void InitializeGraphics()
{
Cursor.Hide();
PresentParameters pres = new PresentParameters();
pres.Windowed = ! FullScreen;
pres.SwapEffect = SwapEffect.Discard;
pres.EnableAutoDepthStencil = true ;
pres.AutoDepthStencilFormat = DepthFormat.D16;
if ( FullScreen)
{
pres.BackBufferCount = 1;
pres.BackBufferFormat = Format.X8R8G8B8;
pres.BackBufferWidth = 1280;
pres.BackBufferHeight = 1024;
}
int b,Q = 0;
if ( AntiAlias)
{
for ( int i = 0; i < (int) MultiSampleType.SixteenSamples; i )
{
if ( Manager.CheckDeviceMultiSampleType(0,DeviceType.Hardware,Manager.Adapters[0].CurrentDisplayMode.Format,! FullScreen,(MultiSampleType) i,out b,out Q) )
pres.MultiSample = (MultiSampleType) i;
}
pres.MultiSampleQuality = Q-1;
}
device = new Device(0, DeviceType.Hardware, this , CreateFlags.HardwareVertexProcessing | CreateFlags.PureDevice ,
pres);
device.RenderState.CullMode = Cull.None;
font12 = new Microsoft.DirectX.Direct3D.Font(device,new System.Drawing.Font("Arial",12));
font24 = new Microsoft.DirectX.Direct3D.Font(device,new System.Drawing.Font("Arial",24));
font36 = new Microsoft.DirectX.Direct3D.Font(device,new System.Drawing.Font("Arial",36,FontStyle.Bold));
device.Transform.Projection = Matrix.PerspectiveFovLH( (float) Math.PI /2f,(float)this.Width/(float) this.Height ,1f,200f);
level = new Level( (Levels) rnd.Next(Level.numLevels) );
players[0] = new Player(device,dinput.Key.W,dinput.Key.S,
dinput.Key.A,dinput.Key.D,TextureLoader.FromFile(device,@"..\..\tex3.bmp"),level,"玩家 1",0);
players[1] = new Player(device,dinput.Key.UpArrow,dinput.Key.DownArrow,
dinput.Key.LeftArrow,dinput.Key.RightArrow,TextureLoader.FromFile(device,@"..\..\tex1.bmp"),level,"玩家 2",1);
for ( int i = 0; i < players.Length; i )
players[i].onLost = new lost(Playerlost);
device.SamplerState[0].MagFilter = TextureFilter.Anisotropic;
device.SamplerState[0].MinFilter = TextureFilter.Anisotropic;
intro = new Intro(device,"双人贪吃蛇 3D");
intro.Start(DXUtil.Timer(DirectXTimer.GetAbsoluteTime) );
intro.Ready = new Finished(IntroFinished);
arena = new Arena(device,TextureLoader.FromFile(device,@"..\..\tex4.bmp"),level);
}
代码片段和文件信息
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace Snake3D
{
public class Arena
{
private Texture tex;
private Device device;
private Material mat = new Material();
plane Plane p2p3;
plane obstacle;
Vector3[] obstacles;
public static Vector3 ArenaCenter;
public Arena(Device dTexture tLevel lev)
{
device = d;
tex = t;
ArenaCenter = new Vector3(40030);
Size s = new Size(8060);
Plane = new plane(devicetex1new Size(s.Widths.Height));
p2 = new plane(devicetexs.Widthnew Size(5s.Height) );
p3 = new plane(devicetexs.Heightnew Size(s.Width5) );
obstacle = new plane(deviceTextureLoader.FromFile(device@“..\..\tex2.bmp“)1.65f);
mat.Ambient = Color.DarkGra属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 55808 2018-01-19 23:59 Snake3D\.vs\Snake3D\v15\.suo
文件 0 2018-01-19 23:23 Snake3D\.vs\Snake3D\v15\Server\sqlite3\db.lock
文件 1265664 2018-01-19 23:59 Snake3D\.vs\Snake3D\v15\Server\sqlite3\storage.ide
文件 207 2018-01-19 23:26 Snake3D\app.config
文件 1078 2004-08-04 10:23 Snake3D\App.ico
文件 2350 2018-01-19 23:48 Snake3D\Arena.cs
文件 446 2018-01-19 23:52 Snake3D\AssemblyInfo.cs
文件 473600 2017-12-04 22:58 Snake3D\bin\Debug\Microsoft.DirectX.Direct3D.dll
文件 578560 2017-12-04 22:58 Snake3D\bin\Debug\Microsoft.DirectX.Direct3DX.dll
文件 159232 2017-12-04 22:58 Snake3D\bin\Debug\Microsoft.DirectX.DirectInput.dll
文件 223232 2017-12-04 22:58 Snake3D\bin\Debug\Microsoft.DirectX.dll
文件 45056 2018-01-19 23:59 Snake3D\bin\Debug\Snake3D.exe
文件 207 2018-01-19 23:26 Snake3D\bin\Debug\Snake3D.exe.config
文件 48640 2018-01-19 23:59 Snake3D\bin\Debug\Snake3D.pdb
文件 5753 2018-01-19 23:50 Snake3D\DXUtil.cs
文件 1036 2018-01-19 23:51 Snake3D\EventKey.cs
文件 8464 2018-01-19 23:46 Snake3D\Form1.cs
文件 8289 2004-08-07 11:19 Snake3D\Form1.resx
文件 2090 2018-01-19 23:43 Snake3D\Intro.cs
文件 3411 2018-01-19 23:43 Snake3D\Level.cs
文件 1815 2004-08-07 14:12 Snake3D\Outro.cs
文件 6851 2018-01-19 23:44 Snake3D\plane.cs
文件 2996 2018-01-19 23:44 Snake3D\Pla
文件 6738 2018-01-19 23:33 Snake3D\Snake3D.csproj
文件 2083 2018-01-19 23:23 Snake3D\Snake3D.csproj.user
文件 1107 2018-01-19 23:23 Snake3D\Snake3D.sln
文件 196662 2004-08-05 19:53 Snake3D\tex1.bmp
文件 196662 2004-08-06 10:29 Snake3D\tex2.bmp
文件 196662 2004-08-04 19:05 Snake3D\tex3.bmp
文件 196662 2004-07-04 16:55 Snake3D\tex4.bmp
............此处省略13个文件信息
- 上一篇:C# 终结者2压枪 辅助工具源码
- 下一篇:中国象棋源码
相关资源
- adsl 自动拨号类 源码
- C# 读取并编辑window系统的右键菜单
- 通过C#自带的头文件(类)获取Windo
- C#获取电脑CPU以及内存使用率
- Syndication实现读取、创建、订阅、更新
- jQuery lazyload-预加载 功能,已经通过运
- tf-idf一种计算方法
- httpclient source code by csharp
- NServiceKit.Redis 基础操作
- Prodave6联接程序源码
- UDP Messenger 1.0.unitypackage
-
C# 播放铃声(AxWindowsMediaPla
yer)最新 - wpf实现展开收缩效果(ShrinkSpread)
- C# FileStream寫入檔案、StreamReader讀取、
- C# 透過 Google map Geocoder API 以經緯度
- DevExpress_14.1.4破解补丁
- Heizungsregler(Ein digitaler Heizungsregler)
- 二维表
- AD 操作 Helper类代码
- NAudio实现mp3转换成wav
- A 2D/3D force directed graph algorithm in C#
- halcon标定(基于HalconDotNet)
- Dotween.unitypackage
- C# 创建PDF文档
- DotNetZip 解压缩 以及分卷压缩类
- 通过Visual Studio项目预生成命令获取
- C# 快捷查看文件夹下所有文件的MD5
- C# 文件編碼轉換器FileCodeConvert
- C# 文件编码转换工具(支持UTF-8/UTF-
- word中批注替换和查找替换

评论
共有 条评论