Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6219013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:42:25+00:00 2026-05-24T07:42:25+00:00

I have searched for three days and didn’t find a solution, Here is the

  • 0

I have searched for three days and didn’t find a solution, Here is the code:

if (keyboardState.IsKeyDown(Keys.Right))
{
    for (int i = GlobalClass.BlocksPositions.Count - 1; i > 0; i--)
    {
        if (new Rectangle((int)GlobalClass.BlocksPositions[i].X, (int)GlobalClass.BlocksPositions[i].Y, bT.Width, bT.Height).Intersects(new Rectangle((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height)))
        {

            c = 0;
        }
        else
        {
            c = 1;
        }
    }

    if (c == 1)
    {
        Position.X += Speed;
    }

}

Each Block position equals a block that I can create by clicking on the screen, the new block position is then put in the List. Basically I have a list of blocks Coordinates in my BlockPosition List. Then I pass the condition for each blockposition, the Condition Create A rectangle for each BlockPosition and one for the Player… if there’s a collision, the player won’t move in that direction. When I try the code, My character will Collide only with the first element of the List and not the others, if I delete the first element it will then collide with the next one but not the others. All the variables are FINE I know it because I tried to replace this code by something like this:

if (keyboardState.IsKeyDown(Keys.Right))
{
    for (int i = GlobalClass.BlocksPositions.Count - 1; i > 0; i--)
    {
        if (new Rectangle((int)GlobalClass.BlocksPositions[i].X, (int)GlobalClass.BlocksPositions[i].Y, bT.Width, bT.Height).Intersects(new Rectangle((int)Position.X, (int)Position.Y, Texture.Width, Texture.Height)))
        {
            GlobalClass.BlocksPositions.RemoveAt[i];

        }
    }
}

Same thing but here if it collides I delete the Element of the List, it’s the same condition but when I try it it will detect all of the elements and delete the ones that I touch. I tried the foreach function and I get the same Results. What’s wrong? I already do a lot of things with does variables So I’m sure the problem don’t come from their values but with what I do with them. Help please! (:

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:42:26+00:00Added an answer on May 24, 2026 at 7:42 am

    For readability, consider something like this:

    if (GlobalClass.BlocksPositions.All(x => !DoesIntersect(Position, x))
         Position.X += speed;
    

    Not only is the purpose easier to deduce, but the particular mistake you made just doesn’t come up.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched the web for days now but I can't seem to find
How can I find the parameters of an undocumented Dll function? I have searched
I have searched around, and it seems that this is a limitation in MS
I have searched but apparently my google foo is weak. What I need is
I've have searched on this and it seems to be a catch all, unfortunately
I've searched for this a little but I have not gotten a particularly straight
I have searched for two weeks, every night, exhaustively reading forum threads and trying
I didn't find any info on searches when I looked this up. I've been
This problem has been kicking my butt for a few days now. I have
I'm currently using Eclipselink, but I know now days most JPA implementations have been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.