Changeset 2968
- Timestamp:
- 2012-06-13 09:37:07 (11 years ago)
- Location:
- 2012/24/AnttoniS
- Files:
-
- 45 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
2012/24/AnttoniS/Pong/Pong.sln
r2915 r2968 4 4 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pong", "Pong\Pong\Pong.csproj", "{1EEF96B7-AF40-48FC-BD3F-A15296E0C48A}" 5 5 EndProject 6 Project("{ 96E2B04D-8817-42C6-938A-82C39BA4D311}") = "PongContent", "Pong\PongContent\PongContent.contentproj", "{0DA0C7C8-574C-485E-A440-D79D48E7AD0C}"6 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PongContent", "Pong\PongContent\PongContent.contentproj", "{0DA0C7C8-574C-485E-A440-D79D48E7AD0C}" 7 7 EndProject 8 8 Global -
2012/24/AnttoniS/Pong/Pong/Pong/Pong.cs
r2915 r2968 9 9 public class Pong : PhysicsGame 10 10 { 11 Vector nopeusYlos = new Vector(0, 200);12 Vector nopeusAlas = new Vector(0, - 200);11 Vector nopeusYlos = new Vector(0, 1000); 12 Vector nopeusAlas = new Vector(0, -1000); 13 13 14 14 PhysicsObject pallo; … … 17 17 PhysicsObject maila2; 18 18 19 PhysicsObject vasenReuna; 20 PhysicsObject oikeaReuna; 21 22 IntMeter pelaajan1Pisteet; 23 IntMeter pelaajan2pisteet; 24 19 25 public override void Begin() 20 26 { … … 22 28 LuoKentta(); 23 29 AsetaOhjaimet(); 30 LisaaLaskurit(); 24 31 AloitaPeli(); 25 32 … … 38 45 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2 : Liikuta mailaa ylös", maila2, nopeusYlos); 39 46 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 40 Keyboard.Listen(Key.Down, ButtonState.Down 47 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikutaa mailaa alas", maila2, nopeusAlas); 48 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 49 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 41 50 Keyboard.Listen (Key.Escape, ButtonState.Pressed,ConfirmExit, "Lopeta peli" ); 42 51 } … … 47 56 void AloitaPeli() 48 57 { 49 Vector impulssi = new Vector( 500, 0.0);58 Vector impulssi = new Vector(2000, 1.0); 50 59 pallo.Hit(impulssi); 51 60 } 52 61 void LuoKentta() 53 62 { 54 pallo = new PhysicsObject( 40, 40);63 pallo = new PhysicsObject(50, 50); 55 64 Add(pallo); 56 65 pallo.Color = Color.Yellow; … … 60 69 pallo.Restitution = 1.0; 61 70 Add(pallo); 71 AddCollisionHandler(pallo, KasittelePallonTormays); 62 72 63 73 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 64 74 maila2 = LuoMaila(Level.Right - 20.0,0.0); 65 75 66 Level.CreateBorders(1.0, false); 76 vasenReuna = Level.CreateLeftBorder(); 77 vasenReuna.Restitution = 1.0; 78 vasenReuna.IsVisible = false; 79 oikeaReuna = Level.CreateRightBorder(); 80 oikeaReuna.Restitution = 1.0; 81 oikeaReuna.IsVisible = false; 82 PhysicsObject ylaReuna = Level.CreateTopBorder(); 83 ylaReuna.Restitution = 1.0; 84 ylaReuna.IsVisible = false; 85 PhysicsObject alaReuna = Level.CreateBottomBorder(); 86 alaReuna.Restitution = 1.0; 87 alaReuna.IsVisible = false; 67 88 pallo.Restitution = 1.0; 68 89 Level.BackgroundColor = Color.YellowGreen; … … 83 104 return maila; 84 105 } 106 107 void LisaaLaskurit() 108 { 109 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 110 pelaajan2pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 111 } 112 113 IntMeter LuoPisteLaskuri( double x, double y) 114 { 115 IntMeter laskuri = new IntMeter(0); 116 laskuri.MaxValue = 10; 117 Label naytto = new Label(); 118 naytto.BindTo(laskuri); 119 naytto.X = x; 120 naytto.Y = y; 121 naytto.TextColor = Color.White; 122 naytto.BorderColor = Level.BackgroundColor; 123 naytto.Color = Level.BackgroundColor; 124 Add(naytto); 125 return laskuri; 126 } 127 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 128 { 129 if (kohde == oikeaReuna) 130 { 131 pelaajan1Pisteet.Value += 1; 132 } 133 else if (kohde == vasenReuna) 134 { 135 pelaajan2pisteet.Value += 1; 136 } 137 } 138 139 140 141 142 143 144 145 146 147 148 149 150 85 151 }
Note: See TracChangeset
for help on using the changeset viewer.