/// <summary> /// Create a new instance of the <see cref="World"/> class. /// </summary> /// <param name="collision">The collisionSystem which is used to detect /// collisions. See for example: <see cref="CollisionSystemSAP"/> /// or <see cref="CollisionSystemBrute"/>. /// </param> public World(CollisionSystem collision) { if (collision == null) { throw new ArgumentNullException("The CollisionSystem can't be null.", "collision"); } arbiterCallback = new Action <object>(ArbiterCallback); integrateCallback = new Action <object>(IntegrateCallback); // Create the readonly wrappers this.RigidBodies = new ReadOnlyHashset <RigidBody>(rigidBodies); this.Constraints = new ReadOnlyHashset <Constraint>(constraints); this.SoftBodies = new ReadOnlyHashset <SoftBody>(softbodies); this.CollisionSystem = collision; collisionDetectionHandler = new CollisionDetectedHandler(CollisionDetected); this.CollisionSystem.CollisionDetected += collisionDetectionHandler; this.arbiterMap = new ArbiterMap(); AllowDeactivation = true; }
public void AddBody(SoftBody body) { if (body == null) { throw new ArgumentNullException(nameof(body), "body can't be null."); } if (softbodies.Contains(body)) { throw new ArgumentException("The body was already added to the world.", nameof(body)); } softbodies.Add(body); CollisionSystem.AddEntity(body); Events.RaiseAddedSoftBody(body); foreach (Constraint constraint in body.EdgeSprings) { AddConstraint(constraint); } foreach (var massPoint in body.VertexBodies) { Events.RaiseAddedRigidBody(massPoint); rigidBodies.Add(massPoint); } }
public void setVars() { touchingUnits = new HashSet <Collider>(); playerCollision = GetComponent <CollisionSystem>(); player = GetComponent <Transform>(); activePlayer = true; }
public MainWindow() { InitializeComponent(); collision = new CollisionSystemSAP(); world = new World(collision); Jitter.Collision.Shapes.Shape shape = new BoxShape(1.0f, 1.0f, 1.0f); body = new RigidBody(shape); JVector pos = new JVector() { X = 0.0f, Y = 0.0f, Z = -12.0f }; body.Position = pos; world.AddBody(body); Jitter.Collision.Shapes.Shape groundShape = new BoxShape(100f, 1.0f, 100f); ground = new RigidBody(groundShape); JVector groundPos = new JVector() { X = 0.0f, Y = -2.0f, Z = 0.0f }; ground.Position = groundPos; world.AddBody(ground); JVector vector = new JVector() { X = 0.0f, Y = -300.0f, Z = 0.0f }; world.Gravity = vector; }
public override void OnTriggerEnter(Collider other) { if (other.gameObject.GetComponent <Car>() != null) { Car otherCar = other.gameObject.GetComponent <Car>(); if (car.state == OCar.State.inLine && otherCar.state == OCar.State.inLine)//道路中行驶的车辆不会碰撞 { return; } Car lucky = CollisionSystem.ChooseLucky(car, otherCar); var value = CollisionSystem.LineLineIntersection(car.transform.position, car.transform.forward, otherCar.transform.position, otherCar.transform.forward); if (value == Vector3.zero)//尾部碰撞器,两车不会碰撞 { return; } var newBarrier = new Barrier(); newBarrier.position = value; if (lucky == car)//设置otherCar的barrier { if (otherCar.barrier == null || Vector3.Distance(otherCar.barrier.position, otherCar.transform.position) >= Vector3.Distance(newBarrier.position, otherCar.transform.position)) { otherCar.barrier = newBarrier; } } if (lucky == otherCar)//设置Car的barrier { if (car.barrier == null || Vector3.Distance(car.barrier.position, car.transform.position) >= Vector3.Distance(newBarrier.position, car.transform.position)) { car.barrier = newBarrier; } } } }
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; collisionSystem = new CollisionSystemPersistentSAP(); collisionSystem.CollisionDetected += new CollisionDetectedHandler(CollisionDetected); world = new World(collisionSystem); Random rr = new Random(); rndColors = new Color[20]; for (int i = 0; i < 20; i++) { rndColors[i] = new Color((float)rr.NextDouble(), (float)rr.NextDouble(), (float)rr.NextDouble()); } wireframe = new RasterizerState(); wireframe.FillMode = FillMode.WireFrame; cullMode = new RasterizerState(); cullMode.CullMode = CullMode.None; normal = new RasterizerState(); }
private bool RemoveBody(RigidBody body, bool removeMassPoints) { if (!removeMassPoints && body.IsParticle) return false; if (!rigidBodies.Remove(body)) return false; foreach (Arbiter arbiter in body.arbiters) { arbiterMap.Remove(arbiter); events.RaiseBodiesEndCollide(arbiter.body1, arbiter.body2); } foreach (Constraint constraint in body.constraints) { constraints.Remove(constraint); events.RaiseRemovedConstraint(constraint); } CollisionSystem.RemoveEntity(body); islands.RemoveBody(body); events.RaiseRemovedRigidBody(body); return true; }
void Start() { stairsLayer = LayerMask.GetMask("Stairs"); collisionSystem = GetComponent <CollisionSystem>(); gravitySystem = GetComponent <JumpGravitySystem>(); inputController = FindObjectOfType <InputController>(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Create game systems InputSystem = new InputSystem(this); NetworkSystem = new NetworkSystem(this); RenderingSystem = new RenderingSystem(this); MovementSystem = new MovementSystem(this); WeaponSystem = new WeaponSystem(this); EnemyAISystem = new EnemyAISystem(this); NpcAISystem = new NpcAISystem(this); GarbagemanSystem = new GarbagemanSystem(this); CollisionSystem = new Systems.CollisionSystem(this); RoomChangingSystem = new RoomChangingSystem(this); QuestLogSystem = new QuestLogSystem(this); SpriteAnimationSystem = new SpriteAnimationSystem(this); SkillSystem = new SkillSystem(this); TextSystem = new TextSystem(this); // Testing code. LevelManager.LoadContent(); LevelManager.LoadLevel("D01F01R01"); //End Testing Code }
public virtual void DoSelfCollision(CollisionDetectedHandler collision) { if (!selfCollision) { return; } JVector point, normal; float penetration; for (int i = 0; i < points.Count; i++) { queryList.Clear(); this.dynamicTree.Query(queryList, ref points[i].boundingBox); for (int e = 0; e < queryList.Count; e++) { Triangle t = this.dynamicTree.GetUserData(queryList[e]); if (!(t.VertexBody1 == points[i] || t.VertexBody2 == points[i] || t.VertexBody3 == points[i])) { if (XenoCollide.Detect(points[i].Shape, t, ref points[i].orientation, ref JMatrix.InternalIdentity, ref points[i].position, ref JVector.InternalZero, out point, out normal, out penetration)) { int nearest = CollisionSystem.FindNearestTrianglePoint(this, queryList[e], ref point); collision(points[i], points[nearest], point, point, normal, penetration); } } } } }
// Token: 0x0600026C RID: 620 RVA: 0x00007634 File Offset: 0x00005834 public void _DoStart() { bool flag = PhysicService._instance != this; if (flag) { Debug.LogError("Duplicate CollisionSystemAdapt!", Array.Empty <object>()); } else { CollisionSystem collisionSystem = new CollisionSystem { worldSize = this.worldSize, pos = this.pos, minNodeSize = this.minNodeSize, loosenessval = this.loosenessval }; this._debugService.Trace(string.Format("worldSize:{0} pos:{1} minNodeSize:{2} loosenessval:{3}", new object[] { this.worldSize, this.pos, this.minNodeSize, this.loosenessval }), false, false); this.collisionSystem = collisionSystem; collisionSystem.DoStart(this.collisionMatrix, this.allTypes); CollisionSystem collisionSystem2 = collisionSystem; collisionSystem2.funcGlobalOnTriggerEvent = (FuncGlobalOnTriggerEvent)Delegate.Combine(collisionSystem2.funcGlobalOnTriggerEvent, new FuncGlobalOnTriggerEvent(PhysicService.GlobalOnTriggerEvent)); string colliderDataRelFilePath = this.config.ColliderDataRelFilePath; ColliderData[] datas = ColliderDataUtil.ReadFromFile(Path.Combine(ProjectConfig.DataPath, colliderDataRelFilePath)); this.InitStaticColliders(datas); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { CollisionDetectionSystem det = new CollisionDetectionSystem(); CollisionSystem col = new CollisionSystem(); det.Subscribe(col); SystemManager.Instance.AddSystem(new ScrollingBackgroundSystem(instance.GraphicsDevice, instance.GetContent <Texture2D>("Pic/gamebackground"))); SystemManager.Instance.AddSystem(new ChangeCubesSystem()); SystemManager.Instance.AddSystem(col); SystemManager.Instance.AddSystem(new HUDSystem()); HealthSystem healtSystem = new HealthSystem(); healtSystem.initialize(); SystemManager.Instance.AddSystem(healtSystem); SystemManager.Instance.AddSystem(det); SystemManager.Instance.AddSystem(new MovementSystem()); SystemManager.Instance.AddSystem(new BallOfSpikesSystem()); SystemManager.Instance.AddSystem(new SpawnPowerUpSystem(10)); SystemManager.Instance.AddSystem(new AISystem()); SystemManager.Instance.AddSystem(new DrawTTLSystem("Fonts/TestFont")); FPSCounterComponent fps = new FPSCounterComponent(); int ids = ComponentManager.Instance.CreateID(); ComponentManager.Instance.AddComponentToEntity(ids, fps); StartUpScreenScene stateOne = new StartUpScreenScene(10000); SceneSystem.Instance.setCurrentScene(stateOne); base.Initialize(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { wandererWorld = Matrix.Identity; wanderer = new WandererBody(this); heightMapTransformSystem_Wanderer = new HeightMapTransformSystem_Wanderer(); heightMapComponent = new HeightMapComponent(); heightMapCameraComponent = new HeightMapCameraComponent(); robotComponent = new RobotComponent(); heightMapSystem = new HeightmapSystem(); heightMapTranformSystem = new HeightMapTranformSystem(); heightMapRenderSystem = new HeightMapRenderSystem(graphics.GraphicsDevice); robotSystem = new RobotSystem(); robotTranformSystem = new RobotTranformSystem(); robotRenderSystem = new RobotRenderSystem(); collisionSystem = new CollisionSystem(); houseSystem = new HouseSystem(this); systemRenderer = new Renderer(); base.Initialize(); }
internal PhysicsSystem() { Bodies = new Dictionary <LatipiumObject, RigidBody>(); InitializedTypes = new HashSet <LatipiumObject>(); Collision = new CollisionSystemSAP(); World = new World(Collision); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Create game systems InputSystem = new InputSystem(this); NetworkSystem = new NetworkSystem(this); RenderingSystem = new RenderingSystem(this); MovementSystem = new MovementSystem(this); WeaponSystem = new WeaponSystem(this); EnemyAISystem = new EnemyAISystem(this); NpcAISystem = new NpcAISystem(this); GarbagemanSystem = new GarbagemanSystem(this); CollisionSystem = new Systems.CollisionSystem(this); RoomChangingSystem = new RoomChangingSystem(this); QuestLogSystem = new QuestLogSystem(this); SpriteAnimationSystem = new SpriteAnimationSystem(this); SkillSystem = new SkillSystem(this); TextSystem = new TextSystem(this); EngineeringOffenseSystem = new EngineeringOffenseSystem(this); HUDSystem = new HUDSystem(this); InputHelper.Load(); HUDSystem.LoadContent(); // Testing code. LevelManager.LoadContent(); LevelManager.LoadLevel("D01F01R01"); //Song bg = Content.Load<Song>("Audio/Main_Loop"); //MediaPlayer.Stop(); //MediaPlayer.IsRepeating = true; //MediaPlayer.Play(bg); //End Testing Code }
/// <summary> /// The root scene object which contains all scene objects. /// </summary> public Scene() : base() { Name = "Scene-" + Guid.NewGuid(); _transform.Root = _transform; gameObjects = new List <GameObject>(); _scene = this; renderList = new List <Renderer>(10); materials = new List <Material>(5); effects = new List <Effect>(5); materialsEffectIndex = new Dictionary <int, int>(5); colliders = new List <Collider>(5); cameras = new List <Camera>(1); scripts = new List <Behaviour>(5); lights = new List <Light>(2); prefabs = new List <GameObject>(); postProcessPasses = new List <PostProcessPass>(); _componentsToDestroy = new List <Component>(); _needRemoveCheck = false; defaultMaterial = new UnlitMaterial(); RenderSettings = new RenderSettings(); _physicsCollisionSystem = new CollisionSystemSAP(); _physicsWorld = new World(_physicsCollisionSystem); _reflectionProbes = new List <ReflectionProbe>(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here this.manager = new ComponentManager(this.Content); colsys = new CollisionSystem(); consys = new ControlSystem(); projsys = new ProjectileSystem(); pathsys = new PathingSystem(); anisys = new AnimatedSpriteSystem(); paused = false; mainMenu = true; //start with main menu open dead = false; realDead = false; victory = false; //Create stages this.stages = new List <Stage>(); Stage stage1 = new Stage("stage1.tmx", this.manager); this.stages.Add(stage1); Stage stage2 = new Stage("stage2.tmx", this.manager); this.stages.Add(stage2); Stage stage3 = new Stage("stage3.tmx", this.manager); this.stages.Add(stage3); Stage stage4 = new Stage("stage4.tmx", this.manager); this.stages.Add(stage4); Stage stage5 = new Stage("stage5.tmx", this.manager); this.stages.Add(stage5); Stage stage6 = new Stage("stage6.tmx", this.manager); this.stages.Add(stage6); Stage stage7 = new Stage("stage7.tmx", this.manager); this.stages.Add(stage7); Stage stage8 = new Stage("stage8.tmx", this.manager); this.stages.Add(stage8); Stage stage9 = new Stage("stage9.tmx", this.manager); this.stages.Add(stage9); Stage stage10 = new Stage("stage10.tmx", this.manager); this.stages.Add(stage10); Stage stage11 = new Stage("stage11.tmx", this.manager); this.stages.Add(stage11); Stage stage12 = new Stage("stage12.tmx", this.manager); this.stages.Add(stage12); this.manager.numStages = this.stages.ToArray().Length; this.screenBox = new Rectangle(0, 0, 800, 480); base.Initialize(); }
public static void HeavyAttack(int entity, int position) { ComponentManager cm = ComponentManager.GetInstance(); PositionComponent posComp; MoveComponent moveComp; CollisionComponent collComp; StatsComponent statComp; if (cm.TryGetEntityComponents(entity, out posComp, out moveComp, out collComp, out statComp)) { int width = 70; int height = 70; Point attackPoint = new Point(moveComp.Direction.X * ((width / 2) + (collComp.CollisionBox.Size.X / 2)) - (width / 2), moveComp.Direction.Y * ((height / 2) + (collComp.CollisionBox.Size.Y / 2)) - (height / 2)); Rectangle areOfEffect = new Rectangle(posComp.Position.ToPoint() + attackPoint, new Point(width, height)); heavyAttack = areOfEffect; List <int> entitiesHit = CollisionSystem.DetectAreaCollision(areOfEffect); foreach (int entityHit in entitiesHit) { if (entityHit == entity) { continue; } if (cm.HasEntityComponent <HealthComponent>(entityHit) && !cm.HasEntityComponent <PlayerControlComponent>(entityHit)) { HealthComponent damageComp = cm.GetComponentForEntity <HealthComponent>(entityHit); float damage = 11 + statComp.Strength * 3.5f; damageComp.IncomingDamage.Add((int)damage); damageComp.LastAttacker = entity; } } } }
public Game1(CollisionSystem collisionSystem) { _collisionSystem = collisionSystem; graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IsMouseVisible = true; }
public override bool OpenFileData(FileStream stream) { using (var reader = new StreamReader(stream)) { CollisionSystem = JsonConvert.DeserializeObject <CollisionSystem>(reader.ReadToEnd()); } return(true); }
public World(GMGame game) { Game = game; components = new ComponentStore(); CollisionSystem = new CollisionSystem(); entities = new Dictionary <int, Entity>(); toBeAdded = new List <Entity>(); }
public void Spawn(SeagullSpawner spawner, float speed, float cooldown) { AssignTarget("Home"); this.speed = speed; this.cooldown = cooldown; this.spawner = spawner; collisionSystem = GetComponent <CollisionSystem>(); collisionSystem.Collided += ChangeDirection; }
private string WriteCollsionTypesChunk(CollisionSystem collisionSystem, BinaryWriter w) { var count = collisionSystem.CollisionTypes.Count(x => x.Id != Guid.Empty); if (count == 0) { return(null); } w.Write((ushort)(count + 1)); w.Write((ushort)0); // RESERVED w.Write((uint)0); // RESERVED // Write empty collision type w.Write(0); foreach (var item in collisionSystem.CollisionTypes) { if (item.Id == Guid.Empty) { continue; } int value; Guid valueId = item.EffectParameterValueId ?? Guid.Empty; if (!EffectsDictionary.TryGetValue(item.Effect, out byte effectId)) { Log.Warning($"Effect {item.Effect} not found; {nameof(effectId)} will be set to 0."); } if (item.Effect == Effects.WalkEffect) { if (!WalksDictionary.TryGetValue(valueId, out var data)) { Log.Warning($"Effect {valueId} not found; {nameof(data)} will be set to 0."); } value = data; } else if (item.Effect == Effects.WalkEffect) { if (!BehaviorsDictionary.TryGetValue(valueId, out var data)) { Log.Warning($"Effect {valueId} not found; {nameof(data)} will be set to 0."); } value = data; } else { value = item.EffectParameterValue ?? 0; } w.Write(effectId); w.Write((byte)0); w.Write((ushort)value); } return("TYP\x01"); }
public SystemManager(Game1 myGame) { this.myGame = myGame; // Initiate Instances sSelectionHandler = new SelectionHandlerSystem(myGame); sHealth = new HealthSystem(myGame); sMovement = new MovementSystem(myGame); sSpawn = new SpawnSystem(myGame); sCollision = new CollisionSystem(myGame); }
/// <summary> /// Does not schedule the arena for physics updates. That has to happen in subclass constructor. /// Just make sure to remove the world from the physics engine later. /// </summary> /// <param name="cs"></param> internal Arena3D(CollisionSystem cs) { this.cs = cs; world = new World(cs); objects = new SortedList <int, ObjectData>(); spawnable_rigid_bodies = new List <RigidBody>(); random = new Random(); Physics3DScheduler.Instance.AddWorld(world, this); }
public void SphereCubeOverlap() { Sphere sphere = new Sphere(new Float3(15, 0, 0), 10); Cube cube = new Cube(new Float4(0), new Float4(10), Quaternion.Default); var data = CollisionSystem.SphereCubeIntersection(sphere, cube); Assert.AreEqual(true, data.Intersecting); Assert.AreEqual(5, data.Depth); Assert.AreEqual(new Float3(1, 0, 0), data.Normal); }
public void SphereSphereOverlap() { Sphere sphere1 = new Sphere(new Float3(0), 10); Sphere sphere2 = new Sphere(new Float3(15, 0, 0), 10); var data = CollisionSystem.SphereSphereIntersection(sphere1, sphere2); Assert.AreEqual(true, data.Intersecting); Assert.AreEqual(5, data.Depth); Assert.AreEqual(new Float3(-1, 0, 0), data.Normal); }
public void SphereAABBOverlap() { Sphere sphere = new Sphere(new Float3(15, 0, 0), 10); AABB aabb = new AABB(new Float4(0), new Float4(10)); var data = CollisionSystem.SphereAABBIntersection(sphere, aabb); Assert.AreEqual(true, data.Intersecting); Assert.AreEqual(5, data.Depth); Assert.AreEqual(new Float3(1, 0, 0), data.Normal); }
private void Awake() { collisionHulls = new List <CollisionHull2D>(FindObjectsOfType <CollisionHull2D>()); hullCollisions = new List <CollisionHull2D.Collision>(); toRemove = new List <CollisionHull2D>(); if (_instance == null) { _instance = this; } }
static void Main(string[] args) { var particles = args.Length > 0 ? LoadParticlesFromFile(args[0]) : GenerateParticles(1000); var collisionSystem = new CollisionSystem(particles); using (var game = new Game1(collisionSystem)) game.Run(); }
public World(CollisionSystem collision) { if (collision == null) throw new ArgumentNullException("collision", "The CollisionSystem can't be null."); arbiterCallback = ArbiterCallback; integrateCallback = IntegrateCallback; RigidBodies = new ReadOnlyHashset<RigidBody>(rigidBodies); Constraints = new ReadOnlyHashset<Constraint>(constraints); SoftBodies = new ReadOnlyHashset<SoftBody>(softbodies); CollisionSystem = collision; collisionDetectionHandler = CollisionDetected; CollisionSystem.CollisionDetected += collisionDetectionHandler; arbiterMap = new ArbiterMap(); AllowDeactivation = true; }