EntityManager, an inheritance problem

Så idag har varit en intressant dag, har börjat testa arv i c++ och det finns mycket man inte kan och man hittar ständigt nya saker som man  både kan och inte kan göra. Som “pure virtual functions“, om man vill läsa om dem så rekommenderar jag denna länken: http://www.learncpp.com/cpp-tutorial/126-pure-virtual-functions-abstract-base-classes-and-interface-classes/

Hursomhelst så har jag stött på ett problem idag när jag jobbade på en “EntityManager“, som skulle hålla en vector med “Entity” pekare. Där Entity är basklassen för alla objekt som finns i spelet, och för att simulera att jag lyckades skapa två olika sorters objekt, “WaterEnemyObject” och “FireEnemyObject“, så tänkte jag rita ut en cirkel med vardera och låta dem ha olika färg. Men med det sistnämnda så går något snett. 

När jag försöker debugga så får jag ett “Access violation error

accessviolationerror

 

Sen när jag kollar på “shape”s attributer så märker jag att man ser “Drawable” som ser mystiskt tom ut.

shapenotdrawable

 

Och för att ge ett context så skapas shape i “Entity” klassen, som man ser i bildens högra del, och sedan ska “shape” få sina egenskaper i de olika objektens “Init()” metod.

Programmet kör utmärkt om man tar bort shape och allt som har med shape att göra (förutom det som står i Entity.h), detta är testat genom att kommentera bort allt och sedan printa ut olika objektens olika x värde.

entitymanagerfungerandemedtext

 

Någon som har någon lösning på detta eller har bra länk till arv?

Tackar på förhand för all hjälp man kan få och hoppas ni har en bra dag!

Linking errors, .dll and collision makes for a groundbreaking day

Welcome everyone to another day of hard work and everything that comes with that.

Today, the thirteenth of January, I got some help from one of our student councillors with my previous problem, which to anyone out there with a similar problem is the missing of the SDL.dll file from your debug directory. As well as multiple includes of “SDL.h”, which causes the library and the main to go nuts. So pragma comment SDL2.lib and SDL2main.lib as well as including SDL.h early is advised. However that became the cause of later issues, which will be discussed in a future post.

But to solve the problem the code went a bit like this: linkerror1solve

which you can see involves the main and the engine files.

With this I finally had a “working” project which allowed me to try out new functions et cetera, which meant that I would be going on to try some collision out. And fair enough I got it to work, even though I abandoned my own collision code idea, since it had some flawed logic to it. Which was that it only noticed collision that happened if the right edge of an object was further away from the other objects right edge, which is illustrated on this image. Where the right one would be noticed while the left would just pass right through.

collisionfail

 

 

The last thing I noticed today was that I was unable to send through objects to methods, as I was forced to use a pointer instead (first time using a pointer in one of my own classes, beginning to understand them just a bit now). I do not know why I was unable to send an object through a method, though I do recall a second year:er trying to explain it to me, something about the size of the object. (and pointers will always work since they are, as far as I know, always 4 bits in size).

TL:DR
void Engine::CheckPlayerCollision(Asteroid *asteroid) <— works

void Engine::CheckPlayerCollision(Asteroid asteroid) <— does not work

Well that is all for today,

If you have any thoughts, do send a comment, otherwise have a great day!

Linking errors is a good start.

linkerror1

 

I started on our game assignment two days ago and I directly encountered some problems. (not related to the above picture)
The problems I encountered were related to me being absent from several lectures, due to hospital visits, leaving me uncapable of understanding the code hierarchy of our “big” workshop project. Which was a platformer with a more complex engine which handles sound, sprites etc. and when I look at it now I just do not understand squat. So to try to baffle this problem, I wanted to go for a slow approach to the game I was going to make.

This approach was going to be to make it as simple as possible as the start. Using few classes so that I knew where everything happened etc, and then expanding as I understood what could be done in seperate classes.

And with no visible syntax errors in sight, I decided to test the project to see if I had a rectangle that I could move around on the screen. Well, this is where the picture comes into place… Anyone that have any idea of what could be done about the linking errors?

Any tips are greatly appreciated,

Thanks and see you next time.