public static void Spawn(Vector2 position, float rotation, Collider2D collisionSurface, bool playAudio) { // Using a collision surface, look for an appropriate CollisionSurface component in the parent. CollisionSurface surface = collisionSurface.GetComponentInParent <CollisionSurface>(); if (surface != null) { // Spawn effect, if present. HitEffectPreset effect = surface.GetHitEffect(); if (effect != null) { Spawn(position, rotation, effect); } // Now play audio using the settings on the CollisionSurface AudioClip c = surface.GetAudioClip(); if (c != null) { float volume = surface.GetVolume(); float pitch = surface.GetPitch(); float range = surface.GetRange(); float maxPanRange = surface.GetMaxPanRange(); float minPanRange = surface.GetMinPanRange(); float lowPassStart = surface.GetLowPassDistance(); AudioManager.Instance.PlayOneShot(position, c, volume, pitch, range, minPanRange, maxPanRange, lowPassStart); } } }
/// <summary> /// Constructor of the <c>EventData_ObjectsCollision</c> class. /// </summary> /// <param name="mObject"><c>MoveableObject</c> that collide with a node.</param> /// <param name="node">Node collisioned with the <c>MoveableObject</c>.</param> /// <param name="direction">Direction of the collision.</param> /// <param name="type">Type of surface collision.</param> /// <param name="addValue">Value to be added to the new position.</param> public EventData_ObjectsCollision(MoveableObject mObject, ref OcTreeNode node, CollisionDirection direction, CollisionSurface type, float addValue) { _eventType = EventManager.EventType_UnitCollision; _addValue = addValue; _direction = direction; _type = type; _node = node; _mObject = mObject; }
public bool IsSurface(CollisionSurface surface) { return((surface & Surface) != CollisionSurface.None); }
public void Add(CollisionSurface collisionSurface) { ground = collisionSurface; }
/// <summary> /// Detects and resolves all collisions between the player and his neighboring /// tiles. When a collision is detected, the player is pushed away along one /// axis to prevent overlapping. There is some special logic for the Y axis to /// handle platforms which behave differently depending on direction of movement. /// </summary> private void HandleCollisions(List <Sprite> level) { Rectangle bounds = BoundingBox(); //Reset flag to search for ground collision. isOnGround = false; foreach (CollisionSurface tile in level) { // If this tile is collidable, if (this.BoundingBox().Intersects(tile.BoundingBox())) { Rectangle tileBounds = tile.BoundingBox(); CurrentCollisionSurface = tile; //Sets the colour to a dark blue when you are colliding with the surface if (tile.Colour != Color.Transparent) { tile.Colour = Color.DarkBlue; } if (tile.CollisionType != TileCollision.Slope && tile.CollisionType != TileCollision.Slide) { // Determine collision depth (with direction) and magnitude. Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds, tileBounds); if (depth != Vector2.Zero) { float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); //Resolve the collision along the shallow axis. if (absDepthY < absDepthX || tile.CollisionType == TileCollision.Platform) { //If we crossed the top of a tile, we are on the ground. if (previousBottom <= tileBounds.Top) { isOnGround = true; isJumping = false; isGliding = false; //BEGIN BOUNCE if (tile.CollisionType == TileCollision.Bounce) { CollisionBounce bounceTile = (CollisionBounce)tile; isBouncing = true; BounceLaunchVelocityX = bounceTile.BounceVelocityX; BounceLaunchVelocityY = bounceTile.BounceVelocityY; } //SLIDE PLAYER if (tile.CollisionType == TileCollision.Conveyor) { if (movement != 0) { SlideDirection = movement; } CollisionConveyor conveyorTile = (CollisionConveyor)tile; SlideMoveFactor = conveyorTile.SlideBoost; } } //Ignore platforms, unless we are on the ground. if (IsOnGround) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, Position.Y + depth.Y); Rotation = 0.0f; if (tile.CollisionType == TileCollision.Conveyor) { isSliding = true; } if (tile.CollisionType == TileCollision.Moving) { CollisionMoving movingTile = (CollisionMoving)tile; if (!movingTile.IsAtWaypoint) { if (movingTile.PlatformSpeed.Y > 0) { Position.X += movingTile.PlatformSpeed.X; } else { Position += movingTile.PlatformSpeed; } } } //Perform further collisions with the new bounds. bounds = BoundingBox(); } } else if (tile.CollisionType != TileCollision.Platform) { // Resolve the collision along the X axis Position = new Vector2(Position.X + depth.X, Position.Y); if (tile.CollisionType == TileCollision.Walljump) { IsOnWall = true; if (tile.Position.X < Position.X) { CollisionOnFace = CollisionFace.Left; } else { CollisionOnFace = CollisionFace.Right; } } //Perform further collisions with the new bounds. bounds = BoundingBox(); } } } else if (tile.CollisionType == TileCollision.Slope || tile.CollisionType == TileCollision.Slide) { CollisionSlope slopeTile = (CollisionSlope)tile; float displacement = RectangleExtensions.GetSlopePosition(bounds, tileBounds, slopeTile.BottomSlopePoint); //If we crossed the top of a tile, we are on the ground. if (previousBottom > displacement - this.BoundingBox().Height / 2) { isOnGround = true; isJumping = false; isGliding = false; if (tile.CollisionType == TileCollision.Slide) { CollisionSlide slideTile = (CollisionSlide)tile; SlideDirection = slideTile.SlideDirection; SlideMoveFactor = slideTile.SlideBoost; } } //Ignore platforms, unless we are on the ground. if ((IsOnGround & !wantsToJump) | (IsOnGround & isJumping) | (IsOnGround & isGliding)) { // Resolve the collision along the Y axis. Position = new Vector2(Position.X, displacement - this.BoundingBox().Height / 2); Rotation = RectangleExtensions.GetSlopeAngle(tileBounds, slopeTile.BottomSlopePoint) / 2; if (tile.CollisionType == TileCollision.Slide) { isSliding = true; } //Perform further collisions with the new bounds. bounds = BoundingBox(); } } } } //Save the new bounds bottom. previousBottom = bounds.Bottom; }
public CollisionSurfaceController(MainForm topform, CollisionSurface item) : base(topform, item) { Data = item; }
/// <summary> /// Calculates the Y velocity accounting for jumping and /// animates accordingly. /// </summary> /// <remarks> /// During the accent of a jump, the Y velocity is completely /// overridden by a power curve. During the decent, gravity takes /// over. The jump velocity is controlled by the jumpTime field /// which measures time into the accent of the current jump. /// </remarks> /// <param name="velocityY"> /// The player's current velocity along the Y axis. /// </param> /// <returns> /// A new Y velocity if beginning or continuing a jump. /// Otherwise, the existing Y velocity. /// </returns> private Vector2 DoJump(Vector2 velocity, GameTime gameTime) { // If the player wants to jump if (wantsToJump) { if (IsOnWall) { if (LastSurfaceJumped != CurrentCollisionSurface) { LastSurfaceJumped = CurrentCollisionSurface; HasWallJumped = true; } return(velocity); } // Begin or continue a jump if ((!wasJumping && (IsOnGround | IsOnWall)) || jumpTime > 0.0f) { if (jumpTime == 0.0f) { AudioManager.PlaySfxCue("Jump"); } Rotation = 0.0f; isJumping = true; jumpTime += (float)gameTime.ElapsedGameTime.TotalSeconds; if (Animation.Contains("Left")) { Animation = "LeftJump"; } else if (Animation.Contains("Right")) { Animation = "RightJump"; } } // If we are in the ascent of the jump if (0.0f < jumpTime && jumpTime <= MaxJumpTime) { // Fully override the vertical velocity with a power curve that gives players more control over the top of the jump velocity.Y = JumpLaunchVelocity * (1.0f - (float)Math.Pow(jumpTime / MaxJumpTime, JumpControlPower)); } else { // Reached the apex of the jump jumpTime = 0.0f; isJumping = false; } } else { // Continues not jumping or cancels a jump in progress jumpTime = 0.0f; isJumping = false; } wasJumping = isJumping; return(velocity); }
/*public Point3f linkedPosition() { return ; }*/ public CollisionSurface addCollisionSurface(CollisionSurface collisionSurface) { listCollisionSurfaces.Add(collisionSurface); return collisionSurface; }
public CollisionSurfaceController(MainForm topform, CollisionSurface item, FileController targetFile) : base(topform, item, targetFile) { Data = item; }
/*public Point3f linkedPosition() * { * return ; * }*/ public CollisionSurface addCollisionSurface(CollisionSurface collisionSurface) { listCollisionSurfaces.Add(collisionSurface); return(collisionSurface); }