/// <summary>
        /// Obtains the relative position of the tile map and draws all tiles within the screen using the corresponding tile array. Additionally, all tiles out of the map are drawn as tree foilage.
        /// </summary>
        /// <param name="window"></param>
        /// <param name="v2fTileMapPosition"></param>
        public void Draw(RenderWindow window, Vector2f v2fTileMapPosition)
        {
            int tileMapPositionXNormalized = (int)((-v2fTileMapPosition.X) / tileArrayCreation.GetTileSize());
            int tileMapPositionYNormalized = (int)((-v2fTileMapPosition.Y) / tileArrayCreation.GetTileSize());
            int xLimit = (int)((GameLoop.GetWindowSize().X / tileArrayCreation.GetTileSize()));
            int yLimit = (int)((GameLoop.GetWindowSize().Y / tileArrayCreation.GetTileSize()) + 1);

            for (int xCoord = 0, yCoord = 0; yCoord <= yLimit; xCoord++)
            {
                if (tileMapPositionXNormalized + xCoord >= 0 && tileMapPositionXNormalized + xCoord < tileArrayCreation.GetNumberColumns() &&
                    tileMapPositionYNormalized + yCoord >= 0 && tileMapPositionYNormalized + yCoord < tileArrayCreation.GetNumberRows())
                {
                    spriteTileSheet.Position = new Vector2f(((int)((tileMapPositionXNormalized + xCoord) * tileArrayCreation.GetTileSize() + v2fTileMapPosition.X)),
                                                            (int)(((tileMapPositionYNormalized + yCoord) * tileArrayCreation.GetTileSize() + v2fTileMapPosition.Y)));
                    spriteTileSheet.TextureRect = TileSourceDeterminat0r(tileArrayCreation.GetTilezArray()[xCoord + tileMapPositionXNormalized, yCoord + tileMapPositionYNormalized]);

                    window.Draw(spriteTileSheet);
                }

                if (xCoord > xLimit)
                {
                    xCoord = -1;
                    yCoord++;
                }
            }
        }
示例#2
0
        static void Main()
        {
            Console.CursorVisible = false;

            IMainUserInterface userInterface = new MainUserInterface();
            IGameLoop          gameLoop      = new GameLoop();
            IGame game = new Game(4, 4, 2);

            userInterface.StartGame(gameLoop, game);
        }
示例#3
0
        /// <summary>
        /// Initializes Variables of the State
        /// </summary>
        public override void Initialize()
        {
            targetState = eGameState.gsGameOver;

            fFont = new Font(ContentLoader.fontArial);

            teGameOver          = new Text("GAME OVER", fFont, 50);
            teContinue          = new Text("Press ESC to continue", fFont, 15);
            teGameOver.Position = GameLoop.GetWindowSize() / 2 - new Vector2f(teGameOver.CharacterSize * 4.5f, teGameOver.CharacterSize / 2);
            teContinue.Position = teGameOver.Position + new Vector2f(77, 60);
        }
        /// <summary>
        /// Allows change of the displayed characters size.
        /// </summary>
        /// <param name="sInput"></param>
        /// <param name="color"></param>
        /// <param name="uiCharacterSize"></param>
        /// <returns></returns>
        public static Text TextForPlayer(string sInput, Color color, uint uiCharacterSize)
        {
            textColor = color;
            font      = ContentLoader.fontArial;
            uiSize    = uiCharacterSize;

            text = new Text(sInput, font, uiSize);
            text.CharacterSize = uiSize;
            text.Position      = new Vector2f((int)((GameLoop.GetWindowSize().X / 2) - ((sInput.Length / 2) * (text.CharacterSize / 2))), (int)((GameLoop.GetWindowSize().Y / 2) - (GameLoop.GetWindowSize().Y / 4) - (text.CharacterSize / 2)));
            text.Color         = textColor;

            return(text);
        }
示例#5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Initialize Game
            Game myGame = new Game(new Size(ClientRectangle.Width, ClientRectangle.Height));

            KeyDown += myGame.KeyDownEvent;
            KeyUp   += myGame.KeyUpEvent;

            // Initialize & Start GameLoop
            gameLoop = new GameLoop();
            gameLoop.Load(myGame);
            gameLoop.Start();

            // Start Graphics Timer
            graphicsTimer.Start();
        }
示例#6
0
        /// <summary>
        /// Updates the Main Map Logic
        /// </summary>
        public override eMapState Update(RenderWindow window)
        {
            left  = false;
            right = false;
            up    = false;
            down  = false;

            vPastTileMapPosition       = vPresentTileMapPosition;
            vPresentTileMapPosition    = vTileMapPosition;
            vDifferenceTileMapPosition = vPastTileMapPosition - vPresentTileMapPosition;

            cCamera.Update(vPlayerVirtualPosition, ref vTileMapPosition);

            for (int x = 0; x < lEnemies.Count; x++)
            {
                Vector2f EnemyPosition = lEnemies[x].GetPosition();

                if (EnemyPosition.X > GameLoop.GetWindowSize().X || EnemyPosition.X < -50 ||
                    EnemyPosition.Y > GameLoop.GetWindowSize().Y || EnemyPosition.Y < -50)
                {
                    lEnemies[x].PassiveUpdate();
                    continue;
                }

                lEnemies[x].Update(ref vPlayerVirtualPosition, ref up, ref down, ref right, ref left);

                if (lEnemies[x].GetHealth() <= 0)
                {
                    if (lEnemies[x].GetIsBoss())
                    {
                        uiKillCount++;
                        Player.LevelUp();
                    }
                    SoundManager.PlaySpecificSound(Sounds.Death);

                    lEnemies.RemoveAt(x);
                }
            }

            pPlayer.Update(ref vPlayerVirtualPosition, ref up, ref down, ref right, ref left);

            textQuest = new Text(questTracker.Update(uiKillCount), fFont, 20);

            iInput.Update(ref vPlayerVirtualPosition, ref Player.fSpeed, up, right, down, left, window);

            return(eTargetMap);
        }
示例#7
0
        public Game()
        {
            WindowManager = new WindowManager();
            GameLoop      = new GameLoop(WindowManager);
            Input.Window  = WindowManager;
            Time.GameLoop = GameLoop;

            WindowManager.Scene = new Scene();
            GameObject.Scene    = WindowManager.Scene;

            WindowManager.Scene.ActiveCamera = new Camera();

            WindowManager.Load += OnLoad;
            //WindowManager.Resize += OnResize;
            WindowManager.WindowFrameUpdated += OnFrameUpdate;


            GameLoop.PhysicsUpdated += OnPhysicsUpdate;
            WindowManager.Run();
        }
        /// <summary>
        /// Initializes Variables of the State
        /// </summary>
        public override void Initialize()
        {
            targetState = eGameState.gsMainMenu;

            fFont = ContentLoader.fontArial;

            teMainMenu          = new Text("MAIN MENU", fFont, 30);
            teMainMenu.Position = GameLoop.GetWindowSize() / 2 - new Vector2f(teMainMenu.CharacterSize * 4.5f, 200);

            tePlay          = new Text("Play", fFont, 25);
            tePlay.Position = teMainMenu.Position + new Vector2f(0, 100);
            tePlay.Color    = Color.Red;

            teQuit          = new Text("Quit", fFont, 25);
            teQuit.Position = teMainMenu.Position + new Vector2f(0, 150);
            teQuit.Color    = Color.White;

            iSelected = 0;

            bKeyIsPressed = false;
        }
示例#9
0
        /// <summary>
        /// Destructor of the Projectile
        /// </summary>
        /// <returns>Bool whether Projectile has been destroyed or not</returns>
        public bool Destruct()
        {
            if (SimpleCollisionDetection(sEntity.Position - new Vector2f(tEntity.Size.X / 2, tEntity.Size.Y / 2), tEntity.Size.X, tEntity.Size.Y) || Utilities.DistanceBetweenVectors(StartPosition, sEntity.Position) > GameLoop.GetWindowSize().X / 2)
            {
                return(true);
            }

            else
            {
                return(false);
            }
        }
示例#10
0
        /// <summary>
        /// Returns a List of the Elements to be drawed
        /// Custom List is used to to add Lists rapidly
        /// </summary>
        public override CustomList Draw(RenderWindow window)
        {
            lDrawList = new CustomList();

            lDrawList.AddElement(textQuest);
            lDrawList.AddList(pPlayer.Draw());

            for (int x = 0; x < lEnemies.Count; x++)
            {
                Vector2f EnemyPosition = lEnemies[x].GetPosition();

                if (EnemyPosition.X > GameLoop.GetWindowSize().X || EnemyPosition.X < -50 ||
                    EnemyPosition.Y > GameLoop.GetWindowSize().Y || EnemyPosition.Y < -50)
                {
                    continue;
                }

                lDrawList.AddList(lEnemies[x].Draw());
            }

            if (cText != null)
            {
                tText = cText.ElapsedTime;
            }

            if (tText.AsSeconds() <= 5)
            {
                RectangleShape rShape = new RectangleShape(new Vector2f(20, 15));
                rShape.FillColor        = Color.White;
                rShape.OutlineThickness = 2;
                rShape.OutlineColor     = Color.Black;
                rShape.Position         = new Vector2f(877, 490);

                lDrawList.AddElement(rShape);

                rShape                  = new RectangleShape(new Vector2f(30, 20));
                rShape.FillColor        = Color.White;
                rShape.OutlineThickness = 2;
                rShape.OutlineColor     = Color.Black;
                rShape.Position         = new Vector2f(847, 470);

                lDrawList.AddElement(rShape);

                rShape                  = new RectangleShape(new Vector2f(50, 25));
                rShape.FillColor        = Color.White;
                rShape.OutlineThickness = 2;
                rShape.OutlineColor     = Color.Black;
                rShape.Position         = new Vector2f(805, 450);

                lDrawList.AddElement(rShape);

                rShape                  = new RectangleShape(new Vector2f(200, 50));
                rShape.FillColor        = Color.White;
                rShape.OutlineThickness = 2;
                rShape.OutlineColor     = Color.Black;
                rShape.Position         = new Vector2f(702, 409);

                lDrawList.AddElement(rShape);
                lDrawList.AddElement(TextStreamer.TextForPlayer("Tod den Ecksisten!!", new Vector2f(710, 420)));
            }
            else
            {
                cText = null;
            }


            tTileUndHerrsche.Draw(window, vTileMapPosition);

            return(lDrawList);
        }
        private void Update()
        {
            if (ShouldShowTutorial && !ShowedTutorial)
            {
                ShowedTutorial     = true;
                ShouldShowTutorial = false;
                startMenu.Destroy();
                startMenu    = null;
                tutorialMenu = new TutorialMenu();
                LateAddChild(tutorialMenu);
                ShowedMenu = false;
            }

            if (ShouldStartPlaying && !StartedPlaying)
            {
                StartedPlaying     = true;
                ShouldStartPlaying = false;
                tutorialMenu.Destroy();
                tutorialMenu = null;
                grid         = new GameLoop();
                LateAddChild(grid);
                ShowedMenu = false;
                SoundManager.Instance.Stop("MenuMusic");
                SoundManager.Instance.Play("GameMusic");
            }

            if (ShouldStopPlaying && !StoppedPlaying)
            {
                StoppedPlaying    = true;
                ShouldStopPlaying = false;
                score             = grid.Score;
                if (grid.GotTreasure)
                {
                    gameOverWin = new GameOverWin(score);
                    AddChild(gameOverWin);
                }
                else
                {
                    gameOver = new GameOver(score);
                    AddChild(gameOver);
                }
                grid.Destroy();
                grid = null;
                SoundManager.Instance.Stop("fuelLow");
                SoundManager.Instance.Stop("ambient");
                SoundManager.Instance.Stop("drilling");
                ShowedMenu = false;
            }

            if (ShouldShowMenu && !ShowedMenu)
            {
                ShouldShowMenu    = false;
                ShowedMenu        = true;
                ShowedTutorial    = false;
                StartedPlaying    = false;
                StoppedPlaying    = false;
                ShowedLeaderboard = false;
                score             = -1;
                gameOver?.Destroy();
                leaderboard?.Destroy();
                startMenu = new StartMenu();
                AddChild(startMenu);
                SoundManager.Instance.Play("MenuMusic");
            }

            if (ShouldShowLeaderboard && !ShowedLeaderboard)
            {
                ShouldShowLeaderboard = false;
                ShowedLeaderboard     = true;
                gameOverWin.Destroy();
                leaderboard = new Leaderboard(score);
                AddChild(leaderboard);
            }
        }