Changeset 315
- Timestamp:
- 2009-08-05 15:00:29 (11 years ago)
- Location:
- joonas_s
- Files:
-
- 37 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
joonas_s/Aliohjelma/Peli.cs
r236 r315 21 21 public class Peli : RealTimeGame 22 22 { 23 PhysicsObject Luopallo(double sade, int X, intY)23 PhysicsObject Luopallo(double sade, double X, double Y) 24 24 { 25 25 PhysicsObject pallo = new PhysicsObject(10, Shapes.CreateCircle(sade)); … … 41 41 void PiirraYmpyra() 42 42 { 43 PhysicsObject p3 = Luopallo(10, RandomGen.NextInt(0, 500), RandomGen.NextInt(0, 500)); 44 Level.Objects.Add(p3); 45 43 for (int i = 0; i < 20; i++) 44 { 45 PhysicsObject p3 = Luopallo(10, RandomGen.NextDouble( Level.Left, Level.Right), RandomGen.NextDouble(Level.Bottom,Level.Top)); 46 Level.Objects.Add(p3); 47 p3.Color = Color.Yellow; 48 if (i > 0) 49 { 50 i.Color = Color.Red; 51 } 52 46 53 54 } 47 55 } 48 56 -
joonas_s/Pong/Peli.cs
r236 r315 21 21 public class Peli : PhysicsGame 22 22 { 23 Vector2D nopeusYlos = new Vector2D(0, 200);24 Vector2D nopeusAlas = new Vector2D(0, - 200);23 Vector2D nopeusYlos = new Vector2D(0, 1000); 24 Vector2D nopeusAlas = new Vector2D(0, -1000); 25 25 26 26 PhysicsObject pallo; … … 28 28 PhysicsObject maila2; 29 29 30 Meter<int> pelaajan1Pisteet; 31 Meter<int> pelaajan2Pisteet; 32 30 33 protected override void LoadContent() 31 34 { 32 35 Level = LuoKentta(); 33 36 AsetaOhjaimet(); 37 LisaaLaskurit(); 34 38 AloitaPeli(); 35 39 } … … 40 44 kentta.BackgroundColor = Color.Black; 41 45 42 IShape ympyra = Shapes.CreateCircle(20 0.0);46 IShape ympyra = Shapes.CreateCircle(20.0); 43 47 pallo = new PhysicsObject(10.0, ympyra); 44 48 pallo.X = -200.0; 45 49 pallo.Y = 0.0; 46 pallo.Restitution = 1.1; 50 pallo.Color = Color.DarkGoldenrod; 51 pallo.Restitution = 1.5; 47 52 kentta.Objects.Add(pallo); 53 AddCollisionHandler(pallo, KasittelePallonTormays); 48 54 49 55 maila1 = LuoMaila(kentta.Left + 20.0, 0.0, kentta); … … 57 63 PhysicsObject LuoMaila(double x, double y, Level kentta) 58 64 { 59 IShape suorakulmio = Shapes.CreateRectangle(20.0, 100.0);65 IShape suorakulmio = Shapes.CreateRectangle(20.0, 200.0); 60 66 PhysicsObject maila = PhysicsObject.CreateStaticObject(suorakulmio); 61 67 maila.X = x; 62 68 maila.Y = y; 63 maila.Restitution = 1.1; 69 maila.Restitution = 1.5; 70 maila.Color = Color.LightGreen; 64 71 kentta.Objects.Add(maila); 65 72 return maila; 66 73 } 67 74 75 void LisaaLaskurit() 76 { 77 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 78 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 79 } 80 81 Meter<int> LuoPisteLaskuri(double x, double y) 82 { 83 Meter<int> laskuri = new Meter<int>(0, 0, 10); 84 ValueDisplay naytto = new ValueDisplay(this); 85 naytto.BindTo(laskuri); 86 naytto.X = x; 87 naytto.Y = y; 88 naytto.ValueColor = Color.White; 89 Add(naytto); 90 return laskuri; 91 } 92 93 void KasittelePallonTormays(Collision collision) 94 { 95 PhysicsObject pallo = collision.Obj; 96 PhysicsObject kohde = collision.Other; 97 98 if (kohde == Level.RightBorder) 99 { 100 pelaajan1Pisteet.Value += 1; 101 } 102 else if (kohde == Level.LeftBorder) 103 { 104 pelaajan2Pisteet.Value += 1; 105 } 106 } 107 68 108 void AloitaPeli() 69 109 { 70 Vector2D impulssi = new Vector2D( 20000.0, 2000.0);110 Vector2D impulssi = new Vector2D(5000.0, 2000.0); 71 111 pallo.Hit(impulssi); 72 112 } … … 118 158 } 119 159 } 120
Note: See TracChangeset
for help on using the changeset viewer.