Exemplo n.º 1
0
        void LoadContentGame()
        {
            font        = Content.Load <SpriteFont>("SpriteFonts/Arial");
            spriteBatch = new SpriteBatch(GraphicsDevice);

            EffectMesh = Content.Load <Effect>("Effects/BasicShader");
            EffectSmd  = Content.Load <Effect>("Effects/SMDEffect");
            EffectSmd.CurrentTechnique = EffectSmd.Techniques["SkinnedMesh"];

            // Arma
            weapon = new CWeapon(this, GraphicsDevice, Content, cs_folder);

            // Soldado
            soldier = new CSMDModel("player\\ct_sas", GraphicsDevice, Content, cs_folder);
            soldier.cargar_ani("player\\cs_player_shared_anims", "Death1");
            soldier.anim[0].loop = false;
            soldier.cargar_ani("player\\cs_player_shared_anims", "a_WalkN");
            soldier.anim[1].in_site = true;
            soldier_height          = soldier.size.Y;
            soldier.debugEffect     = EffectMesh;

            // Hostage
            for (int i = 0; i < NUM_HOSTAGE; ++i)
            {
                hostage_model[i] = new CSMDModel("characters\\hostage_0" + (i + 1).ToString(), GraphicsDevice, Content, cs_folder);
                hostage_model[i].cargar_ani("characters\\hostage_0" + (i + 1).ToString() + "_anims", "ragdoll");
                hostage_model[i].anim[0].loop = false;
                hostage_model[i].debugEffect  = EffectMesh;
            }


            // huevo de pascuas
            tgcLogo = Content.Load <Model>("Models/tgc-logo/tgc-logo");
            var modelEffect = (BasicEffect)tgcLogo.Meshes[0].Effects[0];

            modelEffect.DiffuseColor = Color.DarkBlue.ToVector3();
            modelEffect.EnableDefaultLighting();

            debug_box = new CDebugBox(GraphicsDevice);

            scene = new CBspFile(map_name, GraphicsDevice, Content);

            skybox = new CSkybox(GraphicsDevice);

            player = new CPlayer(scene, this);

            Random rnd = new Random();

            for (int i = 0; i < MAX_ENEMIGOS; ++i)
            {
                enemigo[i]          = new CEnemy(scene, this, soldier);
                enemigo[i].Position = new Vector3(rnd.Next((int)scene.p_min.X, (int)scene.p_max.X),
                                                  scene.p_max.Y, rnd.Next((int)scene.p_min.Z, (int)scene.p_max.Z));
                enemigo[i].Position = new Vector3(7242 + rnd.Next(-300, 300), -493, 6746 + rnd.Next(-300, 300));

                float an = rnd.Next(0, 360) * MathF.PI / 180.0f;
                enemigo[i].Direction        = new Vector3(MathF.Cos(an), 0, MathF.Sin(an));
                enemigo[i].currentTime      = rnd.Next(100);
                enemigo[i].currentAnimation = 1;
            }

            enemigo[0].PrevPosition = enemigo[0].Position = new Vector3(6447, -800, 6276);
            enemigo[0].Direction    = new Vector3(0, 0, -1);
            player.Position         = scene.info_player_start_pos;
            player.Direction        = new Vector3(0, 0, 1);

            cant_hostages = scene.cant_hostages;
            for (int i = 0; i < cant_hostages; ++i)
            {
                hostage[i]                  = new CEnemy(scene, this, hostage_model[i % 4]);
                hostage[i].Position         = scene.hostages[i].origin;
                hostage[i].Position.Y      += hostage_model[i % 4].cg.Y;
                hostage[i].currentAnimation = 0;
            }

            base.LoadContent();
        }
Exemplo n.º 2
0
        public void DrawMap(CPlayer player, CEnemy [] enemigo)
        {
            Vector3 Position  = player.Position;
            Vector3 Direction = player.Direction;

            Viewport ant_vp = device.Viewport;
            var      vp     = new Viewport();

            vp.X = 10;
            vp.Y = 50;
            float aspect = (float)ant_vp.Width / (float)ant_vp.Height;

            vp.Width               = vp.Height = 200;
            vp.MinDepth            = 0;
            vp.MaxDepth            = 1;
            device.Viewport        = vp;
            device.RasterizerState = RasterizerState.CullNone;

            device.DepthStencilState = DepthStencilState.None;
            Effect.CurrentTechnique  = Effect.Techniques["ClearScreen"];
            Effect.Parameters["World"].SetValue(Matrix.Identity);
            Effect.Parameters["View"].SetValue(Matrix.Identity);
            Effect.Parameters["Projection"].SetValue(Matrix.Identity);
            device.SetVertexBuffer(spriteVertexBuffer);
            foreach (var pass in Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.DrawPrimitives(PrimitiveType.TriangleList, 0, 2);
            }
            device.Clear(ClearOptions.DepthBuffer, Color.White, 1.0f, 0);

            Direction.Y = 0;
            Direction.Normalize();
            Matrix View  = Matrix.CreateLookAt(Position, Position + Direction * 100, new Vector3(0, 1, 0));
            Matrix World = Matrix.Identity;
            float  kx    = 1.0f / size.X;
            float  ky    = 1.0f / size.Y;
            float  kz    = 1.0f / size.Z;

            kx *= 5 * aspect;
            kz *= 5;
            Matrix S = new Matrix(-kx, 0, 0, 0,
                                  0, 0, ky, 0,
                                  0, -kz, 0, 0,
                                  0, 0, 0.5f, 1);

            Matrix Proj = S;

            device.SetVertexBuffer(VertexBuffer);
            Effect.CurrentTechnique = Effect.Techniques["Map"];
            Effect.Parameters["World"].SetValue(World);
            Effect.Parameters["View"].SetValue(View);
            Effect.Parameters["Projection"].SetValue(Proj);
            Effect.Parameters["Lightmap"].SetValue(lightmap);

            device.BlendState = BlendState.AlphaBlend;

            // escenario estatico
            var pos = 0;

            for (var i = 0; i < cant_subsets; i++)
            {
                var cant_tri   = subset[i].cant_items;
                var cant_items = cant_tri * 3;
                if (cant_items > 0)
                {
                    if (mostrar_tools || !subset[i].image_name.StartsWith("TOOLS"))
                    {
                        Effect.Parameters["ModelTexture"].SetValue(texture[i] != null ? texture[i] : texture_default);
                        foreach (var pass in Effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();
                            device.DrawPrimitives(PrimitiveType.TriangleList, pos, cant_tri);
                        }
                    }
                    pos += cant_items;
                }
            }

            // modelos estaticos
            EffectMesh.CurrentTechnique = EffectMesh.Techniques["Map"];
            for (var L = 0; L < 1; ++L)
            {
                for (var i = 0; i < cant_modelos; ++i)
                {
                    Matrix    world  = modelos[i].world();
                    CSMDModel p_mesh = mesh_pool.meshes[modelos[i].nro_mesh];
                    p_mesh.Draw(device, EffectMesh, world, View, Proj, L);
                }
            }


            BeginDrawImage();
            int W = device.Viewport.Width;
            int H = device.Viewport.Height;

            // dibujo la posicion del cero
            device.BlendState = BlendState.Additive;
            DrawImage(0, W / 2, H / 2, 20, 20);

            // dibujo la pos. de los enemigos
            Matrix T = World * View * Proj;

            for (int i = 0; i < enemigo.Length; ++i)
            {
                Vector4 v = Vector4.Transform(enemigo[i].Position, T);
                if (v.W > 0)
                {
                    float x = v.X / v.W;
                    float y = v.Y / v.W;
                    float d = x * x + y * y;
                    if (d < 0.9f)
                    {
                        int xs = (int)(W * (0.5f + x / 2));
                        int ys = (int)(H * (0.5 - y / 2));
                        DrawImage(2, xs - 5, ys - 5, 10, 10);
                    }
                }
            }
            device.Viewport          = ant_vp;
            device.DepthStencilState = DepthStencilState.Default;
        }