Changeset 1570
- Timestamp:
- 2010-08-03 14:56:35 (12 years ago)
- Location:
- 2010/31/arsajukk/Pong
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/31/arsajukk/Pong/Content/Content.contentproj
r1529 r1570 1 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">1 <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5"> 2 2 <PropertyGroup> 3 3 <ProjectGuid>8ad7a651-3f1c-4a35-8e22-f226cc4eee7c</ProjectGuid> … … 34 34 <Reference Include="Microsoft.Xna.Framework.Content.Pipeline.XImporter, Version=3.1.0.0, Culture=neutral, PublicKeyToken=6d5c3888ef60e27d" /> 35 35 </ItemGroup> 36 <ItemGroup> 37 <Compile Include="head.png"> 38 <Name>head</Name> 39 <Importer>TextureImporter</Importer> 40 <Processor>TextureProcessor</Processor> 41 </Compile> 42 </ItemGroup> 36 43 </Project> -
2010/31/arsajukk/Pong/Peli.cs
r1529 r1570 12 12 PhysicsObject maila1; 13 13 PhysicsObject maila2; 14 PhysicsObject vasenReuna; 15 PhysicsObject oikeaReuna; 16 IntMeter pelaajan1Pisteet; 17 IntMeter pelaajan2Pisteet; 18 19 Image pallonKuva = LoadImage("head"); 14 20 15 21 … … 18 24 LuoKentta(); 19 25 AsetaOhjaimet(); 26 LisaaLaskurit(); 27 AloitaPeli(); 20 28 21 AloitaPeli();22 29 23 30 } … … 25 32 void LuoKentta() 26 33 { 27 pallo = new PhysicsObject( 40.0, 40.0);34 pallo = new PhysicsObject(80.0, 80.0); 28 35 pallo.Shape = Shapes.Circle; 29 36 pallo.X = -200.0; 30 37 pallo.Y = 0.0; 31 38 pallo.Restitution = 1.0; 39 pallo.Image = pallonKuva; 40 32 41 Add(pallo); 42 43 AddCollisionHandler(pallo, KasittelePallonTormays); 33 44 34 45 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 35 46 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 47 maila1.Color = Color.Blue; 48 maila2.Color = Color.Red; 49 vasenReuna = Level.CreateLeftBorder(); 50 vasenReuna.Restitution = 1.0; 51 vasenReuna.IsVisible = false; 52 53 oikeaReuna = Level.CreateRightBorder(); 54 vasenReuna.Restitution = 1.0; 55 vasenReuna.IsVisible = false; 56 57 PhysicsObject yläReuna = Level.CreateTopBorder(); 58 vasenReuna.Restitution = 1.0; 59 vasenReuna.IsVisible = false; 60 61 PhysicsObject alaReuna = Level.CreateBottomBorder(); 62 vasenReuna.Restitution = 1.0; 63 vasenReuna.IsVisible = false; 36 64 37 38 Level.CreateBorders(1.0, false); 39 Level.BackgroundColor = Color.Black; 65 Level.BackgroundColor = Color.LightGreen; 40 66 41 67 Camera.ZoomToLevel(); … … 54 80 maila.X = x; 55 81 maila.Y = y; 56 maila.Restitution = 1.0; 82 maila.Restitution = 2.0; 83 57 84 Add(maila); 58 85 return maila; … … 76 103 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 77 104 105 ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos); 106 ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 107 ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas); 108 ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 109 110 ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos); 111 ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 112 ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas); 113 ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 114 115 ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 116 ControllerTwo.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 78 117 79 118 } … … 81 120 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 82 121 { 122 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 123 { 124 maila.Velocity = Vector.Zero; 125 return; 126 } 83 127 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 84 128 { … … 89 133 maila.Velocity = nopeus; 90 134 } 135 136 137 void LisaaLaskurit() 138 { 139 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 140 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 141 142 } 143 144 145 146 IntMeter LuoPisteLaskuri(double x, double y) 147 { 148 IntMeter laskuri = new IntMeter(0); 149 laskuri.MaxValue = 10; 150 Label naytto = new Label(); 151 naytto.BindTo(laskuri); 152 naytto.X = x; 153 naytto.Y = y; 154 naytto.TextColor = Color.Orange; 155 Add(naytto); 156 return laskuri; 157 } 158 159 void KasittelePallonTormays( PhysicsObject pallo, PhysicsObject kohde ) 160 { 161 if ( kohde == oikeaReuna ) 162 { 163 pelaajan1Pisteet.Value += 1; 164 } 165 else if ( kohde == vasenReuna ) 166 { 167 pelaajan2Pisteet.Value += 1; 168 } 169 170 91 171 } 92 172 173 }
Note: See TracChangeset
for help on using the changeset viewer.