Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How do i display a winner message?  (Read 1409 times)

0 Members and 1 Guest are viewing this topic.

Navy

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
How do i display a winner message?
« on: June 28, 2019, 06:23:38 pm »
What i'm trying to do is. Lets say PlayerOne and PlayerTwo. IF PlayerOne reach the edge of the screen then display playerOne Wins! Else PlayerTwo Wins AND display playerTwo Wins!.

Something like this. Sorry my first time on c++ and on a game..

#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
using namespace sf;
using namespace std;
int main()
{
    // Create the main window
    RenderWindow window(VideoMode(1000, 625), "SFML window");
    window.setKeyRepeatEnabled(false);
    // Load a sprite to display
    Texture backgroundTexture;
    Texture tilesTexture;
    Texture bikerTexture;
    Texture biker2Texture;
    backgroundTexture.loadFromFile("data/images/background.png");
    tilesTexture.loadFromFile("data/images/tiles.png");
    bikerTexture.loadFromFile("data/images/biker.png");
    biker2Texture.loadFromFile("data/images/biker2.png");
    Sprite backgroundSprite(backgroundTexture);
    Sprite bikerSprite(bikerTexture);
    Sprite biker2Sprite(biker2Texture);
    Sprite tilesSprite(tilesTexture);
    bikerSprite.setPosition(0,500);
    biker2Sprite.setPosition(0,555);
    tilesSprite.setPosition(Vector2f(0,500));
    // Start the game loop
    while (window.isOpen())
    {
    // Process events
    Event eventCheck;
    while (window.pollEvent(eventCheck)) {
    switch (eventCheck.type) {
    case Event::Closed:
    window.close();
    break;
    case Event::KeyPressed:
    switch (eventCheck.key.code) {
    case Keyboard::Space:
    if (Keyboard::isKeyPressed(Keyboard::Space)) {
    bikerSprite.move(10,0);
    }
    break;
    case Keyboard::Enter:
    if (Keyboard::isKeyPressed(Keyboard::Enter)) {
    biker2Sprite.move(10,0);
    }
    break;
    }}}
    // Clear screen
    window.clear();
    // Draw the sprite
    window.draw(backgroundSprite);
    window.draw(tilesSprite);
    window.draw(bikerSprite);
    window.draw(biker2Sprite);
    // Update the window
    window.display();
    }
    return EXIT_SUCCESS;
}
 
« Last Edit: June 29, 2019, 12:48:54 pm by Navy »

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: How do i display a winner message?
« Reply #1 on: June 28, 2019, 06:41:31 pm »
What do you have so far?

terrifiedobama

  • Newbie
  • *
  • Posts: 13
  • Hi, i am eager to learn SFML.
    • AOL Instant Messenger - Skype+:+live:mohasmedec
    • View Profile
    • https://www.google.bg/search?ei=fSI7XdixF6PuxgOC64iwCA&q=Chicken+fight&oq=Chicken+fight&gs_l=psy-ab.3..0l10.2406.2677..2783...0.0..0.92.181.2......0....1..gws-wiz.......0i71.bzIU-zC-Thw&ved=0ahUKEwiY5JaY-dLjAhUjt3EKHYI1AoYQ4dUDCAo&uact
    • Email
Re: How do i display a winner message?
« Reply #2 on: June 28, 2019, 11:13:20 pm »
Okay this is what i could invent
its basic and stupid but it also work i guess
Guys my name's Boris. I'm 22 year old and I want to tell you that I'm happy to join your community. I hope we can learn together , or learn each other.
If you want to get to know me or help me or help you contact me, the following below is the INFORMATION..
@@@@@@@@
Skype : live:mohasmedec
@@@@@@@@

Navy

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: How do i display a winner message?
« Reply #3 on: June 29, 2019, 01:08:23 pm »
No its not stupid. I'm sorry i tried but couldn't understand. i have updated the code above.

terrifiedobama

  • Newbie
  • *
  • Posts: 13
  • Hi, i am eager to learn SFML.
    • AOL Instant Messenger - Skype+:+live:mohasmedec
    • View Profile
    • https://www.google.bg/search?ei=fSI7XdixF6PuxgOC64iwCA&q=Chicken+fight&oq=Chicken+fight&gs_l=psy-ab.3..0l10.2406.2677..2783...0.0..0.92.181.2......0....1..gws-wiz.......0i71.bzIU-zC-Thw&ved=0ahUKEwiY5JaY-dLjAhUjt3EKHYI1AoYQ4dUDCAo&uact
    • Email
Re: How do i display a winner message?
« Reply #4 on: June 29, 2019, 02:25:32 pm »
Do you have skype or something we could contact and see if i could help.
Guys my name's Boris. I'm 22 year old and I want to tell you that I'm happy to join your community. I hope we can learn together , or learn each other.
If you want to get to know me or help me or help you contact me, the following below is the INFORMATION..
@@@@@@@@
Skype : live:mohasmedec
@@@@@@@@

 

anything