- Timestamp:
- 2017-07-25 10:12:27 (6 years ago)
- Location:
- 2017/30/MainiI
- Files:
-
- 7 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
2017/30/MainiI/Pong/Pong/Pong/Pong.cs
r9043 r9078 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 3 5 using Jypeli; 4 6 using Jypeli.Assets; … … 9 11 public class Pong : PhysicsGame 10 12 { 13 Vector nopeusYlos = new Vector(0, 200); 14 Vector nopeusAlas = new Vector(0, -200); 15 11 16 PhysicsObject pallo; 17 PhysicsObject maila1; 18 PhysicsObject maila2; 19 20 PhysicsObject vasenReuna; 21 PhysicsObject oikeaReuna; 22 23 IntMeter pelaajan1Pisteet; 24 IntMeter pelaajan2Pisteet; 25 26 Image taustakuva = LoadImage("Jalkapallokentta"); 27 28 12 29 public override void Begin() 13 30 { 14 31 LuoKentta(); 32 AsetaOhjaimet(); 33 LisaaLaskurit(); 15 34 AloitaPeli(); 16 17 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 35 } 18 36 19 20 PhoneBackButton.Listen(ConfirmExit, "Lopeta peli");21 22 }23 37 void LuoKentta() 24 38 { 25 pallo = new PhysicsObject(50.0, 50.0); 26 Add(pallo); 39 pallo = new PhysicsObject(40.0, 40.0); 27 40 pallo.Shape = Shape.Circle; 28 41 pallo.X = -200.0; 29 42 pallo.Y = 0.0; 30 pallo.Restitution = 50.0; 43 pallo.Restitution = 1.0; 44 pallo.KineticFriction = 0.0; 45 pallo.MomentOfInertia = Double.PositiveInfinity; 46 Add(pallo); 47 AddCollisionHandler(pallo, KasittelePallonTormays); 48 pallo.Color = Color.Charcoal; 31 49 32 LuoMaila(level.left + 20.0, 0.0);33 Luomaila(level.right - 20.0, 0.0);50 maila1 = LuoMaila(Level.Left + 20.0, 0.0); 51 maila2 = LuoMaila(Level.Right - 20.0, 0.0); 34 52 35 Camera.ZoomToLevel(300.0); 53 maila2.Color = Color.Aquamarine; 54 maila1.Color = Color.Aquamarine; 36 55 37 Level.Background.Color = Color.SkyBlue; 38 Level.CreateBorders(1.0, true); 56 vasenReuna = Level.CreateLeftBorder(); 57 vasenReuna.Restitution = 1.0; 58 vasenReuna.KineticFriction = 0.0; 59 vasenReuna.IsVisible = false; 60 61 oikeaReuna = Level.CreateRightBorder(); 62 oikeaReuna.Restitution = 1.0; 63 oikeaReuna.KineticFriction = 0.0; 64 oikeaReuna.IsVisible = false; 65 66 PhysicsObject ylaReuna = Level.CreateTopBorder(); 67 ylaReuna.Restitution = 1.0; 68 ylaReuna.KineticFriction = 0.0; 69 ylaReuna.IsVisible = false; 70 71 PhysicsObject alaReuna = Level.CreateBottomBorder(); 72 alaReuna.Restitution = 1.0; 73 alaReuna.IsVisible = false; 74 alaReuna.KineticFriction = 0.0; 75 76 Level.Background.Color = Color.SeaGreen; 77 Level.Background.Image = taustakuva; 78 79 Camera.ZoomToLevel(); 80 } 81 82 PhysicsObject LuoMaila(double x, double y) 83 { 84 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 85 maila.Shape = Shape.Rectangle; 86 maila.X = x; 87 maila.Y = y; 88 maila.Restitution = 1.0; 89 maila.KineticFriction = 0.0; 90 Add(maila); 91 return maila; 92 } 93 94 void LisaaLaskurit() 95 { 96 pelaajan1Pisteet = LuoPisteLaskuri(Screen.Left + 100.0, Screen.Top - 100.0); 97 pelaajan2Pisteet = LuoPisteLaskuri(Screen.Right - 100.0, Screen.Top - 100.0); 98 } 99 100 IntMeter LuoPisteLaskuri(double x, double y) 101 { 102 IntMeter laskuri = new IntMeter(0); 103 laskuri.MaxValue = 10; 104 105 Label naytto = new Label(); 106 naytto.BindTo(laskuri); 107 naytto.X = x; 108 naytto.Y = y; 109 naytto.TextColor = Color.White; 110 naytto.BorderColor = Level.BackgroundColor; 111 naytto.Color = Level.BackgroundColor; 112 Add(naytto); 113 114 return laskuri; 115 } 116 117 void KasittelePallonTormays(PhysicsObject pallo, PhysicsObject kohde) 118 { 119 if (kohde == oikeaReuna) 120 { 121 pelaajan1Pisteet.Value += 1; 122 } 123 else if (kohde == vasenReuna) 124 { 125 pelaajan2Pisteet.Value += 1; 126 } 39 127 } 40 128 … … 44 132 pallo.Hit(impulssi); 45 133 } 46 void LuoMaila(double x, double y)47 134 135 void AsetaOhjaimet() 48 136 { 49 PhysicsObject maila = PhysicsObject.CreateStaticObject(20.0, 100.0); 50 maila.Shape = Shape.Rectangle; 51 maila.X = x; 52 maila.Y = y; 53 maila.Restitution = 1.0; 54 Add(maila); 137 Keyboard.Listen(Key.A, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa ylös", maila1, nopeusYlos); 138 Keyboard.Listen(Key.A, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 139 Keyboard.Listen(Key.Z, ButtonState.Down, AsetaNopeus, "Pelaaja 1: Liikuta mailaa alas", maila1, nopeusAlas); 140 Keyboard.Listen(Key.Z, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 55 141 56 LuoMaila(Level.Left + 20.0, 0.0); 57 LuoMaila(Level.Right - 20.0, 0.0); 142 Keyboard.Listen(Key.Up, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa ylös", maila2, nopeusYlos); 143 Keyboard.Listen(Key.Up, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 144 Keyboard.Listen(Key.Down, ButtonState.Down, AsetaNopeus, "Pelaaja 2: Liikuta mailaa alas", maila2, nopeusAlas); 145 Keyboard.Listen(Key.Down, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 58 146 59 Level.CreateBorders(1.0, false);60 Level.Background.Color = Color.Black;147 Keyboard.Listen(Key.F1, ButtonState.Pressed, ShowControlHelp, "Näytä ohjeet"); 148 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 61 149 62 Camera.ZoomToLevel(); 150 ControllerOne.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila1, nopeusYlos); 151 ControllerOne.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 152 ControllerOne.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila1, nopeusAlas); 153 ControllerOne.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila1, Vector.Zero); 63 154 155 ControllerTwo.Listen(Button.DPadUp, ButtonState.Down, AsetaNopeus, "Liikuta mailaa ylös", maila2, nopeusYlos); 156 ControllerTwo.Listen(Button.DPadUp, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 157 ControllerTwo.Listen(Button.DPadDown, ButtonState.Down, AsetaNopeus, "Liikuta mailaa alas", maila2, nopeusAlas); 158 ControllerTwo.Listen(Button.DPadDown, ButtonState.Released, AsetaNopeus, null, maila2, Vector.Zero); 159 160 ControllerOne.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 161 ControllerTwo.Listen(Button.Back, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); 162 } 163 164 void AsetaNopeus(PhysicsObject maila, Vector nopeus) 165 { 166 if ((nopeus.Y < 0) && (maila.Bottom < Level.Bottom)) 167 { 168 maila.Velocity = Vector.Zero; 169 return; 170 } 171 if ((nopeus.Y > 0) && (maila.Top > Level.Top)) 172 { 173 maila.Velocity = Vector.Zero; 174 return; 175 } 176 177 maila.Velocity = nopeus; 64 178 } 65 179 } 66 -
2017/30/MainiI/Pong/Pong/Pong/obj/x86/Debug/ContentPipeline-{F99ED211-AB1B-49D7-8FBE-7BCAEA8A6AD0}.xml
r9043 r9078 2 2 <XnaContent xmlns:Pipeline="Microsoft.Xna.Framework.Content.Pipeline"> 3 3 <Asset Type="Pipeline:BuildItemCollection"> 4 <Item> 5 <Source>Jalkapallokentta.png</Source> 6 <Name>Jalkapallokentta</Name> 7 <Importer>TextureImporter</Importer> 8 <Processor>TextureProcessor</Processor> 9 <Options>None</Options> 10 <Output>C:\MyTemp\MainiI\Pong\Pong\Pong\bin\x86\Debug\Content\Jalkapallokentta.xnb</Output> 11 <Time>2017-07-24T14:57:19.2446235+03:00</Time> 12 </Item> 4 13 <BuildSuccessful>true</BuildSuccessful> 5 14 <Settings> … … 16 25 <Assemblies> 17 26 <Assembly> 27 <Key>C:\Program Files (x86)\Jypeli\lib\ContentExtensions\TextFileContentExtension.dll</Key> 28 <Value>2015-02-09T20:18:44+02:00</Value> 29 </Assembly> 30 <Assembly> 31 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.XImporter.dll</Key> 32 <Value>2011-09-01T16:22:30+03:00</Value> 33 </Assembly> 34 <Assembly> 35 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.VideoImporters.dll</Key> 36 <Value>2011-09-01T16:22:30+03:00</Value> 37 </Assembly> 38 <Assembly> 39 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.TextureImporter.dll</Key> 40 <Value>2011-09-01T16:22:30+03:00</Value> 41 </Assembly> 42 <Assembly> 43 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.FBXImporter.dll</Key> 44 <Value>2011-09-01T16:22:30+03:00</Value> 45 </Assembly> 46 <Assembly> 47 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.EffectImporter.dll</Key> 48 <Value>2011-09-01T16:22:30+03:00</Value> 49 </Assembly> 50 <Assembly> 51 <Key>C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Content.Pipeline.AudioImporters.dll</Key> 52 <Value>2011-09-01T16:22:30+03:00</Value> 53 </Assembly> 54 <Assembly> 55 <Key>C:\Program Files (x86)\Jypeli\lib\ContentExtensions\AnimationExtension.dll</Key> 56 <Value>2015-02-17T22:27:18+02:00</Value> 57 </Assembly> 58 <Assembly> 18 59 <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 60 <Value>2017-07-12T17:01:36.8573441+03:00</Value> -
2017/30/MainiI/Pong/Pong/Pong/obj/x86/Debug/Pong.csproj.FileListAbsolute.txt
r9043 r9078 7 7 C:\MyTemp\MainiI\Pong\Pong\Pong\obj\x86\Debug\Pong.exe 8 8 C:\MyTemp\MainiI\Pong\Pong\Pong\obj\x86\Debug\Pong.pdb 9 C:\MyTemp\MainiI\Pong\Pong\Pong\bin\x86\Debug\Content\Jalkapallokentta.xnb -
2017/30/MainiI/Pong/Pong/PongContent/PongContent.contentproj
r9043 r9078 45 45 <Reference Include="AnimationExtension" /> 46 46 </ItemGroup> 47 <ItemGroup> 48 <Compile Include="Jalkapallokentta.png"> 49 <Name>Jalkapallokentta</Name> 50 <Importer>TextureImporter</Importer> 51 <Processor>TextureProcessor</Processor> 52 </Compile> 53 </ItemGroup> 47 54 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 48 55 <!-- 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.