private void KeyDown(object sender, KeyEventArgs e) { if (MovementEnabled) { switch (e.Key) { case Key.Space: if (jumps < 2 && !space_press) { space_press = true; new Thread(Jumper).Start(); } break; case Key.Escape: if (game_render.isActive()) { game_render.Deactivate(); Menus[MenuType.Pause].Activate(); } else { Menus[MenuType.Pause].Deactivate(); game_render.Activate(); } break; case Key.S: camera.Down = true; break; case Key.A: camera.Left = true; break; case Key.D: camera.Right = true; break; case Key.F1: if (screen.GameData.IsVisible) { screen.GameData.Visibility = Visibility.Hidden; screen.framerater.Stop(); } else { screen.GameData.Visibility = Visibility.Visible; screen.framerater.Start(); } break; } } }
private void EnemyAI_Thread() { while (renderer.isActive()) { if (player.X < X + stopFollowingAt && player.X > X - stopFollowingAt) { if (!played) { played = true; Invoke("outside"); } if (player.X < X) { X = X - 2; } if (player.X > X) { X = X + 2; } if (player.Y > Y) { Y++; } if (player.Y < Y) { Y--; } if (player.X < X + Killingrange && player.X > X - Killingrange && player.Y < Y + Killingrange && player.Y > Y - Killingrange) { Sprite = Image.FromFile("Scene/explode.gif"); Invoke("kill"); } } else { if (played) { Invoke("returnToBase"); } played = false; if (X > baseX) { X -= 3; } if (X < baseX) { X += 3; } if (Y > baseY) { Y -= 3; } if (Y < baseY) { Y += 3; } } Thread.Sleep(10); } X = baseX; Y = baseY; Sprite = Image.FromFile("Scene/enemy.gif"); }
private void CameraMovement_Thread() { while (true) { if (render.isActive()) { try { if (player.Y > 650) { OnFall?.Invoke(); } //because of gravity being in a diffrent thread it checks if it has to move the camera to keep focus in case of falling etc. if (Math.Abs(player.Y - Y * -1) > 425 && player.Y <= 470) { Y -= 0.7f; } if (Up) { //check if collision is present otherwise move player to given direction if (lvl.Tiles.Count(o => o.Y <= player.Y && player.Collide(o) && o.Collidable) == 0) { if (Math.Abs(player.Y - Y * -1) < 125) { Y += 0.8f; } player.Y -= 0.75f; } else { player.Y += 1; Up = false; } } if (Left) { //check if collision is present otherwise move player to given direction if (lvl.Tiles.Count(o => o.X <= player.X && player.Collide(o) && o.Collidable) == 0) { if (X + player.X < 250) { X += 0.45f; } player.X -= 0.45f; } else { player.X += 1; Left = false; } } if (Right) { //check if collision is present otherwise move player to given direction if (lvl.Tiles.Count(o => o.X >= player.X && player.Collide(o) && o.Collidable) == 0) { if (X + player.X > 350) { X -= 0.45f; } player.X += 0.45f; } else { player.X -= 1; Right = false; } } } catch { } Thread.Sleep(1); } } }