I'm making a game where I have a 'endzonebox' that the player needs to run into to complete the level (this uses a collision detection method).
At the start of each level I set up the endzonebox in the required position in the level. This is the code that currently does this:
-(void)setupEndzoneBoxWithExitSide:(int)ExitSide exitStart:(int)ExitStart andExitEnd:(int)ExitEnd {
NSLog(@"End Zone Box Width%.2f Height%.2f", endzoneBox.width, endzoneBox.height);
float width = abs(ExitEnd - ExitStart);
float height = 30;
NSLog(@"width %.2f height %.2f", width, height);
endzoneBox.width = width;
endzoneBox.height = height;
NSLog(@"End Zone Box Width%.2f Height%.2f", endzoneBox.width, endzoneBox.height);
switch (ExitSide) {
case 1: //top
endzoneBox.rotation = 0;
endzoneBox.x=ExitStart;
endzoneBox.y=GAME_UI_HEIGHT;
break;
case 2: //right
endzoneBox.rotation = PI / 2;
endzoneBox.x=mWidth;
endzoneBox.y=ExitStart+GAME_UI_HEIGHT;
break;
case 3: //bottom
endzoneBox.rotation = PI;
endzoneBox.x = ExitEnd;
endzoneBox.y = mHeight;
break;
case 4: //left
endzoneBox.rotation = PI * 3 / 2;
endzoneBox.x = 0;
endzoneBox.y = ExitEnd+GAME_UI_HEIGHT;
break;
default:
NSLog(@"Error with currentLevel.exitSide on setting up endzone box");
break;
}
NSLog(@"End Zone Box x%.0f y%.0f rotation%.2f width%.2f height%.2f", endzoneBox.x,
endzoneBox.y, endzoneBox.rotation, endzoneBox.width ,endzoneBox.height);
}
ExitSide is the side of the screen where the box is to be positioned (1-4 top to left clockwise), ExitStart is the smallest x or y (depending on the side) where the box is to go and ExitEnd is the largest x or y where the box is to go.
The works some of the times for some of the levels, e.g. works fine for level 1, for level 2 you have to die (the game reloads the level) for the box to show in the correct side.
When it is wrong here's the output from NSLog:
2015-01-28 14:34:39.277 Sparrow RBR[868:192183] End Zone Box Width30.00 Height190.00
2015-01-28 14:34:39.277 Sparrow RBR[868:192183] width 190.00 height 30.00
2015-01-28 14:34:39.278 Sparrow RBR[868:192183] End Zone Box Width0.30 Height3242.66
2015-01-28 14:34:39.278 Sparrow RBR[868:192183] End Zone Box x0 y260 rotation-1.57 width0.30 height3242.66