- Timestamp:
- 2013-06-12 15:04:45 (10 years ago)
- Location:
- 2013/24/JoonasE/Mastermind/Mastermind
- Files:
-
- 30 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2013/24/JoonasE/Mastermind/Mastermind/Mastermind/Mastermind.cs
r4071 r4103 7 7 using Jypeli.Widgets; 8 8 9 public class Maali : PhysicsObject 10 { 11 public bool pelaajaMaalissa = false; 12 public Maali(double leveys, double korkeus) 13 : base(leveys, korkeus) 14 { 15 IsUpdated = true; 16 } 17 18 public List<GameObject> PelaajatLahella(List<GameObject> oliot, double maxEtaisyys) 19 { 20 List<GameObject> pelaajatLahella = oliot.FindAll(x => x is Pelaaja && Vector.Distance(x.Position, this.Position) < maxEtaisyys); 21 return pelaajatLahella; 22 } 23 24 public override void Update(Time time) 25 { 26 27 base.Update(time); 28 } 29 } 30 31 public class Pelaaja : PlatformCharacter 32 { 33 public bool onkoMaalissa = false; 34 public Vector aloituspaikka; 35 36 public Pelaaja(double leveys, double korkeus) 37 : base(leveys, korkeus) 38 { 39 } 40 } 41 9 42 public class Mastermind : PhysicsGame 10 43 { 44 void PääValikko() 45 { 46 MultiSelectWindow alkuValikko = new MultiSelectWindow("", "Aloita", "Lopeta"); 47 alkuValikko.AddItemHandler(0, AloitaAlusta); 48 alkuValikko.AddItemHandler(1, Exit); 49 50 alkuValikko.Buttons[0].Image = nappula; 51 alkuValikko.Buttons[1].Image = nappula; 52 53 alkuValikko.Image = tausta; 54 Add(alkuValikko); 55 } 56 57 int kenttaNro = 1; 58 11 59 const double nopeus = 200; 12 60 const double hyppyNopeus = 750; 13 61 const int RUUDUN_KOKO = 40; 14 62 15 PlatformCharacter pelaaja1; 16 PlatformCharacter pelaaja2; 63 List<Pelaaja> pelaajat; 64 Pelaaja pelaaja1; 65 Pelaaja pelaaja2; 66 67 bool pelaaja1Maalissa = false; 68 bool pelaaja2Maalissa = false; 17 69 18 70 Animation pelaajanKuva2; 19 71 Animation pelaajanKuva; 72 Animation maaliAnim; 20 73 Image tahtiKuva = LoadImage("tahti"); 21 74 Image maa = LoadImage("block"); 75 Image vaara = LoadImage("Danger block"); 76 Image tausta = LoadImage("Tausta"); 77 Image pääTausta = LoadImage("Taustakuva"); 78 Image nappula = LoadImage("nappula"); 79 Image taustuliini = LoadImage("taustablur"); 80 22 81 23 82 SoundEffect maaliAani = LoadSoundEffect("maali"); … … 25 84 public override void Begin() 26 85 { 27 pelaajanKuva2 = LoadAnimation("stillblue"); 86 IsFullScreen = true; 87 88 Level.Background.Image = pääTausta; 89 PääValikko(); 90 91 MediaPlayer.Play("musa"); 92 MediaPlayer.IsRepeating = true; 93 94 95 96 97 } 98 99 void AloitaAlusta() 100 { 101 ClearAll(); 102 //Gravity = new Vector(0, -1000); 103 pelaajat = new List<Pelaaja>(); 104 105 SeuraavaKentta(); 106 107 // Camera.StayInLevel = true; 108 Camera.Follow(pelaaja1, pelaaja2);//, pelaaja2); 109 } 110 111 112 void SeuraavaKentta() 113 { 114 ClearAll(); 115 pelaajat.Clear(); pelaajanKuva2 = LoadAnimation("stillblue"); 28 116 pelaajanKuva = LoadAnimation("still"); 117 maaliAnim = LoadAnimation("maali"); 29 118 30 119 Gravity = new Vector(0, -1000); 31 120 32 LuoKentta(); 121 if (kenttaNro == 1) LuoKentta("kentta1"); 122 else if (kenttaNro == 2) LuoKentta("kentta2"); 123 else if (kenttaNro == 3) LuoKentta("kentta3"); 124 else if (kenttaNro == 4) LuoKentta("kentta4"); 125 else if (kenttaNro == 5) LuoKentta("kentta5"); 126 else if (kenttaNro == 6) LuoKentta("kentta6"); 127 else if (kenttaNro == 7) LuoKentta("kentta7"); 128 else if (kenttaNro == 8) LuoKentta("kentta8"); 129 else if (kenttaNro == 9) LuoKentta("kentta9"); 130 else if (kenttaNro == 10) LuoKentta("kentta10"); 131 else if (kenttaNro == 11) LuoKentta("kentta11"); 132 else if (kenttaNro == 12) LuoKentta("kentta12"); 133 else if (kenttaNro == 13) LuoKentta("kentta13"); 134 else if (kenttaNro == 14) LuoKentta("kentta14"); 135 else if (kenttaNro == 15) LuoKentta("kentta15"); 136 else if (kenttaNro == 16) LuoKentta("kentta16"); 137 else if (kenttaNro > 16) Exit(); 33 138 LisaaNappaimet(); 34 35 139 Camera.Follow(pelaaja1, pelaaja2); 36 37 } 38 39 void LuoKentta() 40 { 41 TileMap kentta = TileMap.FromLevelAsset("kentta1"); 140 141 } 142 143 void LuoKentta(string kenttaTiedostonNimi) 144 { 145 pelaaja1 = new Pelaaja(1, 1); 146 pelaaja2 = new Pelaaja(1, 1); 147 pelaajat.Add(pelaaja1); 148 pelaajat.Add(pelaaja2); 149 150 TileMap kentta = TileMap.FromLevelAsset(kenttaTiedostonNimi); 42 151 kentta.SetTileMethod('#', LisaaTaso); 43 152 kentta.SetTileMethod('*', LisaaTahti); 44 pelaaja1 = new PlatformCharacter(1, 1); 45 pelaaja2 = new PlatformCharacter(1, 1); 46 kentta.SetTileMethod('A', LisaaPelaaja); 47 kentta.SetTileMethod('B', LisaaPelaaja2); 153 kentta.SetTileMethod('V', LisaaVTaso); 154 kentta.SetTileMethod('G', LisaaMaali, pelaaja1); 155 kentta.SetTileMethod('g', LisaaMaali, pelaaja2); 156 kentta.SetTileMethod('A', LisaaPelaaja, pelaaja1, pelaajanKuva); 157 kentta.SetTileMethod('B', LisaaPelaaja, pelaaja2, pelaajanKuva2); 48 158 kentta.Execute(RUUDUN_KOKO, RUUDUN_KOKO); 49 159 Level.CreateBorders(); 50 Level.Background.CreateGradient(Color.BloodRed, Color.Blue); 160 Level.Background.Image = taustuliini; 161 Level.Background.TileToLevel(); 162 Level.BackgroundColor = Color.Gray; 163 51 164 } 52 165 … … 59 172 Add(taso); 60 173 } 174 61 175 62 176 void LisaaTahti(Vector paikka, double leveys, double korkeus) … … 70 184 } 71 185 72 void LisaaPelaaja(Vector paikka, double leveys, double korkeus) //, PlatformCharacter pelaaja, Animation paikallaan, Animation kavely) 73 { 74 pelaaja1 = new PlatformCharacter(leveys*0.8, korkeus*0.8); 75 pelaaja1.Position = paikka; 76 pelaaja1.Mass = 4.0; 77 pelaaja1.Animation = pelaajanKuva; 78 pelaaja1.Animation.Start(); 79 AddCollisionHandler(pelaaja1, "tahti", TormaaTahteen); 80 Add(pelaaja1); 81 } 82 83 void LisaaPelaaja2(Vector paikka, double leveys, double korkeus) //, PlatformCharacter pelaaja, Animation paikallaan, Animation kavely) 84 { 85 pelaaja2 = new PlatformCharacter(leveys * 0.8, korkeus * 0.8); 86 pelaaja2.Position = paikka; 87 pelaaja2.Mass = 4.0; 88 pelaaja2.Animation = pelaajanKuva2; 89 pelaaja2.Animation.Start(); 90 AddCollisionHandler(pelaaja2, "tahti", TormaaTahteen); 91 Add(pelaaja2); 92 } 93 186 void LisaaMaali(Vector paikka, double leveys, double korkeus, Pelaaja pelaaja) 187 { 188 Maali maali = new Maali(leveys, korkeus); 189 maali.MakeStatic(); 190 maali.Position = paikka; 191 maali.Animation = maaliAnim; 192 maali.Animation.Start(); 193 maali.Tag = "maali"; 194 Timer ajastin = new Timer(); 195 ajastin.Interval = 0.5; 196 ajastin.Timeout += 197 delegate 198 { 199 List<GameObject> pelaajat = maali.PelaajatLahella(GetObjects(x => true), leveys * 2); 200 if (pelaajat.Count == 0) 201 { 202 pelaaja.onkoMaalissa = false; 203 return; 204 } 205 Pelaaja p = (Pelaaja)pelaajat[0]; 206 if (p == pelaaja) 207 { 208 pelaaja.onkoMaalissa = true; 209 if (this.pelaajat.TrueForAll(x => x.onkoMaalissa)) 210 { 211 MessageDisplay.Add("Kenttä selvitetty!"); 212 ajastin.Stop(); 213 kenttaNro++; 214 SeuraavaKentta(); 215 216 return; 217 } 218 } 219 }; 220 ajastin.Start(); 221 Add(maali); 222 223 } 224 225 void LisaaPelaaja(Vector paikka, double leveys, double korkeus, Pelaaja pelaaja, Animation animaatio) //, PlatformCharacter pelaaja, Animation paikallaan, Animation kavely) 226 { 227 pelaaja.Size = new Vector(leveys * 0.8, korkeus * 0.8); 228 pelaaja.aloituspaikka = paikka; 229 pelaaja.Position = paikka; 230 pelaaja.Mass = 4.0; 231 pelaaja.Animation = animaatio; 232 pelaaja.Animation.Start(); 233 AddCollisionHandler<Pelaaja, PhysicsObject>(pelaaja, "vaara", TormaaVaaraan); 234 AddCollisionHandler(pelaaja, "maali", maaliinPaasy); 235 Add(pelaaja); 236 } 237 238 //void LisaaPelaaja2(Vector paikka, double leveys, double korkeus) //, PlatformCharacter pelaaja, Animation paikallaan, Animation kavely) 239 //{ 240 // pelaaja2 = new Pelaaja(leveys * 0.8, korkeus * 0.8); 241 // pelaaja2.Position = paikka; 242 // pelaaja2.Mass = 4.0; 243 // pelaaja2.Animation = pelaajanKuva2; 244 // pelaaja2.Animation.Start(); 245 // AddCollisionHandler<Pelaaja, PhysicsObject>(pelaaja2, "tahti", TormaaTahteen); 246 // AddCollisionHandler(pelaaja2, "maali", maaliinPaasy); 247 // Add(pelaaja2); 248 //} 249 250 void LisaaVTaso(Vector paikka, double leveys, double korkeus) 251 { 252 PhysicsObject vtaso = PhysicsObject.CreateStaticObject(leveys, korkeus); 253 vtaso.Position = paikka; 254 vtaso.Color = Color.Purple; 255 vtaso.Image = vaara; 256 vtaso.Tag = "vaara"; 257 Add(vtaso); 258 259 } 260 261 void maaliinPaasy(PhysicsObject tormaaja, PhysicsObject kohde) 262 { 263 if (tormaaja == pelaaja1) 264 { 265 pelaaja1Maalissa = true; 266 } 267 if (tormaaja == pelaaja2) 268 { 269 pelaaja2Maalissa = true; 270 } 271 if (pelaaja1Maalissa == true && pelaaja2Maalissa == true) 272 { 273 //MessageDisplay.Add("Selvitit kentän!"); 274 } 275 276 } 277 278 94 279 95 280 void LisaaNappaimet() 96 281 { 97 282 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 98 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 99 Keyboard.Listen(Key.P, ButtonState.Pressed, Pause, "Pysäytys!!!"); 283 Keyboard.Listen(Key.Escape, ButtonState.Pressed, VäliValikko, "Valikko"); 100 284 101 285 Keyboard.Listen(Key.Left, ButtonState.Down, Liikuta, "Liikkuu vasemmalle", pelaaja1, -nopeus); … … 116 300 } 117 301 118 void Liikuta(P latformCharacterhahmo, double nopeus)302 void Liikuta(Pelaaja hahmo, double nopeus) 119 303 { 120 304 hahmo.Walk(nopeus); 121 305 } 122 306 123 void Hyppaa(P latformCharacterhahmo, double nopeus)307 void Hyppaa(Pelaaja hahmo, double nopeus) 124 308 { 125 309 hahmo.Jump(nopeus); 126 310 } 127 311 128 void TormaaTahteen(PhysicsObject hahmo, PhysicsObject tahti) 129 { 130 maaliAani.Play(); 131 MessageDisplay.Add("öhnäsit öhnösti"); 132 tahti.Destroy(); 312 void TormaaVaaraan(Pelaaja pelaaja, PhysicsObject vtaso) 313 { 314 //AloitaAlusta(); 315 pelaajat.ForEach(x => x.Position = x.aloituspaikka); 316 MessageDisplay.Add("Yritä uudestaan!"); 317 318 } 319 320 void VäliValikko() 321 { 322 MultiSelectWindow väliValikko = new MultiSelectWindow("Välivalikko", "Jatka", "Aloita alusta", "Lopeta"); 323 väliValikko.Image = LoadImage("norsu"); 324 //alkuValikko.AddItemHandler(0, AloitaAlusta); 325 väliValikko.AddItemHandler(1, AloitaAlusta); 326 väliValikko.AddItemHandler(2, PääValikko); 327 328 väliValikko.Buttons[0].Image = nappula; 329 väliValikko.Buttons[1].Image = nappula; 330 väliValikko.Buttons[2].Image = nappula; 331 332 väliValikko.Image = tausta; 333 Add(väliValikko); 133 334 } 134 335 } -
2013/24/JoonasE/Mastermind/Mastermind/MastermindContent/MastermindContent.contentproj
r4071 r4103 46 46 </ItemGroup> 47 47 <ItemGroup> 48 <Compile Include="maali.wav">49 <Name>maali</Name>50 <Importer>WavImporter</Importer>51 <Processor>SoundEffectProcessor</Processor>52 </Compile>53 48 <Compile Include="norsu.png"> 54 49 <Name>norsu</Name> … … 91 86 <Importer>AnimationImporter</Importer> 92 87 <Processor>AnimationContentProcessor</Processor> 88 </Compile> 89 </ItemGroup> 90 <ItemGroup> 91 <Compile Include="maali.anim"> 92 <Name>maali</Name> 93 <Importer>AnimationImporter</Importer> 94 <Processor>AnimationContentProcessor</Processor> 95 </Compile> 96 </ItemGroup> 97 <ItemGroup> 98 <Compile Include="kentta2.txt"> 99 <Name>kentta2</Name> 100 <Importer>TextFileImporter</Importer> 101 <Processor>TextFileContentProcessor</Processor> 102 </Compile> 103 </ItemGroup> 104 <ItemGroup> 105 <Compile Include="kentta10.txt"> 106 <Name>kentta10</Name> 107 <Importer>TextFileImporter</Importer> 108 <Processor>TextFileContentProcessor</Processor> 109 </Compile> 110 <Compile Include="kentta11.txt"> 111 <Name>kentta11</Name> 112 <Importer>TextFileImporter</Importer> 113 <Processor>TextFileContentProcessor</Processor> 114 </Compile> 115 <Compile Include="kentta12.txt"> 116 <Name>kentta12</Name> 117 <Importer>TextFileImporter</Importer> 118 <Processor>TextFileContentProcessor</Processor> 119 </Compile> 120 <Compile Include="kentta13.txt"> 121 <Name>kentta13</Name> 122 <Importer>TextFileImporter</Importer> 123 <Processor>TextFileContentProcessor</Processor> 124 </Compile> 125 <Compile Include="kentta14.txt"> 126 <Name>kentta14</Name> 127 <Importer>TextFileImporter</Importer> 128 <Processor>TextFileContentProcessor</Processor> 129 </Compile> 130 <Compile Include="kentta15.txt"> 131 <Name>kentta15</Name> 132 <Importer>TextFileImporter</Importer> 133 <Processor>TextFileContentProcessor</Processor> 134 </Compile> 135 <Compile Include="kentta16.txt"> 136 <Name>kentta16</Name> 137 <Importer>TextFileImporter</Importer> 138 <Processor>TextFileContentProcessor</Processor> 139 </Compile> 140 <Compile Include="kentta3.txt"> 141 <Name>kentta3</Name> 142 <Importer>TextFileImporter</Importer> 143 <Processor>TextFileContentProcessor</Processor> 144 </Compile> 145 <Compile Include="kentta4.txt"> 146 <Name>kentta4</Name> 147 <Importer>TextFileImporter</Importer> 148 <Processor>TextFileContentProcessor</Processor> 149 </Compile> 150 <Compile Include="kentta5.txt"> 151 <Name>kentta5</Name> 152 <Importer>TextFileImporter</Importer> 153 <Processor>TextFileContentProcessor</Processor> 154 </Compile> 155 <Compile Include="kentta6.txt"> 156 <Name>kentta6</Name> 157 <Importer>TextFileImporter</Importer> 158 <Processor>TextFileContentProcessor</Processor> 159 </Compile> 160 <Compile Include="kentta7.txt"> 161 <Name>kentta7</Name> 162 <Importer>TextFileImporter</Importer> 163 <Processor>TextFileContentProcessor</Processor> 164 </Compile> 165 <Compile Include="kentta8.txt"> 166 <Name>kentta8</Name> 167 <Importer>TextFileImporter</Importer> 168 <Processor>TextFileContentProcessor</Processor> 169 </Compile> 170 <Compile Include="kentta9.txt"> 171 <Name>kentta9</Name> 172 <Importer>TextFileImporter</Importer> 173 <Processor>TextFileContentProcessor</Processor> 174 </Compile> 175 </ItemGroup> 176 <ItemGroup> 177 <Compile Include="nappula.png"> 178 <Name>nappula</Name> 179 <Importer>TextureImporter</Importer> 180 <Processor>TextureProcessor</Processor> 181 </Compile> 182 <Compile Include="Tausta.png"> 183 <Name>Tausta</Name> 184 <Importer>TextureImporter</Importer> 185 <Processor>TextureProcessor</Processor> 186 </Compile> 187 <Compile Include="Taustakuva.png"> 188 <Name>Taustakuva</Name> 189 <Importer>TextureImporter</Importer> 190 <Processor>TextureProcessor</Processor> 191 </Compile> 192 </ItemGroup> 193 <ItemGroup> 194 <Compile Include="musa.mp3"> 195 <Name>musa</Name> 196 <Importer>Mp3Importer</Importer> 197 <Processor>SongProcessor</Processor> 198 </Compile> 199 </ItemGroup> 200 <ItemGroup> 201 <Compile Include="taustablur.png"> 202 <Name>taustablur</Name> 203 <Importer>TextureImporter</Importer> 204 <Processor>TextureProcessor</Processor> 93 205 </Compile> 94 206 </ItemGroup> -
2013/24/JoonasE/Mastermind/Mastermind/MastermindContent/kentta1.txt
r4071 r4103 1 ####################################################################################### 2 # # # 3 # # # # 4 # # # # # # # # 5 # B #### # # # # # # 6 ####################################################################################### 7 # ### # # # # # 8 # # # # # # 9 # # # ##### # 10 # A # # # # # 11 ####################################################################################### 1 ########################## 2 # # 3 # # # 4 #B # g # 5 ########################## 6 # # # 7 # # # 8 #A # G # 9 ##########################
Note: See TracChangeset
for help on using the changeset viewer.