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 }
public void OnAction(Entity entity) { if ((entity.Mask & MASK) == MASK) { List <IComponent> components = entity.Components; IComponent audioComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_AUDIO); }); ComponentAudio audio = (ComponentAudio)audioComponent; IComponent positionComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_POSITION); }); ComponentPosition position = (ComponentPosition)positionComponent; IComponent velocityComponent = components.Find(delegate(IComponent component) { return(component.ComponentType == ComponentTypes.COMPONENT_VELOCITY || component.ComponentType == ComponentTypes.COMPONENT_ARTIFICIAL_INTELLIGENCE); }); Audio(ref audio, ref position, ref velocityComponent); } }
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; }
public void OnNewEntity(Entity entity) { if ((entity.Mask & MASK) == MASK) { _entities.Add(entity); ComponentAudio audio = ((ComponentAudio)entity.GetComponent(ComponentTypes.COMPONENT_AUDIO)); audio.MuteAudio(false); } }
public void Set(ComponentAudio audio, ComponentPosition pos) { audio.Gpos = pos.Position; Matrix world = Matrix.CreateTranslation(audio.Gpos); Matrix wvp = world * CoolGameBase.view * CoolGameBase.projection; audio.setPos = Vector3.Transform(pos.Position, wvp); audio.updateA(); }
/// <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 OnRemoveEntity(Entity entity) { if ((entity.Mask & MASK) == MASK) { _entities.Remove(entity); ComponentAudio audio = ((ComponentAudio)entity.GetComponent(ComponentTypes.COMPONENT_AUDIO)); if (audio != null) { audio.MuteAudio(true); } } }
public override void OnAction(Entity entity) { ComponentAudio audio = entity.GetComponent <ComponentAudio>(); ComponentTransform position = entity.Transform; if (AudioManager.AudioListener != null) { audio.UpdatePosition(position.Position, AudioManager.AudioListener.Transform.Position, AudioManager.AudioListener.Transform.Forward, AudioManager.AudioListener.Transform.Up); } else { audio.UpdatePosition(position.Position, new Vector3(0, 0, 3), new Vector3(0, 0, -1), Vector3.UnitY); } }
public override string showDebugInfo() { string soundName; if (mSound != SOUND_DEFINE.SD_MIN) { soundName = ComponentAudio.getAudioName(mSound); } else { soundName = mSoundFileName; } return(this.GetType().ToString() + " : sound : " + mSound + ", name : " + soundName + ", loop : " + mLoop + ", volume : " + mVolume); }
private void SetupAudio() { // Setup OpenAL Listener listenerPosition = eyePos; listenerDirection = targetPos; listenerUp = Vector3.UnitY; ding1 = new ComponentAudio("Audio/ding1.wav", false); Vector3 emitterPosition = eyePos; ding1.SetPosition(emitterPosition); ding2 = new ComponentAudio("Audio/ding2.wav", false); ding2.SetPosition(emitterPosition); }
public void Audio(ref ComponentAudio audio, ref ComponentPosition position, ref IComponent velocity) { if (velocity.ComponentType == ComponentTypes.COMPONENT_VELOCITY) { audio.Velocity = ((ComponentVelocity)velocity).Velocity; } else { audio.Velocity = ((ComponentArtificialIntelligence)velocity).Velocity; } audio.Position = position.Position; AL.Source(audio.Source, ALSource3f.Position, audio.Position.X, audio.Position.Y, audio.Position.Z); AL.Source(audio.Source, ALSource3f.Velocity, audio.Velocity.X, audio.Velocity.Y, audio.Velocity.Z); AL.DopplerFactor(17f); }
public void OnUpdate() { foreach (var entity in _entities) { ComponentAudio audio = ((ComponentAudio)entity.GetComponent(ComponentTypes.COMPONENT_AUDIO)); Vector3 position = ((ComponentPosition)entity.GetComponent(ComponentTypes.COMPONENT_POSITION)).Position; Vector3 listenerPosition = ((ComponentPosition)_player.GetComponent(ComponentTypes.COMPONENT_POSITION)).Position; Vector3 listenerDirection = -Vector3.Normalize(position - listenerPosition); Vector3 listenerUp = Vector3.UnitY; AL.Source(audio.AudioSource, ALSource3f.Position, ref position); AL.Listener(ALListener3f.Position, ref listenerPosition); AL.Listener(ALListenerfv.Orientation, ref listenerDirection, ref listenerUp); } }
public override void execute() { txUIObject window = mReceiver as txUIObject; WindowComponentAudio audioComponent = window.getFirstActiveComponent <WindowComponentAudio>(); if (audioComponent != null) { string soundName; if (mSound != SOUND_DEFINE.SD_MIN) { soundName = ComponentAudio.getAudioName(mSound); } else { soundName = mSoundFileName; } audioComponent.play(soundName, mLoop, mVolume); } }
public override void execute() { GameScene gameScene = (mReceiver) as GameScene; GameSceneComponentAudio audioComponent = gameScene.getFirstActiveComponent <GameSceneComponentAudio>(); if (audioComponent != null) { string soundName; if (mSound != SOUND_DEFINE.SD_MIN) { soundName = ComponentAudio.getAudioName(mSound); } else { soundName = mSoundFileName; } audioComponent.play(soundName, mLoop, mVolume); } }
/// <summary> /// This is called when the game exits. /// </summary> public override void Close() { List <Entity> entities = entityManager.Entities(); foreach (Entity entity in entities) { if (entity.Components.Exists(x => x.ComponentType.ToString() == "COMPONENT_AUDIO")) { ComponentAudio audio = entity.GetAudio(0); audio.Close(); if (entity.Name.Contains("ghost")) { audio = entity.GetAudio(1); audio.Close(); } } } ding1.Close(); ding2.Close(); }
public override void OnCollision(Entity other) { if (other.HasMask(ComponentTypes.COMPONENT_SCRIPT)) { var scripts = other.GetComponents(ComponentTypes.COMPONENT_SCRIPT); bool isPickUp = false; foreach (ComponentScript p in scripts) { if (p.script is PickUp) { ComponentAudio audio = other.GetComponent(ComponentTypes.COMPONENT_AUDIO) as ComponentAudio; audio.SetAudioBuffer("collectable-pickup", false); isPickUp = true; UsePickUp(p.script as PickUp); } if (p.script is DroneMovementScript) { if ((p.script as DroneMovementScript).droneState != DroneMovementScript.DroneStateTypes.Dead && (p.script as DroneMovementScript).droneState != DroneMovementScript.DroneStateTypes.Disabled) { Health--; ComponentAudio audio = _droneCollision.GetComponent(ComponentTypes.COMPONENT_AUDIO) as ComponentAudio; audio.SetAudioBuffer("drone-collide", false); (entity.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position = _startPos; if (Health <= 0) { _sceneManager.SetScene("GameOver"); } } } } if (isPickUp) { other.Destroy(); } } base.OnCollision(other); }
private void DroneDeath() { ComponentRotation rotation = entity.GetComponent(ComponentTypes.COMPONENT_ROTATION) as ComponentRotation; ComponentPosition position = entity.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition; ComponentAudio audio = entity.GetComponent(ComponentTypes.COMPONENT_AUDIO) as ComponentAudio; DroneMovementScript movement = null; List <IComponent> scripts = entity.GetComponents(ComponentTypes.COMPONENT_SCRIPT); foreach (ComponentScript script in scripts) { if (script.script is DroneMovementScript) { movement = script.script as DroneMovementScript; } } rotation.Rotation = LookAt(position.Position, new Vector3(position.Position.X, -10.0f, position.Position.Z)); position.Position = new Vector3(position.Position.X, 0.0f, position.Position.Z); audio.SetAudioBuffer("drone-disable", false); movement.droneState = DroneMovementScript.DroneStateTypes.Dead; ResourceManager.GetPostProccessEffects()["AttackShake"].Active = false; entity.RemoveComponent(ComponentTypes.COMPONENT_RIGIDBODY); scripts = _droneTracker.GetComponents(ComponentTypes.COMPONENT_SCRIPT); foreach (ComponentScript script in scripts) { if (script.script is DroneTrackerScript) { (script.script as DroneTrackerScript).DeadDrones++; } } }
public override void OnUpdate(float pDelta) { if ((entity.Mask & MASK) == MASK) { ComponentTargetNode targetNode = entity.GetComponent(ComponentTypes.COMPONENT_TARGET) as ComponentTargetNode; ComponentPosition position = entity.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition; ComponentRotation rotation = entity.GetComponent(ComponentTypes.COMPONENT_ROTATION) as ComponentRotation; ComponentVelocity velocity = entity.GetComponent(ComponentTypes.COMPONENT_VELOCITY) as ComponentVelocity; ComponentSpeedModifier speedMod = entity.GetComponent(ComponentTypes.COMPONENT_SPEEDMOD) as ComponentSpeedModifier; ComponentAudio audio = entity.GetComponent(ComponentTypes.COMPONENT_AUDIO) as ComponentAudio; EnvironmentLocationScript droneLocation = null; List <IComponent> scripts = entity.GetComponents(ComponentTypes.COMPONENT_SCRIPT); foreach (ComponentScript script in scripts) { if (script.script is EnvironmentLocationScript) { droneLocation = script.script as EnvironmentLocationScript; } } if (droneState == DroneStateTypes.Idle) { IdleDroneLogic(targetNode, position, rotation, velocity, speedMod, audio, droneLocation, pDelta); } else if (droneState == DroneStateTypes.Aggressive) { AggressiveDroneLogic(targetNode, position, rotation, velocity, speedMod, audio, droneLocation, pDelta); } } else { throw new Exception("Drone doesn't have all required components"); } }
public static Entity[] LoadObject(string filename) { // Creates an empty entity list to be filled with all entities loaded for supplied xml file List <Entity> entityList = new List <Entity>(); try { // Loads in xml file with supplied name XDocument file = XDocument.Load(filename); // Will loop through each entity in file untill all have been added var entities = file.Descendants("entity"); foreach (var entity in entities) { // Initlises new entity with name found from file Entity newEntity = new Entity(entity.Element("name").Value.ToString()); var components = entity.Element("components").Elements(); // Searches through all components supplied and when matched adds that componenet to this new entity foreach (var component in components) { switch (component.Name.ToString()) { // POSITION COMPONENT case "position": // Splits by , to make a new vector from supplied floats string[] Pos = component.Value.Split(','); float[] posValues = Array.ConvertAll <string, float>(Pos, float.Parse); newEntity.AddComponent(new ComponentPosition(new Vector3(posValues[0], posValues[1], posValues[2]))); break; // TRANSFORM COMPONENT case "transform": // Splits by , to make a new vector from supplied floats string[] trans = component.Value.Split(','); float[] transValues = Array.ConvertAll <string, float>(trans, float.Parse); Vector3 scale = new Vector3(transValues[0], transValues[1], transValues[2]); Vector3 rotation = new Vector3(transValues[3], transValues[4], transValues[5]); newEntity.AddComponent(new ComponentTransform(scale, rotation)); break; // TEXTURE COMPONENT case "texture": // Splits by , to see if texture has supplied scaler value string[] texs = component.Value.Trim().Split(','); if (texs.Length == 1) { newEntity.AddComponent(new ComponentTexture(component.Value.Trim())); } else if (texs.Length == 2) { newEntity.AddComponent(new ComponentTexture(texs[0], float.Parse(texs[1]))); } break; // GEOMETRY COMPONENT case "geometry": newEntity.AddComponent(new ComponentGeometry(component.Value.Trim())); break; // VELOCITY COMPONENT case "velocity": // Splits by , to make a new vector from supplied floats string[] Vel = component.Value.Split(','); float[] velValues = Array.ConvertAll <string, float>(Vel, float.Parse); newEntity.AddComponent(new ComponentVelocity(new Vector3(velValues[0], velValues[1], velValues[2]))); break; // AUDIO COMPONENT case "audio": // Splits to check if audio file and volume is supplied with auto play and auto loop string[] aud = component.Value.Split(','); // Checks for number of parameters supplied if (aud.Length == 2) { newEntity.AddComponent(new ComponentAudio(aud[0], float.Parse(aud[1]))); } else if (aud.Length == 3) { newEntity.AddComponent(new ComponentAudio(aud[0], float.Parse(aud[1]), bool.Parse(aud[1]))); } else if (aud.Length == 4) { newEntity.AddComponent(new ComponentAudio(aud[0], float.Parse(aud[1]), bool.Parse(aud[2]), bool.Parse(aud[3]))); } // Reloads the audio object so settings are applied ComponentAudio audio = (ComponentAudio)newEntity.FindComponent(ComponentTypes.COMPONENT_AUDIO); audio.CloseAudio(); audio.AudioObject.ReloadAudio(); break; // SKYBOX COMPONENT case "skybox": // Splits by , to get each texture for skybox string[] skybox = component.Value.Trim().Split(','); newEntity.AddComponent(new ComponentSkyBox(skybox)); break; // COLLISION COMPONENT case "collision": newEntity.AddComponent(new ComponentCollider(bool.Parse(component.Value.Trim()))); break; // AI COMPONENT case "ai": newEntity.AddComponent(new ComponentAI(component.Value.Trim())); break; // ANIMATION COMPONENT case "animator": // Splits by , to get 3 direction to rotate in and final value is speed to rotate at string[] AniVals = component.Value.Split(','); float[] Ani = Array.ConvertAll <string, float>(AniVals, float.Parse); newEntity.AddComponent(new ComponentAnimation( new Vector3(Ani[0], Ani[1], Ani[2]), Ani[3])); break; } } // Finally adds this new entity to the list entityList.Add(newEntity); } } catch (Exception e) { Console.WriteLine(e.ToString()); } return(entityList.ToArray()); }
private void Playback(ComponentAudio AudioComponent, Vector3 position) { AudioComponent.SetPosition(position); }
public void Position(ComponentPosition positionComponent, ComponentAudio audioComponent) { audioComponent.SetPosition(positionComponent.Position); }
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; } }
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(); } } } }
private void Motion(ComponentAudio audio, ComponentPosition pos) { audio.SetPosition(pos.Position); }
private void AggressiveDroneLogic(ComponentTargetNode targetNode, ComponentPosition inPos, ComponentRotation inRot, ComponentVelocity inVel, ComponentSpeedModifier inSpeed, ComponentAudio inAudio, EnvironmentLocationScript inLoc, float inDelta) { Vector3 playerPosition = (_player.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; EnvironmentLocationScript playerLocation = null; List <IComponent> scripts = _player.GetComponents(ComponentTypes.COMPONENT_SCRIPT); foreach (ComponentScript script in scripts) { if (script.script is EnvironmentLocationScript) { playerLocation = script.script as EnvironmentLocationScript; } } _timeSinceTrigger += inDelta; //Once the trigger sound has finished, we changed to the angry sound if (_timeSinceTrigger > 1.1f && _timeSinceTrigger < 1.2f) { inAudio.SetAudioBuffer("angry-woah", true); } //Fastest way to calculate the distance float deltaX = playerPosition.X - inPos.Position.X; float deltaY = playerPosition.Y - inPos.Position.Y; float deltaZ = playerPosition.Z - inPos.Position.Z; double distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); Vector3 newPPos = new Vector3(playerPosition.X, inPos.Position.Y, playerPosition.Z); //Calculate new rotation inRot.Rotation = LookAt(inPos.Position, newPPos); if (_targettingPlayer) { inVel.Velocity = -Vector3.Normalize(inPos.Position - playerPosition); //Update position inPos.Position += ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); if (_nodePath.Count != 0) { _targettingPlayer = false; _targettingNodePath = true; targetNode.TargetNode = _nodePath.First(); } } else if (_targettingNodePath) { Vector3 targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); //Update position inPos.Position += ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); _previousPositions.Add(inPos.Position); if (_previousPositions.Count > 6) { _previousPositions.Remove(_previousPositions.First()); if (CheckIfStuck()) { //Recalculate velocity inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); } } //Distance the drone is going to travel Vector3 travelDistance = ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); //Fastest way to calculate the distance deltaX = targetPosition.X - inPos.Position.X; deltaY = targetPosition.Y - inPos.Position.Y; deltaZ = targetPosition.Z - inPos.Position.Z; double distanceToNode = Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); if (travelDistance.Length > distanceToNode) { inPos.Position = targetPosition; } else { inPos.Position += travelDistance; } //If drone reached temporary node position then we target the player again if (targetPosition == inPos.Position) { //If we've reached our target, target player again _nodePath.Remove(_nodePath.First()); if (_nodePath.Count != 0) { targetNode.TargetNode = _nodePath.First(); } else { _targettingPlayer = true; _targettingNodePath = false; } } } //If we're targetting the player, we will see if there are any nodes between myself and the player and target the nodes instead //if (_targettingPlayerAgg) //{ // inVel.Velocity = -Vector3.Normalize(inPos.Position - playerPosition); // //Update position // inPos.Position = inPos.Position + ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); // Tuple<bool, Entity> closestNode = NodeCloserThanPlayer(inPos.Position, newPPos, inLoc); // if (closestNode.Item1) // { // _targettingPlayerAgg = false; // _targettingNodeAgg = true; // targetNode.TargetNode = closestNode.Item2; // Vector3 targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; // inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); // } //} //If we found nodes between the drone and the player, we will target the node and then retarget the player //if (_targettingNodeAgg) //{ // //Update position // inPos.Position = inPos.Position + ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); // Vector3 targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; // _previousPositions.Add(inPos.Position); // if (_previousPositions.Count > 6) // { // _previousPositions.Remove(_previousPositions.First()); // if (CheckIfStuck()) // { // //Recalculate velocity // inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); // } // } // //Update position // Vector3 travelDistance = ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); // //Fastest way to calculate the distance // deltaX = targetPosition.X - inPos.Position.X; // deltaY = targetPosition.Y - inPos.Position.Y; // deltaZ = targetPosition.Z - inPos.Position.Z; // double distanceToNode = Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); // if (travelDistance.Length > distanceToNode) // { // inPos.Position = targetPosition; // } // else // { // inPos.Position += travelDistance; // } // //If drone reached temporary node position then we target the player again // if (targetPosition == inPos.Position) // { // //If we've reached our target, target player again // _targettingNodeAgg = false; // _targettingPlayerAgg = true; // } //} //If the distance between the player and drone is greater than the range then we change state, or if they are not in the same environment (can't be seen) if (distance > _viewRange && _nodePath.Count == 0 || playerLocation.EnvironmentLocation <= 0) { //Since we can't see the player anymore, we'll find the nearest node in our environment to follow targetNode.TargetNode = FindNearestEnvironmentNode(inPos, inLoc); Vector3 targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; //Other logic (speed mod change, reset velocity to target node (temp)) inSpeed.SpeedMod = 1.0f; inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); //Calculate new rotation inRot.Rotation = LookAt(inPos.Position, targetPosition); //Change drone state to idle droneState = DroneStateTypes.Idle; entity.RemoveComponent(ComponentTypes.COMPONENT_RIGIDBODY); _timeSinceTrigger = 0.0f; inAudio.SetAudioBuffer("idle-woah", true); _targettingPlayer = false; _targettingNodePath = false; //Change vaporwave post process effects active variable to false ResourceManager.GetPostProccessEffects()["AttackShake"].Active = false; } }
private void IdleDroneLogic(ComponentTargetNode targetNode, ComponentPosition inPos, ComponentRotation inRot, ComponentVelocity inVel, ComponentSpeedModifier inSpeed, ComponentAudio inAudio, EnvironmentLocationScript inLoc, float inDelta) { Vector3 targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; if (_player != null) { Vector3 playerPosition = (_player.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; EnvironmentLocationScript playerLocation = null; List <IComponent> scripts = _player.GetComponents(ComponentTypes.COMPONENT_SCRIPT); foreach (ComponentScript script in scripts) { if (script.script is EnvironmentLocationScript) { playerLocation = script.script as EnvironmentLocationScript; continue; } } //Fastest way to calculate the distance float deltaX = playerPosition.X - inPos.Position.X; float deltaY = playerPosition.Y - inPos.Position.Y; float deltaZ = playerPosition.Z - inPos.Position.Z; double distance = Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); //If the distance between the player and drone is less than 5 then we change state if (distance < _viewRange && inLoc.EnvironmentLocation == playerLocation.EnvironmentLocation && CanDroneSeeTarget(inPos.Position, targetPosition, playerPosition)) { //Other logic (speed mod change) inSpeed.SpeedMod = 3.0f; //Change drone state to aggressive droneState = DroneStateTypes.Aggressive; entity.AddComponent(new ComponentRigidbody()); //Change sound to the trigger sound inAudio.SetAudioBuffer("trigger-woah", false); //Change vaporwave post process effects active variable to true ResourceManager.GetPostProccessEffects()["AttackShake"].Active = true; _targettingPlayer = true; } else if (targetPosition == inPos.Position) { //If we've reached our target, update to a new target FindNewTarget(targetNode, inPos, inVel, inRot); } //Update position Vector3 travelDistance = ((inVel.Velocity * inSpeed.SpeedMod) * inDelta); //Fastest way to calculate the distance deltaX = targetPosition.X - inPos.Position.X; deltaY = targetPosition.Y - inPos.Position.Y; deltaZ = targetPosition.Z - inPos.Position.Z; double distanceToNode = Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ); if (travelDistance.Length > distanceToNode) { inPos.Position = targetPosition; } else { inPos.Position += travelDistance; } _previousPositions.Add(inPos.Position); if (_previousPositions.Count > 6) { _previousPositions.Remove(_previousPositions.First()); if (CheckIfStuck()) { //Since we can't see the player anymore, we'll find the nearest node in our environment to follow targetNode.TargetNode = FindNearestEnvironmentNode(inPos, inLoc, "CorridorNode"); targetPosition = (targetNode.TargetNode.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition).Position; //Other logic (speed mod change, reset velocity to target node (temp)) inVel.Velocity = -Vector3.Normalize(inPos.Position - targetPosition); //Calculate new rotation inRot.Rotation = LookAt(inPos.Position, targetPosition); } } } else { _player = _sceneManager.Scenes["Main"].Entities.Find(delegate(Entity e) { return(e.Name == "Camera1"); }); } }
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 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); }
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; } } } }