Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualpovilaslt2

Posted 15 December 2012 - 01:14 PM

Hello, i thinking about complete tilemap game, but i have one problem. Problem is with collision, i can't make normal collision for my game, here's the code:

			for (int x = 0; x < tilemap.GetLength(1); x++)
			{
				for (int y = 0; y < tilemap.GetLength(0); y++)
				{
					if (tilemap[y, x] == -1) continue;
					if (man.Position.Y > (y * TextureHeight) - TextureHeight &amp;&amp; man.Position.Y < y * TextureHeight)
						tilesaty.Add(new Vector2(x * 40, y * 40));
				}
			}

			    foreach (Vector2 pos in tilesaty)
			    {
				    Rectangle rect = new Rectangle((int)pos.X, (int)pos.Y, TextureWidth, TextureHeight);
				    Rectangle rect2 = new Rectangle((int)man.Position.X, (int)man.Position.Y, (int)(man.mSpriteTexture.Width * man.Scale), (int)(man.mSpriteTexture.Height * man.Scale));
				    if (rect2.Right >= rect.Right &amp;&amp; rect2.Left < rect.Right)
					    man.Position.X -= 1;
			    }

#2povilaslt2

Posted 15 December 2012 - 01:14 PM

Hello, i thinking about complete tilemap game, but i have one problem. Problem is with collision, i can't make normal collision for my game, here's the code:

			for (int x = 0; x < tilemap.GetLength(1); x++)
			{
				for (int y = 0; y < tilemap.GetLength(0); y++)
				{
					if (tilemap[y, x] == -1) continue;
					if (man.Position.Y > (y * TextureHeight) - TextureHeight &amp;&amp; man.Position.Y < y * TextureHeight)
						tilesaty.Add(new Vector2(x * 40, y * 40));
				}
			}

			    foreach (Vector2 pos in tilesaty)
			    {
				    Rectangle rect = new Rectangle((int)pos.X, (int)pos.Y, TextureWidth, TextureHeight);
				    Rectangle rect2 = new Rectangle((int)man.Position.X, (int)man.Position.Y, (int)(man.mSpriteTexture.Width * man.Scale), (int)(man.mSpriteTexture.Height * man.Scale));
				    if (rect2.Right >= rect.Right &amp;&amp; rect2.Left < rect.Right)
					    man.Position.X -= 1;
			    }

#1povilaslt2

Posted 15 December 2012 - 01:13 PM

Hello, i thinking about complete tilemap game, but i have one problem. Problem is with collison, i can't make normal collision for my game, here's the code:

			for (int x = 0; x < tilemap.GetLength(1); x++)
			{
				for (int y = 0; y < tilemap.GetLength(0); y++)
				{
					if (tilemap[y, x] == -1) continue;
					if (man.Position.Y > (y * TextureHeight) - TextureHeight && man.Position.Y < y * TextureHeight)
						tilesaty.Add(new Vector2(x * 40, y * 40));
				}
			}

			    foreach (Vector2 pos in tilesaty)
			    {
				    Rectangle rect = new Rectangle((int)pos.X, (int)pos.Y, TextureWidth, TextureHeight);
				    Rectangle rect2 = new Rectangle((int)man.Position.X, (int)man.Position.Y, (int)(man.mSpriteTexture.Width * man.Scale), (int)(man.mSpriteTexture.Height * man.Scale));
				    if (rect2.Right >= rect.Right && rect2.Left < rect.Right)
					    man.Position.X -= 1;
			    }

PARTNERS