Changeset 6185
- Timestamp:
- 2015-06-23 14:57:02 (8 years ago)
- Location:
- 2015/26/SanteriP
- Files:
-
- 56 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/26/SanteriP/Pong/Pong/Pong/Pong.cs
r6144 r6185 9 9 public class Pong : PhysicsGame 10 10 { 11 12 Vector nopeusYlös = new Vector(0, 200); 13 Vector nopeusAlas = new Vector(0, -200); 14 11 15 PhysicsObject pallo; 16 17 PhysicsObject maila1; 18 PhysicsObject maila2; 19 20 PhysicsObject vasenReuna; 21 PhysicsObject oikeaReuna; 22 23 IntMeter pelaajan1Pisteet; 24 IntMeter pelaajan2Pisteet; 12 25 13 26 public override void Begin() 14 27 { 15 // TODO: Kirjoita ohjelmakoodisi tähän16 28 LuoKentta(); 29 asetaohjaimet(); 30 LisaaLaskurit(); 17 31 AloitaPeli(); 32 } 18 33 19 Keyboard.Listen(Key.A, ButtonState.Down,LiikutaMaila1Ylos, "Pelaaja 1: Liikuta mailaa ylös"); 34 void LisaaLaskurit() 35 { 36 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 37 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 38 } 20 39 40 IntMeter LuoPisteLaskuri(double x, double y) 41 { 42 IntMeter laskuri = new IntMeter(0); 43 laskuri.MaxValue = 10; 44 45 Label nayttö = new Label(); 46 nayttö.BindTo(laskuri); 47 nayttö.X = x; 48 nayttö.Y = y; 49 nayttö.TextColor = Color.White; 50 nayttö.BorderColor = Level.Background.Color; 51 nayttö.Color = Level.Background.Color; 52 Add(nayttö); 53 54 return laskuri; 55 } 56 void asetaohjaimet() 57 { 58 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlös); 59 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 60 61 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 62 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 63 64 65 66 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlös); 67 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 68 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 69 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 70 71 72 73 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 21 74 22 75 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); … … 32 85 Add(pallo); 33 86 87 AddCollisionHandler(pallo, KasittelePallonTormaus); 88 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 89 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 34 90 35 LuoMaila(Level.Left + 20.0, 0.0); 36 LuoMaila(Level.Right - 20.0, 0.0); 91 vasenReuna = Level.CreateLeftBorder(); 92 vasenReuna.Restitution = 1.0; 93 vasenReuna.KineticFriction = 0.0; 94 vasenReuna.IsVisible = false; 37 95 38 Level.CreateBorders(1.0, false); 96 oikeaReuna = Level.CreateRightBorder(); 97 oikeaReuna.Restitution = 1.0; 98 oikeaReuna.KineticFriction = 0.0; 99 oikeaReuna.IsVisible = false; 100 101 PhysicsObject ylaReuna = Level.CreateTopBorder(); 102 ylaReuna.Restitution = 1.0; 103 ylaReuna.KineticFriction = 0.0; 104 ylaReuna.IsVisible = false; 105 106 PhysicsObject alaReuna = Level.CreateBottomBorder(); 107 alaReuna.Restitution = 1.0; 108 alaReuna.IsVisible = false; 109 alaReuna.KineticFriction = 0.0; 39 110 40 111 Level.Background.Color = Color.Black; 41 42 43 44 45 112 46 113 Camera.ZoomToLevel(); 47 114 48 115 } 49 50 voidLuoMaila(double x, double y)116 117 PhysicsObject LuoMaila(double x, double y) 51 118 { 52 119 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); … … 56 123 maila.Restitution = 1.0; 57 124 Add(maila); 125 return maila; 126 } 127 void KasittelePallonTormaus(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 } 58 137 } 59 138 … … 64 143 pallo.Hit(impulssi); 65 144 } 145 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 146 { 147 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 148 { 149 maila.Velocity = Vector.Zero; 150 return; 151 } 152 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 153 { 154 maila.Velocity = Vector.Zero; 155 return; 156 157 } 158 159 maila.Velocity = nopeus; 160 } 161 66 162 67 163 } -
2015/26/SanteriP/Pong/Pong/Pong/obj/x86/Debug/ContentPipeline-{44E55511-5866-492E-BFE2-174CEE65073D}.xml
r6144 r6185 9 9 <BuildConfiguration>Debug</BuildConfiguration> 10 10 <CompressContent>false</CompressContent> 11 <RootDirectory>C:\MyTemp\ santerip\Pong\Pong\PongContent\</RootDirectory>12 <LoggerRootDirectory>C:\MyTemp\ santerip\Pong\Pong\Pong\</LoggerRootDirectory>13 <IntermediateDirectory>C:\MyTemp\ santerip\Pong\Pong\Pong\obj\x86\Debug\</IntermediateDirectory>14 <OutputDirectory>C:\MyTemp\ santerip\Pong\Pong\Pong\bin\x86\Debug\Content\</OutputDirectory>11 <RootDirectory>C:\MyTemp\SanteriP\Pong\Pong\PongContent\</RootDirectory> 12 <LoggerRootDirectory>C:\MyTemp\SanteriP\Pong\Pong\Pong\</LoggerRootDirectory> 13 <IntermediateDirectory>C:\MyTemp\SanteriP\Pong\Pong\Pong\obj\x86\Debug\</IntermediateDirectory> 14 <OutputDirectory>C:\MyTemp\SanteriP\Pong\Pong\Pong\bin\x86\Debug\Content\</OutputDirectory> 15 15 </Settings> 16 16 <Assemblies> 17 17 <Assembly> 18 18 <Key>C:\Windows\Microsoft.Net\assembly\GAC_32\Microsoft.Xna.Framework.Content.Pipeline\v4.0_4.0.0.0__842cf8be1de50553\Microsoft.Xna.Framework.Content.Pipeline.dll</Key> 19 <Value>201 2-03-16T14:33:41.9515583+02:00</Value>19 <Value>2014-04-23T00:30:18.4504836+03:00</Value> 20 20 </Assembly> 21 21 </Assemblies>
Note: See TracChangeset
for help on using the changeset viewer.