So I'm making my first game in SDL, and it performs so bad it slows down my linux pc to a crawl
Here's the code: https://github.com/Nyapp/Cell
You might want to take a look at entity::collisionDetect() first, because I feel like I'm doing it wrong
So I'm making my first game in SDL, and it performs so bad it slows down my linux pc to a crawl
Here's the code: https://github.com/Nyapp/Cell
You might want to take a look at entity::collisionDetect() first, because I feel like I'm doing it wrong
I didnt look over your code in any detail, so I cant comment on your speed issues, maybe its time to start profilling and debuging :)
But on a design note, I did see you have a few classes that inherrit from your texture class, i.e.
class entity : public texture
class level : public texture
This isint really correct, if you use the is-a / has-a rule here, I dont think you can correctly say
An Entity is a Texture, or a Level is a texture.
more likely:
An Entity has a Texture, a Level has a texture.
This shows you should be using compisition rather then inherittance in this case, I know this doesnt really answer your question, but just to note!
Ok, I felt bad about not at least attempting to anwer your question :P - I believe Oberon is correct here; in your update call you seem to be calling your collision detection on both your x and y axis, which is fine - but your collision detection is checking everything in the game each pass. So for each update - you are checking everything twice for collision.
You should try and reduce this down, something like quadtrees or other spacial partitioning maybe the way to go depending on how complex you see your game getting, but for a simpiler quicker way, maybe just keep track of enemys that are on screen / close enough to actually collide with - and test your collisions on this subset of enemies.
You could have a broadphaze / narrowphaze collision - where you first check if an enemy is within 500 pixels of your character - if so then check for all collision types, if not ignore it
Checking the collision for everything in a level every time will slow things down a fair amount. I think @[member='McGrane'], had a great idea in his
where you first check if an enemy is within 500 pixels of your character
Developer with a bit of Kickstarter and business experience.
YouTube Channel: Hostile Viking Studio
Twitter: @Precursors_Dawn