Changeset 8260 for 2016/30/HenriJ/xx/xx
- Timestamp:
- 2016-07-29 13:24:45 (7 years ago)
- Location:
- 2016/30/HenriJ/xx/xx/xx
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/30/HenriJ/xx/xx/xx/xx.cs
r8095 r8260 9 9 public class xx : PhysicsGame 10 10 { 11 Vector nopeusYlos = new Vector(0, 200); 12 Vector nopeusAlas = new Vector(0, -200); 13 11 14 PhysicsObject gf; 12 13 15 PhysicsObject maila1; 14 16 PhysicsObject maila2; 17 18 PhysicsObject vasen; 19 PhysicsObject oikea; 20 21 IntMeter pisteet1; 22 IntMeter pisteet2; 15 23 public override void Begin() 16 24 { 17 25 LuoKentta(); 26 Laskuri(); 18 27 aloitapeli(); 19 28 Asetanäppäin(); … … 24 33 gf = new PhysicsObject(50.0, 50.0); 25 34 gf.Shape = Shape.Circle; 35 gf.Color = Color.DarkRed; 26 36 gf.X = -200.0; 27 37 gf.Y = 0.0; … … 29 39 Add(gf); 30 40 31 Luomaila(Level.Left + 20.0, 0.0);32 Luomaila(Level.Right - 20.0, 0.0);41 maila1 = Luomaila(Level.Left + 20.0, 0.0); 42 maila2 = Luomaila(Level.Right - 20.0, 0.0); 33 43 34 Level.CreateBorders(1.0, false); 44 vasen = Level.CreateLeftBorder(); 45 vasen.Restitution = 1.0; 46 vasen.IsVisible = false; 47 oikea = Level.CreateRightBorder(); 48 oikea.Restitution = 1.0; 49 oikea.IsVisible = false; 50 PhysicsObject alapuoli = Level.CreateBottomBorder(); 51 alapuoli.Restitution = 1.0; 52 alapuoli.IsVisible = false; 53 PhysicsObject ylapuoli = Level.CreateTopBorder(); 54 ylapuoli.Restitution = 1.0; 55 ylapuoli.IsVisible = false; 56 57 AddCollisionHandler(gf, kasittelepallo); 35 58 36 59 Camera.ZoomToLevel(); … … 42 65 gf.Hit(impulssi); 43 66 } 44 voidLuomaila(double x, double y)67 PhysicsObject Luomaila(double x, double y) 45 68 { 46 69 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 47 70 maila.Shape = Shape.Rectangle; 71 maila.Color = Color.BloodRed; 48 72 maila.X = x; 49 73 maila.Y = y; 50 74 maila.Restitution = 1.0; 51 75 Add(maila); 76 return maila; 52 77 } 53 78 void Asetanäppäin() … … 55 80 Keyboard.Listen(Key.A, ButtonState.Down, Asetanopeus, "Pelaaja 1: Liikuta mailaa ylos", maila1, nopeusYlos); 56 81 Keyboard.Listen(Key.A, ButtonState.Released, Asetanopeus, null, maila1, Vector.Zero); 82 Keyboard.Listen(Key.Z, ButtonState.Down, Asetanopeus, "Pelaaja 1: Liikuta mailaa ylos", maila1, nopeusAlas); 83 Keyboard.Listen(Key.Z, ButtonState.Released, Asetanopeus, null, maila1, Vector.Zero); 84 85 Keyboard.Listen(Key.Up, ButtonState.Down, Asetanopeus, "Pelaaja 2: Liikuta mailaa ylos", maila2, nopeusYlos); 86 Keyboard.Listen(Key.Up, ButtonState.Released, Asetanopeus, null, maila2, Vector.Zero); 87 Keyboard.Listen(Key.Down, ButtonState.Down, Asetanopeus, "Pelaaja 2: Liikuta mailaa ylos", maila2, nopeusAlas); 88 Keyboard.Listen(Key.Down, ButtonState.Released, Asetanopeus, null, maila2, Vector.Zero); 57 89 58 90 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); … … 62 94 void Asetanopeus(PhysicsObject maila, Vector nopeus) 63 95 { 96 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 97 { 98 maila.Velocity = Vector.Zero; 99 return; 100 } 64 101 maila.Velocity = nopeus; 65 102 } 103 void Laskuri() 104 { 105 pisteet1 = Luolaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 106 pisteet2 = Luolaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 107 108 } 109 IntMeter Luolaskuri(double x, double y) 110 { 111 IntMeter laskuri = new IntMeter(0); 112 laskuri.MaxValue = 10; 113 114 Label naytto = new Label(); 115 naytto.BindTo(laskuri); 116 naytto.X = x; 117 naytto.Y = y; 118 naytto.TextColor = Color.White; 119 naytto.BorderColor = Level.Background.Color; 120 naytto.Color = Level.Background.Color; 121 Add (naytto); 122 return laskuri; 123 } 124 void kasittelepallo(PhysicsObject gf, PhysicsObject kohde) 125 { 126 if (kohde == oikea) 127 { 128 pisteet1.Value += 1; 129 } 130 else if (kohde == vasen) 131 { 132 pisteet2.Value += 1; 133 } 134 135 } 136 66 137 }
Note: See TracChangeset
for help on using the changeset viewer.