Add death drop
This commit is contained in:
parent
9c1fef7a86
commit
847b5cbd8e
30
main.cpp
30
main.cpp
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#define PLAYER_ID 0x00000001
|
#define PLAYER_ID 0x00000001
|
||||||
#define STONE_ID 0x00000002
|
#define STONE_ID 0x00000002
|
||||||
|
#define DEATH 0x00000003
|
||||||
|
|
||||||
class Player : public SDLPP::RectangleRender {
|
class Player : public SDLPP::RectangleRender {
|
||||||
public:
|
public:
|
||||||
@ -74,13 +75,13 @@ bool quit = false;
|
|||||||
void addStuff(SDLPP::Scene &scene, std::shared_ptr<SDLPP::Renderer> &r) {
|
void addStuff(SDLPP::Scene &scene, std::shared_ptr<SDLPP::Renderer> &r) {
|
||||||
std::shared_ptr<SDLPP::RectangleRender> stone;
|
std::shared_ptr<SDLPP::RectangleRender> stone;
|
||||||
double posx = 0;
|
double posx = 0;
|
||||||
while(posx < 1) {
|
while(posx < 3) {
|
||||||
stone = std::make_shared<SDLPP::RectangleRender>(posx,0.5,0.15,0.1,r);
|
stone = std::make_shared<SDLPP::RectangleRender>(posx,0.5,0.15,0.1,r);
|
||||||
stone->addCollision(SDLPP::Rect(0,0,1,1));
|
stone->addCollision(SDLPP::Rect(0,0,1,1));
|
||||||
stone->setTexture("stone.png");
|
stone->setTexture("stone.png");
|
||||||
stone->setId(STONE_ID);
|
stone->setId(STONE_ID);
|
||||||
scene.addObject(stone);
|
scene.addObject(stone);
|
||||||
posx += 0.15;
|
posx += 0.45;
|
||||||
}
|
}
|
||||||
auto x = std::make_shared<Player>(0,0,0.2,0.2, r);
|
auto x = std::make_shared<Player>(0,0,0.2,0.2, r);
|
||||||
x->addCollision(SDLPP::Rect(0,0,1,1));
|
x->addCollision(SDLPP::Rect(0,0,1,1));
|
||||||
@ -88,6 +89,10 @@ void addStuff(SDLPP::Scene &scene, std::shared_ptr<SDLPP::Renderer> &r) {
|
|||||||
x->setId(PLAYER_ID);
|
x->setId(PLAYER_ID);
|
||||||
scene.addObject(x);
|
scene.addObject(x);
|
||||||
player = x;
|
player = x;
|
||||||
|
auto z = std::make_shared<SDLPP::RectangleRender>(0,2.5,100,100,r);
|
||||||
|
z->addCollision(SDLPP::Rect(0,0,1,1));
|
||||||
|
z->setId(DEATH);
|
||||||
|
scene.addObject(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void quitGame() {
|
void quitGame() {
|
||||||
@ -175,8 +180,6 @@ void doInput(std::shared_ptr<SDLPP::Scene> scene) {
|
|||||||
FPSmanager gFPS;
|
FPSmanager gFPS;
|
||||||
SDL_initFramerate(&gFPS);
|
SDL_initFramerate(&gFPS);
|
||||||
SDL_setFramerate(&gFPS, 200);
|
SDL_setFramerate(&gFPS, 200);
|
||||||
int base = SDL_GetTicks();
|
|
||||||
int frames = 0;
|
|
||||||
while(!quit) {
|
while(!quit) {
|
||||||
SDL_framerateDelay(&gFPS);
|
SDL_framerateDelay(&gFPS);
|
||||||
pollEvents(*scene);
|
pollEvents(*scene);
|
||||||
@ -194,14 +197,12 @@ void doInput(std::shared_ptr<SDLPP::Scene> scene) {
|
|||||||
if(player->isGravityEnabled())
|
if(player->isGravityEnabled())
|
||||||
player->setLastStand();
|
player->setLastStand();
|
||||||
}
|
}
|
||||||
|
if( x->getId() == DEATH ) {
|
||||||
|
std::cout << "Oh no, you died!" << std::endl;
|
||||||
|
quitGame();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
player->setGravity(gravity);
|
player->setGravity(gravity);
|
||||||
frames++;
|
|
||||||
if(SDL_GetTicks() - base >= 1000) {
|
|
||||||
base = SDL_GetTicks();
|
|
||||||
printf("FPS: %d\n", frames);
|
|
||||||
frames = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,6 +221,9 @@ int main() {
|
|||||||
player->setMovementSpeed(0.3);
|
player->setMovementSpeed(0.3);
|
||||||
player->enableGravity();
|
player->enableGravity();
|
||||||
|
|
||||||
|
int base = SDL_GetTicks();
|
||||||
|
int frames = 0;
|
||||||
|
|
||||||
FPSmanager gFPS;
|
FPSmanager gFPS;
|
||||||
SDL_initFramerate(&gFPS);
|
SDL_initFramerate(&gFPS);
|
||||||
SDL_setFramerate(&gFPS, 60);
|
SDL_setFramerate(&gFPS, 60);
|
||||||
@ -228,6 +232,12 @@ int main() {
|
|||||||
SDL_framerateDelay(&gFPS);
|
SDL_framerateDelay(&gFPS);
|
||||||
main_scene->renderScene();
|
main_scene->renderScene();
|
||||||
main_scene->presentScene();
|
main_scene->presentScene();
|
||||||
|
frames++;
|
||||||
|
if(SDL_GetTicks() - base >= 1000) {
|
||||||
|
base = SDL_GetTicks();
|
||||||
|
printf("FPS: %d\n", frames);
|
||||||
|
frames = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
inputThread.join();
|
inputThread.join();
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,8 @@ public:
|
|||||||
setTexture(texture);
|
setTexture(texture);
|
||||||
}
|
}
|
||||||
virtual void render() {
|
virtual void render() {
|
||||||
SDL_RenderCopy(renderer->getRendererPtr(), texture->getTexturePtr(), NULL, &rect);
|
if(texture != NULL)
|
||||||
|
SDL_RenderCopy(renderer->getRendererPtr(), texture->getTexturePtr(), NULL, &rect);
|
||||||
}
|
}
|
||||||
virtual void move(int ticks) {
|
virtual void move(int ticks) {
|
||||||
auto dimension = renderer->getSmallerSide();
|
auto dimension = renderer->getSmallerSide();
|
||||||
|
Loading…
Reference in New Issue
Block a user