UPDATE! The code below has been changed to reflect how it looks after altering it per Chili's instructions in Lesson 8!
OK, so here is my code for lesson 8:
Code: Select all
// Start moving reticle code
int yTMove = 100; // Defines start of top Y line
int xRMove = 700; // Defines start of right X line
int yBMove = 500; // Defines start of bottom y line
int xLMove = 100; // Defines start of right x line
if(xPosMove == xLMove && yPosMove > 100)
{
yPosMove -= 2;
}
if(yPosMove == yBMove)
{
xPosMove -= 2;
}
if(xPosMove == xRMove)
{
yPosMove += 2;
}
if(yPosMove == yTMove)
{
xPosMove += 2;
}
gfx.PutPixel(xPosMove-5,yPosMove,red,green,blue);
gfx.PutPixel(xPosMove-4,yPosMove,red,green,blue);
gfx.PutPixel(xPosMove-3,yPosMove,red,green,blue);
gfx.PutPixel(xPosMove+3,yPosMove,red,green,blue);
gfx.PutPixel(xPosMove+4,yPosMove,red,green,blue);
gfx.PutPixel(xPosMove+5,yPosMove,red,green,blue);
gfx.PutPixel(xPosMove,yPosMove,red,green,blue);
gfx.PutPixel(xPosMove,yPosMove-5,red,green,blue);
gfx.PutPixel(xPosMove,yPosMove-4,red,green,blue);
gfx.PutPixel(xPosMove,yPosMove-3,red,green,blue);
gfx.PutPixel(xPosMove,yPosMove+3,red,green,blue);
gfx.PutPixel(xPosMove,yPosMove+4,red,green,blue);
gfx.PutPixel(xPosMove,yPosMove+5,red,green,blue);
// End moving reticle code
The problem is this code:
Code: Select all
if(yPosMove == yTMove)
{
xPosMove += 2;
}
Code: Select all
if(xPosMove < xRMove)
{
xPosMove += 2;
}
Also when I do this:
Code: Select all
if(xPosMove == yTMove)
{
xPosMove += 2;
}
I just don't understand why the first statement works and the others do not. Why do I have to increment xPosMove under the y position statements in order to get the reticle to move? Why wouldn't the reticle move under x statements instead? I didn't get very far into lesson 8, so perhaps Chili explains this, but I would really like to understand what's going on here.
I know its a logic error, an error in my thinking. That somehow my thought process, of getting the reticle to travel from point A to B along a certain axis, x for x and y for y, is wrong for some reason. I want to identify this error and correct my thinking. I want to get inside the head of the computer and see things from its perspective, in a way I can understand it. Could someone help me out here?
Thanks!