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 - Daoxin

Pages: [1]
1
General / Re: Starting off without a blank prompt
« on: July 30, 2022, 02:38:03 am »
Thank you it worked! Thank you!

2
General / Starting off without a blank prompt
« on: July 29, 2022, 04:26:23 am »
So I am making a text adventure game with choices. The issue I have is that  I made my text as an array list that goes on as you click to enter to advance the text, but every time you start the game, there is a blank screen until you click enter, and the prompt from the area starts.

When I manually put a text, I have it appearing at the start when you start the game. I tried placing it in other areas but won't go away when pressing enter. I notice if I have it in another class, it would o to the next class and continue, but it has that same issue where the screen will be blank until you click the enter button to show the next prompt.

How do I fix this issue?

Here is a copy of the code I have on my cpp file:

#include "Gameplay.h"
#include "GameText.h"
#include "ChoiceA.h"


Gameplay::Gameplay(std::shared_ptr<Context> &context) : context(context){}

Gameplay::~Gameplay(){}

void Gameplay::Init()
{
    context->assets->AddFont(MainFont, "Assets/Myuniquefont-Regular.otf");
    text.setFont(context->assets->GetFont(MainFont));
    text.setOrigin(context->window->getSize().x/2.f,
                   context->window->getSize().y/2.f);
    text.setPosition(context->window->getSize().x/2.f,
                      context->window->getSize().y/2.f);
    text.setCharacterSize(65);
}

void Gameplay::ProcessInput()
{
    std::string text_array[] = {"There was once a hafling and a dragon."
                                "\nThey were wandering around in secrecy.",
                                "Traveling together and far",
                                "And third text",
                                "option \"A\" or option \"B\""};

    std::string text_array_two[] = {"We here on option A",
                                    "Maybe here too?",
                                    "unkown places but here we are"};

    std::string text_array_twoSideB[] = {"We here on option B",
                                    "Maybe here too? Or maybe not",
                                    "unkown places but here we are"};

    sf::Event event;
    while (context->window->pollEvent(event))
    {
        text.setString("Please click enter to continue the story.");

        if (event.type == sf::Event::Closed)
        {
            context->window->close();
        }

        if(event.type == sf::Event::KeyPressed)
        {

            if (event.key.code == sf::Keyboard::Return)
            {
                text.setString("Please click enter to continue the story.");

//                text.setString(text_array[text_counter]);
//                text_counter++;
            }

            else if(text_array->back() && event.key.code == sf::Keyboard::A)
            {
//                context->states->Add(std::make_unique<ChoiceA>(context), true);
//                text_counter = 0;
            }

//            else if(text_array->size() -1 && event.key.code == sf::Keyboard::B)
//            {
//                text.setString(text_array_twoSideB[text_counter_two]);
//                text_counter_two++;
//
//            }
         }
    }

}


void Gameplay::Update(sf::Time deltaTime)
{

}

void Gameplay::Draw()
{
    context->window->clear();
    context->window->draw(text);
    context->window->display();
}
 

and here is my header file:

#ifndef SFML_PROJECT_GAMEPLAY_H
#define SFML_PROJECT_GAMEPLAY_H

#pragma once
#include "State.h"
#include "Game.h"
#include "GameText.h"
#include <memory>
#include <SFML/Graphics.hpp>

class Gameplay : public Engine::State
{
private:
    std::shared_ptr<Context> context;
    sf::Text text;

public:
    Gameplay(std::shared_ptr<Context>& context);
    ~Gameplay();

    unsigned int text_counter = 0;
    unsigned int text_counter_two = 0;

    void Init() override;
    void ProcessInput() override;
    void Update(sf::Time deltaTime) override;
    void Draw() override;
    void Pause() override;
    void Start() override;
};


#endif //SFML_PROJECT_GAMEPLAY_H

 


As you can see, I tried different ways to clear the blank spot, but I keep running a road block with a manual string that won't clear no matter if I tried to destroy it or clear it off the screen.

3
Window / Re: Text Base Adventure Game using SFML
« on: January 21, 2022, 05:38:18 am »
Sorry for the late reply and I see, I will give this a try thank you!

4
Window / Text Base Adventure Game using SFML
« on: December 27, 2021, 05:49:06 am »
So been trying to make a choose your adventure game with choices you make that affect the story. Seems easier when doing it on the IDE but having trouble making it with SFML. I have a menu screen working and getting a new screen with user keypress to advance some text but thinking this might not be an efficient way of what I want to do. This is what I have so far as a snippet:

void Gameplay::ProcessInput()
{
    int choiceCounter = 0;
    int choiceCounterTwo = 0;

    std::string text_array[] = {"This is the first text",
                                "This is the second one",
                                "And third text",
                                "End"};

    std::string text_array_two[] = {"We here",
                                    "Maybe here too?"};

    sf::Event event;
    while (context->window->pollEvent(event))
    {
        if (event.type == sf::Event::Closed)
        {
            context->window->close();
        }

        if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return)
        {
            if (text_counter < (sizeof(text_array) / sizeof(text_array[0])))
            {
                text.setString(text_array[text_counter]);
                text_counter++;
            }
            else
            {
                text_counter = 0;

                text.setString(text_array[text_counter]);
                text_counter++;
            }

            if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Num1)
            {
                choiceCounter++;
                std::string choiceRes = std::to_string(choiceCounter);
                text.setString("Here is the choice point: " + choiceRes);
            }
            else
            {
                choiceCounterTwo++;
                std::string choiceRes = std::to_string(choiceCounterTwo);
                text.setString("Here is the other choice point: " + choiceRes);
            }
           
        }
    }

}
 

I get why it ignores the text array and goes straight to results as when I take out the keypress with the number 1, it works fine and advances to the next text. Thinking about it. I guess text array isn't a good way to go. So I've been thinking of either making its own class for the actual text story.

So my question is, how do I advance the text based on the user input in another way?

5
General / Re: Moving a sliding puzzle
« on: June 08, 2021, 12:53:00 am »
Okay I did some more stuff to make it move but unsure what I need to do to make it move. I think what I have is right so far but unsure?

header file:

#include <SFML/Graphics.hpp>
#include "Button.h"
#include "ButtonTwo.h"
#include "Fonts.h"
#include "Rectangle.h"

class MainGame
{
private:
    sf::RenderWindow window;
    Button button;
    ButtonTwo exitButton;
    Rectangle r;
    Rectangle rTwo;
    Rectangle rThree;
    Rectangle rFour;
    sf::Text title;
    WindowDialog dialog;
public:
    enum boxCanMove{UP, LEFT, DOWN, RIGHT};
    MainGame();
    void run();

};
 

cpp file

MainGame::MainGame() : window({1920, 1080, 32}, "SFML Final Project")
{

    button.setOrigin({button.getGlobalBounds().width/2,
                      button.getGlobalBounds().height/2});

    button.setPosition({window.getSize().x/2.f,
                        window.getSize().y/2.f});

    exitButton.setOrigin({button.getGlobalBounds().width/2,
                      button.getGlobalBounds().height/2});

    exitButton.setPosition({window.getSize().x/2.f,
                        window.getSize().y/1.5f});

    title.setFont(Fonts::getFont());
    title.setOrigin(title.getGlobalBounds().width/2,
                      title.getGlobalBounds().height/2);
    title.setPosition(window.getSize().x/5.5f,
                      window.getSize().y/9.5f);
    title.setFillColor(sf::Color::Blue);
    title.setCharacterSize(150);
    title.setString("Final Siding Puzzle Game");

    r.setSize({100, 100});
    r.setPosition({window.getSize().x / 2.f,
                   window.getSize().y / 2.f});
    r.setFillColor(sf::Color(53, 189, 164));

    rTwo.setSize({100,100});
    rTwo.setPosition({window.getSize().x/2.25f,
                      window.getSize().y/2.f});
    rTwo.setFillColor(sf::Color::Yellow);

    rThree.setSize({100, 100});
    rThree.setPosition({window.getSize().x / 2.f,
                   window.getSize().y / 2.48f});
    rThree.setFillColor(sf::Color::Yellow);

    rFour.setSize({100,100});
    rFour.setPosition({window.getSize().x/2.25f,
                      window.getSize().y/2.48f});
    rFour.setFillColor(sf::Color::Yellow);

}

void MainGame::run()
{

    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
            {
                window.close();
            }

            sf::FloatRect bounds = button.getGlobalBounds();
            sf::FloatRect boundsTwo = exitButton.getGlobalBounds();
            sf::Vector2f mPos = (sf::Vector2f) sf::Mouse::getPosition(window);

            if(sf::Mouse::isButtonPressed(sf::Mouse::Left) && bounds.contains(mPos))
            {
                //this will set the rectangle to a fade state
                button.enableState(States::HIDDEN);
                exitButton.enableState(States::HIDDEN);
                r.disableState(States::HIDDEN);
                rTwo.disableState(States::HIDDEN);
                rThree.disableState(States::HIDDEN);
                rFour.disableState(States::HIDDEN);

            }

            else if(sf::Mouse::isButtonPressed(sf::Mouse::Left) && boundsTwo.contains(mPos))
            {
                exit(1);
            }

            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
            {
                if(boxCanMove(UP))
                {
                    sf::FloatRect bounds = r.getGlobalBounds();

                    r.setPosition({
                                          bounds.left,
                                          bounds.top - bounds.height
                                  });
                }
            }
            else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
            {
                if(boxCanMove(LEFT))
                {
                    sf::FloatRect bounds = r.getGlobalBounds();

                    r.setPosition({
                                          bounds.left + bounds.width,
                                          bounds.top
                                  });
                }
            }

            //other events
            button.addEventHandler(window, event);
            exitButton.addEventHandler(window, event);


        }

        button.update();
        exitButton.update();
        window.clear(sf::Color(53, 189, 164));
        window.draw(button);
        window.draw(exitButton);
        window.draw(title);
        window.draw(r);
        window.draw(rTwo);
        window.draw(rThree);
        window.draw(rFour);
        window.display();
    }
}


 

6
General / Moving a sliding puzzle
« on: June 06, 2021, 02:00:12 am »
So having trouble setting up this sliding puzzle game where I have one square that matches the background and trying to make the squares move. I know about the keyboard input and tried to implement it but I am unsure how to connect that to my squares? Should I make a new class to move these square or how should I approach it? How can I that connection for it?

this is my classes for the rest of the game I have made except for the buttons as they work fine and the text object as well
class States
{
private:
    std::vector<bool> objectStates;
public:
    States();
    enum states {HOVERED, NORMAL, HIDDEN, LAST};
    bool checkState(states state) const;
    void enableState(states state);
    void disableState(states state);

};

States::States()
{
    for(int i=0; i<LAST; i++)
        objectStates.push_back(false);
}
bool States::checkState(states state) const
{
    return objectStates[state];
}
void States::enableState(states state)
{
    objectStates[state] = true;
}
void States::disableState(states state)
{
    objectStates[state] = false;
}
 

#include <SFML/Graphics.hpp>
#include "States.h"
#include "LinkedListPiece.h"

class Rectangle : public sf::Drawable, public States
{

private:
    sf::RectangleShape background;
    sf::RectangleShape rectangle;
   
public:
    Rectangle();
    void center();
    void draw(sf::RenderTarget& window, sf::RenderStates states) const;
    void addEventHandler(sf::RenderWindow &window, sf::Event event);
    void update();

    void setSize(sf::Vector2f size);
    void setPosition(sf::Vector2f position);

    sf::FloatRect getGlobalBounds();
};

#include "Rectangle.h"

Rectangle::Rectangle() { enableState(HIDDEN);}

void Rectangle::update()
{

}

void Rectangle::draw(sf::RenderTarget& window, sf::RenderStates states) const
{
    if(!checkState(HIDDEN))
        window.draw(rectangle);
}

void Rectangle::center()
{

}

void Rectangle::addEventHandler(sf::RenderWindow &window, sf::Event event)
{

}

void Rectangle::setSize(sf::Vector2f size)
{
    rectangle.setSize(size);
}

void Rectangle::setPosition(sf::Vector2f position)
{
    rectangle.setPosition(position);
}

sf::FloatRect Rectangle::getGlobalBounds()
{
    return background.getGlobalBounds();
}
 


#include <SFML/Graphics.hpp>
#include "Button.h"
#include "ButtonTwo.h"
#include "Fonts.h"
#include "Rectangle.h"

class MainGame
{
private:
    sf::RenderWindow window;
    Button button;
    ButtonTwo exitButton;
    Rectangle r;
    Rectangle rTwo;
    Rectangle rThree;
    Rectangle rFour;
    sf::Text title;
    WindowDialog dialog;
public:
    MainGame();
    void run();

};

MainGame::MainGame() : window({1920, 1080, 32}, "SFML Final Project")
{

    button.setOrigin({button.getGlobalBounds().width/2,
                      button.getGlobalBounds().height/2});

    button.setPosition({window.getSize().x/2.f,
                        window.getSize().y/2.f});

    exitButton.setOrigin({button.getGlobalBounds().width/2,
                      button.getGlobalBounds().height/2});

    exitButton.setPosition({window.getSize().x/2.f,
                        window.getSize().y/1.5f});

    title.setFont(Fonts::getFont());
    title.setOrigin(title.getGlobalBounds().width/2,
                      title.getGlobalBounds().height/2);
    title.setPosition(window.getSize().x/5.5f,
                      window.getSize().y/9.5f);
    title.setFillColor(sf::Color::Blue);
    title.setCharacterSize(150);
    title.setString("Final Siding Puzzle Game");

    r.setSize({100, 100});
    r.setPosition({window.getSize().x / 2.f,
                   window.getSize().y / 2.f});

    rTwo.setSize({100,100});
    rTwo.setPosition({window.getSize().x/2.25f,
                      window.getSize().y/2.f});

    rThree.setSize({100, 100});
    rThree.setPosition({window.getSize().x / 2.f,
                   window.getSize().y / 2.48f});
    rFour.setSize({100,100});
    rFour.setPosition({window.getSize().x/2.25f,
                      window.getSize().y/2.48f});

}

void MainGame::run()
{

    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
                window.close();

            sf::FloatRect bounds = button.getGlobalBounds();
            sf::FloatRect boundsTwo = exitButton.getGlobalBounds();
            sf::Vector2f mPos = (sf::Vector2f) sf::Mouse::getPosition(window);
            if(sf::Mouse::isButtonPressed(sf::Mouse::Left) && bounds.contains(mPos))
            {
                //this will set the rectangle to a fade state
                button.enableState(States::HIDDEN);
                exitButton.enableState(States::HIDDEN);
                r.disableState(States::HIDDEN);
                rTwo.disableState(States::HIDDEN);
                rThree.disableState(States::HIDDEN);
                rFour.disableState(States::HIDDEN);

            }
            else if (sf::Mouse::isButtonPressed(sf::Mouse::Left) && boundsTwo.contains(mPos))
            {
                button.enableState(States::HIDDEN);
                exitButton.enableState(States::HIDDEN);
            }
            //other events
            button.addEventHandler(window, event);
            exitButton.addEventHandler(window, event);
        }

        button.update();
        window.clear(sf::Color(53, 189, 164));
        window.draw(button);
        window.draw(exitButton);
        window.draw(title);
        window.draw(r);
        window.draw(rTwo);
        window.draw(rThree);
        window.draw(rFour);
        window.display();
    }
}

 

and my main

#include <iostream>
#include <SFML/Graphics.hpp>
#include "MainGame.h"

int main()
{
    MainGame game;
    game.run();
    return 0;
}

 

7
General / Re: Text advancing or getting to the new line of text
« on: June 06, 2021, 01:47:05 am »
That helped thank you!

8
General / Re: Text advancing or getting to the new line of text
« on: May 17, 2021, 08:56:27 pm »
I copied the

unsigned int text_counter = 0;
    std::string text_array[] = {"This is the first text",
                                "This is the second one",
                                "And third text",
                                "End"};
if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return)
        {
            if (text_counter < (sizeof(text_array) / sizeof(text_array[0])))
            {
                text.setString(text_array[text_counter]);
                text_counter++;
            }
        }

Parts into mine and yeah only the first part of the array appears only. I even put the array in the same class function I have for the event to see if that was the issue but was not.

GamePlay::GamePlay(std::shared_ptr<Context> &context) : context(context),
AdvanceButton(false)
{

}

GamePlay::~GamePlay()
{

}

void GamePlay::Init()
{
    //rectangle shape of the chat box
    chatBox.setSize({1500, 320});
    chatBox.setFillColor(sf::Color::Black);
    chatBox.setOutlineColor(sf::Color::White);
    chatBox.setOutlineThickness(5.f);
    chatBox.setOrigin(chatBox.getGlobalBounds().width/1,
                        chatBox.getGlobalBounds().height/1);
    chatBox.setPosition(context->window->getSize().x/1.1f,
                        context->window->getSize().y/1.01f);

    //Titlle screen name of the game code
    context -> assets ->AddFont(MainFont, "Assets/Asdonuts.ttf");
    text.setFont(context->assets->GetFont(MainFont));

    text.setCharacterSize(50);
    text.setFillColor(sf::Color::White);
    text.setPosition(context->window->getSize().x/5.7f,
                     context->window->getSize().y/2);


}

void GamePlay::ProcessInput()
{

    unsigned int text_counter = 0;
    std::string text_array[] = {"This is the first text",
                                "This is the second one",
                                "And third text",
                                "End"};

    sf::Event event;
    while(context->window->pollEvent(event))
    {
        if (event.type == sf::Event::Closed)
        {
            context->window->close();
        }

        if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return)
        {
            if (text_counter < (sizeof(text_array) / sizeof(text_array[0])))
            {
                text.setString(text_array[text_counter]);
                text_counter++;
            }
        }
    }
}

void GamePlay::Update(sf::Time deltaTime)
{
//    text.setString("Hello There");
//
//        text.setString("Hello Again");
}

void GamePlay::Draw()
{
    context->window->clear(sf::Color::Black);
    context->window->draw(chatBox);
    context->window->draw(text);
    context->window->display();
}

9
General / Re: Text advancing or getting to the new line of text
« on: May 17, 2021, 07:37:25 pm »
i don't know if I really understand your question... you want to change to a new text everytime the user press Enter? if that's the point, I don't think you need a class for simply holding a text. you could simply have an array of texts. example:

#include <SFML/Graphics.hpp>

int main(){
    sf::RenderWindow window(sf::VideoMode(800, 600), "Text Adventure");

    unsigned int text_counter = 0;
    std::string text_array[] = {"This is the first text",
                                "This is the second one",
                                "And third text",
                                "End"};
    sf::Font font;
    if (!font.loadFromFile("automati.ttf"))
        return 1;
    sf::Text text("", font, 20);

    while (window.isOpen()){
        sf::Event event;
        while (window.pollEvent(event)){
            if (event.type == sf::Event::Closed){
                window.close();
            }
            if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Return){
                if (text_counter < (sizeof(text_array)/sizeof(text_array[0]))){
                    text.setString(text_array[text_counter]);
                    text_counter++;
                }
            }

        }
        window.clear();
        window.draw(text);
        window.display();
    }
    return 0;
}
 

Strangely that did not work for me, It stays in the first line from the array. Thanks though but I will try using the array as you said for a bit.

10
General / Re: Text advancing or getting to the new line of text
« on: May 17, 2021, 07:29:37 pm »
I see what you mean, I might give that a try then and yes that was my question haha sorry about the confusion. I will give the array a try just a bit worried as it is long with choices and having puzzles involved but will see if that will work then. Thank you! :D

11
General / Text advancing or getting to the new line of text
« on: May 14, 2021, 11:33:37 pm »
So I have been working on a text-based adventure game where it is heavy on text and choices you make. The main problem is that the text I try to set up does appear in the game but does not advance after clicking enter and been struggling with it. Should I make a new class for the text that will be read off from or put it all in this current class I have made. So far I can make only one text appear if the player clicks enter and that is good. That is what I want but want to delete the text after they click enter and a new text appears. I tried to do if statements, when they click, enter and works but that is WAY TOO MANY if to continue the story. Wondering if maybe I just need to make a new class that if you click enter, a new text appears or something. I know it has to update or something to advance the text string but unsure what it could be.

Here is the code I have made so far in different classes:

GamePlay::GamePlay(std::shared_ptr<Context> &context) : context(context),
AdvanceButton(false)
{

}

GamePlay::~GamePlay()
{

}

void GamePlay::Init()
{
    //rectangle shape of the chat box
    chatBox.setSize({1500, 320});
    chatBox.setFillColor(sf::Color::Black);
    chatBox.setOutlineColor(sf::Color::White);
    chatBox.setOutlineThickness(5.f);
    chatBox.setOrigin(chatBox.getGlobalBounds().width/1,
                        chatBox.getGlobalBounds().height/1);
    chatBox.setPosition(context->window->getSize().x/1.1f,
                        context->window->getSize().y/1.01f);

    //Titlle screen name of the game code
    context -> assets ->AddFont(MainFont, "Assets/Asdonuts.ttf");
    text.setFont(context->assets->GetFont(MainFont));

    text.setCharacterSize(50);
    text.setFillColor(sf::Color::White);
    text.setPosition(context->window->getSize().x/5.7f,
                     context->window->getSize().y/2);
}

void GamePlay::ProcessInput()
{
    sf::Event event;
    while(context->window->pollEvent(event))
    {
        if (event.type == sf::Event::Closed)
        {
            context->window->close();
        }

        else if(event.type == sf::Event::KeyPressed)
        {

            switch(event.key.code)
            {
                case sf::Keyboard::Enter:
                {
                    text.setString("Hey There");

                    text.setString("Welcome here");//ignore these two as I was just texting this part out that it could work like this

                    text.setString("Wow");//ignore this one too



                    break;
                }
            }
        }
    }
}

void GamePlay::Update(sf::Time deltaTime)
{

}

void GamePlay::Draw()
{
    context->window->clear(sf::Color::Black);
    context->window->draw(chatBox);
    context->window->draw(text);
    context->window->display();
}

#pragma once
#include <iostream>
#include <memory>
#include <SFML/Graphics.hpp>
#include "Game.h"
#include "State.h"
#include <sstream>
#include "ConversationText.h"

class GamePlay : public Engine::State
{
private:
    std::shared_ptr<Context> context;
    sf::Sprite WindowBox;
    sf::RectangleShape chatBox;
    sf::Text text;
    std::ostringstream chat;

    bool isSelected = false;
    bool hasLimit = false;
    bool AdvanceButton;
    int limit;

    void inputLogic(int chaTyped);

public:
    GamePlay(std::shared_ptr<Context> &context);
    ~GamePlay();

    void Init() override;

    void ProcessInput() override;
    void Update(sf::Time deltaTime) override;
    void Draw() override;
};

 

Pages: [1]
anything