Mario: add goomba into moving_objects
This commit is contained in:
parent
edeeadb232
commit
28d7e208fc
@ -1,5 +1,6 @@
|
||||
#include "../sdlpp/sdlpp.hpp"
|
||||
#include "sprites.hpp"
|
||||
#include <memory>
|
||||
#ifdef _WIN32
|
||||
#include "../sdlpp/SDL2/SDL2_framerate.h"
|
||||
#include <ctime>
|
||||
@ -125,6 +126,7 @@ void pollEvents( SDLPP::Scene &scene ) {
|
||||
auto prev_mario_pos = mario->getAbsolutePos();
|
||||
scene.updateSizeAndPosition();
|
||||
moveToMarioPosition( scene, prev_mario_pos );
|
||||
update = true;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@ -154,7 +156,7 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
|
||||
moving_objects[i]->handleVisitor( *visitor );
|
||||
auto rightmost_pos = moving_objects[i]->getAbsolutePos().getX() +
|
||||
moving_objects[i]->getDoubleRect().second.getX();
|
||||
if(rightmost_pos < 0) {
|
||||
if(rightmost_pos < 0 && moving_objects[i] != mario) {
|
||||
moving_objects[i]->destroy();
|
||||
}
|
||||
}
|
||||
@ -175,14 +177,14 @@ void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
|
||||
// if player is > 0.7 of playground, move everything left
|
||||
auto playerX = mario->getRect().x;
|
||||
auto width = scene->getWidth();
|
||||
auto rightBarrier = width * 0.7;
|
||||
auto rightBarrier = width * 0.5;
|
||||
auto rightmostX =
|
||||
scene->rightmost()->getRect().x + scene->rightmost()->getRect().w;
|
||||
scene->moveEverything(
|
||||
( playerX > rightBarrier && rightmostX > width ) *
|
||||
( rightBarrier - playerX ) / width,
|
||||
0 );
|
||||
update = playerX > rightBarrier && rightmostX > width;
|
||||
update = update || (playerX > rightBarrier && rightmostX > width);
|
||||
global_frames++;
|
||||
}
|
||||
}
|
||||
@ -203,6 +205,8 @@ int main() {
|
||||
// prepare global vars
|
||||
g_terrain_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_enemies_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/enemies.png", MARIO_OVERWORLD_COLORKEY );
|
||||
|
||||
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
||||
g_playground = scene;
|
||||
@ -268,10 +272,8 @@ int main() {
|
||||
|
||||
auto base = SDL_GetTicks();
|
||||
int frames = 0;
|
||||
std::thread inputThread( doInput, scene );
|
||||
scene->moveEverything( -mario->getDoubleRect().first.getX() + 0.2, 0 );
|
||||
update = true;
|
||||
moving_objects.push_back(mario);
|
||||
|
||||
std::unordered_set<uint64_t> background_ids = {
|
||||
HILL_INCLINE_ID, HILL_DECLINE_ID, HILL_DOTS_RIGHT_ID, HILL_DOTS_LEFT_ID,
|
||||
@ -283,9 +285,25 @@ int main() {
|
||||
scene->setBackgroundObjectIDs(background_ids);
|
||||
scene->updateBackgroundObjectZIndex();
|
||||
|
||||
while ( !quit ) {
|
||||
// we want mario to be first because visiting isn't perfect
|
||||
moving_objects.push_back(mario);
|
||||
std::unordered_set<int> moving_object_ids = {
|
||||
GOOMBA_ID,
|
||||
};
|
||||
for(auto &obj : scene->getObjects(moving_object_ids)) {
|
||||
moving_objects.push_back(std::dynamic_pointer_cast<MarioBlock>(obj));
|
||||
}
|
||||
|
||||
std::thread inputThread( doInput, scene );
|
||||
SDL_PumpEvents();
|
||||
scene->updateSizeAndPosition();
|
||||
scene->renderScene();
|
||||
renderer->presentRenderer();
|
||||
|
||||
update = true;
|
||||
while ( !quit ) {
|
||||
SDL_framerateDelay( &gFPS );
|
||||
SDL_PumpEvents();
|
||||
std::lock_guard< std::mutex > lock( render_mutex );
|
||||
mario->setStanding();
|
||||
if ( update ) {
|
||||
|
Loading…
Reference in New Issue
Block a user