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

Pages: [1]
1
General / Problem with rendering (SFML2.1, OOP + <vector>)
« on: June 24, 2014, 10:29:58 am »
Hi guys, i have a big problem which i can't solve after hours and i need your help.
My program task is to make a skin move on the map and pick up item which will go into my inventory.
The problem is that my program doesn't want to render skins properly. Take a look on the code which is long and then i'll give you more details. 
main.cpp
(click to show/hide)
Item.h
(click to show/hide)
Item.cpp
(click to show/hide)
Gracz.h
(click to show/hide)
Gracz.cpp
(click to show/hide)

So, as you can take a look at the main.cpp I declared an object of Gracz class and i gave it a skin "skin.png", in my program it's just a black square, but later i gave a skin to an item "item1.png" which was little black heart in square, but what i got is next black square! Just to satisfy my curiosity later a gave Gracz object "item1.png" skin instead of "skin.png" and everything on the map(items and Gracz object) had the same picture(little black heart on square) but with other size(Gracz object had skin 50x50 and item is 30x30)
 The next thing when i push_back my items vector the next items don't want to show up on the map. I mean they are on the map, i can pick up them, but i can't see them.
It seems like something would be rendered wrong maybe it's in vector class or my loops, don't really know.
I would appreciate your help.

UPDATE: I found out that when i'll go my Gracz black square to the "invisible item" it shows up that Item is a white square. Sometimes when i pick up "invisible item", a new one respawn with a proper skin. 

2
Graphics / Rendering private sprite of class
« on: May 27, 2014, 09:09:27 pm »
Hi guys
I am writing here, because i need Your help.
The problem is how to excatly draw a sprite of a class?

Quote
main.cpp
#include <SFML/Window.hpp>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>


#include "Mob.h"

using namespace std;

int main()
{
    sf::RenderWindow window(sf::VideoMode(1280, 1000), "Title");
    window.setPosition(sf::Vector2i(320, 0));
    window.setVerticalSyncEnabled(true); // call it once, after creating the window

    Mob mob1;
    mob1.attack(10);
    mob1.setskin("zombie");

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

        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
        window.clear(sf::Color::White);
        mob1.render(window);
        window.display();
    }
    return 0;
}
 

Quote
Mob.h
#ifndef MOB_H_INCLUDED
#define MOB_H_INCLUDED

#include <SFML/Window.hpp>
#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <sstream>
#include <windows.h>
#include <ctime>
#include <cstdlib>

using namespace std;

class Mob
{
    private:
        int hp;
        int mana;
        int ad;
        sf::Texture T_skin;
        sf::Sprite skin;
    public:
        void attack(int amount);
        void sethp();
        void setskin(std::string name);
        void render(sf::RenderWindow& i);
};

#endif // MOB_H_INCLUDED
 

Quote
mob.cpp
#include <iostream>
#include "Mob.h";

void Mob::attack(int amount)
{
    std::cout << "You attacked someone\n";
}


void Mob::setskin(string name)
{
    if(T_skin.loadFromFile(name+".png"))
    {
        skin.setTexture(T_skin);
        skin.setTextureRect(sf::IntRect(0, 0, T_skin.getSize().x, T_skin.getSize().y));
        skin.setPosition(sf::Vector2f(640, 290));
        cout << "I'm setting the \"Skin\" option\n";
    }
}

void Mob::render(sf::RenderWindow& i)
{
    i.draw(skin);
}
 

The problem is exactly in Mob::render() and main loop in main() - no error(img loaded, run as admin)
I would really appreciate Your help(explanations, examples).

3
System / Problem with sf::Sleep
« on: February 21, 2014, 12:32:12 pm »
Hi guys, recently i have a big problem with sf::sleep. The problem is that sf::sleep stops the whole application. I'm using sf::sleep only in threads, but in some threads sf::sleep wants to work properly, in some doesn't. 
What is the difference i saw:
When i call the thread during getting event(for example when i press Q then i call the thread), sf::sleep works
but when i made an AI thread in while(window.isOpen()) and not in getting events sf::sleep lags the whole program. Any ideas why it is like that? My whole program has 2800 lines, so it's hard to show you all of them.
while (window.isOpen())
    {
        // ruchy AI
        if(AI_MOVES == 1 && menuswitch == 3)
        {
            if(waitforr != 2)
            {
                if(ordershield == 1 && canuse[2][AI] == 0)
                {
                    ordershield = 0;
                    Wspellenemy();
                }
                random[0] = rand() % 100;
                random[1] = rand() % 100;
                random[2] = rand() % 100;
                thread_aiattackfunction.launch();
            }
            else thread_rspellenemy.launch();

        }
// ...

void aiattackfunction()
{
    if(random[0] >= 0 && random[0] <= 50)
    {
        if(canuse[0][AI] == 0 && blockspells[0][AI] != 1)
        {
            canuse[0][AI] = 1;
            if(random[1] > stats[avoid][USER])
            {
                if(random[2] <= stats[critic][AI])
                    dealdmg(stats[ad][AI]*2, 0);
                else dealdmg(stats[ad][AI], 0);
            }
            else cout << "Uniknalem\n";
        }
    }
    else if(random[0] >= 51 && random[0] <= 75)
    {
        if( canuse[1][AI] == 0 && blockspells[1][AI] != 1)
            Qspellenemy();
    }
    else if(random[0] >= 76 && random[0] <= 100)
    {
        if( canuse[2][AI] == 0 && blockspells[2][AI] != 1)
            Rspellenemy();
    }
}
void Rspellenemy()
{
    if(waitforr != 2 && waitforr != 1)
    {
        if(stunned[0] != 1)
        {
            waitforr = 1;
            canuse[2][AI] = 1;
            T_wait = sf::Time::Zero;
            blockspells[0][AI] = 1;
            blockspells[1][AI] = 1;
            blockspells[2][AI] = 1;
            string15.setString("Press Space!");
        }
    }
    else if(waitforr == 2)
    {
        ultiamount += 1;
        if(ultiamount >= 30)
            S_Rultibar.setTextureRect(sf::IntRect(0, 0, 271, 10));
        else S_Rultibar.setTextureRect(sf::IntRect(0, 0, ultiamount*271/30, 10));
        if(ultiamount == 30) // ignore
        {
            dealdmg(50, USER);
            statrefresh(hp, USER); // update the hp bar
            sf::sleep(sf::milliseconds(200));
            dealdmg(50, USER);
            statrefresh(hp, USER);
            sf::sleep(sf::milliseconds(200));
            dealdmg(50, USER);
            statrefresh(hp, USER);
            sf::sleep(sf::milliseconds(2000));
            blockspells[0][AI] = 0;
            blockspells[1][AI] = 0;
            blockspells[2][AI] = 0;
            waitforr = 0;
        }
        sf::sleep(sf::milliseconds(170));
    }
}
 
The problem is in Rspellenemy before it whole end the program is lagged.
The qeustion is how to do the AI(where to call it), to make its spells not lag the whole program.
if u don't understand what i exactly wrote, please ask, i'll try to translate it better.


4
System / [SFML 2.1] float timer problem
« on: February 07, 2014, 07:15:05 pm »
Hi guys, a few days before i started programming in SFML and i'm stucked in one moment, exactly in making cooldowns. I wanted to make a basic attack depending on attackspeedplayer variable, but the program clock doesn't want to update more often than 1 sec, so when i run this program i'll get something like this:
0,66666667
-0,3333333
-1,3333333
but the if will be skipped.
Is there any other way to make it properly?

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

using namespace std;

int main()
{
    float attackspeedplayer = 1.5;
    float attackspeedtotal = 1 / attackspeedplayer;
   
    sf::RenderWindow window( sf::VideoMode( 200, 200 ), "SFML works!" );
    sf::CircleShape shape( 100.f );
    shape.setFillColor( sf::Color::Green );
   
    sf::Clock clock;
    sf::Time elapsed;
    while( window.isOpen() )
    {
        elapsed = clock.getElapsedTime();
        cout << attackspeedtotal - elapsed.asMilliseconds() / 1000 << endl;
        if( attackspeedtotal - elapsed.asMilliseconds() / 1000 == 0 )
        {
            cout << "CD minal!";
        }
        sf::Event event;
        while( window.pollEvent( event ) )
        {
            if( event.type == sf::Event::Closed )
                 window.close();
           
        }
       
        window.clear();
        window.display();
    }
   
    return 0;
}
 

Pages: [1]