public GameplayController() : base(SceneMgr.GetScene("default")["default"]) { GameMgr.MaxGameSpeed = 60; GameMgr.MinGameSpeed = 60; Text.CurrentFont = Resources.Fonts.Arial; ScreenController.Init(); Audio = new SoundController(Layer); MapController.Init(); MapController.CurrentMap.Build(); CollisionDetector.Init(); Scene.Priority = -10000; GUILayer = Scene.CreateLayer("gui"); GUILayer.IsGUI = true; music = new LayeredSound(SoundController.MusicGroup); music.AddLayer("top", Resources.Sounds.MainTopLayer); music.AddLayer("base", Resources.Sounds.MainBaseLayer); music.Play(); SoundController.UpdatingSounds.Add(music); }
[Test] //Test for om der Log funktionen bliver kaldt når der er collision public void CheckIfFileLogCalled() { _log = Substitute.For <FileLogger, ILog>("test"); _uut = new CollisionDetector(_log); _testAirspace = new List <IAirplaneInfo>(); _testAirplaneInfo1 = Substitute.For <IAirplaneInfo>(); _testAirplaneInfo2 = Substitute.For <IAirplaneInfo>(); _testAirspace.Add(_testAirplaneInfo1); _testAirspace.Add(_testAirplaneInfo2); _testAirplaneInfo1.X.Returns(35000); _testAirplaneInfo1.Y.Returns(35000); _testAirplaneInfo1.Altitude.Returns(600); _testAirplaneInfo2.X.Returns(35000); _testAirplaneInfo2.Y.Returns(35000); _testAirplaneInfo2.Altitude.Returns(1100); _uut.Register(_testAirspace); _log.Received().Logs(LOGTYPE.COLLISIONS, Arg.Any <List <string> >()); }
// Use this for initialization void Start() { // コンポーネントを取得 rb = GetComponent <Rigidbody>(); GroundCollision = GetComponent <CollisionDetector>(); // 一定時間おきに地面から離れたところに移動 InvokeRepeating("ResetPosition", 0.0f, cycle); // OnCollisionEnter GroundCollision.onCollisionEnterSmoothed += collision => { // ここに処理を記述 Debug.Log("OnCollisionEnterSmoothed"); }; // OnCollisionStay GroundCollision.onCollisionStaySmoothed += collision => { // ここに処理を記述 Debug.Log("OnCollisionStaySmoothed"); }; // OnCollisionExit GroundCollision.onCollisionExitSmoothed += collision => { // ここに処理を記述 Debug.Log("OnCollisionExitSmoothed"); }; }
public void Check_StopsObject_EvenIfItIsMovingLessThanOnePixel() { var map = CollisionMap.Empty; map.TileSize = 16; map.MapData.Width = 4; // create a fake map // 0, 0, 0, 0, // 0, -1, -1, 0, // 0, -1, -1, 0, // 0, 0, 0, 0 map.MapData[0] = 0; map.MapData[1] = 0; map.MapData[2] = 0; map.MapData[3] = 0; map.MapData[4] = 0; map.MapData[5] = -1; map.MapData[6] = -1; map.MapData[7] = 0; map.MapData[8] = 0; map.MapData[9] = -1; map.MapData[10] = -1; map.MapData[11] = 0; map.MapData[12] = 0; map.MapData[13] = 0; map.MapData[14] = 0; map.MapData[15] = 0; var detector = new CollisionDetector(map); // now, simulate a collision where the entity wants to travel 0.32000000023f on X and 4.8f on Y var result = detector.Check(new Vector2(16, 16), new Vector2(-0.3200000023f, 4.8f), new Vector2(64, 64)); // X position should be pushed back (entity was in a bad spot before) Assert.Equal(16f, result.Position.X); // Y should increase as expected Assert.Equal(20.8f, result.Position.Y); }
public void MyUpdate() { status = new GameStatusUpdater(); colDetector = GetComponent <CollisionDetector>(); if (positioner == null) { positioner = GameObject.Find("MainCamera").GetComponent <CameraPositions>(); } if (updater == null) { updater = GameObject.Find("MainCamera").GetComponent <CameraPositionUpdater>(); } if (GameStatusUpdater.gStatus == GameStatuses.Playable) { if (colDetector.GetConvBool() == true) { if (Input.GetKeyDown(KeyCode.E)) { StartConvo(); updater.SetCameraToInteraction(0); GameStatusUpdater.gStatus = GameStatuses.Conversation; } } } }
private void DetectCollisions(CollisionSphere sphere, CollisionData data) { foreach (var plane in Planes) { CollisionDetector.SphereAndHalfSpace(sphere, plane, data); } foreach (var primative in Primatives) { if (primative == sphere) { continue; } if (data.NoMoreContacts()) { break; } switch (primative) { case CollisionSphere sphere2: CollisionDetector.SphereAndSphere(sphere, sphere2, data); break; case CollisionBox box: CollisionDetector.BoxAndSphere(box, sphere, data); break; } } }
public void TestTwoCirclesAreInTouchCircleCenterIsInMainCircle() { var circle = new RigidCircle(new Vector(20, 0), 15, true, true); var expected = new CollisionInfo(25, new Vector(1, 0), new Vector(5, 0)); Assert.AreEqual(expected, CollisionDetector.GetCollisionInfo(circle, MainCircle)); }
Vector3 characterPosition; //necesitaremos esto para ver si caimos en una esquina public ObstacleAvoidance(Kinetics Character, Transform[] Obstacles, float AvoidDistance, float LookAhead, SteeringOutput CharacterSteering) : base(Character, Character, 1f) { avoidDistance = AvoidDistance; lookAhead = LookAhead; collisionDetector = new CollisionDetector(Obstacles); characterSteering = CharacterSteering; }
void initializeCollisionDetector() { float RAYCASTLENGTH = 2f; float HALFPLAYERWIDTH = .7f; //.709f; float HALFPLAYERHEIGHT = .90f; //.99f;//1.02f; float HALFPLAYERFOOTWIDTH = .2f; collisionDetector = new CollisionDetector(whatIsGround, new CollisionDetectorRaycast { angle = 0f, relativePosition = new Vector2(HALFPLAYERWIDTH, -HALFPLAYERHEIGHT), length = RAYCASTLENGTH }, new CollisionDetectorRaycast { angle = 0f, relativePosition = new Vector2(HALFPLAYERWIDTH, HALFPLAYERHEIGHT), length = RAYCASTLENGTH }, new CollisionDetectorRaycast { angle = Mathf.PI / 2f, relativePosition = new Vector2(HALFPLAYERWIDTH, HALFPLAYERHEIGHT), length = RAYCASTLENGTH }, new CollisionDetectorRaycast { angle = Mathf.PI / 2f, relativePosition = new Vector2(-HALFPLAYERWIDTH, HALFPLAYERHEIGHT), length = RAYCASTLENGTH }, new CollisionDetectorRaycast { angle = Mathf.PI, relativePosition = new Vector2(-HALFPLAYERWIDTH, HALFPLAYERHEIGHT), length = RAYCASTLENGTH }, new CollisionDetectorRaycast { angle = Mathf.PI, relativePosition = new Vector2(-HALFPLAYERWIDTH, -HALFPLAYERHEIGHT), length = RAYCASTLENGTH }, new CollisionDetectorRaycast { angle = 3f * Mathf.PI / 2f, relativePosition = new Vector2(HALFPLAYERWIDTH, -HALFPLAYERHEIGHT - .1f), length = RAYCASTLENGTH }, new CollisionDetectorRaycast { angle = 3f * Mathf.PI / 2f, relativePosition = new Vector2(-HALFPLAYERWIDTH, -HALFPLAYERHEIGHT - .1f), length = RAYCASTLENGTH }); }
protected override void Awake() { base.Awake(); _isInterfaceButton = GetComponent <RectTransform>() != null; _initialLocalPosition = transform.localPosition; var localPos = transform.localPosition; if (_isInterfaceButton) { localPos.z = GetHeightByLerp(RestingHeightLerp); } else { localPos.y = GetHeightByLerp(RestingHeightLerp); } transform.localPosition = localPos; _detector = GetComponent <CollisionDetector>(); AddConfigurableJoint(); GetRigidbody(); JointAnchor = AddAnchor(); gameObject.AddComponent <InteractableItem>().PhysicsLayer = PhysicsLayer.UI; //_initialInverseTransformPoint = transform.InverseTransformPoint(_trigger.transform.position); CurrentState = ButtonState.Idle; }
public void TestOneCircleIsInAnother() { var first = new RigidCircle(new Vector(15, 0), 10, true, true); var expected = new CollisionInfo(25, new Vector(1, 0), new Vector(5, 0)); Assert.AreEqual(expected, CollisionDetector.GetCollisionInfo(first, MainCircle)); }
public void ReturnProperChar() { // Arrange var detector = new CollisionDetector(); // Act var result = detector.GuideMessage('-'); var result1 = detector.GuideMessage('@'); var result2 = detector.GuideMessage('1'); var result3 = detector.GuideMessage('2'); var result4 = detector.GuideMessage('x'); var result5 = detector.GuideMessage('?'); var expected = GlobalMessages.PathMessage; var expected1 = GlobalMessages.RockMessage; var expected2 = GlobalMessages.MonsterMessage; var expected3 = GlobalMessages.BossMonsterMessage; var expected4 = GlobalMessages.ExitMessage; var expected5 = string.Empty; // Assert Assert.AreEqual(expected, result); Assert.AreEqual(expected1, result1); Assert.AreEqual(expected2, result2); Assert.AreEqual(expected3, result3); Assert.AreEqual(expected4, result4); Assert.AreEqual(expected5, result5); }
public void GameLoop(object sender, EventArgs args) { if (currentLevel.WavesAmount == 0) { currentLevel.IsCompleted = true; currentLevel.Particles.Add(ParticleFactory.CreateExit(currentLevel.Exit.Center)); } if (player.IsDead) { ResetState(); } if (currentLevel.IsCompleted && CollisionDetector.GetCollisionInfo(player.CollisionShape, currentLevel.Exit) != null) { currentLevel = LevelManager.MoveNextLevel(); InitState(); } var shouldRenderRaytracing = keyState.pressesOnPAmount % 2 == 1; var shouldRenderDebug = keyState.pressesOnIAmount % 2 == 1; UpdateState(shouldRenderRaytracing); RenderPipeline.Render(currentLevel, camera, cursor.Position, shouldRenderRaytracing, shouldRenderDebug); AudioEngine.Update(); }
public void TestTwoCirclesHaveTheSameCenters() { var first = new RigidCircle(Vector.ZeroVector, 10, true, true); var expected = new CollisionInfo(MainCircle.Radius, new Vector(0, -1), new Vector(0, 30)); Assert.AreEqual(expected, CollisionDetector.GetCollisionInfo(first, MainCircle)); }
private void AddWalls(List <RigidShape> staticShapes, Size levelSizeInTiles) { var circle = new RigidCircle(Vector.ZeroVector, 32, true, true); for (var j = 1; j < levelSizeInTiles.Width - 1; ++j) { for (var i = 1; i < levelSizeInTiles.Height - 1; ++i) { circle.MoveTo(new Vector(j, i) * 32); var canWalk = true; foreach (var staticShape in staticShapes) { if (CollisionDetector.GetCollisionInfo(circle, staticShape) == null) { continue; } canWalk = false; break; } if (!canWalk) { walls.Add(new Point(j, i)); } } } }
public virtual bool Collision(Vector2 position, Level level) { int xa = (int)position.X; int ya = (int)position.Y; if (xa + hitbox.Left < 0 || ya + hitbox.Top < 0 || xa + hitbox.Right >= level.mapWidth * level.CurrentMap.TileWidth || ya + hitbox.Bottom >= level.mapHeight * level.CurrentMap.TileHeight) { return(true); } foreach (var coll in level.maps[mapid].collisions) //MAP Collisions { if (CollisionDetector.Collison(new Rectangle(xa + hitbox.X, ya + hitbox.Y, hitbox.Width, hitbox.Height), coll)) //Level Collisions { LastCollision = null; return(true); } } foreach (var coll in level.entities) //Mobs Collisions { if (coll != this && coll.mapid == level.mapID && coll.solid) { if (xa + hitbox.Left < coll.x + coll.hitbox.Right && xa + hitbox.Right > coll.x + coll.hitbox.Left && ya + hitbox.Top < coll.y + coll.hitbox.Bottom && ya + hitbox.Bottom > coll.y + coll.hitbox.Top) //Level Collisions { if (coll is ChessFigure && this is ChessFigure) { continue; } LastCollision = coll; return(true); } } } return(false); }
public void LoadContent(ArrayList spriteList, ArrayList fireBallList) { //nothing to do here Collision = new CollisionDetector(Game.Scene.Mario, spriteList, fireBallList); controllerList.Add(new KeyboardController(Game.Scene.Mario, Game)); controllerList.Add(new GamepadController(Game.Scene.Mario, Game)); }
public void IsCollisionLineAndCircle_Positive() { LineSegment line1 = new LineSegment(new Vector2(1, -1), new Vector2(1, 1)); Circle circle = new Circle(0.5f, new Vector2(0.5f, 0)); Assert.IsTrue(CollisionDetector.IsCollision(line1, circle)); }
private void InitCone() { CollisionDetector cd = gameObject.GetComponentInChildren <CollisionDetector>(); cd.SuscribeOnTriggerEnter2D(CustomOnTriggerEnter2D); cd.SuscribeOnTriggerExit2D(CustomOnTriggerExit2D); }
public bool Collision(int xa, int ya) //TODO ENTITY COLLISION { xa += (x); ya += (y); if (Collision(new Vector2(xa, ya), level)) { return(true); } foreach (var coll in level.CurrentMap.teleporters) { if (CollisionDetector.Collison(new Rectangle(xa + hitbox.X, ya + hitbox.Y, hitbox.Width, hitbox.Height), coll.position)) { if (this == level.getClientPlayer()) { if (level.ChangeMap(coll.mapID)) { mapid = coll.mapID; x = (int)coll.tpCoordinates.X; y = (int)coll.tpCoordinates.Y; Position = new Vector2(x, y); } } } } return(false); }
private void GameLoop(object sender, EventArgs e) { HighScore += ScoreForTick; if (Enemies.Any(enemy => CollisionDetector.AreCollided(Batwing, enemy))) { timer.Stop(); renderer.ShowEndGameScreen(HighScore); return; } renderer.Clear(); renderer.Draw(Batwing); if (rand.Next(100) < SpawnEnemyChange) { var enemy = enemiesFactory.Get(renderer.ScreenWidth, rand.Next(renderer.ScreenHeight)); Enemies.Add(enemy); GameObjects.Add(enemy); } KillEnemiesIfColliding(); HighScore += Enemies.Count(enemy => !enemy.IsAlive) * ScoreForKill; RemoveNotAliveGameObjects(); UpdateObjectsPositions(); DrawGameObjects(); }
public void SetUp() { _detector = new CollisionDetector(); //Instantiating two colliding tracks and adding them to a list _track1 = new Track { Tag = "AAA111", PositionX = 15000, PositionY = 30000, Altitude = 850, Course = 0, Timestamp = DateTime.Now, Velocity = 0 }; TrackList.Add(_track1); _track2 = new Track { Tag = "BBB222", PositionX = 15000, PositionY = 30000, Altitude = 850, Course = 0, Timestamp = DateTime.Now, Velocity = 0 }; TrackList.Add(_track2); //Attaching handlers to the events. _detector.Separation += (o, e) => separationWasRaised = true; _detector.NotColliding += (o, e) => notColldingWasRaised = true; }
public override void Update() { IsDownPrevious = IsDown; IsDown = false; foreach (var actorEntity in Scene.GetEntityListByComponent <StackableActorComponent>()) { var physics = actorEntity.GetComponent <PhysicsComponent>(); var position = actorEntity.GetComponent <PositionComponent>(); physics.Collider.Position = position.Position; physics.Collider.PreviousPosition = position.PreviousPosition; if (CollisionDetector.CheckCollision(_collider, physics.Collider)) { IsDown = true; break; } } if (Pressed) { var position = GetComponent <PositionComponent>(); SoundController.PlaySoundAt(Resources.Sounds.ButtonPress, position.Position); } if (Released) { var position = GetComponent <PositionComponent>(); SoundController.PlaySoundAt(Resources.Sounds.ButtonRelease, position.Position); } }
private void setupEnvironments(Car car, World world, Game game, Move move) { TilePos.TileSize = game.TrackTileSize; GlobalMap.InstanceInit(world); GlobalMap.Instance.SetupEnvironment(world, game); AngleReachEvent.setupEnvironment(game); MoveToAngleFunction.setupEnvironment(world); MoveToPoint.setupEnvironment(world); PhysicExtensions.setupEnvironment(game); PhysicEventsCalculator.setupEnvironment(game, world); CollisionSide.SetupEnvironment(game); CollisionCircle.SetupEnvironment(game); CollisionDetector.SetupEnvironment(game, GlobalMap.Instance); map.SetupEnvironment(car, GlobalMap.Instance); path.SetupEnvironment(car, GlobalMap.Instance, world, game); foreach (IAction action in actions.Values) { action.setupEnvironment(car, world, game, path); } foreach (AdditionalPoints action in additionalPointsActions) { action.setupEnvironment(car, world, game, path); } }
public bool HasCollision(ICollidablePrimitive other) { #region Argument Check if (other == null) { throw new ArgumentNullException("other"); } #endregion var otherCpp = other as ConvexPolygonPrimitive; if (otherCpp != null) { return(CollisionDetector.CheckPolygonToPolygonCollision(this, otherCpp)); } var line = other as LinePrimitive; if (line != null) { return(CollisionDetector.CheckLineToPolygonCollision(line, this)); } var circle = other as CirclePrimitive; if (circle != null) { return(CollisionDetector.CheckCircleToPolygonCollision(circle, this)); } throw new NotSupportedException(); }
public void TestTwoCirclesAreInTouchOnEdge() { var first = new RigidCircle(new Vector(40, 0), 10, true, true); var expected = new CollisionInfo(0, new Vector(1, 0), new Vector(30, 0)); Assert.AreEqual(expected, CollisionDetector.GetCollisionInfo(first, MainCircle)); }
private static LineSegment2D?ClosestTo(Point pt, ConvexPolygon poly) { FixedPoint? closest = null; LineSegment2D edge = default; for (var i = 0; i < poly.NumLineSegments; i++) { var seg = poly.GetLineSegment(i); var dist = CollisionDetector.DetermineClosestPoint(seg, pt); if (dist == null) { continue; } if (closest == null || dist.Value.Distance < closest) { closest = dist.Value.Distance; edge = seg; } } if (closest == null) { return(null); } return(edge); }
private bool IsInView(Vector objectCenter, List <Edge> sceneEdges) { var vectorToObject = (objectCenter - Position).Normalize(); var sightNormal = sight.GetNormal(); var v = Vector.ScalarProduct(vectorToObject, sightNormal); var sc = Vector.ScalarProduct(vectorToObject, sight); if (sc < 0) { return(false); } var sightAngleVector = v > 0 ? sight.Rotate(sightAngle, Vector.ZeroVector) : sight.Rotate(-sightAngle, Vector.ZeroVector); var sightAngleVectorProjection = Vector.ScalarProduct(sightAngleVector, sightNormal); if (!(Math.Abs(sightAngleVectorProjection) > Math.Abs(v))) { return(false); } foreach (var wall in sceneEdges) { if (CollisionDetector.AreCollide(Position, objectCenter, wall)) { return(false); } } return(true); }
private void CheckCollision(GameTime gameTime, bool handlePlayerCollision) { foreach (var player in _players) { var agentsInCollision = _gameObjects .OfType <CarAgent>() .Where(x => CollisionDetector.IsCollision(x, player)); foreach (var agent in agentsInCollision) { agent.HandleCollision(player, gameTime); player.HandleCollision(agent, gameTime); } if (handlePlayerCollision) { var playersInCollision = _gameObjects .OfType <Car>() .Where(x => !x.Id.Equals(player.Id) && CollisionDetector.IsCollision(x, player)); foreach (var other in playersInCollision) { other.HandleCollision(player, gameTime); player.HandleCollision(other, gameTime); } } } }
public ProjectileCollisionDetector(Game game, List <Fireball> projectile) { myGame = game; proj = projectile; projBlock = new CollisionDetector(); }
private void Start() { characterController = GetComponent<CharacterController>(); crouchCollisionTop = GameObject.Find("collision_detector_top").GetComponent<CollisionDetector>(); crouchCollisionBottom = GameObject.Find("collision_detector_bottom").GetComponent<CollisionDetector>(); controllerHeight = characterController.height; heightDifference = (controllerHeight - crouchHeight); }
public void Summon() { GetGO(); _coll = EnemyGO.AddComponent<CollisionDetector>(); _coll.Hit += Collide; _coll.UpdateEvent += Update; EnemyGO.GetComponent<Collider>().isTrigger = true; EnemyGO.tag = "enemy"; OriginHealth = Health; AddHealthbar(); //AddTriger(); Move(); }
public void Init(Object owner, Vector3 position, Vector3 velocity, float life) { detector = GetComponent<CollisionDetector>(); detector.ClearEvents(); detector.Collided += detector_Collided; Owner = owner; transform.position = position; Velocity = velocity; Lifetime = life; gameObject.SetActive(true); }
public void Build(Vector3 pos) { if (Controller.Gold - Cost >= 0) { GetGO(pos); _enemies = new List<GameObject>(); _coll = TowerGO.AddComponent<CollisionDetector>(); _coll.gameObject.GetComponent<SphereCollider>().radius = Radius; _coll.Hit += Collide; _coll.Exit += ExitCollision; _coll.UpdateEvent += Update; TowerGO.GetComponent<Collider>().isTrigger = true; TowerGO.tag = "tower"; Controller.Gold -= Cost; } }
// Use this for initialization void Start() { if (_instance != null) return; _instance = this; _map = GameObject.Find("Map"); ShowMap(false); _gui = FindObjectOfType<GUI>(); _gui.StartGui(); _originGold = Gold; _endColl = End.AddComponent<CollisionDetector>(); ChangedCells = new List<GridCell>(); _endColl.Hit += EndReached; _originEnemiesInWave = EnemiesInWave; }
public void forCollisionDetectorUseOnly(CollisionDetector cd) { this.cd = cd; }
void Start() { transform.localScale = new Vector3 (_defaultScale, _defaultScale, 1); _timerJump = 0; collisionState = GetComponent<CollisionDetector> (); _animator = gameObject.GetComponent<Animator> (); }
void Start() { Instance = this; }
void Start() { gui = GameObject.FindObjectOfType<GUI>(); collisionDetector = GameObject.FindObjectOfType<CollisionDetector>(); collisionDetector.collisionDelegate = Collision; collectibleList = new List<Collectible>(); indexGridArray = new int[Grid.width * Grid.height]; for (int i = 0; i < indexGridArray.Length; ++i) { indexGridArray[i] = i; } UpdateResolution(); cooldownTransition = new Cooldown(5f); cooldownChilling = new Cooldown(0.5f); cooldownChilling.Start(); startButton = new Button(new Vector2(0.5f, 0.5f)); startButton.UpdateSize(0.3f); // AddCollectible(startButton); Cursor.visible = false; GotoChilling(); }
protected void MoveBall() { //paddleid 1=right paddle, 2 == left paddle CollisionDetector ColliteLeftpaddle = new CollisionDetector(BallPosition, LeftPaddlePosition, 2); CollisionDetector ColliteRightpaddle = new CollisionDetector(BallPosition, RightPaddlePosition, 1); if (ColliteLeftpaddle.hitpaddle || ColliteRightpaddle.hitpaddle) { AudioManager.PlayCue("HitPaddle"); flag1 = true; } if (mySettings.ActiveObstacle) { CollisionDetector CollitetoObstacle = new CollisionDetector(BallPosition, ObstaclePosition); if (CollitetoObstacle.hitobst && flag1) { AudioManager.PlayCue("HitObs"); flag1 = false; } } BallPosition.X += 1 * BallPosition.XSpeedFactor; BallPosition.Y += 1 * BallPosition.YSpeedFactor; // Keep the ball inside of the frame if (BallPosition.Y < 5 || BallPosition.Y > 575) { BallPosition.YSpeedFactor = -BallPosition.YSpeedFactor; AudioManager.PlayCue("HitBorder"); } //if Ball Lost else if (BallPosition.X < 0 || BallPosition.X > 800) { AudioManager.PlayCue("Drop"); if (BallPosition.X < 0) { Player_2_Points++; } else { Player_1_Points++; } BallPosition.reset(); } }
//public RigidBodySimulator(CollisionDetector detector) //{ // m_collisionDetector = detector; //} public RigidBodySimulator() { collisionDetector = new CollisionDetector(this); }