From 0b349969d72c586978183ce2b25d360fe096eee4 Mon Sep 17 00:00:00 2001 From: martin Date: Fri, 21 Sep 2018 15:45:53 +0200 Subject: [PATCH 1/2] Auto stash before merge of "master" and "origin/master" --- .../Tetris/bin/data/_Tetris/effects.json | 8 ------ apps/tetris/Tetris/src/NoGravityRule.cpp | 28 +++++++++++++++++++ apps/tetris/Tetris/src/NoGravityRule.h | 12 ++++++++ apps/tetris/Tetris/src/NoGravityRule.hpp | 13 +++++++++ .../Tetris/src/tetris/GameObjectContainer.cpp | 5 ++++ .../src/tetris/rules/StoneControlRule.cpp | 1 + 6 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 apps/tetris/Tetris/src/NoGravityRule.cpp create mode 100644 apps/tetris/Tetris/src/NoGravityRule.h create mode 100644 apps/tetris/Tetris/src/NoGravityRule.hpp diff --git a/apps/tetris/Tetris/bin/data/_Tetris/effects.json b/apps/tetris/Tetris/bin/data/_Tetris/effects.json index 389d7bf..3b601c1 100644 --- a/apps/tetris/Tetris/bin/data/_Tetris/effects.json +++ b/apps/tetris/Tetris/bin/data/_Tetris/effects.json @@ -15,14 +15,6 @@ "sound":"Eisiger Stein.mp3", "type":"stone" }, - { - "state":"big", - "main":"большой камень", - "sub":"(großer Stein)", - "time": 2000, - "sound":"Grosser Stein.mp3", - "type":"stone" - }, { "state":"wind", "main":"ветер", diff --git a/apps/tetris/Tetris/src/NoGravityRule.cpp b/apps/tetris/Tetris/src/NoGravityRule.cpp new file mode 100644 index 0000000..2f5fe12 --- /dev/null +++ b/apps/tetris/Tetris/src/NoGravityRule.cpp @@ -0,0 +1,28 @@ +#include "NoGravityRule.h" + + + +NoGravityRule::NoGravityRule(GameParameters* params,int runtime):Rule("NoGravityRule", params,runtime) +{ + +} + +void NoGravityRule::applyRule() +{ + + bool disableOnRuleEnd = ofGetElapsedTimef()-getCreationTime() > runtime -5; + + if(!gravityDisabled && !disableOnRuleEnd) { + int i = 0; + // apply on runtime start + + gravityDisabled = true; + } else { + if(disableOnRuleEnd) { + // apply on runtime end + + } + } + + +} diff --git a/apps/tetris/Tetris/src/NoGravityRule.h b/apps/tetris/Tetris/src/NoGravityRule.h new file mode 100644 index 0000000..bc26d4e --- /dev/null +++ b/apps/tetris/Tetris/src/NoGravityRule.h @@ -0,0 +1,12 @@ +#pragma once +#include "Rule.h" +#include "TetrisStone.h" +class NoGravityRule : + public Rule +{ +public: + NoGravityRule(GameParameters* params,int runtime); + bool gravityDisabled = false; + void applyRule(); +}; + diff --git a/apps/tetris/Tetris/src/NoGravityRule.hpp b/apps/tetris/Tetris/src/NoGravityRule.hpp new file mode 100644 index 0000000..275932f --- /dev/null +++ b/apps/tetris/Tetris/src/NoGravityRule.hpp @@ -0,0 +1,13 @@ +// +// NoGravityRule.hpp +// Tetris +// +// Created by Martin Herrmann on 25.08.18. +// + +#ifndef NoGravityRule_hpp +#define NoGravityRule_hpp + +#include + +#endif /* NoGravityRule_hpp */ diff --git a/apps/tetris/Tetris/src/tetris/GameObjectContainer.cpp b/apps/tetris/Tetris/src/tetris/GameObjectContainer.cpp index dfce39d..3e37a81 100644 --- a/apps/tetris/Tetris/src/tetris/GameObjectContainer.cpp +++ b/apps/tetris/Tetris/src/tetris/GameObjectContainer.cpp @@ -19,6 +19,11 @@ void GameObjectContainer::initPhysics(float gravity) physics.setFPS(60.0); } +void GameObjectContainer::setPhysics(float gravity) +{ + physics.setGravity(0, gravity); +} + void GameObjectContainer::addGameObject(shared_ptr object) { gameControl.push_back(object); diff --git a/apps/tetris/Tetris/src/tetris/rules/StoneControlRule.cpp b/apps/tetris/Tetris/src/tetris/rules/StoneControlRule.cpp index 53dfbbc..c561a3d 100644 --- a/apps/tetris/Tetris/src/tetris/rules/StoneControlRule.cpp +++ b/apps/tetris/Tetris/src/tetris/rules/StoneControlRule.cpp @@ -23,6 +23,7 @@ void StoneControlRule::enableGravity() int velocity = components->params()->settings["tetrisStone"]["startVelocity"].get(); body->setVelocity(0, velocity); body->enableGravity(false); + }; } else { for (auto& body : stone->getBody()) { From 0f8b365125b9b513870e21092539d758db52cbb7 Mon Sep 17 00:00:00 2001 From: martin Date: Sat, 22 Sep 2018 08:17:13 +0200 Subject: [PATCH 2/2] speed up stone creation and velocity, added params for min and max --- .../tetris/Tetris/bin/data/_Tetris/params.json | 8 +++++--- apps/tetris/Tetris/src/NoGravityRule.hpp | 13 ------------- apps/tetris/Tetris/src/tetris/GameEvents.h | 3 ++- .../Tetris/src/tetris/GameObjectContainer.h | 2 +- .../src/tetris/rules/GameControlRule.cpp | 18 ++++++++++++++++++ .../src/{ => tetris/rules}/NoGravityRule.cpp | 5 +---- .../src/{ => tetris/rules}/NoGravityRule.h | 6 +++--- .../src/tetris/rules/StoneControlRule.cpp | 2 +- .../src/tetris/rules/StoneCreationRule.cpp | 11 +++++++---- .../Tetris/src/tetris/rules/WindRule.cpp | 2 -- 10 files changed, 38 insertions(+), 32 deletions(-) delete mode 100644 apps/tetris/Tetris/src/NoGravityRule.hpp rename apps/tetris/Tetris/src/{ => tetris/rules}/NoGravityRule.cpp (77%) rename apps/tetris/Tetris/src/{ => tetris/rules}/NoGravityRule.h (53%) diff --git a/apps/tetris/Tetris/bin/data/_Tetris/params.json b/apps/tetris/Tetris/bin/data/_Tetris/params.json index 66dc0d6..3574a9b 100644 --- a/apps/tetris/Tetris/bin/data/_Tetris/params.json +++ b/apps/tetris/Tetris/bin/data/_Tetris/params.json @@ -3,7 +3,7 @@ "height": 1920, "gameplay":{ "winningHeightMin":0.10, - "winningHeightMax":0.25, + "winningHeightMax":0.25, "maxDuration":80000, "startHeightReduction":20000 }, @@ -36,9 +36,11 @@ }, "tetrisStone": { "density": 1.0, - "produceEveryMilliseconds": 8000, + "stoneCreationIntervalMax" :5000, + "stoneCreationIntervalMin" : 500, "scale":20, - "startVelocity": 10 + "velocityBeforeCollisionMin": 10, + "velocityBeforeCollisionMax": 30 }, "paddle": { "width": 450, diff --git a/apps/tetris/Tetris/src/NoGravityRule.hpp b/apps/tetris/Tetris/src/NoGravityRule.hpp deleted file mode 100644 index 275932f..0000000 --- a/apps/tetris/Tetris/src/NoGravityRule.hpp +++ /dev/null @@ -1,13 +0,0 @@ -// -// NoGravityRule.hpp -// Tetris -// -// Created by Martin Herrmann on 25.08.18. -// - -#ifndef NoGravityRule_hpp -#define NoGravityRule_hpp - -#include - -#endif /* NoGravityRule_hpp */ diff --git a/apps/tetris/Tetris/src/tetris/GameEvents.h b/apps/tetris/Tetris/src/tetris/GameEvents.h index 579494c..120c9dc 100644 --- a/apps/tetris/Tetris/src/tetris/GameEvents.h +++ b/apps/tetris/Tetris/src/tetris/GameEvents.h @@ -26,7 +26,8 @@ class GameEvents string gamestate = "idle"; float winningHeight = 0.9; - + float velocityBeforeCollision = 10; + float stoneCreationIntervall = 3000; void registerEraseEvent(ofEvent& ev); private: diff --git a/apps/tetris/Tetris/src/tetris/GameObjectContainer.h b/apps/tetris/Tetris/src/tetris/GameObjectContainer.h index 82bd6d4..ffd28f2 100644 --- a/apps/tetris/Tetris/src/tetris/GameObjectContainer.h +++ b/apps/tetris/Tetris/src/tetris/GameObjectContainer.h @@ -18,7 +18,7 @@ class GameObjectContainer void addGameObject(shared_ptr object); void addPaddle(shared_ptr object); void addRule(shared_ptr rule); - + void setPhysics(float gravity); shared_ptr getRule(string name); shared_ptr getPaddle(string name); vector> paddles; diff --git a/apps/tetris/Tetris/src/tetris/rules/GameControlRule.cpp b/apps/tetris/Tetris/src/tetris/rules/GameControlRule.cpp index dcecf76..28dd9ca 100644 --- a/apps/tetris/Tetris/src/tetris/rules/GameControlRule.cpp +++ b/apps/tetris/Tetris/src/tetris/rules/GameControlRule.cpp @@ -65,6 +65,9 @@ void GameControlRule::applyRule() } } else if (gamestate == "countdown3" && isTSwitch) { components->events()->winningHeight = components->params()->settings["gameplay"]["winningHeightMax"].get(); + + components->events()->stoneCreationIntervall = components->params()->settings["tetrisStone"]["stoneCreationIntervalMax"].get(); + components->events()->velocityBeforeCollision = components->params()->settings["tetrisStone"]["velocityBeforeCollisionMin"].get(); changeGamestate("countdown2"); } else if (gamestate == "countdown2" && isTSwitch) { changeGamestate("countdown1"); @@ -79,9 +82,24 @@ void GameControlRule::applyRule() else if (gameControl->paddles[1]->towerHeight > winningHeight) { changeGamestate("end2"); } + //reduce winning height if (now - startState > components->params()->settings["gameplay"]["startHeightReduction"].get()){ + + components->events()->velocityBeforeCollision = + ofMap(now - startState, components->params()->settings["gameplay"]["startHeightReduction"].get(), + components->params()->settings["gameplay"]["maxDuration"].get(), + components->params()->settings["tetrisStone"]["velocityBeforeCollisionMin"].get(), + components->params()->settings["tetrisStone"]["velocityBeforeCollisionMax"].get(),true); + + components->events()->stoneCreationIntervall = + ofMap(now - startState, components->params()->settings["gameplay"]["startHeightReduction"].get(), + components->params()->settings["gameplay"]["maxDuration"].get(), + components->params()->settings["tetrisStone"]["stoneCreationIntervalMax"].get(), + components->params()->settings["tetrisStone"]["stoneCreationIntervalMin"].get(),true); + + components->events()->winningHeight = ofMap(now - startState, components->params()->settings["gameplay"]["startHeightReduction"].get(), components->params()->settings["gameplay"]["maxDuration"].get(), diff --git a/apps/tetris/Tetris/src/NoGravityRule.cpp b/apps/tetris/Tetris/src/tetris/rules/NoGravityRule.cpp similarity index 77% rename from apps/tetris/Tetris/src/NoGravityRule.cpp rename to apps/tetris/Tetris/src/tetris/rules/NoGravityRule.cpp index 2f5fe12..92d1413 100644 --- a/apps/tetris/Tetris/src/NoGravityRule.cpp +++ b/apps/tetris/Tetris/src/tetris/rules/NoGravityRule.cpp @@ -1,9 +1,6 @@ #include "NoGravityRule.h" - - -NoGravityRule::NoGravityRule(GameParameters* params,int runtime):Rule("NoGravityRule", params,runtime) -{ +NoGravityRule::NoGravityRule(shared_ptr components,int runtime):GameRule("WindRule", components,runtime){ } diff --git a/apps/tetris/Tetris/src/NoGravityRule.h b/apps/tetris/Tetris/src/tetris/rules/NoGravityRule.h similarity index 53% rename from apps/tetris/Tetris/src/NoGravityRule.h rename to apps/tetris/Tetris/src/tetris/rules/NoGravityRule.h index bc26d4e..15a05d1 100644 --- a/apps/tetris/Tetris/src/NoGravityRule.h +++ b/apps/tetris/Tetris/src/tetris/rules/NoGravityRule.h @@ -1,11 +1,11 @@ #pragma once -#include "Rule.h" +#include "GameRule.h" #include "TetrisStone.h" class NoGravityRule : - public Rule + public GameRule { public: - NoGravityRule(GameParameters* params,int runtime); + NoGravityRule(shared_ptr components,int runtime); bool gravityDisabled = false; void applyRule(); }; diff --git a/apps/tetris/Tetris/src/tetris/rules/StoneControlRule.cpp b/apps/tetris/Tetris/src/tetris/rules/StoneControlRule.cpp index c561a3d..d738272 100644 --- a/apps/tetris/Tetris/src/tetris/rules/StoneControlRule.cpp +++ b/apps/tetris/Tetris/src/tetris/rules/StoneControlRule.cpp @@ -20,7 +20,7 @@ void StoneControlRule::enableGravity() shared_ptr stone = std::static_pointer_cast(obj); if (!stone->collided) { for (auto& body : stone->getBody()) { - int velocity = components->params()->settings["tetrisStone"]["startVelocity"].get(); + int velocity = components->events()->velocityBeforeCollision; body->setVelocity(0, velocity); body->enableGravity(false); diff --git a/apps/tetris/Tetris/src/tetris/rules/StoneCreationRule.cpp b/apps/tetris/Tetris/src/tetris/rules/StoneCreationRule.cpp index 128f3f4..193d5d6 100644 --- a/apps/tetris/Tetris/src/tetris/rules/StoneCreationRule.cpp +++ b/apps/tetris/Tetris/src/tetris/rules/StoneCreationRule.cpp @@ -4,7 +4,7 @@ StoneCreationRule::StoneCreationRule(shared_ptr components) :GameRule("StoneControlRule", components) { - produceStoneIntervallInMillis = components->params()->settings["tetrisStone"]["produceEveryMilliseconds"].get(); + produceStoneIntervallInMillis = components->params()->settings["tetrisStone"]["stoneCreationIntervalMax"].get(); ofAddListener(components->gameControl()->physics.contactStartEvents, this, &StoneCreationRule::contactStart); } @@ -14,7 +14,10 @@ StoneCreationRule::~StoneCreationRule() } void StoneCreationRule::applyRule() { - if (components->events()->gamestate == "game") produceStoneByIntervall(); + if (components->events()->gamestate == "game"){ + produceStoneByIntervall(); + produceStoneIntervallInMillis = components->events()->stoneCreationIntervall; + } } void StoneCreationRule::produceStoneByIntervall() { @@ -28,7 +31,7 @@ void StoneCreationRule::produceStoneByIntervall() { void StoneCreationRule::produceStone(int player) { - if (getLastCreatedStone(player) == nullptr || getLastCreatedStone(player)->getBody()[0]->getPosition().y >500) { + if (getLastCreatedStone(player) == nullptr || getLastCreatedStone(player)->getBody()[0]->getPosition().y >300) { //create stone auto stone = GameFactory::makeTetrisStone(components, components->events()->nextCreationRule[player - 1]); stone->setPlayer(player); @@ -130,4 +133,4 @@ void StoneCreationRule::contactStart(ofxBox2dContactArgs &e) { collisionHandler(stone); } } -} \ No newline at end of file +} diff --git a/apps/tetris/Tetris/src/tetris/rules/WindRule.cpp b/apps/tetris/Tetris/src/tetris/rules/WindRule.cpp index fadb4a0..6154bc7 100644 --- a/apps/tetris/Tetris/src/tetris/rules/WindRule.cpp +++ b/apps/tetris/Tetris/src/tetris/rules/WindRule.cpp @@ -1,7 +1,5 @@ #include "WindRule.h" - - WindRule::WindRule(shared_ptr components,int runtime):GameRule("WindRule", components,runtime) {