public EnemySonar(Vector2 position, GameConstants.POINTDIR direction, Enemy sourceEnemy) : base(position) { active = true; this.direction = direction; isCollidable = false; this.sourceEnemy = sourceEnemy; base.Model = GameplayScreen._models["projectile"]; // hitbox for collision //UpdateBoundingBox(base.Model, Matrix.CreateTranslation(base.Position), false, false); SetVerticalOffset(-20); SetDirection(); base.HitboxHeight = 40; base.HitboxWidth = 300; //base.HitboxWidthOffset = 48; base.HitboxHeightOffset = 20; }
public LaserProjectile(int column, int row, GameConstants.POINTDIR direction) : base(column, row) { base.Model = GameplayScreen._models["projectile"]; Scale(1.9f, 3f, 3f); //Rotate(0f, 0f, 90f); //SetVerticalOffset(); //SetHorizontalOffset(30); active = true; this.direction = direction; isCollidable = false ; SetDirection(); // hitbox for collision UpdateBoundingBox(base.Model, Matrix.CreateTranslation(base.Position), false, false); soundEffects = new SoundEffectPlayer(this); //set up sound soundEffects.LoadSound("LaserWhirLoop", GameplayScreen._sounds["LaserWhirLoop"]); soundEffects.PlayAndLoopSound("LaserWhirLoop"); }
public override void LoadContent(ContentManager contentManager) { animmodel.LoadContent(contentManager); // Provides a hitbox for the block - Steven UpdateBoundingBox(animmodel.Model, Matrix.CreateTranslation(base.Position), false, false); base.HitboxWidth = 40; base.HitboxHeight = 16; base.HitboxHeightOffset = 20; soundEffects = new SoundEffectPlayer(this); SoundEffect sound = contentManager.Load<SoundEffect>("Sounds/DoombaLoop"); soundEffects.LoadSound("Roomba", contentManager.Load<SoundEffect>("Sounds/DoombaLoop")); soundEffects.PlayAndLoopSound("Roomba"); soundEffects.SoundInstances["Roomba"].Volume = 1f; base.LoadContent(contentManager); //attack range enemyRangeL = new Rectangle((int)(Position.X - (HitboxWidth * 10)), (int)(Position.Y + (HitboxHeight * 1.5)), (HitboxWidth * 10), (HitboxHeight)); enemyRangeR = new Rectangle((int)(Position.X + (HitboxWidth)), (int)(Position.Y + (HitboxHeight * 1.5)), (HitboxWidth * 10), (HitboxHeight)); // generate random direction and initialize Random rand = new Random(); if (rand.Next(0, 1) == 0) direction = GameConstants.POINTDIR.pointLeft; else direction = GameConstants.POINTDIR.pointRight; }
private void CheckEnemyBoxCollision(RenderContext renderContext) { elaspedTime += renderContext.GameTime.ElapsedGameTime.Milliseconds; if (renderContext.Player.Hitbox.Intersects(Hitbox)) { renderContext.Player.TakeDamage(GameConstants.PLAYER_DAMAGE, renderContext.GameTime); movestate = !movestate; if (direction == GameConstants.POINTDIR.pointLeft && elaspedTime > TIME_DELAY) { direction = GameConstants.POINTDIR.pointRight; elaspedTime = 0; return; } else if (direction == GameConstants.POINTDIR.pointRight && elaspedTime > TIME_DELAY) { direction = GameConstants.POINTDIR.pointLeft; elaspedTime = 0; return; } return; } List<GameObject3D> checkBlocks = new List<GameObject3D>(); checkBlocks.AddRange(renderContext.Level.gameObjects[typeof(PickableBox)]); checkBlocks.AddRange(renderContext.Level.gameObjects[typeof(Door)]); checkBlocks.AddRange(wallsToCheck); //Check collision of enemy against all objects in level except toggle switch and foreach (CellObject levelObject in checkBlocks) { if ((levelObject.isCollidable && Hitbox.Intersects(levelObject.Hitbox) && levelObject.GetType() != typeof(ToggleSwitch)) || (Hitbox.Intersects(levelObject.Hitbox) && levelObject.GetType() == typeof(Character))) { if (levelObject.GetType() == typeof(Character)) { } float wy = (levelObject.Hitbox.Width + Hitbox.Width) * (levelObject.Hitbox.Center.Y - Hitbox.Center.Y); float hx = ((Hitbox.Height) + levelObject.Hitbox.Height) * (levelObject.Hitbox.Center.X - Hitbox.Center.X); if (wy > hx) { //boxHitState = "Box Left";// left movestate = false; direction = GameConstants.POINTDIR.pointRight; } if (wy > -hx) { //boxHitState = "Box Right";// right movestate = true; direction = GameConstants.POINTDIR.pointLeft; } } } }