Jump to content
  • Advertisement

afflicto

Member
  • Content Count

    13
  • Joined

  • Last visited

Community Reputation

127 Neutral

About afflicto

  • Rank
    Member
  1. Played Super Street Fighter IV Arcade Edition (PC) in the last 24 hours. http://t.co/rrERaNtBDw
  2. SOLVED!   Hello! I'm trying to implement A* pathfinding for my RTS game, and I've got it working, but I'm confused with some parts of the algorithm.   Essentially, I don't know how to implement diagonal paths.   I followed this guide, while writing this script and I'm confused as to what I should do on line 96.   Here's the script. A few notes, the current.adjecentNodes() method returns the 8 adjecent nodes (north, northeast, east etc). Also, the i variable used in the foreach loop is simply used to detect diagonal adjecent nodes. Every 2nd node is a diagonal move. public Path findPath(Node start, Node goal) { if (start == null || goal == null || start == goal) return null; open.Clear (); closed.Clear (); open.Add (start); start.g = 0; while(open.Count > 0) { //get the lowest F node Node current = null; float f = 0; foreach(Node node in open) { if (current == null) { current = node; }else if (node.f < current.f) { current = node; } } //did we get the goal? if (current == goal) { return traceBack(start, goal); } closed.Add (current); open.Remove(current); int i = 1; foreach(Node adjecent in current.adjecentNodes()) { if (adjecent != null && adjecent.walkable && !closed.Contains (adjecent)) { int g = 10; if (i % 2 == 0) { g += 4; } //set g,h and f scores //and parent adjecent.g += current.g; adjecent.h = getHeuristic(adjecent, goal); adjecent.f = adjecent.g + adjecent.h; //is it closed? if (open.Contains(adjecent) == false) { open.Add(adjecent); adjecent.parent = current; }else { //it's already on the open list //check to see if this path to that square is better, // using G cost as the measure. // A lower G cost means that this is a better path. // If so, change the parent of the square to the current square, // and recalculate the G and F scores of the square. float currentToThis = current.g + adjecent.g; float prevToThis = current.parent.g + adjecent.g; if (prevToThis < currentToThis) { adjecent.parent = current.parent; adjecent.g = current.parent.g + g; adjecent.f = adjecent.g + adjecent.h; } } } i++; } } return null; } Thanks in advance.     UPDATE: Thanks for your reply guys, I was able to solve it though. There was apparently a problem with the heuristics calculation.
  3. Played Counter-Strike: Global Offensive (PC) in the last 24 hours. http://t.co/rrERaNtBDw
  4. [SOLVED] Is there a way to rename the topic? Someone else might find the solution helpful. Maybe. Hello!   I'm working on a 2D platformer in java using LibGDX and over the past week I've been trying to get a good platform movement system working   So basically I have the following vectors: velocity, acceleration, friction & gravity. What I want is, essentially the gravity being accumulated over time, not a constant gravity. (That way I can do things like, if you hit the ground with a y velocity higher than say 200, decrease the health of the player by some amount (based off of the velocity somehow).   I can do that, by simply doing: velocity += gravity * 0.01f and after one second, the Y velocity would be 240. I can then simply limit the Y velocity to say 400 to prevent the player from falling too quickly.   However, I also need to add the friction vector and when I do so, since it is higher than gravity * 0.01f it causes the gravity to become very weak.   Solution So the solution is essentially to make sure the friction isn't too high and also only apply gravity when the player is in the air. Pretty simple.
  5. afflicto

    C++ & SFML?

    I was able to make it work.   It's not exactly a singleton. I just need my input object, sound object, gui object etc to access each other.   I think passing things around all the time is more like spaghetti code than to have 1 single place to store a reference to something. Less typing as well.
  6. afflicto

    C++ & SFML?

    I run into another issue.   I have a class 'Game'. and when instantiated, I want to store the instance on a static member of the 'Game' class but some code in SFML complains about NonCopyable.   I tried storing a reference, reference to a pointer and a the dereferenced object to no avail.   Here's the class: class Game { private: sf::RenderWindow mWindow; protected: std::vector<Entity> entities; public: static Game instance; } and the implementation: Game::Game() : mWindow(sf::VideoMode(640, 480), "SFML!") { //set the game instance Game::instance = *this; } Here's the full error: error C2248: 'sf::NonCopyable::operator =' : cannot access private member declared in class 'sf::NonCopyable' c:\sfml2.1\include\sfml\window\window.hpp 477 1 sfmltest2 What's going on here?
  7. afflicto

    C++ & SFML?

    Hm.. ok. I'll look into that, thanks!
  8. afflicto

    C++ & SFML?

    I have another question. in SFML there is a templated Vector2 class.   I've been trying to extend it for the past few hours but damn...   Here's my code: #pragma once #include <SFML/Graphics.hpp> #include <cmath> template <typename T> class Vector2 : sf::Vector2 { public: T mag(); void normalize(); void invert(); void decrease(T i); void reset(); void limit(int i); }; template <typename T> T Vector2<T>::mag() { return sqrt(this->x*2 + this->y*2); }
  9. afflicto

    C++ & SFML?

    Ah, I see. thanks :)
  10. afflicto

    C++ & SFML?

    I have a question. What's going on in the Dog::Dog() constructor there? Class Dog { private: Pig pig; Cat cat; } Dog::Dog() : pig(1) , cat() { } Coming from other OOP languages, I find this strange
  11. Played Counter-Strike: Global Offensive (PC) in the last 24 hours. http://t.co/27f7WosSnI
  12. afflicto

    C++ & SFML?

    I see. I did some stuff with the words 'linking' and 'sfml_static' I dno if that was linking.
  13. afflicto

    C++ & SFML?

    Oh... I guess my patience is not top notch today :P
  14. afflicto

    C++ & SFML?

    I found them and it works! ;D   Thanks for the quick reply btw!
  15. afflicto

    C++ & SFML?

    Hm. The tutorial on sfml-dev.org didn't say that.   Where can I find it then?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!