- Timestamp:
- 2010-07-29 14:52:37 (13 years ago)
- Location:
- 2010/30/nilaiton
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/30/nilaiton/Tasohyppely1/Peli.cs
r1374 r1408 3 3 using Jypeli.Widgets; 4 4 using Jypeli.Assets; 5 using Jypeli.Effects; 5 6 6 7 … … 14 15 PlatformCharacter pelaaja1; 15 16 PhysicsObject maali; 17 IntMeter pisteLaskuri; 18 GameObject[] alkupisteet = new GameObject[10]; 19 GameObject[] loppupisteet = new GameObject[10]; 20 21 ExplosionSystem rajahdys; 22 16 23 17 24 protected override void Begin() 18 25 { 26 rajahdys = new ExplosionSystem(LoadImage("tahti"), 300); 27 Add(rajahdys); 28 19 29 Gravity = new Vector(0, -1000); 20 LuoMaali();30 //LuoMaali(); 21 31 luoKentta1(); 22 32 lisaaNappaimet(); 23 AddCollisionHandler(pelaaja1, KasittelePallonTormays);24 33 25 34 Camera.Follow(pelaaja1); … … 29 38 30 39 void luoKentta1() 31 { 32 Level.CreateBorders(); 40 { 41 MessageDisplay.TextColor = Color.White; 42 MessageDisplay.X = Screen.Left + 1000; 43 MessageDisplay.Y = Screen.Top -100; 44 45 46 MessageDisplay.Add("Taso 1"); 47 48 49 50 51 LuoLaskuri(); 33 52 //Level.Background.CreateGradient(Color.White, Color.SkyBlue); 34 53 Level.Background.CreateStars(); 35 54 36 37 lisaaTasoPaikkaan(100, 141); 38 lisaaTasoPaikkaan(-50, -250); 39 lisaaTasoPaikkaan(170, -325); 40 lisaaTasoPaikkaan(220, -170); 41 lisaaTasoPaikkaan(87, -50); 42 lisaaTasoPaikkaan(-100, 30); 43 lisaaTasoPaikkaan(300, 30); 44 lisaaTasoPaikkaan(-270, -186); 45 lisaaTasoPaikkaan(-415, -115); 46 lisaaTasoPaikkaan(-350, -350); 47 48 49 lisaaPelaajat(); 50 } 51 void luoKentta2() 52 { 53 ClearAll(); 54 55 56 //Level.Background.CreateGradient(Color.White, Color.SkyBlue); 57 Level.Background.CreateStars(); 58 59 TileMap ruudut = TileMap.FromFile("kentta2.txt"); 55 TileMap ruudut = TileMap.FromFile("kentta1.txt"); 60 56 61 57 ruudut['-'] = lisaaTaso; 62 58 ruudut['M'] = LuoMaaliTileMap; 63 59 ruudut['X'] = lisaaPelaajatTileMap; 64 60 //ruudut['V'] = LuoVihollinen; 61 ruudut['0'] = LuoReitti0; 62 ruudut['1'] = LuoReitti1; 63 ruudut['2'] = LuoReitti2; 64 ruudut['3'] = LuoReitti3; 65 ruudut['4'] = LuoReitti4; 65 66 Gravity = new Vector(0, -1000); 66 67 67 68 ruudut.Insert(ruudunLeveys, ruudunKorkeus); 68 69 69 70 71 70 for (int i = 0; i < 10; i++) 71 { 72 if (alkupisteet[i] != null) 73 { 74 75 PhysicsObject vihollinen = LuoVihollinen(i); 76 Add(vihollinen); 77 } 78 } 79 } 80 void luoKentta2() 81 { 82 ClearAll(); 83 LuoLaskuri(); 84 //Level.Background.CreateGradient(Color.White, Color.SkyBlue); 85 Level.Background.CreateStars(); 86 87 TileMap ruudut = TileMap.FromFile("kentta2.txt"); 88 89 ruudut['-'] = lisaaTaso; 90 ruudut['M'] = LuoMaaliTileMap; 91 ruudut['X'] = lisaaPelaajatTileMap; 92 //ruudut['V'] = LuoVihollinen; 93 ruudut['0'] = LuoReitti0; 94 ruudut['1'] = LuoReitti1; 95 ruudut['2'] = LuoReitti2; 96 ruudut['3'] = LuoReitti3; 97 ruudut['4'] = LuoReitti4; 98 Gravity = new Vector(0, -1000); 99 100 ruudut.Insert(ruudunLeveys, ruudunKorkeus); 101 102 for ( int i = 0; i < 10; i++) 103 { 104 if (alkupisteet[i] != null) 105 { 106 107 PhysicsObject vihollinen = LuoVihollinen(i); 108 Add(vihollinen); 109 } 110 } 111 72 112 Camera.Follow(pelaaja1); 73 113 Camera.ZoomFactor = 2.0; 74 114 Camera.StayInLevel = true; 75 115 lisaaNappaimet(); 76 } 77 void luoKentta3() 78 { 79 ClearAll(); 80 81 82 //Level.Background.CreateGradient(Color.White, Color.SkyBlue); 83 Level.Background.CreateStars(); 84 85 86 87 Gravity = new Vector(0, -1000); 88 89 lisaaTasoPaikkaan(100, 100); 90 91 92 93 94 Camera.Follow(pelaaja1); 95 Camera.ZoomFactor = 2.0; 96 Camera.StayInLevel = true; 97 lisaaNappaimet(); 98 } 99 100 void luoKentta4() 101 { 102 103 } 104 105 void luoKentta5() 106 { 107 } 108 109 void lisaaTasoPaikkaan(double x, double y) 116 117 } 118 void luoKentta3() 119 { 120 ClearAll(); 121 122 123 //Level.Background.CreateGradient(Color.White, Color.SkyBlue); 124 Level.Background.CreateStars(); 125 126 127 128 Gravity = new Vector(0, -1000); 129 Camera.Follow(pelaaja1); 130 Camera.ZoomFactor = 2.0; 131 Camera.StayInLevel = true; 132 lisaaNappaimet(); 133 } 134 135 void luoKentta4() 136 { 137 138 } 139 140 void luoKentta5() 141 { 142 } 143 144 void lisaaTasoPaikkaan(double x, double y) 110 145 { 111 146 PhysicsObject taso = PhysicsObject.CreateStaticObject(200, 18); … … 116 151 } 117 152 118 PhysicsObject lisaaTaso() 119 { 120 PhysicsObject taso = PhysicsObject.CreateStaticObject(200, 18); 121 taso.Color = Color.White; 122 123 return taso; 124 } 125 126 127 128 129 void lisaaPelaajat() 130 { 131 pelaaja1 = new PlatformCharacter(40, 40); 132 pelaaja1.Mass = 4.0; 133 pelaaja1.Image = LoadImage("tahti"); 134 pelaaja1.X = 0; 135 pelaaja1.Y = Level.Bottom + 100; 136 137 Add(pelaaja1); 138 } 153 PhysicsObject lisaaTaso() 154 { 155 PhysicsObject taso = PhysicsObject.CreateStaticObject(200, 18); 156 taso.Color = Color.White; 157 158 return taso; 159 } 160 161 162 163 164 //void lisaaPelaajat() 165 //{ 166 // pelaaja1 = new PlatformCharacter(40, 40); 167 // pelaaja1.Mass = 4.0; 168 // pelaaja1.Image = LoadImage("tahti"); 169 // pelaaja1.X = 0; 170 // pelaaja1.Y = Level.Bottom + 100; 171 // LaserGun laserPyssy = new LaserGun(20, 5); 172 // //laserPyssy.LaserCollision = LaserSadeOsuu; 173 // pelaaja1.Weapon = new LaserGun(0, 0); 174 // Add(pelaaja1); 175 // //laserPyssy.Ammo.Value = 100; 176 // laserPyssy.IsVisible = false; 177 //} 139 178 140 179 void vaihdaKentta(int kenttaLaskuri) 141 180 { 142 if (kenttaLaskuri ==1)181 if (kenttaLaskuri == 1) 143 182 { 144 183 luoKentta1(); 145 184 } 146 if (kenttaLaskuri ==2)185 if (kenttaLaskuri == 2) 147 186 { 148 187 luoKentta2(); … … 163 202 Keyboard.Listen(Key.Right, ButtonState.Down, liikuta, "Liikkuu oikealle", pelaaja1, nopeus); 164 203 Keyboard.Listen(Key.Space, ButtonState.Pressed, hyppaa, "Hyppää", pelaaja1, hyppyVoima); 204 Keyboard.Listen(Key.RightControl, ButtonState.Down, AmmuAseella, "Ammu"); 165 205 166 206 ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä"); … … 180 220 hahmo.Jump(voima); 181 221 } 182 void KasitteleP allonTormays(PhysicsObject pelaaja1, PhysicsObject kohde)222 void KasittelePelaajanTormays(PhysicsObject pelaaja, PhysicsObject kohde) 183 223 { 184 224 if (kohde.Tag.ToString() == "maali1") … … 186 226 kenttaLaskuri++; 187 227 vaihdaKentta(kenttaLaskuri); 228 229 } 230 if (kohde.Tag.ToString() == "maali2") 231 { 232 kenttaLaskuri++; 233 vaihdaKentta(kenttaLaskuri); 234 } 235 236 if (kohde.Tag.ToString() == "vihollinen") 237 { 238 rajahdys.MinScale = 0.01; 239 rajahdys.MaxScale = 0.4; 240 rajahdys.MinVelocity = 10; 241 rajahdys.MaxVelocity = 200; 242 rajahdys.MinLifetime = 0.1; 243 rajahdys.MaxLifetime = 1.5; 244 245 rajahdys.AddEffect(pelaaja.X, pelaaja.Y, 50); 246 pelaaja.Destroy(); 247 248 249 250 } 251 } 252 253 void KasitteleAmpuminen(PhysicsObject ammus, PhysicsObject kohde) 254 { 255 if(kohde.Tag.ToString() == "vihollinen") 256 { 257 Explosion rajahdys2 = new Explosion(25); 258 rajahdys2.Position = kohde.Position; 259 rajahdys2.Speed = 200.0; 260 rajahdys2.Force = 0; 261 rajahdys2.ShockwaveColor = Color.Lime; 262 263 264 Add(rajahdys2); 265 kohde.Destroy(); 266 188 267 } 189 268 } … … 206 285 pelaaja1.X = 0; 207 286 pelaaja1.Y = Level.Bottom + 100; 287 LaserGun laserPyssy = new LaserGun(20, 5); 288 pelaaja1.Weapon = new LaserGun(0, 0); 289 Add(pelaaja1); 290 laserPyssy.IsVisible = false; 291 AddCollisionHandler(pelaaja1, KasittelePelaajanTormays); 208 292 209 293 return pelaaja1; 294 210 295 } 211 296 PhysicsObject LuoMaaliTileMap() 212 297 { 213 maali = PhysicsObject.CreateStaticObject(75.0, 1 20.0);298 maali = PhysicsObject.CreateStaticObject(75.0, 100.0); 214 299 maali.X = 150.0; 215 300 maali.Y = 200.0; 216 301 maali.Shape = Shapes.Rectangle; 217 302 maali.Color = Color.Yellow; 218 maali.Tag = "maali 1";303 maali.Tag = "maali2"; 219 304 return maali; 220 305 } 306 307 PhysicsObject LuoVihollinen(int reitti) 308 { 309 PhysicsObject vihollinen = new PhysicsObject(50, 50); 310 vihollinen.Shape = Shapes.Circle; 311 vihollinen.Color = Color.DarkMagenta; 312 vihollinen.Mass = 4.0; 313 vihollinen.Tag = "vihollinen"; 314 PathFollowerBrain aivo = new PathFollowerBrain(); 315 //vihollinen.IgnoresCollisionResponse = true; 316 vihollinen.IgnoresGravity = true; 317 vihollinen.Position = alkupisteet[reitti].Position; 318 319 Vector[] pisteet = new Vector[] 320 { 321 alkupisteet[reitti].Position, 322 loppupisteet[reitti].Position, 323 }; 324 325 aivo.Path = pisteet; 326 vihollinen.Brain = aivo; 327 aivo.Speed = 100.0; 328 return vihollinen; 329 330 } 331 332 void AmmuAseella() 333 { 334 PhysicsObject ammus = pelaaja1.Weapon.Shoot(); 335 336 if (ammus != null) 337 { 338 ammus.Size *= 4; 339 ammus.Color = Color.Lime; 340 AddCollisionHandler(ammus, KasitteleAmpuminen); 341 ammus.Tag = "ammus"; 342 343 } 344 } 345 GameObject LuoReittiPiste(int reitti) 346 { 347 GameObject piste = new GameObject(1, 1); 348 piste.IsVisible = false; 349 if (alkupisteet[reitti] == null) 350 { 351 alkupisteet[reitti] = piste; 352 } 353 else 354 { 355 loppupisteet[reitti] = piste; 356 } 357 return piste; 358 359 } 360 361 GameObject LuoReitti0() 362 { 363 return LuoReittiPiste(0); 364 } 365 366 GameObject LuoReitti1() 367 { 368 return LuoReittiPiste(1); 369 } 370 GameObject LuoReitti2() 371 { 372 return LuoReittiPiste(2); 373 } 374 GameObject LuoReitti3() 375 { 376 return LuoReittiPiste(3); 377 } 378 GameObject LuoReitti4() 379 { 380 return LuoReittiPiste(4); 381 } 382 383 384 void LuoLaskuri() 385 { 386 pisteLaskuri = new IntMeter(0); 387 388 Label pisteNaytto = new Label(); 389 pisteNaytto.X = Screen.Left + 100; 390 pisteNaytto.Y = Screen.Top - 100; 391 pisteNaytto.TextColor = Color.Red; 392 393 pisteNaytto.BindTo(pisteLaskuri); 394 Add(pisteNaytto); 395 396 Label pisteTeksti = new Label("Pisteitä: "); 397 pisteTeksti.X = Screen.Left + 50; 398 pisteTeksti.Y = Screen.Top - 100; 399 pisteTeksti.TextColor = Color.Red; 400 Add(pisteTeksti); 401 } 402 403 221 404 } 222 405 -
2010/30/nilaiton/Tasohyppely1/Tasohyppely1.csproj
r1374 r1408 89 89 <Content Include="Game.ico" /> 90 90 <Content Include="GameThumbnail.png" /> 91 <Content Include="kentta1.txt"> 92 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> 93 </Content> 91 94 <Content Include="kentta2.txt"> 92 95 <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> -
2010/30/nilaiton/Tasohyppely1/kentta2.txt
r1374 r1408 1 1 M 2 2 3 -- 3 4 4 -- 5 5 3 3 6 6 -- -- 7 7 --- … … 18 18 - ---- -- 19 19 -- 20 - 20 - 21 21 ---- -- 22 22 23 - --- 23 - --- 2 2 24 24 - ---- 25 25 - 26 - 26 - X 27 27 - -- --- 28 28 29 X30 - 31 32 ----- 33 - --------29 0 0 30 - - ----------- 31 -- 32 ----- 1 1 33 - 44 -------- 34 34 --------------------------------------------------------- -
2010/30/nilaiton/kentta2.txt
r1374 r1408 1 1 M 2 --3 2 3 -- X 4 4 -- 5 5 00 6 6 -- -- 7 7 --- … … 27 27 - -- --- 28 28 29 X 29 30 30 - ----------- 31 31
Note: See TracChangeset
for help on using the changeset viewer.