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

Pages: [1]
1
General / Re: Including header in a header - loop
« on: March 07, 2015, 01:46:29 pm »
thanks, I think I got it working.
The change of header guards from #pragma once didn't work.
I added a forward declaration to Header.h
class Quadtree;
and included the Quadtree.h in Person.cpp

It seems to work. For now.

2
General / Including header in a header - loop
« on: March 07, 2015, 01:10:42 pm »
I may be too stupid for this, but I can't really get my head around this:
I have files Header.h, Header.cpp, Quadtree.h and Quadtree.cpp.

Header.h
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include "Quadtree.h" <------------------------------ CAUSES ERRORS, without it working fine

class Person
{
protected:
        ...
public:
        ...
        virtual void update(Quadtree quadtree); //<---- I NEED THE ABOVE INCLUDE FOR THIS ARG
};

Quadtree.h
#ifndef __QUADTREE_H__
#define __QUADTREE_H__

#include "Header.h"
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/Text.hpp>

class Quadtree {
public:
        Quadtree(float x, float y, float width, float height, int level, int maxLevel);
private:
        ...

I need to pass a Quadtree instance to update function in Person. So what I tried was adding the include Quadtree.h, but that gives me loads of errors and I don't know how to fix it. I have the header guards in Header.h and Quadtree.h.. so what is the problem?

Here are the errors, I don't expect you to find something in these, I am just posting this to show how many bullshit error comes up by only adding one include in Header.h

3
General / Re: Checking for collisions in vector of shapes is bugged
« on: March 05, 2015, 11:57:15 am »
Oh god, at first look I thought "wait, this is the same way I did it in the first post". But then I realized how stupid I am.

Thanks

4
General / Re: Checking for collisions in vector of shapes is bugged
« on: March 05, 2015, 11:25:08 am »
Thanks, I got it working.
Thanks for the advices, but I not a newbie programmer, I have been programming in various languages (starting with c) for over 6 years now.

zsbzsb:
-1){swearing} I was frustrated with looking for the bug. When I am frustrated I am not very creative, so variables get first name which comes to mind. Also, this is my personal project, so I don't really care. You should meet my friend, one of the best programmers I know, and he puts swearing into his code all the time. Really, it doesn't matter if it won't be public.
0) I use the debugger
1) okay, I will look into unique pointers, never worked with them
2) I don't use them, this was just a temporary solution, because a static declaration of the vector didn't work properly for some reason
3) I know how and when to use else if, guess I was just too tired when writing that code
4) googled clamp, found some one line functions in boost. Is that supposed to be it?
5) Yes I know, I just prefer readability

Arcade:
I fixed the code with:
for (j = fuckingPerson.begin(); j != fuckingPerson.end(); j++)
{
        if (this != (*j) && boundingBox.intersects((*j)->getPersonShape().getGlobalBounds())) { k++; }
}
return (k > 0) ? true : false;

5
edit: added SOLVED
I just started coding in SFML so I am not sure if there is already some class for the following thing:

I have RectangleShapes in my game. I need to check if they are colliding between each other so I can adjust their position based on that. So if I hit into another RectangleShape it will stop etc...


Person is a class which holds the rectangle shape and other info, like speed etc.
I made a global vector:
std::vector<Person*>& fuckingPerson;

And I am pushing newly created items into it:
fuckingPerson.push_back(* new Someone(sf::Vector2f(300, 211), sf::Vector2f(0, 0), fuckingPerson));
fuckingPerson.push_back(*new Someone(sf::Vector2f(300, 311), sf::Vector2f(0, 0), fuckingPerson));
MainPlayer ply(sf::Vector2f(250, 100), sf::Vector2f(0, 0), window, mainView, fuckingPerson);
fuckingPerson.push_back(&ply);
 
I have an update function in the Person class (MainPlayer and Someone are inherited from Person)
void Person::update()
{
        curPos = m_recShShape->getPosition();
        m_recShShape->move(m_vfSpeed);
        if (m_vfSpeed.x > 0) m_vfSpeed.x -= m_fFriction;
        if (m_vfSpeed.x < 0) m_vfSpeed.x += m_fFriction;
        if (m_vfSpeed.y > 0) m_vfSpeed.y -= m_fFriction;
        if (m_vfSpeed.y < 0) m_vfSpeed.y += m_fFriction;
       
        if (m_vfSpeed.x < m_fFriction && m_vfSpeed.x > 0) m_vfSpeed.x = 0;
        if (m_vfSpeed.y < m_fFriction && m_vfSpeed.y > 0) m_vfSpeed.y = 0;

        if (collidesWithWall() || collidesWithSomeone())
        {
                m_recShShape->setPosition(curPos);
                m_vfSpeed.x = 0;
                m_vfSpeed.y = 0;
        }
}

My main problem lies probably in the collidesWithSomeone function:
bool Person::collidesWithSomeone()
{
        sf::FloatRect boundingBox = m_recShShape->getGlobalBounds();
        std::vector<Person*>::iterator j;
        for (j = fuckingPerson.begin(); j != fuckingPerson.end(); j++)
        {
               
                if (this != (*j))
                {
                        if (boundingBox.intersects((*j)->getPersonShape().getGlobalBounds()))
                        {
                                return  true;
                        }
                        else
                        {
                                return false;
                        }
                }
        }
}

My problem is that the collision detection works between the first inserted Person and MainPlayer. Other inserted Persons are ignored. Examples in images below. I have been trying to solve this problem for about 4 hours now and I just can't find the damn bug.

Blue ones are "Someone".
Green one is "MainPlayer". Global bounds box is drawn for each shape.

Detects collision properly on the first inserted:


Another doesn't:

Pages: [1]
anything