- Timestamp:
- 2010-06-10 14:57:42 (13 years ago)
- Location:
- 2010/23/laemkaup/Tasohyppelypeli
- Files:
-
- 4 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/23/laemkaup/Tasohyppelypeli/Content/Content.contentproj
r670 r690 68 68 </Compile> 69 69 </ItemGroup> 70 <ItemGroup> 71 <Compile Include="karkki.png"> 72 <Name>karkki</Name> 73 <Importer>TextureImporter</Importer> 74 <Processor>TextureProcessor</Processor> 75 </Compile> 76 </ItemGroup> 77 <ItemGroup> 78 <Compile Include="hammaspeikko.png"> 79 <Name>hammaspeikko</Name> 80 <Importer>TextureImporter</Importer> 81 <Processor>TextureProcessor</Processor> 82 </Compile> 83 </ItemGroup> 70 84 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 71 85 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
2010/23/laemkaup/Tasohyppelypeli/Peli.cs
r670 r690 8 8 9 9 namespace Tasohyppelypeli 10 11 10 { 12 11 13 class Tasohyppely : PhysicsGame14 {12 class Tasohyppely : PhysicsGame 13 { 15 14 const int ruudunLeveys = 30; 16 15 const int ruudunKorkeus = 30; 17 16 18 19 17 18 20 19 const double nopeus = 200; 21 20 const double hyppyVoima = 4000; 22 23 IntMeter pisteLaskuri; 21 22 24 23 ValueDisplay pisteNaytto; 25 24 … … 28 27 int kenttaNro; // monesko kenttä on menossa 29 28 30 29 IntMeter pistelaskuri; 30 31 31 32 protected override void Begin() 32 33 { … … 34 35 Level.Width = 1500; 35 36 Level.Height = 1000; 36 37 // Luodaan pistelaskuri38 pisteLaskuri = new IntMeter(0);39 40 // luodaan pistelaskunäyttö41 pisteNaytto = new ValueDisplay();42 pisteNaytto.Text = "Pisteitä: ";43 pisteNaytto.X = Screen.RightSafe - 250;44 pisteNaytto.Y = Screen.TopSafe - 50;45 pisteNaytto.BindTo(pisteLaskuri);46 Add(pisteNaytto); // lisätään peliin47 48 37 // Zoomataan lähemmäksi 49 38 Camera.ZoomFactor = 2.0; … … 54 43 MessageDisplay.Add("Kerää kaikki porkkanat"); 55 44 } 56 45 void laskuriYlarajassa(int arvo) 46 { 47 MessageDisplay.TextColor = Color.Black; 48 MessageDisplay.Add(" Onnea! Voitit hammaspeikot!"); 49 } 57 50 void seuraavaKentta() 58 51 { 59 52 ClearAll(); 60 pisteLaskuri.Reset();53 61 54 62 55 kenttaNro += 1; // lisätään kenttänumeroa yhdellä … … 68 61 luoKentta(); 69 62 lisaaNappaimet(); 63 lisaaLaskurit(); 70 64 Camera.Follow(pelaaja1); 65 } 66 67 private void lisaaLaskurit() 68 { 69 pistelaskuri = new IntMeter(0); 70 ValueDisplay pisteNaytto = new ValueDisplay(); 71 pisteNaytto.Text = "Porkkanoita: "; 72 pisteNaytto.X = Screen.Right - 100; 73 pisteNaytto.Y = Screen.Top - 20; 74 pisteNaytto.ValueColor = Color.Green; 75 pisteNaytto.TextColor = Color.Green; 76 pisteNaytto.BindTo(pistelaskuri); 77 Add(pisteNaytto); 78 pistelaskuri.MaxValue = 20; 79 pistelaskuri.UpperLimit += laskuriYlarajassa; 80 71 81 } 72 82 … … 76 86 merkit['x'] = LuoPalikka; 77 87 merkit['p'] = LuoPorkkana; 88 merkit['k'] = LuoKarkki; 78 89 79 90 char[,] ruudut = Tiles.ReadFromFile("kenttä.txt"); … … 107 118 Level.CreateBorders(); 108 119 109 }120 } 110 121 void lisaaTaso(double x, double y, double koko) 111 122 { 112 PhysicsObject taso2 = PhysicsObject.CreateStaticObject ( koko,30);113 taso2.Color = Color.Yellow;114 taso2.X = x;115 taso2.Y = y;116 Add(taso2);123 PhysicsObject taso2 = PhysicsObject.CreateStaticObject(koko, 30); 124 taso2.Color = Color.Yellow; 125 taso2.X = x; 126 taso2.Y = y; 127 Add(taso2); 117 128 } 118 129 … … 132 143 porkkana.Image = LoadImage("porkkana"); 133 144 porkkana.Tag = "porkkana"; 145 134 146 return porkkana; 135 147 136 148 } 137 138 139 140 141 149 PhysicsObject LuoKarkki() 150 { 151 PhysicsObject karkki = PhysicsObject.CreateStaticObject(30.0, 30.0); 152 karkki.Image = LoadImage("karkki"); 153 karkki.Tag = "karkki"; 154 155 return karkki; 156 } 157 158 159 160 161 142 162 143 163 void lisaaPelaajat() … … 149 169 pelaaja1.Y = Level.Bottom + 120; 150 170 151 AddCollisionHandler(pelaaja1, osuiMaaliin);171 AddCollisionHandler(pelaaja1, pelaajaOsui); 152 172 153 173 Add(pelaaja1); … … 196 216 } 197 217 198 void osuiMaaliin(PhysicsObject collidingObject, PhysicsObject otherObject)218 void pelaajaOsui(PhysicsObject collidingObject, PhysicsObject otherObject) 199 219 { 200 220 if (otherObject.Tag.ToString() == "maali") 201 221 { 202 222 this.PlaySound("maali"); 203 int edellisenKentanPisteet = piste Laskuri.Value;223 int edellisenKentanPisteet = pistelaskuri.Value; 204 224 seuraavaKentta(); 205 225 MessageDisplay.Add("Pääsit läpi kentän " + kenttaNro + ". Pisteitä: " + edellisenKentanPisteet); … … 207 227 if (otherObject.Tag.ToString() == "porkkana") 208 228 { 209 MessageDisplay.Add("porkkana"); 210 } 211 212 } 229 pistelaskuri.Value++; // ++ tarkoittaa että arvoa lisätään yhdellä 230 otherObject.Destroy(); 231 } 232 if (otherObject.Tag.ToString() == "karkki") 233 { 234 otherObject.Destroy(); 235 LuoHammaspeikko(); 236 } 237 } 238 239 void LuoHammaspeikko() 240 { 241 PhysicsObject hammaspeikko = new PhysicsObject(120, 120, Shapes.Circle); 242 hammaspeikko.Image = LoadImage("hammaspeikko"); 243 hammaspeikko.Tag = "hammaspeikko"; 244 hammaspeikko.Position = new Vector(RandomGen.NextDouble(Level.Left, Level.Right), 245 RandomGen.NextDouble(Level.Bottom, Level.Top)); 246 247 // TODO : miten hammaspeikot liikkumaan ? 248 249 AddCollisionHandler(hammaspeikko, osuttiinHammaspeikkoon); 250 Add(hammaspeikko); 251 } 252 253 void osuttiinHammaspeikkoon(PhysicsObject peikko, PhysicsObject kukaOsui) 254 { 255 if (kukaOsui is PlatformCharacter) 256 { 257 Explosion rajahdys = new Explosion(1000); 258 rajahdys.Position = pelaaja1.Position; 259 260 rajahdys.Speed = 500.0; 261 rajahdys.Force = 10000; 262 rajahdys.ShockwaveColor = Color.Red; 263 Add(rajahdys); 264 MessageDisplay.Add("Osuit hammaspeikkoon, hävisit pelin!"); 265 pelaaja1.Destroy(); 266 } 267 268 } 213 269 } 270 214 271 } -
2010/23/laemkaup/Tasohyppelypeli/kenttä.txt
r670 r690 2 2 3 3 4 p4 k p k 5 5 xxxxxxxxxxxx 6 6 7 7 8 8 9 p10 xxxxxxxxxx p11 12 xxx 9 k p 10 xxxxxxxxxx k p 11 k p xxxxxxxxxxxxx 12 xxx k k k p 13 13 xxxxxxxxxxxxxx 14 pp15 xxxxxxxxxx xxxx p16 xxxxxxxxxxxxx17 p 14 k p k k p 15 xxxxxxxxxx xxxx k p 16 xxxxxxxxx 17 p k k p 18 18 xxxxxxxxx xxxxxxxxxxx 19 19 20 20 21 p p21 k p k p k 22 22 xxxxxxxxxx xxxxxxxxxxxxxx 23 23 24 p pp24 k p k p k k p 25 25 xxxxxxxxx xxxxxxxxxxx xxxxxxx 26 26 … … 28 28 29 29 30 p pp30 k p k p k k p k k p k p 31 31 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Note: See TracChangeset
for help on using the changeset viewer.