Exemplo n.º 1
0
        public override void Update(GameTime gameTime, Rectangle clientBounds, Floor floor, UserControlledSprite player, Random rand)
        {
            if (Turn && !turnTaken) //Once per turn
            {
                CurrentRoom = floor[Location.X, Location.Y];
                dir         = rand.Next(1, 5);                               //Choose direction
                if (dir == 1 && Location.Y != 0)                             //Up and not at top
                {
                    if (floor[Location.X, Location.Y - 1].moveRequest(this)) //Allowed to move up
                    {
                        distance = 60;
                        newLoc   = new Vector2(0, -1);
                    }
                }
                if (dir == 2 && Location.X != 26)                            //Right and not at right edge
                {
                    if (floor[Location.X + 1, Location.Y].moveRequest(this)) //Allowed to move right
                    {
                        distance = 60;
                        newLoc   = new Vector2(1, 0);
                    }
                }
                if (dir == 3 && Location.Y != 26) //Down and not at bottom edge
                {
                    if (floor[Location.X, Location.Y + 1].moveRequest(this))
                    {
                        distance = 60;
                        newLoc   = new Vector2(0, 1);
                    }
                }
                if (dir == 4 && Location.X != 0) //Down and not at bottom edge
                {
                    if (floor[Location.X - 1, Location.Y].moveRequest(this))
                    {
                        distance = 60;
                        newLoc   = new Vector2(-1, 0);
                    }
                }
                if (distance == 0)
                {
                    newLoc = Vector2.Zero;
                }
                else
                {
                    CurrentRoom.RemoveContent(this);
                    Location   += newLoc;
                    CurrentRoom = floor[Location.X, Location.Y];
                    CurrentRoom.AddContent(this);
                } //Remove from room if it is moving
                if (!center)
                {
                    centerDistance = 20; centering = oldCentering;
                }

                turnTaken = true;
            }//^^Once per turn^^

            if (Turn) //Cycled until turn is over
            {
                if (centerDistance > 0) //Sprite needs to move towards center
                {
                    Offset += centering;
                    centerDistance--;
                    //Console.WriteLine(index + " Offset: " + Offset + " Rate: " + centering + " EnemyCount: " + CurrentRoom.EnemyCount);
                    if (centerDistance == 0)
                    {
                        center = true;
                    }
                }
                if (center && distance > 0) //Sprite has moved to middle of room and is ready to move to new room
                {
                    if (dir == 1)
                    {
                        Position = new Point(Position.X, Position.Y - 5);
                    }
                    if (dir == 2)
                    {
                        Position = new Point(Position.X + 5, Position.Y);
                    }
                    if (dir == 3)
                    {
                        Position = new Point(Position.X, Position.Y + 5);
                    }
                    if (dir == 4)
                    {
                        Position = new Point(Position.X - 5, Position.Y);
                    }
                    distance--;
                    if (distance == 0) //Sprite is in center of new room
                    {
                        outsideDistance = 20;
                        center          = false;
                        centering       = getRate(CurrentRoom.Enemies.IndexOf(this));
                        oldCentering    = centering; //Always go back the same way it came
                    }
                }
                if (newLoc == Vector2.Zero && center) // Didn't change rooms but still in the center
                {
                    outsideDistance = 20;
                    center          = false;
                    centering       = getRate(CurrentRoom.Enemies.IndexOf(this));
                    oldCentering    = centering; //Always go back the same way it came
                }
                if (outsideDistance > 0)         //Sprite has moved into the new room but the turn isn't over
                {
                    Offset += -centering;
                    outsideDistance--;
                }
                if (outsideDistance == 0 && distance == 0 && centerDistance == 0) //END OF TURN Sprite has changed rooms and walked to its offset
                {
                    //Console.WriteLine("Turn End " + index + " Offset: " + Offset + " Rate: " + centering + " EnemyCount: " + CurrentRoom.EnemyCount);
                    if (Animations.CurrentAnimation != "idle")
                    {
                        Animations.CurrentAnimation = "idle";
                    }
                    changeTurn(false);
                }
            }

            base.Update(gameTime, clientBounds, floor);
        }
Exemplo n.º 2
0
        private void move(int dir, Floor floor)
        {
            noMove = false;
            switch (dir)
            {
            case 1:     //Up
                if (Location.Y != 0)
                {
                    if (floor[Location.X, Location.Y - 1].moveRequest(this))
                    {
                        this.dir = dir;
                        CurrentRoom.RemoveContent(this);
                        distance    = 60;
                        Location    = new Vector2(Location.X, Location.Y - 1);
                        CurrentRoom = floor[Location.X, Location.Y];
                        CurrentRoom.AddContent(this);
                    }
                }
                break;

            case 2:     //Right
                if (Location.X != 26)
                {
                    if (floor[Location.X + 1, Location.Y].moveRequest(this))
                    {
                        this.dir = dir;
                        CurrentRoom.RemoveContent(this);
                        distance    = 60;
                        Location    = new Vector2(Location.X + 1, Location.Y);
                        CurrentRoom = floor[Location.X, Location.Y];
                        CurrentRoom.AddContent(this);
                    }
                }
                break;

            case 3:     //Down
                if (Location.Y != 26)
                {
                    if (floor[Location.X, Location.Y + 1].moveRequest(this))
                    {
                        this.dir = dir;
                        CurrentRoom.RemoveContent(this);
                        distance    = 60;
                        Location    = new Vector2(Location.X, Location.Y + 1);
                        CurrentRoom = floor[Location.X, Location.Y];
                        CurrentRoom.AddContent(this);
                    }
                }
                break;

            case 4:     //Left
                if (Location.X != 0)
                {
                    if (floor[Location.X - 1, Location.Y].moveRequest(this))
                    {
                        this.dir = dir;
                        CurrentRoom.RemoveContent(this);
                        distance    = 60;
                        Location    = new Vector2(Location.X - 1, Location.Y);
                        CurrentRoom = floor[Location.X, Location.Y];
                        CurrentRoom.AddContent(this);
                    }
                }
                break;
            }
        }
Exemplo n.º 3
0
        public override void Update(GameTime gameTime, Rectangle clientBounds, Floor floor, SpriteManager spriteManager)
        {
            if (Game1.PAUSED)
            {
                base.Update(gameTime, clientBounds, floor);

                return;
            }

            if (!turnTaken && Turn)
            {
                Game1.BATTLE = spriteManager.BattleChecker();
                //oldState = Keyboard.GetState();
            }
            if (distance == 0 && rotation == 0)
            {
                if (Animations.CurrentAnimation != "idle")
                {
                    Animations.CurrentAnimation = "idle";
                }

                if (turnTaken && Turn)
                {
                    if (!rotated && rotationEnergy < rotationEnergyMax)
                    {
                        rotationEnergy += 1;
                    }
                    if (buffs.Count > 0)
                    {
                        for (int i = 0; i < buffs.Count; i++)
                        {
                            buffs[i].Duration--;
                            if (buffs[i].Duration == 0)
                            {
                                RemoveBuff(buffs[i]);
                            }
                        }
                    }
                    CurrentRoom = floor[Location.X, Location.Y];
                    CurrentRoom.AddContent(this);
                    spriteManager.NewSpawn();
                    //Console.WriteLine("end of turn");
                    Game1.BATTLE = spriteManager.BattleChecker();
                    if (CurrentRoom.Enemies.Count == 0)
                    {
                        changeTurn(false);
                        rotated = false;
                    }
                }

                if (Turn && !Game1.BATTLE)
                {
                    oldState = UpdateInput(oldState, floor, spriteManager);
                }
            }
            if (rotation > 0)
            {
                rotation -= 5;
            }
            if (distance > 0)
            {
                if (dir == 1)
                {
                    Position = new Point(Position.X, Position.Y - 5);
                }
                if (dir == 2)
                {
                    Position = new Point(Position.X + 5, Position.Y);
                }
                if (dir == 3)
                {
                    Position = new Point(Position.X, Position.Y + 5);
                }
                if (dir == 4)
                {
                    Position = new Point(Position.X - 5, Position.Y);
                }
                distance -= 5;
            }

            base.Update(gameTime, clientBounds, floor);
        }