// This function is called when a object needs to be added to bin public void OnObjectAdded(ISpriteCollideable gameObject) { // Add object to the object list this.listOfCollideableObjects.Add(gameObject); // If this bin does not have multiple objects and the the number of // collideable objects are greater than 1. the bin adds itself the // managerslist of object bins to check if (!hasMultipleObjects && this.listOfCollideableObjects.Count > 1) { // add this bin to a list of bins to check for collision refCollisionManager.ObjectBinsToCheck.Add(this); hasMultipleObjects = true; //Debug.Print("Multiple Object in Bin: " + gridCoord.ToString() + " are true"); } }
// This function is called when a object needs to be removed from a bin public void OnObjectRemoved(ISpriteCollideable gameObject) { // Remove Object from the object list this.listOfCollideableObjects.Remove(gameObject); // If this bin has multiple objects and the the number of // collideable objects are less than 2. the bin removes itself from // the managerslist of object bins to check if (hasMultipleObjects && this.listOfCollideableObjects.Count < 2) { // remove this bin from the list of bins to check for collision refCollisionManager.ObjectBinsToCheck.Remove(this); hasMultipleObjects = false; //Debug.Print("Multiple Object in Bin: " + gridCoord.ToString() + " are false"); } }
// Removes object from the corresponding object bins protected void OnRemoveObjectFromBin(ISpriteCollideable collideableObject, List<Point> listOfObjectBinCoord) { // loop though the coordinates remove the object to the // coresponding grid space foreach (Point binCoord in listOfObjectBinCoord) { // Check if the coordinate is within the grid space // Remove Object from the ObjectList of a Bin if (binCoord.X >= 0 && binCoord.X < gridWidth && binCoord.Y >= 0 && binCoord.Y < gridHeight) this.objectCollisionGrid[binCoord.X, binCoord.Y].OnObjectRemoved(collideableObject); } // Remove from Object Look Up Table this.objBinLookupTable.Remove(collideableObject.IdNumber); }
// Gets the Objects World Coordinates/Rectangle and transforms them into Bin Coordinates // Works by taking the topleft and the bottom right and interpolates to get all the // coordinates in between. protected List<Point> getObjectCollisionBinCoord(ISpriteCollideable collideableObject) { Point p = WorldCoordToBinCoord(new Vector2(200, 200)); List<Point> listOfBinCoord = new List<Point>(); Point leftTop = WorldCoordToBinCoord( new Vector2(collideableObject.Rectangle.Left, collideableObject.Rectangle.Top)); Point rightBottom = WorldCoordToBinCoord( new Vector2(collideableObject.Rectangle.Right, collideableObject.Rectangle.Bottom)); // If the left top and right bottom are not equal // scan through the points if (!leftTop.Equals(rightBottom)) { for (int y = leftTop.Y; y <= rightBottom.Y; y++) { for (int x = leftTop.X; x <= rightBottom.X; x++) { listOfBinCoord.Add(new Point(x, y)); } } } // if the left top and bottom right are equal add just the left top else { listOfBinCoord.Add(leftTop); } return listOfBinCoord; }
// Adds object to the coresponding object bins protected void OnAddObjectToBin(ISpriteCollideable collideableObject, List<Point> listOfObjectBinCoord) { // loop though the coordinates add the object to the // coresponding grid space foreach (Point binCoord in listOfObjectBinCoord) { // Add Object to Object Collision Grid if (binCoord.X >= 0 && binCoord.X < gridWidth && binCoord.Y >= 0 && binCoord.Y < gridHeight) this.objectCollisionGrid[binCoord.X, binCoord.Y].OnObjectAdded(collideableObject); } // Update Look Up Table this.objBinLookupTable[collideableObject.IdNumber] = listOfObjectBinCoord; }
// Finds out if the object is in camera space protected Boolean findOutIfObjectIsInCameraSpace(ISpriteCollideable collideableObject) { Rectangle objectRectangle = collideableObject.Rectangle; if ((objectRectangle.Left >= collisionSpaceRectangle.Left) && (objectRectangle.Right < collisionSpaceRectangle.Right) && (objectRectangle.Top >= collisionSpaceRectangle.Top) && (objectRectangle.Bottom < collisionSpaceRectangle.Bottom)) return true; return false; }
protected Boolean findOutIfObjectIsInGridSpace(ISpriteCollideable collideableObject) { Rectangle gridObjectRectangle; return false; }
// Adds an object to the registered object list // (Adds a object to a bin on the next update because the // camera may not have been created yet) public void addObjectToRegisteredObjectList(ISpriteCollideable collideableObject) { // Registers a Collideable Object registeredObject.Add(collideableObject); // assigns a id number to object collideableObject.IdNumber = this.IDNumberCounter; // increment the idnumberCounter IDNumberCounter++; //Debug.Print("Object Added to Registered List: " + collideableObject.IdNumber); }
// Removes an object from the registered object list // the object is removed on the next update public void removeObjectFromRegisteredObjectList(ISpriteCollideable collideableObject) { // Removes the object from the registered object list collideableObject.removeFromRegistrationList = true; // Debug.Print("Object Removed from Registered List: " + collideableObject.IdNumber); }
Boolean BoundingBox(ISpriteCollideable collideableObjectA, ISpriteCollideable collideableObjectB) { return collideableObjectA.Rectangle.Intersects(collideableObjectB.Rectangle); }
public void OnSpriteCollision(ISpriteCollideable characterCollidedWith) { IDamageable damage = characterCollidedWith as IDamageable; if (damage != null && damage.TakesDamageFrom != this.DoesDamageTo) { // we hit /* this.gameScreen.World.SpriteCollisionManager.removeObjectFromRegisteredObjectList(this); this.ParentScreen.Components.Remove(this); this.Dispose(); */ } }
public void OnSpriteCollision(ISpriteCollideable objectCollidedWith) { IDamaging damagingObject = objectCollidedWith as IDamaging; if (damagingObject != null) { TakeDamage(damagingObject); } }
// Activated on sprite collision. public void OnSpriteCollision(ISpriteCollideable objectCollidedWith) { if (objectCollidedWith == World.Player) { playerCollided = true; } }
public void OnSpriteCollision(ISpriteCollideable objectCollidedWith) { if (objectCollidedWith == World.Player) { if (!playerColliding) { playerColliding = true; StoryboardScreen sbs = new StoryboardScreen("Test", "Game", @"StoryboardXML\TitleScreenStoryboard"); ScreenManager.Instance.ScreenList.Add(sbs); ScreenTransition st = new ScreenTransition("Game", "Test", 0.2f, 0.2f, false, false); ScreenManager.Instance.Transition(st); World.Paused = true; World.RemoveWorldObject(this); } } }
public void OnSpriteCollision(ISpriteCollideable objectCollidedWith) { if (objectCollidedWith is IDamaging) { this.TakeDamage((IDamaging)objectCollidedWith); } if (objectCollidedWith is IPhysical) { Vector2 force = ((IPhysical)objectCollidedWith).Position - Position; float force_amount = 8.0f; force /= force.Length(); // Normalize vector to merely be directional. force *= force_amount; //((IPhysical)objectCollidedWith).NetForce += force; //this.NetForce -= force; } }
public void OnSpriteCollision(ISpriteCollideable characterCollidedWith) { #if !XBOX && DEBUG //Debug.Print("Player Hit By: " + characterCollidedWith.IdNumber); #endif IDamaging damage = characterCollidedWith as IDamaging; if (!currentState.Contains("Hit") && !currentState.Contains("Dead")) { if (damage != null) { this.TakeDamage(damage); } } }
public void OnSpriteCollision(ISpriteCollideable objectCollidedWith) { if (objectCollidedWith is IPhysical) { Vector2 force = ((IPhysical)objectCollidedWith).Position - Position; force /= force.Length(); // Normalize vector to merely be directional. force *= FORCE_AMOUNT; ((IPhysical)objectCollidedWith).NetForce += force; } if (objectCollidedWith is IDamageable) { ((IDamageable)objectCollidedWith).TakeDamage(this); } }
public void OnSpriteCollision(ISpriteCollideable characterCollidedWith) { IDamaging damage = characterCollidedWith as IDamaging; if (damage != null) { this.TakeDamage(damage); } }
public void OnSpriteCollision(ISpriteCollideable characterCollidedWith) { // Do nothing :) if(characterCollidedWith is Explosion) this.removeFromCollisionRegistration = true; }
void ISpriteCollideable.OnSpriteCollision(ISpriteCollideable characterCollidedWith) { // Nothing happens to the cactus on collisions. }