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

Pages: 1 2 3 [4]
46
General / Re: [HELP] laser movement
« on: April 18, 2014, 11:44:42 am »
ChronicRat is right, normalize(V2 - V1) will give you the direction vector from V1 to V2.

If you want that in an angle, here's how you do it (radian): atan2(direction.y, direction.x), you can then convert to degrees if needed. :p

it looks like one of my function in npc[movable struct]:

#define toDegrees 57.32f        //(180 / 3.14)

float gameEntityMove::coordsToAngle(sf::Vector2f start, sf::Vector2f end)
{
        #pragma warning(disable : 4715) // not all control paths return a value

        if (start.x != end.x && start.y != end.y)
                return std::atan2(start.y - end.y, start.x - end.x) * toDegrees;
        else
                return -1;
}

am i right ?

47
General / Re: [HELP] laser movement
« on: April 18, 2014, 11:34:53 am »
thanks  ;) i will write you if it works, but i'll try it later

48
General / Re: [HELP] laser movement
« on: April 18, 2014, 11:04:20 am »
i need to calculate the direction of laser from those two points

49
General / [HELP] laser movement
« on: April 18, 2014, 10:23:08 am »
Well as topic already say i need to help with laser movement like on this video:


as you cant see player and npc are moving with some angle and laser must move with them at some angle and speed, or otherwise it will be rocket.

and that: (me[angle] + npc[angle]) / 2 = laser[angle] -> i dont know if it is right, tell me if am i doing it wrong
i need to calculate angle + speed of laser [using sf::Sprite]

50
General / Re: [HELP] Enemy Around
« on: April 16, 2014, 10:17:26 pm »
// QuadtreeSimple.cpp : Demonstrates the use of Quadtree using SFML
//

#include "Quadtree.h"
#include "Object.h"
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Graphics/Font.hpp>
#include <iostream>

int main()
{
        using namespace std;

        sf::RenderWindow app( sf::VideoMode( 800, 600, 32 ), "Quadtree" );
        app.setFramerateLimit( 60 );

        sf::Font font;
        font.loadFromFile( "DroidSans.ttf" );

        Quadtree quadtree( 0.0f, 0.0f, 800.0f, 600.0f, 0, 3 );
        quadtree.SetFont( font );

        vector<Object> objects;

        while( app.isOpen() ) {
                sf::Event event;
                sf::Vector2i mousePosition = sf::Mouse::getPosition( app );
                while( app.pollEvent( event ) ) {
                        if ( event.type == sf::Event::KeyPressed ) {
                                if ( event.key.code == sf::Keyboard::Escape ) {
                                        app.close();
                                }
                        }
                        if ( event.type == sf::Event::MouseButtonPressed ) {
                                objects.push_back( Object( mousePosition.x, mousePosition.y, 32, 32 ) );
                        }
                }
                app.clear();

                for ( int n = 0; n < objects.size(); ++n ) {
                        quadtree.AddObject( &objects[n] );
                        objects[n].Draw( app );
                }
                quadtree.Draw( app );

                vector<Object*> returnObjects = quadtree.GetObjectsAt( mousePosition.x, mousePosition.y );
                cout << returnObjects.size() << endl;
                quadtree.Clear();

                app.display();
        }

        return 0;
}

#ifndef __QUADTREE_H__
#define __QUADTREE_H__

#include <vector>
#include <SFML/Graphics/RenderTarget.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/Text.hpp>

using namespace std;

class Quadtree;
class Object;

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

        void                                    AddObject(Object *object);
        vector<Object*>                         GetObjectsAt(float x, float y);
        void                                    Clear();

        void                                    SetFont(const sf::Font &font);
        void                                    Draw(sf::RenderTarget &canvas);

private:
        float                                   x;
        float                                   y;
        float                                   width;
        float                                   height;
        int                                     level;
        int                                     maxLevel;
        vector<Object*>                         objects;

        Quadtree *                              parent;
        Quadtree *                              NW;
        Quadtree *                              NE;
        Quadtree *                              SW;
        Quadtree *                              SE;

        sf::RectangleShape                      shape;
        sf::Text                                text;

        bool                                    contains(Quadtree *child, Object *object);
};

#endif

quadtree.cpp
#include "Quadtree.h"
#include "Object.h"
#include <iostream>
#include <sstream>

using namespace std;

Quadtree::Quadtree(float _x, float _y, float _width, float _height, int _level, int _maxLevel) :
        x               (_x),
        y               (_y),
        width   (_width),
        height  (_height),
        level   (_level),
        maxLevel(_maxLevel)
{
        shape.setPosition(x, y);
        shape.setSize(sf::Vector2f(width, height));
        shape.setFillColor(sf::Color(0, 0, 0, 0));
        shape.setOutlineThickness(1.0f);
        shape.setOutlineColor(sf::Color(64, 128, 255));
        text.setPosition(x, y + level * 16);
        text.setCharacterSize(12);

        if (level == maxLevel) {
                return;
        }

        NW = new Quadtree(x, y, width / 2.0f, height / 2.0f, level+1, maxLevel);
        NE = new Quadtree(x + width / 2.0f, y, width / 2.0f, height / 2.0f, level+1, maxLevel);
        SW = new Quadtree(x, y + height / 2.0f, width / 2.0f, height / 2.0f, level+1, maxLevel);
        SE = new Quadtree(x + width / 2.0f, y + height / 2.0f, width / 2.0f, height / 2.0f, level+1, maxLevel);
}

Quadtree::~Quadtree()
{
        if (level == maxLevel)
                return;

        delete NW;
        delete NE;
        delete SW;
        delete SE;
}

void Quadtree::AddObject(Object *object) {
        if (level == maxLevel) {
                objects.push_back(object);
                return;
        }
        if (contains(NW, object)) {
                NW->AddObject(object); return;
        } else if (contains(NE, object)) {
                NE->AddObject(object); return;
        } else if (contains(SW, object)) {
                SW->AddObject(object); return;
        } else if (contains(SE, object)) {
                SE->AddObject(object); return;
        }
        if (contains(this, object)) {
                objects.push_back(object);
        }
}

vector<Object*> Quadtree::GetObjectsAt(float _x, float _y) {
        if (level == maxLevel) {
                return objects;
        }
       
        vector<Object*> returnObjects, childReturnObjects;
        if (!objects.empty()) {
                returnObjects = objects;
        }
        if (_x > x + width / 2.0f && _x < x + width) {
                if (_y > y + height / 2.0f && _y < y + height) {
                        childReturnObjects = SE->GetObjectsAt(_x, _y);
                        returnObjects.insert(returnObjects.end(), childReturnObjects.begin(), childReturnObjects.end());
                        return returnObjects;
                } else if (_y > y && _y <= y + height / 2.0f) {
                        childReturnObjects = NE->GetObjectsAt(_x, _y);
                        returnObjects.insert(returnObjects.end(), childReturnObjects.begin(), childReturnObjects.end());
                        return returnObjects;
                }
        } else if (_x > x && _x <= x + width / 2.0f) {
                if (_y > y + height / 2.0f && _y < y + height) {
                        childReturnObjects = SW->GetObjectsAt(_x, _y);
                        returnObjects.insert(returnObjects.end(), childReturnObjects.begin(), childReturnObjects.end());
                        return returnObjects;
                } else if (_y > y && _y <= y + height / 2.0f) {
                        childReturnObjects = NW->GetObjectsAt(_x, _y);
                        returnObjects.insert(returnObjects.end(), childReturnObjects.begin(), childReturnObjects.end());
                        return returnObjects;
                }
        }
        return returnObjects;
}

void Quadtree::Clear() {
        if (level == maxLevel) {
                objects.clear();
                return;
        } else {
                NW->Clear();
                NE->Clear();
                SW->Clear();
                SE->Clear();
        }
        if (!objects.empty()) {
                objects.clear();
        }
}

void Quadtree::SetFont(const sf::Font &font) {
        text.setFont(font);
        if (level != maxLevel) {
                NW->SetFont(font);
                NE->SetFont(font);
                SW->SetFont(font);
                SE->SetFont(font);
        }
}

void Quadtree::Draw(sf::RenderTarget &canvas) {
        stringstream ss;
        ss << objects.size();
        string numObjectsStr = ss.str();
        text.setString(numObjectsStr);
        canvas.draw(shape);
        canvas.draw(text);
        if (level != maxLevel) {
                NW->Draw(canvas);
                NE->Draw(canvas);
                SW->Draw(canvas);
                SE->Draw(canvas);
        }
}

bool Quadtree::contains(Quadtree *child, Object *object) {
        return   !(object->x < child->x ||
                                object->y < child->y ||
                                object->x > child->x + child->width  ||
                                object->y > child->y + child->height ||
                                object->x + object->width < child->x ||
                                object->y + object->height < child->y ||
                                object->x + object->width > child->x + child->width ||
                                object->y + object->height > child->y + child->height);
}
 

51
General / Re: [HELP] Enemy Around
« on: April 16, 2014, 10:13:59 pm »
As far i know QuadTree has an official website, but i forgot its name.
i have quadtree from github, downloaded about 6 months back.

52
General / Re: [HELP] Enemy Around
« on: April 16, 2014, 10:00:06 pm »
Use spatial partition. For example a simple grid, a quadtree, or an R-tree (Boost.Geometry).

There have also been several threads about this problem, you could search the forum.

thanks.
It looks like i will implement QuadTree.

53
General / [HELP] Enemy Around
« on: April 16, 2014, 09:31:02 pm »
Hello all,

2D game,
i need to find if there is any enemy around another enemy but, using lenght and collision detection with 200 npcs it's equivalent to winVista as server on WiFi.
Is there any other way to find any enemy near another enemy ?

And sys look like this:

entity:
struct gameEntity_NPC

entity manager:
map<string, unique_ptr<gameEntity_NPC>>

54
System / Re: sf::Thread Constructor Problem
« on: April 01, 2014, 02:08:21 pm »
Replace "this" in your code (which is a gameWindow instance) with the instance of the gameInputMgr class that you must have somewhere around.

If you have no idea about what you're doing, then you should probably not try to use threads.

I am sorry what did a say before, but now when i read every word you say, i see what you mean

55
System / Re: sf::Thread Constructor Problem
« on: April 01, 2014, 01:58:23 pm »
You pass a member function of gameInputMgr and an instance of gameWindow. You must of course pass an instance of gameInputMgr.

Thanks for the reply, but how does it look in a code ?

56
System / sf::Thread Constructor Problem
« on: April 01, 2014, 05:32:05 am »
Hello all, i am new to this forum, but i am working with sfml 1 year or more.

The problem is this:

sf::Thread kb(&gameInputMgr::keyboard, this);
sf::Thread ms(&gameInputMgr::mouse, this);
kb.launch();
ms.launch();

this above is inside :
void gameWindow::run()

Libs are compiled in VC++12 [STATIC]

I have even tried this:
gameInputMgr gInputMgr;

sf::Thread kb(&gInputMgr.keyboard, this);
sf::Thread ms(&gInputMgr.mouse, this);
&
sf::Thread kb(&gInputMgr.keyboard);
sf::Thread ms(&gInputMgr.mouse);

I have no idea whats wrong, there is my output log:

  gameWindow.cpp
D:\Dark Orbit X\_shared\SFML-2.1\SFML/System/Thread.inl(48): error C2064: term does not evaluate to a function taking 1 arguments
          D:\Dark Orbit X\_shared\SFML-2.1\SFML/System/Thread.inl(48) : while compiling class template member function 'void sf::priv::ThreadFunctorWithArg<F,A>::run(void)'
          with
          [
              F=void (__thiscall gameInputMgr::* )(void)
  ,            A=gameWindow *
          ]
          D:\Dark Orbit X\_shared\SFML-2.1\SFML/System/Thread.inl(79) : see reference to class template instantiation 'sf::priv::ThreadFunctorWithArg<F,A>' being compiled
          with
          [
              F=void (__thiscall gameInputMgr::* )(void)
  ,            A=gameWindow *
          ]
          gameWindow.cpp(29) : see reference to function template instantiation 'sf::Thread::Thread<void(__thiscall gameInputMgr::* )(void),gameWindow*>(F,A)' being compiled
          with
          [
              F=void (__thiscall gameInputMgr::* )(void)
  ,            A=gameWindow *
          ]

N3v3r h48 4ny pr0bl3ms w11h 11.

Pages: 1 2 3 [4]
anything