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

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
TheCollector
Posts: 41
Joined: August 1st, 2019, 9:57 pm

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

Post by TheCollector » August 4th, 2019, 6:00 am

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?

TheCollector
Posts: 41
Joined: August 1st, 2019, 9:57 pm

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

Post by TheCollector » August 4th, 2019, 6:16 am

I'm guessing because the else statement is there is why?

User avatar
cyboryxmen
Posts: 169
Joined: November 14th, 2014, 2:03 am

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

Post by cyboryxmen » August 4th, 2019, 8:14 am

How were you writing it before?
Zekilk

TheCollector
Posts: 41
Joined: August 1st, 2019, 9:57 pm

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

Post by TheCollector » August 4th, 2019, 5:26 pm

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;
//}

albinopapa
Posts: 3790
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

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

Post by albinopapa » August 4th, 2019, 7:10 pm

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;
}
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 3790
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

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

Post by albinopapa » August 4th, 2019, 7:12 pm

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.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

TheCollector
Posts: 41
Joined: August 1st, 2019, 9:57 pm

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

Post by TheCollector » August 4th, 2019, 10:37 pm

So, I figured out what I was doing wrong. Simple error. Mixing = and ==

Post Reply