Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added params vor min and max stone speed and creation intervall #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions apps/tetris/Tetris/bin/data/_Tetris/effects.json
Original file line number Diff line number Diff line change
Expand Up @@ -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":"ветер",
Expand Down
8 changes: 5 additions & 3 deletions apps/tetris/Tetris/bin/data/_Tetris/params.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"height": 1920,
"gameplay":{
"winningHeightMin":0.10,
"winningHeightMax":0.25,
"winningHeightMax":0.25,
"maxDuration":80000,
"startHeightReduction":20000
},
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion apps/tetris/Tetris/src/tetris/GameEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class GameEvents
string gamestate = "idle";

float winningHeight = 0.9;

float velocityBeforeCollision = 10;
float stoneCreationIntervall = 3000;
void registerEraseEvent(ofEvent<uint64_t>& ev);

private:
Expand Down
5 changes: 5 additions & 0 deletions apps/tetris/Tetris/src/tetris/GameObjectContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GameObject> object)
{
gameControl.push_back(object);
Expand Down
2 changes: 1 addition & 1 deletion apps/tetris/Tetris/src/tetris/GameObjectContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GameObjectContainer
void addGameObject(shared_ptr<GameObject> object);
void addPaddle(shared_ptr<Paddle> object);
void addRule(shared_ptr<Rule> rule);

void setPhysics(float gravity);
shared_ptr<Rule> getRule(string name);
shared_ptr<Paddle> getPaddle(string name);
vector<shared_ptr<Paddle>> paddles;
Expand Down
18 changes: 18 additions & 0 deletions apps/tetris/Tetris/src/tetris/rules/GameControlRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ void GameControlRule::applyRule()
}
} else if (gamestate == "countdown3" && isTSwitch) {
components->events()->winningHeight = components->params()->settings["gameplay"]["winningHeightMax"].get<float>();

components->events()->stoneCreationIntervall = components->params()->settings["tetrisStone"]["stoneCreationIntervalMax"].get<float>();
components->events()->velocityBeforeCollision = components->params()->settings["tetrisStone"]["velocityBeforeCollisionMin"].get<float>();
changeGamestate("countdown2");
} else if (gamestate == "countdown2" && isTSwitch) {
changeGamestate("countdown1");
Expand All @@ -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<int>()){

components->events()->velocityBeforeCollision =
ofMap(now - startState, components->params()->settings["gameplay"]["startHeightReduction"].get<int>(),
components->params()->settings["gameplay"]["maxDuration"].get<int>(),
components->params()->settings["tetrisStone"]["velocityBeforeCollisionMin"].get<float>(),
components->params()->settings["tetrisStone"]["velocityBeforeCollisionMax"].get<float>(),true);

components->events()->stoneCreationIntervall =
ofMap(now - startState, components->params()->settings["gameplay"]["startHeightReduction"].get<int>(),
components->params()->settings["gameplay"]["maxDuration"].get<int>(),
components->params()->settings["tetrisStone"]["stoneCreationIntervalMax"].get<float>(),
components->params()->settings["tetrisStone"]["stoneCreationIntervalMin"].get<float>(),true);


components->events()->winningHeight =
ofMap(now - startState, components->params()->settings["gameplay"]["startHeightReduction"].get<int>(),
components->params()->settings["gameplay"]["maxDuration"].get<int>(),
Expand Down
25 changes: 25 additions & 0 deletions apps/tetris/Tetris/src/tetris/rules/NoGravityRule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "NoGravityRule.h"

NoGravityRule::NoGravityRule(shared_ptr<GameComponents> components,int runtime):GameRule("WindRule", components,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

}
}


}
12 changes: 12 additions & 0 deletions apps/tetris/Tetris/src/tetris/rules/NoGravityRule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include "GameRule.h"
#include "TetrisStone.h"
class NoGravityRule :
public GameRule
{
public:
NoGravityRule(shared_ptr<GameComponents> components,int runtime);
bool gravityDisabled = false;
void applyRule();
};

3 changes: 2 additions & 1 deletion apps/tetris/Tetris/src/tetris/rules/StoneControlRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ void StoneControlRule::enableGravity()
shared_ptr<TetrisStone> stone = std::static_pointer_cast<TetrisStone>(obj);
if (!stone->collided) {
for (auto& body : stone->getBody()) {
int velocity = components->params()->settings["tetrisStone"]["startVelocity"].get<int>();
int velocity = components->events()->velocityBeforeCollision;
body->setVelocity(0, velocity);
body->enableGravity(false);

};
} else {
for (auto& body : stone->getBody()) {
Expand Down
11 changes: 7 additions & 4 deletions apps/tetris/Tetris/src/tetris/rules/StoneCreationRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

StoneCreationRule::StoneCreationRule(shared_ptr<GameComponents> components) :GameRule("StoneControlRule", components)
{
produceStoneIntervallInMillis = components->params()->settings["tetrisStone"]["produceEveryMilliseconds"].get<uint64_t>();
produceStoneIntervallInMillis = components->params()->settings["tetrisStone"]["stoneCreationIntervalMax"].get<uint64_t>();
ofAddListener(components->gameControl()->physics.contactStartEvents, this, &StoneCreationRule::contactStart);
}

Expand All @@ -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() {
Expand All @@ -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);
Expand Down Expand Up @@ -130,4 +133,4 @@ void StoneCreationRule::contactStart(ofxBox2dContactArgs &e) {
collisionHandler(stone);
}
}
}
}
2 changes: 0 additions & 2 deletions apps/tetris/Tetris/src/tetris/rules/WindRule.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "WindRule.h"



WindRule::WindRule(shared_ptr<GameComponents> components,int runtime):GameRule("WindRule", components,runtime)
{

Expand Down