Changeset 2370
- Timestamp:
- 2011-06-30 14:53:07 (12 years ago)
- Location:
- 2011/26/JouniM/MatoPeli/MatoPeli
- Files:
-
- 10 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/26/JouniM/MatoPeli/MatoPeli/MatoPeli/Peli.cs
r2301 r2370 17 17 Timer sadeajastin; 18 18 Timer aikaLaskuri; 19 IntMeter pisteLaskuri; 20 21 Image MadonKuva = LoadImage("Mato"); 22 Image SaaliinKuva = LoadImage("Saalis"); 23 Image GameOver = LoadImage("game over"); 19 24 20 25 bool kuolematon = false; … … 23 28 { 24 29 // TODO: Kirjoita ohjelmakoodisi tähän 25 30 26 31 ajastin = new Timer(); 27 32 ajastin.Interval = 0.1; … … 36 41 aikaLaskuri.Trigger += LaskeAlaspain; 37 42 38 39 40 41 Aloitapeli(); 42 43 44 45 43 Aloitapeli(); 46 44 47 45 } … … 73 71 void LuoMato() 74 72 { 75 Mato = new PhysicsObject(30.0, 40.0); 76 Mato.Tag = "Mato"; 77 Add(Mato); 78 Mato.Shape = Shape.Heart; 79 AddCollisionHandler(Mato, KasitteleMadonTormays); 73 Mato = new PhysicsObject(30.0, 40.0); 74 Mato.Tag = "Mato"; 75 Add(Mato); 76 Mato.Shape = Shape.Heart; 77 Mato.Image = MadonKuva; 78 79 AddCollisionHandler(Mato, KasitteleMadonTormays); 80 80 81 81 } 82 82 83 83 void KasitteleMadonTormays(PhysicsObject Mato, PhysicsObject kohde) 84 85 86 { 87 88 if (kohde.Tag.ToString() == "saalis") 89 { 90 kohde.Destroy(); 91 Saalis_Destroyed(); 92 } 84 { 85 86 if (kohde.Tag.ToString() == "saalis") 87 { 88 kohde.Destroy(); 89 SaalisDestroyed(); 90 } 93 91 94 92 } … … 96 94 97 95 void AsetaOhjaimet() 98 99 96 { 100 97 Mouse.IsCursorVisible = true; 101 Keyboard.Listen(Key.G, ButtonState.Down, TuleeKuolemattomaksi, null);102 Keyboard.Listen(Key.G, ButtonState.Up, Kuolemattomuusloppuu, null);98 Keyboard.Listen(Key.G, ButtonState.Down, TuleeKuolemattomaksi, null); 99 Keyboard.Listen(Key.G, ButtonState.Up, Kuolemattomuusloppuu, null); 103 100 Keyboard.Listen(Key.R, ButtonState.Released, uudestaan, "aloitus"); 104 101 … … 107 104 108 105 109 110 111 112 106 void TuleeKuolemattomaksi() 107 { 108 kuolematon = true; 109 } 113 110 114 111 void Kuolemattomuusloppuu() … … 126 123 } 127 124 128 void LiikutaMatoa (Timer sender)125 void LiikutaMatoa(Timer sender) 129 126 { 130 127 Vector etaisyys = Mouse.PositionOnWorld - Mato.Position; 131 Mato.MoveTo(Mouse.PositionOnWorld, etaisyys.Magnitude *1.5);132 Mato.Angle = etaisyys.Angle +Angle.RightAngle;133 128 Mato.MoveTo(Mouse.PositionOnWorld, etaisyys.Magnitude * 1.5); 129 Mato.Angle = etaisyys.Angle + Angle.FromDegrees(270); 130 134 131 } 135 132 … … 138 135 Saalis = new PhysicsObject(30, 30); 139 136 Saalis.Tag = "saalis"; 137 Saalis.Image = SaaliinKuva; 140 138 Add(Saalis); 141 139 Saalis.Shape = Shape.Star; 142 140 Saalis.X = RandomGen.NextDouble(Level.Left, Level.Right); 143 141 Saalis.Y = RandomGen.NextDouble(Level.Bottom, Level.Top); 144 FollowerBrain karkuunSaalis = new FollowerBrain(Mato, -50); 145 karkuunSaalis.Target = Mato; 146 Saalis.Brain = karkuunSaalis; 142 //FollowerBrain karkuunSaalis = new FollowerBrain(Mato, -50); 143 //karkuunSaalis.Target = Mato; 144 //Saalis.Brain = karkuunSaalis; 145 Saalis.Hit(new Vector(RandomGen.NextDouble(-600, 600), RandomGen.NextDouble(-600, 600))); 146 AddCollisionHandler(Saalis, KasitteleSaaliinTormays); 147 147 //Saalis.Destroyed += new Action(Saalis_Destroyed); 148 149 150 151 152 153 } 154 155 void Saalis_Destroyed() 156 { 157 LuoSaalis(RandomGen.NextDouble(Level.Left, Level.Right), RandomGen.NextDouble(Level.Bottom, Level.Top) ); 148 } 149 150 void KasitteleSaaliinTormays(PhysicsObject saalis, PhysicsObject kohde) 151 { 152 if(kohde.Tag.ToString() != "saalis") saalis.Hit(-1/2*saalis.Position); 153 } 154 155 void SaalisDestroyed() 156 { 158 157 LuoSaalis(RandomGen.NextDouble(Level.Left, Level.Right), RandomGen.NextDouble(Level.Bottom, Level.Top)); 159 pisteLaskuri.Value = pisteLaskuri.Value + 1;160 }161 162 IntMeter pisteLaskuri;158 LuoSaalis(RandomGen.NextDouble(Level.Left, Level.Right), RandomGen.NextDouble(Level.Bottom, Level.Top)); 159 pisteLaskuri.Value = pisteLaskuri.Value + 1 ; 160 // KasvataMatoa(); 161 } 163 162 164 163 void LuoLaskuri() … … 185 184 void LuoVihollinen(Timer sender) 186 185 { 187 sender.Interval = sender.Interval -0.019;186 sender.Interval = sender.Interval - 0.019; 188 187 189 188 Vector suunta = new Vector(0, 1); 190 189 191 190 Vector position; 192 191 if (RandomGen.NextBool()) 193 192 { 194 position = new Vector(RandomGen.NextDouble(Level.Left, Level.Right), Level.Top); 193 double x = RandomGen.NextDouble(Level.Left, Level.Right); 194 while (Math.Abs(Mato.X - x) <100 ) 195 { 196 x = RandomGen.NextDouble(Level.Left, Level.Right); 197 } 198 position = new Vector(x, Level.Top); 195 199 suunta = new Vector(0.0, -1); 196 200 } … … 198 202 else 199 203 { 200 position = new Vector ( Level.Left, RandomGen.NextDouble(Level.Bottom, Level.Top)); 201 suunta = new Vector(1, 0); 202 } 203 PhysicsObject Vihollinen = new PhysicsObject(new RaySegment(position, suunta, 2000) ); 204 Vihollinen.MaximumLifetime = TimeSpan.FromSeconds(2.0); 205 206 AddCollisionHandler(Vihollinen, KasitteleVihollisenTormays); 207 204 double y = RandomGen.NextDouble(Level.Bottom, Level.Top); 205 while (Math.Abs(Mato.Y - y) <100 ) 206 { 207 y = RandomGen.NextDouble(Level.Bottom, Level.Top); 208 } 209 position = new Vector(Level.Left, y); 210 suunta = new Vector(1,0); 211 } 212 213 214 PhysicsObject Vihollinen = new PhysicsObject(new RaySegment(position, suunta, 2000)); 215 Vihollinen.MaximumLifetime = TimeSpan.FromSeconds(2.0); 216 Vihollinen.Color = Color.Red; 217 AddCollisionHandler(Vihollinen, KasitteleVihollisenTormays); 208 218 Add(Vihollinen); 209 219 210 220 } 211 221 212 222 void KasitteleVihollisenTormays(PhysicsObject Vihollinen, PhysicsObject kohde) 213 223 { 214 215 224 if (kohde.Tag.ToString() == "Mato" && kuolematon == false) 216 225 { 217 226 kohde.Destroy(); 218 219 } 220 221 } 222 223 227 } 228 } 224 229 225 230 void LuoAikaLaskuri() 226 231 { 227 alaspainLaskuri = new DoubleMeter(30); 228 229 232 alaspainLaskuri = new DoubleMeter(35); 230 233 231 234 Label aikaNaytto = new Label(); … … 244 247 if (alaspainLaskuri.Value <= 0) 245 248 { 246 MessageDisplay.Add(" total anhilation");249 MessageDisplay.Add("Peli Loppui"); 247 250 timer.Stop(); 251 ClearAll(); 252 Widget lopputeksti = new Widget(Screen.Width, Screen.Height); 253 lopputeksti.Image = GameOver; 254 Add(lopputeksti); 248 255 249 256 // täydennä mitä tapahtuu, kun aika loppuu -
2011/26/JouniM/MatoPeli/MatoPeli/MatoPeliContent/MatoPeliContent.contentproj
r2242 r2370 42 42 </Reference> 43 43 </ItemGroup> 44 <ItemGroup> 45 <Compile Include="Mato.png"> 46 <Name>Mato</Name> 47 <Importer>TextureImporter</Importer> 48 <Processor>TextureProcessor</Processor> 49 </Compile> 50 </ItemGroup> 51 <ItemGroup> 52 <Compile Include="Saalis.png"> 53 <Name>Saalis</Name> 54 <Importer>TextureImporter</Importer> 55 <Processor>TextureProcessor</Processor> 56 </Compile> 57 </ItemGroup> 58 <ItemGroup> 59 <Compile Include="game over.jpg"> 60 <Name>game over</Name> 61 <Importer>TextureImporter</Importer> 62 <Processor>TextureProcessor</Processor> 63 </Compile> 64 </ItemGroup> 44 65 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 45 66 <!-- 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.