Mario: better side collision handling
This commit is contained in:
+6
-2
@@ -10,6 +10,7 @@
|
||||
#endif // UNIX
|
||||
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include "global_vars.hpp"
|
||||
#include "objectids.hpp"
|
||||
#include "blocks.hpp"
|
||||
@@ -24,6 +25,8 @@ std::shared_ptr< SDLPP::RectangleRender > leftStop = nullptr;
|
||||
std::shared_ptr< SDLPP::Renderer > renderer = nullptr;
|
||||
std::shared_ptr< SDLPP::TextRenderer > fps = nullptr;
|
||||
|
||||
std::mutex render_mutex;
|
||||
|
||||
void handleKeyDown( SDL_Keycode key, SDLPP::Scene &scene ) {
|
||||
switch ( key ) {
|
||||
case SDLK_ESCAPE:
|
||||
@@ -125,14 +128,14 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
|
||||
while ( true ) {
|
||||
SDL_framerateDelay( &gFPS );
|
||||
pollEvents( *scene );
|
||||
auto prevPos = mario->getDoubleRect().first;
|
||||
std::lock_guard<std::mutex> lock(render_mutex);
|
||||
scene->updateScene();
|
||||
MarioVisitor mv(mario->getMovement().getY() < 0);
|
||||
scene->visitCollisions( *mario, mv );
|
||||
if ( mv.isDead() ) {
|
||||
quit = true;
|
||||
}
|
||||
mario->handleVisitor(mv, prevPos);
|
||||
mario->handleVisitor(mv);
|
||||
|
||||
// if player is > 0.7 of playground, move everything left
|
||||
auto playerX = mario->getRect().x;
|
||||
@@ -227,6 +230,7 @@ int main() {
|
||||
while ( !quit ) {
|
||||
SDL_PumpEvents();
|
||||
SDL_framerateDelay( &gFPS );
|
||||
std::lock_guard<std::mutex> lock(render_mutex);
|
||||
mario->setStanding();
|
||||
if(update) {
|
||||
scene->updateSizeAndPosition();
|
||||
|
||||
Reference in New Issue
Block a user