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

Pages: [1] 2
1
General / Re: Best way for day > night transition
« on: February 09, 2015, 10:44:54 pm »
Just the answer I was hoping for! I will go learn more about shaders.

ty for the answer and have a good day!

case closed

2
General / Best way for day > night transition
« on: February 09, 2015, 09:05:44 pm »
hi i've made a small game with some simple textures as background

what would be the best way to make a like a day > night transition? aka go from bright to dark... sort of
I did some small research about shaders but didn't understand it very well

are there any easy ways to change brightness or something?
otherwise I'll just read up more on shaders I suppose

big thanks in advance! and apologise if these kind of threads are not "appreciated".....

3
General / Re: sf::Text array
« on: July 28, 2014, 09:15:45 pm »
nice! I'll be studying this for a while! thanks

4
General / Re: sf::Text array
« on: July 25, 2014, 11:55:50 pm »
in all honesty, i've never done that mate. would you care to explain how?


5
General / sf::Text array
« on: July 25, 2014, 11:08:56 pm »
hello mates,

i'm developing a small 2d rpg but having difficulties when it comes to text and subtitles. first of all I wanted to do a text array for an npc, but it doesn't seem to respond to any variables other than the first one so to speak.
for example:

sf::Text npc_text[10]

npc_text[0].setFont(font);
npc_text[0].setString("greetings sire");

this works, but if I change to:

npc_text [1].setFont(font);
npc_text[1].setString("greetings sire");

it all of a sudden DOESN'T work, why?

how should I go about coding the texts and subtitles in a smooth way? i'm also not sure how I could set the fonts to all the texts in a simple way? other than typing:

npc_text[1].setFont(font);
npc_text[2].setFont(font);
npc_text[3].setFont(font);
npc_text[4].setFont(font);

etc etc.

i have attempted a for loop for this, but it has only resulted in crashes. mayhaps because of initializing too many fonts at once?

thank you mate
 

6
General / Re: reason for the & sign
« on: July 05, 2014, 02:05:25 am »
thanks

7
General / reason for the & sign
« on: July 04, 2014, 08:29:10 pm »
I created a function that looks like this:

void Draw(sf::RenderWindow &window);

... to draw a sprite.

but I don't understand why the & sign needs to be there...
what is it for? I can't seem to find out

8
General / Re: Unnecessary blocks of code
« on: April 18, 2014, 03:34:58 pm »
Quote
Have you really not done this before? How to use functions and parameters is basic C++, maybe you should have a deeper look at a good book..
Yes... I suppose i've been too eager to just jump into game development without learning the c++ basics.
I'll go read a book

thanks anyway

9
General / Re: Unnecessary blocks of code
« on: April 18, 2014, 03:01:26 pm »
So you mean I should have 5 different functions, one for each ball? I suppose it makes it easier to read but it's still just as much code.

It's not possible to just have this code:

Quote
         if (!gamefinished && playerSprite.getPosition().x > obstacleSprite[0].getPosition().x - 30 &&
         playerSprite.getPosition().y > obstacleSprite[0].getPosition().y - 30 &&
         playerSprite.getPosition().x < obstacleSprite[0].getPosition().x + 20 &&
         playerSprite.getPosition().y < obstacleSprite[0].getPosition().y + 30)
      {
         gamefinished = true;
         musicsound.stop();
         endgameText.setString("                          YOU DIED\n\n\n\n\nYOU FINISHED GAME WITH:  " + currentGold + "  GOLD!");
      }

work for all variables in the array instead of just (in this case, obstacleSprite[0])

10
General / Unnecessary blocks of code
« on: April 18, 2014, 02:02:22 pm »
Hello I'm after some tips regarding continous blocks of code related to the same things...

I've been thinking about some ways to handle it in a good way because the amount of code I've written seems a bit unnecessary and there must be some sort of way to make it simpler.

Let me give you an example:
I'm trying to create a game, and in it there are 5 different balls that you have to avoid. If you get hit by one of them you'll lose. So I typed this code to fix the collision:

Quote
         if (!gamefinished && playerSprite.getPosition().x > obstacleSprite[0].getPosition().x - 30 &&
         playerSprite.getPosition().y > obstacleSprite[0].getPosition().y - 30 &&
         playerSprite.getPosition().x < obstacleSprite[0].getPosition().x + 20 &&
         playerSprite.getPosition().y < obstacleSprite[0].getPosition().y + 30)
      {
         gamefinished = true;
         musicsound.stop();
         endgameText.setString("                          YOU DIED\n\n\n\n\nYOU FINISHED GAME WITH:  " + currentGold + "  GOLD!");
      }

The problem is that I have to repeat this code for all 5 balls, and later on I'm thinking of adding more balls, so that would mean an immense amount of code. This is the case for a lot of things more than collision too, so there's so much code!!

How to make it smoother and easier to read?

thank you in advance!!

edit: to clarify, what I'm looking for is to how to make it happen for all variables in the array. I could look something like:
if (!gamefinished && playerSprite.getPosition().x > obstacleSprite[0, 1, 2, 3, 4, 5].getPosition().x - 30

11
General / Re: Trying to place collision in a class
« on: April 07, 2014, 10:10:26 pm »
No, what you quoted:

Quote
if(playerSprite.getPosition().x + 16 > screenDimensions.x / 2)
    position.x = playerSprite.getPosition().x + 16;
else
    position.x = screenDimensions.x / 2;

has nothing to do with player collision, it sets the screen to follow the player, what I meant was this class:


Quote
class PlayerCollision
{
public:
        PlayerCollision(sf::Sprite playerSprite)
        {
                if (playerSprite.getPosition().x <= 0)
                {
                        cout << "collision";
                        playerSprite.setPosition(0, playerSprite.getPosition().y);
                }
 
                if (playerSprite.getPosition().x >= 1536)
                {
                        playerSprite.setPosition(1536, playerSprite.getPosition().y);
                }
 
                if (playerSprite.getPosition().y <= 32 && playerSprite.getPosition().x >= 833)
                {
                        playerSprite.setPosition(playerSprite.getPosition().x, 32);
                }
        }
};
 

together with:
Quote
PlayerCollision pCol(playerSprite);
in the main loop.

Sorry for not being clear enough :)

Thanks!

12
General / Trying to place collision in a class
« on: April 07, 2014, 09:12:26 pm »
I've been busy trying to place my collision code (so you can't run outside the window) in a class, but seemingly fail to make it work.

Here's my source code:


Quote
#include <SFML/Graphics.hpp>
#include <iostream>
 
using namespace std;
 
 
class PlayerCollision
{
public:
        PlayerCollision(sf::Sprite playerSprite)
        {
                if (playerSprite.getPosition().x <= 0)
                {
                        cout << "collision";
                        playerSprite.setPosition(0, playerSprite.getPosition().y);
                }
 
                if (playerSprite.getPosition().x >= 1536)
                {
                        playerSprite.setPosition(1536, playerSprite.getPosition().y);
                }
 
                if (playerSprite.getPosition().y <= 32 && playerSprite.getPosition().x >= 833)
                {
                        playerSprite.setPosition(playerSprite.getPosition().x, 32);
                }
        }
};
 
int main()
{
        enum Direction { Down, Left, Right, Up };
 
        sf::Vector2i source(1, Down);
 
        sf::Vector2i screenDimensions(800, 600);
 
        float frameCounter = 0, switchFrame = 100, frameSpeed = 500;
 
        sf::RenderWindow window;
        window.create(sf::VideoMode(screenDimensions.x, screenDimensions.y), "SFML", sf::Style::Close);
 
        window.setFramerateLimit(60);
 
        sf::Texture pTexture;
        sf::Sprite playerSprite;
 
 
        sf::Texture bTexture;
        sf::Sprite bImage;
 
        sf::Clock clock;
 
        bool updateFrame = true;
        bool InMovement = false;
 
        if(!pTexture.loadFromFile("Content/player.png"))
                cout << "Error loading player image" << endl;
 
        if(!bTexture.loadFromFile("Content/bg.png"))
                cout << "Error loading background image" << endl;
 
        playerSprite.setTexture(pTexture);
        playerSprite.setPosition(70, 230);
        bImage.setTexture(bTexture);
 
        sf::View view;
 
        view.reset(sf::FloatRect(0, 0, screenDimensions.x, screenDimensions.y));
        view.setViewport(sf::FloatRect(0, 0, 1.0f, 1.0f));
 
        sf::Vector2f position(screenDimensions.x / 2, screenDimensions.y / 2);
 
        while(window.isOpen())
        {
                sf::Event Event;
                while (window.pollEvent(Event))
                {
                        switch(Event.type)
                        {
                        case sf::Event::Closed:
                                window.close();
                                break;
                        }
                }
 
                if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                {
                        source.y = Up;
                        playerSprite.move(0, -3);
                        InMovement = true;
                }
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                {
                        source.y = Down;
                        playerSprite.move(0, 3);
                        InMovement = true;
                }
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                {
                        source.y = Right;
                        playerSprite.move(3, 0);
                        InMovement = true;
 
                }
                else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        source.y = Left;
                        playerSprite.move(-3, 0);
                        InMovement = true;
                }
                else
                {
                        InMovement = false;
                }
 
                if(sf::Mouse::isButtonPressed(sf::Mouse::Left))
                        updateFrame = true;
                else if(sf::Mouse::isButtonPressed(sf::Mouse::Right))
                        updateFrame = false;
 
                if(updateFrame)
                        frameCounter += frameSpeed * clock.restart().asSeconds();
                else
                        frameCounter = 0;
 
                frameCounter = (updateFrame) ? frameCounter + frameSpeed * clock.restart().asSeconds() : 0;
 
                if(InMovement)
                {
                        if(frameCounter >= switchFrame)
                        {
                                frameCounter = 0;
                                source.x++;
                                if(source.x * 32 >= pTexture.getSize().x)
                                        source.x = 0;
                        }
                }
 
                if(playerSprite.getPosition().x + 16 > screenDimensions.x / 2)
                        position.x = playerSprite.getPosition().x + 16;
                else
                        position.x = screenDimensions.x / 2;
 
                if(playerSprite.getPosition().y + 16 > screenDimensions.y / 2)
                        position.y = playerSprite.getPosition().y + 16;
                else
                        position.y = screenDimensions.y / 2;
 
                if(playerSprite.getPosition().x - 16 > screenDimensions.x / 2)
                        position.x = playerSprite.getPosition().x - 16;
                else
                        position.x = screenDimensions.x / 2;
 
                if(playerSprite.getPosition().y - 16 > screenDimensions.y / 2)
                        position.y = playerSprite.getPosition().y - 16;
                else
                        position.y = screenDimensions.y / 2;
 
                view.setCenter(position);
 
                window.setView(view);
 
                PlayerCollision pCol(playerSprite);
 
                playerSprite.setTextureRect(sf::IntRect(source.x * 32, source.y * 32, 32, 32));
                window.draw(bImage);
                window.draw(playerSprite);
                window.display();
        }
 
        return 0;



As you can see, the collision is in a class, and I'm not sure how it works, exactly.

And by the way,

Quote
                if (playerSprite.getPosition().x <= 0)
                {
                        cout << "collision";
                        playerSprite.setPosition(0, playerSprite.getPosition().y);
                }

It actually outputs "collision" in the command prompt, but the collision just doesn't work.

Thanks in advance and have a good evening :)!

13
General / Re: Missing MSVCP110D.dll and 0xc000007b Error
« on: March 30, 2014, 11:06:42 pm »
Thanks, it's working now.

Have a good evening!

14
General / Re: Missing MSVCP110D.dll and 0xc000007b Error
« on: March 30, 2014, 10:24:55 pm »
I'm sorry if it's a stupid question, but what do you mean by "He still needs the release DLLs"?

OK, I compile the game in release mode and use the new .exe file it spits out, but where are the mentioned 'release DLLs' exactly?

I recognise a stupid question when there is one, but I don't understand

15
General / Re: Missing MSVCP110D.dll and 0xc000007b Error
« on: March 30, 2014, 01:46:18 pm »
Right, I didn't even have debug / release in mind.

Oh and he downloaded it from me, there was a MSVCP110D.dll in my Visual Studio folder so I just sent it to him.

I'll try compiling in release and see what happens, thank you.

Pages: [1] 2
anything