コード例 #1
0
ファイル: Sample.cs プロジェクト: Dahrkael/CoRe
 public void Play()
 {
     sei = se.CreateInstance();
     sei.Volume = volume;
     sei.Pitch = pitch;
     sei.Play();
 }
コード例 #2
0
        public void Initialize()
        {
            Game.InitializeAssetDatabase();

            defaultEngine = new AudioEngine();

            using (var monoStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                monoSoundEffect = SoundEffect.Load(defaultEngine, monoStream);
            }
            using (var stereoStream = AssetManager.FileProvider.OpenStream("EffectStereo", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                stereoSoundEffect = SoundEffect.Load(defaultEngine, stereoStream);
            }
            using (var contStream = AssetManager.FileProvider.OpenStream("EffectToneA", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                continousMonoSoundEffect = SoundEffect.Load(defaultEngine, contStream);
            }
            using (var contStream = AssetManager.FileProvider.OpenStream("EffectToneAE", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                continousStereoSoundEffect = SoundEffect.Load(defaultEngine, contStream);
            }
            using (var monoStream = AssetManager.FileProvider.OpenStream("Effect44100Hz", VirtualFileMode.Open, VirtualFileAccess.Read))
            {
                laugherMono = SoundEffect.Load(defaultEngine, monoStream);
            }

            monoInstance = monoSoundEffect.CreateInstance();
            stereoInstance = stereoSoundEffect.CreateInstance();
        }
コード例 #3
0
ファイル: Audio.cs プロジェクト: Nagraal/Tactile-Engine
        private Maybe <int> add_new_playing_sound(
            SoundEffectInstance instance,
            Maybe <int> channel,
            bool duckBgm)
        {
            int actual_channel;

            // If the channel is defined
            if (channel.IsSomething)
            {
                if (channel >= Playing_Sounds.Length || channel < 0)
                {
                    throw new ArgumentException();
                }

                // If a sound is already on this channel
                if (Playing_Sounds[channel] != null)
                {
                    // If the sound on this channel is also a channel sound,
                    if (Playing_Sounds[channel].FixedChannel)
                    {
                        // Dispose the sound so it can be replaced
                        Playing_Sounds[channel].Stop();
                        Playing_Sounds[channel].Dispose();
                        Playing_Sounds[channel] = null;
                    }
                    else
                    {
                        // If there aren't empty channels to move the sound to instead
                        // Remove the oldest sound
                        if (too_many_active_sounds)
                        {
                            remove_oldest_playing_sound();
                        }
                        // Move all sounds up a channel if this one is still taken
                        if (Playing_Sounds[channel] != null)
                        {
                            push_sound_ids(channel);
                        }
                    }
                }

                actual_channel = channel;
            }
            // Else play on the first open channel
            else
            {
                actual_channel = -1;
                // Remove the oldest sound if there are too many
                if (too_many_active_sounds)
                {
                    remove_oldest_playing_sound();
                }
                // Find the first empty channel
                for (int i = 0; i < Playing_Sounds.Length; i++)
                {
                    if (Playing_Sounds[i] == null)
                    {
                        actual_channel = i;
                        break;
                    }
                }
            }

            // If we found a channel to play the sound on
            if (actual_channel >= 0)
            {
                instance.Play();
                // If calling play on the sound results in some error, dispose it
                if (instance.State == SoundState.Initial)
                {
                    instance.Dispose();
                }
                else
                {
                    // Don't duck by sfx if the BGM is manually ducked
                    if (!BgmDuckedBySfx && BgmManager.IsBgmDucked)
                    {
                        duckBgm = false;
                    }

                    Playing_Sounds[actual_channel] = new ChannelSound(
                        instance, channel.IsSomething, duckBgm);
                    if (duckBgm)
                    {
                        BgmManager.DuckBgmVolume();
                        BgmDuckedBySfx = true;
                    }
                    return(actual_channel);
                }
            }
            return(Maybe <int> .Nothing);
        }
コード例 #4
0
ファイル: Audio.cs プロジェクト: Nagraal/Tactile-Engine
 public SoundEffectGetter(bool ogg, SoundEffect sound, SoundEffectInstance instance)
 {
     Ogg      = ogg;
     Sound    = sound;
     Instance = instance;
 }
コード例 #5
0
        public static void Play3DSound(SoundEffect e, Vector3 position, IARCamera camera)
        {
            SoundEffectInstance i = e.CreateInstance();

            Play3DSound(i, position, camera);
        }
コード例 #6
0
ファイル: Ice_Revolver.cs プロジェクト: Tyfyter/Entropy
 public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
 {
     passivereload = 0;
     if (player.altFunctionUse == 2)
     {
         for (int i = 0; i < 14 - player.itemAnimation; i++)
         {
             Dust.NewDustPerfect(position + new Vector2(6, 0).RotatedBy(MathHelper.ToRadians(i * 60)), 263, new Vector2(), 0, new Color(75, 255, 255, 200), 0.5f).noGravity = true;
         }
         if (player.itemAnimation <= 4)
         {
             if (player.controlUseTile)
             {
                 if (RoundsLeft < RoundsMax && player.CheckMana((int)(35 * player.manaCost), true))
                 {
                     RoundsLeft++;
                 }
                 player.itemAnimation = 0;
                 return(false);
             }
             if (reloading == 0 && reloaddelay <= 0)
             {
                 reloading = 10;
             }
             reloaddelay          = 1;
             player.itemAnimation = 0;
         }
         return(false);
     }
     if (!CanUseItem(player))
     {
         return(false);
     }
     item.noUseGraphic = false;
     if (boosted && (player.itemAnimation == 10 || player.itemAnimation == 11 || player.itemAnimation == 13 || player.itemAnimation == 14))
     {
         Main.PlaySound(SoundID.Item, (int)position.X, (int)position.Y, 38).Volume *= 0.5f;
         Main.PlaySound(SoundID.Item, (int)position.X, (int)position.Y, 30);
         SoundEffectInstance a = Main.PlaySound(SoundID.Shatter, (int)position.X, (int)position.Y);
         a.Volume *= 0.15f;
         a.Pitch  *= 0.5f;
         RoundsLeft--;
         for (int i = 0; i < 3; i++)
         {
             //DustID.PortalBoltTrail DustID.FlameBurst
             Dust.NewDustDirect(position, 0, 0, DustID.PortalBoltTrail, speedX / 0.4f, speedY / 0.4f, 0, new Color(75, 255, 255, 200), 0.5f).noGravity = true;
         }
     }
     else if (!boosted && (player.itemAnimation == 13 || player.itemAnimation == 14))
     {
         Main.PlaySound(SoundID.Item, (int)position.X, (int)position.Y, 38).Volume *= 0.5f;
         Main.PlaySound(SoundID.Item, (int)position.X, (int)position.Y, 30);
         SoundEffectInstance a = Main.PlaySound(SoundID.Shatter, (int)position.X, (int)position.Y);
         a.Volume *= 0.15f;
         a.Pitch  *= 0.5f;
         RoundsLeft--;
         for (int i = 0; i < 3; i++)
         {
             //DustID.PortalBoltTrail DustID.FlameBurst
             Dust.NewDustDirect(position, 0, 0, DustID.PortalBoltTrail, speedX / 0.4f, speedY / 0.4f, 0, new Color(75, 255, 255, 200), 0.5f).noGravity = true;
         }
     }
     else if (!boosted && player.itemAnimation > 1 && player.itemAnimation < 8)
     {
         item.noUseGraphic = true;
         if (player.controlUseItem && player.itemAnimation < 6)
         {
             boosting = true;
         }
         if (boosting)
         {
             Vector2 speed = new Vector2(speedX, speedY);
             if (player.controlDown || player.controlUp || player.controlLeft || player.controlRight)
             {
                 speed *= 0;
                 if (player.controlLeft || player.controlRight)
                 {
                     speed.X = player.controlRight?1:-1;
                 }
                 if (player.controlDown || player.controlUp)
                 {
                     speed.Y = player.controlDown?1:-1;
                 }
             }
             player.velocity += player.velocity.Y == 0 && !player.controlUp?new Vector2(10 * (Math.Sign(speed.X)), 0):new Vector2(speed.X * 2, speed.Y * 8);
             if ((speed.X != 0 || (speed.Y < 0 || player.velocity.Y != 0)) || player.itemAnimation > 5)
             {
                 player.immuneTime = player.immuneTime > 2?player.immuneTime:2;
             }
             if ((speed.X != 0 || (speed.Y < 0 || player.velocity.Y != 0)) || player.itemAnimation > 5)
             {
                 player.immune = true;
             }
             player.direction = (int)(Math.Sign(speedX)) * (player.itemAnimation < 7 && player.itemAnimation > 3?-1:1);
             if ((speed.X != 0 || (speed.Y < 0 || player.velocity.Y != 0)) || player.itemAnimation > 5)
             {
                 player.stealth = 1;
             }
             if (player.itemAnimation <= 2)
             {
                 player.velocity     *= player.velocity.Y == 0?0.05f:0.3f;
                 boosted              = true;
                 player.itemAnimation = 14;
             }
         }
         return(false);
     }
     else
     {
         if (player.itemAnimation < 8)
         {
             item.noUseGraphic = true;
         }
         return(false);
     }
     return(base.Shoot(player, ref position, ref speedX, ref speedY, ref type, ref damage, ref knockBack));
 }
コード例 #7
0
        public void LoadLevel(ContentManager content,
                              GraphicsDeviceManager graphics,
                              List <GameObject> objects,
                              string levelNumber,
                              string roomNumber,
                              bool restartMusic)
        {
            bgMusic = content.Load <SoundEffect>("Sounds/Music/J04");

            if (soundEffectInstance != null && levelNumber != levelNumberHolder)
            {
                soundEffectInstance.Stop(true);
                soundEffectInstance.Dispose();
            }

            if (restartMusic)
            {
                soundEffectInstance = bgMusic.CreateInstance();
                soundEffectInstance.Play();
            }

            levelNumberHolder = levelNumber;


            //Load and Draw the map and walls
            wallMap.Load(content);
            tiledMap = content.Load <TiledMap>("TiledMaps/m_level_" + levelNumber);
            renderer = new TiledMapRenderer(graphics.GraphicsDevice);



            //access walls in map
            var tiledMapWallsLayer = tiledMap.GetLayer <TiledMapTileLayer>("Wall");

            //access stairs in map
            var tiledMapInteractLayer = tiledMap.GetLayer <TiledMapTileLayer>("Interact");

            //access objects in map
            objectLayer = tiledMap.GetLayer <TiledMapObjectLayer>("Room_" + roomNumber);

            if (objectLayer != null)
            {
                for (int i = 0; i < objectLayer.Objects.Length; i++)
                {
                    // create player
                    if (objectLayer.Objects[i].Type == "Player" && objects.Count == 0)
                    {
                        if (Door.transitionDirection == "StairTransition")
                        {
                            if (objectLayer.Objects[i].Name == "PlayerStartStairs")
                            {
                                objects.Add(new Player(new Vector2(objectLayer.Objects[i].Position.X,
                                                                   objectLayer.Objects[i].Position.Y)));
                            }
                        }
                        else if (Door.transitionDirection != "StairTransition" && objectLayer.Objects[i].Name == "PlayerStart")
                        {
                            if (Game1.levelNumber != "Overworld")
                            {
                                objects.Add(new Player(new Vector2(objectLayer.Objects[i].Position.X,
                                                                   objectLayer.Objects[i].Position.Y)));
                            }
                            else
                            {
                                objects.Add(new PlayerOverworld(new Vector2(objectLayer.Objects[i].Position.X,
                                                                            objectLayer.Objects[i].Position.Y)));
                            }
                        }
                        //if the player exist, initialize and load
                        if (objects.Count > 0)
                        {
                            objects[0].Initialize();
                            objects[0].Load(content);
                        }
                    }

                    //create enemies
                    if (objectLayer.Objects[i].Type == "Enemy")
                    {
                        objects.Add(new PatrolEnemy(new Vector2(objectLayer.Objects[i].Position.X,
                                                                objectLayer.Objects[i].Position.Y)));
                    }

                    // create camera and min max values
                    if (objectLayer.Objects[i].Type == "Camera")                     // set camera max and min
                    {
                        if (objectLayer.Objects[i].Name == "cameraMin")
                        {
                            Camera.cameraMin = objectLayer.Objects[i].Position + Camera.cameraOffset;
                            roomMin          = objectLayer.Objects[i].Position;
                        }
                        if (objectLayer.Objects[i].Name == "cameraMax")
                        {
                            Camera.cameraMax = objectLayer.Objects[i].Position - Camera.cameraOffset;
                            roomMax          = objectLayer.Objects[i].Position;
                        }
                    }
                    if (objectLayer.Objects[i].Type == "Door")                     // make doors
                    {
                        wallMap.doors.Add(new Door(new Rectangle((int)objectLayer.Objects[i].Position.X,
                                                                 (int)objectLayer.Objects[i].Position.Y,
                                                                 (int)objectLayer.Objects[i].Size.Width,
                                                                 (int)objectLayer.Objects[i].Size.Height),
                                                   objectLayer.Objects[i].Name));
                    }
                }
            }
            // draw the walls
            if (tiledMapWallsLayer != null)
            {
                for (var i = 0; i < tiledMapWallsLayer.Width; i++)
                {
                    for (var j = 0; j < tiledMapWallsLayer.Height; j++)
                    {
                        if ((i > (roomMin.X - tiledMapWallsLayer.TileWidth) / tiledMapWallsLayer.TileWidth &&
                             j > (roomMin.Y - tiledMapWallsLayer.TileHeight) / tiledMapWallsLayer.TileHeight) &&
                            (i <= (roomMax.X + tiledMapWallsLayer.TileWidth) / tiledMapWallsLayer.TileWidth &&
                             j <= (roomMax.Y + tiledMapWallsLayer.TileHeight) / tiledMapWallsLayer.TileHeight))
                        {
                            if (tiledMapWallsLayer.TryGetTile(i, j, out TiledMapTile? tile))
                            {
                                if (tile.Value.GlobalIdentifier == 1)                                 // make walls
                                {
                                    wallMap.walls.Add(new Wall(new Rectangle(i * tiledMapWallsLayer.TileWidth,
                                                                             j * tiledMapWallsLayer.TileHeight,
                                                                             tiledMapWallsLayer.TileWidth,
                                                                             tiledMapWallsLayer.TileHeight)));
                                }
                            }
                            if (tiledMapInteractLayer != null)
                            {
                                if (tiledMapInteractLayer.TryGetTile(i, j, out TiledMapTile? itile))
                                {
                                    if (itile.Value.GlobalIdentifier == 2)                                     // make stairs
                                    {
                                        //use for stair directions
                                        if (!itile.Value.IsFlippedHorizontally)
                                        {
                                            wallMap.stairs.Add(new Stair(new Rectangle(i * tiledMapInteractLayer.TileWidth,
                                                                                       j * tiledMapInteractLayer.TileHeight,
                                                                                       tiledMapInteractLayer.TileWidth,
                                                                                       tiledMapInteractLayer.TileHeight)));
                                        }
                                        else
                                        {
                                            wallMap.stairs.Add(new Stair(new Rectangle(i * tiledMapInteractLayer.TileWidth,
                                                                                       j * tiledMapInteractLayer.TileHeight,
                                                                                       tiledMapInteractLayer.TileWidth,
                                                                                       tiledMapInteractLayer.TileHeight), false));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            //load objects
            LoadObjects(content, objects);
        }
コード例 #8
0
 /// <summary>
 /// Stops the music immediately.
 /// </summary>
 public void StopMusic()
 {
     _currentMusic.Stop();
     _currentMusic.Dispose();
     _currentMusic = null;
 }
コード例 #9
0
        public override void LoadContent()
        {
            this.weaponManager = new WeaponManager();

            this.players = new List <Player>();

            this.bulletActive = false;
            this.addMaterial  = false;
            this.rocketFlying = false;

            background = Content.Load <Texture2D>("Textures/Level2/level2");

            this.backgroundOriginal = Content.Load <Texture2D>("Textures/Level2/level2");

            this.bold = Content.Load <SpriteFont>("Fonts/spriteFontBold");

            this.backgroundOriginalColour = new Color[this.backgroundOriginal.Width * this.backgroundOriginal.Height];
            this.backgroundOriginal.GetData(this.backgroundOriginalColour);

            tank = Content.Load <Texture2D>("Textures/tank-custom");

            font = Content.Load <SpriteFont>("Fonts/spritefont1");

            parachute = Content.Load <Texture2D>("Textures/parachute");

            this.missile_thumbnail = Content.Load <Texture2D>("Textures/missile-thumbnail");

            color = new Color[background.Width * background.Height];
            background.GetData(color);

            turret = Content.Load <Texture2D>("Textures/turret");

            this.tex = Content.Load <Texture2D>("Textures/Particle2");

            this.hud = Content.Load <Texture2D>("Textures/hud2");

            bullet      = Content.Load <Texture2D>("Textures/circle2");
            bulletColor = new Color[bullet.Width * bullet.Height];
            bullet.GetData(bulletColor);


            //Reset the modified terrain from the original texture
            this.color = this.backgroundOriginalColour;
            this.background.SetData(this.color);


            //Initialise the players:

            players.Add(new Player(0, tank, new Vector2(135, 0), Color.Green, turret, new Vector2(135 + 37, 21), Color.Green, this.weaponManager));

            players.Add(new Player(1, tank, new Vector2(935, 0), Color.Blue, turret, new Vector2(935 + 37, 21), Color.Blue, this.weaponManager));

            players.Add(new Player(2, tank, new Vector2(550, 0), Color.Purple, turret, new Vector2(550 + 37, 21), Color.Purple, this.weaponManager));

            players[0].setTurretOrigin(2, 5);
            players[1].setTurretOrigin(2, 5);
            players[2].setTurretOrigin(2, 5);

            levelManager = new LevelManager(players, gameStateManager);
            levelManager.setCurrentPlayer(players[0]);
            levelManager.setGameStatus(true);

            rocketPosition = new Vector2(levelManager.getCurrentPlayer().getPlayerPosition().X + tank.Width / 2, levelManager.getCurrentPlayer().getPlayerPosition().Y);

            this.p = new ParticleSystemModified(new Vector2(levelManager.getCurrentPlayer().getPlayerPosition().X + (tank.Width / 2), levelManager.getCurrentPlayer().getPlayerPosition().Y), 400, 999, 108);

            //Start the snow particles
            //  simulateSnow();

            //Initialise sounds
            soundWindBlowing                    = Content.Load <SoundEffect>("Sounds/snow_blowing");
            soundWindowBlowingInstance          = soundWindBlowing.CreateInstance();
            soundWindowBlowingInstance.IsLooped = true;

            soundWindowBlowingInstance.Play();


            this.launch         = Content.Load <SoundEffect>("Sounds/rlaunch");
            this.launchInsatnce = this.launch.CreateInstance();

            this.hit         = Content.Load <SoundEffect>("Sounds/single_explosion");
            this.hitInstance = this.hit.CreateInstance();
        }
コード例 #10
0
ファイル: AmbientSound.cs プロジェクト: JordanFisher/WAL
        public static void SetVolume(this SoundEffectInstance instance, float volume)
        {
            float restrictedVolume = CoreMath.Restrict(0, 1, volume);

            instance.Volume = restrictedVolume;
        }
コード例 #11
0
 public SafeSoundEffectInstance(SoundEffectInstance inner)
 {
     this.inner = inner;
 }
コード例 #12
0
ファイル: SoundPlayer.cs プロジェクト: Alan-FGR/aelum
    private bool lastInRange = false; //was it in range last tick?

    public SoundPlayer(Entity entity, string effectId) : base(entity)
    {
        effectId_       = effectId;
        effectInstance_ = PipelineAssets.LoadAsset <SoundEffect>(effectId).CreateInstance();
    }
コード例 #13
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load badge textures.
            badges = Loader.ContentLoad <Texture2D>(Content, "Badges");

            // Ex 6
            // Set up viewport object.
            Viewport viewport = GraphicsDevice.Viewport;


            // Set up badge position.
            // Set up menu positions
            Rectangle position1 = new Rectangle(viewport.Width / 2 - 60, viewport.Height / 2 - 60, 100, 100);
            Rectangle position2 = new Rectangle(position1.X + 70, position1.Y, 100, 100);
            Rectangle position3 = new Rectangle(position2.X + 70, position2.Y, 100, 100);
            Rectangle position4 = new Rectangle(position3.X + 70, position3.Y, 100, 100);
            Rectangle position5 = new Rectangle(position4.X + 70, position4.Y, 100, 100);

            positions[0] = position1;
            positions[1] = position2;
            positions[2] = position3;
            positions[3] = position4;
            positions[4] = position5;

            // Texture version.
            foreach (var item in badges)
            {
                // Queue Method
                // qbadges.Enqueue(item.Value);

                // Ex 6.
                // Set up Badge Objects.
                badgeObjects.Add(item.Key, new Badge(this, item.Key, item.Value, false, positions[positionCounter]));
                positionCounter++;
            }

            // Texture version.
            // Get the first texture item.

            //_dequeued = qbadges.Dequeue();
            //qbadges.Enqueue(_dequeued);

            // Add badge objects to badge object queue.
            //foreach (var badge in badgeObjects)
            //{
            //    queueBadgeObjects.Enqueue(badge.Value);
            //}

            // Get the first badge object.
            //dequeuedBadge = queueBadgeObjects.Dequeue();
            //queueBadgeObjects.Enqueue(dequeuedBadge);

            // Load sound effects.
            AudioManager.SoundEffects = Loader.ContentLoad <SoundEffect>(Content, "Sounds");

            player = AudioManager.SoundEffects["Badges_0"].CreateInstance();
            //player.Play();

            //AudioManager.Play(ref player, "Badges_0");

            // TODO: use this.Content to load your game content here

            background = Content.Load <Texture2D>("gameOverBackground");
        }
コード例 #14
0
 private void PlayFlyingSound()
 {
     FlyingSoundEffect = Game.PlaySoundEffect(content.audio.drone_flying, true);
 }
コード例 #15
0
 /// <summary>
 /// Initializes a new sound effect
 /// </summary>
 /// <param name="soundEffect">The base SoundEffect to use</param>
 public GameSFX(SoundEffect soundEffect)
 {
     //Sets the base sounds
     baseEffect   = soundEffect;
     baseInstance = baseEffect.CreateInstance();
 }
コード例 #16
0
ファイル: AmbientSound.cs プロジェクト: JordanFisher/WAL
 public static void SetVolume(this SoundEffectInstance instance, double volume)
 {
     instance.SetVolume((float)volume);
 }
コード例 #17
0
        public void TestMultipleCreations()
        {
            ///////////////////////////////////////////////////////////////////////////////////
            // 1. Check that creating and starting lots of instances in parallel does not crash
            const int nbOfInstances = 100;
            var instances = new SoundEffectInstance[nbOfInstances];
            for (int i = 0; i < nbOfInstances; ++i)
            {
                instances[i] = monoSoundEffect.CreateInstance();
                instances[i].Play();
            }
            Utilities.Sleep(2000);
            foreach (var instance in instances)
                instance.Dispose();

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // 2. Check that restarting again and again instances does not result in memory leaks (android recreate the voices)
            for (int i = 0; i < 100; ++i)
            {
                monoSoundEffect.Play();
                Utilities.Sleep(1); // SourceVoice.SubmitBuffer crashes in native code after the 64th successive iteration if this line is not here
                monoSoundEffect.Stop();
            }
        }
コード例 #18
0
ファイル: ActionGame.cs プロジェクト: havri/ActionGame
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            if (running)
            {
                using (Loading loadingForm = new Loading())
                {
                    GameTime gameTime = new GameTime(TimeSpan.Zero, TimeSpan.Zero);
                    loadingForm.Show();

                    loadingForm.SetLabel("Loading graphics device tools...");
                    spriteBatch = new SpriteBatch(GraphicsDevice);

                    loadingForm.SetLabel("Loading content...");
                    contentRepository.LoadContent();

                    loadingForm.SetLabel("Loading gun types...");
                    LoadGunTypes();

                    player   = new Player(this);
                    opponent = new Opponent(this);

                    town = new Town(this, loadingForm);

                    loadingForm.SetLabel("Loading player...");
                    loadingForm.SetValue(0);
                    Point          playerPoint    = town.CurrentQuarter.GetRandomSquare(s => s == MapFillType.Sidewalk);
                    PositionInTown playerPosition = new PositionInTown(town.CurrentQuarter, playerPoint.ToVector2() * TownQuarter.SquareWidth + Vector2.One * 0.5f * TownQuarter.SquareWidth);
                    player.Load(contentRepository.Player, playerPosition, MathHelper.PiOver2, drawer.WorldTransformMatrix);
                    town.CurrentQuarter.SpaceGrid.AddObject(player);
                    town.CurrentQuarter.SetOwner(player, gameTime);
                    player.AddEnemy(opponent);

                    loadingForm.SetLabel("Loading opponent...");
                    loadingForm.SetValue(0);
                    TownQuarter    oppQuarter  = (from q in town.Quarters where q != town.CurrentQuarter orderby random.Next() select q).First();
                    Point          oppPoint    = oppQuarter.GetRandomSquare(s => s == MapFillType.Sidewalk);
                    PositionInTown oppPosition = new PositionInTown(oppQuarter, oppPoint.ToVector2() * TownQuarter.SquareWidth);
                    opponent.Load(contentRepository.Opponent, oppPosition, 0, drawer.WorldTransformMatrix);
                    oppQuarter.BeEnteredBy(opponent);
                    oppQuarter.SetOwner(opponent, gameTime);
                    opponent.AddEnemy(player);
                    Components.Add(town);


                    BulletVisualisation.Texture = Content.Load <Texture2D>("Textures/white");
                    backgroundSound             = Content.Load <SoundEffect>("Sounds/background").CreateInstance();

                    loadingForm.SetLabel("Cleaning memory...");
                    loadingForm.SetValue(0);
                    GC.Collect();
                    loadingForm.SetValue(100);

                    loadingForm.SetLabel("Content loaded. Get ready to play!");
                    loadingForm.SetValue(100);
                    loadingForm.Close();

                    backgroundSound.IsLooped = true;
                    backgroundSound.Play();
                    drawer.ShowMessage(new GameTime(), String.Format("Wellcome in the game. You're in {0}.", player.Position.Quarter.Name));
                }
                if (settings.Fullscreen)
                {
                    graphics.ToggleFullScreen();
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            //background images + full screen displays
            bGText       = Content.Load <Texture2D>("bw2/bgCuteTemp");
            background   = new HUDObjects(bGText, new Rectangle(0, 0, windowX, windowY));
            testText     = Content.Load <Texture2D>("bw2/breadwars");
            introTest    = new HUDObjects(testText, new Rectangle(0, 0, windowX, windowY));
            helpSplash   = Content.Load <Texture2D>("helpScreen");
            help         = new HUDObjects(helpSplash, new Rectangle(0, 0, windowX, windowY));
            creditSplash = Content.Load <Texture2D>("CreditsScreen");
            credits      = new HUDObjects(creditSplash, new Rectangle(0, 0, windowX, windowY));
            tie1Text     = Content.Load <Texture2D>("tieGame1");
            tie2Text     = Content.Load <Texture2D>("tieGame2");
            tie1         = new HUDObjects(tie1Text, new Rectangle(470, 420, 320, 60));
            tie2         = new HUDObjects(tie2Text, new Rectangle(470, 480, 320, 60));
            win1Text     = Content.Load <Texture2D>("bw2/play1splash");
            win2Text     = Content.Load <Texture2D>("bw2/play2splash");
            WinGame      = new HUDObjects[2];
            WinGame[0]   = new HUDObjects(win1Text, new Rectangle(0, 0, windowX, windowY));
            WinGame[1]   = new HUDObjects(win2Text, new Rectangle(0, 0, windowX, windowY));
            confettiText = Content.Load <Texture2D>("bw2/confet");
            confetti     = new HUDObjects(confettiText, new Rectangle(0, 0, 1280, 2400), 3, 1);
            confetti.UnpackSprites();
            confetti.MsPerFrame = 300;

            //deck& AI buttons
            buttonP    = Content.Load <Texture2D>("bw2/pinkbutton");
            buttonB    = Content.Load <Texture2D>("bw2/bluebutton");
            buttons    = new Texture2D[2];
            buttons[0] = buttonP;
            buttons[1] = buttonB;
            //for (int i = 0; i < 6; i++) deckButtons[i] = new Drawable(buttons[1], deckButtonPos[i]);
            for (int i = 0; i < 2; i++)
            {
                numPlayButtons[i] = new Drawable(buttons[i], numPlayButtonPos[i]);
            }

            //main menu button
            mainMenuButton = new HUDObjects(buttonB, new Rectangle(503, 503, buttonX, buttonY));
            //full screen cont.- pause screens
            /////////////////////////////////////////////////////////////////////////////////////delete this if everthing works
            //pause1Text = Content.Load<Texture2D>("pausephase1");
            //pause1 = new HUDObjects(pause1Text, new Rectangle(0, 0, windowX, windowY));
            //pause2Text = Content.Load<Texture2D>("pausephase2");
            //pause2 = new HUDObjects(pause2Text, new Rectangle(0, 0, windowX, windowY));
            pauseText = Content.Load <Texture2D>("bw2/pausephase");
            pause     = new HUDObjects(pauseText, new Rectangle(0, 0, windowX, windowY));

            //results text
            win1Text    = Content.Load <Texture2D>("player1wins");
            player1wins = new HUDObjects(win1Text, new Rectangle(470, 460, 320, 60));
            win2Text    = Content.Load <Texture2D>("player2wins");
            player2wins = new HUDObjects(win2Text, new Rectangle(470, 460, 340, 60));
            vsText      = Content.Load <Texture2D>("vs");
            vs          = new HUDObjects(vsText, new Rectangle(570, 260, 70, 50));

            //Card backs
            backText = Content.Load <Texture2D>("backCard");
            backCard = new HUDObjects(backText, new Rectangle(0, 0, 0, 0));

            //Health Assets
            nibText     = Content.Load <Texture2D>("toasternib");
            toasterNib1 = new HUDObjects(nibText, new Rectangle(65, 0, 53, 22));
            toasterNib2 = new HUDObjects(nibText, new Rectangle(65, 0, 53, 22));
            toasterText = Content.Load <Texture2D>("toaster");
            toaster1    = new HUDObjects(toasterText, new Rectangle(0, 50, 125, 275));
            toaster2    = new HUDObjects(toasterText, new Rectangle(0, 450, 125, 275));


            font  = Content.Load <SpriteFont>("Arial");
            font2 = Content.Load <SpriteFont>("cheri");

            //things with textures
            //cards- load all card textures into array here, rename card textures to numbers -card0, card1, card2... cardn
            cardText = new Texture2D[21];
            for (int i = 0; i < 21; i++)
            {
                cardText[i] = Content.Load <Texture2D>("bw2/cards/card" + (i + 1));
            }
            //numbers
            numbers         = new Drawable(Content.Load <Texture2D>("numbers14020"), new Rectangle(0, 0, 140, 20));
            numbers.Rows    = 1;
            numbers.Columns = 10;
            numbers.UnpackSprites();
            //Deck
            deck = new Deck(cardText, numbers);
            string[] allFiles = Directory.GetFiles("..\\..\\..\\..\\..\\..\\Bread Wars Deck Builder\\bin\\Debug");
            foreach (string f in allFiles)
            {
                if (f.Contains(".dat"))
                {
                    deckFiles.Add(f);
                }
            }


            //The players
            player1 = new Player(1, font2, new Vector2(20, 100));
            player2 = new Player(2, font2, new Vector2(830, 100));

            //player array
            players    = new Player[2];
            players[0] = player1;
            players[1] = player2;

            //music assets
            this.title   = Content.Load <Song>("titleEdit2");
            this.game    = Content.Load <SoundEffect>("game");
            this.gameEnd = Content.Load <SoundEffect>("gameOver");
            scream       = Content.Load <SoundEffect>("scream");

            gInstance  = game.CreateInstance();
            geInstance = gameEnd.CreateInstance();
            sInstance  = scream.CreateInstance();

            MediaPlayer.Play(title);
            MediaPlayer.IsRepeating = true;
        }
コード例 #20
0
 public override SoundEffectInstance PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type)
 {
     soundInstance        = sound.CreateInstance();
     soundInstance.Volume = volume * 1f;
     return(soundInstance);
 }
コード例 #21
0
 public Sound(SoundEffectInstance i)
 {
     instance = i;
     restart  = false;
 }
コード例 #22
0
 public static void Track(SoundEffectInstance sound)
 {
 }
コード例 #23
0
        public override void LoadContent()
        {
            switchCamera();

            midTerrain = new Vector3(terrain.terrainWidth / 2, waterLevel, terrain.terrainLength / 2);

            //Create water
            water = new WaterBase(midTerrain, waterLevel, new Vector2(terrain.TerrainWidth, terrain.TerrainLength), baseWaterKey, waveKey, baseWaterRowX, baseWaterRowY, "water", amountWaves, Game);
            Game.Components.Add(water);

            //Adding the models
            Models.AddModels addModels = new Models.AddModels(Game, models, terrain, modelmapKey, Game.Content);

            foreach (Models.LFModel model in models)
            {
                if (!Game.Components.Contains(model))
                {
                    Game.Components.Add(model);
                }
            }

            //Load songs.
            this.smallFireSong       = Game.Assets.Load <Song>("flamesmall");
            this.mediumFireSong      = Game.Assets.Load <Song>("flamemedium");
            this.bigFireSong         = Game.Assets.Load <Song>("flamebig");
            this.songPlayTimeCounter = 0;
            this.currentlyPlaying    = this.smallFireSong;
            MediaPlayer.Play(this.currentlyPlaying);

            //Load Soundeffects.
            SoundEffect s = Game.Assets.Load <SoundEffect>("collectmeteor");

            this.collectMeteorInstance = s.CreateInstance();
            s = Game.Assets.Load <SoundEffect>("treefall");
            this.treeFallInstance = s.CreateInstance();
            s = Game.Assets.Load <SoundEffect>("watersplash");
            this.waterSplash = s.CreateInstance();
            s = Game.Assets.Load <SoundEffect>("burnsomething");
            this.burnSomething = s.CreateInstance();
            s = Game.Assets.Load <SoundEffect>("collectstar");
            this.collectStarInstance = s.CreateInstance();

            foreach (Models.LFModel model in models)
            {
                if (model is Coal)
                {
                    Vector3 pos = model.Position + new Vector3(0, 0.5f, -1.5f);
                    BillBoard.HorizontalBillboarding circle = new BillBoard.HorizontalBillboarding(pos, pos.Y, new Vector2(6), Game.Assets.Load <Texture2D>("circle"), 1, 1, Game.GraphicsDevice, Game.Content, Game);
                    Game.Components.Add(circle);
                }
                else if (model is Meteoriet)
                {
                    Vector3 pos = model.Position + new Vector3(0, 32, 0);
                    BillBoard.VerticalBillBoard beam = new BillBoard.VerticalBillBoard(pos, pos.Y, new Vector2(6, 50), Game.Assets.Load <Texture2D>("lightbeam"), 1, 1, Game.GraphicsDevice, Game.Content, Game);
                    Game.Components.Add(beam);
                }
                else if (model is Tree && this is States.GreenHills.Tutorial)
                {
                    Vector3 pos = model.Position + new Vector3(0, 0.5f, 0f);
                    BillBoard.HorizontalBillboarding circle = new BillBoard.HorizontalBillboarding(pos, pos.Y, new Vector2(7), Game.Assets.Load <Texture2D>("circletree"), 1, 1, Game.GraphicsDevice, Game.Content, Game);
                    Game.Components.Add(circle);
                }
            }

            foreach (Models.LFModel model in models)
            {
                if (model is Meteoriet)
                {
                    Vector3 pos = model.Position + new Vector3(0.5f, 0.5f, 0f);
                    BillBoard.HorizontalBillboarding circle = new BillBoard.HorizontalBillboarding(pos, pos.Y, new Vector2(8), Game.Assets.Load <Texture2D>("circle"), 1, 1, Game.GraphicsDevice, Game.Content, Game);
                    Game.Components.Add(circle);
                }
            }

            // If there is a load file, load the game from that point.
            if (loadName != "")
            {
                loadProgress(loadName);
            }

            //Set the player's position
            player.Position = this.terrain.GetHeightAtPosition(startPosition.X, startPosition.Z, 0);

            //Create the sky
            sky = new Sky(Game, Game.Assets.Load <TextureCube>("sky"));
            Game.Components.Add(sky);
        }
コード例 #24
0
 public Sound(SoundEffect effect)
 {
     curFadeTime = 0;
     this.effect = effect.CreateInstance();
 }
コード例 #25
0
        public override void AI()
        {
            Projectile P = projectile;
            Player     O = Main.player[P.owner];

            Lead = Main.projectile[(int)P.ai[0]];
            if (!Lead.active || Lead.owner != P.owner || Lead.type != mod.ProjectileType("ChargeLead"))
            {
                P.Kill();
                return;
            }

            if (P.numUpdates == 0)
            {
                P.frame++;
            }
            if (P.frame > 1)
            {
                P.frame = 0;
            }

            range    = Max_Range;
            distance = Max_Distance;

            oPos = O.RotatedRelativePoint(O.MountedCenter, true);

            if (Lead != null && Lead.active)
            {
                for (int k = 0; k < range; k++)
                {
                    float   targetrot = (float)Math.Atan2((P.Center.Y - Lead.Center.Y), (P.Center.X - Lead.Center.X));
                    Vector2 tilePos   = Lead.Center + targetrot.ToRotationVector2() * k;
                    int     i         = (int)MathHelper.Clamp(tilePos.X / 16, 0, Main.maxTilesX - 2);
                    int     j         = (int)MathHelper.Clamp(tilePos.Y / 16, 0, Main.maxTilesY - 2);

                    if (Main.tile[i, j] != null && Main.tile[i, j].active() && Main.tileSolid[Main.tile[i, j].type] && !Main.tileSolidTop[Main.tile[i, j].type])
                    {
                        range    = Math.Max(range - 1, 1);
                        distance = Math.Max(distance - 1, 1);
                    }
                    else
                    {
                        range    = Math.Min(range + 1, Max_Range);
                        distance = Math.Min(distance + 1, Max_Distance);
                    }
                }
            }

            if (P.owner == Main.myPlayer)
            {
                P.netUpdate = true;

                Vector2 diff = Main.MouseWorld - oPos;
                diff.Normalize();

                mousePos = oPos + diff * Math.Min(Vector2.Distance(oPos, Main.MouseWorld), range);

                target = null;
                for (int i = 0; i < Main.maxNPCs; i++)
                {
                    if (Main.npc[i].active && Main.npc[i].lifeMax > 5 && !Main.npc[i].dontTakeDamage && !Main.npc[i].friendly)
                    {
                        NPC       npc     = Main.npc[i];
                        Rectangle npcRect = new Rectangle((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height);

                        float point = 0f;
                        if (Vector2.Distance(oPos, npc.Center) < range &&
                            Collision.CheckAABBvLineCollision(npcRect.TopLeft(), npcRect.Size(), oPos, P.Center, P.width, ref point))
                        {
                            range    = Vector2.Distance(oPos, npc.Center);
                            mousePos = oPos + diff * Math.Min(Vector2.Distance(oPos, Main.MouseWorld), range);
                        }

                        bool flag = (Vector2.Distance(oPos, npc.Center) <= range + distance && Vector2.Distance(npc.Center, mousePos) <= distance);

                        if (Main.npc[i].CanBeChasedBy(P, false))
                        {
                            if (target == null || !target.active)
                            {
                                if (flag)
                                {
                                    target = npc;
                                }
                            }
                            else
                            {
                                if (npc != target && flag && Vector2.Distance(npc.Center, mousePos) < Vector2.Distance(target.Center, mousePos))
                                {
                                    target = npc;
                                }

                                if (Vector2.Distance(oPos, target.Center) > range + distance || Vector2.Distance(target.Center, mousePos) > distance)
                                {
                                    target = null;
                                }
                            }
                        }
                    }
                }

                if (!setTargetPos)
                {
                    targetPos    = P.Center;
                    setTargetPos = true;
                    return;
                }
                else if (target != null && target.active)
                {
                    targetPos = target.Center;
                }
                else
                {
                    if (P.numUpdates == 0)
                    {
                        //targetPos = new Vector2(mousePos.X + Main.rand.Next(-30, 31), mousePos.Y + Main.rand.Next(-30, 31));
                        targetPos    = oPos + diff * range;
                        targetPos.X += (float)Main.rand.Next(-30, 31) * (Vector2.Distance(oPos, P.Center) / Max_Range);
                        targetPos.Y += (float)Main.rand.Next(-30, 31) * (Vector2.Distance(oPos, P.Center) / Max_Range);
                    }
                }

                if (P.numUpdates == 0)
                {
                    if (soundDelay <= 0)
                    {
                        if (!soundPlayed)
                        {
                            soundInstance = Main.PlaySound(SoundLoader.customSoundType, (int)O.position.X, (int)O.position.Y, mod.GetSoundSlot(SoundType.Custom, "Sounds/WavebusterStart"));
                            soundPlayed   = true;
                            soundDelay    = 50;
                        }
                        else
                        {
                            if (soundInstance != null)
                            {
                                soundInstance.Stop(true);
                            }
                            soundInstance = Main.PlaySound(SoundLoader.customSoundType, (int)O.position.X, (int)O.position.Y, mod.GetSoundSlot(SoundType.Custom, "Sounds/WavebusterLoop"));
                            soundDelay    = 138;
                        }
                    }
                    else
                    {
                        soundDelay--;
                    }
                    for (int i = 0; i < 3; i++)
                    {
                        ampDest[i] = Main.rand.Next(-30, 31);
                    }
                }

                if (ampSyncCooldown-- <= 0)
                {
                    ampSyncCooldown       = 20;
                    projectile.netUpdate2 = true;
                }
            }

            float speed       = Math.Max(8f, Vector2.Distance(targetPos, P.Center) * 0.025f);
            float targetAngle = (float)Math.Atan2((targetPos.Y - P.Center.Y), (targetPos.X - P.Center.X));

            P.velocity = targetAngle.ToRotationVector2() * speed;

            if (O.controlUseItem)
            {
                P.timeLeft = 10;
            }
            else
            {
                P.Kill();
            }

            if (P.numUpdates == 0)
            {
                for (int i = 0; i < 3; i++)
                {
                    ampDest[i] = Main.rand.Next(-30, 31);
                }
            }

            for (int i = 0; i < 3; i++)
            {
                if (amp[i] < ampDest[i])
                {
                    amp[i] += 3;
                }
                else
                {
                    amp[i] -= 3;
                }
            }
        }
コード例 #26
0
ファイル: Player.cs プロジェクト: Yaumy/FinalRush
        // UPDATE & DRAW

        public void Update(MouseState souris, KeyboardState clavier, List <Wall> walls, List <Bonus> bonus)
        {
            if (Global.Collisions.collision_speed)
            {
                speed = 6;
            }
            else if (Global.Collisions.LowSpeed)
            {
                speed = 2;
            }
            else
            {
                speed = 4;
            }
            GameTime gametime;

            gametime = new GameTime();
            Main.Update(gametime);

            #region Bullets
            if (Keyboard.GetState().IsKeyDown(Keys.Q) && bullets.Count() < 3 && !shot && Global.Handler.ammo_left > 0 && state == "standing")
            {
                shot = true;
                Bullets bullet = new Bullets(Resources.bullet);
                bullet.velocity = 5;
                if (Direction == Direction.Right)
                {
                    bullet.position = new Vector2(Hitbox.X + Hitbox.Width / 2, Hitbox.Y + Hitbox.Height / 3) + new Vector2(bullet.velocity * 5, 0);
                    Old_Dir         = Direction.Right;
                }
                else
                {
                    bullet.position = new Vector2(Hitbox.X, Hitbox.Y + Hitbox.Height / 3) + new Vector2(bullet.velocity * 5, 0);
                    Old_Dir         = Direction.Left;
                }
                bullet.isVisible = true;
                bullets.Add(bullet);
            }
            else
            {
                shot = false;
            }
            foreach (Bullets bullet in bullets)
            {
                if (Old_Dir == Direction.Right)
                {
                    bullet.position.X += bullet.velocity; // va vers la droite
                }
                else
                {
                    bullet.position.X -= bullet.velocity; // va vers la gauche
                }
                // la balle disparait si elle parcourt la distance ou rencontre un obstacle
                if (Vector2.Distance(bullet.position, new Vector2(Hitbox.X, Hitbox.Y)) >= 200)
                {
                    bullet.isVisible = false;
                }
                foreach (Wall wall in walls)
                {
                    if (wall.Hitbox.Intersects(new Rectangle((int)bullet.position.X, (int)bullet.position.Y, 5, 2)))
                    {
                        bullet.isVisible = false;
                    }
                }
            }

            //on retire la balle de la liste si elle disparait
            for (int i = 0; i < bullets.Count; i++)
            {
                if (!bullets[i].isVisible)
                {
                    bullets.RemoveAt(i);
                    i--;
                }
            }

            #endregion

            #region Gravité

            bool gravity = collisions.CollisionDown(Hitbox, walls, this.fallspeed);

            if (!gravity)
            {
                if (collisions.CollisionUp(Hitbox, walls, fallspeed))
                {
                    speedjump = 0;
                }
                if (hasjumped && speedjump > 1)
                {
                    this.Hitbox.Y -= speedjump;
                    speedjump     -= 1;
                }
                else
                {
                    this.Hitbox.Y += this.fallspeed;
                    framecolumn    = 1;
                    state          = "jump";
                }
            }
            else
            {
                if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 4))
                {
                    if (!collisions.CollisionDown(Hitbox, walls, this.fallspeed - 2))
                    {
                        this.Hitbox.Y += 2;
                    }
                    else
                    {
                        this.Hitbox.Y++;
                    }
                }
                if (state == "jump")
                {
                    state = "standing";
                }
            }

            #endregion

            #region Couteau

            if (clavier.IsKeyDown(Keys.D) && state == "standing")
            {
                SoundEffectInstance couteau_sound_instance = Resources.couteau.CreateInstance();
                couteau_sound_instance.Play();
                framecolumn   = 1;
                compteur      = 1;
                state         = "cut";
                Hitbox.Width  = 50;
                Hitbox.Y     -= 16;
                Hitbox.Height = 55;
            }

            #endregion

            #region Déplacements

            //Le sprite et la hitbox accroupi quand le personnage est baissé ou coincé sous un mur
            if (clavier.IsKeyDown(Keys.Down))
            {
                Hitbox.Width  = 35;
                Hitbox.Height = 25;
                state         = "squat";
            }
            //Celui debout quand on se relève et qu'il y a suffisament de place
            if (clavier.IsKeyUp(Keys.Down) && Hitbox.Height == 25 && !collisions.CollisionUp(new Rectangle(Hitbox.X, Hitbox.Y - 15, Hitbox.Width, Hitbox.Height), walls, speed))
            {
                state         = "standing";
                Hitbox.Width  = 36;
                Hitbox.Height = 40;

                if (collisions.CollisionDown(new Rectangle(Hitbox.X, Hitbox.Y, Hitbox.Width, Hitbox.Height), walls, speed))
                {
                    Hitbox.Y = Hitbox.Y - 15;
                }
            }

            // Tir Marco
            if (clavier.IsKeyDown(Keys.Q) && state == "standing") //On tire avec "Q" et debout uniquement
            {
                if (state != "shoot")
                {
                    framecolumn = 1;
                    compteur    = 1;
                }

                if (Global.Handler.ammo_left > 0)
                {
                    fire_sound_instance.Play();
                    state = "shoot";
                }
                else
                {
                    vide_sound_instance.Play();
                }
            }
            if (state == "cut")
            {
                if (compteur % 2 == 0)
                {
                    if (framecolumn < 8)
                    {
                        framecolumn++;
                        compteur++;
                    }
                    else
                    {
                        framecolumn = 1;
                        if (clavier.IsKeyUp(Keys.D))
                        {
                            state         = "standing";
                            Hitbox.Width  = 36;
                            Hitbox.Height = 40;
                            Hitbox.Y     += 15;
                        }
                    }
                }
                else
                {
                    compteur++;
                }
            }
            else
            if (state == "shoot")
            {
                if (compteur % 4 == 0)
                {
                    if (framecolumn < 10)
                    {
                        Hitbox.Width  = 52;
                        Hitbox.Height = 40;
                        framecolumn++;
                    }
                    else
                    {
                        state         = "standing";
                        Hitbox.Width  = 36;
                        Hitbox.Height = 40;
                        framecolumn   = 1;
                        compteur      = 1;
                    }
                }
                compteur++;
            }
            else
            if (clavier.IsKeyDown(Keys.Right) && state != "squat")                  // Permet de bouger à droite
            {
                // Droite si pas de collisions et si le perso est encore sur l'écran
                if (!collisions.CollisionRight(Hitbox, walls, speed))
                {
                    this.Hitbox.X += speed;
                    this.Direction = Direction.Right;
                    if (collisions.CollisionDown(Hitbox, walls, speed))
                    {
                        this.Animate(1, 15, 2);
                    }
                }
                else
                {
                    framecolumn = 1;
                    compteur    = 1;
                }
            }

            else if (clavier.IsKeyDown(Keys.Left) && state != "squat")            // Permet de bouger à gauche
            {
                // Gauche si pas de collisions et si le perso est encore sur l'écran
                if (!collisions.CollisionLeft(Hitbox, walls, this.speed) && Hitbox.X > 0)
                {
                    this.Hitbox.X -= this.speed;
                    this.Direction = Direction.Left;
                    if (collisions.CollisionDown(Hitbox, walls, this.speed))
                    {
                        this.Animate(1, 15, 2);
                    }
                }
                else
                {
                    framecolumn = 1;
                    compteur    = 1;
                }
            }

            if (clavier.IsKeyDown(Keys.Right) && state == "squat")          // Permet de bouger à droite accroupi
            {
                // Droite si pas de collisions et si le perso est encore sur l'écran
                if (!collisions.CollisionRight(Hitbox, walls, this.speed))
                {
                    this.Hitbox.X += this.speed - 1;
                    this.Direction = Direction.Right;
                    if (collisions.CollisionDown(Hitbox, walls, this.speed))
                    {
                        this.Animate(2, 8, 2);
                    }
                }
                else
                {
                    framecolumn = 1;
                    compteur    = 1;
                }
            }

            else if (clavier.IsKeyDown(Keys.Left) && state == "squat")    // Permet de bouger à gauche accroupi
            {
                // Gauche si pas de collisions et si le perso est encore sur l'écran
                if (!collisions.CollisionLeft(Hitbox, walls, this.speed) && Hitbox.X > 0)
                {
                    this.Hitbox.X -= this.speed - 1;
                    this.Direction = Direction.Left;
                    if (collisions.CollisionDown(Hitbox, walls, this.speed))
                    {
                        this.Animate(2, 8, 2);
                    }
                }
                else
                {
                    framecolumn = 1;
                    compteur    = 1;
                }
            }
            #endregion

            #region Déplacements test
            else if (clavier.IsKeyDown(Keys.A))
            {
                Hitbox = new Rectangle(50, 370, Hitbox.Width, Hitbox.Height);
            }
            else if (clavier.IsKeyDown(Keys.N))
            {
                Hitbox = new Rectangle(4500, 100, Hitbox.Width, Hitbox.Height);
            }
            #endregion

            #region Saut

            if (clavier.IsKeyDown(Keys.Space))
            {
                if (compteursaut == 1)
                {
                    spaceIsPressed = false;
                }
                else
                {
                    spaceIsPressed = true;
                    compteursaut++;
                }
            }
            else
            {
                compteursaut = 0;
            }

            if (clavier.IsKeyDown(Keys.Space) && spaceIsPressed && !hasjumped && gravity && state == "standing")
            {
                framecolumn = 1;
                if (!collisions.CollisionUp(Hitbox, walls, this.fallspeed))
                {
                    SoundEffectInstance saut_instance = Resources.saut.CreateInstance();
                    saut_instance.Play();
                    this.Hitbox.Y -= 12;
                    speedjump      = 12;
                }
                hasjumped = true;
                state     = "jump";
            }

            if (hasjumped == true && collisions.CollisionDown(Hitbox, walls, this.fallspeed) == true && state != "squat")
            {
                hasjumped = false;
                state     = "standing";
            }

            #endregion

            #region Effets et animation

            if (clavier.IsKeyUp(Keys.Right) && clavier.IsKeyUp(Keys.Left) && state == "standing")              // Ici c'est une partie de l'animation
            {
                framecolumn = 1;
            }

            switch (Direction)
            {
            case Direction.Left:
                effect = SpriteEffects.FlipHorizontally;
                break;

            case Direction.Right:
                effect = SpriteEffects.None;
                break;

            default:
                break;
            }
            #endregion

            #region Chute

            dead = Hitbox.Y > 480;

            if (dead)
            {
                Hitbox = new Rectangle(50, 350, Hitbox.Width, Hitbox.Height);
            }

            #endregion
            if (Global.Collisions.accu > 0)
            {
                change = false;
            }
            if (!change && Global.Collisions.accu > 0)
            {
                if (marco_color.G < 20)
                {
                    up = true;
                }
                if (marco_color.G > 235)
                {
                    up = false;
                }
                if (up)
                {
                    marco_color.G += 15;
                    marco_color.B += 15;
                }
                else
                {
                    marco_color.G -= 15;
                    marco_color.B -= 15;
                }
                Global.Collisions.accu--;
            }
            else
            {
                marco_color = new Color(254, 255, 255, 255);
            }
        }
コード例 #27
0
 public override void LoadContent()
 {
     jumpSound    = game.Content.Load <SoundEffect>(@"Sound/Effects/jump");
     jumpSoundIns = jumpSound.CreateInstance();
     base.LoadContent();
 }
コード例 #28
0
ファイル: ContentChest.cs プロジェクト: Rixium/Conveyer
        public void Load()
        {
            // Loads all of our assets.

            for (int i = 0; i < conveyer.Length; i++)
            {
                conveyer[i] = Content.Load <Texture2D>("Conveyer/" + (i + 1));
            }

            floor[0] = Content.Load <Texture2D>("Floor/1");

            logo       = Content.Load <Texture2D>("Logo/logo");
            buttons[0] = Content.Load <Texture2D>("Buttons/startButton");
            buttons[1] = Content.Load <Texture2D>("Buttons/quitButton");

            scoreFont2  = Content.Load <SpriteFont>("Fonts/scoreFont2");
            defaultFont = Content.Load <SpriteFont>("Fonts/defaultFont");
            smallFont   = Content.Load <SpriteFont>("Fonts/smallFont");
            scoreFont   = Content.Load <SpriteFont>("Fonts/scoreFont");

            buttonSound  = Content.Load <SoundEffect>("Sounds/buttonSound");
            wrong        = Content.Load <SoundEffect>("Sounds/wrong");
            correct      = Content.Load <SoundEffect>("Sounds/correct");
            machineBreak = Content.Load <SoundEffect>("Sounds/break");
            zap          = Content.Load <SoundEffect>("Sounds/zp");
            fix          = Content.Load <SoundEffect>("Sounds/fix");
            heartbeat    = Content.Load <SoundEffect>("Sounds/heartbeat");

            pixel = Content.Load <Texture2D>("UI/pixel");
            head  = Content.Load <Texture2D>("Worker/Head/head1");
            body  = Content.Load <Texture2D>("Worker/Body/body");


            for (int i = 1; i <= 2; i++)
            {
                headWalk[i - 1] = Content.Load <Texture2D>("Worker/Head/head" + (i));
            }

            for (int i = 0; i < 7; i++)
            {
                walkLegs[i] = Content.Load <Texture2D>("Worker/Legs/walk" + (i + 1));
            }

            idleLegs = Content.Load <Texture2D>("Worker/Legs/idleLegs");
            for (int i = 0; i < 2; i++)
            {
                bodyCarry[i] = Content.Load <Texture2D>("Worker/Body/bodyWalk" + (i + 1));
            }

            fragileItems.Add("Cups", Content.Load <Texture2D>("Items/Fragile/item1"));
            fragileItems.Add("Vase", Content.Load <Texture2D>("Items/Fragile/item2"));
            fragileItems.Add("Shades", Content.Load <Texture2D>("Items/Fragile/item3"));

            bigItems.Add("Teddy", Content.Load <Texture2D>("Items/Big/item1"));
            bigItems.Add("Spade", Content.Load <Texture2D>("Items/Big/item2"));
            bigItems.Add("Drill", Content.Load <Texture2D>("Items/Big/item3"));
            bigItems.Add("Television", Content.Load <Texture2D>("Items/Big/item4"));


            smallItems.Add("Book", Content.Load <Texture2D>("Items/Small/item1"));
            smallItems.Add("Oil", Content.Load <Texture2D>("Items/Small/item2"));
            smallItems.Add("Reader", Content.Load <Texture2D>("Items/Small/item3"));
            smallItems.Add("Jewellery", Content.Load <Texture2D>("Items/Small/item4"));

            orderBar    = Content.Load <Texture2D>("UI/orderBar");
            orderHolder = Content.Load <Texture2D>("UI/order");
            orderSlip   = Content.Load <Texture2D>("UI/orderSlip");

            bigBox     = Content.Load <Texture2D>("Boxes/bigBox");
            smallBox   = Content.Load <Texture2D>("Boxes/smallBox");
            fragileBox = Content.Load <Texture2D>("Boxes/fragileBox");

            bigBoxPackaged     = Content.Load <Texture2D>("Boxes/bigBoxPackaged");
            smallBoxPackaged   = Content.Load <Texture2D>("Boxes/smallBoxPackaged");
            fragileBoxPackaged = Content.Load <Texture2D>("Boxes/fragileBoxPackaged");

            theme = Content.Load <Song>("Music/theme");

            tick = Content.Load <Texture2D>("UI/tick");

            lowerUI       = Content.Load <Texture2D>("UI/lowerUI");
            boxSpawner[0] = Content.Load <Texture2D>("Conveyer/boxSpawner1");

            for (int i = 0; i < sparks.Length; i++)
            {
                sparks[i] = Content.Load <Texture2D>("SparkAnimation/spark" + (i + 1));
            }
            heartBeatInstance = ContentChest.Instance.heartbeat.CreateInstance();

            // order Sounds

            wrongBoxSounds   = new SoundEffect[2];
            noOrderSounds    = new SoundEffect[4];
            droppedBoxSounds = new SoundEffect[1];
            fixBeltSounds    = new SoundEffect[2];

            for (int i = 0; i < fixBeltSounds.Length; i++)
            {
                fixBeltSounds[i] = Content.Load <SoundEffect>("Sounds/fixBelt/" + (i + 1));
            }

            for (int i = 0; i < wrongBoxSounds.Length; i++)
            {
                wrongBoxSounds[i] = Content.Load <SoundEffect>("Sounds/wrongBox/" + (i + 1));
            }

            for (int i = 0; i < noOrderSounds.Length; i++)
            {
                noOrderSounds[i] = Content.Load <SoundEffect>("Sounds/noOrder/" + (i + 1));
            }

            for (int i = 0; i < droppedBoxSounds.Length; i++)
            {
                droppedBoxSounds[i] = Content.Load <SoundEffect>("Sounds/boxFloor/" + (i + 1));
            }
        }
コード例 #29
0
ファイル: Audio.cs プロジェクト: Nagraal/Tactile-Engine
        private static SoundEffectInstance get_music(string cue_name)
        {
            SoundEffect         song = null;
            SoundEffectInstance music = null;
            int intro_start = 0, loop_start = -1, loop_length = -1;

            NVorbis.VorbisReader vorbis = null;
            try
            {
                try
                {
                    Stream cue_stream = TitleContainer.OpenStream(@"Content\Audio\BGM\" + cue_name + ".ogg");


#if __ANDROID__
                    MemoryStream stream = new MemoryStream();
                    cue_stream.CopyTo(stream);
                    vorbis = new NVorbis.VorbisReader(stream, cue_name, true);
#else
                    vorbis = new NVorbis.VorbisReader(cue_stream, cue_name, true);
#endif
                    get_loop_data(vorbis, out intro_start, out loop_start, out loop_length);


                    // If the loop points are set past the end of the song, don't play
                    if (vorbis.TotalSamples < loop_start || vorbis.TotalSamples < loop_start + loop_length)
                    {
#if DEBUG
                        throw new IndexOutOfRangeException("Loop points are set past the end of the song");
#endif
#if __ANDROID__
                        cue_stream.Dispose();
                        vorbis.Dispose();
#else
                        vorbis.Dispose();
#endif
                        throw new FileNotFoundException();
                    }
#if __ANDROID__
                    cue_stream.Dispose();
#endif
                }
                catch (FileNotFoundException ex)
                {
                    throw;
                }
#if __ANDROID__
                catch (Java.IO.FileNotFoundException e)
                {
                    throw;
                }
#endif
            }
            // If loaded as an ogg failed, try loading as a SoundEffect
            catch (FileNotFoundException ex)
            {
                intro_start = 0;
                loop_start  = -1;
                loop_length = -1;
                song        = Global.Content.Load <SoundEffect>(@"Audio/" + cue_name);
            }

            // If the file is an ogg file and was found and initialized successfully
            if (vorbis != null)
            {
                music = get_vorbis_music(vorbis, cue_name,
                                         intro_start, loop_start, loop_length);
            }
            else
            {
                music = get_effect_music(song, cue_name, intro_start, loop_start, loop_length);
            }

            if (music != null)
            {
                music.IsLooped = true;
            }
#if !__ANDROID__
            if (song != null)
            {
                song.Dispose();
            }
#endif
            return(music);
        }
コード例 #30
0
 public override void Update(float t)
 {
     base.Update(t);
     if (!this.IsActive)
     {
         return;
     }
     if (!this.IsInCredits)
     {
         if (this.waveRender == null)
         {
             this.traceDownEffect.Play();
             this.speech                  = this.os.content.Load <SoundEffect>("SFX/Ending/EndingSpeech");
             this.waveRender              = new WaveformRenderer("Content/SFX/Ending/EndingSpeech.wav");
             this.speechinstance          = this.speech.CreateInstance();
             this.speechinstance.IsLooped = false;
             this.CreditsData             = Utils.readEntireFile("Content/Post/CreditsData.txt").Split(Utils.newlineDelim, StringSplitOptions.None);
             MusicManager.stop();
         }
         if (this.speechinstance.State == SoundState.Playing)
         {
             this.elapsedTime += t;
             if ((double)this.elapsedTime > this.speech.Duration.TotalSeconds)
             {
                 this.RollCredits();
             }
             else
             {
                 this.SpeechTextTimer += t;
                 if (this.SpeechTextIndex < this.BitSpeechText.Length)
                 {
                     if ((int)this.BitSpeechText[this.SpeechTextIndex] == 35)
                     {
                         if ((double)this.SpeechTextTimer >= 1.0)
                         {
                             --this.SpeechTextTimer;
                             ++this.SpeechTextIndex;
                         }
                     }
                     else if ((int)this.BitSpeechText[this.SpeechTextIndex] == 37)
                     {
                         if ((double)this.SpeechTextTimer >= 0.5)
                         {
                             this.SpeechTextTimer -= 0.5f;
                             ++this.SpeechTextIndex;
                         }
                     }
                     else if ((double)this.SpeechTextTimer >= 0.0500000007450581)
                     {
                         this.SpeechTextTimer -= 0.05f;
                         ++this.SpeechTextIndex;
                     }
                 }
             }
         }
         else
         {
             this.speechinstance.Play();
         }
     }
     else
     {
         this.elapsedTime += t;
         if ((double)this.elapsedTime > (double)this.HacknetTitleFreezeTime)
         {
             float num = Math.Min(1f, (float)(((double)this.elapsedTime - 10.0) / 8.0));
             this.creditsScroll -= t * this.creditsPixelsScrollPerSecond * num;
         }
     }
 }
コード例 #31
0
 public override SoundEffectInstance PlaySound(ref SoundEffectInstance soundInstance, float volume, float pan, SoundType type)
 {
     soundInstance       = sound.CreateInstance();
     soundInstance.Pitch = MusicMaker.isHigh?1:(MusicMaker.isLow?-1:0);
     return(soundInstance);
 }
コード例 #32
0
 public SAMEffectWrapper(SAMSoundPlayer player, ILifetimeObject owner, SoundEffect effect)
 {
     Player   = player;
     Owner    = owner;
     Instance = effect.CreateInstance();
 }
コード例 #33
0
        //in Terraria.Main.PlaySound before checking type to play sound add
        //  if (SoundLoader.PlayModSound(type, num, num2, num3)) { return; }
        internal static bool PlayModSound(int type, int style, float volume, float pan, ref SoundEffectInstance soundEffectInstance)
        {
            SoundType soundType;

            switch (type)
            {
            case 2:
                soundType = SoundType.Item;
                break;

            case 3:
                soundType = SoundType.NPCHit;
                break;

            case 4:
                soundType = SoundType.NPCKilled;
                break;

            case customSoundType:
                soundType = SoundType.Custom;
                break;

            default:
                return(false);
            }
            if (!modSounds[soundType].ContainsKey(style))
            {
                return(false);
            }
            soundEffectInstance = modSounds[soundType][style].PlaySound(ref GetSoundInstanceArray(soundType)[style], volume, pan, soundType);
            return(true);
        }
コード例 #34
0
ファイル: LoopedSample.cs プロジェクト: Dahrkael/CoRe
 public LoopedSample(string Filename)
 {
     se = Cache.SE(Filename);
     sei = se.CreateInstance();
     sei.Volume = Sample.DefaultVolume;
 }