Add hiding of stuff and scene pause
This commit is contained in:
parent
77d5f9a8cb
commit
ea7dff32a2
11
main.cpp
11
main.cpp
@ -7,6 +7,8 @@
|
|||||||
#define STONE_ID 0x00000002
|
#define STONE_ID 0x00000002
|
||||||
#define DEATH 0x00000003
|
#define DEATH 0x00000003
|
||||||
|
|
||||||
|
bool pause = false;
|
||||||
|
|
||||||
class Player : public SDLPP::RectangleRender {
|
class Player : public SDLPP::RectangleRender {
|
||||||
public:
|
public:
|
||||||
Player(double x, double y, double w, double h, std::shared_ptr<SDLPP::Renderer> &r, double _max_gravity = 1.0, uint32_t _max_gravity_time = 1000) : SDLPP::RectangleRender(x,y,w,h,r) {
|
Player(double x, double y, double w, double h, std::shared_ptr<SDLPP::Renderer> &r, double _max_gravity = 1.0, uint32_t _max_gravity_time = 1000) : SDLPP::RectangleRender(x,y,w,h,r) {
|
||||||
@ -139,6 +141,11 @@ void handleKeyDown(SDL_Keycode key, SDLPP::Scene &scene) {
|
|||||||
case SDLK_r:
|
case SDLK_r:
|
||||||
scene.getRenderer().setRenderColiders(!scene.getRenderer().getRenderColiders());
|
scene.getRenderer().setRenderColiders(!scene.getRenderer().getRenderColiders());
|
||||||
break;
|
break;
|
||||||
|
case SDLK_SPACE:
|
||||||
|
if(pause)
|
||||||
|
scene.setPrevTicks(SDL_GetTicks());
|
||||||
|
pause = !pause;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
scene.setBackground(bgtextures[4]);
|
scene.setBackground(bgtextures[4]);
|
||||||
break;
|
break;
|
||||||
@ -191,6 +198,9 @@ void doInput(std::shared_ptr<SDLPP::Scene> scene) {
|
|||||||
while(!quit) {
|
while(!quit) {
|
||||||
SDL_framerateDelay(&gFPS);
|
SDL_framerateDelay(&gFPS);
|
||||||
pollEvents(*scene);
|
pollEvents(*scene);
|
||||||
|
if(pause)
|
||||||
|
continue;
|
||||||
|
std::cout << "NOOO" << std::endl;
|
||||||
scene->movement();
|
scene->movement();
|
||||||
bool gravity = true;
|
bool gravity = true;
|
||||||
for( auto &x : scene->getCollisions(*player) ) {
|
for( auto &x : scene->getCollisions(*player) ) {
|
||||||
@ -204,6 +214,7 @@ void doInput(std::shared_ptr<SDLPP::Scene> scene) {
|
|||||||
player->setPos(newPX, newPY);
|
player->setPos(newPX, newPY);
|
||||||
if(player->isGravityEnabled())
|
if(player->isGravityEnabled())
|
||||||
player->setLastStand();
|
player->setLastStand();
|
||||||
|
x->setHidden(true);
|
||||||
}
|
}
|
||||||
if( x->getId() == DEATH ) {
|
if( x->getId() == DEATH ) {
|
||||||
std::cout << "Oh no, you died!" << std::endl;
|
std::cout << "Oh no, you died!" << std::endl;
|
||||||
|
13
sdlpp.hpp
13
sdlpp.hpp
@ -172,7 +172,7 @@ public:
|
|||||||
virtual std::pair<std::pair<double,double>,std::pair<double,double>> getDoubleRect() = 0;
|
virtual std::pair<std::pair<double,double>,std::pair<double,double>> getDoubleRect() = 0;
|
||||||
virtual void setPos(double x, double y) = 0;
|
virtual void setPos(double x, double y) = 0;
|
||||||
bool colidesWith(const RenderObject &other) const {
|
bool colidesWith(const RenderObject &other) const {
|
||||||
if(!hasCollisions() || !other.hasCollisions()) {
|
if(!hasCollisions() || !other.hasCollisions() || getHidden() || other.getHidden()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for( const auto &x : collisions ) {
|
for( const auto &x : collisions ) {
|
||||||
@ -226,7 +226,7 @@ public:
|
|||||||
void setHidden(bool hid) {
|
void setHidden(bool hid) {
|
||||||
hidden = hid;
|
hidden = hid;
|
||||||
}
|
}
|
||||||
bool getHidden() {
|
bool getHidden() const {
|
||||||
return hidden;
|
return hidden;
|
||||||
}
|
}
|
||||||
void setColiderColor(const std::string &color) {
|
void setColiderColor(const std::string &color) {
|
||||||
@ -283,6 +283,8 @@ public:
|
|||||||
prev_ticks = now_ticks;
|
prev_ticks = now_ticks;
|
||||||
}
|
}
|
||||||
std::vector<std::shared_ptr<RenderObject>> getCollisions(RenderObject &r) {
|
std::vector<std::shared_ptr<RenderObject>> getCollisions(RenderObject &r) {
|
||||||
|
if(r.getHidden())
|
||||||
|
return {};
|
||||||
std::vector<std::shared_ptr<RenderObject>> ret{};
|
std::vector<std::shared_ptr<RenderObject>> ret{};
|
||||||
for(const auto &x : collisionObjects) {
|
for(const auto &x : collisionObjects) {
|
||||||
if(x->colidesWith(r)) {
|
if(x->colidesWith(r)) {
|
||||||
@ -336,6 +338,9 @@ public:
|
|||||||
Renderer &getRenderer() {
|
Renderer &getRenderer() {
|
||||||
return *renderer;
|
return *renderer;
|
||||||
}
|
}
|
||||||
|
void setPrevTicks(int ticks) {
|
||||||
|
prev_ticks = ticks;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
std::vector<std::shared_ptr<RenderObject>> renderObjects;
|
std::vector<std::shared_ptr<RenderObject>> renderObjects;
|
||||||
std::vector<std::shared_ptr<RenderObject>> collisionObjects;
|
std::vector<std::shared_ptr<RenderObject>> collisionObjects;
|
||||||
@ -369,9 +374,9 @@ public:
|
|||||||
setTexture(texture);
|
setTexture(texture);
|
||||||
}
|
}
|
||||||
virtual void render() {
|
virtual void render() {
|
||||||
if(texture != NULL)
|
if(texture != NULL && !getHidden())
|
||||||
SDL_RenderCopy(renderer->getRendererPtr(), texture->getTexturePtr(), NULL, &rect);
|
SDL_RenderCopy(renderer->getRendererPtr(), texture->getTexturePtr(), NULL, &rect);
|
||||||
if(hasCollisions() && renderer->getRenderColiders()) {
|
if(hasCollisions() && renderer->getRenderColiders() && !getHidden()) {
|
||||||
for(const auto &col : getCollisions())
|
for(const auto &col : getCollisions())
|
||||||
col->render(*renderer, colider_color);
|
col->render(*renderer, colider_color);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user