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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Navy

Pages: [1]
1
General / Re: How do i display a winner message?
« 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.

2
General / 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;
}
 

Pages: [1]
anything