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

Pages: [1]
1
General / Basic inventory tutorial (SFML-1.6)
« on: July 11, 2012, 02:01:48 pm »
Hey, I've thought to make a post with the inventory system that (as a beginner) I'm fairly proud of. Just a little disclaimer, if you're a good programmer then this post won't be of use to you, as you'd be able to come up with a totally better system including pointers, iterations etc etc. This is programmed in SFML 1.6 but can easily be updated to SFML2! I also know that things can be done a lot better than how I've gone about them.

This post is more aimed at the newer people to SFML, whom have gone over the first tutorials but are seeking out examples of such.

Down to business.

For my inventory system, I had a total of 6 functions: InventoryDisplay, InventoryAdd, InventoryRemove, InventoryUpdate, InventoryEquip and InventoryUnequip as well as a few global variables.

The first thing to do is to create some items to work with; this is using the normal sprite creation tutorial.

--- Global Variables ---

I'll now shed some light on the global variables:
Code: [Select]
int Slot[48] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

int Item1Have[3] = {0,0,0}; int Item3Have[3] = {0,0,0};
int Item2Have[3] = {0,0,0}; int Item4Have[3] = {0,0,0};

int Gold = 0;

int SwordEquipped = 0; int OffHandEquipped = 0;
int BracersEquipped = 0; int HandsEquipped = 0;
int HelmetEquipped = 0; int ChestEquipped = 0; int LegsEquipped = 0;

Here we have an array for the inventory slots (48 of them), some more arrays for the different items then integers for Gold, then equipped armours and weapons.

Slot[48]: I use this array to tell the program which slots have been taken. We'll focus more on this in InventoryAdd.

Item1Have[3]: This array is for Item1 and has 3 values of 0. Item1Have[0] is to tell the program if that item is in your inventory. Item1Have[1] stores the slot that it is in. Item1Have[2] tells the program if it has been equipped.

The rest are pretty self explanatory.

--- InventoryDisplay ---

This is the function to call when you press the inventory key:
Code: [Select]
if( (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 165 && Input.GetMouseY() <= 197) || (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237) ||
            (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) || (Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 125 && Input.GetMouseY() <= 157) ||

           (Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) || (Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 145 && Input.GetMouseY() <= 177) ||
           (Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237)||

           (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) || (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 125 && Input.GetMouseY() <= 157) ||
           (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 165 && Input.GetMouseY() <= 197) || (Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237) ||

           (Input.GetMouseX() >= 55  && Input.GetMouseX() <= 87  && (Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242 || Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282 || Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322 || Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362 || Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402 || Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442)) ||
           (Input.GetMouseX() >= 95  && Input.GetMouseX() <= 127 && (Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242 || Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282 || Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322 || Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362 || Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402 || Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442)) ||
           (Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && (Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242 || Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282 || Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322 || Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362 || Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402 || Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442)) ||
           (Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && (Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242 || Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282 || Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322 || Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362 || Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402 || Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442)) ||
           (Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && (Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242 || Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282 || Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322 || Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362 || Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402 || Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442)) ||
           (Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && (Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242 || Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282 || Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322 || Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362 || Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402 || Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442)) ||
           (Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && (Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242 || Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282 || Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322 || Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362 || Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402 || Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442)) ||
           (Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && (Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242 || Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282 || Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322 || Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362 || Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402 || Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442)))
        {
            int i; int e;
            if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 0;
            if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 1;
            if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 2;
            if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 3;
            if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 4;
            if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 5;
            if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 6;
            if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 210 && Input.GetMouseY() <= 242) i = 7;

            if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 8;
            if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 9;
            if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 10;
            if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 11;
            if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 12;
            if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 13;
            if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 14;
            if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 250 && Input.GetMouseY() <= 282) i = 15;

            if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322) i = 16;
            if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322) i = 17;
            if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322) i = 18;
            if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322) i = 19;
            if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322) i = 20;
            if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322) i = 21;
            if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322) i = 22;
            if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 290 && Input.GetMouseY() <= 322) i = 23;

            if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362) i = 24;
            if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362) i = 25;
            if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362) i = 26;
            if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362) i = 27;
            if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362) i = 28;
            if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362) i = 29;
            if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362) i = 30;
            if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 330 && Input.GetMouseY() <= 362) i = 31;

            if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402) i = 32;
            if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402) i = 33;
            if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402) i = 34;
            if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402) i = 35;
            if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402) i = 36;
            if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402) i = 37;
            if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402) i = 38;
            if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 370 && Input.GetMouseY() <= 402) i = 39;

            if(Input.GetMouseX() >= 55 && Input.GetMouseX() <= 87 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 40;
            if(Input.GetMouseX() >= 95 && Input.GetMouseX() <= 127 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 41;
            if(Input.GetMouseX() >= 135 && Input.GetMouseX() <= 167 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 42;
            if(Input.GetMouseX() >= 175 && Input.GetMouseX() <= 207 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 43;
            if(Input.GetMouseX() >= 215 && Input.GetMouseX() <= 247 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 44;
            if(Input.GetMouseX() >= 255 && Input.GetMouseX() <= 287 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 45;
            if(Input.GetMouseX() >= 295 && Input.GetMouseX() <= 327 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 46;
            if(Input.GetMouseX() >= 335 && Input.GetMouseX() <= 367 && Input.GetMouseY() >= 410 && Input.GetMouseY() <= 442) i = 47;

           if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) e = 0; // Bracers
           if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 125 && Input.GetMouseY() <= 157) e = 1; // Hands
           if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 165 && Input.GetMouseY() <= 197) e = 2; // Sword
           if(Input.GetMouseX() >= 545 && Input.GetMouseX() <= 567 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237) e = 3; // Off hand

           if(Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) e = 4; // Helmet
           if(Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 145 && Input.GetMouseY() <= 177) e = 5; // Chest
           if(Input.GetMouseX() >= 675 && Input.GetMouseX() <= 707 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237)  e = 6; // Legs

           if(Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 85 && Input.GetMouseY() <= 117) e = 7; // Neck 1
           if(Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 125 && Input.GetMouseY() <= 157) e = 8; // Neck 2
           if(Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 165 && Input.GetMouseY() <= 197) e = 9; // Ring 1
           if(Input.GetMouseX() >= 780 && Input.GetMouseX() <= 807 && Input.GetMouseY() >= 205 && Input.GetMouseY() <= 237) e = 10; // Ring 2

            // Item Equip/Use
            if(Item1Have[0] == 1 && Item1Have[1] == i && SwordEquipped != 1 && ((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.Button == sf::Mouse::Left))) { InventoryEquip(1); if(Quest3 == 1 && Quest4 == 0 && g_QuestStatus == 1){g_QuestStatus = 2; } }

            // Armour Unequip
            if(e == 2 && SwordEquipped == 1 && Item1Have[2] == 1 &&((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.Button == sf::Mouse::Left))) { InventoryUnequip(1); }

            // Equipment delete
            if(App.GetInput().IsKeyDown(sf::Key::D) && ((Event.Type == sf::Event::MouseButtonPressed) && (Event.MouseButton.Button == sf::Mouse::Right)))
            {
                if(Item1Have[0] == 1 && Item1Have[1] == i)  InventoryRemove(1);
                if(Item2Have[0] == 1 && Item2Have[1] == i)  InventoryRemove(2);
                if(Item3Have[0] == 1 && Item3Have[1] == i)  InventoryRemove(3);
                if(Item4Have[0] == 1 && Item4Have[1] == i)  InventoryRemove(4);
            }

            // Item Descriptions
            if((Item1Have[0] == 1 && Item1Have[1] == i) || SwordEquipped == 1 && e == 2) {Description.SetText("A simple shortsword.\n+1 Physical AP.\n\n(Using this item will equip/unequip it)"); scrollOver = 1;}
            if(Item2Have[0] == 1 && Item2Have[1] == i) {Description.SetText("A health potion."); scrollOver = 1;}
            if(Item3Have[0] == 1 && Item3Have[1] == i) {Description.SetText("A mana potion."); scrollOver = 1;}
            if(Item4Have[0] == 1 && Item4Have[1] == i) {Description.SetText("Pet Rock.\nYour pet rock will always love you."); scrollOver = 1;}
        }
        else { Description.SetText(""); scrollOver = 0; }

NOTE: It's to note that inventory spaces are 32x32 and the massive if statement is check whether the mouse is inside any of these spaces, then it changes the variable 'i' to reflect which space is being hovered over or 'e' for an equipped piece of armour.

I'm not going to go through everything here (unless someone is confused), but look mainly at the way I equip, unequip or delete armour.

--- InventoryAdd ---

Here is the way to add an item to the inventory. To actually add something to the inventory during the game, just call InventoryAdd(2) the number being the item.

Code: [Select]
int InventoryAdd(int ItemID)
{
            int i = 0;
            int x = 0;
            int y = 0;
            while(i < 49)
            {
                if(Slot[i] == 0)
                {
                if(i == 0) {x = 55; y = 210;}
                if(i == 1) {x = 95; y = 210;}
                if(i == 2) {x = 135; y = 210;}
                if(i == 3) {x = 175; y = 210;}
                if(i == 4) {x = 215; y = 210;}
                if(i == 5) {x = 255; y = 210;}
                if(i == 6) {x = 295; y = 210;}
                if(i == 7) {x = 335; y = 210;}

                if(i == 8) {x = 55; y = 250;}
                if(i == 9) {x = 95; y = 250;}
                if(i == 10) {x = 135; y = 250;}
                if(i == 11) {x = 175; y = 250;}
                if(i == 12) {x = 215; y = 250;}
                if(i == 13) {x = 255; y = 250;}
                if(i == 14) {x = 295; y = 250;}
                if(i == 15) {x = 335; y = 250;}

                if(i == 16) {x = 55; y = 290;}
                if(i == 17) {x = 95; y = 290;}
                if(i == 18) {x = 135; y = 290;}
                if(i == 19) {x = 175; y = 290;}
                if(i == 20) {x = 215; y = 290;}
                if(i == 21) {x = 255; y = 290;}
                if(i == 22) {x = 295; y = 290;}
                if(i == 23) {x = 335; y = 290;}

                if(i == 24) {x = 55; y = 330;}
                if(i == 25) {x = 95; y = 330;}
                if(i == 26) {x = 135; y = 330;}
                if(i == 27) {x = 175; y = 330;}
                if(i == 28) {x = 215; y = 330;}
                if(i == 29) {x = 255; y = 330;}
                if(i == 30) {x = 295; y = 330;}
                if(i == 31) {x = 335; y = 330;}

                if(i == 32) {x = 55; y = 370;}
                if(i == 33) {x = 95; y = 370;}
                if(i == 34) {x = 135; y = 370;}
                if(i == 35) {x = 175; y = 370;}
                if(i == 36) {x = 215; y = 370;}
                if(i == 37) {x = 255; y = 370;}
                if(i == 38) {x = 295; y = 370;}
                if(i == 39) {x = 335; y = 370;}

                if(i == 40) {x = 55; y = 410;}
                if(i == 41) {x = 95; y = 410;}
                if(i == 42) {x = 135; y = 410;}
                if(i == 43) {x = 175; y = 410;}
                if(i == 44) {x = 215; y = 410;}
                if(i == 45) {x = 255; y = 410;}
                if(i == 46) {x = 295; y = 410;}
                if(i == 47) {x = 335; y = 410;}

                if(ItemID == 1) { Item1.SetPosition(x,y); Item1Have[0] = 1; Item1Have[1] = i; Slot[i] = 1; return 0; }
                if(ItemID == 2) { Item2.SetPosition(x,y); Item2Have[0] = 1; Item2Have[1] = i; Slot[i] = 1; return 0; }
                if(ItemID == 3) { Item3.SetPosition(x,y); Item3Have[0] = 1; Item3Have[1] = i; Slot[i] = 1; return 0; }
                if(ItemID == 4) { Item4.SetPosition(x,y); Item4Have[0] = 1; Item4Have[1] = i; Slot[i] = 1; return 0; }
                }
                i++;
            }
}

The way this works, is it declares some variables, then it going into the while loop (while (i < 49)) then it goes through each slot and asks if it's available, if it isn't, then 'i' is incremented and then the next slot is tested for availability.

If a slot is available (lets say i = 2 so slot 3 is available, then it puts x and y to where slot 3 is, then it gets the ItemID, sets the position of the item, tells it that it's been added, puts in the slot it's been added to, fills the slot then ends the function with 'return 0'.

--- InventoryRemove ---
Code: [Select]
int InventoryRemove(int ItemID)
{
    if(ItemID == 1) {Item1Have[0] = 0; Slot[Item1Have[1]] = 0; Item1Have[1] = 0; return 0;}
    if(ItemID == 2) {Item2Have[0] = 0; Slot[Item2Have[1]] = 0; Item2Have[1] = 0; return 0;}
    if(ItemID == 3) {Item3Have[0] = 0; Slot[Item3Have[1]] = 0; Item3Have[1] = 0; return 0;}
    if(ItemID == 4) {Item4Have[0] = 0; Slot[Item4Have[1]] = 0; Item4Have[1] = 0; return 0;}
}
This then removes an item from the program supplying an ItemID when the function is called. It resets everything to tell the program that that slot is now free for another item to fill it's place.

--- InventoryUpdate ---
Code: [Select]

int InventoryUpdate()
{
    Health.SetText(convertInt(Stats[0]));
    Mana.SetText(convertInt(Stats[1]));
    Stamina.SetText(convertInt(Stats[2]));
    Defense.SetText(convertInt(Stats[3]));
    MagicResist.SetText(convertInt(Stats[4]));
    PhysicalAP.SetText(convertInt(Stats[5]));
    MagicalAP.SetText(convertInt(Stats[6]));
}
This is what updates the stats of the character when an item is equipped, as they are shown in the inventory screen. This makes sure that when an item is equipped, that it will show the new stats straight away.

--- InventoryEquip & InventoryUnequip ---
Code: [Select]
int InventoryEquip(int ItemID)
{
    if(ItemID == 1) { SwordEquipped = 1; InventoryRemove(1); Item1Have[2] = 1; Stats[5] += 1; InventoryUpdate(); }
}
This will equip the certain item, in this case, a sword. It changes the variable SwordEquipped to 1, to tell that that slot is taken then it removes it from the inventory, changes the Item2Have[2] variable to show it's been equipped then gives the stat change and updates it!

Whereas, the InventoryUnequip does the exact opposite:
Code: [Select]
int InventoryUnequip(int ItemID)
{
    if(ItemID == 1) { SwordEquipped = 0; InventoryAdd(1); Item1Have[2] = 0; Stats[5] -= 1; InventoryUpdate(); }
}

Hopefully this can help some of the beginners of SFML (and coding) to give them an idea of one way to implement a basic inventory. Remember to change it to your project's needs!

EDIT: Fixed some formatting.

2
General / Issue with movement
« on: July 08, 2012, 05:51:20 pm »
Hey, a week ago, I reinstalled Ubuntu alongside windows in order to see how it'd run a few games, in the end decided to switch back, as a 256mb gfx card isn't going to run games that smoothly under wine. In the end I went back to Windows 7, and decided to work a little on my game. After compiling the exact same file that had been working before I installed linux, it built fine and started up, but when going into the game, the movement doesn't work, nor does Inventory or party display :/

I've tried loads of things, as I really wanna get this working and even after reinstalling Windows 7 this morning, it hasn't solved anything.

I was wondering if anyone on the forums could look at the code and help me with this, otherwise I'm most likely to either scrap it & make a different type of game, or I might even try and recode it to SFML2 if I feel like doing that.

http://www.filedropper.com/beforethereign

Anyone that can contribute to helping, I thank you dearly!


EDIT: My best idea is that something is running over the maingame function, as I've put some couts around and they don't call when pressing a button. Plus, clicking a few times on the screen will make it not respond.

3
General / Problems with the SFML2 tutorial program
« on: July 04, 2012, 12:41:47 pm »
I followed the SFML 2 tutorial step by step (I believe) but it comes up with these errors (after a fresh install of codeblocks as I was having different errors before:

Code: [Select]
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Config.hpp|146|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Time.hpp|34|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Clock.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Err.hpp|32|error: ostream: No such file or directory|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Err.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\InputStream.hpp|34|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\NonCopyable.hpp|34|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Lock.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Mutex.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Sleep.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\String.hpp|32|error: locale: No such file or directory|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\String.hpp|33|error: string: No such file or directory|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\String.hpp|36|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Thread.hpp|33|error: cstdlib: No such file or directory|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Thread.hpp|36|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\ThreadLocal.hpp|36|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\ThreadLocalPtr.hpp|34|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\ThreadLocalPtr.inl|26|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Utf.hpp|32|error: algorithm: No such file or directory|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Utf.hpp|38|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Vector2.hpp|29|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\System\Vector3.hpp|29|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\GlResource.hpp|34|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\ContextSettings.hpp|29|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\Context.hpp|37|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\Joystick.hpp|34|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\Keyboard.hpp|34|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\Mouse.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\Event.hpp|37|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\VideoMode.hpp|32|error: vector: No such file or directory|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\VideoMode.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\WindowHandle.hpp|38|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\WindowStyle.hpp|29|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Window\Window.hpp|43|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\BlendMode.hpp|28|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Color.hpp|34|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Rect.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Glyph.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Image.hpp|38|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Texture.hpp|36|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Font.hpp|37|error: map: No such file or directory|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Font.hpp|42|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Transform.hpp|36|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\RenderStates.hpp|36|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\View.hpp|37|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\PrimitiveType.hpp|28|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Vertex.hpp|36|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\RenderTarget.hpp|43|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\RenderTexture.hpp|36|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\RenderWindow.hpp|38|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Shader.hpp|42|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Drawable.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Transformable.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\VertexArray.hpp|39|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Shape.hpp|38|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\CircleShape.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\RectangleShape.hpp|35|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\ConvexShape.hpp|36|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Sprite.hpp|38|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\SFML-2\include\SFML\Graphics\Text.hpp|42|error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sf'|
C:\Users\aBallofWin\Documents\sfml2\test.c||In function 'main':|
C:\Users\aBallofWin\Documents\sfml2\test.c|5|error: expected expression before ':' token|
C:\Users\aBallofWin\Documents\sfml2\test.c|6|error: duplicate label 'sf'|
C:\Users\aBallofWin\Documents\sfml2\test.c|5|note: previous definition of 'sf' was here|
C:\Users\aBallofWin\Documents\sfml2\test.c|6|error: expected expression before ':' token|
C:\Users\aBallofWin\Documents\sfml2\test.c|8|error: 'window' undeclared (first use in this function)|
C:\Users\aBallofWin\Documents\sfml2\test.c|8|error: (Each undeclared identifier is reported only once|
C:\Users\aBallofWin\Documents\sfml2\test.c|8|error: for each function it appears in.)|
C:\Users\aBallofWin\Documents\sfml2\test.c|10|error: duplicate label 'sf'|
C:\Users\aBallofWin\Documents\sfml2\test.c|5|note: previous definition of 'sf' was here|
C:\Users\aBallofWin\Documents\sfml2\test.c|10|error: expected expression before ':' token|
C:\Users\aBallofWin\Documents\sfml2\test.c|11|error: 'event' undeclared (first use in this function)|
C:\Users\aBallofWin\Documents\sfml2\test.c|13|error: 'sf' undeclared (first use in this function)|
C:\Users\aBallofWin\Documents\sfml2\test.c|13|error: expected ')' before ':' token|
C:\Users\aBallofWin\Documents\sfml2\test.c|18|error: 'text' undeclared (first use in this function)|
C:\Users\aBallofWin\Documents\sfml2\test.c|5|warning: label 'sf' defined but not used|
||=== Build finished: 72 errors, 1 warnings ===|

I wanted to try out libMy but due to being in sfml2 I tried the tutorial and this happened :( Any suggestions?

4
SFML projects / [Revived] Before the Reign
« on: March 14, 2012, 08:18:39 pm »
Hey all, I'm back!

I'm in Uni at the moment (Games Technology) and have decided to carry on with BTR. Development will be sluggish as I do have a lot of work to do. I've worked out some bugs that prevented me from continuing before. A new menu and a few fixes have been added so far.

The majority of work at the moment will be centered towards cleaning up the code, getting it a bit more efficient and getting it working on most (hopefully all) systems.

I'm going to wait a little longer before posting up some images, I want to work on designing some more parts of the game before doing so.

Latest version will always be available from my dropbox: https://dl.dropbox.com/u/106198621/Game%20release.zip


Please reply what you think plus any bugs or errors you may receive.

Cheers :)

5
Graphics / Drawing a number from a function
« on: January 15, 2012, 02:27:32 pm »
I'm currently coding a battle system, and I'm having a little trouble with displaying a number from a function.

What I need to do is display the hero's and enemy's hp, and to get the enemy's hp, i have a function that in a text based environment I used to call with:

cout << enemy.GetHP();

But I'm not to sure how to keep the number updated on the screen. I tried

    sf::String anyText;

    std::stringstream enemyhp;
    enemyhp << enemy.GetHP();
    anyText.SetText(enemyhp.str());

    anyText.SetFont(Font);
      anyText.SetSize(30);
      anyText.SetColor(sf::Color::Black);
      anyText.SetPosition(20.f,100.f);

and drew it on the screen, but it doesn't update :( anyone know how i could do this?


Cheers,

Jake

6
Graphics / Loop problems with animation (AniSprite)
« on: January 09, 2012, 01:03:59 am »
I've recently decided to move my game from a top down view to a more 2d view with animated sprites and I've got the main sprite animated using AniSprite, apart when I've put it into my main game .hpp to play the animation when the character moves.

I've spent about 5 hours trying to get it to work, tried everything I could think off to get it to move when I hold down an arrow key, even rewriting most of this part of the program.

The thing is, is that when I move left for example, I want the animation to keep on playing until I release the left key, here's the initial movement coding:
Code: [Select]
if (cantmove == 0) ///cant move if 1

{
if(App.GetInput().IsKeyDown(sf::Key::Left))

{
map.Move(speed,0); map3.Move(speed,0);

guy.Move(speed,0); woman.Move(speed,0);

woman2.Move(speed,0);

if (Collision::PixelPerfectTest(map, aniCross)
|| Collision::PixelPerfectTest(guy, aniCross) || Collision::PixelPerfectTest(woman, aniCross) || Collision::PixelPerfectTest(woman2, aniCross))
{
map.Move(-speed,0); map3.Move(-speed,0);

guy.Move(-speed,0); woman.Move(-speed,0);

woman2.Move(-speed,0);
}
}

if(App.GetInput().IsKeyDown(sf::Key::Right))

{
map.Move(-speed,0); map3.Move(-speed,0);

guy.Move(-speed,0); woman.Move(-speed,0);

woman2.Move(-speed,0);

if (Collision::PixelPerfectTest(map, aniCross) || Collision::PixelPerfectTest(guy, aniCross) || Collision::PixelPerfectTest(woman, aniCross)
|| Collision::PixelPerfectTest(woman2, aniCross))
{
map.Move(speed,0); map3.Move(speed,0);

guy.Move(speed,0); woman.Move(speed,0);

woman2.Move(speed,0);
}
}

if(App.GetInput().IsKeyDown(sf::Key::Up))

{
map.Move(0,speed); map3.Move(0,speed);

guy.Move(0,speed); woman.Move(0,speed);

woman2.Move(0,speed);

if (Collision::PixelPerfectTest(map, aniCross) || Collision::PixelPerfectTest(guy, aniCross)
|| Collision::PixelPerfectTest(woman, aniCross) || Collision::PixelPerfectTest(woman2, aniCross))
{
map.Move(0,-speed); map3.Move(0,-speed);

guy.Move(0,-speed); woman.Move(0,-speed);

woman2.Move(0,-speed);
}
}

if(App.GetInput().IsKeyDown(sf::Key::Down))

{
map.Move(0,-speed); map3.Move(0,-speed);

guy.Move(0,-speed) ;woman.Move(0,-speed);

woman2.Move(0,-speed);

if (Collision::PixelPerfectTest(map, aniCross) || Collision::PixelPerfectTest(guy, aniCross)
|| Collision::PixelPerfectTest(woman, aniCross) || Collision::PixelPerfectTest(woman2, aniCross))
{
map.Move(0,speed); map3.Move(0,speed);

guy.Move(0,speed); woman.Move(0,speed);

woman2.Move(0,speed);
}
            }
}

*aniCross is the crosshair which is used as the center of the screen and the character; guy, woman and woman2 are npcs*

Then I put in this piece of code, which gets it to do the animation, but only once:
Code: [Select]
if (App.GetEvent(Event))
    {
        if (Event.Type == sf::Event::KeyPressed)
            {
                switch (Event.Key.Code)
                {
                    case sf::Key::Left:
                            aniCross.Play(3, 6);
                           // break;
                }
            }

        if (Event.Type == sf::Event::KeyReleased)
            {
                switch (Event.Key.Code)
                {
                    case sf::Key::Left:
                        aniCross.Stop();
                        //break;    not making a difference
                }
            }
    }


I put this in just before the last bracket in the first code, and the peculiar thing is that when holding left, it will go through the 3 frames once then leave me with a static image of the first, but if i'm holding left, and then tap up or down, it will start looping like i want it to. Very weird indeed :/

(I've also tried placing it everywhere else in the program, but this is the best place so far)

It would be awesome if someone could help with this, otherwise my only other option would be to copy and paste the sprite sheet onto itself so it will be one massive picture, but that will be inefficient, it will eventually end, and it's the lazy way out :(

Cheers in advance!

Jake


P.S I can also give out the entire source code if that's needed! (be on tomorrow)

EDIT:   I removed the (3, 6) from aniCross.Play() and found out that it will only play 3 sprites altogether, maybe some problem with it accessing it?

7
General / Problem with compiling AniSprite
« on: January 08, 2012, 06:20:09 pm »
Hey, I'm trying to compile the following code:
Code: [Select]

#include "SFML/Graphics.hpp"
#include "SFML/System.hpp"
#include "AniSprite.h"

int main()
{
    sf::RenderWindow App(sf::VideoMode(640, 420,32), "Test");

sf::Image Image;

if (!Image.LoadFromFile("untitled1.bmp"))
   return 1;
Image.CreateMaskFromColor(sf::Color::Black);


AniSprite Sprite(Image,93,96);
Sprite.SetLoopSpeed(0.007); //60 fps




while(App.IsOpened())
{
    sf::Event Event;

    while (App.GetEvent(Event))
    {
        if (Event.Type == sf::Event::Closed)
                App.Close();
        if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::A))
                Sprite.Play();
        else if ((Event.Type == sf::Event::KeyReleased) && (Event.Key.Code == sf::Key::A))
                Sprite.Stop();

    }

    App.Clear();
    Sprite.Update();
    App.Draw(Sprite);
    App.Display();
}
}

and I get
Code: [Select]

/home/aballofwin/Downloads/frame_anim_animated/sample/main(1).o||In function `main':|
main(1).cpp|| undefined reference to `AniSprite::AniSprite(sf::Image const&, int, int)'|
main(1).cpp|| undefined reference to `AniSprite::SetLoopSpeed(float)'|
main(1).cpp|| undefined reference to `AniSprite::Play()'|
main(1).cpp|| undefined reference to `AniSprite::Stop()'|
main(1).cpp|| undefined reference to `AniSprite::Update()'|
main(1).cpp|| undefined reference to `AniSprite::~AniSprite()'|
main(1).cpp|| undefined reference to `AniSprite::~AniSprite()'|
||=== Build finished: 7 errors, 0 warnings ===|


and I was wondering if there's a linker option I'm missing, or something else?

8
General / Problem with sequencing events
« on: January 07, 2012, 04:07:00 pm »
Hey, for part of my game, I will be making a story part, and an rpg part. For the story part, i've designed it so that text will be displayed using a typewriter effect, you wait for that to stop, wait something like 5 seconds then it clears that and goes onto the next string. Well, i've tried while loops, do loops, if statements and even switches, but it's not working.

The closest i've come to it actually working is with while loops, this is an example of the closest i've come to making it work:

Code: [Select]

while (progress == 0)
{
    if (timer.GetElapsedTime() > 0.01 && character < str.length())
            {
                timer.Reset();
                character++;
                text.SetText( str.substr(0, character) ) ;

                App.Clear();
                App.Draw(text);
                App.Display();
            }

            if (character == str.length())
                {
                    sf::Sleep(5);
                    progress = 1;
                }
}


That piece of code will go through the string (str) and display it letter by letter, and this works. To then get it out of the loop, I then put an if statement to know when it's finished and put progress to 1, to make it get out of the loop, and then carry on with another while loop where it will be "while (progress == 1)".

The thing is, it stops all together after progress = 1 and doesn't exit the loop. To make sure that it did actually make progress 1, i did this:

Code: [Select]

if (character == str.length())
                {
                    sf::Sleep(5);
                    std::cout << "Test";
                    progress = 1;
                    std::cout << progress;
                }


and it actually put test, and 1 to the console but just stopped dead :/

If anyone could tell me what I'm doing wrong, or come up with another way round it, i'd be thrilled!

When i've made this, I'll be submitting it to the forums, with the source code, as other people's source code has really helped me learn, and i wanna give back to the community :)

aBallofWin

9
Graphics / Rainfall
« on: January 05, 2012, 12:28:54 am »
Hey, for my game's main menu, i've been trying to find out how i could simulate rainfall, either with little sprites or even just drawing lines. After a lot of searching and experimenting (newbie here) i couldn't come up with anything.

Here's how it would be wanted ()

I'd like to ask how I could implement this, and any source code would be greatly appreciated :)

jake.

10
Graphics / Main Menu selection
« on: December 28, 2011, 09:36:00 pm »
Hey again, would anyone know how to show a sprite when the mouse is over a certain piece of the screen, like text for example. After that I'll then do a click function to then launch different parts of the game.

Here is my code at the moment, and I have been trying to get it so it automatically comes up with the selection sprite one the first option and then it will be moved by pressing up and down.

Code: [Select]
#include <SFML/Graphics.hpp>

int main()
{
    // Create main window
    sf::RenderWindow App(sf::VideoMode(1024, 600), "Before the rain");

    // Load a font from a file
    sf::Font MyFont;
    if (!MyFont.LoadFromFile("cinnamon_cake/cinnamon cake.ttf", 50))
        return EXIT_FAILURE;

    // Load the sprite image from a file
    sf::Image selection;
    if (!selection.LoadFromFile("selection.tga"))
        return EXIT_FAILURE;

    // Create the sprite
    sf::Sprite Sprite(selection);

    // Change its properties
    // Sprite.SetColor(sf::Color(0, 255, 255, 128));
    // Sprite.SetPosition(200.f, 100.f);
    Sprite.SetScale(2.f, 2.f);

    // Create a graphical string
    sf::String start;
    start.SetText("Start Game");
    start.SetFont(MyFont);
    start.SetColor(sf::Color(0, 128, 128));
    start.SetPosition(50.f, 300.f);
    start.SetSize(28.f);

    sf::String options;
    options.SetText("Options");
    options.SetFont(MyFont);
    options.SetColor(sf::Color(0, 128, 128));
    options.SetPosition(50.f, 350.f);
    options.SetSize(28.f);

    sf::String credits;
    credits.SetText("Credits");
    credits.SetFont(MyFont);
    credits.SetColor(sf::Color(0, 128, 128));
    credits.SetPosition(50.f, 400.f);
    credits.SetSize(28.f);

    sf::String exit;
    exit.SetText("Exit");
    exit.SetFont(MyFont);
    exit.SetColor(sf::Color(0, 128, 128));
    exit.SetPosition(50.f, 450.f);
    exit.SetSize(28.f);

    sf::String title;
    title.SetText("Before The Rain");
    title.SetFont(MyFont);
    title.SetColor(sf::Color(0, 128, 128));
    title.SetPosition(75.f, 100.f);
    title.SetRotation(5.f);
    title.SetSize(75.f);



    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Make the second string rotate
        // Bonjour.Rotate(App.GetFrameTime() * 100.f);

        // Clear screen
        App.Clear();

        // Draw our strings
        App.Draw(title);
        App.Draw(start);
        App.Draw(options);
        App.Draw(credits);
        App.Draw(exit);

    }

    return EXIT_SUCCESS;
}


Either way would REALLY help me out, if someone could supply any source code to do this. Sorry about all the questions, but I'm new and there aren't many tutorials out there for what I need :(

Many thanks, i'll be back on tomorrow!

aBallofWin :)[/code]

11
Graphics / Scrolling Text (Final Fantasy Like)
« on: December 28, 2011, 01:31:34 am »
Hey, I'm new to SFML, and so far it's awesome, but I need a little help. I'm creating a little RPG, and I'd like to know how I could implement text that appears one word after another, much like in Final Fantasy games. ( skip to 5 minutes in and you'll see what I mean).

I wouldn't have the faintest clue on how to even start to do this :s and any help would be greatly appreciated!

Cheers!

aBallofWin

Pages: [1]