Changeset 7649
- Timestamp:
- 2016-07-03 10:00:22 (7 years ago)
- Location:
- 2016/27/SimoR/SimplePhysicsTest/SimplePhysicsTest
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2016/27/SimoR/SimplePhysicsTest/SimplePhysicsTest/SimplePhysicsTest/SimplePhysicsTest.cs
r7648 r7649 15 15 public SimplePlatformCharacter(double width, double height) : base(width, height) 16 16 { 17 FacingDirection = Direction.Right; 17 18 } 18 19 … … 36 37 37 38 public bool Crouch { get; set; } 39 40 public SimplePhysics.Object Carrying { get; set; } 38 41 39 42 private readonly double fullHeight; … … 163 166 tilemap.SetTileMethod(Color.FromHexCode("FFB949"), CreateDestroyableBrick); 164 167 tilemap.SetTileMethod(Color.FromHexCode("FFFF00"), CreateCoin); 168 tilemap.SetTileMethod(Color.FromHexCode("BCB2FF"), CreateTestItem); 165 169 tilemap.SetTileMethod(Color.Blue, CreatePlayer); 166 170 tilemap.SetTileMethod(Color.Red, CreateEnemy); … … 175 179 Keyboard.Listen(Key.Down, ButtonState.Pressed, Crouch, null, player1, true); 176 180 Keyboard.Listen(Key.Down, ButtonState.Released, Crouch, null, player1, false); 177 Keyboard.Listen(Key.Space, ButtonState.Pressed, Shoot, null, player1); 178 Keyboard.Listen(Key.B, ButtonState.Down, MegaShoot, null, player1); 181 Keyboard.Listen(Key.Space, ButtonState.Pressed, PickupThrow, null, player1); 182 Keyboard.Listen(Key.Z, ButtonState.Pressed, Shoot, null, player1); 183 Keyboard.Listen(Key.X, ButtonState.Down, MegaShoot, null, player1); 179 184 Keyboard.Listen(Key.R, ButtonState.Pressed, () => { ClearAll(); Begin(); }, "Lopeta peli"); 180 185 Keyboard.Listen(Key.Escape, ButtonState.Pressed, ConfirmExit, "Lopeta peli"); … … 208 213 SetTile(x, y, tile); 209 214 215 // Tiili hajoaa jos pelaaja törmää siihen alapuolelta. 210 216 tile.AddCollisionHandler("player", (t, player) => 211 217 { … … 242 248 player1.Tag = "player"; 243 249 player1.Crushed += player1.Destroy; 250 player1.CollisionIgnoreGroup = 1; 244 251 Add(player1); 252 253 // Ajastin, joka pitää kannossa olevan kaman pään päällä. 254 var timer = new Timer { Interval = 0.01 }; 255 timer.Timeout += () => 256 { 257 if (player1.Carrying != null) 258 { 259 player1.Carrying.X = player1.X; 260 player1.Carrying.Bottom = player1.Top; 261 } 262 }; 263 timer.Start(); 264 265 // Kuollessa pudotetaan kannossa ollut kama. 266 player1.Destroyed += () => 267 { 268 timer.Stop(); 269 if (player1.Carrying != null) 270 { 271 player1.Carrying.Velocity = player1.Velocity; 272 player1.Carrying.IgnoresGravity = false; 273 player1.Carrying = null; 274 } 275 }; 245 276 246 277 player1.AddCollisionHandler("enemy", HitsEnemy); … … 260 291 var enemy = new Enemy(TileSize * 0.99, TileSize * 0.99); 261 292 enemy.Position = TileToWorldPosition(x, y); 293 enemy.Color = Color.Purple; 262 294 enemy.Tag = "enemy"; 263 295 enemy.Speed = 50; … … 272 304 coin.Tag = "coin"; 273 305 coin.Color = Color.Yellow; 306 coin.Shape = Shape.Star; 274 307 coin.IgnoresCollisionResponse = true; 275 308 coin.IgnoresGravity = true; 276 309 Add(coin); 310 } 311 312 private void CreateTestItem(int x, int y) 313 { 314 var item = new SimplePhysics.Object(TileSize * 0.99, TileSize * 0.99); 315 item.Position = TileToWorldPosition(x, y); 316 item.Tag = "item"; 317 item.Color = Color.DarkGreen; 318 item.Shape = Shape.Circle; 319 item.RestitutionX = 0.5; 320 item.RestitutionY = 0.5; 321 item.CollisionIgnoreGroup = 1; 322 Add(item); 277 323 } 278 324 … … 324 370 } 325 371 372 private void PickupThrow(Player player) 373 { 374 // Heitetään kannossa oleva kama. 375 if (player.Carrying != null) 376 { 377 if (Collisions(player.Carrying, Vector.Zero, true).Count == 0) 378 { 379 player.Carrying.IgnoresGravity = false; 380 player.Carrying.Velocity = new Vector(player.Velocity.X * 2, player.Velocity.Y + 100); 381 player.Carrying = null; 382 } 383 } 384 else // Tai sitten poimitaan lähellä oleva kama. 385 { 386 var items = GetObjectsWithTag("item"); 387 foreach (var item in items) 388 { 389 if (player.IntersectsWith(item)) 390 { 391 player.Carrying = (SimplePhysics.Object)item; 392 player.Carrying.IgnoresGravity = true; 393 break; 394 } 395 } 396 } 397 } 398 326 399 private void Shoot(SimplePlatformCharacter player) 327 400 {
Note: See TracChangeset
for help on using the changeset viewer.