Public Group

# 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.

## 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)
{

}


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

list<int> DataList;

{

list<int>::iterator curr = DataList.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;

}
}


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

DataList = GameData.Body();

DataList2 = GameData.RectLR();


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();

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;

}

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 on other sites
Any one know how to fix this issue?

##### Share on other sites
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 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?

1. 1
Rutin
34
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633334
• Total Posts
3011407
• ### Who's Online (See full list)

There are no registered users currently online

×