I can't figure out what's wrong with this code.
This code doesn't show a blue square.
if (goblin1 == true) {
glBegin(GL_QUADS);
glColor3d(0, 0, 1);
glVertex2d(v1x, v1y);
glVertex2d(v2x, v2y);
glVertex2d(v3x, v3y);
glVertex2d(v4x, v4y);
glEnd();
if(goblinKing == true){
health = 130;
damage = 22;
}
while (v1x > Player.v1x + 40) {
v1x = v1x + 8;
v2x = v2x + 8;
v3x = v3x + 8;
v4x = v4x + 8;
}
while (v1x == Player.v1x + 40) {
if(Player.isAttacking() == true){
health = health - Player.damage;
if(health == 0){
goblin1 = false;
}
} else {
Player.health = Player.health - damage;
}
}
This, however does.
if (goblin1 == true) {
glBegin(GL_QUADS);
glColor3d(0, 0, 1);
glVertex2d(v1x, v1y);
glVertex2d(v2x, v2y);
glVertex2d(v3x, v3y);
glVertex2d(v4x, v4y);
glEnd();
if(goblinKing == true){
health = 130;
damage = 22;
}
while (v1x < Player.v1x + 8) {
v1x = v1x + 8;
v2x = v2x + 8;
v3x = v3x + 8;
v4x = v4x + 8;
}
while (v1x == Player.v1x + 8) {
if(Player.isAttacking() == true){
health = health - Player.damage;
if(health == 0){
goblin1 = false;
}
} else {
Player.health = Player.health - damage;
}
}
And I need the first code snippet to work, I can't use the second code snippet.
Sorry, not a games programmer (although one day... dangit), but that while comparison statement is where I'd look first. What's the value of v1x and what is its potential range, i.e., will it ever satisfy Player.v1x + 40 in either comparison? Also, you're comparing for > in the first code, but it's flipped to a < in the second code.
Looks like its probably the OpenGL state when you execute this code that's the problem. Do you call them right after each other? Best to post the code from which you call this code.