Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Kaandimandimanbopbobop

Member Since 17 May 2012
Offline Last Active Jun 12 2012 03:03 PM

Topics I've Started

Farseer Physics Movement XNA

12 June 2012 - 02:36 PM

Hey. I am working on a 2D Terraria-Like game, and I needed some help with the movement. To handle both collisions and physics, I am using the Farseer Physics Engine. I have two questions, which are probably quite simple.

1. How can I make my character stop moving once the movement keys are released. With the code below, the character still continues to roll:

[source lang="java"]if(k.IsKeyDown(Keys.Left)) { circleBody.ApplyTorque(-1000); } else if (k.IsKeyDown(Keys.Right)) { circleBody.ApplyTorque(1000); }[/source]
2. Can I make the character not bounce at all after colliding with a platform? I have set the RestitutionCoefficient to 0, but it still bounces a very small amount.

3. Is there a way to prevent the character from rotating its texture?

Thanks for the help

Simple ListView Inventory Question

03 June 2012 - 06:38 PM

Hi, for my game in XNA, I decided to use a Windows Form as the inventory interface. On the Form, I added a ListView item. So far it is working well, but now that I want to add quantities of items, it is not going to work. How can I set it so that the list of items in the ListView are my own custom objects (I have an Item class). If I could find a way to implement this, I think it would be much easier. All help would be appreciated :)

XNA Enemy AI Help

27 May 2012 - 01:40 PM

Hi. I am working on an enemy class in my tile-based 2d rpg game in xna, and I am having difficulty with the AI. I attempted to make my own custom method; It works sometimes but not always. Right now, I am testing it on a simple map with a river running through it and a bridge. When my player's X position is the same as the bridge's, the enemy is able to reach me. When it is not, the enemy simply walks towards the river until it can't move anymore (enemy's can't enter water). By the way, the enemy and the player are on opposite sides of the river. Before trying this method, I looked into the A* method. Unfortunately, I am only in 8th grade, so it is a bit too confusing for me. Could you please try to modify or explain to me why my code is not working. I do understand why it is not working, but do not understand how to fix the problem.

Here is the AI Method.:

public void Move()
		{
			if (movetimer > 0)
			{
				movetimer--;
			}
		  
				if (movetimer == 0)
				{
					int TargetX;
					int TargetY;

					List<Vector2> possibleTiles = new List<Vector2>();
					List<Vector2> movableTiles = new List<Vector2>();
					List<Vector2> movableDesiredTiles = new List<Vector2>();
					if (X < Main.map.grid.GetLength(1))
					{
						possibleTiles.Add(new Vector2(X + 1, Y));
					}
					possibleTiles.Add(new Vector2(X, Y + 1));
					if (X > 0)
					{
						possibleTiles.Add(new Vector2(X - 1, Y));
					}
					possibleTiles.Add(new Vector2(X, Y - 1));

					foreach (Vector2 tile in possibleTiles)
					{
						if (tile.X < Main.map.grid.GetLength(1) && tile.Y < Main.map.grid.GetLength(0))
						{
							if (Main.map.grid[(int)tile.Y, (int)tile.X] != 2)
							{
								movableTiles.Add(new Vector2(tile.X, tile.Y));
							}
						}
					}

					foreach (Vector2 tile in movableTiles)
					{
						if (Vector2.Distance(new Vector2(tile.X, tile.Y), new Vector2(Main.player.X, Main.player.Y)) < Vector2.Distance(new Vector2(X, Y), new Vector2(Main.player.X, Main.player.Y)))
						{
							movableDesiredTiles.Add(new Vector2(tile.X, tile.Y));
						}
					}
					if (movableDesiredTiles.Count > 0)
					{
						Vector2 mostDesiredTile = new Vector2(X, Y);
						int distanceX;
						int distanceY;
						int totalDistance = 100;
						foreach (Vector2 tile in movableDesiredTiles)
						{
							int specificDistance;
							distanceX = Main.player.X - X;
							if (distanceX < 0)
							{
								distanceX *= -1;
							}
							distanceY = Main.player.Y - Y;
							if (distanceY < 0)
							{
								distanceY *= -1;
							}
							specificDistance = distanceX + distanceY;
							if (specificDistance < totalDistance)
							{
								mostDesiredTile = new Vector2(tile.X, tile.Y);
								totalDistance = specificDistance;
							}
						}
						TargetX = (int)mostDesiredTile.X;
						TargetY = (int)mostDesiredTile.Y;
						X = TargetX;
						Y = TargetY;
					  
					  
					}

					movetimer = 60;
				}

XNA CS File Goes Wrong Over Night

25 May 2012 - 02:53 PM

Hello. Yesterday, I was working on a game in xna. I got everything to work, and then saved it for the night. Now, I wake up to find that all the classes are fine except for one. Instead of having my code, it has this text in it:

  O¿PKO¿PKOÑÅK
c HTTP:https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/372683_100002489225494_1119274177_q.jpg request-method GET response-head HTTP/1.1 200 OK
Content-Type: image/jpeg
Content-Length: 2592
X-Backend: hs1433.ash4
X-Blockid: 372683
Last-Modified: Fri, 01 Jan 2010 00:00:00 GMT
Access-Control-Allow-Origin: *
Cache-Control: max-age=1209600
Expires: Fri, 08 Jun 2012 09:26:44 GMT
Date: Fri, 25 May 2012 09:26:44 GMT
security-info FnhllAKWRHGAlo+ESXykKAAAAAAAAAAAwAAAAAAAAEaphjojJrhKnIPx6drbNrgwAWYKMiaRXE/7uyCJhaYy3wUAAAAAAAAAAMAAAAAAAABGAAADdjCCA3IwggLboAMCAQICBAcnf00wDQYJKoZIhvcNAQEFBQAwdTELMAkGA1UEBhMCVVMxGDAWBgNVBAoTD0dURSBDb3Jwb3JhdGlvbjEnMCUGA1UECxMeR1RFIEN5YmVyVHJ1c3QgU29sdXRpb25zLCBJbmMuMSMwIQYDVQQDExpHVEUgQ3liZXJUcnVzdCBHbG9iYWwgUm9vdDAeFw0xMTA5MDExODI2MTFaFw0xMjA4MzExODIzNTZaME0xCzAJBgNVBAYTAlVTMSIwIAYDVQQKExlBa2FtYWkgVGVjaG5vbG9naWVzLCBJbmMuMRowGAYDVQQDExFhMjQ4LmUuYWthbWFpLm5ldDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAtAE08ZCuvkgGb5E3FMMQVuiqcsQgM4RN2SSM4PhQcQ6mWdAAqUGFmCFJE+K3QNlnd0DlNlm8tMvRlipik3NT8aiEBBCv0pkLAadUsz38GkA4vmbe6DLJdhXZCXHWHh19gAeR1C70FTNQL4ssMEU25ONP+C2nE3T0g3qSB6GXuhcCAwEAAaOCATUwggExMAkGA1UdEwQCMAAwRAYDVR0RBD0wO4IRYTI0OC5lLmFrYW1haS5uZXSCDiouYWthbWFpaGQubmV0ghYqLmFrYW1haWhkLXN0YWdpbmcubmV0MAsGA1UdDwQEAwIFIDCBiQYDVR0jBIGBMH+heaR3MHUxC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Izg+FBxDqZZ0ACpQYWYIUkT4rdA2Wd3QOU2Wby0y9GWKmKTc1PxqIQEEK/SmQsBp1SzPfwaQDi+Zt7oMsl2FdkJcdYeHX2AB5HULvQVM1AviywwRTbk40/4LacTdPSDepIHoZe6FwIDAQABo4IBNTCCATEwCQYDVR0TBAIwADBEBgNVHREEPTA7ghFhMjQ4LmUuYWthbWFpLm5ldIIOKi5ha2FtYWloZC5uZXSCFiouYWthbWFpaGQtc3RhZ2luZy5uZXQwCwYDVR0PBAQDAgUgMIGJBgNVHSMEgYEwf6F5pHcwdTELMAkGA1UEBhMCVVMxGDAWBgNVBAoTD0dURSBDb3Jwb3JhdGlvbjEnMCUGA1UECxMeR1RFIEN5YmVyVHJ1c3QgU29sdXRpb25zLCBJbmMuMSMwIQYDVQQDExpHVEUgQ3liZXJUcnVzdCBHbG9iYWwgUm9vdIICAaUwRQYDVR0fBD4wPDA6oDigNoY0aHR0cDovL3d3dy5wdWJsaWMtdHJ1c3QuY29tL2NnaS1iaW4vQ1JMLzIwMTgvY2RwLmNybDANBgkqhkiG9w0BAQUFAAOBgQA9imYX9omKH9mL9XXYVdddeOPh/1+CYf1iStzxBzGtuc37XMxJKBnUR4FJwSynjC0/gmMzL8N00k55IuFdNS7ITbhrQoa7Ks7AYWGUdSuFW6yl4UNNpKHrAJffY5YLCOGAzI4gVZ9ruS6GNPbDOLEa3ffDo9KxowhdupaghD6kvwAAAQAAAAEAAAAAB0FFUy0yNTYAAAABAAAAAAAAAAAAAAAAAAAAAAA= atic void Draw(SpriteBatch spriteBatch)
{
int itemY = 70;
if (open == true)
{
//INVENTORY
spriteBatch.DrawString(Globals.font, "Inventory", new Vector2(90, 25), Color.Red);
spriteBatch.Draw(background, new Rectangle(90, 50, 280 , 360), Color.White);
spriteBatch.Draw(outline, new Rectangle(90, 50, 280, 360), Color.Yellow);

spriteBatch.DrawString(Globals.font, "Press 'D' to De  €  O¿PKO¿dOÑ‘d O ^ ÿHTTP:https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash2/373114_21295715752_917005752_s.jpg request-method GET response-head HTTP/1.1 200 OK
Content-Type: image/jpeg
Content-Length: 6991
X-Backend: hs811.ash4
X-Blockid: 373114
Last-Modified: Fri, 01 Jan 2010 00:00:00 GMT
Access-Control-Allow-Origin: *
Cache-Control: max-age=1209600
Expires: Fri, 08 Jun 2012 05:45:17 GMT
Date: Fri, 25 May 2012 05:45:17 GMT
security-info FnhllAKWRHGAlo+ESXykKAAAAAAAAAAAwAAAAAAAAEaphjojJrhKnIPx6drbNrgwAWYKMiaRXE/7uyCJhaYy3wUAAAAAAAAAAMAAAAAAAABGAAADdjCCA3IwggLboAMCAQICBAcnf00wDQYJKoZIhvcNAQEFBQAwdTELMAkGA1UEBhMCVVMxGDAWBgNVBAoTD0dURSBDb3Jwb3JhdGlvbjEnMCUGA1UECxMeR1RFIEN5YmVyVHJ1c3QgU29sdXRpb25zLCBJbmMuMSMwIQYDVQQDExpHVEUgQ3liZXJUcnVzdCBHbG9iYWwgUm9vdDAeFw0xMTA5MDExODI2MTFaFw0xMjA4MzExODIzNTZaME0xCzAJBgNVBAYTAlVTMSIwIAYDVQQKExlBa2FtYWkgVGVjaG5vbG9naWVzLCBJbmMuMRowGAYDVQQDExFhMjQ4LmUuYWthbWFpLm5ldDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAtAE08ZCuvkgGb5E3FMMQVuiqcsQgM4RN2SSM4PhQcQ6mWdAAqUGFmCFJE+K3QNlnd0DlNlm8tMvRlipik3NT8aiEBBCv0pkLAadUsz38GkA4vmbe6DLJdhXZCXHWHh19gAeR1C70FTNQL4ssMEU25ONP+C2nE3T0g3qSB6GXuhcCAwEAAaOCATUwggExMAkGA1UdEwQCMAAwRAYDVR0RBD0wO4IRYTI0OC5lLmFrYW1haS5uZXSCDiouYWthbWFpaGQubmV0ghYqLmFrYW1haWhkLXN0YWdpbmcubmV0MAsGA1UdDwQEAwIFIDCBiQYDVR0jBIGBMH+heaR3MHUxCzAJBgNVBAYTAlVTMRgwFgYDVQQKEw9HVEUgQ29ycG9yYXRpb24xJzAlBgNVBAsTHkdURSBDeWJlclRydXN0IFNvbHV0aW9ucywgSW5jLjEjMCEGA1UEAxMaR1RFIEN5YmVyVHJ1c3QgR2xvYmFsIFJvb3SCAgGlMEUGA1UdHwQ+MDwwOqA4oDaGNGh0dHA6Ly93d3cucHVibGljLXRy

Part of my code is in there, but where is everything else? Is there a way to retrieve the code, because I really dont want to restart. All help would be EXTREMELY appreciated.

XML simple loading problem

24 May 2012 - 07:31 PM

Hello. I am trying to create items for my game by putting their settings in an xml file, but I am having no help. I have had little previous experience with xml, so my mistake is probably a very simple one. To load the settings, I use the Load() method in my Item class. I have added the xml file to my game's content, but it is still not working.

The error is:

Error 1 There was an error while deserializing intermediate XML. 'Element' is an invalid XmlNodeType. Line 6, position 4.

Here is the Item Class:


using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using System.Xml;
using Microsoft.Xna.Framework;


namespace RPG
{
	class Item
	{

		protected string assetName;
		protected string description;
		protected Texture2D graphicIcon;
		protected int goldValue;
		protected bool dropable;


		public void Load(string asset)
		{
			XmlDocument doc = new XmlDocument();
			doc.Load(@"Content/Items/" + asset + ".xml");

			foreach (XmlNode root in doc.ChildNodes)
			{
				foreach (XmlNode node in root.ChildNodes)
				{
					if (node.Name == "Asset")
						assetName = node.InnerText;

					if (node.Name == "Description")
						description = node.InnerText;

					if (node.Name == "GraphicIcon")
						graphicIcon = LoadTexture(node.InnerText);

					if (node.Name == "GoldValue")
						goldValue = int.Parse(node.InnerText);

					if (node.Name == "Dropable")
						dropable = bool.Parse(node.InnerText);

				}//end child nodes
			}

		}

		protected Texture2D LoadTexture(string asset)
		{
			return Globals.Content.Load<Texture2D>("" + asset);
		}
	}
}


and XML code:

<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
  <!-- TODO: replace this Asset with your own XML asset data. -->
  <Asset Type="System.String"></Asset>

  <Item>
  
  <Asset>BronzeBand</Asset>
  <Description>This worn ring looks rusted</Description>
  <GoldValue>1</GoldValue>
  <Dropable>true</Dropable>
  

</Item>


</XnaContent>

PARTNERS