Page 1 of 1

How can I program the reticle to turn red for the y coordinates?

Posted: August 4th, 2019, 6:00 am
by TheCollector
I coded the x coordinates like this and it works:

if (chx >= enemy1x - 55)
{
if (chx <= enemy1x - 49)
{
chg = 0;
chb = 0;
chr = 255;
}
else
{
chg = 255;
chb = 255;
chr = 255;
}
}
else
{
chg = 255;
chb = 255;
chr = 255;
}

I've tried doing the same thing but with the y and it makes the reticle not turn red for either the x or the y coordinates, but the x ones alone work. What's going on with that?

Is there a way to do it similarly to how I did it for x but for the y?

Re: How can I program the reticle to turn red for the y coordinates?

Posted: August 4th, 2019, 6:16 am
by TheCollector
I'm guessing because the else statement is there is why?

Re: How can I program the reticle to turn red for the y coordinates?

Posted: August 4th, 2019, 8:14 am
by cyboryxmen
How were you writing it before?

Re: How can I program the reticle to turn red for the y coordinates?

Posted: August 4th, 2019, 5:26 pm
by TheCollector
Before I was trying it with bools and && signs so that when both values were true a bool would be set to true. The only problem is, even when one was supposedly false I kept getting a return of 1. Now, I'm having a similar problem with these bools.

Well, I added the y coordinates (which right now I just have noted out with //) and I'm testing the X coordinates with booleans so that when you're over the x gfx for the enemy ytargeting (where the reticle turns red when over the y coordinates) is disabled and vice versa but my code is running even when not over the stick figure enemy. Maybe you can tell me why my bool keeps returning a value of true? I've been having this problem with bools almost every time I try to use them like this.

Code: Select all

	if (chx >= enemy1x - 55)
	{
		if (chx <= enemy1x - 49)
		{
			EnemyTargetedX = true;
			EnemyTargetedY = false;
		}
		else
		{
			EnemyTargetedX = false;
			EnemyTargetedY = false;
		}
	}
	else
	{
		EnemyTargetedX = false;
		EnemyTargetedY = false;
	}
	
//if (chy >= enemy1y - 3)
//{
//	if (chx <= enemy1y + 5)
//	{
//		EnemyTargetedX = false;
//		EnemyTargetedY = true;
//	}
//	else
//	{
//		EnemyTargetedY = false;
//		EnemyTargetedX = false;
//	}
//}
//else
//{
//	EnemyTargetedY = false;
//}
//
	if (EnemyTargetedX = false)
	{
		chg = 255;
		chb = 255;
		chr = 255;
	}
	if (EnemyTargetedX = true)
	{
		chg = 0;
		chb = 0;
		chr = 255;
	}

//if (EnemyTargetedY = false)
//{
//	chg = 255;
//	chb = 255;
//	chr = 255;
//}
//if (EnemyTargetedY = true)
//{
//	chg = 0;
//	chb = 0;
//	chr = 255;
//}

Re: How can I program the reticle to turn red for the y coordinates?

Posted: August 4th, 2019, 7:10 pm
by albinopapa
Try and see if you follow this.

Code: Select all

int left = enemy1x;
int top = enemy1y;
int right = enemy1x + 55;
int bottom = enemy1y + 3;
if( ( chx >= left && chx <= right ) && 
    ( chy >= top && chy <= bottom ) )
{
   chr = 255;
   chg = 0;
   chb = 0;
}
else
{
   chr = 255;
   chg = 255;
   chb = 255;
}

Re: How can I program the reticle to turn red for the y coordinates?

Posted: August 4th, 2019, 7:12 pm
by albinopapa
This assumes that enemy1x is the left side of the graphic and enemy1y is the top of the graphic.
The if statement checks to see if chx and chy ( the center of the cross hairs I'm assuming ) are between left and right and top and bottom. If so, then make red, if not make white.

Re: How can I program the reticle to turn red for the y coordinates?

Posted: August 4th, 2019, 10:37 pm
by TheCollector
So, I figured out what I was doing wrong. Simple error. Mixing = and ==