- Timestamp:
- 2010-07-09 13:05:21 (13 years ago)
- Location:
- 2010/27/patammi/Autopeli1
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/27/patammi/Autopeli1/Autopeli2.csproj
r1155 r1231 57 57 </PropertyGroup> 58 58 <ItemGroup> 59 <Reference Include="Jypeli2, Version= 1.0.0.0, Culture=neutral, processorArchitecture=x86">59 <Reference Include="Jypeli2, Version=2.2.4.0, Culture=neutral, processorArchitecture=x86"> 60 60 <SpecificVersion>False</SpecificVersion> 61 61 <HintPath>..\..\lib\Jypeli2.dll</HintPath> -
2010/27/patammi/Autopeli1/Content/Content.contentproj
r1174 r1231 45 45 </Compile> 46 46 </ItemGroup> 47 <ItemGroup> 48 <Compile Include="Untitled.png"> 49 <Name>Untitled</Name> 50 <Importer>TextureImporter</Importer> 51 <Processor>TextureProcessor</Processor> 52 </Compile> 53 </ItemGroup> 47 54 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 48 55 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
2010/27/patammi/Autopeli1/Peli.cs
r1174 r1231 4 4 using Jypeli.Assets; 5 5 using Jypeli.Effects; 6 6 //Janne Ja Paveli 7 7 public class Peli : TopDownPhysicsGame 8 8 { … … 14 14 15 15 PhysicsObject OilBarrel; 16 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 17 18 BarGauge auton1palkki, auton2palkki; 19 DoubleMeter auton1hp, auton2hp; 16 20 17 21 ExplosionSystem es; … … 19 23 protected override void Begin() 20 24 { 21 KineticFriction = 1.0; // Asetetaan kitka 25 Level.Background.Image = LoadImage("Untitled"); 26 Level.Background.Size = new Vector(Level.Width, Level.Height); 27 KineticFriction = 100.00; // Asetetaan kitka 28 29 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 30 maila.Shape = Shapes.Rectangle; 31 maila.X = Level.Left + 150.0; 32 maila.Y = 0.0; 33 maila.Restitution = 1.0; 34 Add(maila); 35 maila.Color = Color.Black; 36 37 PhysicsObject maila2 = PhysicsObject.CreateStaticObject(20.0, 100.0); 38 maila2.Shape = Shapes.Rectangle; 39 maila2.X = Level.Right - 150.0; 40 maila2.Y = 0.0; 41 maila2.Restitution = 1.0; 42 Add(maila2); 43 maila2.Color = Color.Red; 22 44 23 45 auto = new Automobile(40, 20); 24 auto.Mass = 1.0;46 auto.Mass = 25.0; 25 47 auto.Maneuverability = Angle.Degrees(120); 26 48 auto.Color = new Color(0, 0, 0); 27 49 auto.AngularDamping = 0.9; 50 auto.X = Level.Right - 20.0; 28 51 Add(auto); 29 52 30 laserPyssy1 = new LaserGun(20, 5); 31 laserPyssy1.TimeBetweenUse = TimeSpan.FromSeconds(0.5); 32 auto.Add(laserPyssy1); 33 laserPyssy2 = new LaserGun(20, 5); 53 34 54 35 55 auto2 = new Automobile(40, 20); 36 auto2.Mass = 10.0;56 auto2.Mass = 25.0; 37 57 auto2.Maneuverability = Angle.Degrees(120); 38 58 auto2.Color = new Color(192, 192, 255); 39 59 auto2.AngularDamping = 0.9; 60 auto2.X = Level.Left + 20.0; 61 40 62 Add(auto2); 41 63 42 auto2.Add(laserPyssy2); 43 44 45 for (int a = 0; a < 10; a++) 64 LisaaAseet(); 65 66 for (int a = 0; a < 21; a++) 46 67 { 47 68 LisaaOilBarrel(); 48 69 } 49 50 70 51 71 Camera.ZoomToLevel(5); 52 72 Level.CreateBorders(1.0, false); 53 Level.BackgroundColor = Color.Gray; 54 73 74 75 luoHpMittarit(); 55 76 AsetaNappaimet(); 56 77 AsetaXBoxOhjaimet(); 78 79 57 80 LataaRajahdys(); 58 81 ControllerOne.Vibrate(0.5, 0.5, 0.0, 0.0, 0.1); 82 } 83 void LisaaAseet() 84 { 85 laserPyssy1 = new LaserGun(20, 15); 86 laserPyssy1.Color = Color.Green; 87 laserPyssy1.TimeBetweenUse = TimeSpan.FromSeconds(0.6); 88 laserPyssy1.LaserCollision += laserOsuu; 89 auto.Add(laserPyssy1); 90 91 laserPyssy2 = new LaserGun(40, 5); 92 laserPyssy2.TimeBetweenUse = TimeSpan.FromSeconds(0.6 ); 93 laserPyssy2.LaserCollision += laserOsuu; 94 auto2.Add(laserPyssy2); 95 } 96 97 //Controller 98 99 void luoHpMittarit() 100 { 101 auton1hp = new DoubleMeter(100); 102 auton1hp.MaxValue = 100; 103 auton1hp.MinValue = 0; 104 auton1hp.LowerLimit += new Meter<double>.OnLimitHandler(auto1kuoli); 105 auton1palkki = new BarGauge(100, 15); 106 auton1palkki.BarColor = Color.Red; 107 auton1palkki.BorderColor = Color.Black; 108 auton1palkki.Position = new Vector(Screen.Right - 100, Screen.Top - 100); 109 auton1palkki.BindTo(auton1hp); 110 Add(auton1palkki); 111 112 auton2hp = new DoubleMeter(100); 113 auton2hp.MaxValue = 100; 114 auton2hp.MinValue = 0; 115 auton2hp.LowerLimit += new Meter<double>.OnLimitHandler(auto2kuoli); 116 auton2palkki = new BarGauge(100, 15); 117 auton2palkki.BarColor = Color.Red; 118 auton2palkki.BorderColor = Color.Black; 119 auton2palkki.Position = new Vector(Screen.Left + 100, Screen.Top - 100); 120 auton2palkki.BindTo(auton2hp); 121 Add(auton2palkki); 122 } 123 124 void auto2kuoli(double value) 125 { 126 auto2.Position = new Vector(Level.Left + 20, 0); 127 auton2hp.Value = 100; 128 } 129 130 void auto1kuoli(double value) 131 { 132 auto.Position = new Vector(Level.Right - 20, 0); 133 auton1hp.Value = 100; 59 134 } 60 135 … … 62 137 { 63 138 Image expl = LoadImage("Red"); 64 es = new ExplosionSystem(expl, 1000);139 es = new ExplosionSystem(expl, 500); 65 140 Add(es); 66 141 … … 69 144 void AsetaXBoxOhjaimet() 70 145 { 146 71 147 ControllerOne.ListenAnalog(AnalogControl.LeftStick, 0.1, LiikutaPelaajaa, "Liikuta pelaajaa tattia pyörittämällä."); 72 73 148 ControllerOne.Listen(Button.RightTrigger, ButtonState.Down, kiihdyta, null, auto); 149 ControllerOne.Listen(Button.LeftTrigger, ButtonState.Down, jarruta, null, auto); 150 ControllerTwo.ListenAnalog(AnalogControl.LeftStick, 0.1, LiikutaPelaajaa2, "Liikuta pelaajaa tattia pyörittämällä."); 151 ControllerTwo.Listen(Button.RightTrigger, ButtonState.Down, kiihdyta, null, auto2); 152 ControllerTwo.Listen(Button.LeftTrigger, ButtonState.Down, jarruta, null, auto2); 153 154 155 ControllerOne.Listen(Button.A, ButtonState.Down, Ammu, null, laserPyssy1, auto); 156 ControllerTwo.Listen(Button.A, ButtonState.Down, Ammu, null, laserPyssy2, auto2); 74 157 } 75 158 void LiikutaPelaajaa(AnalogState state) 76 159 { 77 160 auto.Turn(Angle.Degrees(state.StateVector.X * -4), Time.SinceLastUpdate.TotalSeconds); 161 } 162 void LiikutaPelaajaa2(AnalogState state) 163 { 164 auto2.Turn(Angle.Degrees(state.StateVector.X * -4), Time.SinceLastUpdate.TotalSeconds); 78 165 } 79 166 void AsetaNappaimet() … … 92 179 93 180 94 Keyboard.Listen(Key.M, ButtonState.Down, laserPyssy1.Use, "ammu"); 95 Keyboard.Listen(Key.V, ButtonState.Down, laserPyssy2.Use, "ammu"); 96 97 } 98 99 100 void laaserase() 101 { 102 //laserPyssy.LaserCollision = LaserSadeOsuu; 103 } 104 105 106 181 Keyboard.Listen(Key.M, ButtonState.Down, Ammu, "ammu", laserPyssy1, auto); 182 Keyboard.Listen(Key.V, ButtonState.Down, Ammu, "ammu", laserPyssy2, auto2); 183 184 } 185 186 void Ammu(LaserGun ase, PhysicsObject ampuja) 187 { 188 PhysicsObject ammus = ase.Shoot(); 189 if (ammus != null) 190 { 191 ammus.Width *= 2; 192 ammus.Height *=2; 193 ammus.Tag = ampuja; 194 AddCollisionHandler(ammus, laserOsuu); 195 } 196 } 197 198 void laserOsuu(PhysicsObject laser, PhysicsObject kohde) 199 { 200 if (kohde == auto && laser.Tag != auto) 201 { 202 auton1hp.Value -= 15; 203 } 204 if (kohde == auto2 && laser.Tag != auto2) 205 { 206 auton2hp.Value -= 15; 207 } 208 if (kohde.Tag.ToString() == "oilbarrel") 209 { 210 double etaisyys = Etaisyys(kohde.Position, auto.Position); 211 double etaisyys2 = Etaisyys(kohde.Position, auto2.Position); 212 if (etaisyys < 150) 213 { 214 VahennaHP(auto); 215 } 216 if (etaisyys2 < 150) 217 { 218 VahennaHP(auto2); 219 } 220 } 221 } 107 222 108 223 … … 122 237 } 123 238 239 double Etaisyys(Vector p1, Vector p2) 240 { 241 double dx = Math.Abs(p1.X - p2.X); 242 double dy = Math.Abs(p1.Y - p2.Y); 243 return Math.Sqrt(dx * dx + dy * dy); 244 } 124 245 125 246 126 247 void Rajahdys(PhysicsObject tormaaja, PhysicsObject kohde) 127 248 { 128 es.AddEffect(tormaaja.X, tormaaja.Y, 20);249 es.AddEffect(tormaaja.X, tormaaja.Y, 984); 129 250 tormaaja.Destroy(); 251 //if (kohde == auto && OilBarrel.Tag != auto) 252 253 VahennaHP(kohde); 254 LisaaOilBarrel(); 255 256 257 } 258 259 void VahennaHP(PhysicsObject kohde) 260 { 261 if (kohde == auto) 262 { 263 auton1hp.Value -= 75; 264 return; 265 } 266 // if (kohde == auto2 && OilBarrel.Tag != auto2) 267 if (kohde == auto2) 268 { 269 auton2hp.Value -= 75; 270 return; 271 272 } 130 273 } 131 274 … … 133 276 { 134 277 OilBarrel = new PhysicsObject(15, 15, Shapes.Circle); 135 OilBarrel.Color = Color.Red; 136 OilBarrel.Mass = 100; 278 OilBarrel.Mass = 1000; 137 279 OilBarrel.LinearDamping = 0.9; 280 OilBarrel.Tag = "oilbarrel"; 138 281 Add(OilBarrel); 139 282 AddCollisionHandler(OilBarrel, Rajahdys); 140 283 OilBarrel.X = RandomGen.NextDouble(Level.Left, Level.Right); 141 284 OilBarrel.Y = RandomGen.NextDouble(Level.Bottom, Level.Top); 285 OilBarrel.Color = RandomGen.NextColor(); 142 286 } 143 287
Note: See TracChangeset
for help on using the changeset viewer.