• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=littlefoot;37066222]Can classes be ignored in C++? Am I missing something about them being more essential than just a method of organizing things?[/QUOTE] There's nothing forcing you to use classes, but OOP is a bit more than just grouping function names together with variables. Inheritance and polymorphism can be powerful tools. And even without getting into those, the encapsulation you get by distinguishing public interface from private implementation helps to keep your program well-structured and maintainable. If classes aren't the best solution for a particular task, feel free to not use them for that task, but don't decide that classes are pointless and never use them at all.
I want pixels because that would make the artsyle easier since I suck at drawing stuff, and I don't know modelling. Not sure if I want to learn a code or make a game. I have around 4 months to do it and it's not anything special, so it really depends how long it takes to learn Java. (All guides and stuff I've found for java is javascript wich appareantly isn't the same as java.) Does anyone know any online courses or something?
[QUOTE=Confuzzed Otto;37076602]I want pixels because that would make the artsyle easier since I suck at drawing stuff,[/QUOTE] ONE OF US ONE OF US But seriously google is your friend. Pick one: [url=http://lmgtfy.com/?q=lwjgl+tutorial]1[/url] [url=http://lmgtfy.com/?q=xna+tutorial]2[/url] or [url=http://www.riemers.net/]2[/url] [url=http://lmgtfy.com/?q=sfml+glfw+sdl+tutorial]3[/url] or [url=http://www.open.gl/]even better[/url] [url=https://love2d.org/wiki/Main_Page]4[/url]
Did you just link him to 4 different frameworks when he clearly said he hasn't learnt to code yet?
[QUOTE=laylay;37076880]Did you just link him to 4 different frameworks when he clearly said he hasn't learnt to code yet?[/QUOTE] That's no learning if you're not doing anything
[QUOTE=Confuzzed Otto;37076602]I want pixels because that would make the artsyle easier since I suck at drawing stuff, and I don't know modelling. Not sure if I want to learn a code or make a game. I have around 4 months to do it and it's not anything special, so it really depends how long it takes to learn Java. (All guides and stuff I've found for java is javascript wich appareantly isn't the same as java.) Does anyone know any online courses or something?[/QUOTE] If you only have 4 months you're going to struggle with a programming language. Go with Game Maker.
[url=http://math.hws.edu/javanotes/index.html]javanotes[/url]?
Got some problems with class inheritence,polymoprhism or whatever its called. When I do this Object* Player = Objects.getObjectByName("Player"); Player->Update(dt); it calls this void Object::Update(sf::Time dt) instead of this void Player::Update(sf::Time dt) Player is created like this [CODE] Object* tempobject; if(type == "Player") { tempobject = new Player; } else { tempobject = new Object; } tempobject->Load(x,y,draw,texture_id); objectList.push_back(*tempobject); [/CODE] objectList is a std::vector<Object> objectList; Player.hpp [CODE] #ifndef PLAYER #define PLAYER #include "Object.hpp" #include "SFML\Graphics.hpp" class Player : public Object { public: Player(); ~Player(); void Update(sf::Time dt); private: bool _isLoaded; }; #endif // PLAYER [/CODE] Object.hpp [CODE] #ifndef OBJECT #define OBJECT #include <SFML/Graphics.hpp> class Object { public: Object(); virtual ~Object(); virtual bool isDrawable(); virtual void Load(float x,float y,bool draw,int texture_id); virtual sf::Vector2f getPosition(); virtual sf::Vector2f getPositionL(); virtual sf::Vector2f getVelocity(); virtual void Update(sf::Time dt); virtual void setVelocity(float x,float y); virtual void setPosition(float x,float y); virtual int textureID(); virtual float getWidth(); virtual float getHeight(); virtual void Draw(); protected: int textureid; bool drawable; bool _isLoaded; sf::Vector2f position; sf::Vector2f positionL; sf::Vector2f velocity; sf::Sprite sprite; }; #endif // OBJECT [/CODE] Objects.getObjectByName() [CODE] Object* ObjectManager::getObjectByName(std::string name) { int id = -1; for(unsigned int i = 0;i<objectNames.size();i++) { if(objectNames[i] == name) { id = objectNameIDS[i]; break; } } return &objectList.at(id); } [/CODE]
[QUOTE=Sartek;37077913]Got some problems with class inheritence,polymoprhism or whatever its called. When I do this [CODE] Object* Player = Objects.getObjectByName("Player"); Player->Update(dt); [/CODE] it calls this void Object::Update(sf::Time dt) instead of this void Player::Update(sf::Time dt) Player is created like this [CODE] Object* tempobject; if(type == "Player") { tempobject = new Player; } else { tempobject = new Object; } tempobject->Load(x,y,draw,texture_id); objectList.push_back(*tempobject); [/CODE] objectList is a std::vector<Object> objectList;[/QUOTE] Make Update virtual in your Object class.
Yeah it is virtual MakeR, I think the problem is to do with my ObjectManager But not really sure.
Nevermind. [editline]4th August 2012[/editline] damn automerge. I saw your edit.
You are trying to store a derived class in a vector of the base class, the derived objects will be 'sliced' and stored as Objects in the vector. Use a vector of Object pointers instead.
Thanks pretty sure it had something to do with the way I was doing the ObjectManager Edit:Sweet changed about 4 lines of code in the objectmanager and everythings working
Just make sure you delete all your pointers when you're done with them, then remove them from the vector. You could also use something like a std::map<std::string, object*> to hold them, which will use a much more efficient lookup if you only ever need to find things by name.
Objects don't need a name but you can give them one.
[QUOTE=Wyzard;37075179]the encapsulation you get by distinguishing public interface from private implementation helps to keep your program well-structured and maintainable.[/QUOTE] opaque pointers and static functions are all you need for encapsulation
[QUOTE=swift and shift;37078858]opaque pointers and static functions are all you need for encapsulation[/QUOTE] Actually, virtual functions are basically syntactic sugar for that.
Im doing some stuff with xna, and I have been wondering even if I put tons of sprites it still doesnt use really any resource so what if I draw whole map of mario bros. at start of level and just move the map, then never need draw anything else for map will it really use much resource ?
[QUOTE=ArgvCompany;37080324]Actually, virtual functions are basically syntactic sugar for that.[/QUOTE] Well, no, not really. They have qualities that other constructs in C++ don't. Such as being in the vtable.
Hey, i'm trying to create an average "chunk" of values from an unknown amount of "chunks" of data which are all in the same array, the problem i'm having is that i only know the start and end indexes of each chunks. I don't know if i'm being blind here or something but I'm pretty stuck on how you would add each separate value onto the next in the other chunks. The start and end indexes i use to loop through the values in-between but that is as far as i have got, normally i would just look into the next "chunk" at the same index but all the chunks are in one array and have different lengths.
I'm attempting to make an isometric grid where you can select each block with the mouse. I do this by having a regular old grid and then just rotate it 45 degrees. I can't seem to translate my mouse-coordinates to select blocks after it's been rotated. It's probably really easy, but I can't get my head around it. I figure I have to do something like this: [cpp]Vec2 mouse = Input::getMousePos(); mouse.x = ldirX(mouse.x, -gridAngle) + ldirX(mouse.y, -gridAngle); mouse.y = ldirY(mouse.x, -gridAngle) + ldirY(mouse.y, -gridAngle);[/cpp] Where ldirX and ldirY are done like this: [cpp] // Calculate the vector of a given length and direction static GLfloat ldirX(GLfloat length, GLfloat direction) { return (cos(direction * (M_PI / 180.0f)) * length); } // Calculate the vector of a given length and direction static GLfloat ldirY(GLfloat length, GLfloat direction) { return (sin(direction * (M_PI / 180.0f)) * length); } [/cpp]
I have done this thousands of times, but not the isometric approach. You should be able to figure out the rest. Basically all you need to to is to divide the position with the grid size. Of course, the should be rounded of to integers. So if the grid size is 32 and mouse position is on position 48, the mouse would be at square 2. Really simple in fact. If it make it easier, try make an ordinary grind first and then rotate it. The principle is the same.
[QUOTE=AlienCat;37082433]I have done this thousands of times, but not the isometric approach. You should be able to figure out the rest. Basically all you need to to is to divide the position with the grid size. Of course, the should be rounded of to integers. So if the grid size is 32 and mouse position is on position 48, the mouse would be at square 2. Really simple in fact. If it make it easier, try make an ordinary grind first and then rotate it. The principle is the same.[/QUOTE] Oh, that part I have figured out. Here's how I've done it, basically: [cpp]GLint selected; selected = (int)((mouse.x - gridOffset.x) / tileSize.x) + (int)((mouse.y - gridOffset.y) / tileSize.y) * gridSize.x;[/cpp] Where gridsize.x is the amount of tiles along the width of the grid. It works well if the grid is not rotated, but if I draw the grid rotated it I obviously need to translate the mouse position so that it seems as if the grid itself is rotated.
Try this: [code]mouse.x = ldirX(mouse.x, -gridAngle) - ldirY(mouse.y, -gridAngle) mouse.y = ldirY(mouse.x, -gridAngle) + ldirX(mouse.y, -gridAngle)[/code]
[QUOTE=MakeR;37083007]Try this: [code]mouse.x = ldirX(mouse.x, -gridAngle) - ldirY(mouse.y, -gridAngle) mouse.y = ldirY(mouse.x, -gridAngle) + ldirX(mouse.y, -gridAngle)[/code][/QUOTE] Yes, that seems to work. I guess I was on the right track then. Still have some related issues I need to work out though.
I have a question with probably really stupid answer. Is it possible to make a Batch file that would generate and output a single random number within a certain range? If yes then how should I do it or where can I learn more about it?
[QUOTE=Jack Trades;37087561]I have a question with probably really stupid answer. Is it possible to make a Batch file that would generate and output a single random number within a certain range? If yes then how should I do it or where can I learn more about it?[/QUOTE] What possible use is this for?
[QUOTE=Jookia;37087611]What possible use is this for?[/QUOTE] To get a random number when I need it? Like a dice but with certain amount of sides.
[QUOTE=Jack Trades;37087561]I have a question with probably really stupid answer. Is it possible to make a Batch file that would generate and output a single random number within a certain range? If yes then how should I do it or where can I learn more about it?[/QUOTE] according to this thing there's %random%... [url]http://archive.atomicmpc.com.au/forums.asp?s=2&c=10&t=3221[/url]
[QUOTE=esalaka;37080988]Well, no, not really. They have qualities that other constructs in C++ don't. Such as being in the vtable.[/QUOTE] Yeah, sorry, meant to say regular functions.
Sorry, you need to Log In to post a reply to this thread.