- Timestamp:
- 2014-07-01 14:55:46 (9 years ago)
- Location:
- 2014/27/EmilK
- Files:
-
- 83 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2014/27/EmilK/pili pali pong/pili pali pong/pili pali pong/pili_pali_pong.cs
r5168 r5240 9 9 public class pili_pali_pong : PhysicsGame 10 10 { 11 Vector nopeusYlos = new Vector(0, 200); 12 Vector nopeusAlas = new Vector(0, -200); 13 11 14 PhysicsObject pallo; 15 PhysicsObject maila1; 16 PhysicsObject maila2; 12 17 18 PhysicsObject vasenReuna; 19 PhysicsObject oikeaReuna; 20 21 IntMeter pelaajan1Pisteet; 22 IntMeter pelaajan2Pisteet; 13 23 14 24 public override void Begin() … … 16 26 { 17 27 LuoKentta(); 18 19 Vector impulssi = new Vector(500.0, 0.0);20 pallo.Hit(impulssi);28 AloitaPeli(); 29 AsetaOhjaimet(); 30 LisaaLaskurit(); 21 31 22 32 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 23 33 } 24 34 void AloitaPeli() 35 { 36 Vector impulssi = new Vector(500.0, 0.0); 37 pallo.Hit(impulssi); 38 } 25 39 void LuoKentta() 26 40 { 27 41 pallo = new PhysicsObject(40.0, 40.0); 28 42 Add(pallo); 29 Level.CreateBorders(1.0, false); 43 44 oikeaReuna = Level.CreateRightBorder(); 45 oikeaReuna.Restitution = 1.0; 46 oikeaReuna.IsVisible = false; 47 48 PhysicsObject alaReuna = Level.CreateBottomBorder(); 49 alaReuna.Restitution = 1.0; 50 alaReuna.IsVisible = false; 51 52 PhysicsObject yläReuna = Level.CreateTopBorder(); 53 yläReuna.Restitution = 1.0; 54 yläReuna.IsVisible = false; 55 56 vasenReuna = Level.CreateLeftBorder(); 57 vasenReuna.Restitution = 1.0; 58 vasenReuna.IsVisible = false; 59 30 60 Vector impulssi = new Vector(500.0, 0.0); 31 61 pallo.Hit(impulssi); … … 35 65 pallo.Restitution = 1.0; 36 66 67 68 69 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 70 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 71 72 AddCollisionHandler(pallo, KasittelePallonTormays); 73 74 75 Level.Background.Color = Color.Black; 76 Camera.ZoomToLevel(); 77 78 } 79 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 80 { 81 if (kohde == oikeaReuna) 82 { 83 pelaajan1Pisteet.Value += 1; 84 } 85 else if (kohde == vasenReuna) 86 { 87 pelaajan2Pisteet.Value += 1; 88 } 89 } 90 PhysicsObject LuoMaila(double x, double y) 91 92 { 37 93 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 38 94 maila.Shape = Shape.Rectangle; 39 maila.X = Level.Left + 20.0;40 maila.Y = 0.0;95 maila.X = x; 96 maila.Y = y; 41 97 maila.Restitution = 1.0; 42 98 Add(maila); 43 Level.Background.Color = Color.Black; 44 Camera.ZoomToLevel(); 99 return maila; 100 } 101 void AsetaOhjaimet() 102 { 103 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 104 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 105 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 106 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 107 108 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 109 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 110 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 111 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 112 113 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 45 114 115 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 116 } 117 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 118 { 119 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 120 { 121 maila.Velocity = Vector.Zero; 122 return; 123 } 124 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 125 { 126 maila.Velocity = Vector.Zero; 127 return; 128 } 129 maila.Velocity = nopeus; 130 } 131 void LisaaLaskurit() 132 { 133 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 134 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 135 } 136 IntMeter LuoPisteLaskuri(double x, double y) 137 { 138 IntMeter laskuri = new IntMeter(0); 139 laskuri.MaxValue = 10; 46 140 47 } 48 141 Label naytto = new Label(); 142 naytto.BindTo(laskuri); 143 naytto.X = x; 144 naytto.Y = y; 145 naytto.TextColor = Color.White; 146 naytto.BorderColor = Level.Background.Color; 147 naytto.Color = Level.Background.Color; 148 Add(naytto); 149 150 return laskuri; 151 } 49 152 }
Note: See TracChangeset
for help on using the changeset viewer.