コード例 #1
0
ファイル: Game1.cs プロジェクト: liamthanrahan/Assignment2CG
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        ///
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            debugFont   = Content.Load <SpriteFont>("debugFont");

            // Set cullmode to none
            RasterizerState rs = new RasterizerState();

            rs.CullMode = CullMode.None;
            GraphicsDevice.RasterizerState = rs;

            DebugShapeRenderer.Initialize(GraphicsDevice);

            foreach (Human ch in modelManager.models.OfType <Human>())
            {
                chosen = ch;
                chosen.resetPosition = chosen.position;
                foreach (Dwarf df in modelManager.models.OfType <Dwarf>())
                {
                    follower               = df;
                    follower.position      = chosen.position - Vector3.UnitX * 40;
                    follower.resetPosition = follower.position;
                }
            }
        }
コード例 #2
0
ファイル: Enemy.cs プロジェクト: liamthanrahan/Assignment2CG
        //NEW updated the structure for CHASE, still trying to figure out attack and throw.
        public override void Update(Camera camera)
        {
            skinningData = model.Tag as SkinningData;
            float?rayLength = game.collisionRayToBox(vision, game.chosen.box);

            Console.WriteLine("RayLength = " + rayLength);

            /*if ((game.modelCollidingWith(vision) is Character) && rayLength < attackThreshold)
             * state = enemyState.ATTACK;
             * else*/
            //if (rayLength < chaseThreshold)  when rayLength is null, this is false.
            if (rayLength < chaseThreshold)
            {
                chasingPlayer = true;
            }
            else if (!(game.modelCollidingWith(vision) is Character))
            {
                state = enemyState.PATROL;
            }
            if (!chasingPlayer)
            {
                switch (state)
                {
                case enemyState.IDLE:
                    break;

                case enemyState.ATTACK:
                    if (game.chosen.position.X - position.X > 0)
                    {
                        game.chosen.position += Vector3.Right * 3;
                    }
                    else
                    {
                        game.chosen.position += Vector3.Left * 3;
                    }
                    break;

                case enemyState.CHASE:
                    break;

                case enemyState.THROW:
                    break;

                case enemyState.PATROL:
                    if (patrolByWalls)
                    {
                        if (rotationY == MathHelper.ToRadians(180))
                        {
                            position        += Vector3.Left;
                            vision.Direction = Vector3.Left;
                        }
                        else if (rotationY == 0)
                        {
                            position        += Vector3.Right;
                            vision.Direction = Vector3.Right;
                        }
                        if (game.collisionBoxToBoxes(box, game.levelBoxes) == Game1.collisionType.RIGHT)
                        {
                            rotationY = 0;
                        }
                        else if (game.collisionBoxToBoxes(box, game.levelBoxes) == Game1.collisionType.LEFT)
                        {
                            rotationY = MathHelper.ToRadians(180);
                        }
                    }
                    else if (patrolBySetWalls)
                    {
                        wallup();
                        if (box.Intersects(leftWall))
                        {
                            rotationY = 0;
                        }
                        else if (box.Intersects(rightWall))
                        {
                            rotationY = MathHelper.ToRadians(180);
                        }
                    }
                    break;
                }
                chasing();

                if (rotationY == MathHelper.ToRadians(180))
                {
                    vision = new Ray(position, Vector3.Left);
                }

                foreach (QuadTree qt in QuadTree.leavesInsideBound)
                {
                    if (qt.objects.Contains(this))
                    {
                        chasing();//NEW
                        if (rotationY == MathHelper.ToRadians(180))
                        {
                            vision = new Ray(position, Vector3.Left);
                        }
                        else if (rotationY == 0)
                        {
                            vision = new Ray(position, Vector3.Right);
                        }
                        DebugShapeRenderer.AddLine(position, position + vision.Direction * 200, Color.DarkBlue);
                        position += velocity;
                        backFeet  = new Vector3(box.Min.X, box.Min.Y - 5, 0);
                        frontFeet = new Vector3(box.Max.X, box.Min.Y - 5, 0);
                    }
                }
            }
        }
コード例 #3
0
ファイル: Game1.cs プロジェクト: liamthanrahan/Assignment2CG
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            //GraphicsDevice.BlendState = BlendState.Opaque;
            //GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            DebugShapeRenderer.AddBoundingBox(chosen.box, Color.HotPink);
            DebugShapeRenderer.AddLine(chosen.backFeet, chosen.backFeet + Vector3.Up * (chosen.box.Max.Y - chosen.box.Min.Y), Color.OldLace);
            DebugShapeRenderer.AddLine(chosen.frontFeet, chosen.frontFeet + Vector3.Up * (chosen.box.Max.Y - chosen.box.Min.Y), Color.OldLace);
            DebugShapeRenderer.AddBoundingBox(follower.box, Color.Magenta);
            DebugShapeRenderer.AddLine(follower.backFeet + Vector3.UnitZ * 50, follower.backFeet + Vector3.Up * (follower.box.Max.Y - follower.box.Min.Y) + Vector3.UnitZ * 50, Color.OldLace);
            DebugShapeRenderer.AddLine(follower.frontFeet + Vector3.UnitZ * 50, follower.frontFeet + Vector3.Up * (follower.box.Max.Y - follower.box.Min.Y) + Vector3.UnitZ * 50, Color.OldLace);

            foreach (Enemy enemy in modelManager.models.OfType <Enemy>())
            {
                DebugShapeRenderer.AddBoundingBox(enemy.box, Color.Red);
            }

            if (aStar != null)
            {
                foreach (AStar.Node node in aStar.gridBoxes)
                {
                    //DebugShapeRenderer.AddBoundingBox(node.box, Color.BlanchedAlmond);
                }
                foreach (AStar.Node node in aStar.closedList)
                {
                    //DebugShapeRenderer.AddBoundingBox(node.box, Color.LightGoldenrodYellow);
                    if (node.hasParent())
                    {
                        DebugShapeRenderer.AddLine(node.centre(), node.currentParent.centre(), Color.Red);
                    }
                }
                foreach (AStar.Node node in aStar.openList)
                {
                    if (node != null)
                    {
                        DebugShapeRenderer.AddLine((node.centre() + new Vector3(-10, 0, 0)), (node.centre() + new Vector3(10, 0, 0)), Color.DeepPink);
                        DebugShapeRenderer.AddLine((node.centre() + new Vector3(0, -10, 0)), (node.centre() + new Vector3(0, 10, 0)), Color.DeepPink);
                    }
                }

                foreach (Vector3 targetNode in aStar.paths)
                {
                    DebugShapeRenderer.AddLine((targetNode + new Vector3(-10, 0, 0)), (targetNode + new Vector3(10, 0, 0)), Color.CadetBlue);
                    DebugShapeRenderer.AddLine((targetNode + new Vector3(0, -10, 0)), (targetNode + new Vector3(0, 10, 0)), Color.CadetBlue);
                }
                DebugShapeRenderer.AddBoundingFrustum(camera.frustum, Color.Firebrick);
                if (quadTree != null)
                {
                    foreach (QuadTree qt in QuadTree.leavesInsideBound)
                    {
                        DebugShapeRenderer.AddBoundingBox(qt.boundingBox, Color.Violet);
                    }
                }
                //spriteBatch.Begin();
                //foreach (AStar.Node node in aStar.gridBoxes)
                //{
                //    string h = string.Copy("H: " + node.hScore + "\nG: " + node.gScore + "\nF: " + node.fScore());// + "\nY:" + aStar.nodeArrayIndex(aStar.gridBoxes, node));
                //    Vector3 projectedPosMax = GraphicsDevice.Viewport.Project(node.box.Max, camera.projection, camera.view, Matrix.Identity);
                //    Vector3 projectedPosMin = GraphicsDevice.Viewport.Project(node.box.Min, camera.projection, camera.view, Matrix.Identity);
                //    Vector2 screenPos = new Vector2(projectedPosMin.X + 10, projectedPosMax.Y);
                //    //spriteBatch.DrawString(debugFont, test, screenPos, Color.White);
                //    spriteBatch.DrawString(debugFont, h, screenPos, Color.White);
                //}
                //spriteBatch.End();
            }

            GraphicsDevice.BlendState        = BlendState.Opaque;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            DebugShapeRenderer.Draw(gameTime, camera.view, camera.projection);

            base.Draw(gameTime);
            showDebug();
            showScore();
        }