d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ Is Whack... Or My Code Is Wrong.. > Halp
Add Reply New Topic New Poll
Member
Posts: 7,969
Joined: Jul 7 2008
Gold: 286.54
Jun 26 2012 06:30pm
Code

//Quickly checking Intersections.
for (std::vector<_Element>::iterator id = Elements.begin(); id != Elements.end(); ++id){
 
 
 bool iLEFT=false, iRIGHT=false, iUP=false, iDOWN=false;


 //if intersection with left
 if (InterSection(this->Pos.x-32, (*id).Pos.x, this->Pos.y, (*id).Pos.y, this->Rect.width, (*id).Rect.width, this->Rect.height, (*id).Rect.height)) { iLEFT=true; }

 //if intersection with right
 if (InterSection(this->Pos.x+32, (*id).Pos.x, this->Pos.y, (*id).Pos.y, this->Rect.width, (*id).Rect.width, this->Rect.height, (*id).Rect.height)) { iRIGHT=true; }
 
 //if intersection with up
 if (InterSection(this->Pos.x, (*id).Pos.x, this->Pos.y-32, (*id).Pos.y, this->Rect.width, (*id).Rect.width, this->Rect.height, (*id).Rect.height)){ iUP=true; }
 
 //if intersection with down
 if (InterSection(this->Pos.x, (*id).Pos.x, this->Pos.y+32, (*id).Pos.y, this->Rect.width, (*id).Rect.width, this->Rect.height, (*id).Rect.height)) { iDOWN=true; }

 
 if (iLEFT || iRIGHT) {this->textureLocation = sf::Vector2f(0, 0);}
 if (iUP || iDOWN) {this->textureLocation = sf::Vector2f(64, 32);}

 //CODE?! Y U NO WORK
 if (iLEFT && iDOWN) {this->textureLocation = sf::Vector2f(32, 0);} //LEFT AND DOWNAA
 if (iRIGHT && iDOWN) {this->textureLocation = sf::Vector2f(64, 0);} //RIGHT AND DOWNAA
 if (iUP && iRIGHT) {this->textureLocation = sf::Vector2f(0, 32);} //RIGHT AND UPA
 if (iUP && iLEFT) {this->textureLocation = sf::Vector2f(32, 32);} //LEFT AND UPA
 
}


Doesn't change Texture Location Properly.
I have been able to use variables by themselves (ie:
Code
if (iUP) {}
and it works just fine....)
What's the problem with &&?!?

Help....
Banned
Posts: 2,525
Joined: Jan 2 2012
Gold: 0.01
Warn: 10%
Jun 27 2012 07:51am
shouldn't this Y U NO WORK part be outside of loop?

(together with variable declarations above the loop)

This post was edited by ikusus on Jun 27 2012 08:17am
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Jun 27 2012 09:59am
It's almost certainly not the problem at hand, but you might want to look at your _Element class: after the standard
Quote

17.6.3.3.2 Global names [global.names]
1 Certain sets of names and function signatures are always reserved to the implementation:
— Each name that contains a double underscore __ or begins with an underscore followed by an uppercase letter (2.12) is reserved to the implementation for any use.
— Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.


This post was edited by KrzaQ2 on Jun 27 2012 10:04am
Member
Posts: 7,969
Joined: Jul 7 2008
Gold: 286.54
Jun 27 2012 07:15pm
Quote (ikusus @ Jun 27 2012 05:51am)
shouldn't this Y U NO WORK part be outside of loop?

(together with variable declarations above the loop)


The same thing happens. :\

Quote (KrzaQ2 @ Jun 27 2012 07:59am)
It's almost certainly not the problem at hand, but you might want to look at your _Element class: after the standard


Removed / changed to : Element
and I'm still having the same problem.



Here's a more visual representation:



it only works if anything is BELOW an Element. (or DOWN)

and...


it only works if anything is LEFT to an Element.


but.... the problem is...


Doesn't check both for some reason.

This post was edited by Salvationvsfate on Jun 27 2012 07:20pm
Member
Posts: 7,969
Joined: Jul 7 2008
Gold: 286.54
Jul 3 2012 10:56pm
Fixed the problem.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll