protected virtual void CollideWith(CollidableObject obj) { if (obj == null) { return; } else if (obj is Unit) { Unit unit = (Unit)obj; if (IsCollide(unit)) { Vel.Y = -Maxvel.Y * 3; Vel.X = -Vel.X * XBound; HP -= unit.Attack; OnCollide(unit); } } else if (obj is Bullet) { Bullet bullet = (Bullet)obj; if (IsCollide(bullet)) { //HPとかはbulletクラス OnCollide(bullet); } } }
/// <summary> /// Updates the collisions between a list of entities and a particular object /// by brute force iteration over all the entities. /// </summary> /// <param name="entities"></param> /// <param name="obj"></param> private void UpdateObjectEntityCollisions(List <CollidableObject> entities, CollidableObject obj) { foreach (var item in entities) { Vector2 penDepth; if (obj.CheckCollision(item, out penDepth)) { RecordCollision(obj, item); CollisionType type = CollisionType.stay; if (!wasCollidingWith(obj, item))//Weren't colliding before-> collision enter { type = CollisionType.enter; } Player player = obj as Player; if (player != null) { GameEventManager.Instance.PlayerCollision(player, item, penDepth, type); } else { GameEventManager.Instance.NonPlayerCollision(obj, item, penDepth); } } } }
private void OnSelectedObjectManipulatorTriggerEnter(Collider otherCollider) { ObjectManipulator currentObjectManipulator = objectManipulationInputController.CurrentObjectManipulator; CollidableObject componentInParent = otherCollider.gameObject.GetComponentInParent <CollidableObject>(); if (componentInParent != null && currentObjectManipulator != null) { switch (objectManipulationInputController.GetCollisionRule(componentInParent)) { case CollisionRuleResult.Stack: case CollisionRuleResult.StackXNormal: break; case CollisionRuleResult.Intersect: break; case CollisionRuleResult.NotAllowed: currentObjectManipulator.CollisionIsValid = false; break; case CollisionRuleResult.Squash: componentInParent.IsSquashed = true; break; } } }
public NonPlayerCollisionEventArgs(CollidableObject collider, object colllidedWith, Vector2 collisionDepth, CollisionType collisionType) { this.collider = collider; this.colllidedWith = colllidedWith; this.collisionDepth = collisionDepth; this.collisionType = collisionType; }
private void CollideWith(CollidableObject obj) { if (obj == null) { return; } if (obj is Bullet) { CollidableObject bullet = obj; if (IsCollide(bullet)) { OnCollide(bullet); bullet.OnCollide(this); asd.Engine.AddObject2D(new ItemGetEffect_PenetrateTriShot(new asd.Vector2DF(320, 240))); } } if (obj is PenetrateBullet) { CollidableObject bullet = obj; if (IsCollide(bullet)) { OnCollide(bullet); //bullet.OnCollide(this); asd.Engine.AddObject2D(new ItemGetEffect_PenetrateTriShot(new asd.Vector2DF(320, 240))); } } }
private void removeObjectManipulators() { modifyObjectManipulators(delegate(GameObject go, DecorationLayoutData data) { ManipulatableObjectEffects component = go.GetComponent <ManipulatableObjectEffects>(); if ((bool)component) { UnityEngine.Object.Destroy(component); } ManipulatableObject component2 = go.GetComponent <ManipulatableObject>(); if ((bool)component2) { component2.OnRemoved -= onObjectRemoved; component2.BeforeParentChanged -= onBeforeManipulatableObjectReParented; component2.AfterParentChanged -= onAfterManipulatableObjectReParented; UnityEngine.Object.Destroy(component2); } CollidableObject component3 = go.GetComponent <CollidableObject>(); if ((bool)component3) { UnityEngine.Object.Destroy(component3); } for (int i = 0; i < sceneModifiers.Length; i++) { sceneModifiers[i].ObjectRemoved(data, go); } }); }
private void linkManipulatableObjectWithDefinition(ManipulatableObject mo, CollidableObject co, DecorationLayoutData data) { CollisionRuleSetDefinitionKey collisionRuleSet = null; switch (data.Type) { case DecorationLayoutData.DefinitionType.Decoration: { if (decorationDefinitions.TryGetValue(data.DefinitionId, out var value2)) { collisionRuleSet = value2.RuleSet; mo.Type = DecorationLayoutData.DefinitionType.Decoration; mo.DefinitionId = value2.Id; } break; } case DecorationLayoutData.DefinitionType.Structure: { if (structureDefinitions.TryGetValue(data.DefinitionId, out var value)) { collisionRuleSet = value.RuleSet; mo.Type = DecorationLayoutData.DefinitionType.Structure; mo.DefinitionId = value.Id; } break; } } co.CollisionRuleSet = collisionRuleSet; }
public CollisionRuleResult GetCollisionRule(CollidableObject installedDecoration) { if (CurrentlySelectedObject != null) { CollidableObject component = CurrentlySelectedObject.GetComponent <CollidableObject>(); if (component == null || component.CollisionRuleSet == null || installedDecoration == null || component.CollisionRuleSet == null) { Log.LogError(this, "Problem: Installed decoration or selected object is not tracked properly and the placement rule cannot be found. Defaulting to stacking"); return(CollisionRuleResult.Stack); } if (decorationInstallationRulesets.ContainsKey(installedDecoration.CollisionRuleSet.Id)) { CollisionRuleSetDefinition collisionRuleSetDefinition = decorationInstallationRulesets[component.CollisionRuleSet.Id]; CollisionRuleDefinition[] installedItemRules = collisionRuleSetDefinition.InstalledItemRules; foreach (CollisionRuleDefinition collisionRuleDefinition in installedItemRules) { if (collisionRuleDefinition.InstalledItem.Id == installedDecoration.CollisionRuleSet.Id) { return(collisionRuleDefinition.Result); } } throw new InvalidOperationException(string.Format("No rule was found for the combination {0} and {1} on of the selected object {0} and the installed object", component.CollisionRuleSet.Id, installedDecoration.CollisionRuleSet.Id, CurrentlySelectedObject, installedDecoration.gameObject)); } Log.LogErrorFormatted(this, "Unknown rule: {0}, found for the selected item {1}. Defaulting to stacking", installedDecoration.CollisionRuleSet.Id, CurrentlySelectedObject); return(CollisionRuleResult.Stack); } throw new InvalidOperationException("Selected item is null"); }
//want do we want to do now that we have collided with an object? private void HandleCollisions(CollidableObject collidableObjectCollider, CollidableObject collidableObjectCollidee) { //did the "as" typecast return a valid object? if (collidableObjectCollidee != null) { if (collidableObjectCollidee.ActorType == ActorType.CollidablePickup) { #region DEMO COLLISION RESPONSE FOR PICKUPS EventDispatcher.Publish(new EventData(collidableObjectCollidee, EventActionType.OnRemoveActor, EventCategoryType.SystemRemove)); //after fixing the event dispatcher update() method we can not successfully increment UI and/or send other events (e.g. play sound) object[] additionalEventParams = { AppData.PlayerOneProgressControllerID, 1 }; EventDispatcher.Publish(new EventData(EventActionType.OnHealthDelta, EventCategoryType.Player, additionalEventParams)); object[] additionalParameters = { "boing" }; EventDispatcher.Publish(new EventData(EventActionType.OnPlay, EventCategoryType.SoundStart, additionalParameters)); //do whatever you want here when you hit a collidable pickup... #endregion } //add else if statements here for all the responses that you want your player to have else if (collidableObjectCollidee.ActorType == ActorType.CollidableDoor) { } else if (collidableObjectCollidee.ActorType == ActorType.CollidableAmmo) { } } }
public Archer(ContentManager content) { texture = content.Load<Texture2D>("Player\\player"); position.X = 0; position.Y = SCREEN_HEIGHT - texture.Height; collidable = new CollidableObject(texture, position, 0.0f); collidable.Origin = new Vector2(0, 0); }
public override void OnCollide(CollidableObject obj) { Singleton.Getsingleton(); //Singleton.singleton.itemhaving = サブクラスで定義 //Singleton.singleton.itemcount = 0; サブクラスで定義 asd.Engine.Sound.Play(itemGet); Dispose(); }
//Record a collision between object 1 and object 2 (one way only) private void RecordCollision(CollidableObject o1, CollidableObject o2) { if (!collisionsThisFrame.ContainsKey(o1)) { collisionsThisFrame.Add(o1, new HashSet <CollidableObject>()); } collisionsThisFrame[o1].Add(o2); }
public override void OnCollide(CollidableObject obj) { base.OnCollide(obj); //Singleton.Getsingleton(); Singleton.singleton.movebomb_flag = true; //asd.Engine.Sound.Play(itemGet); //Dispose(); }
public override void OnCollide(CollidableObject otherObject) { if (otherObject is PlayerShip) { (otherObject as PlayerShip).Damage(1); Kill = true; } }
public ArcheryTarget(ContentManager content) { texture = content.Load<Texture2D>("bullsEye"); position = new Vector2(SCREEN_WIDTH - texture.Width, 0); collidable = new CollidableObject(texture, position, 0.0f); collidable.Origin = new Vector2(0, 0); moveVelocity = MOVE_SPEED; }
public void UpdateZombe(GameTime gameTime, CollidableObject player) { Move(player); position = phys.Update(gameTime, position); Vector2 nulled = new Vector2(0, 0); phys.Force = nulled; }
//how do we want this object to respond to collisions? private void HandleCollisions(CollidableObject collidableObjectCollider, CollidableObject collidableObjectCollidee) { if (collidableObjectCollidee.ActorType == ActorType.CollidablePickup) { //remove the object? EventDispatcher.Publish(new EventData(collidableObjectCollidee, EventActionType.OnRemoveActor, EventCategoryType.SystemRemove)); //publish an event to play a sound, increment a score } }
public override void OnCollide(CollidableObject obj) { base.OnCollide(obj); //Singleton.Getsingleton(); Singleton.singleton.itemhaving = 4; Singleton.singleton.itemcount = 0; //asd.Engine.Sound.Play(itemGet); //Dispose(); }
private void HandleObjectCategoryEvent(EventData eventData) { if (eventData.EventActionType == EventActionType.OnRemoveActor) { CollidableObject collidableObject = eventData.Parameters[0] as CollidableObject; this.PhysicsSystem.RemoveBody(collidableObject.Body); } }
public void OnEnable() { CollidableObject component = GetComponent <CollidableObject>(); if (component != null) { component.ReloadColliders(); } base.enabled = false; }
//Check whether object 1 and 2 were colliding last frame private bool wasCollidingWith(CollidableObject o1, CollidableObject o2) { HashSet <CollidableObject> set; if (collisionsLastFrame.TryGetValue(o1, out set)) { return(set.Contains(o2)); } return(false); }
public override bool CollisionSkin_callbackFn(CollisionSkin collider, CollisionSkin collidee) { CollidableObject collidableObject = collider.Owner.ExternalData as CollidableObject; if (collidableObject.ActorType == GDLibrary.ActorType.Pickup) { int x = 0; } return(true); }
private void DoShowInfo() { Vector3 pos, normal; CollidableObject pickedObject = mouseManager.GetPickedObject(cameraManager, 10, 1000, out pos, out normal) as CollidableObject; //does this object return true in the predicate if (collisionPredicate(pickedObject)) { //get info about the health value of the pickup int value = (pickedObject as PickupCollidableObject).Value; System.Diagnostics.Debug.WriteLine(pickedObject.ID + ", " + value); } }
/// <summary> /// Detects a pixel level collision between two CollidableObjects. /// </summary> /// <param name="collidable">The CollidableObject to check a collision against</param> /// <returns>True if colliding, false if not.</returns> public bool IsColliding(CollidableObject collidable) { bool retval = false; if (this.BoundingRectangle.Intersects(collidable.BoundingRectangle)) { if (IntersectPixels(this.Transform, this.Texture.Width, this.Texture.Height, this.TextureData, collidable.Transform, collidable.Texture.Width, collidable.Texture.Height, collidable.TextureData)) { retval = true; } } return(retval); }
public override void setParent(Transform parent) { base.setParent(parent); CollidableObject childCollidableObject = null; for (int i = 0; i < thisTransform.childCount; ++i) { if ((childCollidableObject = thisTransform.GetChild(i).GetComponent <CollidableObject>()) != null) { childCollidableObject.setStartParent(thisTransform); } } }
public static string AsText(this CollidableObject obj) { switch (obj) { case CollidableObject.Player: return("player"); case CollidableObject.Enemy: return("enemy"); case CollidableObject.Platform: return("platform"); case CollidableObject.Shield: return("shield"); default: return("empty"); } }
private void DoRemove() { Vector3 pos, normal; CollidableObject pickedObject = mouseManager.GetPickedObject(cameraManager, 10, 1000, out pos, out normal) as CollidableObject; //does this object return true in the predicate if (collisionPredicate(pickedObject)) { object[] parameters = { pickedObject }; EventDispatcher.Publish(new EventData(EventCategoryType.Object, EventActionType.OnRemoveActor, parameters)); //publish other events... //play sound, increment player health, start countdown, increment UI } }
public bool IsSelectedObjectAllowedInCurrentPosition() { bool result = true; foreach (Collider currentCollider in CurrentObjectManipulator.CurrentColliders) { CollidableObject componentInParent = currentCollider.gameObject.GetComponentInParent <CollidableObject>(); if (componentInParent != null && GetCollisionRule(componentInParent) == CollisionRuleResult.NotAllowed) { result = false; break; } } return(result); }
void OnTriggerEnter2D(Collider2D other) { if (this.gameObject.tag == "Player") { switch (other.gameObject.tag) { // Handles Player and Enemy collision case "Enemy_1": case "Enemy_2": CollidableObject player = this.gameObject.GetComponent <CollidableObject>(); if (!player.HasCollided) { _explosion.Play(); CollidableObject enemy = other.gameObject.GetComponent <CollidableObject>(); gameController.Lives -= 1; enemy.HasCollided = true; player.HasCollided = true; } break; // Handles Player and Asteroid collision case "Asteroid": AsteroidController asteroid = other.gameObject.GetComponent <AsteroidController>(); if (!asteroid.HasCollided) { _ding.Play(); gameController.Score += 100; asteroid.HasCollided = true; } break; } } else if (this.gameObject.tag == "Bullet") { switch (other.gameObject.tag) { // Handles Bullet and Enemy collision case "Enemy_1": case "Enemy_2": _explosion.Play(); CollidableObject enemy = other.gameObject.GetComponent <CollidableObject>(); CollidableObject bullet = this.gameObject.GetComponent <CollidableObject>(); enemy.Reset(); bullet.Reset(); break; } } }
public void Move(CollidableObject player) { Vector2 mousePosition = new Vector2(player.position.X, player.position.Y); Vector2 direction = mousePosition - position; direction.Normalize(); rotation = (float)Math.Atan2((double)direction.Y, (double)direction.X); // движение к персонажу var directory = new Vector2((float)Math.Cos(MathHelper.ToRadians(90) - rotation), -(float)Math.Sin(MathHelper.ToRadians(90) - rotation)); phys.Force.X = (float)Math.Sin(MathHelper.ToRadians(90) - rotation) * 4f; phys.Force.Y = (float)Math.Cos(MathHelper.ToRadians(90) - rotation) * 4f; }
public void AddCollisionSkinVertexData(CollidableObject collidableObject) { if (!collidableObject.Body.CollisionSkin.GetType().Equals(typeof(JigLibX.Geometry.Plane))) { wf = collidableObject.Collision.GetLocalSkinWireframe(); // if the collision skin was also added to the body // we have to transform the skin wireframe to the body space if (collidableObject.Body.CollisionSkin != null) { collidableObject.Body.TransformWireframe(wf); } AddVertexDataForShape(wf, collidableObject.EffectParameters.DiffuseColor); } }
private void DoLift() { if (!bCurrentlyPicking) { camera = cameraManager.ActiveCamera; currentPickedObject = mouseManager.GetPickedObject(cameraManager, pickStartDistance, pickEndDistance, out pos, out normal) as CollidableObject; if (currentPickedObject != null) { Vector3 vectorDeltaFromCentreOfMass = pos - currentPickedObject.Collision.Owner.Position; vectorDeltaFromCentreOfMass = Vector3.Transform(vectorDeltaFromCentreOfMass, Matrix.Transpose(currentPickedObject.Collision.Owner.Orientation)); cameraPickDistance = (camera.Transform3D.Translation - pos).Length(); //remove any controller from any previous pick-release objectController.Destroy(); damperController.Destroy(); currentPickedObject.Collision.Owner.SetActive(); //move object by pos (i.e. point of collision and not centre of mass) objectController.Initialise(currentPickedObject.Collision.Owner, vectorDeltaFromCentreOfMass, pos); //dampen velocity (linear and angular) on object to Zero damperController.Initialise(currentPickedObject.Collision.Owner, ConstraintVelocity.ReferenceFrame.Body, Vector3.Zero, Vector3.Zero); objectController.EnableConstraint(); damperController.EnableConstraint(); //we're picking a valid object for the first time bCurrentlyPicking = true; } //if we have an object picked from the last update then move it according to the mouse pointer if (objectController.IsConstraintEnabled && (objectController.Body != null)) { // Vector3 delta = objectController.Body.Position - this.camera.Transform.Translation; Vector3 direction = mouseManager.GetMouseRay(camera).Direction; cameraPickDistance += mouseManager.GetDeltaFromScrollWheel() * 0.1f; //set the desired world position objectController.WorldPosition = camera.Transform3D.Translation + cameraPickDistance * direction; objectController.Body.SetActive(); } } else //releasing object { //release object from constraints and allow to behave as defined by gravity etc objectController.DisableConstraint(); damperController.DisableConstraint(); } }
public Arrow(ContentManager content, float x, float y) { changeY = 0; docked = true; inAir = true; isOnTarget = false; texture = content.Load<Texture2D>("Player\\arrow"); Position.X = x; Position.Y = y; Origin.X = 2; Origin.Y = 2; rotation = 0; Collidable = new CollidableObject(texture, Position, rotation); Collidable.LoadTexture(texture, Origin); beenshot = false; stopxveloc = false; archerytarget = new ArcheryTarget(content); }
public Menu(ContentManager content) { xPos = 410; archer = content.Load<Texture2D>("Menu\\archer"); target = content.Load<Texture2D>("Menu\\target"); bear = content.Load<Texture2D>("Menu\\bear"); exit = content.Load<Texture2D>("Menu\\exit"); archerbox = new Rectangle(); targetbox = new Rectangle(); bearbox = new Rectangle(); exitbox = new Rectangle(); archerbox.X = xPos; targetbox.X = xPos; bearbox.X = xPos; exitbox.X = xPos; archerbox.Y = ORIGARCHPOS; targetbox.Y = ORIGARCHPOS + 180; bearbox.Y = ORIGARCHPOS + 180 + 80; exitbox.Y = ORIGARCHPOS + 180 + 80 + 80; archerbox.Width = archer.Width; archerbox.Height = archer.Height; targetbox.Width = target.Width; targetbox.Height = target.Height; bearbox.Width = bear.Width; bearbox.Height = bear.Height; exitbox.Width = exit.Width; exitbox.Height = exit.Height; archerCollide = new CollidableObject(archer, new Vector2(archerbox.X, archerbox.Y)); targetCollide = new CollidableObject(target, new Vector2(targetbox.X, targetbox.Y)); bearCollide = new CollidableObject(bear, new Vector2(bearbox.X, bearbox.Y)); exitCollide = new CollidableObject(exit, new Vector2(exitbox.X, exitbox.Y)); archerCollide.Origin = new Vector2(0, 0); targetCollide.Origin = new Vector2(0, 0); bearCollide.Origin = new Vector2(0, 0); exitCollide.Origin = new Vector2(0, 0); }
public Nyan(ContentManager content) { rand = new Random(); elapsed = 0; randlapsed = 0f; deadlapsed = 0f; isDead = false; nyan1 = content.Load<Texture2D>("Nyan\\nyan1"); nyan2 = content.Load<Texture2D>("Nyan\\nyan2"); nyanDead = content.Load<Texture2D>("Nyan\\nyandead"); texture = nyan1; position.X = -300; position.Y = 3; angle = 0; Collidable = new CollidableObject(texture, position); nyanSongIsPlaying = false; meowHasPlayed = false; thudHasPlayed = false; }
public CollidableObject getCollidable() { CollidableObject collidable; Texture2D theTexture; #region assignTexture switch (bearState) { case BearState.Walking: switch (walkingAnime.currFrame) { case 0: theTexture = bearWalk1; break; case 1: theTexture = bearWalk2; break; case 2: theTexture = bearWalk3; break; case 3: theTexture = bearWalk4; break; default: theTexture = bearWalk1; break; } break; case BearState.Rolling: switch (rollingAnime.currFrame) { case 0: theTexture = bearRoll1; break; case 1: theTexture = bearRoll2; break; case 2: theTexture = bearRoll3; break; case 3: theTexture = bearRoll4; break; default: theTexture = bearRoll1; break; } break; case BearState.Jumping: switch (jumpingAnime.currFrame) { case 0: theTexture = bearJump1; break; case 1: theTexture = bearJump2; break; default: theTexture = bearJump1; break; } break; default: theTexture = bearWalk1; break; } #endregion collidable = new CollidableObject(theTexture, position); collidable.LoadTexture(theTexture); collidable.Origin = new Vector2(0, 0); return collidable; }
public void HandleCollisions() { nyanCollide = nyancat.getCollidableObject(); bool resetarrows = false; foreach (Arrow arrow in bow.getArrows() ) { if (!arrow.isinAir && arrow.isonTarget()) { arrow.changeArcheryTargetPosY(archeryTarget.getPosition().Y); } if (arrow.isinAir == true) { if (arrow.getCollidableObject().IsColliding(nyanCollide)) { nyancat.isdead(); } switch (gameState) { case GameState.Target: if (arrow.getCollidableObject().IsColliding(archeryTarget.getCollidable()) ) { arrow.isinAir = false; arrow.velocity = new Vector2(0, 0); arrow.onTarget(Math.Abs(arrow.position.Y - archeryTarget.getPosition().Y), archeryTarget, Content); targetModeScore += 50; } if (arrow.position.Y < 10 && arrow.position.X < 100) { resetarrows = true; gameState = GameState.Menu; } break; case GameState.Bear: foreach (Bear bear in bearMode.getBears()) { if (!bear.isDead) { if ( !arrow.isDocked() && arrow.getCollidableObject().IsColliding(bear.getCollidable()) ) { bear.isDead = true; bearMode.bearsKilled += 1; arrow.stopXVeloc(); } if (player.getCollidable().IsColliding(bear.getCollidable())) { resetarrows = true; gameState = GameState.GameOver; } } } break; case GameState.Menu: if (arrow.getCollidableObject().IsColliding(menuObjects[0])) // "Archer" logo { arrow.isinAir = false; } if (arrow.getCollidableObject().IsColliding(menuObjects[1])) // "Target" logo { arrow.isinAir = false; resetarrows = true; gameState = GameState.Target; break; } if (arrow.getCollidableObject().IsColliding(menuObjects[2])) // "Bear" logo { arrow.isinAir = false; resetarrows = true; gameState = GameState.Bear; bearMode.reset(); break; } if (arrow.getCollidableObject().IsColliding(menuObjects[3]) ) // "Exit" logo { this.Exit(); } if (arrow.position.Y < 10 && arrow.position.X < 100 && !LoggedIn) // "Login" logo { resetarrows = true; gameState = GameState.Login; } break; } // switch statement } // if isInAir } // foreach arrow if (resetarrows) { bow.resetArrows(Content); } }