Exemplo n.º 1
0
        private bool CheckPlanetCollision(Actor a_1,Actor a_2)
        {
            float a1Rad = a_1.m_radius * a_1.m_scale;
            float a2Rad = a_2.m_radius * a_2.m_scale;

            float distance = (a_1.m_pos - a_2.m_pos).Length();

            if (distance < a1Rad + a2Rad)
                return true;
            else
                return false;
        }
Exemplo n.º 2
0
 public void Init(Actor a_actor, string a_name, int a_fHeight, int a_fWidth, int a_fCount, int a_fColStart, int a_fRowStart, float a_animSpeed, List<Texture2D> a_textures, string a_state)
 {
     //constructor            
     this.m_owningActor = a_actor;
     this.m_SpriteWidth = a_fWidth;
     this.m_SpriteHeight = a_fHeight;
     this.m_frameCount = a_fCount;
     this.m_name = a_name;
     this.m_spriteList = a_textures;
     this.srcUV = new Vector2(0, 0);
     this.m_framesPerRow = a_textures[0].Width / a_fWidth;
     this.m_timeCounter = 0.0f;
     this.m_currentFrame = 0;
     this.m_animSpeed = a_animSpeed;
     this.m_frameColStart = a_fColStart;
     this.m_frameRowStart = a_fRowStart;
     this.m_animState = a_state;
     this.m_hasReachedEnd = false;
 }
Exemplo n.º 3
0
        /// <summary>
        /// function assumes one of the passed actors is the player
        /// </summary>
        /// <param name="a_1"></param>
        /// <param name="a_2"></param>
        /// <returns>true on collision with gravity well</returns>
        private bool CheckGravityCollision(Actor a_1, Actor a_2)
        {
            float a1Rad = 0;
            float a2Rad = 0;

            //            Vector2 pos1 = new Vector2(0,0);
            //            Vector2 pos2 = new Vector2(0,0);
            if (a_1.m_classID != CLASSID.CLASSID_BACKGROUND && a_2.m_classID != CLASSID.CLASSID_BACKGROUND)
            {
                //check if actor one is the player or planet
                if (a_1.m_classID == CLASSID.CLASSID_PLAYER)
                {
                    a1Rad = a_1.m_radius * a_1.m_scale;
                    //                pos1 = a_1.m_pos;
                }
                else
                {
                    Planet planet = (Planet)a_1;
                    a1Rad = planet.m_effectiveRadius * planet.m_scale;
                }

                //check if player one or two is the player
                if (a_2.m_classID == CLASSID.CLASSID_PLAYER)
                {
                    a2Rad = a_2.m_radius * a_2.m_scale;
                }
                else
                {
                    Planet planet = (Planet)a_2;
                    a2Rad = planet.m_effectiveRadius * planet.m_scale;
                }

                float distance = (a_1.m_pos - a_2.m_pos).Length();

                if (distance < a1Rad + a2Rad)
                    return true;
                else
                    return false;
            }
            return false;
        }
Exemplo n.º 4
0
 public void Init(Actor a_owningActor)
 {
     m_actor = a_owningActor;
     
 }
Exemplo n.º 5
0
        //XmlDocument xmlDoc = new XmlDocument(); // Create an XML document object

        //XElement


        //TODO 
        //create global settings for platform to build to - psm, andriod etc

        //==================================        

        public void Init(Game1 a_game, SpriteBatch a_sb, List<Actor> a_list, List<Actor> a_splashList)
        {
            //GOBAL SETTINGS
            m_globalScale = 1;            

            //global scale will scale everything in the game


            //snippets from http://www.dotnetcurry.com/showarticle.aspx?ID=564
            //load xml file
            XElement xelement = XElement.Load("content/config.xml");

//            IEnumerable<XElement> planets = xelement.Elements();

//            var xmlPlanets = from planets in xelement.Elements("planets") select planets;


            Console.WriteLine("=============== Loading XML data ===================");

            //CONFIG
            foreach (var xConfig in xelement.Descendants("config"))
            {
                a_game.UpdateRes(a_game, Convert.ToInt32(xConfig.Element("screenX").Value), Convert.ToInt32(xConfig.Element("screenY").Value));

                Actor bg = new Actor();

                bg.Init(a_game, a_sb, CLASSID.CLASSID_BACKGROUND);

                //bg.m_spritesBackground.Add(a_game.Content.Load<Texture2D>(xConfig.Element("backgroundSprite").Value));
                List<Texture2D> texture = new List<Texture2D>();
                texture.Add(a_game.Content.Load<Texture2D>(xConfig.Element("backgroundSprite").Value));

                bg.m_spriteManager.Cmd(SpriteManager.SpriteCommands.PUSH, "background", texture, Convert.ToInt32(xConfig.Element("frameCount").Value),
                    Convert.ToInt32(xConfig.Element("frameWidth").Value), 0, Convert.ToInt32(xConfig.Element("frameHeight").Value), Convert.ToSingle((xConfig.Element("animSpeed").Value)));


                bg.m_pos = new Vector2(Convert.ToInt32(xConfig.Element("bgX").Value), Convert.ToInt32(xConfig.Element("bgY").Value));

                bg.m_classID = CLASSID.CLASSID_BACKGROUND;

                a_list.Add(bg);

                m_firstState = xConfig.Element("firstGameScreen").Value;
                if (m_firstState == "splash")
                {
                    foreach (var xSprite in xConfig.Descendants("splashSprite"))
                    {
                        Actor splash = new Actor();

                        splash.Init(a_game, a_sb, CLASSID.CLASSID_BACKGROUND);

                        splash.m_pos = new Vector2(0, 0);

                        List<Texture2D> Splashtexture = new List<Texture2D>();
                        Splashtexture.Add(a_game.Content.Load<Texture2D>(xSprite.Value));

                        splash.m_spriteManager.Cmd(SpriteManager.SpriteCommands.PUSH, "splash", Splashtexture, Convert.ToInt32(xConfig.Element("frameCount").Value),
                                            Convert.ToInt32(xConfig.Element("frameWidth").Value), 0, Convert.ToInt32(xConfig.Element("frameHeight").Value), Convert.ToSingle((xConfig.Element("animSpeed").Value)));


                        splash.m_classID = CLASSID.CLASSID_BACKGROUND;

                        a_splashList.Add(splash);
                    }
                }
            }

            //================= building player
            Player player = new Player();

            foreach (var xPlayer in xelement.Descendants("player"))
            {
                Console.WriteLine(xPlayer);

                //================================================================================
                //================ PLAYER CONFIG
                //================================================================================
                //There can only be only be one player
  

                player.Init(a_game, a_sb, CLASSID.CLASSID_PLAYER);  //don't edit this line

                //set the player x and y start position
                //0,0 is top left
                //This is the actual starting position from the centre of the player
                player.m_pos = new Vector2(Convert.ToInt32(xPlayer.Element("posX").Value), Convert.ToInt32(xPlayer.Element("posY").Value));

                float test = Convert.ToSingle(xPlayer.Element("scale").Value);

                //set the players local scale
                player.m_scale = test;

                //put an f at the end
                player.m_mass = Convert.ToSingle(xPlayer.Element("mass").Value);
                player.m_friction = Convert.ToSingle(xPlayer.Element("friction").Value);

                //sprite texture to load
//                player.m_sprite = a_game.Content.Load<Texture2D>(xPlayer.Element("sprite").Value);

                            //=================== building player srpites
                foreach (var xSprite in xPlayer.Descendants("sprite"))
                {
                    //player.m_spritesMain.Add(a_game.Content.Load<Texture2D>(xSprite.Value));
                    List<Texture2D> texture = new List<Texture2D>();
                    texture.Add(a_game.Content.Load<Texture2D>(xSprite.Value));
                    player.m_spriteManager.Cmd(SpriteManager.SpriteCommands.PUSH, "player", texture, Convert.ToInt32(xPlayer.Element("idleCount").Value),
                        Convert.ToInt32(xPlayer.Element("frameWidth").Value), Convert.ToInt32(xPlayer.Element("idleStartCol").Value), Convert.ToInt32(xPlayer.Element("idleStartRow").Value),
                        Convert.ToInt32(xPlayer.Element("frameHeight").Value), Convert.ToSingle(xPlayer.Element("animSpeed").Value), 
                        "idle");
                    player.m_spriteManager.Cmd(SpriteManager.SpriteCommands.PUSH, "player", texture, Convert.ToInt32(xPlayer.Element("runCount").Value),
                        Convert.ToInt32(xPlayer.Element("frameWidth").Value), Convert.ToInt32(xPlayer.Element("runStartCol").Value), Convert.ToInt32(xPlayer.Element("runStartRow").Value), 
                        Convert.ToInt32(xPlayer.Element("frameHeight").Value), Convert.ToSingle(xPlayer.Element("animSpeed").Value), 
                        "run");



                    //Jumping states
                    //jump start
                    player.m_spriteManager.Cmd(SpriteManager.SpriteCommands.PUSH, "player", texture, Convert.ToInt32(xPlayer.Element("jumpStartCount").Value),
                        Convert.ToInt32(xPlayer.Element("frameWidth").Value), Convert.ToInt32(xPlayer.Element("jumpStartCol").Value), Convert.ToInt32(xPlayer.Element("jumpStartRow").Value),
                        Convert.ToInt32(xPlayer.Element("frameHeight").Value), Convert.ToSingle(xPlayer.Element("animSpeed").Value),
                        "start");
                    //jump loop
                    player.m_spriteManager.Cmd(SpriteManager.SpriteCommands.PUSH, "player", texture, Convert.ToInt32(xPlayer.Element("jumpLoopCount").Value),
                        Convert.ToInt32(xPlayer.Element("frameWidth").Value), Convert.ToInt32(xPlayer.Element("jumpLoopCol").Value), Convert.ToInt32(xPlayer.Element("jumpLoopRow").Value),
                        Convert.ToInt32(xPlayer.Element("frameHeight").Value), Convert.ToSingle(xPlayer.Element("animSpeed").Value),
                        "loop");
                    //jump end
                    player.m_spriteManager.Cmd(SpriteManager.SpriteCommands.PUSH, "player", texture, Convert.ToInt32(xPlayer.Element("jumpEndCount").Value),
                        Convert.ToInt32(xPlayer.Element("frameWidth").Value), Convert.ToInt32(xPlayer.Element("jumpEndCol").Value), Convert.ToInt32(xPlayer.Element("jumpEndRow").Value),
                        Convert.ToInt32(xPlayer.Element("frameHeight").Value), Convert.ToSingle(xPlayer.Element("animSpeed").Value),
                        "end");



                    player.m_spriteManager.Cmd(SpriteManager.SpriteCommands.SWITCH,"player", "idle");   //set the initial state to idle
                }


                //center of the image, adjust as needed
                player.m_centre = new Vector2(Convert.ToSingle((xPlayer.Element("centreX").Value)), Convert.ToSingle(xPlayer.Element("centreY").Value));
                

                player.m_spaceMoveSpeed = Convert.ToInt32(xPlayer.Element("spaceMoveSpeed").Value);
                player.m_planetMoveSpeed = Convert.ToInt32(xPlayer.Element("planetMoveSpeed").Value);
                player.m_jumpSpeed = Convert.ToInt32(xPlayer.Element("jumpSpeed").Value);

                //draw the collision circle around the player
                player.m_drawCollision = Convert.ToBoolean(xPlayer.Element("drawCollision").Value);

                player.m_width = Convert.ToSingle(xPlayer.Element("width").Value);
                player.m_height = Convert.ToSingle(xPlayer.Element("height").Value);

                //set the radius of the player
                //default is to get the radius based on texture
                player.m_radius = player.GetRadius(player.m_width, player.m_height);

                //add the player to the main game loop
                a_list.Add(player);
                //=====================================
            }



            //=================== building planets
            foreach (var xPlanet in xelement.Descendants("planet"))
            {
                Console.WriteLine(xPlanet);

                //start creating planet one       
                Planet planet1 = new Planet();

                //TODO - split planet based on type
                planet1.Init(a_game, a_sb, CLASSID.CLASSID_PLANETSPHERE);

                //position
                planet1.m_pos = new Vector2( Convert.ToInt32( xPlanet.Element("posX").Value),  Convert.ToInt32( xPlanet.Element("posY").Value));
                planet1.m_centre = new Vector2(Convert.ToInt32(xPlanet.Element("centreX").Value), Convert.ToInt32(xPlanet.Element("centreY").Value));
                planet1.m_planetGravity = Convert.ToInt32(xPlanet.Element("gravity").Value);

                planet1.m_scale = Convert.ToSingle(xPlanet.Element("scale").Value);

                //radius of the planet for collisions
                planet1.m_radius = Convert.ToSingle(xPlanet.Element("collisionRadius").Value);
                //radius of the planet for detecting gravity effect on the player
                planet1.m_effectiveRadius = Convert.ToSingle(xPlanet.Element("effectiveRadius").Value);
                //draw the effective radius
                planet1.m_drawEfftiveRadius = Convert.ToBoolean(xPlanet.Element("drawCollision").Value);

                //draw the collision circle (good way to see radius)
                planet1.m_drawCollision = Convert.ToBoolean(xPlanet.Element("drawEffective").Value);

                //laod planet sprite
                //planet1.m_sprite = a_game.Content.Load<Texture2D>(xPlanet.Element("sprite").Value);
                
                //add main sprite
                foreach (var xSprite in xPlanet.Descendants("planetSprite"))
                {
                    //Console.WriteLine(xSprite.Value);
                    //planet1.m_spritesMain.Add(a_game.Content.Load<Texture2D>(xSprite.Value));
                    List<Texture2D> texture = new List<Texture2D>();
                    texture.Add(a_game.Content.Load<Texture2D>(xSprite.Value));
                    planet1.m_spriteManager.Cmd(SpriteManager.SpriteCommands.PUSH, "main", texture, Convert.ToInt32(xPlanet.Element("frameCount").Value), Convert.ToInt32(xPlanet.Element("frameWidth").Value),
                        0 , Convert.ToInt32(xPlanet.Element("frameHeight").Value), Convert.ToSingle(xPlanet.Element("animSpeed").Value));
                }

                //add behind sprite elements
                foreach (var xSprite in xPlanet.Descendants("behindSprite"))
                {
                    //Console.WriteLine(xSprite.Value);
                    //planet1.m_spritesBehind.Add(a_game.Content.Load<Texture2D>(xSprite.Value));
                    List<Texture2D> texture = new List<Texture2D>();
                    texture.Add(a_game.Content.Load<Texture2D>(xSprite.Value));
                    planet1.m_spriteManager.Cmd(SpriteManager.SpriteCommands.PUSH, "behind", texture, Convert.ToInt32(xPlanet.Element("frameCount").Value), Convert.ToInt32(xPlanet.Element("frameWidth").Value),
                        0 , Convert.ToInt32(xPlanet.Element("frameHeight").Value), Convert.ToSingle(xPlanet.Element("animSpeed").Value));

                }

                //add in front sprite elements
                foreach (var xSprite in xPlanet.Descendants("infrontSprite"))
                {
                    //Console.WriteLine(xSprite.Value);
                    //planet1.m_spritesInfront.Add(a_game.Content.Load<Texture2D>(xSprite.Value));
                    List<Texture2D> texture = new List<Texture2D>();
                    texture.Add(a_game.Content.Load<Texture2D>(xSprite.Value));
                    planet1.m_spriteManager.Cmd(SpriteManager.SpriteCommands.PUSH, "front", texture, Convert.ToInt32(xPlanet.Element("frameCount").Value), Convert.ToInt32(xPlanet.Element("frameWidth").Value), 
                        0, Convert.ToInt32(xPlanet.Element("frameHeight").Value), Convert.ToSingle(xPlanet.Element("animSpeed").Value));
                }                

                //add the planet to the list
                a_list.Add(planet1);


                //=================================================
                //set the first planet the player is attracted to, this can be any planet but it must be set 
                //TODO currently set to last planet added, change to be set via config
                player.m_curPlanet = planet1;
            }

            Console.WriteLine("============== End xml data ==============");

        }
Exemplo n.º 6
0
        public virtual void IsCollidingGravityWell(Actor a_colActor)
        {

        }
Exemplo n.º 7
0
        /// <summary>
        /// called by the collision detector, up to child actors to do anything with collisions
        /// used for main planet collisions
        /// </summary>
        /// <param name="a_colActor">colliding actor</param>
        public virtual void IsColliding(Actor a_colActor)
        {

        }
Exemplo n.º 8
0
        public override void IsColliding(Actor a_colActor)
        {
            base.IsColliding(a_colActor);

            
            //get intersecting length
//            float r1 = GetRadius(m_sprite.Width, m_sprite.Height);
//            float r2 = GetRadius(a_colActor.m_sprite.Width, a_colActor.m_sprite.Height);
//
//            float length = (m_pos - a_colActor.m_pos).Length();
//
//            float distance = Math.Abs(length - (r1 + r2));
//
//            Vector2 reverseHeading = new Vector2(0,0);
//
//            if (m_gravHeading.X > 0)
//                reverseHeading.X = -m_gravHeading.X;
//
//            if (m_gravHeading.X < 0)
//                reverseHeading.X = Math.Abs(m_gravHeading.X);
//
//            if (m_gravHeading.Y > 0)
//                reverseHeading.Y = -m_gravHeading.Y;
//
//            if (m_gravHeading.Y < 0)
//                reverseHeading.Y = Math.Abs(m_gravHeading.Y);
//
//            Vector2 offset = reverseHeading * distance;
//
//            m_pos += offset;
            if (!m_hasCollided && a_colActor == m_curPlanet)
            {
                //initial velocity
                Vector2 Vi = m_gravityVelocity;
                //collision normal
                Vector2 N = new Vector2(-Vi.Y, Vi.X);
                N.Normalize();

                //negative magnitude of P
                float magP = -Vector2.Dot(Vi, N);

                Vector2 P = N * magP;

                P = -P;

                Vector2 Vf = 2 * P + Vi;
                Vf = -Vf;

                m_hasCollided = true;

                m_pos += Vf;

                m_newPlanet = false;

                m_killUpVelocity = false;
                
                //m_game.updateCamera(m_curPlanet.m_pos); //update the cameras position

            }
            //Console.WriteLine(Vf);
            //Console.WriteLine(m_gravityVelocity);
        }
Exemplo n.º 9
0
        public override void IsCollidingGravityWell(Actor a_colActor)
        {
            base.IsCollidingGravityWell(a_colActor);

            if ((Planet)a_colActor != m_curPlanet && !m_newPlanet && !m_hasCollided)
            {
                //Console.WriteLine("switching planet");

                m_game.m_score++;

                m_curPlanet = (Planet)a_colActor;

                m_newPlanet = true;

                m_killUpVelocity = true;

            }
            //Console.WriteLine("colliding with gravity! \n");

        }