コード例 #1
0
ファイル: Game1.cs プロジェクト: IIS-Mobile/TanksMonogame
        private void CheckColisionForPlayer(BulletSprite bullet, TankSprite player, TankSprite enemy)
        {
            if (bullet.shouldDraw && bullet.IsCollidingWith(player) && bullet.bulletOwner != player.playerNumber)
            {
                var explosion = new AnimatedSprite(explosionTexture,
                                                   new Vector2(player.position.X, player.position.Y) - new Vector2(explosionTexture.Width / 2 / 4, explosionTexture.Height / 2 / 4), 4, 4);

                player.position = player.startingPosition;
                enemy.score++;
                explosions.Add(explosion);
                bullet.shouldDraw = false;
                explosionSound.Play();
            }
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: IIS-Mobile/TanksMonogame
        protected override void LoadContent()
        {
            GraphicsDevice.BlendState        = BlendState.Opaque;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.SamplerStates[0]  = SamplerState.LinearWrap;

            spriteBatch    = new SpriteBatch(GraphicsDevice);
            bulletTexture  = Content.Load <Texture2D>("Bullets/bulletBeige");
            playerTexture  = Content.Load <Texture2D>("Default size/tank_green");
            explosionSound = Content.Load <SoundEffect>("SoundFX/explosion");

            /*           backgroundMusic = Content.Load<Song>("SoundFX/background_music");
             *         MediaPlayer.Play(backgroundMusic);
             *         MediaPlayer.Volume = 0.1f;*/

            explosionTexture = Content.Load <Texture2D>("explosion/exp2_0");
            var lines = File.ReadAllLines(@"Content/Level1.txt");

            foreach (var line in lines)
            {
                var       data        = line.Split(';');
                Texture2D tempTexture = Content.Load <Texture2D>(data[0]);
                Vector2   tempPos     = new Vector2(float.Parse(data[1]), float.Parse(data[2]));

                if (data.Length == 5 && !data[4].Equals("auto") && !data[4].Equals("none"))
                {
                    var collisionPoints    = data[4].Split(',');
                    var collisionTriangles = new List <Triangle>();
                    for (var i = 0; i < collisionPoints.Length; i += 6)
                    {
                        collisionTriangles.Add(new Triangle(
                                                   new Vector2(float.Parse(collisionPoints[i]), float.Parse(collisionPoints[i + 1])),
                                                   new Vector2(float.Parse(collisionPoints[i + 2]),
                                                               float.Parse(collisionPoints[i + 3])),
                                                   new Vector2(float.Parse(collisionPoints[i + 4]),
                                                               float.Parse(collisionPoints[i + 5]))
                                                   )
                                               );
                    }

                    Level.Add(new Sprite(tempTexture, tempPos, float.Parse(data[3]), collisionTriangles));
                }
                else if (data.Length == 5 && data[4].Equals("auto"))
                {
                    Level.Add(new Sprite(tempTexture, tempPos, float.Parse(data[3])));
                }
                else
                {
                    Level.Add(new Sprite(tempTexture, tempPos, float.Parse(data[3]), null));
                }
            }

            var player1Keys =
                new TankKeyMap {
                up = Keys.W, down = Keys.S, left = Keys.A, right = Keys.D, fire = Keys.Space
            };

            playerSprite = new TankSprite(player1Keys, playerTexture, new Vector2(0, 0), 1, this, new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));

            var player2Keys = new TankKeyMap
            {
                up    = Keys.Up,
                down  = Keys.Down,
                left  = Keys.Left,
                right = Keys.Right,
                fire  = Keys.Enter
            };

            playerSprite2 = new TankSprite(player2Keys, playerTexture, new Vector2(graphics.PreferredBackBufferWidth - playerTexture.Width,
                                                                                   graphics.PreferredBackBufferHeight - playerTexture.Height), 2, this, new Vector2(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));


            HUDFont            = Content.Load <SpriteFont>("HUDFont");
            playerSprite.font  = HUDFont;
            playerSprite2.font = HUDFont;

            foreach (var sprite in Level)
            {
                sprite.font = HUDFont;
            }

            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Obstacles/barrelGreen_up"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Obstacles/barrelRed_up"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Obstacles/oil"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Obstacles/sandbagBeige"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Obstacles/sandbagBrown"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Environment/treeLarge"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Environment/treeSmall"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Environment/grass"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Environment/sand"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Environment/dirt"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/barrelBlack_top"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/barrelGreen_top"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/barrelRed_top"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/barrelRust_top"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/barricadeMetal"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/fenceRed"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/fenceYellow"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/barricadeWood"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/oilSpill_large"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/sandbagBeige"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/sandbagBeige_open"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass1"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/barricadeWood"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadCornerLL"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadCornerLR"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadCornerUL"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadCornerUR"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadCrossing"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadCrossingRound"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadEast"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadNorth"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadSplitE"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadSplitN"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadSplitS"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadSplitW"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadTransitionE"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadTransitionE_dirt"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadTransitionN"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadTransitionN_dirt"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadTransitionS"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadTransitionS_dirt"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadTransitionW"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_roadTransitionW_dirt"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_transitionE"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_transitionN"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_transitionS"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass_transitionW"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass1"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileGrass2"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadCornerLL"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadCornerLR"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadCornerUL"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadCornerUR"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadCrossing"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadCrossingRound"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadEast"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadNorth"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadSplitE"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadSplitN"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadSplitS"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand_roadSplitW"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand1"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tileSand2"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tracksDouble"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tracksLarge"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Default size/tracksSmall"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Tanks/barrelRed"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Tanks/barrelRed_outline"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Tanks/barrelBeige"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Tanks/barrelBeige_outline"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Tanks/barrelBlack"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Tanks/barrelBlack_outline"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Tanks/barrelBlue"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("Tanks/barrelBlue_outline"));

            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_03"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_18"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_06"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_11"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_10"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_07"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_14"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_09"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_12"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_05"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_23"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_02"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_19"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_16"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_20"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_22"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_04"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_21"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_15"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_08"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_01"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_17"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Structure/medievalStructure_13"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_13"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_17"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_05"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_01"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_08"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_20"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_04"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_12"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_02"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_07"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_21"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_03"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_11"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_06"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_09"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_14"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_16"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_19"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_10"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_18"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Environment/medievalEnvironment_15"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_17"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_05"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_10"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_02"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_14"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_01"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_19"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_06"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_18"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_08"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_23"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_11"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_12"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_09"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_04"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_07"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_24"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_15"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_03"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_20"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_13"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_21"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_22"));
            MapEditorAvailableItems.Add(Content.Load <Texture2D>("RTS/Unit/medievalUnit_16"));
        }