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