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

Pages: 1 2 [3] 4
31
General / SFML GameDev Book Chapter 3 Problems
« on: August 13, 2013, 05:07:40 am »
So I've been reading the book.  And I ended up just copying the code from https://github.com/SFML/SFML-Game-Development-Book/tree/master/03_World and then I'm going to re-read the chapter so that I know what's going on without having to type everything in.

When I run it the background displays and scrolls, but none of the planes are displayed.
Is there anyway that I can fix this?

Thank you!

32
General / Re: Other people can't run my programs...
« on: August 13, 2013, 05:04:34 am »
I had this problem as well.  There are several dll files that you need.  I always just end up putting them directly in the file with your exe in it.  You need:

    libsndfile-1.dll
    msvcp110.dll (I have 110 becaues I'm using VC 11 compiler)
    msvcp110d.dll
    msvcr110.dll
    msvcr110d.dll
    openal32.dll

It seems like you know where the msvcp and msvcr files are.  The lbsndfile-1.dll and openal32.dll is located in the SFML-2.1/bin folder.

If you just add those to the folder it should work on other computers!
Good luck with your project.  ;)

33
General / Re: Some Bounding Box Help
« on: July 30, 2013, 07:45:10 pm »
Yeah, the two collision functions were an earlier test that I then realized were exactly the same.  Unfortunately I can't seem to get it to work though, should I call p1.update() in multiple places?  If so, where?

Well, as a side note.  What can I do to the player movement?  Like, when the player collides with the box, what should I do the the player's movement?  Is what I'm using currently ok?  Because it seems ... awkward. 

34
General / Some Bounding Box Help
« on: July 29, 2013, 11:48:26 pm »
Hello again everybody!

So right now I'm just trying to add some collision.  I have a tiled map ( a .txt file with different values for different textures) I'm just going to try for some bounding box collision at the moment.  This is what I have so far, but when I move the player into the enemy box, it just gets stuck.  How can I fix that, or is there a better way to implement collision with a tiled map?  Actually, a better system of implementing collision would be greatly appreciated! :D

#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
#include <cctype>
#include <string>
#include <vector>

const int TILE_SIZE = 32;

class Player
{
public:
        sf::RectangleShape rect;
        float top, bottom, left, right;

        Player(sf::Vector2f position, sf::Vector2f size, sf::Color color)
        {
                rect.setPosition(position);
                rect.setSize(size);
                rect.setFillColor(color);
        }

        void Update(void)
        {
                top = rect.getPosition().y;
                bottom = rect.getPosition().y + rect.getSize().y;
                left = rect.getPosition().x;
                right = rect.getPosition().x + rect.getSize().x;
        }

        bool VertCollision(Player p)
        {
                if (top > p.bottom || bottom < p.top || left > p.right || right < p.left)
                        return false;

                return true;
        }

        bool HorzCollision(Player p)
        {
                if (top > p.bottom || bottom < p.top || left > p.right || right < p.left)
                        return false;

                return true;
        }
};

int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 480, 32), "Bounding Box Collision");

        Player p1(Player(sf::Vector2f(10, 10), sf::Vector2f(20, 20), sf::Color::Green)),
                p2(Player(sf::Vector2f(100, 100), sf::Vector2f(20, 20), sf::Color::Red));

        while (window.isOpen())
        {
                sf::Event event;

                while (window.pollEvent(event))
                {
                        switch (event.type)
                        {
                        case::sf::Event::Closed:
                                window.close();
                                break;
                        default:
                                break;
                        }
                }

                p1.Update();
                p2.Update();

                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
                {
                        p1.rect.move(0, -1.0f);
                        if (p1.VertCollision(p2))
                                p1.rect.move(0, 1.0f);
                }
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
                {
                        p1.rect.move(0, 1.0f);
                        if (p1.VertCollision(p2))
                                p1.rect.move(0, -1.0f);
                }      
                if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
                {
                        p1.rect.move(-1.0f, 0);
                        if (p1.HorzCollision(p2))
                                p1.rect.move(1.0f, 0);
                }
                else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
                {
                        p1.rect.move(1.0f, 0);
                        if (p1.HorzCollision(p2))
                                p1.rect.move(-1.0f, 0);
                }

                window.clear();

                window.draw(p1.rect);
                window.draw(p2.rect);

                window.display();
        }

        return 0;
}

Thanks!

35
Window / Re: Render Function in the Player Class
« on: July 19, 2013, 10:14:55 pm »
Actually, I made this  post on stackoverflow (gamedev) that has to do with this.  I followed another tutorial, but it's not working.  Could you guys look at it please?  I'm not getting much luck there, but I don't really want to make another post here, because it's pretty similar.

Link: http://gamedev.stackexchange.com/questions/59404/sfml-renderwindow-unhandled-exception

Thanks!

36
Window / Re: Render Function in the Player Class
« on: July 18, 2013, 05:50:57 am »
Hmm, I tried this:
Player.cpp :
sf::Sprite* CPlayer::GetPlayer()
{
        if (!pTexture.loadFromFile("player.png"))
                std::cout << "Could not load player image" << std::endl;

        pImage.setTexture(pTexture);
        pImage.setPosition(384, 284);
        pImage.setTextureRect(sf::IntRect(source.x * 32, source.y * 32, 32, 32));

        return &pImage;
}

Setup.cpp:
window.draw(player -> GetPlayer());

But there's an error (red line underneath the . ) that says: "No instance of overloaded function 'sf::RenderWindow draw' matches the argument list argument types are: (sf::Sprite*) object type is sf::RenderWindow."

How can I fix this?

37
Window / Render Function in the Player Class
« on: July 18, 2013, 02:00:56 am »
Hello everybody,

So I had a working program before but it only consisted of a header file and a cpp file.  It basically created a player sprite that moved using the arrow keys.

But now I'm splitting things up into different classes and I've encountered a problem.  In my game loop I can call:
window.draw(playerImage);
but I can't do that in the player class (at least I don't know how to).

What's giving me trouble is that I can't access the window variable from another class. I've tried adding this in my setup class and calling it from the player class, but it doesn't work:
//Setup class:
void CSetup::Render(sf::Texture texture, sf::Sprite sprite, std::string path, float x, float y)
{
        if (!texture.loadFromFile(path))
                std::cout << "Could not find " << path << std::endl;

        sprite.setTexture(texture);
        sprite.setPosition(x, y);

        window.draw(sprite);
}

//Player class
void CPlayer::RenderPlayer(void)
{
        setup -> Render(pTexture, pImage, "player.png", 384, 284);
}

When I try to do this, the screen just appears white and I can't exit the window except by closing the debug console.

How can I draw a Sprite from the player class?

Thanks for your time!

38
General / Re: Writing Good Code
« on: July 17, 2013, 08:25:04 pm »

Here is an example of what not to do. Mind you, that (commercial) game still shipped.

Oh god.  I can't even look at that. I opened up the link and cringed. :-\  It's hard to believe that that actually shipped...

And I'm working on putting everything into different classes right now actually, it's much easier to look at. :P

39
General / Re: Writing Good Code
« on: July 16, 2013, 11:17:52 pm »
Woops, I meant I'll definitely get C++ Primer, I read through the "Look Inside!" section on amazon, and it seems pretty informative.

40
General / Re: Writing Good Code
« on: July 16, 2013, 10:15:16 pm »
Ok, I'll definitely get the book. 

41
General / Re: Writing Good Code
« on: July 16, 2013, 09:53:35 pm »
Ok, thanks!   I'll definitely check that book out.  Anything for making programming less frustrating.  It's an addicting puzzle but sometimes it can be so frustrating. :)

Just as a side note, how does the code in the github link look?

EDIT: Forgot to mention.  I've heard of a lot of people that learned C++ through TheNewBoston.  Would those tutorials be a decent substitute?  Or should I just stick with the book?

42
General / Writing Good Code
« on: July 16, 2013, 08:07:51 pm »
Hello everybody!

I'm relatively new with C++ (I have a basic understanding and so far I really like it) and I'm pretty proficient with Java.  Learning Java really helped learning C++ but the structures within cpp files and java classes is TOTALLY different.  I've just been following CodingMadeEasy's tutorials and have my code has just gotten bigger and bigger.  However, it's really ugly and sometimes hard to follow, so I split everything into different functions and I call those functions in the constructor.  Then I call the constructor in the main method.  Here's my code.

https://github.com/ChaoticCactus/SFMLProject

You can ignore the first 2 files. 

I'm just curious how I can improve my coding.

Thanks!


43
General / Re: SFML Project for VS 2012
« on: July 15, 2013, 02:28:11 am »
Ok thanks.  I just copy pasted that from another tutorial, so not much thought went into it. 

Oh, I actually set it to All Configurations when I was adding the lib and include directories.  Should I only do the Active(Debug) and Release Directories separately?

EDIT: Oh wow! I got it to work.  I followed the tutorial really closely and I got an error that said I was using the wrong set of SFML (I was using 64 bit, I should have used 32 bit... ) and now it works!

Thanks for the help! :D

44
General / Re: SFML Project for VS 2012
« on: July 15, 2013, 02:03:59 am »
Ok, sorry I had some stuff to do and so wasn't able to reply right away.

I followed the tutorial and this is what happened.

I just used this code that I found from another tutorial:
#include <SFML/Window.hpp>
 
using namespace sf;
 
int main()
{
    VideoMode videoMode(320,240);
    Window window(videoMode,"Basic Display Window");
    window.display();
    system("PAUSE");
    window.close();
    return EXIT_SUCCESS;
}

And I get a total of 8 errors, all of which are along the lines of this:
Error   2       error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::~String(void)" (__imp_??1String@sf@@QAE@XZ) referenced in function _main        c:\Users\Connor\documents\visual studio 2012\Projects\SFML\SFML\Source.obj      SFML
 

45
General / Re: SFML Project for VS 2012
« on: July 15, 2013, 12:00:48 am »
Wait, so I downloaded the SFML 2.0 file from the downloads directory that's on this website.  So do I still have to do the CMake tutorial?

Also, the one that I downloaded was the "VC++ 11 (2012) 64 Bit" so does that mean that it's for Visual Studio 2012?

Pages: 1 2 [3] 4