Man, it's photobucket, filtering software is retarded (are you at school or something?). Okay, I don't think this is appropriate to make a new thread for, because it's a really bad question, and I don't actually want someone to help me unless they are really bored. Just look at all this as me thinking aloud unless your heart compells you to actually look at this.
Here is what I thought my problem was: I thought that maybe somewhere, an object is being copied, instead of being assigned a reference. But it does appear that s.find returns a reference to a Thingy inside the vector (made known by alerting the value of the reference, and of 'this'), so I don't think this is the problem any more. So, let me explain a little.
Okay, I have this, it detects whether you pressed an arrow key, and moves an object on the 'screen'. My 'screen' has a vector of things which all have ID values, which I can retrieve them by (throws exception if ID is not found). Each object has a method to move them in a direction. After I move them, I update the 'screen' (which adds the now changed object back to the screen grid) and then re paint the window.
Code:
case WM_KEYDOWN:
try
{
Thingy & t = s.find(CIRCLE_ID);
switch(wParam)
{
case VK_UP: t.move(Thingy::up); break;
case VK_RIGHT: t.move(Thingy::right); break;
case VK_LEFT: t.move(Thingy::left); break;
case VK_DOWN: t.move(Thingy::down); break;
}
s.update();
::UpdateWindow(hwnd);
}
catch(std::exception & e)
{
ErrorMessage(_T("Error: %s"), e.what());
}
break;
Here is how update is implemented, I'll figure out optimizing these methods later.
Code:
void Screen::update()
{
for(int _i = 0; _i < _x; ++_i)
for(int _j = 0; _j < _y; ++_j)
scr[_i][_j] = RGB(0, 0, 0);
for(std::vector<Thingy>::iterator i = v.begin(); i != v.end(); ++i)
for(std::vector<Pixel>::iterator j = i->coords.begin(); j != i->coords.end(); ++j)
scr[j->c.x][j->c.y] = j->cr;
}
'scr' is a 2-D grid of COLORREF values. 'v' is an std::vector<Thingy> of the things stored on the screen. 'coords' is an std::vector<Pixel> which is a set of Pixels in the Thingy. Here is how some less important methods are implemented Screen::find, Thingy::move
Code:
Thingy & Screen::find(int id)
{
for(std::vector<Thingy>::iterator i = v.begin(); i != v.end(); ++i)
{
if(i->getId() == id)
{
return *i;
}
}
throw std::exception("id not found");
}
Code:
void Thingy::move(direction d)
{
int x = 0, y = 0;
switch(d)
{
case up: y = -1;
case down: y = 1;
case left: x = -1;
case right: x = 1;
}
for(std::vector<Pixel>::iterator i = coords.begin(); i != coords.end(); ++i)
{
i->c.x += x;
i->c.y += y;
}
}
I can not see why it is not working now. The thingy on the screen displays fine, but I can not get it to move!