Changeset 1969
- Timestamp:
- 2011-06-13 14:56:56 (12 years ago)
- Location:
- 2011/24/LeeviK/Pong/Pong
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2011/24/LeeviK/Pong/Pong/Pong/Peli.cs
r1955 r1969 13 13 Vector nopeusYlos = new Vector(0, 200); 14 14 Vector nopeusAlas = new Vector(0, -200); 15 Image taustaKuva = LoadImage("tausta"); 15 16 16 PhysicsObject pallo;17 PhysicsObject maila1;18 PhysicsObject maila2;19 17 20 PhysicsObject vasenReuna;21 PhysicsObject oikeaReuna;18 PhysicsObject pelaaja1; 19 22 20 23 IntMeter pelaajan1Pisteet;24 IntMeter pelaajan2Pisteet;21 22 25 23 26 24 public override void Begin() … … 28 26 LuoKentta(); 29 27 AsetaOhjaimet(); 30 LisaaLaskurit();31 28 AloitaPeli(); 29 Mouse.IsCursorVisible = true; 30 Mouse.ListenMovement(0.1, KuunteleLiiketta, null); 31 32 33 // x, y 34 Keyboard.Listen(Key.Left, ButtonState.Down, LiikutaPelaajaa, "Liikuta pelaajaa vasemmalle", new Vector(-1000, 0)); 35 Keyboard.Listen(Key.Right, ButtonState.Down, LiikutaPelaajaa, null, new Vector(1000, 0)); 36 Keyboard.Listen(Key.Up, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, 1000)); 37 Keyboard.Listen(Key.Down, ButtonState.Down, LiikutaPelaajaa, null, new Vector(0, -1000)); 32 38 } 33 39 40 void LiikutaPelaajaa(Vector kakkakasa) 41 { 42 pelaaja1.Push(kakkakasa); 43 } 44 34 45 void LuoKentta() 35 46 { 36 p allo = new PhysicsObject(40.0, 40.0);37 p allo.Shape = Shape.Circle;38 p allo.X = -200.0;39 p allo.Y = 0.0;40 p allo.Restitution = 1.0;41 p allo.KineticFriction = 0.0;42 Add(p allo);43 AddCollisionHandler(pallo, KasittelePallonTormays);47 pelaaja1 = new PhysicsObject(200.0, 200.0); 48 pelaaja1.Shape = Shape.Circle; 49 pelaaja1.X = -200.0; 50 pelaaja1.Y = 0.0; 51 pelaaja1.Restitution = 1.0; 52 pelaaja1.KineticFriction = 0.0; 53 Add(pelaaja1); 54 pelaaja1.Image = LoadImage("jenkki"); 44 55 45 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 46 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 47 48 vasenReuna = Level.CreateLeftBorder(); 49 vasenReuna.Restitution = 1.0; 50 vasenReuna.IsVisible = false; 51 oikeaReuna = Level.CreateRightBorder(); 52 oikeaReuna.Restitution = 1.0; 53 oikeaReuna.IsVisible = false; 54 PhysicsObject ylaReuna = Level.CreateTopBorder(); 55 ylaReuna.Restitution = 1.0; 56 ylaReuna.IsVisible = false; 57 PhysicsObject alaReuna = Level.CreateBottomBorder(); 58 alaReuna.Restitution = 1.0; 59 alaReuna.IsVisible = false; 60 61 Level.BackgroundColor = Color.Black; 62 63 Camera.ZoomToLevel(); 56 Level.Background.Image = taustaKuva; 57 Camera.Follow(pelaaja1); 64 58 } 65 59 66 PhysicsObject LuoMaila(double x, double y) 67 { 68 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 69 maila.Shape = Shape.Rectangle; 70 maila.X = x; 71 maila.Y = y; 72 maila.Restitution = 1.0; 73 Add(maila); 74 return maila; 75 } 60 76 61 77 void LisaaLaskurit() 78 { 79 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 80 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 81 } 62 82 63 83 64 IntMeter LuoPisteLaskuri(double x, double y) … … 95 76 return laskuri; 96 77 } 78 79 80 97 81 98 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 99 { 100 if (kohde == oikeaReuna) 101 { 102 pelaajan1Pisteet.Value += 1; 103 } 104 else if (kohde == vasenReuna) 105 { 106 pelaajan2Pisteet.Value += 1; 107 } 108 } 82 109 83 110 84 void AloitaPeli() 111 85 { 112 Vector impulssi = new Vector(500.0, 0.0);113 pallo.Hit(impulssi);86 87 114 88 } 115 89 116 90 void AsetaOhjaimet() 117 91 { 118 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos);119 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);120 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas);121 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero);122 123 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos);124 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero);125 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas);126 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero);127 128 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet");129 92 Keyboard.Listen(Key.Escape, ButtonState.Pressed, Exit, "Poistu"); 130 131 ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos); 132 ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 133 ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas); 134 ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 135 136 ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos); 137 ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 138 ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas); 139 ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 140 141 ControllerOne.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 142 ControllerTwo.Listen(Button.Back, ButtonState.Pressed, Exit, "Poistu"); 93 //Keyboard.Listen(Key.Left, ButtonState.Down, 94 143 95 } 144 96 145 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 97 98 void KuunteleLiiketta(AnalogState hiirenTila) 146 99 { 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 100 158 maila.Velocity = nopeus; 101 Mouse.IsCursorVisible = true; 102 Vector hiirenLiike = hiirenTila.MouseMovement; 103 pelaaja1.Angle = hiirenLiike.Angle; 159 104 } 105 106 107 160 108 } -
2011/24/LeeviK/Pong/Pong/PongContent/PongContent.contentproj
r1955 r1969 42 42 </Reference> 43 43 </ItemGroup> 44 <ItemGroup> 45 <Compile Include="jenkki.png"> 46 <Name>jenkki</Name> 47 <Importer>TextureImporter</Importer> 48 <Processor>TextureProcessor</Processor> 49 </Compile> 50 </ItemGroup> 51 <ItemGroup> 52 <Compile Include="tausta.png"> 53 <Name>tausta</Name> 54 <Importer>TextureImporter</Importer> 55 <Processor>TextureProcessor</Processor> 56 </Compile> 57 </ItemGroup> 58 <ItemGroup> 59 <Compile Include="crosshair.png"> 60 <Name>crosshair</Name> 61 <Importer>TextureImporter</Importer> 62 <Processor>TextureProcessor</Processor> 63 </Compile> 64 </ItemGroup> 44 65 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 45 66 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Note: See TracChangeset
for help on using the changeset viewer.