How can I program the reticle to turn red for the y coordinates?
-
- Posts: 41
- Joined: August 1st, 2019, 9:57 pm
How can I program the reticle to turn red for the y coordinates?
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?
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?
-
- Posts: 41
- Joined: August 1st, 2019, 9:57 pm
Re: How can I program the reticle to turn red for the y coordinates?
I'm guessing because the else statement is there is why?
- cyboryxmen
- Posts: 190
- Joined: November 14th, 2014, 2:03 am
Re: How can I program the reticle to turn red for the y coordinates?
How were you writing it before?
Zekilk
-
- Posts: 41
- Joined: August 1st, 2019, 9:57 pm
Re: How can I program the reticle to turn red for the y coordinates?
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.
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;
//}
-
- Posts: 4373
- 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?
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
-
- Posts: 4373
- 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?
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.
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
-
- Posts: 41
- Joined: August 1st, 2019, 9:57 pm
Re: How can I program the reticle to turn red for the y coordinates?
So, I figured out what I was doing wrong. Simple error. Mixing = and ==