I am making a racing game and am trying to find a way to let some one 'win' the game. in order to do this I am trying to display and image on the background at a certain position. This image isn't visable on the screen though until the racer looks around the background which moves. Once the racer finds this image i want the game to display "player _ wins" and then quit after 5 seconds. If you can help me with the image placement or the rest of it i would be grateful. I am using Visual C++ if that helps

Thanks

Dani AI

Generated

The symptom describes — the image stuck at the top-left and "acting like the player does" — usually means the sprite is being drawn with player/screen coordinates or parented to the player transform. Give the finish-line image its own world position, keep the camera separate, and convert world -> screen when you render. That way the image stays fixed in the game world and only shows up when the camera (player view) moves over it.

A minimal, practical approach:

  • Store targetWorldPos (fixed).
  • Compute cameraPos from the player position (center the camera on the player).
  • Render at screenPos = targetWorldPos - cameraPos.
  • Detect the win by testing intersection in world coordinates (player AABB vs target AABB).
  • When won, record a timestamp and keep rendering a "Player X wins" overlay; quit only after 5 seconds of elapsed game time (do not call Sleep, which blocks the loop).

Example (C++-style pseudocode):

Vector2 targetWorldPos = {1000.0f, 200.0f};
Vector2 cameraPos = player.pos - Vector2(screenW/2, screenH/2);
Vector2 targetScreenPos = targetWorldPos - cameraPos;

if (rectOnScreen(targetScreenPos, targetSize)) {
    drawSprite(targetImage, targetScreenPos);
}

Rect playerBox = player.getWorldAABB();
Rect targetBox = Rect(targetWorldPos.x, targetWorldPos.y, targetW, targetH);
if (playerBox.intersects(targetBox) && gameState != WON) {
    gameState = WON;
    winStart = std::chrono::steady_clock::now();
}

if (gameState == WON) {
    auto elapsed = std::chrono::steady_clock::now() - winStart;
    if (elapsed >= std::chrono::seconds(5)) exitGame();
    drawOverlay("Player X wins");
}

When posting code for debugging (as requested), include: the render routine, camera update, the player bounding box logic, and how you currently store positions. For safe timer use see the std::chrono reference. For the intersection test, review axis-aligned bounding box basics (collision detection overview).

Recommended Answers

All 3 Replies

Have you done anything so far? Any ideas on how to do it?

well all ive gotten so far is to get the image to appear on screen, but at the moment it is positioned at the top left next to the player and acts like the player does

Could you post the code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.