- Timestamp:
- 2013-07-04 19:44:40 (10 years ago)
- Location:
- 2013/27/TeemuM/Game/Game
- Files:
-
- 14 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/27/TeemuM/Game/Game/Game/AudioPlayer.cs
r4446 r4448 10 10 class AudioPlayer 11 11 { 12 private int updateInterval;13 12 private G game; 13 private int lastStartIndex = -1; 14 14 15 Timer playerUpdater;15 private Timer tick = new Timer(); 16 16 17 List<String> types = new List<String>();18 List<int> max = new List<int>();17 private List<String> types = new List<String>(); 18 private List<int> max = new List<int>(); 19 19 20 public AudioPlayer(G game, int uInterval)20 public AudioPlayer(G game, int cInterval) 21 21 { 22 22 this.game = game; 23 this.updateInterval = uInterval; 23 tick.Interval = cInterval; 24 } 24 25 25 playerUpdater.Interval = updateInterval; 26 playerUpdater.Timeout += delegate() { }; 26 public bool RegisterType(String type, int maxValue) 27 { 28 if (maxValue < 0 || type == "") 29 return false; 30 31 types.Add(type); 32 max.Add(maxValue); 33 34 return true; 27 35 } 36 37 public bool Play(String type, bool force) 38 { 39 for (int i = 0; i < types.Count; i++) 40 if (types[i].ToLower() == type.ToLower()) 41 { 42 if (force) 43 game.MediaPlayer.Stop(); 44 45 tick.Timeout += delegate() { Player(types[i], max[i]); }; 46 tick.Start(); 47 Player(types[i], max[i]); 48 return true; 49 } 50 51 return false; 52 } 53 54 public void Stop() 55 { 56 game.MediaPlayer.Stop(); 57 } 58 59 public void PlayOne(String resource, bool stopAfterThis) 60 { 61 if (stopAfterThis) 62 tick.Stop(); 63 64 game.MediaPlayer.Stop(); 65 game.MediaPlayer.Play(resource); 66 } 67 68 public void SetCheckInterval(double interval) 69 { 70 tick.Interval = interval; 71 } 72 73 private void Player(string type, int max) 74 { 75 if (!game.MediaPlayer.IsPlaying) 76 { 77 lastStartIndex = RandomGen.NextInt(0, max + 1); 78 game.MediaPlayer.Play(type + lastStartIndex); 79 } 80 } 81 82 #region Console 83 84 private void Print(String txt) 85 { 86 game.MessageDisplay.Add(txt); 87 } 88 89 public bool Console(String command) 90 { 91 if (command.Length < 0) 92 return false; 93 94 String[] commands = command.Split(' '); 95 if (commands[0] == "play") 96 { 97 if (commands.Length < 2) 98 return false; 99 100 bool force = true; 101 if (commands.Length > 2) 102 if (commands[2] == "!force") 103 force = true; 104 105 if (Play(commands[1], force)) 106 Print("Playing " + commands[1] + " #" + lastStartIndex); 107 else 108 Print("Type \"" + commands[1] + "\" is not registered"); 109 } 110 else if (commands[0] == "playone") 111 { 112 if (commands.Length < 2) 113 return false; 114 115 bool stop = false; 116 if (commands.Length > 2) 117 if (commands[2] == "stop") 118 stop = true; 119 120 PlayOne(commands[1], stop); 121 Print("Playing " + commands[1]); 122 } 123 else if (commands[0] == "register") 124 { 125 if (commands.Length < 2) 126 return false; 127 128 if (commands[1] == "list") 129 { 130 if (types.Count > 0) 131 { 132 Print("Registered types: "); 133 foreach (string type in types) 134 Print(type); 135 } 136 else { Print("No registered types"); } 137 } 138 } 139 else 140 { 141 return false; 142 } 143 144 return true; 145 } 146 147 #endregion 28 148 } -
2013/27/TeemuM/Game/Game/Game/Game.cs
r4446 r4448 9 9 public class G : PhysicsGame 10 10 { 11 private AudioPlayer audio; 12 public G() 13 { 14 audio = new AudioPlayer(this, 3); 15 16 audio.RegisterType("Background", 4); 17 audio.RegisterType("EasterEgg", 0); 18 audio.RegisterType("Enemyspawn", 0); 19 audio.RegisterType("GameOver", 0); 20 audio.RegisterType("MenuMusic", 0); 21 audio.RegisterType("RandomSound", 0); 22 audio.RegisterType("ZombieBite", 0); 23 audio.RegisterType("Zombiesound", 2); 24 } 25 26 11 27 public static G game; 12 28 private IntMeter scoreboard; … … 24 40 { 25 41 MultiSelectWindow menu = new MultiSelectWindow("TESTMODE", "Developer tools", "Start this thing", "Perks", "Get me out of here"); 26 menu.DefaultCancel = -0;42 menu.DefaultCancel = 0; 27 43 menu.AddItemHandler(0, delegate() { MessageDisplay.Add("Starting game..."); StartGame(); DeveloperCommand(); }); 28 44 menu.AddItemHandler(1, CharacterMenu); … … 30 46 menu.AddItemHandler(3, Exit); 31 47 Add(menu); 32 33 48 } 34 49 … … 52 67 MessageDisplay.Add("-$" + int.Parse(commands[2])); 53 68 } 69 } 70 else if (commands[0] == "audio") 71 { 72 audio.Console(p.InputBox.Text.Substring(6)); 54 73 } 55 74 else if (commands[0] == "score") -
2013/27/TeemuM/Game/Game/Game/Game.csproj.Debug.cachefile
r4443 r4448 4 4 Content\Zombie3.xnb 5 5 Content\Zombie4.xnb 6 Content\ DemonSpawn.xnb7 Content\ GameM1.xnb8 Content\ GameM2.xnb9 Content\ GameM3.xnb10 Content\ GameM4.xnb11 Content\ GameMTroll1.xnb12 Content\GameOver .xnb13 Content\MenuMusic .xnb14 Content\Randomsound H.xnb15 Content\ SpesialEasterEgg.xnb16 Content\Zombie Bite.xnb17 Content\Zombie Create.xnb18 Content\Zombiesou d1.xnb19 Content\Zombiesou d2.xnb20 Content\ DemonSpawn.wma21 Content\ GameM1.wma22 Content\ GameM2.wma23 Content\ GameM3.wma24 Content\ GameM4.wma25 Content\ GameMTroll1.wma26 Content\GameOver .wma27 Content\MenuMusic .wma28 Content\Randomsound H.wma29 Content\ SpesialEasterEgg.wma30 Content\Zombie Bite.wma31 Content\Zombie Create.wma32 Content\Zombiesou d1.wma33 Content\Zombiesou d2.wma6 Content\Background0.xnb 7 Content\Background1.xnb 8 Content\Background2.xnb 9 Content\Background3.xnb 10 Content\Background4.xnb 11 Content\Enemyspawn0.xnb 12 Content\GameOver0.xnb 13 Content\MenuMusic0.xnb 14 Content\Randomsound0.xnb 15 Content\EasterEgg0.xnb 16 Content\Zombiebite0.xnb 17 Content\Zombiesound0.xnb 18 Content\Zombiesound1.xnb 19 Content\Zombiesound2.xnb 20 Content\Background0.wma 21 Content\Background1.wma 22 Content\Background2.wma 23 Content\Background3.wma 24 Content\Background4.wma 25 Content\Enemyspawn0.wma 26 Content\GameOver0.wma 27 Content\MenuMusic0.wma 28 Content\Randomsound0.wma 29 Content\EasterEgg0.wma 30 Content\Zombiebite0.wma 31 Content\Zombiesound0.wma 32 Content\Zombiesound1.wma 33 Content\Zombiesound2.wma -
2013/27/TeemuM/Game/Game/GameContent/GameContent.contentproj
r4445 r4448 75 75 </ItemGroup> 76 76 <ItemGroup> 77 <Compile Include=" RandomsoundH.mp3">78 <Name> RandomsoundH</Name>77 <Compile Include="Background0.mp3"> 78 <Name>Background0</Name> 79 79 <Importer>Mp3Importer</Importer> 80 80 <Processor>SongProcessor</Processor> 81 81 </Compile> 82 <Compile Include="SpesialEasterEgg.mp3"> 83 <Name>SpesialEasterEgg</Name> 82 <Compile Include="Background1.mp3"> 83 <Name>Background1</Name> 84 <Importer>Mp3Importer</Importer> 85 <Processor>SongProcessor</Processor> 86 </Compile> 87 <Compile Include="Background2.mp3"> 88 <Name>Background2</Name> 89 <Importer>Mp3Importer</Importer> 90 <Processor>SongProcessor</Processor> 91 </Compile> 92 <Compile Include="Background3.mp3"> 93 <Name>Background3</Name> 94 <Importer>Mp3Importer</Importer> 95 <Processor>SongProcessor</Processor> 96 </Compile> 97 <Compile Include="Background4.mp3"> 98 <Name>Background4</Name> 99 <Importer>Mp3Importer</Importer> 100 <Processor>SongProcessor</Processor> 101 </Compile> 102 <Compile Include="Enemyspawn0.mp3"> 103 <Name>Enemyspawn0</Name> 104 <Importer>Mp3Importer</Importer> 105 <Processor>SongProcessor</Processor> 106 </Compile> 107 <Compile Include="GameOver0.mp3"> 108 <Name>GameOver0</Name> 109 <Importer>Mp3Importer</Importer> 110 <Processor>SongProcessor</Processor> 111 </Compile> 112 <Compile Include="MenuMusic0.mp3"> 113 <Name>MenuMusic0</Name> 114 <Importer>Mp3Importer</Importer> 115 <Processor>SongProcessor</Processor> 116 </Compile> 117 <Compile Include="Randomsound0.mp3"> 118 <Name>Randomsound0</Name> 119 <Importer>Mp3Importer</Importer> 120 <Processor>SongProcessor</Processor> 121 </Compile> 122 <Compile Include="EasterEgg0.mp3"> 123 <Name>EasterEgg0</Name> 124 <Importer>Mp3Importer</Importer> 125 <Processor>SongProcessor</Processor> 126 </Compile> 127 <Compile Include="Zombiebite0.mp3"> 128 <Name>Zombiebite0</Name> 129 <Importer>Mp3Importer</Importer> 130 <Processor>SongProcessor</Processor> 131 </Compile> 132 <Compile Include="Zombiesound0.mp3"> 133 <Name>Zombiesound0</Name> 134 <Importer>Mp3Importer</Importer> 135 <Processor>SongProcessor</Processor> 136 </Compile> 137 <Compile Include="Zombiesound1.mp3"> 138 <Name>Zombiesound1</Name> 139 <Importer>Mp3Importer</Importer> 140 <Processor>SongProcessor</Processor> 141 </Compile> 142 <Compile Include="Zombiesound2.mp3"> 143 <Name>Zombiesound2</Name> 84 144 <Importer>Mp3Importer</Importer> 85 145 <Processor>SongProcessor</Processor>
Note: See TracChangeset
for help on using the changeset viewer.