Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Collisions and Reloading Textures

$
0
0
I'm currently working on my first game in XNA. I have a clear understanding of C# but I am still getting used to some minor things with XNA.

The first thing is how would I make simple "wall" collision between 2 entity's.
I already have an extremely simple collision class setup.
namespace Bruce
{
    class Collision 
    {
        public Rectangle collisionbox;
        public void Setcollision(int width, int height, Vector2 location)
        {
            collisionbox = new Rectangle((int)location.X, (int)location.Y, width, height);
            
        }
        
     
        
    }
}



I have also used this system to activate an event.
  public void Update(GameTime gametime, Char_Bruce bruce)
        {
            base.Update(gametime, Goatspeed, Goatdirection);
            UpdateMovement(bruce);
            UpdateStatus(bruce);
            if (base.collisionbox.collisionbox.Intersects(bruce.collisionbox.collisionbox))
            {
                bruce.IS_CALLING = true;
                
            }
       
            
      
        }


But I want to know, how would I use this to create a simple wall.

My second question is how I update the texture of a rectangle mid-game.
I have a class:
  class Load_sector
    {
        Texture2D background;
        Texture2D s00;
        Texture2D s10;
        
        int scale = 2;
        public Vector2 sector = new Vector2(0,0);
        Rectangle source;
        public string sectortexture;
        public void LoadSectorTextures(ContentManager content)
        {
            s00 = content.Load<Texture2D>("sector_test");
            s10 = content.Load<Texture2D>("test_bg");
        }
        public void LoadSector(ContentManager content)
        {
            
            if (sector.X == 0)
            {
                if (sector.Y == 0)
                {
                    Collision treeline = new Collision();
                    treeline.Setcollision(200,600,(new Vector2(400,0)));
                    background = s00;
                }
            }
            if (sector.X == 1)
            {
                if (sector.Y == 0)
                {
                    background = s10;
                }
            }
        }
        public void LoadContent(ContentManager contentmanager)
        {
            

        
            source = new Rectangle(0, 0, background.Width /* scale*/, background.Height /* scale*/);
        }
        

        public void UpdateSector()
        {
            if (sector.X == 0)
            {
                if (sector.Y == 0)
                {
                    sectortexture = "sector_test";
                }
            }
            if (sector.X == 1)
            {
                if (sector.Y == 0)
                {
                    sectortexture = "test_bg";
                }
            }
        }
        public void ChangeSector(Char_Bruce bruce, npc_Goat goat)
        {
            if (bruce.position.Y < 0)
            {
                sector.X = sector.X + 1;
                bruce.position.Y = background.Height - 50;
                goat.position.Y = background.Height - 50;
                
            }
        }
        public void Draw(SpriteBatch spritebatch, Char_Bruce bruce)
        {
            spritebatch.Draw(background, new Rectangle(0, 0, background.Width, background.Height), Color.White);
        }

    }

}


And I reference UpdateSector in the Update void of game1.cs. However I knew it wouldn't be that easy.

Thank you in advance for any help I may get.
I made a blog for friends and people who are interested in my groups first project "Bruce"
http://cameljivegames.blogspot.com.au/

Also sorry if this is annoying to read or I've done something wrong, first post.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>