- Timestamp:
- 2010-07-29 14:50:34 (13 years ago)
- Location:
- 2010/30/johulkko/FysiikkaPeli2
- Files:
-
- 4 added
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
2010/30/johulkko/FysiikkaPeli2/Content/Content.contentproj
r1375 r1405 55 55 </Compile> 56 56 </ItemGroup> 57 <ItemGroup> 58 <Compile Include="CAME OVER.png"> 59 <Name>CAME OVER</Name> 60 <Importer>TextureImporter</Importer> 61 <Processor>TextureProcessor</Processor> 62 </Compile> 63 </ItemGroup> 64 <ItemGroup> 65 <Compile Include="rajahdys.png"> 66 <Name>rajahdys</Name> 67 <Importer>TextureImporter</Importer> 68 <Processor>TextureProcessor</Processor> 69 </Compile> 70 </ItemGroup> 71 <ItemGroup> 72 <Compile Include="ohjus.png"> 73 <Name>ohjus</Name> 74 <Importer>TextureImporter</Importer> 75 <Processor>TextureProcessor</Processor> 76 </Compile> 77 </ItemGroup> 57 78 </Project> -
2010/30/johulkko/FysiikkaPeli2/FysiikkaPeli2.sln
r1333 r1405 2 2 Microsoft Visual Studio Solution File, Format Version 10.00 3 3 # Visual Studio 2008 4 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = " FysiikkaPeli2", "FysiikkaPeli2.csproj", "{D1E5BE3B-455E-4237-A0F6-9CC3D12525FD}"4 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "avoid", "avoid.csproj", "{D1E5BE3B-455E-4237-A0F6-9CC3D12525FD}" 5 5 EndProject 6 6 Global -
2010/30/johulkko/FysiikkaPeli2/Peli.cs
r1375 r1405 1 1 using System; 2 using System.Collections.Generic; 3 2 4 using Jypeli; 3 5 using Jypeli.Widgets; 4 6 using Jypeli.Assets; 7 using Jypeli.Effects; 8 5 9 6 10 public class Peli : PhysicsGame … … 15 19 Image olionKuva = LoadImage("hahmo2 pienenpi"); 16 20 PlatformCharacter hahmo; 21 Image CameOver = LoadImage("CAME OVER"); 22 23 Image pomminkuva = LoadImage("ohjus"); 24 25 IntMeter elamaLaskuri; 26 IntMeter pisteLaskuri; 27 Label pisteNaytto; 28 29 PhysicsObject maa; 30 31 double pommienPutoamisKiihtyvyys; 32 ExplosionSystem rajahdys; 17 33 18 34 protected override void Begin() 19 35 { 36 rajahdys = new ExplosionSystem(LoadImage("rajahdys"), 300); 37 Add(rajahdys); 38 20 39 LuoKentta(); 40 LuoPelihahmo(); 21 41 LuoOhjaimet(); 42 LuoLaskurit(); 43 LuoPomminPudotusAjastin(); 22 44 Camera.ZoomToLevel(); 23 45 } 24 46 25 void LuoKentta() 26 { 27 //maastonMuoto = Shapes.FromImage(maastonLeveys, maastonKorkeus, maastonKuva); 28 //PhysicsObject maasto = 29 // PhysicsObject.CreateStaticObject( 30 // maastonLeveys, 31 // maastonKorkeus, 32 // maastonMuoto); 33 //maasto.Image = maastonKuva; 34 //maasto.Color = Color.Green; 35 //Add(maasto); 36 //maasto.Y = -300; 37 Mouse.IsCursorVisible = true; 38 39 PhysicsObject maa = PhysicsObject.CreateStaticObject(Level.Width, 110.0); 40 maa.Y = -350; 41 maa.Color = Color.Green; 42 Add(maa); 43 44 LuoTaso(200, 100); 45 LuoTaso(0, -100); 46 LuoTaso(-200, 100); 47 48 Gravity = new Vector(0.0, -800.0); 49 50 Level.CreateLeftBorder(); 51 Level.CreateBottomBorder(); 52 Level.CreateRightBorder(); 53 47 void LuoPelihahmo() 48 { 54 49 hahmo = new PlatformCharacter(50, 72); 55 56 50 hahmo.Shape = Shapes.Rectangle; 57 51 hahmo.Image = olionKuva; 58 52 hahmo.Tag = "tyyppi"; 59 53 Add(hahmo); 60 54 61 55 hahmo.Y = -180; 62 56 hahmo.X = -110; 57 AddCollisionHandler(hahmo, PelaajaTormasi); 58 } 59 60 void PelaajaTormasi(PhysicsObject hahmo, PhysicsObject kohde) 61 { 62 if (kohde.Tag.ToString() == "pommi") 63 { 64 elamaLaskuri.Value--; 65 } 66 } 67 68 private void LuoPomminPudotusAjastin() 69 { 70 Timer ajastin = new Timer(); 71 ajastin.Interval = 1; 72 ajastin.Trigger += LuoPommi; 73 ajastin.Start(); 74 } 75 76 void LuoPommi(Timer t) 77 { 78 double x= RandomGen.NextDouble(Level.Left, Level.Right); 79 double y = Level.Top; 80 PhysicsObject pommi = new PhysicsObject(20, 40, Shapes.Rectangle); 81 pommi.Position = new Vector(x, y); 82 pommienPutoamisKiihtyvyys = RandomGen.NextDouble(0.65, 0.99); 83 pommi.LinearDamping = pommienPutoamisKiihtyvyys; 84 pommi.Tag = "pommi"; 85 pommi.Image = pomminkuva; 86 AddCollisionHandler(pommi, PommiTormasi); 87 Add(pommi); 88 } 89 90 void PommiTormasi(PhysicsObject pommi, PhysicsObject kohde) 91 { 92 rajahdys.MinVelocity = 20; 93 rajahdys.MaxVelocity = 300; 94 rajahdys.MinScale = 0.05; 95 rajahdys.MaxScale = 0.2; 96 rajahdys.MinLifetime = 0.1; 97 rajahdys.MaxLifetime = 1.5; 98 rajahdys.AddEffect(pommi.X, pommi.Y, 40); 99 pommi.Destroy(); 100 101 if (kohde==maa) 102 { 103 if (pisteLaskuri.Value >= 50) 104 { 105 pisteLaskuri.Value -= 50; 106 107 } 108 else 109 { 110 pisteLaskuri.Value = 0; 111 } 112 } 113 114 115 116 } 117 118 void LuoKentta() 119 { 120 Mouse.IsCursorVisible = true; 121 122 maa = PhysicsObject.CreateStaticObject(Level.Width, 110.0); 123 maa.Y = -350; 124 maa.Color = Color.Green; 125 Add(maa); 126 127 LuoTaso(200, 100); 128 LuoTaso(0, -100); 129 LuoTaso(-200, 100); 130 131 Gravity = new Vector(0.0, -800.0); 132 133 Level.CreateLeftBorder(); 134 Level.CreateBottomBorder(); 135 Level.CreateRightBorder(); 63 136 } 64 137 … … 69 142 void LuoOhjaimet() 70 143 { 71 Keyboard.Listen( Key.Escape, ButtonState.Pressed, Exit, "Poistu");72 73 Keyboard.Listen(Key.Left, ButtonState.Down, HahmoLiikkuu, "hahmo liikkuu vasemmalle", hahmo, nopeusvasemmalle);74 Keyboard.Listen(Key.Left, ButtonState.Released, HahmoLiikkuu, null, hahmo, 0.0);75 Keyboard.Listen(Key.Right, ButtonState.Down, HahmoLiikkuu, "hahmo liikkuu oikealle", hahmo, nopeusoikealle);76 Keyboard.Listen(Key.Right, ButtonState.Released, HahmoLiikkuu, null, hahmo, 0.0);77 Keyboard.Listen(Key.Up, ButtonState.Pressed, Hahmohyppaa, "hahmo liikkuu oikealle", hahmo);78 Keyboard.Listen(Key.Up, ButtonState.Released, Hahmohyppaa, null, hahmo);79 80 Keyboard.Listen(Key.A, ButtonState.Down, HahmoLiikkuu, "hahmo liikkuu vasemmalle", hahmo, nopeusvasemmalle);81 Keyboard.Listen(Key.A, ButtonState.Released, HahmoLiikkuu, null, hahmo, 0.0);82 Keyboard.Listen(Key.D, ButtonState.Down, HahmoLiikkuu, "hahmo liikkuu oikealle", hahmo, nopeusoikealle);83 Keyboard.Listen(Key.D, ButtonState.Released, HahmoLiikkuu, null, hahmo, 0.0);84 Keyboard.Listen(Key.W, ButtonState.Pressed, Hahmohyppaa, "hahmo liikkuu oikealle", hahmo);85 Keyboard.Listen(Key.W, ButtonState.Released, Hahmohyppaa, null, hahmo);86 144 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 145 146 Keyboard.Listen(Key.Left, ButtonState.Down, HahmoLiikkuu, "hahmo liikkuu vasemmalle", hahmo, nopeusvasemmalle); 147 Keyboard.Listen(Key.Left, ButtonState.Released, HahmoLiikkuu, null, hahmo, 0.0); 148 Keyboard.Listen(Key.Right, ButtonState.Down, HahmoLiikkuu, "hahmo liikkuu oikealle", hahmo, nopeusoikealle); 149 Keyboard.Listen(Key.Right, ButtonState.Released, HahmoLiikkuu, null, hahmo, 0.0); 150 Keyboard.Listen(Key.Up, ButtonState.Pressed, Hahmohyppaa, "hahmo liikkuu oikealle", hahmo); 151 //Keyboard.Listen(Key.Up, ButtonState.Released, Hahmohyppaa, null, hahmo); 152 153 Keyboard.Listen(Key.A, ButtonState.Down, HahmoLiikkuu, "hahmo liikkuu vasemmalle", hahmo, nopeusvasemmalle); 154 Keyboard.Listen(Key.A, ButtonState.Released, HahmoLiikkuu, null, hahmo, 0.0); 155 Keyboard.Listen(Key.D, ButtonState.Down, HahmoLiikkuu, "hahmo liikkuu oikealle", hahmo, nopeusoikealle); 156 Keyboard.Listen(Key.D, ButtonState.Released, HahmoLiikkuu, null, hahmo, 0.0); 157 Keyboard.Listen(Key.W, ButtonState.Pressed, Hahmohyppaa, "hahmo liikkuu oikealle", hahmo); 158 //Keyboard.Listen(Key.W, ButtonState.Released, Hahmohyppaa, null, hahmo); 159 87 160 Mouse.Listen(MouseButton.Left, ButtonState.Pressed, Ammu, "hahmo liikkuu oikealle"); 88 161 … … 93 166 hahmo.Walk(nopeus); 94 167 } 95 168 96 169 void Hahmohyppaa(PlatformCharacter hahmo) 97 170 { … … 99 172 } 100 173 101 void LuoTaso( 174 void LuoTaso(double x, double y) 102 175 { 103 176 PhysicsObject taso = PhysicsObject.CreateStaticObject(100, 20); 104 177 taso.X = x; 105 178 taso.Y = y; 179 180 PathFollowerBrain polkuAivot = new PathFollowerBrain(); 181 List<Vector> polku = new List<Vector>(); 182 183 for (int i = 0; i < 10; i++) 184 { 185 polku.Add(new Vector( 186 RandomGen.NextDouble(Level.Left + 50, Level.Right - 50), 187 RandomGen.NextDouble(Level.Bottom+200, Level.Top-100) 188 )); 189 } 190 191 polkuAivot.Path = polku; 192 polkuAivot.Active = true; 193 polkuAivot.Speed = 50; 194 195 taso.Brain = polkuAivot; 106 196 taso.Color = Color.Gray; 107 197 Add(taso); … … 111 201 void Ammu() 112 202 { 113 PhysicsObject panos = new PhysicsObject( 6, 6);203 PhysicsObject panos = new PhysicsObject(9, 9); 114 204 panos.Color = Color.Yellow; 115 205 panos.Shape = Shapes.Circle; 116 206 117 Vector Pyssynteho = Mouse.PositionOnWorld;118 panos.Angle = Pyssynteho.Angle;119 Pyssynteho.X = Pyssynteho.X * 5;120 Pyssynteho.Y = Pyssynteho.Y * 5;121 if ( Pyssynteho.X < hahmo.X)207 Vector pyssynTeho = Mouse.PositionOnWorld - hahmo.Position; 208 panos.Angle = pyssynTeho.Angle; 209 pyssynTeho.X = pyssynTeho.X * 5; 210 pyssynTeho.Y = pyssynTeho.Y * 5; 211 if (pyssynTeho.X < hahmo.X) 122 212 { 123 213 panos.X = hahmo.X - 20; 124 214 panos.Y = hahmo.Y; 125 215 } 126 else 216 else 127 217 { 128 218 panos.X = hahmo.X + 20; 129 219 panos.Y = hahmo.Y; 130 220 } 131 panos.Hit( Pyssynteho);221 panos.Hit(pyssynTeho); 132 222 panos.IgnoresGravity = false; 133 223 TimeSpan elinaika = new TimeSpan(10000000); … … 136 226 Add(panos); 137 227 } 228 138 229 void PanosOsuu(PhysicsObject panos, PhysicsObject kohde) 139 230 { … … 142 233 panos.Destroy(); 143 234 } 144 } 145 146 147 IntMeter pisteLaskuri; 148 149 void LuoLaskuri() 150 { 151 pisteLaskuri = new IntMeter(5); 152 153 Label pisteNaytto = new Label(); 154 pisteNaytto.X = Screen.Left + 100; 235 236 if (kohde.Tag.ToString() == "pommi") 237 { 238 pisteLaskuri.Value += 25; 239 } 240 } 241 242 243 244 void LuoLaskurit() 245 { 246 elamaLaskuri = new IntMeter(5); 247 elamaLaskuri.MinValue = 0; 248 elamaLaskuri.LowerLimit += ElamatLoppu; 249 250 pisteLaskuri = new IntMeter(0); 251 pisteLaskuri.MinValue = 0; 252 Label elamaNaytto = new Label(); 253 elamaNaytto.X = Screen.Left + 100; 254 elamaNaytto.Y = Screen.Top - 100; 255 elamaNaytto.TextColor = Color.Black; 256 elamaNaytto.BindTo(elamaLaskuri); 257 Add(elamaNaytto); 258 259 Label elamaTeksti = new Label("Elämät: "); 260 elamaTeksti.X = Screen.Left + 50; 261 elamaTeksti.Y = Screen.Top - 100; 262 elamaTeksti.TextColor = Color.Black; 263 Add(elamaTeksti); 264 265 pisteNaytto = new Label(); 266 pisteNaytto.X = Screen.Right - 100; 155 267 pisteNaytto.Y = Screen.Top - 100; 156 pisteNaytto.TextColor = Color.Red; 157 268 pisteNaytto.TextColor = Color.Black; 158 269 pisteNaytto.BindTo(pisteLaskuri); 159 270 Add(pisteNaytto); 160 Label pisteTeksti = new Label("Pisteitä: "); 161 162 pisteTeksti.X = Screen. Left + 50;271 272 Label pisteTeksti = new Label("Pisteet: "); 273 pisteTeksti.X = Screen.Right - 200; 163 274 pisteTeksti.Y = Screen.Top - 100; 164 pisteTeksti.TextColor = Color. Red;275 pisteTeksti.TextColor = Color.Black; 165 276 Add(pisteTeksti); 166 167 pisteLaskuri.Value++; 168 pisteLaskuri.Value += 1; 169 pisteLaskuri.Value = pisteLaskuri.Value + 1; 170 171 IntMeter laskuri = new IntMeter(5); 172 laskuri.MinValue = 10; 173 laskuri.LowerLimit += ElamatLoppu; 277 174 278 175 279 } … … 177 281 void ElamatLoppu(int elamat) 178 282 { 179 180 } 181 283 ClearAll(); 284 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 285 Level.Background.Image = CameOver; 286 } 287 182 288 }
Note: See TracChangeset
for help on using the changeset viewer.