Changeset 8216
- Timestamp:
- 2016-07-28 14:56:32 (7 years ago)
- Location:
- 2016/30/PyryS/Peli
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/30/PyryS/Peli/Peli/Peli/Peli.cs
r8171 r8216 6 6 using Jypeli.Effects; 7 7 using Jypeli.Widgets; 8 using System.Collections.Generic; 8 9 9 10 public class Peli : PhysicsGame … … 15 16 Vector nopeusVasempaan = new Vector(-50000, 0); 16 17 17 AssaultRifle vihu1Laser;18 Pelaaja pelaaja; 18 19 AssaultRifle pelaajanAse; 19 20 PhysicsObject wihu; 21 PhysicsObject vihu; 22 PhysicsObject pelaaja; 20 23 21 PhysicsObject oikeareuna; 24 22 PhysicsObject vasenreuna; 25 23 24 26 25 public override void Begin() 27 26 { … … 29 28 30 29 Leveli(); 30 LuoPelaaja(0, -400); 31 31 Ohjaimet(); 32 33 34 35 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 32 Vihollinen2Ase(); 33 Vihollinen2(Level.Right, 0); 34 35 Timer vihuSpawnausAika = new Timer(); 36 vihuSpawnausAika.Interval = 2.0; 37 vihuSpawnausAika.Timeout += delegate { LuoVihollinen(Level.Right, 20); }; 38 vihuSpawnausAika.Start(7); 39 40 41 42 43 36 44 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 37 45 } … … 39 47 void LuoVihollinen(double x, double y) 40 48 { 41 Vihollinen vihu1 = new Vihollinen( 40.0, 40.0);49 Vihollinen vihu1 = new Vihollinen(x, y); 42 50 vihu1.X = x; 43 51 vihu1.Y = y; 52 vihu1.LifetimeLeft = TimeSpan.FromSeconds(10.0); 44 53 //vihu1.CollisionIgnoreGroup = 1; 54 AddCollisionHandler(vihu1, "joku", CollisionHandler.AddMeterValue(vihu1.VihuHealth, -1)); 55 vihu1.CanRotate = false; 56 vihu1.CollisionIgnoreGroup = 3; 45 57 Add(vihu1); 58 46 59 47 60 //AddCollisionHandler(vihu1, "joku", VihuunOsuu); 48 vihu1Laser = new AssaultRifle(30, 10);61 AssaultRifle vihu1Laser = new AssaultRifle(30, 10); 49 62 vihu1Laser.InfiniteAmmo = true; 63 vihu1Laser.Angle = Angle.FromDegrees(-90); 50 64 vihu1Laser.ProjectileCollision = VihuOsuu; 51 65 vihu1.Add(vihu1Laser); 52 66 53 67 Timer ammusajastin = new Timer(); 54 ammusajastin.Interval = 1.5;55 ammusajastin.Timeout += V1LaserAmpuu;68 ammusajastin.Interval = 0.2; 69 ammusajastin.Timeout += delegate() { V1LaserAmpuu(vihu1Laser); }; 56 70 ammusajastin.Start(); 57 71 58 72 59 60 61 } 62 void Leveli() 63 { 64 65 pelaaja = new PhysicsObject(40.0, 40.0); 73 PathFollowerBrain vihu1Aivot = new PathFollowerBrain(200); 74 75 76 77 List<Vector> polku = new List<Vector>(); 78 polku.Add(new Vector(Level.Right, 0)); 79 polku.Add(new Vector(Level.Right - 50, 0)); 80 polku.Add(new Vector(Level.Right - 100, 10)); 81 polku.Add(new Vector(Level.Right - 200, 50)); 82 polku.Add(new Vector(Level.Right - 250, 100)); 83 polku.Add(new Vector(Level.Right - 300, 125)); 84 polku.Add(new Vector(Level.Right - 350, 150)); 85 polku.Add(new Vector(Level.Right - 400, 200)); 86 polku.Add(new Vector(Level.Right - 450, 250)); 87 polku.Add(new Vector(Level.Right - 650, 600)); 88 //polku.Add(new Vector(-100, 50)); 89 //polku.Add(new Vector(-250, -200)); 90 91 vihu1Aivot.Path = polku; 92 vihu1Aivot.Loop = false; 93 vihu1Aivot.Speed = 200; 94 95 vihu1.Brain = vihu1Aivot; 96 97 98 99 100 101 102 103 104 } 105 void LuoPelaaja(double x, double y) 106 { 107 pelaaja = new Pelaaja(40.0, 40.0); 66 108 pelaaja.Shape = Shape.Triangle; 67 109 pelaaja.X = 0.0; … … 72 114 pelaaja.MaxVelocity = 1.0; 73 115 pelaaja.CanRotate = false; 116 AddCollisionHandler(pelaaja, "vihu1Luoti", VahennaElamaa); 74 117 Add(pelaaja); 75 118 76 119 PelaanjaAse(); 77 78 120 } 121 void Leveli() 122 { 79 123 oikeareuna = Level.CreateRightBorder(); 80 124 vasenreuna = Level.CreateLeftBorder(); 125 oikeareuna.CollisionIgnoreGroup = 3; 126 vasenreuna.CollisionIgnoreGroup = 3; 81 127 oikeareuna.Restitution = 0.0; 82 128 vasenreuna.Restitution = 0.0; 129 Level.BackgroundColor = Color.Black; 83 130 84 vihu = new Vihollinen(50.0, 50.0);85 wihu = new Vihollinen(-50, -50);86 131 87 132 … … 111 156 { 112 157 laser.Destroy(); 113 if (kohde == pelaaja) 114 { 115 kohde.Destroy(); 116 } 158 117 159 } 118 160 119 161 void PelaanjaAse () 120 162 { 121 pelaajanAse = new AssaultRifle( 30, 10);163 pelaajanAse = new AssaultRifle(10, 10); 122 164 pelaajanAse.InfiniteAmmo = true; 123 //pelaajanAse.ProjectileCollision = PelaajaaOsuu;165 pelaajanAse.ProjectileCollision = PelaajaOsuu; 124 166 pelaajanAse.Angle = Angle.FromDegrees(90); 125 167 pelaajanAse.Image = null; … … 127 169 } 128 170 129 void V1LaserAmpuu () 130 { 131 PhysicsObject laser = vihu1Laser.Shoot(); 171 void PelaajaOsuu (PhysicsObject luoti, PhysicsObject kohde) 172 { 173 174 if (kohde is Vihollinen) 175 { 176 luoti.Destroy(); 177 } 178 179 } 180 181 void V1LaserAmpuu (AssaultRifle ase) 182 { 183 PhysicsObject laser = ase.Shoot(); 132 184 133 185 if (laser != null) 134 186 { 135 Vector vihuAmpumisSuunta = (pelaaja.Position - vihu.Position).Normalize();187 Vector vihuAmpumisSuunta = (pelaaja.Position - ase.Position).Normalize(); 136 188 laser.Velocity = vihuAmpumisSuunta * 300; 189 laser.Tag = "vihu1Luoti"; 137 190 laser.Angle = vihuAmpumisSuunta.Angle; 138 191 laser.CollisionIgnoreGroup = 2; … … 147 200 { 148 201 pelaajanammus.Size *= 3; 149 //pelaajanammus.Tag = "joku";202 pelaajanammus.Tag = "joku"; 150 203 pelaajanammus.CollisionIgnoreGroup = 2; 151 }152 153 }154 155 void PelaajaaOsuu (PhysicsObject luoti, PhysicsObject kohde)156 {157 luoti.Destroy();158 if (kohde == vihu)159 {160 kohde.Destroy();161 204 162 205 } 163 } 164 /*void VihuunOsuu (PhysicsObject vihu, PhysicsObject ammus) 165 { 166 vihu.Destroy(); 167 ammus.Destroy(); 168 169 }*/ 206 207 } 208 209 void VahennaElamaa(PhysicsObject pelaaja, PhysicsObject luoti) 210 { 211 (pelaaja as Pelaaja).VahennaElamaa(); 212 } 213 214 void Vihollinen2(double x, double y) 215 { 216 Vihollinen2 vihu2 = new Vihollinen2(50, 50); 217 vihu2.Color = Color.Red; 218 vihu2.X = x; 219 vihu2.Y = y; 220 vihu2.CanRotate = false; 221 vihu2.CollisionIgnoreGroup = 3; 222 AddCollisionHandler(vihu2, "joku", CollisionHandler.AddMeterValue(vihu2.Vihu2Health, -1)); 223 Add(vihu2); 224 225 226 227 PathFollowerBrain vihu2Aivot = new PathFollowerBrain(200); 228 229 230 231 List<Vector> polku = new List<Vector>(); 232 polku.Add(new Vector(Level.Right, 0)); 233 polku.Add(new Vector(Level.Left + 20, 0)); 234 polku.Add(new Vector(0, 400)); 235 polku.Add(new Vector(Level.Right + 10000, 0)); 236 237 vihu2Aivot.Path = polku; 238 vihu2Aivot.Loop = false; 239 vihu2Aivot.Speed = 200; 240 241 vihu2.Brain = vihu2Aivot; 242 243 } 244 245 void Vihollinen2Ase() 246 { 247 PhysicsObject clusterBall = new PhysicsObject(75, 75); 248 clusterBall.Shape = Shape.Circle; 249 250 251 Add(clusterBall); 252 } 170 253 171 254 } 172 255 class Vihollinen : PhysicsObject 173 256 { 257 private IntMeter vihuHealth = new IntMeter(2, 0, 2); 258 public IntMeter VihuHealth { get { return vihuHealth; } } 259 260 261 public Vihollinen(double leveys, double korkeus) 262 : base(40, 40) 263 { 264 VihuHealth.LowerLimit += delegate { this.Destroy(); }; 265 } 266 267 268 269 } 270 271 class Pelaaja : PhysicsObject 272 { 174 273 private IntMeter elamaLaskuri = new IntMeter(3, 0, 3); 175 274 public IntMeter ElamaLaskuri { get { return elamaLaskuri; } } 176 177 public Vihollinen(double leveys, double korkeus) 275 private bool voikoOttaaOsumaa = true; 276 public Pelaaja(double leveys, double korkeus) 277 : base(leveys, korkeus) 278 { 279 elamaLaskuri.LowerLimit += delegate { this.Destroy(); }; 280 } 281 public void VahennaElamaa () 282 { 283 if (voikoOttaaOsumaa) 284 { 285 elamaLaskuri.Value -= 1; 286 voikoOttaaOsumaa = false; 287 Timer.SingleShot(1, delegate { voikoOttaaOsumaa = true; }); 288 } 289 } 290 } 291 292 class Vihollinen2 : PhysicsObject 293 { 294 private IntMeter vihu2Health = new IntMeter(10, 0, 10); 295 public IntMeter Vihu2Health { get { return vihu2Health; } } 296 297 298 public Vihollinen2(double leveys, double korkeus) 178 299 : base(40, 40) 179 300 { 180 elamaLaskuri.LowerLimit += delegate { this.Destroy(); }; 181 } 301 Vihu2Health.LowerLimit += delegate { this.Destroy(); }; 302 } 303 182 304 183 305 184 306 } 185 307 308
Note: See TracChangeset
for help on using the changeset viewer.