public Boolean ReflectMovingEntity(IEntity movingEntity, ICollision.CollisionSide side) // had this previously. May be needed in future (Rectangle collisionRect) { Boolean moved = false; if (side == ICollision.CollisionSide.TOP) //Entity would be moving down { movingEntity.Y -= Global.Var.SCALE; //movingEntity.Y -= collisionRect.Height; moved = true; } else if (side == ICollision.CollisionSide.RIGHT) //Entity would be moving left { movingEntity.X += Global.Var.SCALE; moved = true; } else if (side == ICollision.CollisionSide.BOTTOM) //Entity would be moving up { movingEntity.Y += Global.Var.SCALE; moved = true; } else if (side == ICollision.CollisionSide.LEFT) //Entity would be moving right { movingEntity.X -= Global.Var.SCALE; moved = true; } //If this call is made we know there is a collision so an else condition is not needed return(moved); }
public override void StartMoving(ICollision.CollisionSide Side) { isMoving = true; side = Side; if (soundPlay) { Sound.SoundLoader.Instance.GetSound(Sound.SoundLoader.Sounds.LOZ_Secret).Play(Global.Var.VOLUME, Global.Var.PITCH, Global.Var.PAN); soundPlay = false; } }
public void BounceOfEnemy(ICollision.CollisionSide Side) { _side = Side; _bouncingOfEnemy = true; /* * May need to: * Pause animation; * Stop accepting move input keys for link */ }
public static bool LinkDamaged(Game1 gameInstance, IPlayer link, Rectangle linkRect, Rectangle enemyRect) { side = enemyCollision.SideOfCollision(enemyRect, linkRect); /*Have initial reflection so Link can't move through enemy, then continue to move him back */ alreadyMoved = blockCollision.ReflectMovingEntity((IEntity)link, side); link.BounceOfEnemy(side); link.TakeDamage(); ILink damagedLink = new DamagedLink(link, gameInstance); gameInstance.link = damagedLink; return(alreadyMoved); }
public ICollision.CollisionSide SideOfCollision(Rectangle enemyRect, Rectangle characterRect) { intersectionRect = Rectangle.Intersect(characterRect, enemyRect); //Logic to determine where the overlap is if (intersectionRect.Top == enemyRect.Top) { if (intersectionRect.Left == enemyRect.Left) { if (intersectionRect.Height > intersectionRect.Width) { side = ICollision.CollisionSide.LEFT; } else { side = ICollision.CollisionSide.TOP; } } else if (intersectionRect.Right == enemyRect.Right) { if (intersectionRect.Height > intersectionRect.Width) { side = ICollision.CollisionSide.RIGHT; } else { side = ICollision.CollisionSide.TOP; } } else //Link only intersects top. Will happen with bottom wall { side = ICollision.CollisionSide.TOP; } } else if (intersectionRect.Bottom == enemyRect.Bottom) { if (intersectionRect.Left == enemyRect.Left) { if (intersectionRect.Height > intersectionRect.Width) { side = ICollision.CollisionSide.LEFT; } else { side = ICollision.CollisionSide.BOTTOM; } } else if (intersectionRect.Right == enemyRect.Right) { //compare width and height if (intersectionRect.Height > intersectionRect.Width) { side = ICollision.CollisionSide.RIGHT; } else { side = ICollision.CollisionSide.BOTTOM; } } else //Link only intersects Bottom. Will happen with top wall { side = ICollision.CollisionSide.BOTTOM; } } else if (intersectionRect.Left == enemyRect.Left) { side = ICollision.CollisionSide.LEFT; } else //Link ran into left wall { side = ICollision.CollisionSide.RIGHT; } return(side); }
private void DetectDoorCollision(Dictionary <int, IEntity> enemies, List <IDoor> doors, List <IEntity> linkProj, List <IEntity> enemyProj) { Rectangle linkRect = ((IEntity)link).GetBoundingRect(); Boolean alreadyMoved = false; foreach (IDoor door in doors) { Rectangle doorRect = door.GetBoundingRect(); if (doorRect.Intersects(linkRect)) { if (door.DoorDestination != -1) { // Add more complex logic here. gameInstance.dungeon.ChangeRoom(door); } else { side = blockCollision.SideOfCollision(doorRect, linkRect); blockCollision.ReflectMovingEntity((IEntity)link, side); } } //enemy vs blocks foreach (int enemy in enemies.Keys) { // TODO: For some enemies, like the Spike and Final Boss, I don't want it to check for it's hit box IEntity currentEnemy; enemies.TryGetValue(enemy, out currentEnemy); AbstractEntity cEnemy = (AbstractEntity)currentEnemy; Rectangle enemyRect = cEnemy.GetBoundingRect(); alreadyMoved = false; if (doorRect.Intersects(enemyRect)) { side = blockCollision.SideOfCollision(doorRect, enemyRect); if (!alreadyMoved) //This will prevent it from moving back twice { alreadyMoved = blockCollision.ReflectMovingEntity(currentEnemy, side); } } } //proj vs blocks foreach (AbstractEntity proj in linkProj) { if (doorRect.Intersects(proj.GetBoundingRect())) { ProjectileCollisionHandler.ProjectileWallHit((IProjectile)proj, gameInstance.dungeon.CurrentRoom); } } foreach (AbstractEntity proj in enemyProj) { if (doorRect.Intersects(proj.GetBoundingRect())) { ProjectileCollisionHandler.ProjectileWallHit((IProjectile)proj, gameInstance.dungeon.CurrentRoom); } } } }
private void DetectBlockCollision(Dictionary <int, IEntity> enemies, List <IBlock> blocks, List <IEntity> linkProj, List <IEntity> enemyProj) { Rectangle linkRect = ((IEntity)link).GetBoundingRect(); Boolean alreadyMoved = false; foreach (AbstractBlock block in blocks) { Rectangle blockRect = block.GetBoundingRect(); //link vs blocks if (block.IsCollidable() && blockRect.Intersects(linkRect)) { side = blockCollision.SideOfCollision(blockRect, linkRect); //Create a movable block class?? But how to only let it move one full space in one direction? if (!alreadyMoved) //This will prevent it from moving back twice { /*This allows link to push blocks. Enemies can not push blocks*/ if (block.IsMovable() && ((block.PushSide() == side) || (block.PushSide2() == side))) { block.StartMoving(side); } alreadyMoved = blockCollision.ReflectMovingEntity((IEntity)link, side); } } //enemy vs blocks foreach (int enemy in enemies.Keys) { // TODO: For some enemies, like the Spike and Final Boss, I don't want it to check for it's hit box IEntity currentEnemy; enemies.TryGetValue(enemy, out currentEnemy); IEntity cEnemy = currentEnemy; Rectangle enemyRect = cEnemy.GetBoundingRect(); alreadyMoved = false; if (((block.IsCollidable() && cEnemy.IsCollidable()) || block.IsTall()) && blockRect.Intersects(enemyRect)) { side = blockCollision.SideOfCollision(blockRect, enemyRect); if (!alreadyMoved) //This will prevent it from moving back twice { alreadyMoved = blockCollision.ReflectMovingEntity(currentEnemy, side); } } } //proj vs blocks foreach (AbstractEntity proj in linkProj) { if (block.IsTall() && blockRect.Intersects(proj.GetBoundingRect())) { ProjectileCollisionHandler.ProjectileWallHit((IProjectile)proj, gameInstance.dungeon.CurrentRoom); } } foreach (AbstractEntity proj in enemyProj) { if (block.IsTall() && blockRect.Intersects(proj.GetBoundingRect())) { ProjectileCollisionHandler.ProjectileWallHit((IProjectile)proj, gameInstance.dungeon.CurrentRoom); } } } }
public virtual void StartMoving(ICollision.CollisionSide Side) { // }
public ICollision.CollisionSide SideOfCollision(Rectangle blockRect, Rectangle characterRect) { intersectionRect = Rectangle.Intersect(characterRect, blockRect); //Insert logic to determine where the overlap is if (intersectionRect.Top == blockRect.Top) { if (intersectionRect.Left == blockRect.Left) { if (intersectionRect.Height > intersectionRect.Width) { side = ICollision.CollisionSide.LEFT; } else { side = ICollision.CollisionSide.TOP; } } else if (intersectionRect.Right == blockRect.Right) { if (intersectionRect.Height > intersectionRect.Width) { side = ICollision.CollisionSide.RIGHT; } else { side = ICollision.CollisionSide.TOP; } } else //Only intersects top (Not sure if this is possible) -- Will be with the walls { side = ICollision.CollisionSide.TOP; } } else if (intersectionRect.Bottom == blockRect.Bottom) { if (intersectionRect.Left == blockRect.Left) { if (intersectionRect.Height > intersectionRect.Width) { side = ICollision.CollisionSide.LEFT; } else { side = ICollision.CollisionSide.BOTTOM; } } else if (intersectionRect.Right == blockRect.Right) { //compare width and height if (intersectionRect.Height > intersectionRect.Width) { side = ICollision.CollisionSide.RIGHT; } else { side = ICollision.CollisionSide.BOTTOM; } } else //Only intersects Bot (Don't think this is possible) { side = ICollision.CollisionSide.BOTTOM; } } else if (intersectionRect.Left == blockRect.Left) { side = ICollision.CollisionSide.LEFT; } else //Link ran into left wall { side = ICollision.CollisionSide.RIGHT; } return(side); }