예제 #1
0
        public void Collision(ComponentPosition positionComponent, ComponentCollision collisionComponent, ComponentVelocity velocityComponent, ComponentPosition fpositionComponent, ComponentCollision fcollisionComponent, ComponentVelocity fvelocityComponent)
        {
            var still = Vector3.Zero;


            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)
            {
                if (velocityComponent.Velocity == up)
                {
                    positionComponent.Position += downfix;
                    velocityComponent.Velocity  = still;
                }
                else if (velocityComponent.Velocity == down)
                {
                    positionComponent.Position += upfix;
                    velocityComponent.Velocity  = still;
                }
                else if (velocityComponent.Velocity == right)
                {
                    positionComponent.Position += leftfix;
                    velocityComponent.Velocity  = still;
                }
                else if (velocityComponent.Velocity == left)
                {
                    positionComponent.Position += rightfix;
                    velocityComponent.Velocity  = still;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Returns the Vector3 position of this entity
        /// </summary>
        /// <returns></returns>
        public Vector3 GetPosition()
        {
            List <IComponent> compList = this.Components;
            ComponentPosition compPos  = (ComponentPosition)compList[0];

            return(compPos.Position);
        }
예제 #3
0
        /// <summary>
        /// Creates and intialises all systems required for this game scene
        /// </summary>
        private void CreateSystems()
        {
            ISystem newSystem;

            // Creates the system to calculate the SkyBox
            newSystem = new SystemSkyBox(ref sceneManager.camera);
            systemManager.AddSystem(newSystem);

            // Creates an array of light point for use in SystemRenderer
            Vector3[] array = new Vector3[] {
                new Vector3(G1X, 13.0f, 10.0f),
                new Vector3(G2X, 13.0f, 10.0f)
            };
            // Creates the system to calculate all the rendering (including lighting)
            newSystem = new SystemRender(ref sceneManager.camera, array);
            systemManager.AddSystem(newSystem);
            // Creates the system to handle all collision on X&Y axis (Sets object to check collision against to banana)
            ComponentPosition pos = (ComponentPosition)entityManager.FindEntity("Banana").FindComponent(ComponentTypes.COMPONENT_POSITION);

            newSystem = new SystemColliderXY(ref entityManager, pos);
            systemManager.AddSystem(newSystem);
            // Creates the system to handle the animation of game objects
            newSystem = new SystemAnimator();
            systemManager.AddSystem(newSystem);
        }
 private bool TryParseComponentPosition(string s, FileRange range, out ComponentPosition componentPosition, out string remaining)
 {
     if (s.StartsWith("_Start", StringComparison.OrdinalIgnoreCase))
     {
         componentPosition = ComponentPosition.Start;
         remaining         = s.Substring("_Start".Length);
         return(true);
     }
     else if (s.StartsWith("_Middle", StringComparison.OrdinalIgnoreCase))
     {
         componentPosition = ComponentPosition.Middle;
         remaining         = s.Substring("_Middle".Length);
         return(true);
     }
     else if (s.StartsWith("_End", StringComparison.OrdinalIgnoreCase))
     {
         componentPosition = ComponentPosition.End;
         remaining         = s.Substring("_End".Length);
         return(true);
     }
     else
     {
         _logger.Log(LogLevel.Error, range, $"Invalid point '{s}' (expected a string beginning with '_Start', '_Middle' or '_End'", null);
         componentPosition = ComponentPosition.Absolute;
         remaining         = null;
         return(false);
     }
 }
예제 #5
0
        private void FollowPath(ComponentVelocity vel, ComponentPosition pos)
        {
            int p = 0;

            if (path[p + 1].Position.X == path[p].Position.X)
            {
                if (path[p + 1].Position.Y < path[p].Position.Y)
                {
                    vel.Velocity = new Vector3(0, 0, -droneSpeed);
                }
                else
                {
                    vel.Velocity = new Vector3(0, 0, droneSpeed);
                }
            }
            else if (path[p + 1].Position.Y == path[p].Position.Y)
            {
                if (path[p + 1].Position.X < path[p].Position.X)
                {
                    vel.Velocity = new Vector3(-droneSpeed, 0, 0);
                }
                else
                {
                    vel.Velocity = new Vector3(droneSpeed, 0, 0);
                }
            }
            Vector2 v = new Vector2(pos.Position.X, pos.Position.Z);

            if (v == path[p + 1].Position)
            {
                p++;
            }
        }
예제 #6
0
 public void Collision(ref Entity entity, ref ComponentPosition position, ref ComponentCollisionSphere coll)
 {
     if ((position.Position - camera.cameraPosition).Length < coll.Radius + camera.Radius)
     {
         collisionManager.CollisionBetweenCamera(ref entity, COLLISIONTYPE.SPHERE_SPHERE);
     }
 }
        private void Animation(ComponentPosition position, ComponentDirection direction, ComponentAnimation animation)
        {
            float currentTime = animation.CurrentTime;
            float period      = animation.Period;
            float dt          = SceneManager.dt;
            float timeOver    = 0.0f;

            currentTime += dt;

            if (currentTime > period)
            {
                timeOver = (currentTime - period) % period;
                animation.CurrentTime = timeOver;
            }
            else
            {
                animation.CurrentTime = currentTime;
            }

            AnimationType type = animation.Type;

            if (type == AnimationType.ROTATION_Y)
            {
                Matrix3 rot = Matrix3.CreateRotationY(DegreeToRadians(360 / period) * SceneManager.dt);
                direction.Direction = rot * direction.Direction;
            }
            else if (type == AnimationType.OSCILLATION_Y)
            {
                float   angle     = (currentTime / period) * 360;
                float   height    = (float)Math.Cos(angle / 180 * Math.PI);
                Vector3 positionV = position.Position;
                positionV.Y       = position.StartPosition.Y + animation.MaxHeight * (-(height - 1) / 2f);
                position.Position = positionV;
            }
        }
예제 #8
0
        public void Motion(ComponentVelocity vel, ComponentPosition pos)
        {
            pos.Position = pos.Position + vel.Velocity * CoolGameBase.dt;

            //Console.WriteLine("Position of Drone: " + pos.Position);
            //Console.WriteLine("Velocity of Drone: " + vel.Velocity);
        }
 public void Collision(ref Entity entity, ref ComponentPosition position, ref ComponentCollisionLine coll)
 {
     if (CameraCollision(ref entity, ref position, ref coll))
     {
         collisionManager.CollisionBetweenCamera(ref entity, COLLISIONTYPE.LINE_LINE);
     }
 }
예제 #10
0
        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);
            }
        }
        public void Motion(ComponentPosition position, float velocity, ComponentDirection direction)
        {
            Matrix3 rot = Matrix3.CreateRotationY(DegreeToRadians(direction.DirectionChange) * SceneManager.dt);

            direction.Direction = rot * direction.Direction;

            position.Position += direction.Direction * velocity * SceneManager.dt;
        }
예제 #12
0
 public XmlComponentPoint(
     ComponentPosition relativeToX,
     ComponentPosition relativeToY,
     IEnumerable <IXmlComponentPointOffset> offsets)
 {
     RelativeToX = relativeToX;
     RelativeToY = relativeToY;
     Offsets     = offsets.ToList();
 }
예제 #13
0
 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;
     }
 }
예제 #14
0
        public static ComponentPoint ReadComponentPoint(this System.IO.BinaryReader reader)
        {
            ComponentPosition relX    = (ComponentPosition)reader.ReadUInt32();
            ComponentPosition relY    = (ComponentPosition)reader.ReadUInt32();
            double            offsetX = reader.ReadDouble();
            double            offsetY = reader.ReadDouble();

            return(new ComponentPoint(relX, relY, new Vector(offsetX, offsetY)));
        }
예제 #15
0
        /// <summary>
        /// Works out which 1x1 unit tiles of the map can be walked on by the AI
        /// </summary>
        void CalculateTraversableTiles()
        {
            // This method works in a similar idea to battleships to set units in the
            // 2D grid to say if something is there or not, in this case it will be true if its clear, false if its blocked
            //Entity[] test = Collidables;
            for (int x = 0; x < Traversable.GetLength(0); x++)
            {
                for (int z = 0; z < Traversable.GetLength(1); z++)
                {
                    Traversable[x, z] = true;
                }
            }

            foreach (Entity entity in Collidables)
            {
                ComponentTransform t = (ComponentTransform)entity.Components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_TRANSFORM);
                });
                ComponentPosition p = (ComponentPosition)entity.Components.Find(delegate(IComponent component)
                {
                    return(component.ComponentType == ComponentTypes.COMPONENT_POSITION);
                });

                // Works out position of each entity and the starting point of the shape (e.g. position is centra of entity)
                Vector3 scale = new Vector3(t.Transform.ExtractScale().X, 0.0f, t.Transform.ExtractScale().Z);
                Vector3 start = new Vector3((p.Position.X - (scale.X)), 0.0f, (p.Position.Z - (scale.Z)));
                // Offset changes from world coords to grid coords (e.g. a 50x50 world would centre at 0,0 but grid centre would be 25,25)
                int xOffset = (int)start.X + (mWidth / 2);
                int zOffset = (int)start.Z + (mHeight / 2);

                if (!(xOffset >= Traversable.GetLength(0)) && !(zOffset > Traversable.GetLength(1)) && !(xOffset < 0) && !(zOffset < 0))
                {
                    // This sets units where a collidable entity is to false to say the AI cannot traverse this unit
                    for (int x = xOffset; x < (xOffset + t.Transform.ExtractScale().X * 2); x++)
                    {
                        for (int z = zOffset; z < (zOffset + t.Transform.ExtractScale().Z * 2); z++)
                        {
                            float xSize = (Traversable.GetLength(0)) - 2;
                            float zSize = (Traversable.GetLength(1)) - 2;

                            xSize++;
                            zSize++;
                            if (!(x <= 0) && !(x >= xSize) && !(z <= 0) && !(z >= zSize))
                            {
                                // This creates the cube for AI to avoid apposed to avoid just a single vertex
                                Traversable[z, x + 1]     = false;
                                Traversable[z + 1, x]     = false;
                                Traversable[z + 1, x + 1] = false;
                            }
                            Traversable[z, x] = false;
                        }
                    }
                }
            }
        }
예제 #16
0
        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();
        }
예제 #17
0
        public void Motion(ComponentPosition pPos, ComponentVelocity pVel, ComponentAI pAI, string name)
        {
            // Updates the target with the most recent player position
            if (targetIsPlayer)
            {
                pAI.Target = mCamera.Position;
            }

            // Checks if the AI has found its target and skips search code for efficency
            if (RoundVectorPosition(pPos.Position).Xz == pAI.Target.Xz)
            {
                return;
            }

            // Checks if the AI's target is within map boundaries
            if (!(pAI.Target.X < (mWidth / 2) && !(pAI.Target.X > (mWidth / 2)) && pAI.Target.Z < (mHeight / 2) && !(pAI.Target.Z > (mHeight / 2))))
            {
                return;
            }

            // Makes sure target is in a traversable area
            if (!Traversable[(int)pAI.Target.Z + (mHeight / 2), (int)pAI.Target.X + (mWidth / 2)])
            {
                return;
            }

            if (pAI.Path.Length > 0 && pAI.ogTarget == pAI.Target)
            {
                // Path following
                Vector3 direction = pAI.Path[0] - pPos.Position;
                pPos.Position += direction * pVel.Veclotiy * deltaTime;
            }
            else
            {
                // Updates path finding
                pAI.ogTarget = pAI.Target;
                pAI.Path     = ASPath(RoundVectorPosition(pPos.Position), RoundVectorPosition(pAI.Target));
                // Path following
                if (pAI.Path.Length <= 0)
                {
                    // Path finding failed
                    return;
                }
                Vector3 direction = pAI.Path[0] - pPos.Position;
                pPos.Position += direction * pVel.Veclotiy * deltaTime;
            }
            // Check to see if AI has hit closest point in path and removes it if true so it can follow the next point
            if (RoundVectorPosition(pPos.Position) == pAI.Path[0])
            {
                pAI.Path = pAI.Path.Skip(1).ToArray();
            }
        }
예제 #18
0
 public ComponentPointTemplate(ComponentPosition xPosition,
                               ComponentPosition yPosition,
                               IReadOnlyList <IModifierToken> xModifiers,
                               IReadOnlyList <IModifierToken> yModifiers)
 {
     XPosition  = xPosition;
     YPosition  = yPosition;
     XModifiers = xModifiers;
     YModifiers = yModifiers;
     XVariables = xModifiers.Where(t => t is DefinitionModifierToken).Cast <DefinitionModifierToken>().Select(t => t.Name);
     YVariables = yModifiers.Where(t => t is DefinitionModifierToken).Cast <DefinitionModifierToken>().Select(t => t.Name);
     Variables  = XVariables.Concat(YVariables);
 }
예제 #19
0
 /// <summary>
 /// Initialize logger
 /// </summary>
 /// <param name="props">Collection which has logger configuration</param>
 public FileLogging(IDictionary <string, string> props)
 {
     this.dateTimeKeyValuePair    = new Dictionary <string, string>();
     this.componentPosition       = (ComponentPosition)int.Parse(props["componentPositionInFileName"]);
     this.isDirectoryPerComponent = Convert.ToBoolean(props["directoryRequiredPerComponent"]);
     this.maxFileSize             = Convert.ToInt64(props["filesize"]) * 1024;
     this.fileNameFormat          = props["format"];
     this.messageArray            = props["data"].Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
     this.LogLevel       = (LogLevel)int.Parse(props["logLevel"]);
     this.extension      = props["fileExtension"];
     this.formatArray    = fileNameFormat.Split(new char[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
     this.logFileHandler = new Dictionary <string, KeyValue <string, long> >();
 }
예제 #20
0
        private void CreateSystems()
        {
            ISystem newSystem;

            ComponentPosition pos = (ComponentPosition)entityManager.FindEntity("Banana").FindComponent(ComponentTypes.COMPONENT_POSITION);

            newSystem = new SystemRender();
            systemManager.AddSystem(newSystem);
            newSystem = new SystemCollision(pos.Position);
            systemManager.AddSystem(newSystem);
            newSystem = new SystemPhysics(ref sceneManager.cam);
            systemManager.AddSystem(newSystem);
            newSystem = new SystemSkyBox(ref sceneManager.cam);
            systemManager.AddSystem(newSystem);
        }
예제 #21
0
 private void MoveAi(Vector3 playerPos, ComponentPosition ghostPos, Vector3 vel)
 {
     if (ghostPos.Position.Xz != playerPos.Xz)
     {
         if (ghostPos.Position.Z < playerPos.Z)
         {
             vel.Z = playerPos.Z * -1;
         }
         else
         {
             vel.Z = playerPos.Z;
         }
         ghostPos.Position += vel * GameScene.dt;
     }
 }
        public void TestParseCombinedAxes(string input, ComponentPosition expectedRelativeTo, double expectedXOffset, double expectedYOffset)
        {
            bool success = _parser.TryParse(input, new FileRange(), out var result);

            Assert.That(success, Is.True);

            Assert.That(result.RelativeToX, Is.EqualTo(expectedRelativeTo));
            Assert.That(result.RelativeToY, Is.EqualTo(expectedRelativeTo));

            double xOffset = result.Offsets.Cast <XmlComponentPointOffset>().Where(x => x.Axis == OffsetAxis.X).Sum(x => x.Offset);
            double yOffset = result.Offsets.Cast <XmlComponentPointOffset>().Where(x => x.Axis == OffsetAxis.Y).Sum(x => x.Offset);

            Assert.That(xOffset, Is.EqualTo(expectedXOffset));
            Assert.That(yOffset, Is.EqualTo(expectedYOffset));
        }
예제 #23
0
        public void Collide(ComponentPosition pPos, ComponentTransform transform)
        {
            float xOffset  = pPos.Position.X + (transform.Transform.ExtractScale().X / 2);
            float sxOffset = pPos.Position.X - (transform.Transform.ExtractScale().X / 2);
            float zOffset  = pPos.Position.Z + (transform.Transform.ExtractScale().Z / 2);
            float szOffset = pPos.Position.Z - (transform.Transform.ExtractScale().Z / 2);

            if (mObject.X >= sxOffset && mObject.X <= xOffset)
            {
                if (mObject.Z > szOffset && mObject.Z < zOffset)
                {
                    Console.WriteLine("Collision Detected");
                }
            }
        }
예제 #24
0
        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);
        }
예제 #25
0
        private void PlayerDetection(ComponentPosition pos, ComponentVelocity vel, AIStates state)
        {
            if (state == AIStates.Wandering)
            {
                Vector2 AIpos = new Vector2(pos.Position.X, pos.Position.Z);
                Vector2 v     = MyGame.NewCameraPosition - AIpos;

                float dot = MyGame.DotProduct(v.Normalized(), AIpos.Normalized());

                if (dot > 0.7)
                {
                    droneSpeed = 0.8f;
                }
                else
                {
                    droneSpeed = 0.5f;
                }
            }
        }
예제 #26
0
        public SystemColliderXY(ref EntityManager entityManager, ComponentPosition pPosition)
        {
            // Used to gain player position
            mPosition    = pPosition;
            LastPosition = mPosition.Position;

            // Makes a list of all collidable entities and works out the last entity that will be checked
            // This is used at the end of the collision test to update the LastPosition vector
            EntityNameList = new List <string>();
            for (int i = 0; i < entityManager.EntityNameList().Length; i++)
            {
                Entity value = entityManager.FindEntity(entityManager.EntityNameList()[i]);
                if ((value.Mask & MASK) == MASK)
                {
                    EntityNameList.Add(value.Name);
                }
            }
            LastEntityToCheck = EntityNameList[EntityNameList.Count - 1];
        }
예제 #27
0
        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;
                    }
                }
            }
        }
예제 #28
0
        private void Motion(ComponentPosition positions, Vector3 velocity, Geometry geom, Vector3 objPos, string collisionType, WallCollisions wallCol)
        {
            Vector3 newpos = positions.Position;
            Vector3 newvel = velocity * 15;

            newpos += newvel * GameScene.dt;
            checkCollsion(newpos, geom, objPos, collisionType, ref velocity, wallCol);


            if (hit != true && wallCol.getlength() == i)
            {
                positions.Position += (velocity * GameScene.dt);
            }
            else if (wallCol.getlength() == i)
            {
                velocity           *= -1;
                positions.Position += (velocity * GameScene.dt);
                hit = false;
            }
        }
예제 #29
0
        public override void OnUpdate(float pDelta)
        {
            List <Entity> bullets = (_sceneManager.Scenes["Main"].Entities.FindAll(delegate(Entity e)
            {
                return(e.Name.Contains("Bullet") == true);
            }));

            foreach (var bullet in bullets)
            {
                if (bullet != null)
                {
                    ComponentPosition position = bullet.GetComponent(ComponentTypes.COMPONENT_POSITION) as ComponentPosition;
                    ComponentVelocity velocity = bullet.GetComponent(ComponentTypes.COMPONENT_VELOCITY) as ComponentVelocity;

                    position.Position = position.Position + (velocity.Velocity * _bulletSpeed) * pDelta;
                }
            }

            base.OnUpdate(pDelta);
        }
예제 #30
0
 /// <summary>
 /// Method to organise the ghost AI target points
 /// </summary>
 private void ManageGhostTargets()
 {
     // For every ghost in the system AI update its target
     for (int i = 0; i < NumberOfGhost; i++)
     {
         // Gets access to the AI componet and position component to update their values for each AI
         ComponentAI       Ai  = (ComponentAI)entityManager.FindEntityWithMask(ComponentTypes.COMPONENT_AI)[i].FindComponent(ComponentTypes.COMPONENT_AI);
         ComponentPosition Pos = (ComponentPosition)entityManager.FindEntityWithMask(ComponentTypes.COMPONENT_POSITION)[i].FindComponent(ComponentTypes.COMPONENT_POSITION);
         // If the player is powered up the the target should be the ghost start (makes them run away from the player)
         if (isPowerUp)
         {
             Ai.Target = StartPosition_Ghost;
         }
         // If the player is not powered up then the target is the player (the ghosts be hungery)
         else
         {
             Ai.Target = RoundVector(sceneManager.camera.Position);
         }
     }
 }
예제 #31
0
 public ComponentPoint(ComponentPosition relativeToX, ComponentPosition relativeToY, Vector offset)
 {
     RelativeToX = relativeToX;
     RelativeToY = relativeToY;
     Offset = offset;
 }