Changeset 187
- Timestamp:
- 2009-07-24 13:20:24 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sipi_o/Omapeli/Peli.cs
r146 r187 24 24 //Debuggaus hahmo 25 25 PhysicsObject dbHahmo; 26 PhysicsObject LUOTI; 27 PhysicsObject tahtainn; 28 PhysicsObject zombi; 26 29 //----------------------------------------------- 27 30 … … 30 33 ShowMouseCursor(true); 31 34 DEBUGROOM(); 32 pLisaa();33 35 pLiikuta(); 34 //pHiiri();35 }36 37 void pLisaa()38 {39 //-----------------------------------------------40 //Lisää pelaaja lopulliseen versioon tähän41 //-----------------------------------------------42 36 } 43 37 … … 45 39 { 46 40 Vector2D hiirenSijainti = Controls.Mouse.GetPositionOnWorld(Camera); 41 Level.Objects.Remove(tahtainn); 42 naytaTahtain(hiirenSijainti); 47 43 kaannaPelaajaa(dbHahmo, hiirenSijainti); 48 44 return false; … … 54 50 double kohdekulma = suunta.Angle; 55 51 pelaaja.Angle = new Angle(kohdekulma, false); 52 } 53 54 void naytaTahtain(Vector2D xhair) 55 { 56 IShape testi = Shapes.CreateCircle(28.0); 57 tahtainn = new PhysicsObject(0.1, testi); 58 tahtainn.IgnoresCollisionResponse = true; 59 tahtainn.Texture = Content.Load<Texture2D>("tahtajn"); 60 tahtainn.X = xhair.X; 61 tahtainn.Y = xhair.Y; 62 Level.Objects.Add(tahtainn); 63 } 64 65 void luovihollinen(double enemyHP) 66 { 67 IShape enemy1 = Shapes.CreateRectangle(60.0, 60.0); 68 zombi = new PhysicsObject(10.0, enemy1); 69 70 Texture2D[] elavakuollut1 = 71 { 72 Content.Load<Texture2D>( "zombi2" ), 73 Content.Load<Texture2D>( "zombi1" ) 74 }; 75 AnimatedTexture zombi1text = new AnimatedTexture(elavakuollut1); 76 zombi1text.FPS = 2; 77 zombi.AnimatedTexture = zombi1text; 78 zombi.Tag = "vihollinen"; 79 vihollisenSijainti(); 80 81 Vector2D hahmonsijainti = dbHahmo.Position; 82 zombinSuunta(zombi, hahmonsijainti, enemyHP); 83 } 84 85 void zombinSuunta(PhysicsObject asd, Vector2D qwerty, double omfg) 86 { 87 Vector2D zombiVektori = new Vector2D(qwerty.X - zombi.X, qwerty.Y - zombi.Y); 88 double sombiSuunta = zombiVektori.Angle; 89 asd.Angle = new Angle(sombiSuunta, false); 90 asd.Hit(Vector2D.FromLengthAndAngle(omfg, asd.Angle.Radian)); 91 } 92 93 94 95 void vihollisenSijainti() 96 { 97 int sijaintivariable = RandomGen.NextInt(1, 4); 98 // jos sijaintivariable on... 99 // 1 = spawnaa vasemmalle 100 // 2 = spawnaa oikealle 101 // 3 = spawnaa ylös 102 // 4 = spawnaa alas 103 104 // --- // --- // --- // --- // --- // --- // --- // --- // --- // 105 if (sijaintivariable == 1) 106 { 107 double rofl = RandomGen.NextDouble(Level.Top, Level.Bottom); 108 zombi.X = Level.Left; 109 zombi.Y = rofl; 110 } 111 // --- // --- // --- // --- // --- // --- // --- // --- // --- // 112 if (sijaintivariable == 2) 113 { 114 double rofl = RandomGen.NextDouble(Level.Top, Level.Bottom); 115 zombi.X = Level.Right; 116 zombi.Y = rofl; 117 } 118 // --- // --- // --- // --- // --- // --- // --- // --- // --- // 119 if (sijaintivariable == 3) 120 { 121 double rofl = RandomGen.NextDouble(Level.Left, Level.Right); 122 zombi.X = Level.Top; 123 zombi.Y = rofl; 124 } 125 // --- // --- // --- // --- // --- // --- // --- // --- // --- // 126 if (sijaintivariable == 4) 127 { 128 double rofl = RandomGen.NextDouble(Level.Left, Level.Right); 129 zombi.X = Level.Bottom; 130 zombi.Y = rofl; 131 } 132 // --- // --- // --- // --- // --- // --- // --- // --- // --- // 133 134 Level.Objects.Add(zombi); 56 135 } 57 136 … … 67 146 Controls.Listen(Keys.D, ButtonPosition.Down, pLiikkuuX, "Pelaaja liikkuu oikealle", dbHahmo, pNopeus); 68 147 Controls.Listen(Keys.A, ButtonPosition.Down, pLiikkuuX, "Pelaaja liikkuu vasemmalle", dbHahmo, -pNopeus); 69 //Controls.Listen(MouseButtons.Left, ButtonPosition.Down, 0.0, ammus); 148 Controls.Listen(Keys.W, ButtonPosition.Released, animaationPalautus); 149 Controls.Listen(Keys.S, ButtonPosition.Released, animaationPalautus); 150 Controls.Listen(Keys.D, ButtonPosition.Released, animaationPalautus); 151 Controls.Listen(Keys.A, ButtonPosition.Released, animaationPalautus); 152 Controls.Listen(MouseButtons.Left, ButtonPosition.Pressed, 0.0, ammus); 70 153 Controls.Listen(MouseButtons.None, ButtonPosition.Irrelevant, 0.1, pHiiri); 154 71 155 //----------------------------------------------- 72 156 } 157 bool animaationPalautus(ControlEvent e) 158 { 159 Texture2D[] tekstuurit = 160 { 161 Content.Load<Texture2D>( "spriteidle" ), 162 Content.Load<Texture2D>( "spriteidle" ), 163 Content.Load<Texture2D>( "spriteidle" ), 164 Content.Load<Texture2D>( "spriteidle" ) 165 }; 166 AnimatedTexture walkTexture = new AnimatedTexture(tekstuurit); 167 walkTexture.FPS = 1; 168 return false; 169 } 73 170 74 171 bool ammus(ControlEvent e) 75 172 { 76 return false; 173 174 175 IShape dbLuoti = Shapes.CreateRectangle(40.0, 2.0); 176 LUOTI = new PhysicsObject(5.0, dbLuoti); 177 double hahmoX = dbHahmo.X; 178 double hahmoY = dbHahmo.Y; 179 LUOTI.X = hahmoX; 180 LUOTI.Y = hahmoY; 181 LUOTI.Restitution = 0.0; 182 LUOTI.Color = Color.White; 183 184 LUOTI.Tag = "luoti"; 185 LUOTI.Lifetime.MaxSeconds = 1; 186 Level.Objects.Add(LUOTI); 187 188 AddCollisionHandler(LUOTI, luotiKatoaa); 189 190 Vector2D hiirenSijainti = Controls.Mouse.GetPositionOnWorld(Camera); 191 luodinSuunta(LUOTI, hiirenSijainti); 192 193 return false; 194 } 195 196 void luodinSuunta(PhysicsObject panos, Vector2D ammuksenSuunta) 197 { 198 Vector2D luotiVektori = new Vector2D(ammuksenSuunta.X - dbHahmo.X, ammuksenSuunta.Y - dbHahmo.Y); 199 double luotiSuunta = luotiVektori.Angle; 200 panos.Angle = new Angle(luotiSuunta, false); 201 panos.Hit(Vector2D.FromLengthAndAngle(15000, panos.Angle.Radian)); 77 202 } 78 203 … … 82 207 bool pLiikkuuX(ControlEvent e) 83 208 { 209 84 210 PhysicsObject dbHahmo = e.Parameter0.ToPhysicsObject(); 85 211 double pSpeed = e.Parameter1.ToDouble(); 86 212 double uusiX = dbHahmo.X + pSpeed; 87 dbHahmo.X = uusiX; 213 88 214 if ((Level.Left < uusiX) && (uusiX < Level.Right)) 89 215 { … … 94 220 kaannaPelaajaa(dbHahmo, hiirenSijainti); 95 221 222 Texture2D[] tekstuurit = 223 { 224 Content.Load<Texture2D>( "spriteidle" ), 225 Content.Load<Texture2D>( "spritewalk1" ), 226 Content.Load<Texture2D>( "spriteidle" ), 227 Content.Load<Texture2D>( "spritewalk2" ) 228 }; 229 AnimatedTexture walkTexture = new AnimatedTexture(tekstuurit); 230 walkTexture.FPS = 6; 231 96 232 return false; 97 233 } … … 102 238 bool pLiikkuuY( ControlEvent e ) 103 239 { 240 104 241 PhysicsObject dbHahmo = e.Parameter0.ToPhysicsObject(); 105 242 double pSpeed = e.Parameter1.ToDouble(); 106 243 double uusiY = dbHahmo.Y + pSpeed; 107 dbHahmo.Y = uusiY; 244 108 245 if ((Level.Bottom < uusiY) && (uusiY < Level.Top)) 109 246 { … … 114 251 kaannaPelaajaa(dbHahmo, hiirenSijainti); 115 252 253 Texture2D[] tekstuurit = 254 { 255 Content.Load<Texture2D>( "spriteidle" ), 256 Content.Load<Texture2D>( "spritewalk1" ), 257 Content.Load<Texture2D>( "spriteidle" ), 258 Content.Load<Texture2D>( "spritewalk2" ) 259 }; 260 AnimatedTexture walkTexture = new AnimatedTexture(tekstuurit); 261 walkTexture.FPS = 6; 262 116 263 return false; 117 264 } … … 120 267 { 121 268 PhysicsObject LUOTI = collision.Obj; 122 PhysicsObject seina = collision.Other; 123 124 if (seina == Level.RightBorder) 125 { 126 LUOTI.Lifetime.IsExpired = true; 127 } 128 } 129 130 //----------------------------------------------- 131 //TESTIALUE PELAAJAN LIIKUTUKSEEN JA MUUHUN :) 132 //----------------------------------------------- 269 PhysicsObject tormays = collision.Other; 270 271 if (tormays == Level.RightBorder) 272 { 273 LUOTI.Lifetime.IsExpired = true; 274 } 275 if (tormays == Level.LeftBorder) 276 { 277 LUOTI.Lifetime.IsExpired = true; 278 } 279 if (tormays == Level.TopBorder) 280 { 281 LUOTI.Lifetime.IsExpired = true; 282 } 283 if (tormays == Level.BottomBorder) 284 { 285 LUOTI.Lifetime.IsExpired = true; 286 } 287 if (tormays.Tag == "luoti") 288 { 289 LUOTI.Lifetime.IsExpired = true; 290 } 291 if (tormays.Tag == "vihollinen") 292 { 293 //MITÄ KÄY KUN ZOMBIIN OSUTAAN??? ASD 294 LUOTI.Lifetime.IsExpired = true; 295 296 zombi.Lifetime.IsExpired = true; 297 //double wat =+ 10.0; 298 luovihollinen(1500); 299 } 300 } 301 302 //-----------------------------------------------------// 303 // PELIALUE (debugroom koska en jaksa enää vaihtaa...) // 304 //-----------------------------------------------------// 133 305 void DEBUGROOM() 134 306 { 135 Level.BackgroundColor = Color.LightGreen; 136 Level.CreateBorder(0.0, true); 137 138 IShape dbPallo = Shapes.CreateRectangle(60.0, 40.0); 139 //IShape dbPallo = Shapes.CreateCircle(30.0); 140 dbHahmo = new PhysicsObject(20.0, dbPallo); 307 //Level.BackgroundColor = Color.LightGreen; 308 Texture2D tausta = Content.Load<Texture2D>("Grass"); 309 Level.Background.Image = tausta; 310 Level.Background.FitToLevel(Level); 311 //Level.CreateBorder(0.0, true); 312 313 Texture2D spriteidle = Content.Load<Texture2D>("spriteidle"); 314 IShape dbPallo = Shapes.CreateRectangle(60.0, 60.0); 315 dbHahmo = new PhysicsObject(9999999999.0, dbPallo); 141 316 dbHahmo.X = 0.0; 142 317 dbHahmo.Y = 0.0; 143 318 dbHahmo.Restitution = 0.2; 144 319 dbHahmo.Color = Color.Black; 145 320 //standFPS(); 321 322 Texture2D[] tekstuurit = 323 { 324 Content.Load<Texture2D>( "spriteidle" ), 325 Content.Load<Texture2D>( "spriteidle" ), 326 Content.Load<Texture2D>( "spriteidle" ), 327 Content.Load<Texture2D>( "spriteidle" ) 328 //Content.Load<Texture2D>( "spriteshoot1" ), 329 //Content.Load<Texture2D>( "spriteshoot2" ), 330 //Content.Load<Texture2D>( "spriteshoot3" ), 331 //Content.Load<Texture2D>( "spriteshoot2" ) 332 }; 333 AnimatedTexture walkTexture = new AnimatedTexture(tekstuurit); 334 walkTexture.FPS = 6; 335 dbHahmo.AnimatedTexture = walkTexture; 336 337 luovihollinen(1500); 146 338 Level.Objects.Add(dbHahmo); 339 340 AddCollisionHandler(dbHahmo, zombiosuu); 147 341 //----------------------------------------------- 342 } 343 344 void zombiosuu(Collision collision) 345 { 346 PhysicsObject LUOTI = collision.Obj; 347 PhysicsObject kuolema = collision.Other; 348 349 if (kuolema == zombi) 350 { 351 dbHahmo.Lifetime.IsExpired = true; 352 MessageDisplay.Add("Kuolit!"); 353 MessageDisplay.Add("Kuolit!"); 354 MessageDisplay.Add("Kuolit!"); 355 MessageDisplay.Add("Kuolit!"); 356 MessageDisplay.Add("Kuolit!"); 357 MessageDisplay.Add("Kuolit!"); 358 MessageDisplay.Add("Kuolit!"); 359 MessageDisplay.TextColor = Color.Red; 360 } 148 361 } 149 362 }
Note: See TracChangeset
for help on using the changeset viewer.