Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Needing a bit of help figuring out how to code the show position method anad suc

ID: 663759 • Letter: N

Question

Needing a bit of help figuring out how to code the show position method anad success completion. I have already created the HUD. Just needs some help on this please.

Create a heads-up display (HUD) at the top of the screen (using a new <DIV> element and associated CSS) that displays the following.

The game title

Player position (measured in cells (e.g., 1,2 or 4,5)

Coding needs: a new method for player named showPosition() that captures the current position on each iteration of the game loop and displays the text in the HUD

Percentage of the distance to the goal (measured as %) completed at the current position

Coding needs: need to code an addition for the showPosition() method above that calculates the diagonal distance to the end of the maze from the current position, and then calculates the ratio of that current distance to the total distance (which is the diagonal from position 1,1 to position 14,14). The result is then displayed as text in the HUD. For example, total distance on a diagonal from 14,14 to 1,1 would be 13 / sin(45) or sqrt(13 * 13 + 13 * 13) = 18.3. So, if player is at position coordinates of 5,13, the distance from that point is sqrt(4 * 4 + 12 * 12) = 12.6. So the ratio is 12.6 / 18.3 = 0.69 or 69%—but the percentage completed would be 100% - 69% = 31%.

Success when the goal is reached (defined as arriving at 1,1 on the minimap)

Explanation / Answer

you can write a javascript code for the same. Include it in the head of your application and call the function when the user does some action in background to determine the completion.

it can be something like

lineLength = function(x, y, x0, y0){
    return Math.sqrt((x -= x0) * x + (y -= y0) * y);
};

you can modify the function based on your calculation and requirement.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote