Trying to switch to more object-oriented

This commit is contained in:
2021-03-12 22:33:46 +01:00
parent fbe122a5b9
commit 258ce51cfe
32 changed files with 693 additions and 249 deletions
+13 -13
View File
@@ -1,4 +1,4 @@
#include "sdlpp.hpp"
#include "sdlpp/sdlpp.hpp"
#include <thread>
#include <chrono>
#include <SDL2/SDL2_framerate.h>
@@ -78,8 +78,8 @@ public:
}
if ( jump_ < 0 || jump_ > jump_speed )
jump_ = 0;
og_y += grav * time_portion;
og_y -= jump_ * time_portion;
double addition = grav * time_portion - jump_ * time_portion;
original += {0, addition};
}
private:
@@ -135,7 +135,7 @@ void addStuff( SDLPP::Scene &scene, std::shared_ptr< SDLPP::Renderer > &r ) {
while ( posx < 3 ) {
stone =
std::make_shared< Destroyable >( posx, 0.5, 0.15, 0.1, r, 1000 );
stone->addCollision( SDLPP::Rect( 0, 0, 1, 1 ) );
stone->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
stone->setColor( "#222222FF" );
stone->setId( STONE_ID );
stone->setColiderColor( "FF0000" );
@@ -143,24 +143,24 @@ void addStuff( SDLPP::Scene &scene, std::shared_ptr< SDLPP::Renderer > &r ) {
posx += 0.45;
}
auto x = std::make_shared< Player >( 0, 0, 0.2, 0.2, r );
x->addCollision( SDLPP::Rect( 0.3, 0.7, 0.05, 0.31 ) );
x->addCollision( SDLPP::Rect( 0.65, 0.7, 0.05, 0.31 ) );
x->addCollision( SDLPP::Rect( 0.2, 0.3, 0.6, 0.45 ) );
x->addCollision( SDLPP::Circle( 0.5, 0.15, 0.3 ) );
x->addCollision( SDLPP::RectColider( 0.3, 0.7, 0.05, 0.31 ) );
x->addCollision( SDLPP::RectColider( 0.65, 0.7, 0.05, 0.31 ) );
x->addCollision( SDLPP::RectColider( 0.2, 0.3, 0.6, 0.45 ) );
x->addCollision( SDLPP::CircleColider( 0.5, 0.15, 0.3 ) );
x->setColor( "E164B7" );
x->setId( PLAYER_ID );
x->setColiderColor( "00FF00" );
scene.addObject( x );
player = x;
auto z = std::make_shared< SDLPP::RectangleRender >( 0, 2.5, 0, 0, r );
auto z_col = SDLPP::Rect( -1, 0, -1, -1 );
auto z_col = SDLPP::RectColider( -1, 0, -1, -1 );
z_col.setInfinite();
z->addCollision( z_col );
z->setId( DEATH );
z->setColiderColor( "FF00FF" );
scene.addObject( z );
auto y = std::make_shared< SDLPP::TextRenderer >( 0, 0, 0.2, 0.1, r );
y->setText( *font, "DEMO", "#FFFFFF", "#000000", 5 );
y->setText( font, "DEMO", "#FFFFFF", "#000000", 5 );
y->setPermanent( true );
y->setId( 123 );
scene.addObject( y );
@@ -173,20 +173,20 @@ void addPause( SDLPP::Scene &scene, std::shared_ptr< SDLPP::Renderer > &r ) {
bg->setPermanent( true );
scene.addObject( bg );
auto y = std::make_shared< SDLPP::TextRenderer >( 0.25, 0.1, 0.5, 0.3, r );
y->setText( *font, "PAUSED", "#FFFFFF", "#000000", 5 );
y->setText( font, "PAUSED", "#FFFFFF", "#000000", 5 );
y->setId( 0 );
y->centerX();
scene.addObject( y );
auto resume =
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.5, 0.2, 0.1, r );
resume->setText( *font, "Resume", "#FFFFFF", "#000000", 5 );
resume->setText( font, "Resume", "#FFFFFF", "#000000", 5 );
resume->setColor( "#FFFFFF40" );
resume->centerX();
scene.addObject( resume );
pause_options.push_back( resume );
auto quit =
std::make_shared< SDLPP::TextRenderer >( 0.4, 0.7, 0.2, 0.1, r );
quit->setText( *font, "Quit Game", "#FFFFFF", "#000000", 5 );
quit->setText( font, "Quit Game", "#FFFFFF", "#000000", 5 );
quit->centerX();
scene.addObject( quit );
pause_options.push_back( quit );