Esempio n. 1
0
        private static void DrawMap()
        {
            FoV.RayCast();

            for (int x = Rogue.GameWorld.Player.CameraX - 1; x < Constants.CameraWidth + Rogue.GameWorld.Player.CameraX + 1 + 1; x++)
            {
                for (int y = Rogue.GameWorld.Player.CameraY - 1; y < Constants.CameraHeight + Rogue.GameWorld.Player.CameraY + 1 + 1; y++)
                {
                    if (FoV.InFov(Rogue.GameWorld.Player.X, Rogue.GameWorld.Player.Y, x, y, Rogue.GameWorld.Player))
                    {
                        if (GameMap.IsTerrain(x, y, Constants.Terrain.TileWall))
                        {
                            DrawMapTile(x, y, Tiles.Terrain.WallTile, "white");
                        }
                        else if (GameMap.IsTerrain(x, y, Constants.Terrain.TileFloor))
                        {
                            DrawMapTile(x, y, Tiles.Terrain.FloorTile, "white");
                        }
                    }
                    else if (GameMap.MapExplored(x, y))
                    {
                        if (GameMap.IsTerrain(x, y, Constants.Terrain.TileWall))
                        {
                            DrawMapTile(x, y, Tiles.Terrain.WallTile, "grey");
                        }
                        else if (GameMap.IsTerrain(x, y, Constants.Terrain.TileFloor))
                        {
                            DrawMapTile(x, y, Tiles.Terrain.FloorTile, "grey");
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private static void DrawObjects(GameObject skip)
        {
            foreach (GameObject obj in Rogue.GameWorld.Objects)
            {
                if (skip != null && obj == skip)
                {
                    continue;
                }
                if (FoV.InFov(Rogue.GameWorld.Player.X, Rogue.GameWorld.Player.Y, obj.X, obj.Y, Rogue.GameWorld.Player))
                {
                    obj.Draw("white");
                }
                else if (Rogue.GameWorld.Map.Tiles[obj.X, obj.Y].Explored && obj.AlwaysVisible && Camera.WithinCamera(obj.X, obj.Y))
                {
                    obj.Draw("grey");
                }
            }

            Rogue.GameWorld.Player.Draw("white");
        }
Esempio n. 3
0
        public static GameObject ClosestMonster(GameObject owner)
        {
            GameObject closestObject = null;
            int        closestDist   = owner.Fighter.Sight;

            foreach (GameObject obj in Rogue.GameWorld.Objects)
            {
                if (obj != owner && obj.Fighter != null && obj.Fighter.AI.Type != Constants.AI.None && FoV.InFov(owner.X, owner.Y, obj.X, obj.Y, owner))
                {
                    int distance = (int)DistanceBetween(owner.X, owner.Y, obj.X, obj.Y);
                    if (distance < closestDist)
                    {
                        closestObject = obj;
                        closestDist   = distance;
                    }
                }
            }

            return(closestObject);
        }
        internal void Move(int dx, int dy)
        {
            if (this != Rogue.GameWorld.Player)
            {
                if (dx == 0 && dy == -1)
                {
                    if (Fighter.Direction != 0)
                    {
                        Fighter.Direction = 0;
                        return;
                    }
                }
                if (dx == -1 && dy == 0)
                {
                    if (Fighter.Direction != 90)
                    {
                        Fighter.Direction = 90;
                        return;
                    }
                }
                if (dx == 0 && dy == 1)
                {
                    if (Fighter.Direction != 180)
                    {
                        Fighter.Direction = 180;
                        return;
                    }
                }
                if (dx == 1 && dy == 0)
                {
                    if (Fighter.Direction != 270)
                    {
                        Fighter.Direction = 270;
                        return;
                    }
                }
            }

            if (!GameMap.Blocked(X + dx, Y + dy))
            {
                if (this == Rogue.GameWorld.Player || FoV.InFov(Rogue.GameWorld.Player.X, Rogue.GameWorld.Player.Y, X, Y, Rogue.GameWorld.Player))
                {
                    if (dx == 1 || dx == -1)
                    {
                        for (int x = 0; x < 64 / Constants.MoveSmoothSteps; x++)
                        {
                            OffsetX += Constants.MoveSmoothSteps * dx;
                            if (this != Rogue.GameWorld.Player)
                            {
                                Rendering.RenderAll(this);
                                Draw("white", true);
                                Terminal.Refresh();
                            }
                            else
                            {
                                Rendering.RenderAll();
                            }
                        }

                        OffsetX = 0;
                    }
                    if (dy == 1 || dy == -1)
                    {
                        for (int x = 0; x < 64 / Constants.MoveSmoothSteps; x++)
                        {
                            OffsetY += Constants.MoveSmoothSteps * dy;
                            if (this != Rogue.GameWorld.Player)
                            {
                                Rendering.RenderAll(this);
                                Draw("white", true);
                                Terminal.Refresh();
                            }
                            else
                            {
                                Rendering.RenderAll();
                            }
                        }

                        OffsetY = 0;
                    }

                    if (this == Rogue.GameWorld.Player)
                    {
                        Camera.HandleMoveCamera(dx, dy);
                    }
                }

                X += dx;
                Y += dy;
            }
        }
Esempio n. 5
0
        private static void MouseHoverLook()
        {
            Terminal.Color(Terminal.ColorFromName("white"));

            Terminal.Layer(Constants.Layers["Messages"]);

            int mouseX = Terminal.State(Terminal.TK_MOUSE_X) - 1;
            int mouseY = Terminal.State(Terminal.TK_MOUSE_Y) - 1;

            if (mouseX >= 0 && mouseY >= 0 && mouseX <= 60 && mouseY <= 34)
            {
                if (mouseX % 2 != 0)
                {
                    mouseX -= 1;
                }

                if (mouseY % 2 != 0)
                {
                    mouseY -= 1;
                }

                Coordinate coord = Camera.CameraToCoordinate(mouseX / 4, mouseY / 4);

                foreach (GameObject obj in Rogue.GameWorld.Objects)
                {
                    if (obj.X == coord.X && obj.Y == coord.Y)
                    {
                        if ((GameMap.MapExplored(obj.X, obj.Y) && obj.AlwaysVisible) || FoV.InFov(Rogue.GameWorld.Player.X, Rogue.GameWorld.Player.Y, obj.X, obj.Y, Rogue.GameWorld.Player))
                        {
                            Terminal.Print(mouseX + 1, mouseY + 1, obj.Name);
                        }
                    }
                }
            }
        }
        public static void BasicMonster(GameObject self)
        {
            if (self.Fighter.HP <= 0)
            {
                return;
            }

            if (self.Fighter.TurnDirection != null)
            {
                self.Fighter.Direction     = self.Fighter.TurnDirection.Value;
                self.Fighter.TurnDirection = null;
            }
            else if (FoV.InFov(self.X, self.Y, Rogue.GameWorld.Player.X, Rogue.GameWorld.Player.Y, self))
            {
                self.Fighter.SeenPlayerX = Rogue.GameWorld.Player.X;
                self.Fighter.SeenPlayerY = Rogue.GameWorld.Player.Y;

                if (CommonMethods.DistanceBetween(self.X, self.Y, Rogue.GameWorld.Player.X, Rogue.GameWorld.Player.Y) < 1.41 && Rogue.GameWorld.Player.Fighter.HP > 0)
                {
                    self.Fighter.MeleeAttack(Rogue.GameWorld.Player);
                }
                else
                {
                    self.MoveTowards(Rogue.GameWorld.Player.X, Rogue.GameWorld.Player.Y);
                }
            }
            else if (self.Fighter.SeenPlayerX != null && self.Fighter.SeenPlayerY != null)
            {
                self.MoveTowards(self.Fighter.SeenPlayerX.Value, self.Fighter.SeenPlayerY.Value);

                if (self.X == self.Fighter.SeenPlayerX.Value && self.Y == self.Fighter.SeenPlayerY.Value)
                {
                    self.Fighter.SeenPlayerX = null;
                    self.Fighter.SeenPlayerY = null;
                }
            }
            else
            {
                int choice = Constants.Angles[new Random().Next(0, Constants.Angles.Length)];

                if (choice == self.Fighter.Direction)
                {
                    if (self.Fighter.Direction == 0)
                    {
                        self.Move(0, -1);
                    }
                    else if (self.Fighter.Direction == 90)
                    {
                        self.Move(-1, 0);
                    }
                    else if (self.Fighter.Direction == 180)
                    {
                        self.Move(0, 1);
                    }
                    else if (self.Fighter.Direction == 270)
                    {
                        self.Move(1, 0);
                    }
                }
                else
                {
                    self.Fighter.Direction = choice;
                }
            }
        }
        private static void ThrowingAnimation(GameObject obj, GameObject user)
        {
            for (int times = 0; times < Constants.SpellRange; times++)
            {
                if (user.Fighter.Direction == 90 || user.Fighter.Direction == 270)
                {
                    int dx = user.Fighter.Direction == 90 ? -1 : 1;

                    if (GameMap.MapBlocked(obj.X + dx, obj.Y))
                    {
                        break;
                    }
                    if (CommonMethods.TargetInCoordinate(obj.X, obj.Y))
                    {
                        break;
                    }

                    for (int x = 0; x < 64 / Constants.MoveSmoothSteps; x++)
                    {
                        Rendering.RenderAll(obj);
                        obj.OffsetX += Constants.MoveSmoothSteps * dx;

                        if (GameMap.MapExplored(obj.X + dx, obj.Y) || FoV.InFov(user.X, user.Y, obj.X + dx, obj.Y, user))
                        {
                            obj.Draw("white", true);
                        }

                        Terminal.Refresh();
                    }

                    obj.X      += dx;
                    obj.OffsetX = 0;
                }
                else if (user.Fighter.Direction == 0 || user.Fighter.Direction == 180)
                {
                    int dy = user.Fighter.Direction == 0 ? -1 : 1;

                    if (GameMap.MapBlocked(obj.X, obj.Y + dy))
                    {
                        break;
                    }
                    if (CommonMethods.TargetInCoordinate(obj.X, obj.Y))
                    {
                        break;
                    }

                    for (int x = 0; x < 64 / Constants.MoveSmoothSteps; x++)
                    {
                        Rendering.RenderAll(obj);
                        obj.OffsetY += Constants.MoveSmoothSteps * dy;

                        if (GameMap.MapExplored(obj.X, obj.Y + dy) || FoV.InFov(user.X, user.Y, obj.X, obj.Y + dy, user))
                        {
                            obj.Draw("white", true);
                        }

                        Terminal.Refresh();
                    }

                    obj.Y      += dy;
                    obj.OffsetY = 0;
                }
            }
        }