Example #1
0
        public void Draw(GameTime gametime, Camera camera)
        {
            Effect.View = camera.View;

            Effect.Projection = camera.Projection;
            Effect.World = Matrix.Identity;
            Effect.Texture = texture;

            graphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;

            foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleStrip, vertices, 0, numVertices, indices, 0, numWallTriangles);

            }

            Effect.Texture = roofTexture;

            foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleStrip, vertices, 0, numVertices, indices, offsetRoofIndices, numRoofTriangles);

            }
        }
Example #2
0
        public static void DetectCameraBuildingCollisions(Camera camera,Building building)
        {
            if (building.BoundingBox.Max.Y < camera.BoundingSphere.Center.Y)
                return;
            if(camera.BoundingSphere.Intersects(building.BoundingBox)){
                float leftSep = building.BoundingBox.Min.X - (camera.BoundingSphere.Center.X + camera.BoundingSphere.Radius) ;
                float rightSep =building.BoundingBox.Max.X -(camera.BoundingSphere.Center.X - camera.BoundingSphere.Radius);
                float topSep =  building.BoundingBox.Max.Z - (camera.BoundingSphere.Center.Z - camera.BoundingSphere.Radius);
                float botSep =  building.BoundingBox.Min.Z -(camera.BoundingSphere.Center.Z + camera.BoundingSphere.Radius);

                float moveXaxis=rightSep;
                if(Math.Abs(leftSep)<Math.Abs(rightSep))
                    moveXaxis = leftSep;
                float moveZaxis=topSep;
                if(Math.Abs(botSep)<Math.Abs(topSep))
                    moveZaxis = botSep;

                if (Math.Abs(moveXaxis) < Math.Abs(moveZaxis))
                {
                    camera.ShiftAlongX(moveXaxis);
                }
                else
                {
                    camera.ShiftAlongZ(moveZaxis);
                }

            }
        }
Example #3
0
        public void Update(GameTime gametime, Camera camera)
        {
            float time=(float)gametime.ElapsedGameTime.TotalMilliseconds/1000.0f;

            rotation += angularVelocity * time;
            position += velocity * time;
            velocity += force * time;

            if (size.X < maxSize.X)
            {
                size *= 1.02f;
            }

            Matrix billboardM = Matrix.CreateBillboard(position, camera.Position, camera.Up, camera.Direction);
            Matrix rotationM = Matrix.CreateRotationZ(rotation);
            Matrix scaleM = Matrix.CreateScale(size.X, size.Y, 1);
            //Matrix translateM = Matrix.CreateTranslation(position);

            Matrix transform = scaleM * rotationM * billboardM;//* scaleM;//*rotationM*scaleM

            for (int i = 0; i < 4; i++)
            {
                verts[i].Position = Vector3.Transform(initVertsPos[i], transform);
                verts[i].Color.A = (byte)( 255.0*(1 -(age / maxAge)));

                if ((1 - (age / maxAge)) < 0.0f)
                {
                    ;
                }
            }

               age += time;
        }
Example #4
0
        public void Draw(Camera camera,GraphicsDevice g)
        {
            Effect.View = camera.View;
            Effect.Projection = camera.Projection;
            Effect.World = Matrix.CreateBillboard(position, camera.Position, camera.Up, camera.Direction);
            Effect.Texture = texture;

                foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    g.DrawUserPrimitives(PrimitiveType.TriangleStrip, verts, 0, 2);
                }
        }
Example #5
0
File: NPC.cs Project: kenpower/XNA4
        public override void Draw(GameTime gametime, Camera camera)
        {
            foreach (ModelMesh m in model.Meshes)
            {
                foreach (BasicEffect e in m.Effects)
                {

                    e.World =   Matrix.CreateScale(0.01f)*Matrix.CreateTranslation(position)* Matrix.CreateTranslation(6, 3.1f, 6);
                    e.Projection = camera.Projection;
                    e.View = camera.View;
                }

                m.Draw();
            }
        }
Example #6
0
        public override void Draw(GameTime gametime, Camera camera)
        {
            effect.View = camera.View;

            effect.Projection = camera.Projection;
            effect.World = rotationMatrix;
            effect.Texture = texture;

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleStrip, vertices, 0, numVertices, indices, 0, numTriangles);

            }
        }
Example #7
0
        public void Update(GameTime gametime, Camera camera)
        {
            float time=(float)gametime.ElapsedGameTime.TotalMilliseconds/1000.0f;

            position += velocity * time;

            Matrix billboardM = Matrix.CreateBillboard(position, camera.Position, camera.Up, camera.Direction);

            Matrix transform = billboardM;//* scaleM;//*rotationM*scaleM

            for (int i = 0; i < 4; i++)
            {
                verts[i].Position = Vector3.Transform(initVertsPos[i], transform);

            }
        }
Example #8
0
        public override void Draw(GameTime gametime, Camera camera)
        {
            Matrix orientation = Matrix.CreateFromYawPitchRoll(yawAngle, pitchAngle, 0);
                Matrix world = orientation * Matrix.CreateTranslation(position);

                foreach (ModelMesh m in model.Meshes)
                {
                    foreach (BasicEffect e in m.Effects)
                    {
                        e.EnableDefaultLighting();
                        e.World = world;
                        e.Projection = camera.Projection;
                        e.View = camera.View;
                    }

                    m.Draw();
                }
                base.Draw(gametime, camera);
        }
Example #9
0
        public void Update(GameTime gametime, Camera camera)
        {
            emmiter.Update(gametime, particles);

            particles.RemoveAll(delegate(Particle p) { return p.age >= p.maxAge; });

            foreach (Particle p in particles)
            {
                p.Update(gametime,camera);
            }
        }
Example #10
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            blockSize = new Rectangle(0, 0, 15, 15);
            buildings = new List<Building>();

            BuildingFactory.Init(this,blockSize);

            for(int z=0;z<map.Length;z++){
                for(int x=0;x<map[z].Length;x++){
                    char c=map[z][x];
                    if (BuildingFactory.buildingSymbols.Contains(c))
                    {
                        Building b = BuildingFactory.makeBuilding(map[z][x], new Vector2(x, z) );
                        buildings.Add(b);
                    }
                }
            }

            streets = new List<Street>();

            StreetFactory.Init(this, blockSize);

            for (int z = 0; z < map.Length; z++)
            {
                for (int x = 0; x < map[z].Length; x++)
                {
                    char c = map[z][x];
                    if (StreetFactory.streetSymbols.Contains(c))
                    {
                        Street s = StreetFactory.makeStreet(map[z][x], new Vector2(x, z));
                        streets.Add(s);
                    }
                }
            }

            flares = new List<ParticleSystem>();

            ParticleSystemFactory.Init(this, blockSize);

            for (int z = 0; z < map.Length; z++)
            {
                for (int x = 0; x < map[z].Length; x++)
                {
                    char c = map[z][x];
                    if (ParticleSystemFactory.particleSymbols.Contains(c))
                    {
                        ParticleSystem ps = ParticleSystemFactory.makeParticleSystem(map[z][x], new Vector2(x, z));
                        flares.Add(ps);
                    }
                }
            }

            npcs = new List<NPC>();

            NPCFactory.Init(this, blockSize);

            for (int z = 0; z < NPCmap.Length; z++)
            {
                for (int x = 0; x < NPCmap[z].Length; x++)
                {
                    char c = NPCmap[z][x];
                    if (NPCFactory.NPCSymbols.Contains(c))
                    {
                        NPC npc = NPCFactory.makeNPC(c, new Vector2(x, z));
                        npcs.Add(npc);
                    }
                }
            }

            MissileFactory.Init(this, blockSize);
            MissileFactory.makeMissile(new Vector2(0, 0));

            camera = new Camera();
            camera.Init(new Vector3(0, 10, 0), new Vector3(50, 10, 50), Vector3.Up,0.6f,graphics.GraphicsDevice.Viewport.AspectRatio,1,1000);

            base.Initialize();
        }
Example #11
0
File: NPC.cs Project: kenpower/XNA4
 public abstract override void Draw(GameTime gametime, Camera camera);
Example #12
0
        public void Draw(GameTime gametime, Camera camera)
        {
            Effect.View = camera.View;
            Effect.Projection = camera.Projection;
            Effect.World = Matrix.Identity;
            Effect.Texture = texture;

            int i = 0;
            for(int j=particles.Count-1;j>=0;j--)
            {
                particles[j].getVertices(vertices, i * 6);
                i++;
            }

            BlendState bs = new BlendState();
            BlendState oldbs = graphicsDevice.BlendState;

            bs.ColorBlendFunction = BlendFunction.Add;

            bs.AlphaSourceBlend = Blend.SourceAlpha;
            bs.ColorSourceBlend = Blend.SourceAlpha;

            bs.BlendFactor = Color.Blue;

            bs.AlphaDestinationBlend = Blend.One;
            bs.ColorDestinationBlend = Blend.One;

            graphicsDevice.BlendState = bs;

            DepthStencilState oldDss = graphicsDevice.DepthStencilState;
            DepthStencilState newDss = new DepthStencilState();
            newDss.DepthBufferWriteEnable = false;

            graphicsDevice.DepthStencilState = newDss;

            numTriangles = i * 2;
            if (numTriangles > 0)
            {
                foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, numTriangles);

                }
            }

            graphicsDevice.DepthStencilState = oldDss;
            graphicsDevice.BlendState = oldbs;
        }
Example #13
0
File: NPC.cs Project: kenpower/XNA4
        public override void Draw(GameTime gametime, Camera camera)
        {
            Matrix[] bones = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(bones);
            foreach (ModelMesh m in model.Meshes)
            {
                foreach (BasicEffect e in m.Effects)
                {
                    e.EnableDefaultLighting();
                    e.World = bones[m.ParentBone.Index] * Matrix.CreateScale(0.01f) * Matrix.CreateTranslation(position) * Matrix.CreateTranslation(6,0, 6);
                    e.Projection = camera.Projection;
                    e.View = camera.View;
                }

                m.Draw();
            }
        }
Example #14
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            //
            Texture2D flareTexture = Content.Load<Texture2D>("fireball2");
            Texture2D flareTexture1 = Content.Load<Texture2D>("flare");
            sflares = new List<SimpleParticleSystem>();

            Vector3 position=new Vector3(0);

            SimpleParticleSystem sps = new SimpleParticleSystem(this);

            sps.Texture = flareTexture;
            sps.Position = position;
            sps.Init();

            sflares.Add(sps);

            SimpleParticleSystem sps2 = new SimpleParticleSystem(this);

            sps2.Texture = flareTexture1;
            sps2.Position = position+(new Vector3(10,0,0));
            sps2.Init();

            sflares.Add(sps2);

            camera = new Camera();
            camera.Init(new Vector3(40, 10, 40), new Vector3(0), Vector3.Up,0.6f,graphics.GraphicsDevice.Viewport.AspectRatio,1,1000);

            base.Initialize();
        }
Example #15
0
 internal static void Draw(GameTime gameTime, Camera camera)
 {
     foreach (Missile m in missiles) {
         m.Draw(gameTime, camera);
     }
 }
Example #16
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            blockSize = new Rectangle(0, 0, 15, 15);

            streets = new List<Street>();

            StreetFactory.Init(this, blockSize);

            for (int z = 0; z < map.Length; z++)
            {
                for (int x = 0; x < map[z].Length; x++)
                {
                    char c = map[z][x];
                    if (StreetFactory.streetSymbols.Contains(c))
                    {
                        Street s = StreetFactory.makeStreet(map[z][x], new Vector2(x, z));
                        streets.Add(s);
                    }
                }
            }
            camera = new Camera();
            camera.Init(new Vector3(0, 10, 0), new Vector3(50, 10, 50), Vector3.Up,0.6f,graphics.GraphicsDevice.Viewport.AspectRatio,1,1000);

            base.Initialize();
        }
Example #17
0
 public virtual void Draw(GameTime gametime, Camera camera)
 {
 }
Example #18
0
        public void Update(GameTime gametime, Camera camera)
        {
            float time=(float)gametime.ElapsedGameTime.TotalMilliseconds/1000.0f;

            position += velocity * time;
        }
Example #19
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            blockSize = new Rectangle(0, 0, 15, 15);
            buildings = new List<Building>();

            BuildingFactory.Init(this,blockSize);

            for(int z=0;z<map.Length;z++){
                for(int x=0;x<map[z].Length;x++){
                    char c=map[z][x];
                    if (BuildingFactory.buildingSymbols.Contains(c))
                    {
                        Building b = BuildingFactory.makeBuilding(map[z][x], new Vector2(x, z) );
                        buildings.Add(b);
                    }
                }
            }

            streets = new List<Street>();

            StreetFactory.Init(this, blockSize);

            for (int z = 0; z < map.Length; z++)
            {
                for (int x = 0; x < map[z].Length; x++)
                {
                    char c = map[z][x];
                    if (StreetFactory.streetSymbols.Contains(c))
                    {
                        Street s = StreetFactory.makeStreet(map[z][x], new Vector2(x, z));
                        streets.Add(s);
                    }
                }
            }

            //
            Texture2D flareTexture = Content.Load<Texture2D>("fireball2");
            sflares = new List<SimpleParticleSystem>();

            Vector3 position=new Vector3(0);

            position = new Vector3(blockSize.Width / 2, 0, blockSize.Height / 2); //centre on first tile

            SimpleParticleSystem sps = new SimpleParticleSystem(this);

            sps.Texture = flareTexture;
            sps.Position = position;
            sps.Init();

            sflares.Add(sps);

            flares = new List<ParticleSystem>();

            ParticleSystemFactory.Init(this, blockSize);

            for (int z = 0; z < map.Length; z++)
            {
                for (int x = 0; x < map[z].Length; x++)
                {
                    char c = map[z][x];
                    if (ParticleSystemFactory.particleSymbols.Contains(c))
                    {
                        ParticleSystem ps = ParticleSystemFactory.makeParticleSystem(map[z][x], new Vector2(x, z));
                        flares.Add(ps);
                    }
                }
            }

            npcs = new List<NPC>();

            NPCFactory.Init(this, blockSize);

            for (int z = 0; z < NPCmap.Length; z++)
            {
                for (int x = 0; x < NPCmap[z].Length; x++)
                {
                    char c = NPCmap[z][x];
                    if (NPCFactory.NPCSymbols.Contains(c))
                    {
                        NPC npc = NPCFactory.makeNPC(c, new Vector2(x, z));
                        npcs.Add(npc);
                    }
                }
            }

            MissileFactory.Init(this, blockSize);
            MissileFactory.makeMissile(new Vector2(0, 0));

            camera = new Camera();
            camera.Init(new Vector3(0, 10, 0), new Vector3(50, 10, 50), Vector3.Up,0.6f,graphics.GraphicsDevice.Viewport.AspectRatio,1,1000);

            base.Initialize();
        }
Example #20
0
        public void Update(GameTime gametime, Camera camera)
        {
            emmiter.Update(gametime, particles,this);

            foreach (SimpleParticle p in particles)
            {
                p.Update(gametime,camera);
            }
        }
Example #21
0
 public override void Draw(GameTime gametime, Camera camera)
 {
     foreach(SimpleParticle sp in particles){
         sp.Draw(camera,graphicsDevice);
     }
 }