Changeset 2557
- Timestamp:
- 2011-08-04 14:58:53 (12 years ago)
- Location:
- 2011/31/MaijaH
- Files:
-
- 5 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/31/MaijaH/Smiley/Smiley/Peli.cs
r2523 r2557 10 10 { 11 11 12 12 13 13 const double nopeus = 200; 14 14 const double hyppyNopeus = 1000; … … 17 17 PlatformCharacter pelaaja1; 18 18 19 List<Label> valikonKohdat; 20 21 IntMeter elamaLaskuri; 22 IntMeter pisteLaskuri; 23 24 int pelaajanElamat = 3; 25 26 Image liikkuvatasoKuva = LoadImage("liikkuvataso"); 27 Image kolikkoKuva = LoadImage("kolikko"); 28 Image pilviKuva = LoadImage("Pilvi"); 19 29 Image maaliKuva = LoadImage("Maali"); 20 30 Image pelaajanKuva = LoadImage("Smiley"); … … 28 38 29 39 public override void Begin() 30 { 40 { 31 41 SeuraavaKentta(kenttaNro); 32 Gravity = new Vector(0, -1000); 33 34 lisaaNappaimet(); 35 36 Camera.Follow(pelaaja1); 37 Camera.ZoomFactor = 1.2; 38 Camera.StayInLevel = true; 39 } 42 Valikko(); 43 } 44 45 void Valikko() 46 { 47 ClearAll(); 48 valikonKohdat = new List<Label>(); 49 50 Label kohta1 = new Label("Aloita uusi peli"); 51 kohta1.Position = new Vector(0, 40); 52 valikonKohdat.Add(kohta1); 53 54 Label kohta2 = new Label("Lopeta"); 55 kohta2.Position = new Vector(0, -40); 56 valikonKohdat.Add(kohta2); 57 58 foreach (Label valikonKohta in valikonKohdat) 59 { 60 Add(valikonKohta); 61 } 62 63 Mouse.ListenOn(kohta1, MouseButton.Left, ButtonState.Pressed, AloitaPeli, null); 64 Mouse.ListenOn(kohta2, MouseButton.Left, ButtonState.Pressed, Exit, null); 65 66 Mouse.IsCursorVisible = true; 67 Mouse.ListenMovement(1.0, ValikossaLiikkuminen, null); 68 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, ""); 69 70 } 71 void ValikossaLiikkuminen(AnalogState hiirenTila) 72 { 73 foreach (Label kohta in valikonKohdat) 74 { 75 if (Mouse.IsCursorOn(kohta)) 76 { 77 kohta.TextColor = Color.Red; 78 } 79 else 80 { 81 kohta.TextColor = Color.Black; 82 } 83 84 } 85 } 86 void AloitaPeli() 87 { 88 ClearAll(); 89 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Valikko, "Palaa valikkoon"); 90 } 91 40 92 41 93 void luoKentta(string kenttaTiedostonNimi) … … 52 104 KentanAlaReuna = Level.CreateBottomBorder(); 53 105 Level.Background.CreateGradient(Color.SkyBlue, Color.SkyBlue); 106 LuoLaskuri(); 107 LuoElamaLaskuri(); 108 Camera.Follow(pelaaja1); 109 Camera.ZoomFactor = 1.2; 110 Camera.StayInLevel = true; 111 Gravity = new Vector(0, -1000); 112 lisaaNappaimet(); 54 113 } 55 114 void lisaaNakymatonTaso(Vector paikka, double leveys, double korkeus) … … 66 125 PhysicsObject taso = PhysicsObject.CreateStaticObject(leveys, korkeus); 67 126 taso.Position = paikka; 68 taso.Color = Color. Green;127 taso.Color = Color.White; 69 128 taso.Tag = "taso"; 70 129 Add(taso); 71 } 72 130 taso.Image = pilviKuva; 131 } 132 73 133 void lisaaLiikkuvaTaso(Vector paikka, double leveys, double korkeus) 74 134 { 75 //PhysicsObject taso = PhysicsObject.CreateStaticObject(3*leveys, korkeus);135 //PhysicsObject taso = PhysicsObject.CreateStaticObject(3*leveys, korkeus); 76 136 PhysicsObject taso = new PhysicsObject(3 * leveys, korkeus); 77 137 taso.Mass = 99999999999999999; … … 80 140 taso.IgnoresGravity = true; 81 141 taso.Position = paikka; 82 taso.Color = Color. Red;142 taso.Color = Color.Blue; 83 143 Add(taso); 84 AddCollisionHandler (taso, KasitteleTasonTormays); 85 } 86 void KasitteleTasonTormays (PhysicsObject taso, PhysicsObject kohde) 144 AddCollisionHandler(taso, KasitteleTasonTormays); 145 taso.Image = liikkuvatasoKuva; 146 } 147 void KasitteleTasonTormays(PhysicsObject taso, PhysicsObject kohde) 87 148 { 88 149 if (kohde.Tag.ToString() == "nakymaton" || kohde.Tag.ToString() == "taso") … … 97 158 void lisaaTahti(Vector paikka, double leveys, double korkeus) 98 159 { 99 PhysicsObject tahti = PhysicsObject.CreateStaticObject(leveys , korkeus);160 PhysicsObject tahti = PhysicsObject.CreateStaticObject(leveys/2, korkeus/2); 100 161 tahti.IgnoresCollisionResponse = true; 101 162 tahti.Position = paikka; 102 tahti.Image = tahtiKuva;163 tahti.Image = kolikkoKuva; 103 164 tahti.Tag = "tahti"; 104 165 Add(tahti); 166 105 167 } 106 168 … … 145 207 if (kohde.Tag.ToString() == "tahti") 146 208 { 147 maaliAani.Play();209 pisteLaskuri.Value++; 148 210 kohde.Destroy(); 149 211 } … … 151 213 { 152 214 hahmo.Destroy(); 153 } 154 } 155 156 215 kohde.Destroy(); 216 pelaajanElamat--; 217 Begin(); 218 } 219 if (pelaajanElamat == 0) 220 { 221 Exit(); 222 } 223 if (kohde.Tag.ToString() == "maali") 224 { 225 SeuraavaKentta(++kenttaNro); 226 } 227 228 } 157 229 158 230 void SeuraavaKentta(int kenttaNro) … … 163 235 else if (kenttaNro == 2) luoKentta("kentta2"); 164 236 else if (kenttaNro == 3) luoKentta("kentta3"); 165 166 } 237 } 167 238 void luoMaali(Vector paikka, double leveys, double korkeus) 168 239 { … … 174 245 maali.Image = maaliKuva; 175 246 } 176 177 } 247 248 249 void LuoLaskuri() 250 { 251 pisteLaskuri = new IntMeter(0); 252 253 Label pisteNaytto = new Label(); 254 pisteNaytto.X = Screen.Left + 100; 255 pisteNaytto.Y = Screen.Top - 100; 256 pisteNaytto.TextColor = Color.Blue; 257 258 pisteNaytto.BindTo(pisteLaskuri); 259 Add(pisteNaytto); 260 261 Label pisteTeksti = new Label("Kolikoita: "); 262 pisteTeksti.X = Screen.Left + 50; 263 pisteTeksti.Y = Screen.Top - 100; 264 pisteTeksti.TextColor = Color.Blue; 265 Add(pisteTeksti); 266 267 } 268 void laskuriYlarajassa(int arvo) 269 { 270 MessageDisplay.TextColor = Color.White; 271 MessageDisplay.Add("Pelaaja 1 voitti pelin."); 272 } 273 void LuoElamaLaskuri() 274 { 275 elamaLaskuri = new IntMeter(pelaajanElamat); 276 277 Label pisteNaytto = new Label(); 278 pisteNaytto.X = Screen.Left + 100; 279 pisteNaytto.Y = Screen.Top - 50; 280 pisteNaytto.TextColor = Color.Blue; 281 282 pisteNaytto.BindTo(elamaLaskuri); 283 Add(pisteNaytto); 284 285 Label pisteTeksti = new Label("Elämiä: "); 286 pisteTeksti.X = Screen.Left + 50; 287 pisteTeksti.Y = Screen.Top - 50; 288 pisteTeksti.TextColor = Color.Blue; 289 Add(pisteTeksti); 290 } 291 292 } 178 293 179 294 -
2011/31/MaijaH/Smiley/SmileyContent/SmileyContent.contentproj
r2523 r2557 83 83 </Compile> 84 84 </ItemGroup> 85 <ItemGroup> 86 <Compile Include="Pilvi.png"> 87 <Name>Pilvi</Name> 88 <Importer>TextureImporter</Importer> 89 <Processor>TextureProcessor</Processor> 90 </Compile> 91 </ItemGroup> 92 <ItemGroup> 93 <Compile Include="kolikko.png"> 94 <Name>kolikko</Name> 95 <Importer>TextureImporter</Importer> 96 <Processor>TextureProcessor</Processor> 97 </Compile> 98 </ItemGroup> 99 <ItemGroup> 100 <Compile Include="liikkuvataso.png"> 101 <Name>liikkuvataso</Name> 102 <Importer>TextureImporter</Importer> 103 <Processor>TextureProcessor</Processor> 104 </Compile> 105 </ItemGroup> 106 <ItemGroup> 107 <Compile Include="kentta2.txt"> 108 <Name>kentta2</Name> 109 <Importer>TextFileImporter</Importer> 110 <Processor>TextFileContentProcessor</Processor> 111 </Compile> 112 </ItemGroup> 113 <ItemGroup> 114 <Compile Include="kentta3.txt"> 115 <Name>kentta3</Name> 116 <Importer>TextFileImporter</Importer> 117 <Processor>TextFileContentProcessor</Processor> 118 </Compile> 119 </ItemGroup> 85 120 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 86 121 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
2011/31/MaijaH/Smiley/SmileyContent/kentta1.txt
r2523 r2557 3 3 4 4 5 6 ## ## m 5 * * * 6 ## ## m n 7 7 8 8 … … 12 12 ## 13 13 * 14 * ## 14 * ## * * 15 15 * n m ### 16 N * * ### T16 N * * ### * T 17 17 ######## ############# ########
Note: See TracChangeset
for help on using the changeset viewer.