private void RespondPlayerGhost(Entity player, Entity ghost) { //Debug.WriteLine("collision between player and ghost"); //if ghost is chasing { //play ghost sound ComponentTransform ghostTransform = (ComponentTransform)ghost.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); ComponentAudio ghostAudio = (ComponentAudio)ghost.FindComponent(ComponentTypes.COMPONENT_AUDIO); Vector3 emitterPosition = (ghostTransform).Position; int source = (ghostAudio).Source; AL.Source(source, ALSource3f.Position, ref emitterPosition); ghostAudio.Play(); //kill player ComponentLives livesComponent = (ComponentLives)player.FindComponent(ComponentTypes.COMPONENT_LIVES); livesComponent.Lives -= 1; ComponentTransform transformComponent = (ComponentTransform)player.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); transformComponent.Position = new Vector3(0, 1, 2); ComponentMovement movementComponent = (ComponentMovement)player.FindComponent(ComponentTypes.COMPONENT_MOVEMENT); movementComponent.DesiredLocation = new Vector3(0, 1, 2); } //else if ghost is fleeing //kill ghost //add 100 points to player }
private void RespondPlayerFood(Entity player, Entity food) { //play food sound ComponentTransform foodTransform = (ComponentTransform)food.FindComponent(ComponentTypes.COMPONENT_TRANSFORM); ComponentAudio foodAudio = (ComponentAudio)food.FindComponent(ComponentTypes.COMPONENT_AUDIO); Vector3 emitterPosition = (foodTransform).Position; int source = (foodAudio).Source; AL.Source(source, ALSource3f.Position, ref emitterPosition); foodAudio.Play(); //increase the score ComponentScore scoreComponent = (ComponentScore)player.FindComponent(ComponentTypes.COMPONENT_SCORE); float score = scoreComponent.Score; ComponentValue valueComponent = (ComponentValue)food.FindComponent(ComponentTypes.COMPONENT_VALUE); float value = valueComponent.Value; score += value; scoreComponent.Score = score; food.Enabled = false; }
private void CreateEntities() { Entity newEntity; newEntity = new Entity("Key1"); newEntity.AddComponent(new ComponentPosition(-6.0f, 1.0f, 53.5f)); //newEntity.AddComponent(new ComponentVelocity(0.0f, 0.0f, -1.0f)); newEntity.AddComponent(new ComponentGeometry("Geometry/Key/Key.obj")); newEntity.AddComponent(new ComponentSphereCollider(0.5f)); newEntity.AddComponent(new ComponentAudio("Audio/key_collect.wav", -6.0f, 1.0f, 53.5f)); entityManager.AddEntity(newEntity); keysLeft++; newEntity = new Entity("Key2"); newEntity.AddComponent(new ComponentPosition(-53.0f, 1.0f, 52.5f)); //newEntity.AddComponent(new ComponentVelocity(0.0f, 0.0f, -1.0f)); newEntity.AddComponent(new ComponentGeometry("Geometry/Key/Key.obj")); newEntity.AddComponent(new ComponentSphereCollider(0.5f)); newEntity.AddComponent(new ComponentAudio("Audio/key_collect.wav", -53.0f, 1.0f, 52.5f)); entityManager.AddEntity(newEntity); keysLeft++; newEntity = new Entity("Key3"); newEntity.AddComponent(new ComponentPosition(-53.0f, 1.0f, 3.5f)); //newEntity.AddComponent(new ComponentVelocity(0.0f, 0.0f, -1.0f)); newEntity.AddComponent(new ComponentGeometry("Geometry/Key/Key.obj")); newEntity.AddComponent(new ComponentSphereCollider(0.5f)); newEntity.AddComponent(new ComponentAudio("Audio/key_collect.wav", -53.0f, 1.0f, 3.5f)); entityManager.AddEntity(newEntity); keysLeft++; newEntity = new Entity("Portal"); newEntity.AddComponent(new ComponentPosition(-1.0f, 2.0f, 7.5f)); newEntity.AddComponent(new ComponentGeometry("Geometry/Portal/portal.obj")); newEntity.AddComponent(new ComponentSphereCollider(2.0f)); ComponentAudio PortalAudioComponent = new ComponentAudio("Audio/buzz.wav", -1.0f, 2.0f, 7.5f); newEntity.AddComponent(new ComponentTexture("Textures/Portal/portal_active.jpg")); PortalAudioComponent.Play(); newEntity.AddComponent(PortalAudioComponent); entityManager.AddEntity(newEntity); newEntity = new Entity("Maze"); newEntity.AddComponent(new ComponentPosition(0.0f, 0.0f, 0.0f)); //5.0, 0, 3.0 = good position for portal newEntity.AddComponent(new ComponentGeometry("Geometry/Maze/maze.obj")); newEntity.AddComponent(new ComponentBumpMap()); entityManager.AddEntity(newEntity); newEntity = new Entity("MazeFloor"); newEntity.AddComponent(new ComponentPosition(0.0f, 0.0f, 0.0f)); //5.0, 0, 3.0 = good position for portal newEntity.AddComponent(new ComponentGeometry("Geometry/Maze/floor.obj")); newEntity.AddComponent(new ComponentBumpMap()); entityManager.AddEntity(newEntity); newEntity = new Entity("Enemy1"); newEntity.AddComponent(new ComponentPosition(-28.5f, 2.0f, 28.5f)); newEntity.AddComponent(new ComponentVelocity(0.0f, 0.0f, 0.0f)); newEntity.AddComponent(new ComponentGeometry("Geometry/Moon/moon.obj")); newEntity.AddComponent(new ComponentSphereCollider(2.0f)); Vector3[] nodes = BuildEnemyNetwork(); newEntity.AddComponent(new ComponentTraveller(nodes, BuildEnemyNetworkNeighbours(nodes))); ComponentAudio audioComponent = new ComponentAudio("Audio/alert.wav", -28.5f, 2.0f, 28.5f); newEntity.AddComponent(audioComponent); entityManager.AddEntity(newEntity); newEntity = new Entity("Patroller1"); newEntity.AddComponent(new ComponentPosition(-3, 2, 53)); newEntity.AddComponent(new ComponentVelocity(0.0f, 0.0f, 0.0f)); newEntity.AddComponent(new ComponentGeometry("Geometry/Moon/moon.obj")); newEntity.AddComponent(new ComponentSphereCollider(2.0f)); //audioComponent.Play(); nodes = BuildPatrolNetwork1(); newEntity.AddComponent(new ComponentTraveller(nodes, BuildPatrolNetwork1Neighbours(nodes))); entityManager.AddEntity(newEntity); newEntity = new Entity("Patroller2"); newEntity.AddComponent(new ComponentPosition(-40.5f, 4, 51.5f)); newEntity.AddComponent(new ComponentVelocity(0.0f, 0.0f, 0.0f)); newEntity.AddComponent(new ComponentGeometry("Geometry/Moon/moon.obj")); newEntity.AddComponent(new ComponentSphereCollider(2.0f)); //audioComponent.Play(); nodes = BuildPatrolNetwork2(); newEntity.AddComponent(new ComponentTraveller(nodes, BuildPatrolNetwork1Neighbours(nodes))); entityManager.AddEntity(newEntity); newEntity = new Entity("Skybox"); newEntity.AddComponent(new ComponentPosition(camera.cameraPosition)); newEntity.AddComponent(new ComponentGeometry("Geometry/Skybox/skybox.obj")); newEntity.AddComponent(new ComponentSkybox()); entityManager.AddEntity(newEntity); newEntity = new Entity("MazeOuterCollisionBox"); Vector2[] mazePointsOuterWall = new Vector2[] { new Vector2(-1, 1), new Vector2(-16, 1), new Vector2(-16, 6), new Vector2(-41, 6), new Vector2(-41, 1), new Vector2(-56, 1), new Vector2(-56, 16), new Vector2(-51, 16), new Vector2(-51, 41), new Vector2(-56, 41), new Vector2(-56, 56), new Vector2(-41, 56), new Vector2(-41, 51), new Vector2(-16, 51), new Vector2(-16, 56), new Vector2(-1, 56), new Vector2(-1, 41), new Vector2(-6, 41), new Vector2(-6, 16), new Vector2(-1, 16)//add another 1,1 vector to check against first? }; newEntity.AddComponent(new ComponentLineCollider(mazePointsOuterWall)); entityManager.AddEntity(newEntity); newEntity = new Entity("MazeInnerCollisionBoxTopLeft"); Vector2[] mazeInnerWallTopLeft = new Vector2[] { new Vector2(-11, 16), new Vector2(-16, 16), new Vector2(-16, 11), new Vector2(-26, 11), new Vector2(-26, 21), new Vector2(-21, 21), new Vector2(-21, 26), new Vector2(-11, 26)//be sure to check last against first }; newEntity.AddComponent(new ComponentLineCollider(mazeInnerWallTopLeft)); entityManager.AddEntity(newEntity); newEntity = new Entity("MazeInnerCollisionBoxTopRight"); Vector2[] mazeInnerWallTopRight = new Vector2[] { new Vector2(-11, 31), new Vector2(-21, 31), new Vector2(-21, 36), new Vector2(-26, 36), new Vector2(-26, 46), new Vector2(-16, 46), new Vector2(-16, 41), new Vector2(-11, 41)//be sure to check last against first }; newEntity.AddComponent(new ComponentLineCollider(mazeInnerWallTopRight)); entityManager.AddEntity(newEntity); newEntity = new Entity("MazeInnerCollisionBoxBottomLeft"); Vector2[] mazeInnerWallBottomLeft = new Vector2[] { new Vector2(-31, 11), new Vector2(-41, 11), new Vector2(-41, 16), new Vector2(-46, 16), new Vector2(-46, 26), new Vector2(-36, 26), new Vector2(-36, 21), new Vector2(-31, 21)//be sure to check last against first }; newEntity.AddComponent(new ComponentLineCollider(mazeInnerWallBottomLeft)); entityManager.AddEntity(newEntity); newEntity = new Entity("MazeInnerCollisionBoxBottomRight"); Vector2[] mazeInnerWallBottomRight = new Vector2[] { new Vector2(-36, 31), new Vector2(-46, 31), new Vector2(-46, 41), new Vector2(-41, 41), new Vector2(-41, 46), new Vector2(-31, 46), new Vector2(-31, 36), new Vector2(-36, 36)//be sure to check last against first }; newEntity.AddComponent(new ComponentLineCollider(mazeInnerWallBottomRight)); entityManager.AddEntity(newEntity); }