Jump to content
  • Advertisement
Sign in to follow this  
kingpinzs

Help with drawing function list and the game loop

This topic is 4312 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I think I will satep back wards through this issue to see if it is easyer to understand. This code draws my blcoks on to the screen
void Blocks_Map()
{
        for(list<SPRITE>::iterator i=Sprites.begin();i!=Sprites.end();++i)
        {

            D3DXVECTOR3 position(i->Pos.x,i->Pos.y,0);


        sprite_handler->Draw(
            blocks_image,
            &(i->Src),
            NULL,
            &position,
            D3DCOLOR_XRGB(255,255,255));
        }

}


This is the struct for SPRITE
typedef struct {
    int x,y;
    int width,height;
    int movex,movey;
    int curframe,lastframe;
    int animdelay,animcount;
    int scalex, scaley;
    int rotation, rotaterate;
    POINT Pos;
    RECT Src;
} SPRITE;

list<SPRITE> Sprites;



This creates the Points for me
POINT MakePoint(int X,int Y)
{
    POINT P; P.x=X; P.y=Y;

    return P;

}


This creates the Rect
RECT MakeRect(int Left, int Top, int Right, int Bottom)
{
    RECT r;
         r.left = Left;
         r.top= Top;
         r.right = Right;
         r.bottom = Bottom;


         return r;
        }



This adds it all to the list
void Add(POINT pos,RECT Src)
{

    paddle.Pos=pos;

    paddle.Src=Src;

    Sprites.push_back(paddle);


}


This function get the data from a preloaded list copys it so another list and runs through it to copy it to a third list that is above. which may be one of my issues and probubly can be avoided but I can figure outnhow yet.
//globel veribles
LoadData GameData;

list<int> DataList;
list<LoadData::RectX> DataList2;

LoadData::RectX MyRect;

void Add_Blocks()
{

        list<int>::iterator curr = DataList.begin();

        list<LoadData::RectX>::iterator curr2 = DataList2.begin();

        while(curr != DataList.end()&& curr2 !=DataList2.end())
        {
            // the position
           int PoX = *curr;
            ++curr;
           int PoY = *curr;
            ++curr;
           int  left = curr2->left;
           int   top =   curr2->top;
           int   right =   curr2->right;
           int   bottom =   curr2->bottom;
           ++curr2;

       Add(MakePoint(PoX,PoY),MakeRect(left,top,right, bottom));
       }
}


and the data gets inilized here
GameData.LoadConfig("image*.txt");

//loads position
DataList = GameData.Body();

//loads rect
DataList2 = GameData.RectLR();

Add_Blocks();


And the main issue is not drawing them because it draws my images just fine the big issue is when the ball hits the block it bounces off but I cant get the block to earse off the screen. This is for the collition detection
int Block_Colition()
{
    int top_x = ball.x + ball.width/2;
    int top_y = ball.y;

    int left_x = ball.x;
    int left_y = ball.y + ball.height/2;

    int right_x = ball.x + ball.width;
    int right_y = ball.y + ball.height/2;

    int bottom_x = ball.x + ball.width/2;
    int bottom_y = ball.y + ball.height;
    int PoX , PoY,left,top,right,bottom;


        list<int>::iterator curr = DataList.begin();

        list<LoadData::RectX>::iterator curr2 = DataList2.begin();

        while(curr != DataList.end()&& curr2 !=DataList2.end())
        {
            // the position
            PoX = *curr;
            ++curr;
            PoY = *curr;
            ++curr;
          left = curr2->left;
          top =   curr2->top;
          right =   curr2->right;
          bottom =   curr2->bottom;
         ++curr2;

            if (CPIR(top_x,top_y,MakePoint(PoX,PoY),MakeRect(left,top,right,bottom)))
            {
                // top = true;
                ball.y -= ball.movey;
                ball.movey *= -1;


    DataList2.erase( remove( DataList2.begin(), DataList2.end(),MyRect.makeRect( left, top, right,bottom) ), DataList2.end() );

--curr2;
--curr;
  Add(MakePoint(PoX,PoY),MakeRect(left,top,right, bottom));

            }

            if (CPIR(bottom_x,bottom_y,MakePoint(PoX,PoY),MakeRect(left,top,right,bottom)))
            {
                // bottom = true;
                ball.y -= ball.movey;
                ball.movey *= +1;
DataList2.erase( remove( DataList2.begin(), DataList2.end(),MyRect.makeRect( left, top, right, bottom ) ), DataList2.end() );


             }

            if (CPIR(left_x,left_y,MakePoint(PoX,PoY),MakeRect(left,top,right,bottom)))
            {
                //left = true;
                ball.x -= ball.movex;
                ball.movex *= +1;
                DataList2.erase( remove( DataList2.begin(), DataList2.end(),MyRect.makeRect( left, top, right, bottom ) ), DataList2.end() );


            }

            if (CPIR(right_x,right_y,MakePoint(PoX,PoY),MakeRect(left,top,right,bottom)))
            {
                // right = true;
                ball.x -= ball.movex;
                ball.movex *= -1;
                DataList2.erase( remove( DataList2.begin(), DataList2.end(),MyRect.makeRect( left, top, right, bottom ) ), DataList2.end() );


            }
        }
}


So can any one tell me how I can skip loading to a third list and just use to list the orginal and the one to draw from and second how to erase the blocks? [EDIT] For got to add that Blocks_Map(); and Block_Colition(); are called from the main loop

Share this post


Link to post
Share on other sites
Advertisement
This is odd. I got rid of the addBlock function from running but left by collition detection in place and draw block into place. were the blocks were supose to be it did not draw anything(which that is what is supose to happen) but when the ball got there it placed a block even though it should not do that. So some how the list earse function is adding to the list and not taking away from the list

Any one know why that would be?

Share this post


Link to post
Share on other sites
Looking over my code for the hunderth time and using the function D3DXSprite to draw my blocks.

sprite_handler->Draw(
blocks_image,
&(i->Src),
NULL,
&position,
D3DCOLOR_XRGB(255,255,255));

this is what I have learned how it works.

It first calls for the texture that I will be using then it grabs the "tiles" out of the source image the third peramter specifes the cnter point from which the rotaintion takes place, the fourth parameter specifes the position of the sprite and is typicaly your x and y values, the last perameter specifes the color alteration to be made on the sprite imageas it is drawn.

So if I am right all I realy have to do is get rid of the postion and not
the rect were it pulls it from the image.

Can any one tell me if my theroy is corret please?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!