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.


Topics - Pikmeir

Pages: [1]
1
Graphics / Drawing darkness around player
« on: October 05, 2012, 03:40:08 am »


This is what I'm working on in my game. I want to have the player only able to see a square or so in front of them.

How I'm doing it is I just have a sprite that's all black except for the center, and I have it move along with the player's position. It works, until the sprite boundaries hit the window boundaries (since this sprite has to be rather large to stay black no matter where the player is on the map), and then the sprite doesn't display in this case.

This is all framed within the rest of the screen, so everything else is going on top of it to hide the edges of the "blackness."

I could only think of one option to fix this:

1) Make 4 differently shaped "blackness" sprites, and change between which is displayed depending on where the player is on the map (divide it into 4 quadrants). This way would work, but it would be a pain in the butt to do and take a long time to implement.

I wish there was some way I could just fill the map area of the screen with black, then remove a hole in the area of the sprite, and have that hole move around. Is there someway I can do that?

Or, is there a better way you think I could do this?

Thank you for your help.

2
General / Can't get VC++ to run with SFML [Solved]
« on: August 02, 2012, 10:26:25 pm »
I just finished following the official SFML tutorial perfectly, but I still get this problem.

Code: [Select]
fatal error LNK1104: cannot open file 'sfml-graphics-s-d.lib'

I switched to Dynamic linking and tried the same thing, and got the same error "sfml-graphics-d.lib." It also does the same thing in Release mode, with both Dynamic and Static linking. I've triple checked that the compiler has the include and lib directories like the tutorial shows.

I checked on the forums, and it seems people with this problem were told that they didn't correctly link the libraries.
Perhaps I'm not linking the libraries correctly, but I did exactly what the tutorial said to do.

It's my fifth time trying to install SFML with VC++ 2010 Express :-(
I'm running Windows Vista 32-bit and already used CMake and nmake on the SFML files (I'm using SFML 2.0) and everything up to there worked fine.

Anyone know what the problem is?

3
General / Making my program work on other machines
« on: August 02, 2012, 10:26:15 am »
I'm working on a game, and before I go too deep into it I want to make sure it works fine on other machines.
First of all, I've read all the tutorials on doing this, so I know I'm supposed to include the SFML dlls, the audio dlls, etc etc (I even included the MinGW dll). I'm using SFML 2 and compiling with MinGW.

My laptop uses 32-bit Windows Vista with an ATI Radeon X1200 graphics card (more like a potato chip with circuitry). Anyway, it works great on my laptop. I put my whole program on a friend's desktop (running Windows 7), and it worked great there too. Tried putting it on another friend's laptop (running Windows Vista, same as me) - but the program just crashes before it can even open. It doesn't give an error message, just crashes and Windows tells me it has to close the program (same as any crash).

I'm not sure how I can fix it, or if I just have to accept that it won't work on everyone's computer. Does anyone have any ideas?

4
System / Help with nested if statements? (sf::Time)
« on: July 30, 2012, 06:16:41 am »
Hey guys,
I'm finally adding timers into my game for using special items and spells. I'm not sure if this is a simple nested if statement problem I'm having, or if it's related to sf::Time.

When I click on the screen, it'll wait 5 seconds (it seems a bit short though) then display the message on the console.
After that, when I click again it'll immediately display the message again, instead of waiting the appropriate 5 seconds. Isn't it supposed to have reset to default, and not automatically show the message for another 5 seconds? Anyway I'm a bit stumped here.

Here's the shortest possible example of this I could replicate (this of course isn't my actual code since it's way too long, but this is set up the same way as my real program is).

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <iostream>

std::vector <sf::Time> timerArray (200); // one for each spell
sf::Time currentTime;

// Every spell gets a 5 second timer
void castSpell(unsigned int spellNumber)
{ timerArray.at(spellNumber) = currentTime + sf::seconds(5); }

int main () {
        sf::RenderWindow Screen (sf::VideoMode (800, 600, 32), "Game");

        sf::Clock clock;
        sf::Time startTime = clock.restart();
        sf::Time currentTime = clock.getElapsedTime();

        // Activate all consumable timers (set to startTime)
        for (int i = 1; i <= 199; i++)
        { timerArray.at(i) = startTime; } // default is startTime

        while (Screen.isOpen()) {
                Screen.clear();
                currentTime = clock.getElapsedTime();
       
                sf::Event Event;
                while (Screen.pollEvent (Event)) {
                        if (Event.type == sf::Event::Closed)
                        { Screen.close(); }
                        if (Event.type == sf::Event::MouseButtonPressed)
                        { castSpell(4); }
                }

                // Remove effects of spells (if any)
                for (int i = 1; i <= 199; i++)
                {
                        if (timerArray.at(i) != startTime) // if not in default setting
                        {
                                if (timerArray.at(i) <= currentTime) // if the current time surpasses the set timer
                                {
                                        timerArray.at(i) = startTime; // reset the timer to default
                                        switch (i)
                                        {
                                                case 4: // Spell # 4
                                                        std::cout << "Death spell has worn off!" << std::endl;
                                                        break;
                                                default:
                                                        break;
                                        }
                                }
                        }
                }

                Screen.display();
        }

        return 0;
}

5
Graphics / Help with RPG inventory system (solved) Thanks!
« on: July 09, 2012, 03:14:04 am »
I'm new to SFML (2.0), C++, and new to programming, so please be nice on my code.. I apologize it's so long, but this is the bare minimum I think I can post to explain my problem since I'm stumped. (If you want the whole code, I have no problem giving it out to anyone). With that said...

I'm trying to make an RPG game (here are some screenshots: http://imgur.com/a/vxd9B - pardon the Paint graphics, but I suck at drawing and I'm fine with that), and up until now everything's been going fine. I stressed for about a week about how to make an inventory system, and came up with a solution that semi-works, but is giving me issues.

I declared some global variables:
sf::Texture textureArray[95];  // textures for sprites for slots 1-96
sf::Sprite spriteArray[95];      // sprites for spots 1-96
sf::FloatRect invRect[95];      // floatRect for interacting with spots 1-96

In main(), before the game's while loop, I create/load all my textures, and then I do this from 0-95:
spriteArray[0].setPosition(INV_1_X, INV_1_Y); // INV_1_X and Y are pre-defined coords for where to draw the sprites
invRect[0] = sf::FloatRect(INV_1_X, INV_1_Y, INV_SIZE_X, INV_SIZE_Y); // INV_SIZE_X and Y are pre-defined sizes for the boxes

I then set all of the textureArray[] assets from 0-95 to empty by doing this:
for (int i = 0; i < 95; i++) { textureArray[i] = invEmpty; }

Then I give the player some test items:
addItem(invHPot); // I added this line several times with various items

In the game's while loop, if the inventory window is open I do this:
for (int i = 0; i < 96; i++)
{
        if (cursor_box.intersects(invRect[i])) // cursor_box is the floatRect for the cursor
        {
                selectInv = i;
                std::cout << "SELECTED INV SLOT # " << i + 1 << "." << std::endl; // for testing
        }
}

if (cursor_box.intersects(buttonDispose_box)) // if they click DISPOSE after selecting an item
{
        delItem(selectInv);
        std::cout<<"DISPOSE THIS ITEM"<<std::endl; // for testing
        selectInv = -1; // reset selectInv
}
 

And temporarily, if the player clicks the MOVE button below DISPOSE, I made it run addItem(invHPot) just to test if the system's working. (this function is below)

Here are the two functions for adding and deleting items from the inventory:
void delItem(int selectInv) // selectInv is a number 0-95 and is decided from the functions above (when the player clicks in a space)
{
        sf::Texture invEmpty;
        invEmpty.loadFromFile("res/images/inv/invEmpty.png");
        textureArray[selectInv] = invEmpty; // a blank 5x5 png texture
}

void addItem(sf::Texture textureName) // Inv spot 0-95
{
        int i;
        for (i = 0; i < 95; i++)
        {
                if (textureArray[i].getSize().x == 5) // invEmpty is 5x5 pixels, others are 43x43
                {
                        textureArray[i] = textureName;
                        break;
                }
        }
}

Then toward the end of main(), before showing the screen I do the following:
// Link/Set sprites to appropriate textures
for (int i = 0; i < 95; i++)
{ spriteArray[i].setTexture(textureArray[i]); // now the spriteArray and textureArray elements should be linked}

// Display inventory items
for (int i = 0; i < 95; i++)
{ Screen.draw(spriteArray[i]); // draw all of the sprites }

------------------------------------

Phew, that was long. So what the problem is, is sometimes the program crashes randomly when I open the inventory screen. When it doesn't crash, this is what happens:

The items display fine (I usually try addItem with at least 5-30 items, and they display fine). The selecting and deleting items works fine. If I delete an item, it goes away properly. But when I try to add an item while playing, it will only replace one of the empty spots. It won't let me just add items, unless I've "deleted" one already using delItem (the DISPOSE button). I'm not sure how to fix this. I've tried re-arranging things, but each time I get the same problem (when I was testing it with only 12 elements, before changing it to the full 96, it didn't crash, but I had the same problem).

Please tell me I'm stupid "because there's such an easy solution." I hope someone here can help me out.

Pages: [1]
anything