示例#1
0
 public Game1()
 {
     graphics = new GraphicsDeviceManager(this);
     graphics.PreferredBackBufferWidth  = Width = WorldData.GetInstance().ScreenWidth;
     graphics.PreferredBackBufferHeight = Height = WorldData.GetInstance().ScreenHeight;
     Content.RootDirectory = "Content";
 }
示例#2
0
        public Player(String playerName, Vector2 iniPos, List <I_WorldObject> objectsList)
        {
            leftRight                = true;
            this.playerName          = playerName;
            this.playerPosition      = iniPos;
            this.playerTextureOrigin = Vector2.Zero;
            this.playerVelocity      = Vector2.Zero;
            this.playerRotation      = 0;
            this.playerColor         = Color.White;
            rigidness                = false;
            aliveness                = true;
            currentPosition          = Vector2.Zero;
            PLAYER_SPEED             = WorldData.GetInstance().playerSpeed;
            GRAVITY           = WorldData.GetInstance().Gravity;
            this.worldObjects = objectsList;
            this.gravityState = true;
            this.collidable   = true;
            this.playerState  = State.HIGH;



            frame      = 0;
            frameWidth = 0;
            animCenter = Vector2.Zero;
            scale      = 0;
        }
示例#3
0
        private void adjustPosition()
        {
            if (this.enemyBoundingBox.Min.X < 0)
            {
                this.enemyPosition   = new Vector2(0, enemyPosition.Y);
                this.enemyDirection *= -1;
            }

            if (this.enemyBoundingBox.Min.Y < 0)
            {
                this.enemyPosition   = new Vector2(enemyPosition.X, 0);
                this.enemyDirection *= -1;
            }


            if (this.enemyBoundingBox.Max.Y > WorldData.GetInstance().ScreenHeight)
            {
                this.enemyPosition   = new Vector2(enemyPosition.X, WorldData.GetInstance().ScreenHeight - enemyTexture.Height);
                this.enemyDirection *= -1;
            }



            UpdateBoundingBox();
        }
示例#4
0
        public void Draw(I_WorldObject obj)
        {
            if (trackMe.getPosition().X >= WorldData.GetInstance().ScreenWidth / 2)
            {
                //Vector2 objPosInCameraSpace = obj.getPosition() - new Vector2((trackMe.getPosition()).X, 0);
                Vector2 objPosInCameraSpace = obj.getPosition() - new Vector2((trackMe.getPosition()).X - (WorldData.GetInstance().ScreenWidth / 2), 0);
                objPosInScreenSpace = objPosInCameraSpace;

                tracking = true;
            }
            else
            {
                tracking = false;
                Vector2 objPosInCameraSpace = obj.getPosition();
                objPosInScreenSpace = objPosInCameraSpace;
            }

            if (obj.getName() != "coin")
            {
                mSpriteBatch.Draw(obj.getTexture(), objPosInScreenSpace, null, obj.getColor(), obj.getRotation(), obj.getTextureOrigin(), 1.0f, SpriteEffects.None, 0);
            }
            else if (obj.getName() == "coin")
            {
                Rectangle srcRect = new Rectangle((int)obj.getFrame() * obj.getFrameWidth(), 0, obj.getFrameWidth(), obj.getTexture().Height);

                mSpriteBatch.Draw(obj.getTexture(), objPosInScreenSpace, srcRect, Color.White, obj.getRotation(), Vector2.Zero, obj.getScale(), SpriteEffects.None, 0);
            }
        }
示例#5
0
        private void RandomizeMovement()
        {
            int emm = WorldData.GetInstance().enemyMaxMovement;

            float iX = rndGen.Next(-emm, emm);
            float iY = rndGen.Next(-emm, emm);

            int direction  = rndGen.Next(1, 8);
            int vmagnitude = rndGen.Next(1, 3);
            int hmagnitude = rndGen.Next(1, 3);

            if (direction == 1)
            {
                setDirection(new Vector2(1 * hmagnitude, 0));
            }
            if (direction == 2)
            {
                setDirection(new Vector2(-1 * hmagnitude, 0));
            }
            if (direction == 3)
            {
                setDirection(new Vector2(0, 1 * vmagnitude));
            }
            if (direction == 4)
            {
                setDirection(new Vector2(0, -1 * vmagnitude));
            }
            if (direction == 5)
            {
                setDirection(new Vector2(1 * hmagnitude, 1 * vmagnitude));
            }
            if (direction == 6)
            {
                setDirection(new Vector2(-1 * hmagnitude, 1 * vmagnitude));
            }
            if (direction == 7)
            {
                setDirection(new Vector2(1 * hmagnitude, -1 * vmagnitude));
            }
            if (direction == 8)
            {
                setDirection(new Vector2(-1 * hmagnitude, -1 * vmagnitude));
            }



            enemySpeed = new Vector2(iX * WorldData.GetInstance().enemySpeed, iY * WorldData.GetInstance().enemySpeed);
        }
示例#6
0
        public void init_adamsStuff()
        {
            phraseint = 0;
            time      = 6;


            worldObjectspre  = new List <I_WorldObject>();
            worldtextObjects = new List <I_WorldObject>();

            foreach (Vector2 textPosition in WorldData.GetInstance().textPositions)
            {
                messagebox box = new messagebox("poke_text_messagenew", textPosition);
                box.setPosition(new Vector2(-25, 110));
                worldObjectspre.Add(box);
            }

            foreach (String s in WorldData.GetInstance().fieldvaluepairs)
            {
                messagetexts text = new messagetexts(s, new Vector2(0, 0));
                text.setPosition(new Vector2(200, 540));
                worldtextObjects.Add(text);
            }
        }
示例#7
0
        public void alertCollision(I_WorldObject collidedObject)
        {
            if (collidedObject.getName() == "nun")
            {
                this.setVelocity(Vector2.Zero);
                this.setDirection(new Vector2(1, 0));
                this.setSpeed(Vector2.Zero);
                this.setPhysics(false);

                playerPosition = WorldData.GetInstance().playerInitialPosition;
            }

            if (!collidedObject.isRigid())
            {
                if (collidedObject.getName() == "Spikes" || collidedObject.getName() == "SpikeField")
                {
                    setAlive(false);

                    this.setVelocity(Vector2.Zero);
                    this.setDirection(new Vector2(1, 0));
                    this.setSpeed(Vector2.Zero);
                    this.setPhysics(false);

                    playerPosition = WorldData.GetInstance().playerInitialPosition;

                    setAlive(true);
                }


                if (collidedObject.getName() == "scroll")
                {
                    collidedObject.setAlive(false);
                    WorldData.level++;
                }
            }

            if (collidedObject.isRigid())
            {
                //this.playerColor = Color.Red;

                BoundingBox myAABB = this.playerBoundingBox;
                BoundingBox other  = collidedObject.getBoundingBox();

                int leftBound  = (int)Math.Max(myAABB.Min.X, other.Min.X);
                int rightBound = (int)Math.Min(myAABB.Max.X, other.Max.X);
                int upperBound = (int)Math.Max(myAABB.Min.Y, other.Min.Y);
                int lowerBound = (int)Math.Min(myAABB.Max.Y, other.Max.Y);

                int xMovement = rightBound - leftBound;
                int yMovement = lowerBound - upperBound;

                if (xMovement < yMovement)
                {
                    if (myAABB.Min.X < other.Min.X)
                    {
                        this.playerPosition.X -= xMovement - 1;
                    }
                    else
                    {
                        this.playerPosition.X += xMovement + 1;
                    }
                }
                else
                {
                    if (myAABB.Min.Y < other.Min.Y)
                    {
                        this.playerState = State.GROUNDED;

                        this.playerPosition.Y -= (yMovement);
                        this.setVelocity(new Vector2(0, 0));
                    }
                    else
                    {
                        //this.playerState = State.HIGH;
                        this.playerPosition.Y += (yMovement);
                        this.setVelocity(new Vector2(0, 0));
                        //this.gravityState = true;
                    }
                }
            }
        }
示例#8
0
 protected void AddData(XElement elem)
 {
     XMLParse.AddValueToClassInstance(elem, WorldData.GetInstance());
 }
示例#9
0
        public void init_everything()
        {
            endScene     = false;
            objectsToAdd = new List <I_WorldObject>();
            scareImg     = new ScaryImage();
            nunCount     = new TextBox(new Vector2(20, 0), "nuns impaled: 0", "HUDfont", Color.Yellow);
            scoreDisplay = new TextBox(new Vector2(20, 50), "coins: 0", "HUDfont", Color.Yellow);
            game         = containingGame;
            WorldWidth   = w;
            WorldHeight  = h;

            int worldX = 0;
            int worldY = 0;

            toDelete            = new List <I_WorldObject>();
            worldObjects        = new List <I_WorldObject>();
            intersectingObjects = new List <I_WorldObject>();

            p = new Player("Jordan", WorldData.GetInstance().playerInitialPosition, worldObjects);

            fl = new FlameThrower(this);

            camera = new Camera(containingGame.spriteBatch, p);

            foreach (Vector2 spikePos in WorldData.GetInstance().spikePositions)
            {
                if (spikePos.X > worldX)
                {
                    worldX = (int)spikePos.X;
                }
                if (spikePos.Y > worldY)
                {
                    worldY = (int)spikePos.Y;
                }

                TestBlock s = new TestBlock("Spikes", spikePos + new Vector2(0, 2), scareImg, this);
                s.setDirection(new Vector2(0, -1));
                s.setRigid(false);
                worldObjects.Add(s);
            }

            foreach (Vector2 enemPos in WorldData.GetInstance().enemyPositions)
            {
                if (enemPos.X > worldX)
                {
                    worldX = (int)enemPos.X;
                }
                if (enemPos.Y > worldY)
                {
                    worldY = (int)enemPos.Y;
                }

                Enemy e = new Enemy("nun", enemPos, this);
                e.setRigid(false);
                worldObjects.Add(e);
            }

            foreach (Vector2 platPos in WorldData.GetInstance().platformPositions)
            {
                if (platPos.X > worldX)
                {
                    worldX = (int)platPos.X;
                }
                if (platPos.Y > worldY)
                {
                    worldY = (int)platPos.Y;
                }

                TestBlock b = new TestBlock("usf", platPos, scareImg, this);
                worldObjects.Add(b);
            }

            foreach (Vector2 movingPlatPos in WorldData.GetInstance().movingPlatformPositions)
            {
                if (movingPlatPos.X > worldX)
                {
                    worldX = (int)movingPlatPos.X;
                }
                if (movingPlatPos.Y > worldY)
                {
                    worldY = (int)movingPlatPos.Y;
                }

                TestBlock mp = new TestBlock("movingPlatform", movingPlatPos, scareImg, this);
                worldObjects.Add(mp);
            }

            foreach (Vector2 coinPos in WorldData.GetInstance().coinPositions)
            {
                if (coinPos.X > worldX)
                {
                    worldX = (int)coinPos.X;
                }
                if (coinPos.Y > worldY)
                {
                    worldY = (int)coinPos.Y;
                }

                Coin c = new Coin("coin", 20, new Vector2(0, 0), true, 0.08f, coinPos, scoreDisplay);
                c.setRigid(false);
                worldObjects.Add(c);
            }


            foreach (Vector2 scrollPos in WorldData.GetInstance().scrollPositions)
            {
                if (scrollPos.X > worldX)
                {
                    worldX = (int)scrollPos.X;
                }
                if (scrollPos.Y > worldY)
                {
                    worldY = (int)scrollPos.Y;
                }

                TestBlock s = new TestBlock("scroll", scrollPos, scareImg, this);
                s.setRigid(false);
                worldObjects.Add(s);
            }

            TestBlock scareBLock = new TestBlock("ScareBlock", WorldData.GetInstance().playerInitialPosition + new Vector2(800, 300), scareImg, this);


            worldObjects.Add(scareBLock);

            worldObjects.Add(p);

            worldObjects.Add(fl);

            qt = new QuadTree(new Rectangle(0, 0, worldX, worldY));
        }