コード例 #1
0
ファイル: WeaponManager.cs プロジェクト: Gerjo/Gravwar
        private float shootingTimeElapsed = 0; // Internal counter, leave as-is.

        #endregion Fields

        #region Constructors

        public WeaponManager(AnimPlayer player)
        {
            this.ownerPlayer = player;
            audio = new Audio();
            // Create the collections which will hold our bullets fired/weapons. Mind the clever use of "generics"
            allBullets  = new List<Weapons.AbstractBullet>();

            //defaultWeapon = new Weapons.HeatSeeking();
            defaultWeapon = new Weapons.Pistol();
            //defaultWeapon = new Weapons.BouncyGun();
            pickupWeapon  = null;

            currentWeapon = defaultWeapon;
        }
コード例 #2
0
ファイル: AnimPlayer.cs プロジェクト: Gerjo/Gravwar
        public AnimPlayer(Level ownerLevel, int intPlayerIndex)
        {
            this.ownerLevel     = ownerLevel;
            this.intPlayerIndex = intPlayerIndex;

            switch(intPlayerIndex) {
                case 0:
                    playerIndex = PlayerIndex.One;
                    playerColor = Color.Red;
                    break;

                case 1:
                    playerIndex = PlayerIndex.Two;
                    playerColor = Color.Blue;
                    break;
                case 2:
                    playerIndex = PlayerIndex.Three;
                    playerColor = Color.Green;
                    break;
                case 3:
                    playerIndex = PlayerIndex.Four;
                    playerColor = Color.Yellow;
                    break;
            }

            weaponManager       = new WeaponManager(this);
            audio               = new Audio();

            // If controller "one" is connected use controller as input device. Else use the computer's keyboard and mouse.
            if (GamePad.GetState(PlayerIndex.One).IsConnected)
            {
                inputDevice = new GamePadInput(this);
            }
            else if (playerIndex == PlayerIndex.One)
            {
                inputDevice = new KeyboardInput(this);
            }

            // May have to abstract this routine into a "loadContent" function.
            walkingTex      = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/walkingSpriteMap");
            walkingTexGlow  = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/walkingSpriteMapGlow");
            armTex          = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/arm");
            armTexShoot     = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/armflash");
            pixelTex        = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/pixel");
            haltTex         = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/standingStill2");
            haltTexGlow     = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/standingStillGlow");
            deadTex         = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/dead");
            healthFont      = Game1.INSTANCE.Content.Load<SpriteFont>("Fonts/HealthFont");

            // Will spawn the player at said location:
            spawnPlayer(ownerLevel.spawnPositions[intPlayerIndex]);
        }
コード例 #3
0
ファイル: Level.cs プロジェクト: Gerjo/Gravwar
        /*
         * The LoadContent function of level is one of the most
         * important functions in the game. It loads the level,
         * players and objects. It also loads all the
         * spawn positions.
         */
        public void LoadContent(Menu gameMenu)
        {
            //Hier wordt de informatie vanuit het menu geladen in het level
            fragLimit = gameMenu.fragLimit;
            timeLimit = gameMenu.timeLimit * 60 * 60;

            //Audio initialization.
            audio = new Audio();
            musicVolume = gameMenu.musicVol;
            soundVolume = gameMenu.soundVol;

            playerTotal = gameMenu.numPlayers;

            if (timeLimit == 0)
            {
                timeLimit = int.MaxValue - countdownTime - countdownTime;
            }
            if (fragLimit == 0)
            {
                fragLimit = int.MaxValue;
            }
            if (gameMenu.levelName != null)
            {
                levelName = gameMenu.levelName;
            }
            currentTime = timeLimit + countdownTime;

            //Console.Write("Timelimit: " + timeLimit + " Fraglimit: " + fragLimit + "\n");
            //Load some resources:
            levelTimer = Game1.INSTANCE.Content.Load<SpriteFont>("LevelTimer");
            countDownFont = Game1.INSTANCE.Content.Load<SpriteFont>("Menu");
            pauzeScreenOverlay = Game1.INSTANCE.Content.Load<Texture2D>("Images/Miscellaneous/pauseScreen");
            crowntex[0] = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/Crown4");
            crowntex[1] = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/Crown3");
            crowntex[2] = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/Crown2");
            crowntex[3] = Game1.INSTANCE.Content.Load<Texture2D>("Images/AnimPlayer/Crown1");

            //Create an filestream.
            FileStream fstream = new FileStream(levelName, FileMode.Open, FileAccess.Read);
            byte[] filecontent = new byte[fstream.Length];

            //Create an array to put our data in.
            string[][] leveldata = new string[filecontent.Length][];

            //Read the file and put data in the filecontent.
            for (int i = 0; i < fstream.Length; i++)
            {
                fstream.Read(filecontent, i, 1);
            }

            //Split up the file in "words".
            int currentAt = 0;
            int currentAt2 = 0;
            for (int i = 0; i < filecontent.Length; i++)
            {

                if (leveldata[currentAt] == null)
                {
                    leveldata[currentAt] = new string[255];
                }
                if ((char)filecontent[i] == ' ')
                {
                    currentAt2++;
                }
                else if ((char)filecontent[i] == (char)10)
                {
                    currentAt2 = 0;
                    currentAt++;
                }
                else
                {
                    leveldata[currentAt][currentAt2] += (char)filecontent[i];
                }
            }

            //Go through every data in leveldata.
            for (int i = 0; i < leveldata.Length; ++i)
            {
                if (leveldata[i] != null)
                {
                    if (leveldata[i][0].Contains("background:"))
                    {
                        backgroundTex = Game1.INSTANCE.Content.Load<Texture2D>("Images/Maps/" + leveldata[i][1]);
                    }
                    else if (leveldata[i][0].Contains("backgroundmusic:"))
                    {
                        audio.LoadMusic(leveldata[i][1]);
                    }
                    else if (leveldata[i][0].Contains("object:"))
                    {
                        objects.Add(new Object(leveldata[i][1], int.Parse(leveldata[i][2]), int.Parse(leveldata[i][3]), int.Parse(leveldata[i][4]), int.Parse(leveldata[i][5])));
                    }
                    else if (leveldata[i][0].Contains("moveableobj:"))
                    {
                        objects.Add(new Object(leveldata[i][1], int.Parse(leveldata[i][2]), int.Parse(leveldata[i][3]), int.Parse(leveldata[i][4]), int.Parse(leveldata[i][5]), int.Parse(leveldata[i][6]), int.Parse(leveldata[i][7]), int.Parse(leveldata[i][8])));
                    }
                    else if (leveldata[i][0].Contains("item:"))
                    {
                        items.Add(new Items(int.Parse(leveldata[i][2]), int.Parse(leveldata[i][3]), leveldata[i][1]));
                    }
                    else if (leveldata[i][0].Contains("\r"))
                    {
                    }
                    else if (leveldata[i][0].Contains("spawn:"))
                    {
                        spawnPositions.Add(new SpawnPosition(int.Parse(leveldata[i][1]), int.Parse(leveldata[i][2]), leveldata[i][3]));
                    }
                }
            }

            //What if no background is found?
            if (backgroundTex == null)
            {
                backgroundTex = Game1.INSTANCE.Content.Load<Texture2D>("Images/Maps/BasicShapes/Rectangle");
            }

            // Initiate 4 players:
            for (int i = 0; i < playerTotal; i++)
            {
                animPlayers[i] = new AnimPlayer(this, i);
            }

            // Start the game, we *could* add a start game countdown screen here.
            levelState = LevelStates.StartCountdown;
        }