public void ItemCollision(ComponentPosition positionComponent, ComponentCollision collisionComponent, ComponentVelocity velocityComponent, ComponentPosition fpositionComponent, ComponentCollision fcollisionComponent, ComponentVelocity fvelocityComponent, Entity item, ComponentAudio faudioComponent, ComponentTexture ftextureComponent) { if (positionComponent.Position.X > fpositionComponent.Position.X - 1 && positionComponent.Position.X < fpositionComponent.Position.X + 1 && positionComponent.Position.Y > fpositionComponent.Position.Y - 1 && positionComponent.Position.Y < fpositionComponent.Position.Y + 1 && ftextureComponent.Texture != 0) { faudioComponent.Start(); ftextureComponent.remove(); fpositionComponent.Position = offscreen; } }
/// <summary> /// Renders a stationary entity /// </summary> /// <param name="position">Position of the entity created</param> /// <param name="geo">Entity's geometry file</param> /// <param name="texture">Entity's texture file</param> /// <param name="audio">Entity's audio file</param> /// <param name="loop">Sets audio to loop if true</param> public void CreateEntity(Vector3 position, string geo, string texture, string audio, bool loop) { this.AddComponent(new ComponentPosition(position)); this.AddComponent(new ComponentGeometry(geo)); this.AddComponent(new ComponentTexture(texture)); this.AddComponent(new ComponentAudio(audio, loop)); if (loop) { ComponentAudio sound = this.GetAudio(0); sound.Start(); } }
public void food(ComponentPosition pos, Vector3 foodPos, Entity ent, WallCollisions end, ComponentAudio audio, string foodType) { Vector3 pacPos = pos.Position; if (timer >= 0) { if (timer > 0) { timer += GameScene.dt; } if (timer >= 1000 && power.Name == ent.Name) { timer = 0; audio.Stop(); EntityManager.Remove(ent); } } if (end.overCollsion(pacPos, foodPos)) { if (foodType == "power") { if (power != ent && timer > 10) { return; } timer = 0; timer += GameScene.dt; power = ent; } audio.Start(); if (foodType != "power") { EntityManager.Remove(ent); foodCount++; if (end.getFood() + 1 == foodCount) { GameScene.endGame = true; } } } }
private void CheckXCollision(List <Entity> entities, float dir) { foreach (Entity entity in entities) { Vector3 entityPos = entity.GetPosition(); if (entity.Name.Contains("wall") && collisionOn) { float xCollide = (eyePos.X + dir) - entityPos.X; float zCollide = eyePos.Z - entityPos.Z; if (zCollide < 1.5 && zCollide > -1.5 && xCollide < 1.5 && xCollide > -1.5) { wallCollide = true; break; } } if (entity.Name.Contains("pellet")) { float zCollide = eyePos.Z - entityPos.Z; float xCollide = eyePos.X - entityPos.X; if (zCollide < 1.0 && zCollide > -1.0 && xCollide < 1.0 && xCollide > -1.0) { entity.ChangePosition(new Vector3(0, -10, 0)); Vector3 emitterPosition = eyePos; ding2.SetPosition(emitterPosition); ding2.Start(); pelletsCollected += 1; score += 100; break; } } if (entity.Name.Contains("ghost")) { float xCollide = (eyePos.X + dir) - entityPos.X; float zCollide = eyePos.Z - entityPos.Z; if (zCollide < 1.5 && zCollide > -1.5 && xCollide < 1.5 && xCollide > -1.5) { if (ghostKill) { ComponentAudio killGhost = entity.GetAudio(0); killGhost.Start(); if (entity.Name == "ghostA") { entity.ChangePosition(ghostASpawn); entity.ChangeVelocity(new Vector3(0, 0, 0)); aDead = true; } else if (entity.Name == "ghostB") { entity.ChangePosition(ghostBSpawn); entity.ChangeVelocity(new Vector3(0, 0, 0)); bDead = true; } else { entity.ChangePosition(ghostCSpawn); entity.ChangeVelocity(new Vector3(0, 0, 0)); cDead = true; } score += 500; break; } else { ComponentAudio loseLife = entity.GetAudio(1); loseLife.Start(); eyePos = spawnPoint; targetPos = new Vector3(eyePos.X, eyePos.Y, eyePos.Z - 2); lifeTotal -= 1; break; } } } if (entity.Name.Contains("pUp")) { float zCollide = eyePos.Z - entityPos.Z; float xCollide = eyePos.X - entityPos.X; if (zCollide < 1.0 && zCollide > -1.0 && xCollide < 1.0 && xCollide > -1.0) { Vector3 emitterPosition = eyePos; ding1.SetPosition(emitterPosition); ding1.Start(); ComponentAudio buzz = entity.GetAudio(0); buzz.Stop(); entity.ChangePosition(new Vector3(0, -10, 0)); ghostKill = true; timer = 7.0f; score += 250; break; } } } }
public void GhostPlayerCollision(ComponentPosition positionComponent, ComponentCollision collisionComponent, ComponentVelocity velocityComponent, ComponentPosition fpositionComponent, ComponentCollision fcollisionComponent, ComponentVelocity fvelocityComponent, ComponentLife healthComponent, string entname, List <Entity> EntList, ComponentAudio faudioComponent) { int test = healthComponent.health(); if (test == 1) { if (entname == "Ghost") { if (positionComponent.Position.X > fpositionComponent.Position.X - 1 && positionComponent.Position.X < fpositionComponent.Position.X + 1 && positionComponent.Position.Y > fpositionComponent.Position.Y - 1 && positionComponent.Position.Y < fpositionComponent.Position.Y + 1) { GameScene.gameInstance.test(); faudioComponent.Start(); } } else { if (fpositionComponent.Position.X > positionComponent.Position.X - 1 && fpositionComponent.Position.X < positionComponent.Position.X + 1 && fpositionComponent.Position.Y > positionComponent.Position.Y - 1 && fpositionComponent.Position.Y < positionComponent.Position.Y + 1) { GameScene.gameInstance.test(); faudioComponent.Start(); } } } else { if (entname == "Ghost") { if (positionComponent.Position.X > fpositionComponent.Position.X - 1 && positionComponent.Position.X < fpositionComponent.Position.X + 1 && positionComponent.Position.Y > fpositionComponent.Position.Y - 1 && positionComponent.Position.Y < fpositionComponent.Position.Y + 1) { healthComponent.down(); fpositionComponent.Position = new Vector3(0.0f, 0.25f, -29.5f); foreach (Entity x in EntList) { if (x.Name == "Ghost") { List <IComponent> components = x.Components; IComponent GhostpositionComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_POSITION); }); GhostResest((ComponentPosition)GhostpositionComponent); } } ghostCount = 0; faudioComponent.Start(); } } else { if (fpositionComponent.Position.X > positionComponent.Position.X - 1 && fpositionComponent.Position.X < positionComponent.Position.X + 1 && fpositionComponent.Position.Y > positionComponent.Position.Y - 1 && fpositionComponent.Position.Y < positionComponent.Position.Y + 1) { healthComponent.down(); positionComponent.Position = new Vector3(0.0f, 0.25f, -29.5f); foreach (Entity x in EntList) { if (x.Name == "Ghost") { List <IComponent> components = x.Components; IComponent GhostpositionComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_POSITION); }); GhostResest((ComponentPosition)GhostpositionComponent); } } ghostCount = 0; faudioComponent.Start(); } } } }