Reputation: 1065
i have problem with doing game 2D
now till now i did: create Player + map + Keyboard+ mouse now i am doing the collision with the Player and the map
and i try that if the Player though One or more blocks with that code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.Windows.Forms;
class UpdateCollision
{
Player myPlayer;
Map myMap;
public void Initialize(Player myPlayer, Map myMap)
{
this.myPlayer = myPlayer;
this.myMap = myMap;
}
public void Update(GameTime gameTime)
{
// Use the Rectangle's built-in intersect function to
// determine if two objects are overlapping
Rectangle Player;
Rectangle Block;
// Only create the rectangle once for the player
Player = new Rectangle((int)myPlayer.Position.X,
(int)myPlayer.Position.Y,
myPlayer.Width,
myPlayer.Height);
// Do the collision between the player and the Block
int i, j;
// For each block in the game
for (i = 0; i < myMap.Height / myMap.pictureSize; i++)
{
for (j = 0; j < myMap.Width / myMap.pictureSize; j++)
{
// If the block is Draw
if(myMap.Blocks[i, j].isAlive)
{
Block = new Rectangle((int)myMap.Blocks[i, j].X,
(int)myMap.Blocks[i, j].Y,
myMap.pictureSize,
myMap.pictureSize);
// Determine if the two objects collided with each
// other
if (Player.Intersects(Block))
{
MessageBox.Show(myMap.Blocks[i, j].X+ ","+myMap.Blocks[i, j].Y);
}
}
}
}
}
public void Draw (SpriteBatch spriteBatch)
{
}
}
and it never goes to message box even when it tough
image of the Meeting
Upvotes: 1
Views: 34
Reputation: 1065
@ Pierre-Luc Pineault thank you i played that
my mistake was the mistake in the Blocks class i set it the Y as X and the X as Y so all was upset now it worked
thank you
Upvotes: 2