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; } } } }