Generating stairs but it is eating into each other

Joined
Mar 9, 2023
Messages
1
Reaction score
0
my code is currently generating stairs based on the rounds, such as 16 in round 1, 32 in round 2 etc. so the problem is as the stairs go higher, the stairs start eating into each other's space. If possible, can anyone fix this problem? PS: I am using java swing. this is all generated on a jpanel.


int totalSteps = rdSteps;
int stairWidth = 5000;
int stairHeight = 50;
int width = 50;
int screenY = 0;
int currentStairY = stairHeight;
int currentStairX = getWidth() - 300;
int midp = getHeight() / 2;
for (int i = 0; i < currentStep; i++) {
currentStairY -= stairHeight - (stairHeight * i / totalSteps);
currentStairX -= width - (width * i / totalSteps);
}
int totalStairHeight = stairHeight * (currentStep * 2);

int panelMidpointY = getHeight(); // find midpoint of JPanel
// adjust position of stairs based on midpoint

int screenX = -currentStairX + (currentStep * 70);

// Draw stairs
int stairX = getWidth() - stairWidth + screenX;
int stairY = getHeight() - stairHeight + screenY;
for (int i = 0; i < rdSteps; i++) {
if (i <= currentStep && i%2 == 0) {
Color stairColor = Color.decode("0xA94035");
g2d.setColor(stairColor);
} else if(i <= currentStep && i%2 != 0) {
Color stairColor = Color.decode("0xF37B73");
g2d.setColor(stairColor);
}else{
Color stairColor = Color.decode("0xDAD9D9");
g2d.setColor(stairColor);
}
g2d.fill(new Rectangle2D.Double(stairX, stairY, stairWidth - (100 * i), stairHeight));
double stairHeightDiff = (double) stairHeight / totalSteps;
stairY -= stairHeightDiff * (totalSteps - i);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,818
Messages
2,569,727
Members
45,675
Latest member
benn

Latest Threads

Top