Changeset 612
- Timestamp:
- 2010-06-09 14:10:58 (11 years ago)
- Location:
- 2010/23/teematma
- Files:
-
- 13 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/23/teematma/Tasohyppely2/Content/Content.contentproj
r565 r612 54 54 </Compile> 55 55 </ItemGroup> 56 <ItemGroup> 57 <Compile Include="kuu.png"> 58 <Name>kuu</Name> 59 <Importer>TextureImporter</Importer> 60 <Processor>TextureProcessor</Processor> 61 </Compile> 62 </ItemGroup> 56 63 <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" /> 57 64 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
2010/23/teematma/Tasohyppely2/Peli.cs
r565 r612 9 9 class Tasohyppely : PhysicsGame 10 10 { 11 const double nopeus = 200 ;12 const double hyppyVoima = 15000;11 const double nopeus = 2000; 12 const double hyppyVoima = 2000; 13 13 14 14 IntMeter pisteLaskuri; 15 15 ValueDisplay pisteNaytto; 16 16 17 P latformCharacterpelaaja1;17 PhysicsObject pelaaja1; 18 18 19 19 int kenttaNro; // monesko kenttä on menossa 20 20 21 bool voikoHypata; 22 21 23 22 24 protected override void Begin() 23 25 { 24 26 kenttaNro = 0; 25 Level.Width = 2000;27 Level.Width = 9000; 26 28 Level.Height = 1000; 27 29 … … 51 53 pisteLaskuri.Reset(); 52 54 53 kenttaNro += 1; // lisätään kenttänumeroa yhdellä 55 voikoHypata = true; 56 57 //kenttaNro += 1; lisätään kenttänumeroa yhdellä 54 58 MessageDisplay.Add( "Kenttä " + kenttaNro ); 55 59 56 60 // Asetetaan painovoima 57 Gravity = new Vector( 0, - 1000 );61 Gravity = new Vector( 0, -2000 ); 58 62 59 63 luoKentta(); … … 65 69 { 66 70 Level.CreateBorders(); 67 Level.Background.CreateGradient( Color.Green, Color.Red ); 68 69 lisaaTaso( -200, -350 ); 70 lisaaTaso( 0, -200 ); 71 //Level.Background.CreateGradient( Color.Red, Color.DarkMagenta ); 72 73 lisaaTaso( -4200, -500 ); 74 lisaaTaso( -4100, -400 ); 75 lisaaTaso( -3900, -350 ); 76 lisaaTaso( -3700, -250 ); 77 lisaaTaso( -4500, -500 ); 78 lisaaTaso( -4400, -500 ); 79 80 81 lisaaTaso(-3700, -300 ); 82 lisaaTaso(-3700, -400 ); 83 lisaaTaso(-3700, -350 ); 84 lisaaTaso(-3700, -250 ); 85 lisaaTaso(-4500, -500 ); 86 lisaaTaso(-4400, -500 ); 87 88 lisaaPallo(-4495, -460); 71 89 72 90 lisaaMaali(); … … 76 94 void lisaaTaso( double x, double y ) 77 95 { 78 PhysicsObject taso = PhysicsObject.CreateStaticObject( 100, 30 ); 79 taso.Color = Color.Green; 96 PhysicsObject taso = PhysicsObject.CreateStaticObject( 100, 50 ); 97 taso.Color = Color.Orange; 98 taso.LinearDamping = 1; 99 taso.Tag = "taso"; 80 100 taso.X = x; 81 101 taso.Y = y; 82 102 Add( taso ); 83 103 } 104 void lisaaPallo(double x, double y) 105 { 106 PhysicsObject pallo = PhysicsObject.CreateStaticObject(25, 25); 107 pallo.Shape = Shapes.Circle; 108 pallo.Color = Color.Orange; 109 pallo.LinearDamping = 1; 110 pallo.IgnoresCollisionResponse = true; 111 pallo.Tag = "pallo"; 112 pallo.X = x; 113 pallo.Y = y; 114 Add(pallo); 115 } 84 116 85 117 void lisaaPelaajat() 86 118 { 87 pelaaja1 = new PlatformCharacter( 40, 40 ); 88 pelaaja1.Mass = 40.0; 89 pelaaja1.Image = LoadImage( "rengas" ); 119 //pelaaja1 = new PlatformCharacter( 40, 40 ); 120 pelaaja1 = new PhysicsObject(40, 40, Shapes.Circle); 121 pelaaja1.Mass = 2.0; 122 123 pelaaja1.Image = LoadImage( "kuu" ); 90 124 pelaaja1.KineticFriction = 1; 91 125 pelaaja1.LinearDamping = 0.95; 92 126 93 pelaaja1.X = 0;127 pelaaja1.X = Level.Left + 120; 94 128 pelaaja1.Y = Level.Bottom + 120; 95 129 96 130 AddCollisionHandler( pelaaja1, osuiMaaliin ); 97 131 AddCollisionHandler(pelaaja1, lisaaHyppy); 132 98 133 Add( pelaaja1 ); 99 134 } … … 115 150 Keyboard.Listen( Key.Escape, ButtonState.Pressed, Exit, "Poistu pelistä" ); 116 151 117 Keyboard.Listen( Key.Left, ButtonState.Down, liikuta, "Liikkuu vasemmalle", pelaaja1, -nopeus ); 118 Keyboard.Listen( Key.Right, ButtonState.Down, liikuta, "Liikkuu oikealle", pelaaja1, nopeus ); 119 Keyboard.Listen( Key.Up, ButtonState.Pressed, hyppaa, "Hyppää", pelaaja1, hyppyVoima ); 152 Keyboard.Listen(Key.Left, ButtonState.Down, liikuta, "Liikkuu vasemmalle", pelaaja1, new Vector(-nopeus, 0)); 153 Keyboard.Listen(Key.Right, ButtonState.Down, liikuta, "Liikkuu oikealle", pelaaja1, new Vector(nopeus, 0)); 154 Keyboard.Listen(Key.Up, ButtonState.Pressed, hyppaa, "Hyppää", pelaaja1, new Vector(0, hyppyVoima)); 155 Keyboard.Listen(Key.Enter, ButtonState.Pressed, seuraavaKentta, "Restart"); 120 156 121 157 lisaaGamePadNappaimet( ControllerOne ); … … 126 162 controller.Listen( Button.Back, ButtonState.Pressed, Exit, "Poistu pelistä" ); 127 163 128 controller.Listen( Button.DPadLeft, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", pelaaja1, -nopeus ); 129 controller.Listen( Button.DPadRight, ButtonState.Down, liikuta, "Pelaaja liikkuu oikealle", pelaaja1, nopeus ); 130 controller.Listen( Button.A, ButtonState.Pressed, hyppaa, "Pelaaja hyppää", pelaaja1, hyppyVoima ); 131 } 132 133 void liikuta( PlatformCharacter hahmo, double nopeus ) 134 { 135 hahmo.Walk( nopeus ); 136 } 137 138 void hyppaa( PlatformCharacter hahmo, double voima ) 139 { 140 hahmo.Jump( voima ); 141 } 164 controller.Listen( Button.DPadLeft, ButtonState.Down, liikuta, "Pelaaja liikkuu vasemmalle", pelaaja1, new Vector(-nopeus,0) ); 165 controller.Listen(Button.DPadRight, ButtonState.Down, liikuta, "Pelaaja liikkuu oikealle", pelaaja1, new Vector(nopeus,0)); 166 controller.Listen( Button.A, ButtonState.Pressed, hyppaa, "Pelaaja hyppää", pelaaja1, new Vector(0, hyppyVoima) ); 167 } 168 169 void liikuta( PhysicsObject hahmo, Vector nopeus ) 170 { 171 //hahmo.Walk( nopeus ); Kokeile liikuttamiseen .Push-metodia 172 hahmo.Push(nopeus); 173 } 174 175 void hyppaa( PhysicsObject hahmo, Vector voima ) 176 { 177 //hahmo.Jump( voima ); Kokeile hyppäämiseen .Hit()-metodia 178 if (voikoHypata) 179 { 180 hahmo.Hit(voima); 181 voikoHypata = false; 182 } 183 } 184 185 142 186 143 187 void osuiMaaliin( PhysicsObject collidingObject, PhysicsObject otherObject ) 144 188 { 189 //MessageDisplay.Add("Levelin bottom: " + Level.Bottom); 190 //MessageDisplay.Add(pelaaja1.Position.Y.ToString()); 145 191 if ( otherObject.Tag.ToString() == "maali" ) 146 192 { … … 150 196 MessageDisplay.Add( "Pääsit läpi kentän " + kenttaNro + ". Pisteitä: " + edellisenKentanPisteet ); 151 197 } 198 199 if (collidingObject.Y < Level.Bottom + 20) 200 { 201 MessageDisplay.Add("Kuolit! Paina Enter yrittääksesi uudestaan"); 202 Explosion e = new Explosion(500); 203 e.Speed = 500.0; 204 e.Force = 10000; 205 206 207 e.Position = pelaaja1.Position; 208 collidingObject.Destroy(); 209 Add(e); 210 } 211 } 212 213 void lisaaHyppy(PhysicsObject collidingObject, PhysicsObject otherObject) 214 { 215 if (otherObject.Tag.ToString() == "taso") 216 { 217 voikoHypata = true; 218 } 152 219 } 153 220 }
Note: See TracChangeset
for help on using the changeset viewer.