protected override void OnUpdating() { base.OnUpdating(); if (!MapEvents.Any(obj => obj.IsUpdated)) { foreach (MapObject item in Objects.Where(obj => obj is MapObject mapObject && (mapObject.GetGlobalPosition() - Player.Position).Length > 2500 && mapObject.IsUpdated)) { item.IsUpdated = false; if (item.CollisionShape is PhysicalRectangleShape shape) { shape.IsActive = false; } } foreach (MapObject item in Objects.Where(obj => obj is MapObject mapObject && (mapObject.GetGlobalPosition() - Player.Position).Length <= 2500 && !mapObject.IsUpdated)) { item.IsUpdated = true; if (item.CollisionShape is PhysicalRectangleShape shape) { shape.IsActive = true; } } } UpdateOtherPlayers(); if (!SavePoints.Any(obj => obj.IsActive)) { PhysicalWorld?.Update(); } UpdateCollision(); }
private void AddRoofRigidBody() { var roofShape = new StaticPlaneShape(TGCVector3.Down.ToBulletVector3(), -3580); var roofMotionState = new DefaultMotionState(); var roofInfo = new RigidBodyConstructionInfo(0, roofMotionState, roofShape); var roofBody = new RigidBody(roofInfo); PhysicalWorld.AddBodyToTheWorld(roofBody); }
public GameWorld() { game = null; currentShiftX = neededShiftX = 0; currentShiftY = neededShiftY = 0; StaticImage = new Bitmap(2000, 800); world = new PhysicalWorld(); Shapes = new List <GameObject>(); player = null; }
public override void HandleCollision(Collision collision) { if (!Enabled) { return; } var target = collision.a == this ? collision.b : collision.a; var delta = PhysicalWorld.GetVectorForResolveCollision(target, this); if (delta.DotProductWith(PhysicalWorld.acceleration).IsLess(0)) { Activated = true; } }
private void SelectItem(TypeCommon item) { if (item.Mesh != null && Input.keyPressed(Key.E)) { SoundManager.Collect.play(); ShowInfoItemCollect = true; ItemSelected = item.Name; PhysicalWorld.RemoveBodyToTheWorld(item.Body); QuadTree.RemoveMesh(item.Mesh); if (item.Name.Contains("CORAL")) { Common.ListCorals.Remove(item); } else { Common.ListOres.Remove(item); } } }
public Entity GetEntityAt(Vector2 position, out Physics.Dynamics.Body body, out Physics.Dynamics.Fixture fixture) { fixture = PhysicalWorld.TestPoint(position.ToFPVector2()); body = null; if (fixture == null) { return(null); } body = fixture.Body; if (body == null) { return(null); } if (body.UserData is IPhysicsUserData) { return(((IPhysicsUserData)body.UserData).CustomData as Entity); } return(null); }
/// <summary> /// マップのロード /// </summary> /// <param name="mapIO">マップデータ</param> /// <param name="initDoorID">初期ドアID</param> /// <param name="initSavePointID">初期セーブポイント</param> /// <param name="loader">ロードするオブジェクト</param> /// <returns></returns> public async Task LoadMapData(SatIO.MapIO mapIO, int initDoorID, int initSavePointID, ILoader loader) { //背景 foreach (var item in mapIO.BackGrounds) { var backGround = await BackGround.CreateBackGroudAsync(item); AddObject(backGround); loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1); } //物理世界構築 PhysicalWorld = new PhysicalWorld(new asd.RectF(new asd.Vector2DF(-200, -200), mapIO.Size + new asd.Vector2DF(200, 200) * 2), new asd.Vector2DF(0, 8000)); //カメラ設定 { PlayerCamera = new ScrollCamera(mapIO.CameraRestrictions); PlayerCamera.HomingObject = Player; PlayerCamera.Src = new asd.RectI(0, 0, (int)OriginDisplaySize.X, (int)OriginDisplaySize.Y); PlayerCamera.MapSize = mapIO.Size; AddObject(PlayerCamera); Camera.IsDrawn = false; Camera.IsUpdated = false; } //障害物 foreach (var item in mapIO.CollisionBoxes) { PhysicalRectangleShape temp = new PhysicalRectangleShape(PhysicalShapeType.Static, PhysicalWorld); temp.Density = 1; temp.Restitution = 0; temp.Friction = 0; temp.DrawingArea = new asd.RectF(item.Position, item.Size); Obstacles.Add(temp); loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1); #if DEBUG asd.GeometryObject2D geometryObject = new asd.GeometryObject2D(); geometryObject.Shape = temp; geometryObject.Color = new asd.Color(0, 0, 255, 100); geometryObject.DrawingPriority = 2; AddObject(geometryObject); #endif } foreach (var item in mapIO.CollisionTriangles) { PhysicalTriangleShape temp = new PhysicalTriangleShape(PhysicalShapeType.Static, PhysicalWorld); temp.Density = 1; temp.Restitution = 0; temp.Friction = 0; var i = 0; foreach (var vertex in item.vertexes) { temp.SetPointByIndex(vertex, i); i++; } Obstacles.Add(temp); loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1); #if DEBUG asd.GeometryObject2D geometryObject = new asd.GeometryObject2D(); geometryObject.Shape = temp; geometryObject.Color = new asd.Color(0, 0, 255, 100); geometryObject.DrawingPriority = 2; AddObject(geometryObject); #endif } //ドア var tempDoors = new List <Door>(); foreach (var item in mapIO.Doors) { var door = await Door.CreateDoorAsync(item); door.OnLeave += OnLeave; AddObject(door); tempDoors.Add(door); loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1); } //マップオブジェクト foreach (var item in mapIO.MapObjects) { try { var mapObject = await MapObject.CreateMapObjectAsync(item); AddObject(mapObject); } catch (Exception e) { Logger.Error(e); } loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1); } //イベントオブジェクト List <IActor> actors = new List <IActor>(GameScene.Players); foreach (var item in mapIO.EventObjects) { try { var eventObject = await EventObject.CreateEventObjectAsync(item); AddObject(eventObject); actors.Add(eventObject); } catch (Exception e) { Logger.Error(e); } loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1); } //イベント if (Scene is GameScene gameScene) { foreach (var item in mapIO.MapEvents) { if (GameScene.EndEvents.Any(obj => obj.Key == gameScene.MapPath && obj.Value == item.ID)) { continue; } try { bool isSkip = false; foreach (var item2 in item.Actors.Where(obj => obj.Path != null && obj.Path.IndexOf(".pc") > -1)) { if (!gameScene.CanUsePlayers.Any(obj => obj.Path == item2.Path)) { isSkip = true; break; } } if (isSkip) { continue; } Object.MapEvent.MapEvent temp = await Object.MapEvent.MapEvent.CreateMapEventAsync(item, actors, PlayerCamera); AddObject(temp); } catch (Exception e) { Logger.Error(e); } loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1); } } //セーブポイント List <SavePoint> tempSavePoints = new List <SavePoint>(); foreach (var item in mapIO.SavePoints) { SavePoint savePoint = new SavePoint(item); AddObject(savePoint); tempSavePoints.Add(savePoint); loader.ProgressInfo = (loader.ProgressInfo.taskCount, loader.ProgressInfo.progress + 1); } //プレイヤー初期配置 if (initSavePointID != -1 && tempSavePoints.FirstOrDefault(savePoint => savePoint.ID == initSavePointID) != null) { Player.Position = tempSavePoints.FirstOrDefault(savePoint => savePoint.ID == initSavePointID).Position; } else if (initDoorID != -1 && tempDoors.FirstOrDefault(door => door.ID == initDoorID) != null) { Door door = tempDoors.FirstOrDefault(obj => obj.ID == initDoorID); Player.Position = door.Position; door.Come(); } return; }
internal World(GameState gameState, ParticleManager particles) { GameState = gameState; _physicalWorld = new PhysicalWorld(); _particles = particles; }
public void CreateBulletCallbacks(CharacterStatus characterStatus) => PhysicalWorld.AddContactPairTest(Shark.Body, Character.Body, new SharkAttackCallback(Shark, characterStatus, SoundManager));
private void InitializerObjects() { FogShader = TGCShaders.Instance.LoadEffect(ShadersDir + "Shaders.fx"); FogShader.SetValue("ColorFog", Color.SteelBlue.ToArgb()); FogShader.SetValue("StartFogDistance", 2000); FogShader.SetValue("EndFogDistance", 10000); FogShader.SetValue("globalLightPosition", TGCVector3.TGCVector3ToFloat4Array(LightPosition)); SetMaterialColors(); /* Initializer object */ LightBox = TGCBox.fromSize(TGCVector3.One * 150, Color.White); Skybox = new Skybox(MediaDir, Camera); Water = new Water(MediaDir, ShadersDir, new TGCVector3(0, 3500, 0)); Ship = new Ship(MediaDir); ShowScene = true; Terrain = new Terrain(MediaDir, ShadersDir); MeshBuilder = new MeshBuilder(Terrain, Water); Shark = new Shark(MediaDir, Skybox, Terrain, Camera, SoundManager); Character = new Character(Camera, Input, SoundManager); Weapon = new Weapon(MediaDir, Camera); Vegetation = new Vegetation(MediaDir); Common = new Common(MediaDir); Fishes = Common.ListFishes.Select(mesh => new Fish(Skybox, Terrain, mesh)).ToList(); Bubble = new Bubble(MediaDir); AddWeaponToCharacter(); /* Location */ MeshBuilder.LocateMeshesInWorld(meshes: ref Vegetation.ListAlgas, area: Skybox.CurrentPerimeter); MeshBuilder.LocateMeshesInWorld(meshes: ref Common.ListCorals, area: Skybox.CurrentPerimeter); MeshBuilder.LocateMeshesInWorld(meshes: ref Common.ListOres, area: Skybox.CurrentPerimeter); MeshBuilder.LocateMeshesInWorld(meshes: ref Common.ListRock, area: Skybox.CurrentPerimeter); MeshBuilder.LocateMeshesInWorld(meshes: ref Common.ListFishes, area: Skybox.CurrentPerimeter); MeshBuilder.LocateMeshesInWorld(meshes: ref Bubble.Bubbles, area: Skybox.CurrentPerimeter); Common.LocateObjects(); /* Add rigidBody to the world */ PhysicalWorld = new PhysicalWorld(); PhysicalWorld.AddBodyToTheWorld(Terrain.Body); PhysicalWorld.AddBodyToTheWorld(Character.Body); PhysicalWorld.AddBodyToTheWorld(Ship.BodyOutdoorShip); PhysicalWorld.AddBodyToTheWorld(Ship.BodyIndoorShip); PhysicalWorld.AddBodyToTheWorld(Shark.Body); Common.ListCorals.ForEach(coral => PhysicalWorld.AddBodyToTheWorld(coral.Body)); Common.ListOres.ForEach(ore => PhysicalWorld.AddBodyToTheWorld(ore.Body)); Common.ListRock.ForEach(rock => PhysicalWorld.AddBodyToTheWorld(rock.Body)); AddRoofRigidBody(); Bubble.SetShader(FogShader, "FogBubble"); Skybox.SetShader(FogShader, "Fog"); Common.SetShader(FogShader, "Fog"); Shark.SetShader(FogShader, "Fog"); Vegetation.SetShader(FogShader, "FogVegetation"); Ship.SetShader(ref FogShader); LightBox.Transform = TGCMatrix.Translation(LightPosition); var meshes = GetStaticMeshes(); QuadTree.Camera = Camera; QuadTree.create(meshes, Terrain.world.BoundingBox); }