Changeset 3755
- Timestamp:
- 2012-07-25 15:07:48 (11 years ago)
- Location:
- 2012/30/AnttiS
- Files:
-
- 6 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/30/AnttiS/EksyksissäAvaruudessa/EksyksissäAvaruudessa/EksyksissäAvaruudessa/EksyksissäAvaruudessa.cs
r3731 r3755 8 8 9 9 public class EksyksissäAvaruudessa : PhysicsGame 10 11 10 { 12 PhysicsObject Alus = new PhysicsObject(130, 40); 13 14 11 int kenttaNro = 1; 12 PhysicsObject Alus; 15 13 16 14 public override void Begin() 17 15 { 16 SeuraavaKentta(); 17 } 18 void SeuraavaKentta() 19 { 20 ClearAll(); 21 18 22 LuoAlus(); 19 23 AsetaOhjaimet(); 20 Luo Kentta();24 LuoTausta(); 21 25 26 if (kenttaNro == 1) SijoitaOliot1(); 27 else if (kenttaNro == 2) SijoitaOliot2(); 28 else Exit(); 29 30 LuoPistelaskuri(); 22 31 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 32 } 23 33 24 }25 34 void LuoAlus() 26 35 { 36 Alus = new PhysicsObject(130, 40); 27 37 Alus.LinearDamping = 0.5; 38 Alus.CanRotate = false; 28 39 Alus.Image = LoadImage("avaruusalus"); 40 Alus.X = -400; 41 Alus.Y = 0; 42 Alus.Restitution = 1.0; 29 43 Add(Alus); 44 45 AddCollisionHandler(Alus, "UFO", Kuole); 46 } 47 PhysicsObject LuoMaali() 48 { 49 PhysicsObject Maali = new PhysicsObject(169, 94); 50 Maali.Image = LoadImage("MAALI"); 51 Add(Maali); 52 AddCollisionHandler( Alus, Maali, VaihdaKenttaa ); 53 return Maali; 30 54 } 31 55 void AsetaOhjaimet() 32 56 { 33 //Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaAlusta, null, new Vector( -1000, 0 )); 34 //Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaAlusta, null, new Vector( 1000, 0 )); 35 //Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaAlusta, null, new Vector( 0, 1000 )); 36 //Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaAlusta, null, new Vector( 0, -1000 )); 37 38 Keyboard.Listen( Key.Left, ButtonState.Down, KaannaAlusta, null, Angle.FromDegrees(1)); 39 Keyboard.Listen(Key.Right, ButtonState.Down, KaannaAlusta, null, Angle.FromDegrees(-1)); 40 Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaAlusta, null, 1000.0); 41 Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaAlusta, null, -1000.0); 57 58 Keyboard.Listen(Key.Left, ButtonState.Down, KaannaAlusta, null, Angle.FromDegrees(1)); 59 Keyboard.Listen(Key.Right, ButtonState.Down, KaannaAlusta, null, Angle.FromDegrees(-1)); 60 Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaAlusta, null, 1000.0); 61 Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaAlusta, null, -1000.0); 42 62 43 63 } … … 47 67 Alus.Push(vektori); 48 68 } 49 void Luo Kentta()69 void LuoTausta() 50 70 { 51 Level.CreateBorders(); 71 Level.CreateBorders(1.0, true); 72 Camera.ZoomToLevel(); 73 Image taustaKuva = LoadImage("tausta"); 74 Level.Background.Image = taustaKuva; 75 Level.Background.FitToLevel(); 76 } 77 void LuoPlaneetta1(double x, double y) 78 { 79 PhysicsObject planeetta = PhysicsObject.CreateStaticObject(90, 86); 80 Image planeetta1 = LoadImage("planeetta1"); 81 planeetta.Image = planeetta1; 82 planeetta.X = x; 83 planeetta.Y = y; 84 planeetta.Restitution = 1.0; 85 Add(planeetta); 52 86 } 53 87 void KaannaAlusta(Angle kulma) … … 55 89 Alus.Angle += kulma; 56 90 } 91 void SijoitaOliot1() 92 { 93 LuoUfo(-200, -300, new Vector(-150.0, -150.0)); 94 LuoUfo(200, -300, new Vector(150.0, 150.0)); 95 LuoPlaneetta1(-200, 50); 96 LuoPlaneetta1(-300, 200); 97 LuoPlaneetta1(-40, 120); 98 LuoPlaneetta1(200, 50); 99 LuoPlaneetta1(90, -200); 100 101 PhysicsObject maali = LuoMaali(); 102 maali.X = 200; 103 maali.Y = 200; 104 } 105 void SijoitaOliot2() 106 { 107 LuoUfo(-200, -300, new Vector(-150.0, -150.0)); 108 LuoUfo(200, -300, new Vector(150.0, 150.0)); 109 LuoPlaneetta1(-200, 50); 110 LuoPlaneetta1(-300, 200); 111 LuoPlaneetta1(-40, 120); 112 LuoPlaneetta1(200, 50); 113 LuoPlaneetta1(90, -200); 114 115 PhysicsObject maali = LuoMaali(); 116 maali.X = 200; 117 maali.Y = 200; 118 } 119 void LuoUfo(double x, double y, Vector suunta) 120 { 121 PhysicsObject Ufo = new PhysicsObject(123, 71); 122 Image ufo = LoadImage("ufo"); 123 Ufo.CanRotate = false; 124 Ufo.Image = ufo; 125 Ufo.X = x; 126 Ufo.Y = y; 127 Ufo.Tag = "UFO"; 128 Ufo.Restitution = 1.0; 129 Vector impulssi = suunta; 130 Ufo.Hit(impulssi); 131 Add(Ufo); 132 133 } 134 IntMeter pisteLaskuri; 135 136 void LuoPistelaskuri() 137 { 138 pisteLaskuri = new IntMeter(3); 139 pisteLaskuri.LowerLimit += new Action(pisteLaskuri_LowerLimit); 140 141 Label pisteNaytto = new Label(); 142 pisteNaytto.X = Screen.Right - 100; 143 pisteNaytto.Y = Screen.Top - 100; 144 pisteNaytto.TextColor = Color.Blue; 145 pisteNaytto.Color = Color.Red; 146 pisteNaytto.BindTo(pisteLaskuri); 147 Add(pisteNaytto); 148 149 pisteNaytto.Title = "Elämät"; 150 } 151 152 void pisteLaskuri_LowerLimit() 153 { 154 Widget kuva = new Widget(LoadImage("game over")); 155 kuva.Width = Screen.Width; 156 kuva.Height = Screen.Height; 157 Add(kuva); 158 Timer.SingleShot(5.0, Begin); 159 } 160 void PelaajaTormasi(PhysicsObject tormaaja, PhysicsObject kohde) 161 { 162 MessageDisplay.Add("Pelaaja törmäsi!"); 163 } 164 165 void Kuole(PhysicsObject tormaaja, PhysicsObject kohde) 166 { 167 pisteLaskuri.Value -= 1; 168 } 169 170 57 171 } 172 -
2012/30/AnttiS/EksyksissäAvaruudessa/EksyksissäAvaruudessa/EksyksissäAvaruudessaContent/EksyksissäAvaruudessaContent.contentproj
r3731 r3755 51 51 </Compile> 52 52 </ItemGroup> 53 <ItemGroup> 54 <Compile Include="tausta.png"> 55 <Name>tausta</Name> 56 <Importer>TextureImporter</Importer> 57 <Processor>TextureProcessor</Processor> 58 </Compile> 59 </ItemGroup> 60 <ItemGroup> 61 <Compile Include="planeetta1.png"> 62 <Name>planeetta1</Name> 63 <Importer>TextureImporter</Importer> 64 <Processor>TextureProcessor</Processor> 65 </Compile> 66 </ItemGroup> 67 <ItemGroup> 68 <Compile Include="ufo.png"> 69 <Name>ufo</Name> 70 <Importer>TextureImporter</Importer> 71 <Processor>TextureProcessor</Processor> 72 </Compile> 73 </ItemGroup> 74 <ItemGroup> 75 <Compile Include="game over.png"> 76 <Name>game over</Name> 77 <Importer>TextureImporter</Importer> 78 <Processor>TextureProcessor</Processor> 79 </Compile> 80 </ItemGroup> 81 <ItemGroup> 82 <Compile Include="MAALI.png"> 83 <Name>MAALI</Name> 84 <Importer>TextureImporter</Importer> 85 <Processor>TextureProcessor</Processor> 86 </Compile> 87 </ItemGroup> 53 88 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 54 89 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Note: See TracChangeset
for help on using the changeset viewer.