예제 #1
0
 public Floor(Device device, int sizeX, int sizeZ, CallOfCS cocs)
     : base(device,cocs,0,0,1)
 {
     this.sizeX = sizeX;
     this.sizeZ = sizeZ;
     vBuff = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), sizeX * sizeZ * 4, device, 0, CustomVertex.PositionNormalTextured.Format, Pool.Managed);
     OnVertexBufferCreate(vBuff, null);
     this.inited = true;
 }
예제 #2
0
 public CommonClass(Device device, CallOfCS cocs, short posX, short posZ, short textureindex)
 {
     this.device = device;
     this.cocs = cocs;
     this.size_of_one_rectangle = cocs.size_of_one_rectangle;
     this.posX = posX;
     this.posZ = posZ;
     this.textureIndex = textureindex;
 }
예제 #3
0
        public Wall(Device device, CallOfCS cocs, short posX, short posZ)
            : base(device, cocs, posX, posZ, 2)
        {
            this.posY = 0;
            this.realPos = new Vector3(posX*size_of_one_rectangle,posY*size_of_one_rectangle,posZ*size_of_one_rectangle);
            this.center = new Vector3((posX+0.5f)*size_of_one_rectangle,size_of_one_rectangle*vyska*0.5f,(posZ+0.5f)*size_of_one_rectangle);

            this.rotSpeed = 0.001f;
            vBuff = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 24, device, Usage.None, CustomVertex.PositionNormalTextured.Format, Pool.Managed);
            OnVertexBufferCreate(vBuff,null);
            this.inited = true;
        }
예제 #4
0
 public OneTriangle(Device device, CallOfCS cocs, CustomVertex.PositionNormalTextured first, CustomVertex.PositionNormalTextured second, CustomVertex.PositionNormalTextured third)
     : base(device,cocs,0,0,0)
 {
     verts = new CustomVertex.PositionNormalTextured[3];
     verts[0] = first;
     verts[1] = second;
     verts[2] = third;
     this.center = new Vector3((first.X+second.X+third.X)/3,(first.Y+second.Y+third.Y)/3,(first.Z+second.Z+third.Z)/3);
     vBuff = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 3, device, Usage.None, CustomVertex.PositionNormalTextured.Format, Pool.Managed);
     vBuff.SetData(verts,0,LockFlags.None);
     this.count = 1;
     this.type = PrimitiveType.TriangleList;
 }
예제 #5
0
        public Cube(Device device, CallOfCS cocs, short posX, short posZ)
            : base(device,cocs,posX,posZ,7)
        {
            this.center = new Vector3((posX + 0.5f) * size_of_one_rectangle, size_of_one_rectangle * 0.7f, (posZ + 0.5f) * size_of_one_rectangle);

            this.rotSpeed = constSpeed;
            lastMove = System.Environment.TickCount;
            triangles = new ArrayList();

            //Totally describe the 3D cube using three dimensional points
            this.verts = new CustomVertex.PositionNormalTextured[24];
            // Front face                                         x      y      z      nx     ny     nz    tu    tv
            verts[0]  = new CustomVertex.PositionNormalTextured( 0.0f,  0.0f,  0.0f,  0.0f,  0.0f, -1.0f, 0.0f, 1.0f);
            verts[1]  = new CustomVertex.PositionNormalTextured( 1.0f,  1.0f,  0.0f,  0.0f,  0.0f, -1.0f, 1.0f, 0.0f);
            verts[2]  = new CustomVertex.PositionNormalTextured( 1.0f,  0.0f,  0.0f,  0.0f,  0.0f, -1.0f, 1.0f, 1.0f);
            verts[3]  = new CustomVertex.PositionNormalTextured( 0.0f,  1.0f,  0.0f,  0.0f,  0.0f, -1.0f, 0.0f, 0.0f);
            // Right face
            verts[4]  = new CustomVertex.PositionNormalTextured( 1.0f,  0.0f,  0.0f,  1.0f,  0.0f,  0.0f, 0.0f, 1.0f);
            verts[5]  = new CustomVertex.PositionNormalTextured( 1.0f,  1.0f,  1.0f,  1.0f,  0.0f,  0.0f, 1.0f, 0.0f);
            verts[6]  = new CustomVertex.PositionNormalTextured( 1.0f,  0.0f,  1.0f,  1.0f,  0.0f,  0.0f, 1.0f, 1.0f);
            verts[7]  = new CustomVertex.PositionNormalTextured( 1.0f,  1.0f,  0.0f,  1.0f,  0.0f,  0.0f, 0.0f, 0.0f);
            // Back face
            verts[8]  = new CustomVertex.PositionNormalTextured( 1.0f,  0.0f,  1.0f,  0.0f,  0.0f,  1.0f, 0.0f, 1.0f);
            verts[9]  = new CustomVertex.PositionNormalTextured( 0.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f, 1.0f, 0.0f);
            verts[10]  = new CustomVertex.PositionNormalTextured( 0.0f,  0.0f,  1.0f,  0.0f,  0.0f,  1.0f, 1.0f, 1.0f);
            verts[11]  = new CustomVertex.PositionNormalTextured( 1.0f,  1.0f,  1.0f,  0.0f,  0.0f,  1.0f, 0.0f, 0.0f);
            // Left face
            verts[12]  = new CustomVertex.PositionNormalTextured( 0.0f,  0.0f,  1.0f, -1.0f,  0.0f,  0.0f, 0.0f, 1.0f);
            verts[13]  = new CustomVertex.PositionNormalTextured( 0.0f,  1.0f,  0.0f, -1.0f,  0.0f,  0.0f, 1.0f, 0.0f);
            verts[14]  = new CustomVertex.PositionNormalTextured( 0.0f,  0.0f,  0.0f, -1.0f,  0.0f,  0.0f, 1.0f, 1.0f);
            verts[15]  = new CustomVertex.PositionNormalTextured( 0.0f,  1.0f,  1.0f, -1.0f,  0.0f,  0.0f, 0.0f, 0.0f);
            // Top face
            verts[16]  = new CustomVertex.PositionNormalTextured( 0.0f,  1.0f,  0.0f,  0.0f,  1.0f,  0.0f, 0.0f, 1.0f);
            verts[17]  = new CustomVertex.PositionNormalTextured( 1.0f,  1.0f,  1.0f,  0.0f,  1.0f,  0.0f, 1.0f, 0.0f);
            verts[18]  = new CustomVertex.PositionNormalTextured( 1.0f,  1.0f,  0.0f,  0.0f,  1.0f,  0.0f, 1.0f, 1.0f);
            verts[19]  = new CustomVertex.PositionNormalTextured( 0.0f,  1.0f,  1.0f,  0.0f,  1.0f,  0.0f, 0.0f, 0.0f);
            // Bottom face
            verts[20]  = new CustomVertex.PositionNormalTextured( 0.0f,  0.0f,  1.0f,  0.0f, -1.0f,  0.0f, 0.0f, 1.0f);
            verts[21]  = new CustomVertex.PositionNormalTextured( 1.0f,  0.0f,  0.0f,  0.0f, -1.0f,  0.0f, 1.0f, 0.0f);
            verts[22]  = new CustomVertex.PositionNormalTextured( 1.0f,  0.0f,  1.0f,  0.0f, -1.0f,  0.0f, 1.0f, 1.0f);
            verts[23]  = new CustomVertex.PositionNormalTextured( 0.0f,  0.0f,  0.0f,  0.0f, -1.0f,  0.0f, 0.0f, 0.0f);
            for(short i = 0; i < 6; i++)
            {
                triangles.Add(new OneTriangle(device,cocs,verts[(i*4)],verts[(i*4 + 1)],verts[(i*4 + 2)]) );
                triangles.Add(new OneTriangle(device,cocs,verts[(i*4)],verts[(i*4 + 3)],verts[(i*4 + 1)]) );
            }
            this.useTriangles = true;
            this.inited = true;
        }
예제 #6
0
        public Target(Device device, CallOfCS cocs, short posX, short posZ)
            : base(device, cocs, posX, posZ, 3)
        {
            this.rotSpeed = 0.0005f;

            posXReal = (posX+0.5f)*size_of_one_rectangle;
            posZReal = (posZ+0.5f)*size_of_one_rectangle;
            System.Random foo = new Random(posX);
            rand = foo.Next(0,10000000);
            vBuff = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 4, device, 0/*Usage.Dynamic | Usage.WriteOnly*/, CustomVertex.PositionNormalTextured.Format, Pool.Managed);//24 - je prasarna...
            //vBuff.Created += new EventHandler(this.OnVertexBufferCreate);
            //device.DeviceReset += new EventHandler(this.OnVertexBufferCreate);
            OnVertexBufferCreate(vBuff,null);

            this.inited = true;
        }
예제 #7
0
        public Projectile(Device device, CallOfCS cocs, Vector3 position, float angleZX, float angleZY)
            : base(device, cocs, 0, 0,6)
        {
            startTime = System.Environment.TickCount;
            this.position = position;
            this.angleZX = angleZX;
            this.angleZY = angleZY;
            this.direction = new Vector3((float)-Math.Sin(angleZX),(float) Math.Sin(angleZY),(float) Math.Cos(angleZX));
            this.direction.Normalize();

            this.rotSpeed = 0.008f;

            vBuff = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), 18, device, 0/*Usage.Dynamic | Usage.WriteOnly*/, CustomVertex.PositionNormalTextured.Format, Pool.Managed);//24 - je prasarna...

            OnVertexBufferCreate(vBuff,null);

            this.inited = true;
        }
예제 #8
0
 static void Main(string[] Args)
 {
     CallOfCS game = new CallOfCS();
     //device
     game.workingwindow = new WorkingWindow(800, 600, 0, 0, "Call Of CSharp");
     game.workingwindow.CreateDevice();
     game.device = game.workingwindow.Device;
     //sound
     game.dsDevice = new Microsoft.DirectX.DirectSound.Device();
     game.dsDevice.SetCooperativeLevel(game.workingwindow.form, CooperativeLevel.Priority);
     //init
     game.Init();
     //cursor setup
     game.centerX = game.workingwindow.Size.Width / 2;
     game.centerY = game.workingwindow.Size.Height / 2;
     Cursor.Position = new Point(game.workingwindow.form.Left + game.centerX, game.workingwindow.form.Top + game.centerY);
     Cursor.Hide();
     game.workingwindow.form.KeyDown += new System.Windows.Forms.KeyEventHandler(game.kDown);
     game.workingwindow.form.KeyUp += new System.Windows.Forms.KeyEventHandler(game.kUp);
     game.workingwindow.Idle += new CustomIdleEventHandler(game.idle);
     game.workingwindow.form.MouseMove += new System.Windows.Forms.MouseEventHandler(game.mMove);
     game.workingwindow.form.MouseDown += new System.Windows.Forms.MouseEventHandler(game.mbDown);
     game.workingwindow.form.MouseUp += new System.Windows.Forms.MouseEventHandler(game.mbUp);
     // Run
     game.workingwindow.Run();
 }
예제 #9
0
        public void ReadFromFile(string fileName, Device device, CallOfCS cocs)
        {
            ArrayList addLater = new ArrayList();
            try
            {
                Directory.SetCurrentDirectory(Directory.GetCurrentDirectory() + @"\data\");
                StreamReader tr = new StreamReader(fileName, System.Text.Encoding.ASCII);
                string ln;
                string[] tokens = tr.ReadLine().Split('x');
                if (tokens.Length != 2)
                {
                    System.Console.WriteLine("Map file is corrupted. Size is not defined.");
                    System.Environment.Exit(0);
                }

                try
                {
                    sizeX = Convert.ToInt16(tokens[0]);
                    sizeZ = Convert.ToInt16(tokens[1]);
                    if (sizeX > 100 || sizeZ > 100)
                    {
                        System.Console.WriteLine("Map file is corrupted. Size of map is not defined properly.");
                        System.Environment.Exit(0);
                    }
                }
                catch (FormatException e)
                {
                    System.Console.WriteLine("Map file is corrupted. Size is not defined properly."+e.ToString());
                    System.Environment.Exit(0);
                }
                cocs.universe.Add(new Floor(device, sizeX, sizeZ, cocs));

                cocs.mapSizeX = sizeX;
                cocs.mapSizeZ = sizeZ;
                cocs.mapRealSizeX = cocs.mapSizeX * cocs.size_of_one_rectangle;
                cocs.mapRealSizeZ = cocs.mapSizeZ * cocs.size_of_one_rectangle;

                cocs.aArea = new bool[sizeX, sizeZ];
                for (short k = 0; k < sizeX; k++)
                {
                    for (short l = 0; l < sizeZ; l++)
                    {
                        cocs.aArea[k, l] = true;
                    }
                }

                short j = sizeZ;
                while (((ln = tr.ReadLine()) != null) && j > 0)
                {
                    j--;
                    for (short i = 0; i < Math.Min(sizeX, ln.Length); i++)
                    {
                        switch (ln[i])
                        {
                            case 'A':
                            case 'B':
                            case 'C':
                            case 'D':
                            case 'E':
                            case 'F':
                            case 'G':
                                Object someobject = new Wall(device, cocs, i, j);
                                cocs.universe.Add(someobject);
                                cocs.aArea[i, j] = false;
                                cocs.actionObjects.Add(someobject);
                                break;
                            case '*':
                            case 'a':
                            case 'b':
                            case 'c':
                            case 'd':
                            case 'e':
                            case 'f':
                            case 'g':
                            case 'h':
                            case 'i':
                            case 'j':
                            case 'k':
                            case 'l':
                            case 'm':
                            case 'n':
                            case 'H':
                            case 'I':
                            case 'J':
                            case 'K':
                            case 'L':
                            case 'M':
                            case 'N':
                                cocs.universe.Add(new Wall(device, cocs, i, j));
                                cocs.aArea[i, j] = false;
                                break;
                            case 'O':
                            case 'P':
                            case 'Q':
                            case 'R':
                            case 'S':
                                cocs.myPosX = cocs.size_of_one_rectangle * (i + 0.5f);
                                cocs.myPosZ = cocs.size_of_one_rectangle * (j + 0.5f);
                                break;
                            case 'T':
                                someobject = new Target(device, cocs, i, j);
                                //addLater.Add(someobject);
                                cocs.universe.Add(someobject);
                                cocs.actionObjects.Add(someobject);
                                cocs.numberOfTargets++;
                                break;
                            case 'U':
                            case 'V':
                            case 'W':
                            case 'X':
                            case 'Y':
                            case 'Z':
                                someobject = new Cube(device, cocs, i, j);
                                addLater.Add(someobject);
                                cocs.actionObjects.Add(someobject);
                                cocs.numberOfItems++;
                                break;
                            case '#':
                                addLater.Add(new Cube(device, cocs, i, j));
                                cocs.aArea[i, j] = false;
                                break;
                        }

                    }
                }
                foreach (CommonClass ikx in addLater)
                    cocs.universe.Add(ikx);
                tr.Close();
            }
            catch (DirectoryNotFoundException e)
            {
                System.Console.WriteLine("Directory not found"+e.ToString());
                System.Environment.Exit(0);
            }
            catch (FileNotFoundException e)
            {
                System.Console.WriteLine("File : " + fileName + " not found!"+e.ToString());
                System.Environment.Exit(0);
            }
        }