Skip to content

Commit

Permalink
Corrigido! (#101)
Browse files Browse the repository at this point in the history
Bug #100 corrigido!
  • Loading branch information
bestknighter authored and Anders1232 committed Jun 23, 2017
1 parent 28587cb commit 91e7307
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
3 changes: 3 additions & 0 deletions Engine/src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ void Camera::Update(float dt) {
if(INPUT_MANAGER.IsMouseScrolling()){
Camera::Zoom( (float)INPUT_MANAGER.MouseScroll().y );
}
if(INPUT_MANAGER.KeyPress('k')) {
REPORT_DEBUG2(true," CameraPos("<<pos.x<<","<<pos.y<<") with log zoom of "<<currentLogZoom);
}
}

void Camera::ForceLinearZoom(float newZoom) {
Expand Down
9 changes: 6 additions & 3 deletions Engine/src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,11 @@ float Game::GetDeltaTime(void) const {
}

void Game::UpdateStack(void) {
bool popped = false;
if(stateStack.top()->PopRequested()) {
stateStack.pop();
Resources::ClearResources();
if(!stateStack.empty()) {
stateStack.top()->Resume();
}
popped = true;
}

if(nullptr != storedState) {
Expand All @@ -188,6 +187,10 @@ void Game::UpdateStack(void) {
stateStack.push(std::unique_ptr<State>(storedState));
storedState = nullptr;
}

if(!stateStack.empty() && popped) {
stateStack.top()->Resume();
}
}

Vec2 Game::GetWindowDimensions(void) const {
Expand Down
44 changes: 22 additions & 22 deletions Game/src/StageState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ StageState::StageState(void)
, bg("img/ocean.jpg")
, tileSet(120, 120,"img/map/tileset_v2.png")
, tileMap("map/tileMap.txt", &tileSet)
, inputManager(InputManager::GetInstance())
, inputManager(INPUT_MANAGER)
, music("audio/stageState.ogg")
, isLightning(false)
, lightningTimer()
Expand Down Expand Up @@ -84,24 +84,21 @@ void StageState::Update(float dt) {

waveManager.Update(nullGameObject,dt);

if(InputManager::GetInstance().KeyPress('r')) {
if(INPUT_MANAGER.KeyPress('r')) {
popRequested = true;
Game::GetInstance().Push(new EndState(EndStateData(true)));
}

if(InputManager::GetInstance().KeyPress('t')) {
if(INPUT_MANAGER.KeyPress('t')) {
popRequested = true;
Game::GetInstance().Push(new EndState(EndStateData(false)));
}

if(InputManager::GetInstance().KeyPress('q')) {
Vec2 mousePos = Camera::ScreenToWorld(InputManager::GetInstance().GetMousePos());
if(INPUT_MANAGER.KeyPress('q')) {
Vec2 mousePos = Camera::ScreenToWorld(INPUT_MANAGER.GetMousePos());
std::cout << WHERE << "O mouse está no tile " << tileMap.GetTileMousePos(mousePos, true, 0) << ", cada layer tem " << tileMap.GetHeight()*tileMap.GetHeight() << " tiles." << END_LINE;
}

if(InputManager::GetInstance().MousePress(RIGHT_MOUSE_BUTTON)){
if(INPUT_MANAGER.MousePress(RIGHT_MOUSE_BUTTON)){
REPORT_I_WAS_HERE;
Vec2 mousePos = Camera::ScreenToWorld(InputManager::GetInstance().GetMousePos());
Vec2 mousePos = Camera::ScreenToWorld(INPUT_MANAGER.GetMousePos());
int position = tileMap.GetTileMousePos(mousePos, false, COLLISION_LAYER);
GameObject *go= tileMap.GetGO(position);
if(nullptr == go){
Expand All @@ -112,32 +109,32 @@ void StageState::Update(float dt) {
printf("adicionou drag'n drop\n");
}
}
if(InputManager::GetInstance().KeyPress('e')) {
if(INPUT_MANAGER.KeyPress('e')) {
printf("Tower criado\n");
Vec2 mousePos = Camera::ScreenToWorld(InputManager::GetInstance().GetMousePos())-Vec2(TOWER_LINEAR_SIZE/2, TOWER_LINEAR_SIZE/2);
Vec2 mousePos = Camera::ScreenToWorld(INPUT_MANAGER.GetMousePos())-Vec2(TOWER_LINEAR_SIZE/2, TOWER_LINEAR_SIZE/2);
Tower *newTower= new Tower(static_cast<Tower::TowerType>(rand() % TOTAL_TOWER_TYPES), mousePos, Vec2(TOWER_LINEAR_SIZE, TOWER_LINEAR_SIZE));
AddObject(newTower);
tileMap.InsertGO(newTower);
}
if(InputManager::GetInstance().KeyPress('=')) {
if(INPUT_MANAGER.KeyPress('=')) {
Game &game = Game::GetInstance();
game.SetMaxFramerate(game.GetMaxFramerate()+5);
}
if(InputManager::GetInstance().KeyPress('-')) {
if(INPUT_MANAGER.KeyPress('-')) {
Game &game = Game::GetInstance();
game.SetMaxFramerate( ( (int64_t)game.GetMaxFramerate() )-5);
}
tileMap.ShowCollisionInfo(InputManager::GetInstance().IsKeyDown('g'));
if(InputManager::GetInstance().IsKeyDown('[')){
tileMap.ShowCollisionInfo(INPUT_MANAGER.IsKeyDown('g'));
if(INPUT_MANAGER.IsKeyDown('[')){
Resources::ChangeMusicVolume(-STAGE_STATE_DELTA_VOLUME);
}
if(InputManager::GetInstance().IsKeyDown(']')){
if(INPUT_MANAGER.IsKeyDown(']')){
Resources::ChangeMusicVolume(STAGE_STATE_DELTA_VOLUME);
}
if(InputManager::GetInstance().IsKeyDown(',')){
if(INPUT_MANAGER.IsKeyDown(',')){
Resources::ChangeSoundVolume(-STAGE_STATE_DELTA_VOLUME);
}
if(InputManager::GetInstance().IsKeyDown('.')){
if(INPUT_MANAGER.IsKeyDown('.')){
Resources::ChangeSoundVolume(STAGE_STATE_DELTA_VOLUME);
}

Expand All @@ -163,12 +160,12 @@ void StageState::Render(void) const {

bool highlighted = true;
for(unsigned int cont=0; cont < objectArray.size(); cont++) {
if(InputManager::GetInstance().GetMousePos().IsInRect(objectArray.at(cont)->GetWorldRenderedRect())){
if(INPUT_MANAGER.GetMousePos().IsInRect(objectArray.at(cont)->GetWorldRenderedRect())){
highlighted = false;
break;
}
}
tileMap.Render(Vec2(0,0), false, highlighted ? Camera::ScreenToWorld(InputManager::GetInstance().GetMousePos()) : Vec2(-1, -1));
tileMap.Render(Vec2(0,0), false, highlighted ? Camera::ScreenToWorld(INPUT_MANAGER.GetMousePos()) : Vec2(-1, -1));
REPORT_I_WAS_HERE;
State::RenderArray();

Expand All @@ -181,7 +178,10 @@ void StageState::Render(void) const {

void StageState::Pause(void) {}

void StageState::Resume(void) {}
void StageState::Resume(void) {
Camera::pos = Vec2(CAM_START_X, CAM_START_Y);
Camera::ForceLogZoom(CAM_START_ZOOM);
}

void StageState::SpawnEnemy(int tileMapPosition) {
Vec2 tileSize = tileMap.GetTileSize();
Expand Down

0 comments on commit 91e7307

Please sign in to comment.