Original Post
I''m using someone else''s engine to make a very simple 2D game. I''m starting out by making the user move around using the keyboard. Unfortunately, the character has no boundaries --- it can exit the screen. I tried setting limits using the ''if'' statement, but the boundaries only work on the top and left side of the screen --- the user can still move past the right and bottom screen ends.
Here''s what I have (remember, i''m calling functions from someone else''s engine)
//user movement
down.draw(x,y);
if (m_key.keyDown(DIK_UP)) {
y-=2;
up.draw(x,y);
} else if (m_key.keyDown(DIK_DOWN)) {
y+=2;
down.draw(x,y);
} else if (m_key.keyDown(DIK_RIGHT)) {
x+=2;
right.draw(x,y);
} else if (m_key.keyDown(DIK_LEFT)) {
x-=2;
left.draw(x,y);
}
//...
//wall boundaries
if (x > HORIZ_RES || x < 0) {
x = -x;
} else if (y > VERT_RES || y < 0) {
y = -y;
}
//HORIZ_RES and VERT_RES are the #defines for screen size
//x and y are the user''s current position.
I know you can''t see the whole code, but do anyone know of possible reasons that this doesn''t work completely?
lemonstix