Changeset 5535
- Timestamp:
- 2014-07-22 14:01:45 (9 years ago)
- Location:
- 2014/30/AarniAR
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2014/30/AarniAR/Pongo/Pongo/Pongo/Pongo.cs
r5516 r5535 11 11 PhysicsObject pallo; 12 12 Vector nopeusylos = new Vector(0, 200); 13 Vector nopeusalas = new Vector(0, 200); 13 Vector nopeusalas = new Vector(0, -200); 14 PhysicsObject vasenReuna; 15 PhysicsObject oikeaReuna; 14 16 15 17 PhysicsObject maila1; 16 18 PhysicsObject maila2; 19 20 IntMeter pelaajan1Pisteet; 21 IntMeter pelaajan2Pisteet; 17 22 18 23 public override void Begin() … … 24 29 25 30 aloitapeli(); 31 lisaalaskurit(); 26 32 27 33 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli"); 28 34 } 29 35 30 36 31 37 void Luokentta() … … 33 39 pallo = new PhysicsObject(50.0, 55.0); 34 40 Add(pallo); 35 pallo.Shape = Shape. Diamond;41 pallo.Shape = Shape.Circle; 36 42 pallo.Color = Color.DarkRed; 37 43 pallo.X = Level.Left + 80.0; 38 44 pallo.Y = 0.0; 39 45 40 maila1 = luomaila(Level.Left + 20.0, 0.0); 46 maila1 = luomaila(Level.Left + 20.0, 0.0); 47 maila2 = luomaila(Level.Right - 20.0, 0.0); 48 vasenReuna = Level.CreateLeftBorder(); 49 vasenReuna.Restitution = 1.0; 50 vasenReuna.IsVisible = false; 51 oikeaReuna = Level.CreateRightBorder(); 52 oikeaReuna.Restitution = 1.0; 53 vasenReuna.IsVisible = false; 54 PhysicsObject alaReuna = Level.CreateBottomBorder(); 55 alaReuna.Restitution = 1.0; 56 alaReuna.IsVisible = true; 57 PhysicsObject ylareuna = Level.CreateTopBorder(); 58 ylareuna.Restitution = 1.0; 59 ylareuna.IsVisible = true; 41 60 42 Level.CreateBorders(1.0, true); 43 61 44 62 pallo.Restitution = 1.0; 45 pallo.CanRotate = false;63 pallo.CanRotate = true; 46 64 Level.Background.Color = Color.Emerald; 47 65 Camera.Zoom(1.3); 48 49 PhysicsObject maila2 = PhysicsObject.CreateStaticObject(30.0, 200.0); 50 maila2.Shape = Shape.Circle; 51 maila2.X = Level.Right - 20.0; 52 maila2.Y = 0.0; 53 maila2.Restitution = 1.0; 54 Add(maila2); 66 AddCollisionHandler(pallo, KasittelePallonTormays); 55 67 } 56 68 void aloitapeli() … … 59 71 pallo.Hit(impulssi); 60 72 61 73 62 74 } 63 PhysicsObject luomaila(double X, double Y)75 PhysicsObject luomaila(double x, double y) 64 76 { 65 77 PhysicsObject maila = PhysicsObject.CreateStaticObject(30.0, 200.0); 66 78 maila.Shape = Shape.Circle; 67 maila.X = Level.Left + 20.0;68 maila.Y = 0.0;79 maila.X = x; 80 maila.Y = y; 69 81 maila.Restitution = 1.0; 70 82 Add(maila); … … 75 87 { 76 88 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 77 Keyboard.Listen(Key.Up, ButtonState. Pressed, asetanopeus, "liiku ylos",maila1,nopeusylos);89 Keyboard.Listen(Key.Up, ButtonState.Down, asetanopeus, "liiku ylos", maila1, nopeusylos); 78 90 Keyboard.Listen(Key.Up, ButtonState.Released, asetanopeus, null, maila1, Vector.Zero); 79 Keyboard.Listen(Key. Down, ButtonState.Pressed, asetanopeus, "liiku alas", maila1, nopeusalas); 91 Keyboard.Listen(Key.Down, ButtonState.Down, asetanopeus, "liiku alas", maila1, nopeusalas); 92 Keyboard.Listen(Key.Down, ButtonState.Released, asetanopeus, null, maila1, Vector.Zero); 80 93 94 Keyboard.Listen(Key.W, ButtonState.Down, asetanopeus, "liiku ylös", maila2, nopeusylos); 95 Keyboard.Listen(Key.W, ButtonState.Released, asetanopeus, null, maila2, Vector.Zero); 96 Keyboard.Listen(Key.S, ButtonState.Down, asetanopeus, "liiku alas", maila2, nopeusalas); 97 Keyboard.Listen(Key.S, ButtonState.Released, asetanopeus, null, maila2, Vector.Zero); 98 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "näytä ohjeet"); 81 99 } 82 100 void asetanopeus(PhysicsObject maila, Vector nopeus) 83 101 { 102 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 103 { 104 maila.Velocity = Vector.Zero; 105 return; 106 } 107 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 108 { 109 maila.Velocity = Vector.Zero; 110 return; 111 } 112 84 113 maila.Velocity = nopeus; 114 115 } 116 void lisaalaskurit() 117 { 118 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 119 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 120 } 121 IntMeter LuoPisteLaskuri(double x, double y) 122 { 123 IntMeter laskuri = new IntMeter(0); 124 laskuri.MaxValue = 100; 125 126 Label naytto = new Label(); 127 naytto.BindTo(laskuri); 128 naytto.X = x; 129 naytto.Y = y; 130 naytto.TextColor = Color.Yellow; 131 naytto.BorderColor = Level.Background.Color; 132 naytto.Color = Level.Background.Color; 133 Add(naytto); 134 return laskuri; 135 } 136 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 137 { 138 if (kohde == oikeaReuna) 139 { 140 pelaajan1Pisteet.Value += 1; 141 } 142 else if (kohde == vasenReuna) 143 { 144 pelaajan2Pisteet.Value += 1; 145 } 146 85 147 } 86 148 } 87
Note: See TracChangeset
for help on using the changeset viewer.