Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

XNA Game Help

Options
  • 13-03-2012 2:54pm
    #1
    Registered Users Posts: 183 ✭✭


    I was following Nick Gravelyn's Tile Engine tutorial series. I have created up to video 14. I am still relatively new to XNA. At the moment I have tried to put some objects within a level and I would like the player to collect them. However when they are collected I would like them to be removed from the game. How do I go about doing this? In an easy fashion. Anything I have added so far has been to the game class.

    Also how would I be able to get the enemies moving along between 2 waypoints. Is there an easy tutorial? I don;t want fancy movement, I just want to get things working. I have read through bit of 'Learning XNA4.0' also and it doesn't seem to help me.

    Would anyone be able to help me or point me in the correct direction?

    Here is my code so far.


Comments

  • Registered Users Posts: 11,979 ✭✭✭✭Giblet


    Lerping and Slerping will help with waypoints for simple movement. For collectible objects, you should probably just reference the collectibles in a list, and remove them from the list when your player collects them. (The update / draw calls read the list and render each item, so if you remove something from the list, they no longer update and draw).


  • Registered Users Posts: 183 ✭✭Fizzy Duck


    Thanks I will look into the lerping and slerping.

    From what I have done, I have the food added to a list. They are being rmeoved from the list, yet the score continues to add up and the texture won't dissappear from the screen. This is the code I have in an UpdateScore emthod that is being called by the Update method.
    private void UpdateScore()
            {
                foreach (Food food in foodList)
                {
                    if (sprite.BoundingBox.Intersects(food.BoundingBox))
                    {
    
                        for (int x = 0; x <= 0; x++)
                        {    
                            score += 10;
                        }
    
                        foodList.Remove(food);
                        break;
                    }
                }
            }
    


  • Registered Users Posts: 12,756 ✭✭✭✭Encrypted Pigeon


    Removing it from the list may not be enough, you may also need to remove it from Game component.
    Game.Components.Remove(food);
    


  • Registered Users Posts: 11,979 ✭✭✭✭Giblet


    Don't remove from a list you are currently iterating over either.
    Try a for(int i = 0; i<foodList.Count; i++) instead,
    or store the index of the food item to be removed and remove it after the loop.


  • Closed Accounts Posts: 5,482 ✭✭✭Kidchameleon


    For collecting items OP, I find the best way is when the player collides with them, simply move them off screen to some impossible to reach position, say x -500, y -500. When you are loading a new level you simply give them new positions.


  • Advertisement
  • Closed Accounts Posts: 5,482 ✭✭✭Kidchameleon


    For getting enemys to move and turn around I use two sprites that I dont draw and when the enemy collides with them they change direction.

    You can see both these techniques in my XNA platformer game:

    http://www.mediafire.com/?irb9rr1hzveb6yl

    Id be happy to send you the source also...


Advertisement