예제 #1
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="x">where to start x</param>
 /// <param name="y">where to start x</param>
 /// <param name="w">width of camera</param>
 /// <param name="h">height of camera</param>
 public cCamera(int x, int y, int w, int h)
 {
     _instance = this;
     _pos = new Vector2(x,y);
     _widthHeight = new Vector2(w,h);
     _focusObject = null;
     _bounds = Vector4.Zero;
     _updateToFocus = false;
 }
예제 #2
0
 public cRayCollision()
 {
     collision = false;
     where = new Vector2(0,0);
     normal = new Vector2(0, 0);
     c = new Vector2(0, 0);
     d = new Vector2(0, 0);
     what = null;
 }
예제 #3
0
        /// <summary>
        /// constructor
        /// </summary>
        public cPortal()
            : base(10, 50, 1)
        {
            //RigidBody.CanCollide = false;
            RigidBody.IsStatic = true;
            //this.CanAttachPortalTo = false;
            //this.IsPortalTransparrent = false;
            _attachedTo = null;
            _openingAnim = false;

            cLightMapManager.Instance.add(this);

            // Make sure the textures are available to use
            cSpriteManager.Instance.addTexture(@"Resources/Sprites/portal", "portal");
            cSpriteManager.Instance.addTexture(@"Resources/LightMaps/portalLightMap", "portalLightMap");
            base.setStaticSprite("portal");
            _sprite.Visible = false;
            _lightMap = new cSprite("portalLightMap");
        }
예제 #4
0
        public int checkPortalCollisions(cRigidBodyGameObject obj)
        {
            AABB aabb = obj.RigidBody.Geometry.AABB;
            ContactList newContactList = new ContactList(10);
            newContactList.Clear();

            if (AABB.Intersect(aabb, _portals[0].RigidBody.Geometry.AABB))
            {
                //Console.WriteLine("COLLISION 0");
                obj.RigidBody.Collide(_portals[0].RigidBody, newContactList);
                if (newContactList.Count != 0) { return 0; }
            }
            else if (AABB.Intersect(aabb, _portals[1].RigidBody.Geometry.AABB))
            {
                //Console.WriteLine("COLLISION 1");
                obj.RigidBody.Collide(_portals[1].RigidBody, newContactList);
                if (newContactList.Count != 0) { return 1; }
            }
            else
            {
                //Console.WriteLine("-------");
            }
            return -1;
        }
예제 #5
0
 public void addObject(cRigidBodyGameObject obj)
 {
     _rigidBodies.Add(obj);
     _physicsSimulator.Add(obj.RigidBody);
 }
예제 #6
0
 public void removeObject(cRigidBodyGameObject obj)
 {
     _rigidBodies.Remove(obj);
     _physicsSimulator.Remove(obj.RigidBody);
 }
예제 #7
0
        /// <summary>
        /// Attach to a point with a given normal.
        /// TODO: This will need to be more generic to allow for values other than 1
        ///         but for now it only needs 1.
        /// </summary>
        /// <param name="where">the point to attach at</param>
        /// <param name="normal">the normal of the point its attached at</param>
        public void attachTo(Vector2 where, Vector2 normal, cRigidBodyGameObject what)
        {
            float angle = (float)(Math.Atan2(-normal.Y, -normal.X));
            Orientation = angle;
            Position = where;
            _attachedTo = what;
            _normal = normal;

            _openingAnim = true;
            _openAnimTime = 0;
        }
예제 #8
0
        public void loadLevel(String levelName)
        {
            // TODO: We need to dump the graphics from a previously loaded
            // level before we load new ones, or instead when we load the
            // graphics below we check that they dont already exist.

            #region XMLParsing
            // If the XML document isnt in the correct format that we expect then
            // an XmlException will be thrown to alert the user to the fact.
            try
            {
                // Load the XML document into the reader
                XmlTextReader reader = new XmlTextReader(@"Resources/Levels/"+levelName+".xml");
                Dictionary<String, objDef> spriteVerts = new Dictionary<String, objDef>();

                // Loop through all the elements
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        String elementName = reader.Name;
                        // If its our top-level elemennt
                        if (elementName == "level")
                        {
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);

                                if (reader.Name == "type")
                                {
                                    if (reader.Value == "lab")
                                    {
                                        // Load the parallax graphics
                                        cSpriteManager.Instance.addTexture("Resources/Textures/wall01-800-600", "parallax_lab_back");
                                        //cSpriteManager.Instance.addTexture(gd, "Resources/floor.bmp", "parallax_lab_front");

                                        // Create new sprites
                                        _paralaxBack = new cSprite("parallax_lab_back");
                                        //_paralaxFront = new cSprite("parallax_lab_front");
                                    }
                                }

                                if (reader.Name == "name")
                                {
                                    _currentLevelName = reader.Value;
                                }
                            }
                        }

                        if (elementName == "description")
                        {
                            string str = reader.ReadInnerXml();
                            str = str.Replace("\r","");
                            str = str.Replace("\t","");
                            string[] s = { "\n" };
                            _currentLevelDescription = str.Split(s, StringSplitOptions.RemoveEmptyEntries);
                        }

                        // If its a frame of the animation
                        if (elementName == "sprite")
                        {
                            String spriteURL = "";
                            String type = "";
                            String collisionType = "";
                            String spriteName = "";
                            bool spritecollision = false;
                            int width = 0;
                            int height = 0;
                            float mass = 1;
                            float friction = 1;
                            float restitution = 0;

                            if (reader.HasAttributes)
                            {

                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    reader.MoveToAttribute(i);

                                    // Getting the properties of the sprite
                                    if (reader.Name == "url") { spriteURL += reader.Value; }
                                    if (reader.Name == "type") { type = reader.Value; }
                                    if (reader.Name == "collision") { collisionType = reader.Value; }
                                    if (reader.Name == "w") { width = Int32.Parse(reader.Value); }
                                    if (reader.Name == "h") { height = Int32.Parse(reader.Value); }
                                    if (reader.Name == "mass") { mass = float.Parse(reader.Value); }
                                    if (reader.Name == "friction") { mass = float.Parse(reader.Value); }
                                    if (reader.Name == "restitution") { mass = float.Parse(reader.Value); }
                                    if (reader.Name == "name") { spriteName = reader.Value; }
                                }
                            }

                            if (type == "static") { cSpriteManager.Instance.addTexture(spriteURL, spriteName); }
                            if (collisionType == "rectangle")
                            {
                                Vertices v = Vertices.CreateRectangle(width,height);
                                objDef od = new objDef();
                                od.v = v;
                                od.mass = mass;
                                od.friction = friction;
                                od.restitution = restitution;
                                spriteVerts.Add(spriteName, od);
                            }
                        }

                        // If its a frame of the animation
                        if (elementName == "obj")
                        {
                            String type = "";
                            String resource = "";
                            int x = 0;
                            int y = 0;
                            float orientation = 0;
                            bool canAttachPortalTo = false;

                            if (reader.HasAttributes)
                            {
                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    reader.MoveToAttribute(i);

                                    // Getting the properties of the object
                                    if (reader.Name == "type") { type = reader.Value; }
                                    if (reader.Name == "x") { x = Int32.Parse(reader.Value); }
                                    if (reader.Name == "y") { y = Int32.Parse(reader.Value); }
                                    if (reader.Name == "orientation") { orientation = float.Parse(reader.Value); }
                                    if (reader.Name == "resource") { resource = reader.Value; }
                                    if (reader.Name == "canAttachPortalTo") { canAttachPortalTo = bool.Parse(reader.Value); }
                                }
                            }

                            objDef od = spriteVerts[resource];

                            cRigidBodyGameObject obj = new cRigidBodyGameObject(od.mass,od.v);
                            if (type == "static") { obj.RigidBody.IsStatic = true; }
                            obj.setStaticSprite(resource);
                            obj.Position = new Vector2(x, y);
                            obj.Orientation = orientation*(float)(Math.PI*2/360);
                            obj.RigidBody.RestitutionCoefficient = od.restitution;
                            obj.RigidBody.FrictionCoefficient = od.friction;
                            obj.RigidBody.RotationalDragCoefficient = 10;
                            obj.RigidBody.LinearDragCoefficient = .00001f;
                            obj.CanAttachPortalTo = canAttachPortalTo;
                            _sceneObjects.Add(obj);

                        }

                        // If its a frame of the animation
                        if (elementName == "trigger")
                        {
                            String type = "";
                            int x = 0;
                            int y = 0;
                            int w = 0;
                            int h = 0;
                            String nextLevel = "";
                            String audio = "";

                            if (reader.HasAttributes)
                            {
                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    reader.MoveToAttribute(i);

                                    // Getting the properties of the object
                                    if (reader.Name == "type") { type = reader.Value; }
                                    if (reader.Name == "x") { x = Int32.Parse(reader.Value); }
                                    if (reader.Name == "y") { y = Int32.Parse(reader.Value); }
                                    if (reader.Name == "w") { w = Int32.Parse(reader.Value); }
                                    if (reader.Name == "h") { h = Int32.Parse(reader.Value); }
                                    if (reader.Name == "audio") { audio = reader.Value; }
                                    if (reader.Name == "nextLevel") { nextLevel = reader.Value; }
                                }
                            }

                            if (type == "player_spawn")
                            {
                                cPlayer.Instance.spawnIn(new Vector2(x,y));
                            }

                            if (type == "flame")
                            {
                                cFlameEffect fe = new cFlameEffect(Portal2D.GD, Portal2D.CM, w, h);
                                fe.Position = new Vector2(x, y);
                                _shaderObjects.Add(fe);
                            }

                            if (type == "exit")
                            {
                                cExit e = new cExit(nextLevel,audio);
                                e.Position = new Vector2(x,y);
                                _sceneObjects.Add(e);
                            }

                        }

                        // If its a frame of the animation
                        if (elementName == "light")
                        {
                            String type = "";
                            String resource = "";
                            String lightMap = "";
                            int x = 0;
                            int y = 0;

                            if (reader.HasAttributes)
                            {
                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    reader.MoveToAttribute(i);

                                    // Getting the properties of the object
                                    if (reader.Name == "type") { type = reader.Value; }
                                    if (reader.Name == "resource") { resource = reader.Value; }
                                    if (reader.Name == "lightMap") { lightMap = reader.Value; }
                                    if (reader.Name == "x") { x = Int32.Parse(reader.Value); }
                                    if (reader.Name == "y") { y = Int32.Parse(reader.Value); }
                                }
                            }

                            if (type == "point")
                            {
                                cLight l = new cLight();
                                l.setStaticSprite(resource);
                                l.setLightMap(lightMap);
                                l.AffectedByGravity = false;
                                l.Position = new Vector2(x, y);
                                cLightMapManager.Instance.add(l);
                                _sceneObjects.Add(l);
                            }

                        }
                    }
                }
            }
            catch (XmlException e)
            {
                Console.WriteLine("error occured: " + e.Message);
            }
            #endregion

            _levelFastestTime = this.getLevelFastestTime(_currentLevelName);
        }
예제 #9
0
 /// <summary>
 /// opens a portal at the given location. alternates 
 /// between the two portal, which one is to be opened next
 /// </summary>
 /// <param name="where">where to open the portal</param>
 /// <param name="normal">the normal of the slope to open it on</param>        
 public void openPortal(int number, Vector2 where, Vector2 normal, cRigidBodyGameObject what)
 {
     normal.Y = -normal.Y;
     _portals[number].attachTo(where, normal, what);
     _portals[number].Sprite.Visible = true;
     cAudio.Instance.play("portal");
     cParticleEngine.Instance.spawnParticleEffect("portal_open", where, normal*2);
 }