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

Pages: [1] 2
1
General / Re: Problem with rendering (SFML2.1, OOP + <vector>)
« on: June 24, 2014, 02:27:40 pm »
eXpl0it3r you are right! Thanks.
It works now.

2
General / Re: Problem with rendering (SFML2.1, OOP + <vector>)
« on: June 24, 2014, 01:48:34 pm »
@Ixrec small steps forward, holidays are pretty long and i'm going to learn some about c++. I'll take on my attention what you said, but first enums, then we will see.

For those who are "interested" in my project, it works as it should, but i have a question:
Why when i'm holding(W or D or S or A) and at the same time moving mouse, my square is getting speed boost? :D

My main loop
(click to show/hide)

3
General / Re: Problem with rendering (SFML2.1, OOP + <vector>)
« on: June 24, 2014, 12:41:09 pm »
Okey, with normal C++ array it works, but it's much harder to use it. push_back, erase are really useful things. Now i have to call constructor when i create an array
Item items[4] = {Item(1, interfejs.getRandom(15, 1265), interfejs.getRandom(15, 985)),
    Item(1, interfejs.getRandom(15, 1265), interfejs.getRandom(15, 985)),
    Item(1, interfejs.getRandom(15, 1265), interfejs.getRandom(15, 985)),
    Item(1, interfejs.getRandom(15, 1265), interfejs.getRandom(15, 985))
    };
what is really annoying.

4
General / Re: Problem with rendering (SFML2.1, OOP + <vector>)
« on: June 24, 2014, 12:01:24 pm »
Good than, but first i have to make this damn project work -.-
I'm trying to make an array Item items[4], but than in Gracz.cpp i have a problem with checkcollision() with passing arrays.

5
General / Re: Problem with rendering (SFML2.1, OOP + <vector>)
« on: June 24, 2014, 11:11:14 am »
I was trying to find out what is going wrong, i was checking the constructor, setskin() function and i couldn't find anything. I can tell you that it's my first project with <vector> library, so i didn't know the thing about moving texture in memory.

So how to use ResourceHolder to not change my classes' structures too much?
I don't know how to use enums yet, in this project i don't want to use them. I'll try to learn them during the holidays, so most probably after this project. 

6
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. 

7
Graphics / Re: Rendering private sprite of class
« on: May 27, 2014, 10:48:27 pm »
I updated the code so it works now.
Thanks for your help.

8
Graphics / Re: Rendering private sprite of class
« on: May 27, 2014, 10:11:53 pm »
I have a "C++ Primer Plus" - Stephen Prata (not sure about translating the title) but i coudn't get through this. I read about the half and i stopped right on OOP, i was trying to get through this section but i coudn't. I see i have no choice now ;)

So the reference you say?

9
Graphics / Re: Rendering private sprite of class
« on: May 27, 2014, 09:55:46 pm »
Okey, I saw i one "little" mistake in loadfromfile "!" exactly, but i have the same situation.

Next thing is that i wanted to start learning the OOP so i don't understand so much about it right in this examp.

So what's your proposition? 

10
Graphics / Re: Rendering private sprite of class
« on: May 27, 2014, 09:40:26 pm »
I have updated the Mob.cpp to show msg.

I have a spam in console, that the "skin" is shown, so the program works, but i have only the white screen.

11
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).

12
System / Re: Problem with sf::Sleep
« on: February 22, 2014, 10:13:08 am »
Thanks, for your help.
But at first, I have to learn object-oriented programming, because I started to lose myself in those 2800 lines.

13
System / Re: Problem with sf::Sleep
« on: February 21, 2014, 08:47:03 pm »
fixed-timestep - i really don't what it is, as i told you, it's my first project in SFML.
About sf::Clock in my opinion it takes a bit too much space.
My example
if (T_baseattackcd2 >= baseattackcooldown2 && menuswitch == 3 && canuse[0][AI] == 1)
        {
            canuse[0][AI] = 0;
            T_baseattackcd2 = sf::Time::Zero;
            // cooldown finished
        }
        else if(canuse[0][AI] == 0)
        {
            T_baseattackcd2 = sf::Time::Zero;
        }
 
And during the fight i have already 10 working clocks, so or there is easier way to make it for my example than i know, or clocks in this case for me is complicated to use.

14
System / Re: Problem with sf::Sleep
« on: February 21, 2014, 08:29:44 pm »
Okey so i'll try to explain again.
My game is a real time fight. In game i created a spell called fireball
This is a code of fireball
        statrefresh(mana, USER);
        canuse[1][USER] = 1;
        fireball_fly.play();
        sf::sleep(sf::milliseconds(1000));
        ordershield = 1;
        sf::sleep(sf::milliseconds(1000));
        if(isdead(1) == 0)
        {
            dealdmg(230+stats[ap][USER], 1);
            ordershield = 0;
            fireball_hit.play();
        }
I use a sleep function to make an effect more realistic i play sound, then the program wait 1sec to order enemy to use his shield, then again one second to hit the enemy with fireball. This is why i use sleep.
Everything would be fine, if i wouldn't start to make spells for enemy. Because the game is a real time fight i coudn't make an enemy ai to answer only on my moves(example: i use fireball, then he use shield), so i had to make ai "get random" function for moves put at the begging of main loop. When i use sleep function in any thread, which starts from "ai make move" function it doesn't work properly, it stops the whole game. To compare the situation when i use my spell which is associated to my Q bind keyboard event it doesn't sleep my whole program. Why it is like that?
This is my beginning of program main loop
 
while (window.isOpen())
    {
        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();

        }
 
Okey, so let's suppose that our waitforr variable is equal to 2
This is the thread and case of waitforr equal to 2
Code: [Select]
...
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)
        {
            dealdmg(50, USER);
            statrefresh2;
            sf::sleep(sf::milliseconds(200));
            dealdmg(50, USER);
            statrefresh2();
            sf::sleep(sf::milliseconds(200));
            dealdmg(50, USER);
            dealdmg(150, USER);
            sf::sleep(sf::milliseconds(2000));
statrefresh2();
            blockspells[0][AI] = 0;
            blockspells[1][AI] = 0;
            blockspells[2][AI] = 0;
            waitforr = 0;
        }
        sf::sleep(sf::milliseconds(170));
    }
Here the sf::sleep lags my whole program not the thread <-- this is the problem.

15
System / Re: Problem with sf::Sleep
« on: February 21, 2014, 07:43:37 pm »
Here is my project, please download(coudn't attach here 13MB) it and follow in menu's - "Start, priest, Walka"
http://speedy.sh/Mt95A/sfml-project.rar
In "walka" you can see, that i use other functions(on keyboard Q, W, E, R) which needs to wait some time to synchronize it with sounds.

Pages: [1] 2
anything