From a245066b3c0bc37e575733669296e6bfc46bfaf7 Mon Sep 17 00:00:00 2001 From: SGOrava Date: Sun, 9 Nov 2014 19:06:59 +0100 Subject: [PATCH 1/7] Fix bug when Space pressed... --- playstate.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/playstate.cpp b/playstate.cpp index 148f137..8617532 100644 --- a/playstate.cpp +++ b/playstate.cpp @@ -1,8 +1,10 @@ # include "game.hpp" # include "states.hpp" + PlayState PlayState::m_PlayState; + void PlayState::Init() { Map = map(); @@ -64,6 +66,7 @@ void PlayState::HandleEvents ( game* Game ) if ( event.type == SDL_QUIT) Game->Quit(); + /* Game Over - Write name for score */ if( nameEntering == true && nameEntered == false ) { //Get user input @@ -88,13 +91,16 @@ void PlayState::HandleEvents ( game* Game ) name.show_centered(Game); } + /* Game key logic... */ else { switch ( event.type ) { + /* key pressed.... */ case SDL_KEYDOWN: switch ( event.key.keysym.sym ) { + /* ESCAPE - Pause game (run PauseState) */ case SDLK_ESCAPE: { //Game->SetRunning(false); @@ -102,8 +108,10 @@ void PlayState::HandleEvents ( game* Game ) } break; + /* move part to the right */ case SDLK_RIGHT: { + /* */ part p = Part; # ifdef DEBUG @@ -191,7 +199,7 @@ void PlayState::HandleEvents ( game* Game ) { Part.move ( 0, 1 ); - tick = FPS - 1; + tick = ( FPS / ( ( level > 30 ) ? 30 : level ) ) - 1; } break; @@ -213,8 +221,10 @@ void PlayState::HandleEvents ( game* Game ) void PlayState::Update ( game* Game ) { + /* kontrola či je plné hracie pole... */ if ( Map.isFull() ) { + /* Start enter name */ nameEntering = true; if (nameEntered) @@ -246,8 +256,12 @@ void PlayState::Update ( game* Game ) Part.move ( 0, 1 ); } + /* + if ( tick % ( FPS / ( ( level > 30 ) ? 30 : level ) ) != 0 && Map.isCollision ( Part ) && tick != ( FPS / ( ( level > 30 ) ? 30 : level ) ) -1 ) + std::cout << "DEBUG" << std::endl; + */ - if ( Map.isCollision ( Part ) && tick + 1 == ( FPS / ( ( level > 30 ) ? 30 : level ) ) ) + if ( Map.isCollision ( Part ) && ( tick ) == ( FPS / ( ( level > 30 ) ? 30 : level ) ) -1 ) { int count; From b3f02858bd510fcd4041b66314d16ed7db1521d5 Mon Sep 17 00:00:00 2001 From: SGOrava Date: Mon, 6 Apr 2015 16:18:44 +0200 Subject: [PATCH 2/7] =?UTF-8?q?mal=C3=A1=20=C3=BAprava=20priecinkov...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .kdev4/Tetris.kdev4 | 3 + src/CMakeLists.txt | 24 +++ src/LICENCE | 23 +++ src/game.cpp | 228 +++++++++++++++++++++++++++ src/game.hpp | 73 +++++++++ src/gamestate.hpp | 32 ++++ src/global.cpp | 29 ++++ src/global.hpp | 19 +++ src/main.cpp | 44 ++++++ src/map.cpp | 140 +++++++++++++++++ src/map.hpp | 29 ++++ src/menu.cpp | 68 ++++++++ src/menu.hpp | 34 ++++ src/menuitem.cpp | 39 +++++ src/menuitem.hpp | 34 ++++ src/menustate.cpp | 127 +++++++++++++++ src/menustate.hpp | 52 ++++++ src/part.cpp | 132 ++++++++++++++++ src/part.hpp | 45 ++++++ src/pausestate.cpp | 110 +++++++++++++ src/pausestate.hpp | 48 ++++++ src/playstate.cpp | 373 ++++++++++++++++++++++++++++++++++++++++++++ src/playstate.hpp | 68 ++++++++ src/resource.cpp | 21 +++ src/resource.hpp | 203 ++++++++++++++++++++++++ src/scoreitem.cpp | 35 +++++ src/scoreitem.hpp | 32 ++++ src/scorestate.cpp | 108 +++++++++++++ src/scorestate.hpp | 46 ++++++ src/states.hpp | 4 + src/stringinput.cpp | 99 ++++++++++++ src/stringinput.hpp | 35 +++++ 33 files changed, 2358 insertions(+) create mode 100644 src/CMakeLists.txt create mode 100644 src/LICENCE create mode 100644 src/game.cpp create mode 100644 src/game.hpp create mode 100644 src/gamestate.hpp create mode 100644 src/global.cpp create mode 100644 src/global.hpp create mode 100644 src/main.cpp create mode 100644 src/map.cpp create mode 100644 src/map.hpp create mode 100644 src/menu.cpp create mode 100644 src/menu.hpp create mode 100644 src/menuitem.cpp create mode 100644 src/menuitem.hpp create mode 100644 src/menustate.cpp create mode 100644 src/menustate.hpp create mode 100644 src/part.cpp create mode 100644 src/part.hpp create mode 100644 src/pausestate.cpp create mode 100644 src/pausestate.hpp create mode 100644 src/playstate.cpp create mode 100644 src/playstate.hpp create mode 100644 src/resource.cpp create mode 100644 src/resource.hpp create mode 100644 src/scoreitem.cpp create mode 100644 src/scoreitem.hpp create mode 100644 src/scorestate.cpp create mode 100644 src/scorestate.hpp create mode 100644 src/states.hpp create mode 100644 src/stringinput.cpp create mode 100644 src/stringinput.hpp diff --git a/.gitignore b/.gitignore index 47772a3..6d65327 100644 --- a/.gitignore +++ b/.gitignore @@ -44,3 +44,4 @@ install_manifest.txt windows* build/tetris +.kdev4* diff --git a/.kdev4/Tetris.kdev4 b/.kdev4/Tetris.kdev4 index 89e105a..2ffea92 100644 --- a/.kdev4/Tetris.kdev4 +++ b/.kdev4/Tetris.kdev4 @@ -49,5 +49,8 @@ Use External Terminal=true Working Directory= isExecutable=false +[Project] +VersionControlSupport=kdevgit + [SourceFileTemplates] LastUsedTemplate=/home/juraj/.kde/share/apps/kdevfiletemplates/template_descriptions/cpp_basic.desktop diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..2fa0007 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 2.8) + +add_executable(${EXE_NAME} + scoreitem.cpp + scorestate.cpp + stringinput.cpp + part.cpp + main.cpp + global.cpp + map.cpp + resource.cpp + game.cpp + pausestate.cpp + playstate.cpp + menustate.cpp + menuitem.cpp + menu.cpp +) + +target_link_libraries(${EXE_NAME} SDL SDL_ttf) + +set(CMAKE_CXX_FLAGS "-Wextra -ftabstop=4 -march=native -std=gnu++11 -fshow-column -ftabstop=4 -frounding-math -pipe") + +install(TARGETS ${EXE_NAME} RUNTIME DESTINATION bin) diff --git a/src/LICENCE b/src/LICENCE new file mode 100644 index 0000000..4e45844 --- /dev/null +++ b/src/LICENCE @@ -0,0 +1,23 @@ +Copyright (c) 2014, [SG]Orava +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/game.cpp b/src/game.cpp new file mode 100644 index 0000000..8fcf29d --- /dev/null +++ b/src/game.cpp @@ -0,0 +1,228 @@ +#include "game.hpp" +#include "gamestate.hpp" + + +game::game() +{ } + +game::~game() +{ } + + + +bool game::Init() +{ + if ( SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO ) == -1 ) + { + cerr << "[ERROR] Cannot init SDL" << endl; + + m_bRunning = false; + + return false; + } + + SDL_EnableUNICODE ( SDL_ENABLE ); + + + SDL_WM_SetCaption ( "[SG]Tetris", NULL ); + + m_pScreen = SDL_SetVideoMode ( WIDTH * SIZE + 130, HEIGHT * SIZE, 32, SDL_HWSURFACE | SDL_DOUBLEBUF ); + + if ( m_pScreen == NULL ) + { + cerr << "[ERROR] Cannot setup screen" << endl; + + m_bRunning = false; + + return false; + } + + + if ( TTF_Init() ) + { + cerr << "[ERROR] Cannot init SDL_ttf" << endl; + + m_bRunning = false; + + return false; + } + + + m_bRunning = Load(); + m_bGameOver = false; + tick = 0; + + return m_bRunning; +} + +bool game::Load() +{ + fontMenu = TTF_OpenFont ( "data-latin.ttf", 38 ); + + if ( fontMenu == NULL ) + { + cerr << "[ERROR] Cannot load font 'data-latin.ttf'" << endl; + + return false; + } + + + fontGame = TTF_OpenFont ( "handelgotd.ttf", 30 ); + + if ( fontGame == NULL ) + { + cerr << "[ERROR] Cannot load font 'handelgotd.ttf'" << endl; + + return false; + } + + + return true; +} + +void game::ChangeState ( GameState * state ) +{ + // cleanup the current state + if ( !states.empty() ) + { + states.back()->Clean(); + states.pop_back(); + } + + // store and init the new state + states.push_back ( state ); + states.back()->Init(); +} + +void game::PushState ( GameState * state ) +{ + // pause current state + if ( !states.empty() ) + { + states.back()->Pause(); + } + + // store and init the new state + states.push_back ( state ); + states.back()->Init(); +} + +void game::PopState() +{ + // cleanup the current state + if ( !states.empty() ) + { + states.back()->Clean(); + states.pop_back(); + } + + // resume previous state + if ( !states.empty() ) + { + states.back()->Resume(); + } +} + +void game::DelStateF() +{ + // cleanup the first state + if ( !states.empty() ) + { + states.front()->Clean(); + states.erase(states.begin()); + } +} + +# ifdef DEBUG + int game::CountStates() + { + return states.size(); + } +# endif + +void game::HandleEvents() +{ + states.back()->HandleEvents ( this ); +} + +void game::Update() +{ + states.back()->Update ( this ); +} + +void game::Draw() +{ + states.back()->Draw ( this ); +} + + +SDL_Surface * game::GetScreen() +{ + return m_pScreen; +} + +bool game::Running() +{ + return m_bRunning; +} + +void game::Clean() +{ + # ifdef DEBUG + cout << "Cleanning..." << endl; + # endif + + TTF_CloseFont ( fontMenu ); + + TTF_Quit(); + SDL_Quit(); +} + +void game::Quit() +{ + m_bRunning = false; + + # ifdef DEBUG + cout << "Shutting down..." << endl; + # endif +} + +void game::ReduceFPS() +{ + if ( 1000 / FPS > ( SDL_GetTicks() - start ) ) + { + SDL_Delay ( 1000 / FPS - ( SDL_GetTicks() - start ) ); + } +} + +void game::UpdateFPS() +{ + if ( tick <= FPS ) + { + tick += 1; + } + else + { + tick = 1; + } +} + +Uint32 game::GetStart() +{ + return start; +} + +void game::SetStart ( Uint32 start ) +{ + this->start = start; +} + +TTF_Font * game::GetfontGame() +{ + return fontGame; +} + +TTF_Font * game::GetfontMenu() +{ + return fontMenu; +} diff --git a/src/game.hpp b/src/game.hpp new file mode 100644 index 0000000..105b1ca --- /dev/null +++ b/src/game.hpp @@ -0,0 +1,73 @@ +#ifndef GAME_HPP_INCLUDED +#define GAME_HPP_INCLUDED + +#include +#include +#include +#include + +#include "map.hpp" +#include "part.hpp" + + +using namespace std; + + +class GameState; + +class game +{ + public: + game(); + ~game(); + + bool Init(); + bool Load(); + + void ChangeState ( GameState * state ); + void PushState ( GameState * state ); + void PopState(); + void DelStateF(); + + # ifdef DEBUG + int CountStates(); + # endif + + + void HandleEvents(); + void Update(); + void Draw(); + + SDL_Surface * GetScreen(); + Uint32 GetStart(); + + TTF_Font * GetfontMenu(); + TTF_Font * GetfontGame(); + + void SetStart ( Uint32 start ); + void SetRunning ( bool m_bRunning ); + + void Clean(); + + bool Running(); + void Quit(); + + void ReduceFPS(); + void UpdateFPS(); + + private: + SDL_Surface * m_pScreen; + vector states; + + bool m_bRunning; + bool m_bGameOver; + + TTF_Font * fontMenu; + TTF_Font * fontGame; + + Uint32 start; + int tick; +}; + + +#endif diff --git a/src/gamestate.hpp b/src/gamestate.hpp new file mode 100644 index 0000000..ef2e653 --- /dev/null +++ b/src/gamestate.hpp @@ -0,0 +1,32 @@ +#ifndef GAME_STATE_HPP_INCLUDED +#define GAME_STATE_HPP_INCLUDED + +#include "game.hpp" + + +class GameState +{ + public: + virtual void Init() = 0; + virtual void Clean() = 0; + + virtual void Pause() = 0; + virtual void Resume() = 0; + + virtual void HandleEvents ( game * Game ) = 0; + virtual void Update ( game * Game ) = 0; + virtual void Draw ( game * Game ) = 0; + + void ChangeState ( game * Game, GameState * state ) + { + Game->ChangeState ( state ); + } + + protected: + GameState() { } + + bool FirstRun; +}; + + +#endif diff --git a/src/global.cpp b/src/global.cpp new file mode 100644 index 0000000..be01a1c --- /dev/null +++ b/src/global.cpp @@ -0,0 +1,29 @@ +#include "global.hpp" + + +void drawQuad ( SDL_Surface * screen, short int x, short int y, int color ) +{ + SDL_Rect rect = {x, y, SIZE, SIZE}; + + SDL_FillRect ( screen, &rect, color ); +} + +void apply_surface ( int x, int y, SDL_Surface * source, SDL_Surface * destination, SDL_Rect * clip ) +{ + //Holds offsets + SDL_Rect offset; + + //Get offsets + offset.x = x; + offset.y = y; + + //Blit + SDL_BlitSurface ( source, clip, destination, &offset ); +} + +SDL_Color make_color ( Uint8 r, Uint8 g, Uint8 b ) +{ + SDL_Color color = {r, g, b}; + + return color; +} diff --git a/src/global.hpp b/src/global.hpp new file mode 100644 index 0000000..f94e847 --- /dev/null +++ b/src/global.hpp @@ -0,0 +1,19 @@ +#ifndef GLOBAL_HPP_INCLUDED +#define GLOBAL_HPP_INCLUDED + +#include +#include +#include +#include + +#include "resource.hpp" + + + + +void drawQuad ( SDL_Surface* screen, short int x, short int y, int color ); +void apply_surface ( int x, int y, SDL_Surface * source, SDL_Surface * destination, SDL_Rect * clip = NULL ); +SDL_Color make_color ( Uint8 r, Uint8 g, Uint8 b ); + + +#endif diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..6d9bcb3 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +#include "resource.hpp" +#include "global.hpp" +#include "game.hpp" + +#include "states.hpp" + + +using namespace std; + + +int main ( int argc, char ** argv ) +{ + srand ( time ( NULL ) ); + + game Game; + + if ( !Game.Init() ) + { + return 0; + } + + + Game.ChangeState ( MenuState::Instance() ); + + while ( Game.Running() ) + { + Game.SetStart ( SDL_GetTicks() ); + + Game.HandleEvents(); + Game.Update(); + Game.Draw(); + + Game.ReduceFPS(); + } + + Game.Clean(); + + return 0; +} diff --git a/src/map.cpp b/src/map.cpp new file mode 100644 index 0000000..fb6693a --- /dev/null +++ b/src/map.cpp @@ -0,0 +1,140 @@ +#include "map.hpp" + + +map::map() +{ + reset(); +} + +void map::reset() +{ + for (int y = 0; y < HEIGHT; y++) + { + for (int x = 0; x < WIDTH; x++) + { + data[y][x] = 0; + } + } +} + +bool map::isCollision(part Part, bool strict) +{ + for (int y = 0; y < 4; y++) + { + for (int x = 0; x < 4; x++) + { + if (strict) + { + if ( (Part.getPosY() + y >= 0) && + ( ( data[Part.getPosY() + y][Part.getPosX() + x] && Part.getElement(x, y) ) || + ( Part.getElement(x, y) && Part.getPosX() + x >= WIDTH)) ) + { + return true; + } + } + else + { + if ( (Part.getPosY() + y >= 0) && + ( ( data[Part.getPosY() + y + 1][Part.getPosX() + x] && Part.getElement(x, y) ) || + ( Part.getElement(x, y) && Part.getPosY() + y >= HEIGHT - 1)) ) + { + return true; + } + } + } + } + + return false; +} + +void map::addPart(part Part) +{ + for (int y = 0; y < 4; y++) + { + for (int x = 0; x < 4; x++) + { + if (Part.getElement(x, y)) + data[Part.getPosY() + y][Part.getPosX() + x] = Part.getColor() + 1; + } + } +} + +void map::applyGravity(int h) +{ + int tmp = 0; + + for (int y = h; y > -1; y--) + { + for (int x = 0; x < WIDTH; x++) + { + if (y < (HEIGHT - 1) && data[y + 1][x] == 0 && data[y][x]) + { + tmp = data[y + 1][x]; + data[y + 1][x] = data[y][x]; + data[y][x] = 0; + } + } + } +} + +int map::destroyLines() +{ + int pocet = 0; + + for (int y = 0; y < HEIGHT; y++) + { + bool good = true; + + for (int x = 0; x < WIDTH; x++) + { + if (!data[y][x]) + { + good = false; + + break; + } + } + + if (good) + { + for (int x = 0; x < WIDTH; x++) + { + data[y][x] = 0; + } + + applyGravity(y); + pocet++; + + y = 0; + } + } + + return pocet; +} + +bool map::isFull() +{ + for (int x = 0; x < WIDTH; x++) + { + if (data[0][x]) + { + return true; + } + } + + return false; +} + +void map::draw(SDL_Surface *screen) +{ + for(int i = 0; i < HEIGHT; i++) + { + for(int m = 0; m < WIDTH; m++) + { + if(data[i][m]) + { + drawQuad(screen, m * SIZE, i * SIZE, colors[data[i][m] - 1]); + } + } + } +} diff --git a/src/map.hpp b/src/map.hpp new file mode 100644 index 0000000..b9b2b34 --- /dev/null +++ b/src/map.hpp @@ -0,0 +1,29 @@ +#ifndef MAP_HPP_INCLUDED +#define MAP_HPP_INCLUDED + +#include +#include + +#include "resource.hpp" +#include "part.hpp" +#include "global.hpp" + + +class map +{ + private: + int data[HEIGHT][WIDTH]; + + public: + map(); + + void reset(); + bool isCollision ( part Part, bool strict = false ); + void addPart ( part Part ); + void applyGravity ( int h ); + int destroyLines(); + bool isFull(); + void draw ( SDL_Surface * screen ); +}; + +#endif diff --git a/src/menu.cpp b/src/menu.cpp new file mode 100644 index 0000000..1e59fef --- /dev/null +++ b/src/menu.cpp @@ -0,0 +1,68 @@ +#include "menu.hpp" + + +Menu::Menu() +{ + select = 0; + + # ifdef DEBUG + cout << "First item selected" << endl; + # endif +} + +Menu::~Menu() +{ + +} + +void Menu::addItem(const char* nazov, void (* action)(game*)) +{ + MenuItem item = MenuItem(nazov, action); + + polozky.push_back(item); + + # ifdef DEBUG + cout << "Item was added" << endl; + # endif +} + +void Menu::Execute(game* Game) +{ + polozky[select].Execute(Game); +} + +void Menu::Draw(game* Game) +{ + int i = 0; + + for (vector::iterator it = polozky.begin(); it != polozky.end(); it++) + { + it->draw(Game, 100, (i * 50 + 50), (i == select)); + + i++; + } +} + +void Menu::Down(game* Game) +{ + if (polozky.size() > (select + 1)) + { + select++; + + # ifdef DEBUG + cout << "Next item" << endl; + # endif + } +} + +void Menu::Up(game* Game) +{ + if (select > 0) + { + # ifdef DEBUG + cout << "Previous item" << endl; + # endif + + select--; + } +} diff --git a/src/menu.hpp b/src/menu.hpp new file mode 100644 index 0000000..182445d --- /dev/null +++ b/src/menu.hpp @@ -0,0 +1,34 @@ +#ifndef MENU_HPP_INCLUDED +#define MENU_HPP_INCLUDED + + +#include +#include + +#include "game.hpp" +#include "menuitem.hpp" + + +using namespace std; + + +class Menu +{ + public: + Menu(); + ~Menu(); + + void addItem ( const char * nazov, void ( * action ) ( game * ) ); + void Execute ( game * Game ); + void Draw ( game * Game ); + + void Down ( game * Game ); + void Up ( game * Game ); + + private: + vector polozky; + int select; +}; + + +#endif diff --git a/src/menuitem.cpp b/src/menuitem.cpp new file mode 100644 index 0000000..4c0a82e --- /dev/null +++ b/src/menuitem.cpp @@ -0,0 +1,39 @@ +#include "menuitem.hpp" + + +MenuItem::MenuItem(const char* nazov, void (* action)(game*)) +{ + this->nazov = nazov; + this->action = action; +} + +void MenuItem::Execute(game* Game) +{ + # ifdef DEBUG + cout << "Executing..." << endl; + # endif + + action(Game); +} + +void MenuItem::draw(game* Game, int x, int y, bool active) +{ + SDL_Color textColor; + + if (active) + { + textColor = make_color(123, 123, 255); + } + else + { + textColor = make_color(255, 255, 255); + } + + message = TTF_RenderText_Solid( Game->GetfontMenu(), nazov, textColor); + + apply_surface(x, y, message, Game->GetScreen()); + + + SDL_FreeSurface(message); +} + diff --git a/src/menuitem.hpp b/src/menuitem.hpp new file mode 100644 index 0000000..a703514 --- /dev/null +++ b/src/menuitem.hpp @@ -0,0 +1,34 @@ +#ifndef MENUITEM_HPP_INCLUDED +#define MENUITEM_HPP_INCLUDED + + +#include +#include +#include + +#include "global.hpp" +#include "game.hpp" + + +using namespace std; + + +class MenuItem +{ + public: + MenuItem ( const char * nazov, void ( * action ) ( game * ) ); + + void Execute ( game * Game ); + void draw ( game * Game, int x, int y, bool active = false ); + + private: + void ( * action ) ( game * ); + + const char * nazov; + SDL_Surface * message; + + SDL_Color text_color; +}; + + +#endif diff --git a/src/menustate.cpp b/src/menustate.cpp new file mode 100644 index 0000000..6000851 --- /dev/null +++ b/src/menustate.cpp @@ -0,0 +1,127 @@ +#include "states.hpp" + + +MenuState MenuState::m_MenuState; + +void MenuState::Init() +{ + menu = new Menu(); + + menu->addItem("Play", play); + menu->addItem("High Score", score); + + # ifdef DEBUG + menu->addItem("Debug Info", Debug_Info); + # endif + + menu->addItem("Exit", quit); + + # ifdef DEBUG + std::cout << "MenuState Init Successful" << std::endl; + # endif +} + +void MenuState::Clean() +{ + delete menu; + + # ifdef DEBUG + std::cout << "MenuState Clean Successful" << std::endl; + # endif +} + +void MenuState::Pause() +{ + # ifdef DEBUG + std::cout << "MenuState Paused" << std::endl; + # endif +} + +void MenuState::Resume() +{ + # ifdef DEBUG + std::cout << "MenuState Resumed" << std::endl; + # endif +} + +void MenuState::HandleEvents(game* Game) +{ + SDL_Event event; + + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + Game->Quit(); + break; + + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_ESCAPE: + { + Game->Quit(); + } + break; + + case SDLK_DOWN: + menu->Down(Game); + break; + + case SDLK_UP: + menu->Up(Game); + break; + + case SDLK_SPACE: + menu->Execute(Game); + break; + + case SDLK_RETURN: + menu->Execute(Game); + break; + } + break; + } + } +} + +void MenuState::Update(game* Game) +{ + SDL_FillRect(Game->GetScreen(), NULL, 0x000000); +} + +// We have to change the way we get the screen in this function +void MenuState::Draw(game* Game) +{ + menu->Draw(Game); + + SDL_Flip(Game->GetScreen()); +} + + +void MenuState::play(game* Game) +{ + Game->ChangeState(PlayState::Instance()); +} + +void MenuState::score(game* Game) +{ + Game->PushState(ScoreState::Instance()); +} + +void MenuState::quit(game* Game) +{ + Game->Quit(); +} + +# ifdef DEBUG + void MenuState::Debug_Info(game* Game) + { + std::cout << "\n\n=== DEBUG INFO ===\n" << std::endl; + + std::cout << "Number of States: " << Game->CountStates() << std::endl; + + std::cout << "\n=== Debug Info ===\n\n" << endl; + } +# endif diff --git a/src/menustate.hpp b/src/menustate.hpp new file mode 100644 index 0000000..a8d32df --- /dev/null +++ b/src/menustate.hpp @@ -0,0 +1,52 @@ +#ifndef MENU_STATE_HPP_INCLUDED +#define MENU_STATE_HPP_INCLUDED + + +#include +#include + +#include "game.hpp" +#include "gamestate.hpp" +#include "menuitem.hpp" +#include "menu.hpp" + + +class MenuState : public GameState +{ + public: + void Init(); + void Clean(); + + void Pause(); + void Resume(); + + void HandleEvents ( game * Game ); + void Update ( game * Game ); + void Draw ( game * Game ); + + // Implement Singleton Pattern + static MenuState * Instance() + { + return &m_MenuState; + } + + + static void play ( game * Game ); + static void score ( game * Game ); + static void quit ( game * Game ); + + # ifdef DEBUG + static void Debug_Info ( game * Game ); + # endif + + protected: + MenuState() {} + + private: + static MenuState m_MenuState; + + Menu * menu; +}; + + +#endif diff --git a/src/part.cpp b/src/part.cpp new file mode 100644 index 0000000..de5adf3 --- /dev/null +++ b/src/part.cpp @@ -0,0 +1,132 @@ +#include "part.hpp" + + +part::part() +{ + posX = WIDTH / 2 - 1; + posY = -4; + + generate(); +} + +void part::fillData() +{ + for (int i = 0; i < 4; i++) + { + for (int j = 0; j < 4; j++) + { + data[i][j] = Shapes[shapeIndex][i][j]; + } + } +} + +void part::generate() +{ + int g; + + g = (rand() % 7) * 4; + + shapeIndex = (ShapeIndexes)g; + color = g / 4; + + fillData(); +} + +void part::move(int x, int y) +{ + if (isValid(x, y)) + { + posX += x; + posY += y; + } +} + +void part::rotate() +{ + int coIndex; + + coIndex = shapeIndex; + + shapeIndex = ((shapeIndex + 1) % 4 == 0 ? shapeIndex - 3 : shapeIndex + 1); + + fillData(); + + if (!isValid()) + { + shapeIndex = coIndex; + + fillData(); + } +} + +bool part::isValid(int xOffset, int yOffset) +{ + for (int y = 0; y < 4; y++) + { + for (int x = 0; x < 4; x++) + { + if ( (data[y][x] && (posX + x + xOffset >= WIDTH || posX + xOffset < 0)) || (data[y][x] && (posY + y + yOffset > HEIGHT)) ) + { + # ifdef DEBUG + cout << "InValid" << endl; + # endif + + return false; + } + } + } + + # ifdef DEBUG + cout << "Valid" << endl; + # endif + + return true; +} + +void part::draw(SDL_Surface *screen) +{ + for (int i = 0; i < 4 ;i++) + { + for (int m = 0; m < 4; m++) + { + if (data[i][m]) + { + drawQuad(screen, (m + posX) * SIZE, (i + posY) * SIZE, colors[color]); + } + } + } +} + +void part::draw ( int startX, int startY, SDL_Surface * screen ) +{ + for (int i = 0; i < 4 ;i++) + { + for (int m = 0; m < 4; m++) + { + if (data[i][m]) + { + drawQuad(screen, (m + posX) * SIZE + startX, (i + posY) * SIZE + startY, colors[color]); + } + } + } +} + +int part::getPosX() +{ + return posX; +} + +int part::getPosY() +{ + return posY; +} + +int part::getElement(int x, int y) +{ + return data[y][x]; +} + +int part::getColor() +{ + return color; +} diff --git a/src/part.hpp b/src/part.hpp new file mode 100644 index 0000000..f22dd20 --- /dev/null +++ b/src/part.hpp @@ -0,0 +1,45 @@ +#ifndef PART_HPP_INCLUDED +#define PART_HPP_INCLUDED + +#include +#include + +#include "resource.hpp" +#include "global.hpp" + + +using namespace std; + + +class part +{ + private: + int shapeIndex; + int posX; + int posY; + + void fillData(); + + + protected: + int data[4][4]; + int color; + + + public: + part(); + + void generate(); + void move ( int x, int y ); + void rotate(); + bool isValid ( int xOffset = 0, int yOffset = 0 ); + void draw ( SDL_Surface * screen ); + void draw ( int startX, int startY, SDL_Surface * screen ); + + int getPosX(); + int getPosY(); + int getElement ( int x, int y ); + int getColor(); +}; + +#endif diff --git a/src/pausestate.cpp b/src/pausestate.cpp new file mode 100644 index 0000000..989a1c0 --- /dev/null +++ b/src/pausestate.cpp @@ -0,0 +1,110 @@ +#include "states.hpp" + + +PauseState PauseState::m_PauseState; + +void PauseState::Init() +{ + menu = new Menu(); + + menu->addItem("Resume", resume); + menu->addItem("To menu", go_to_menu); + menu->addItem("Exit", quit); + + # ifdef DEBUG + std::cout << "PauseState Init Successful" << std::endl; + # endif +} + +void PauseState::Clean() +{ + delete menu; + + # ifdef DEBUG + std::cout << "PauseState Clean Successful" << std::endl; + # endif +} + +void PauseState::Pause() +{ + # ifdef DEBUG + std::cout << "PauseState Paused" << std::endl; + # endif +} + +void PauseState::Resume() +{ + # ifdef DEBUG + std::cout << "PauseState Resumed" << std::endl; + # endif +} + +void PauseState::HandleEvents(game* Game) +{ + SDL_Event event; + + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + Game->Quit(); + break; + + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_ESCAPE: + Game->PopState(); + break; + + case SDLK_DOWN: + menu->Down(Game); + break; + + case SDLK_UP: + menu->Up(Game); + break; + + case SDLK_SPACE: + menu->Execute(Game); + break; + + case SDLK_RETURN: + menu->Execute(Game); + break; + } + break; + } + } +} + +void PauseState::Update(game* Game) +{ + SDL_FillRect(Game->GetScreen(), NULL, 0x000000); +} + +// We have to change the way we get the screen in this function +void PauseState::Draw(game* Game) +{ + menu->Draw(Game); + + SDL_Flip(Game->GetScreen()); +} + + +void PauseState::resume(game* Game) +{ + Game->PopState(); +} + +void PauseState::go_to_menu(game* Game) +{ + Game->DelStateF(); + Game->ChangeState(MenuState::Instance()); +} + +void PauseState::quit(game* Game) +{ + Game->Quit(); +} diff --git a/src/pausestate.hpp b/src/pausestate.hpp new file mode 100644 index 0000000..d4baa03 --- /dev/null +++ b/src/pausestate.hpp @@ -0,0 +1,48 @@ +#ifndef PAUSE_STATE_HPP_INCLUDED +#define PAUSE_STATE_HPP_INCLUDED + + +#include +#include + +#include "game.hpp" +#include "gamestate.hpp" +#include "menuitem.hpp" +#include "menu.hpp" + + +class PauseState : public GameState +{ + public: + void Init(); + void Clean(); + + void Pause(); + void Resume(); + + void HandleEvents ( game * Game ); + void Update ( game * Game ); + void Draw ( game * Game ); + + // Implement Singleton Pattern + static PauseState * Instance() + { + return &m_PauseState; + } + + + static void resume ( game * Game ); + static void go_to_menu ( game * Game ); + static void quit ( game * Game ); + + protected: + PauseState() {} + + private: + static PauseState m_PauseState; + + Menu * menu; +}; + + +#endif diff --git a/src/playstate.cpp b/src/playstate.cpp new file mode 100644 index 0000000..8617532 --- /dev/null +++ b/src/playstate.cpp @@ -0,0 +1,373 @@ +# include "game.hpp" +# include "states.hpp" + + +PlayState PlayState::m_PlayState; + + +void PlayState::Init() +{ + Map = map(); + Part = part(); + Next = part(); + + level = 0; + lines = 0; + score = 0; + + tick = 1; + + nameEntered = false; + nameEntering = false; + message = NULL; + + textColor = make_color(255, 255, 255); + + SDL_EnableKeyRepeat ( REPAET_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); + + # ifdef DEBUG + std::cout << "PlayState Init Successful" << std::endl; + # endif +} + +void PlayState::Clean() +{ + SDL_EnableKeyRepeat ( 0, 0 ); + + # ifdef DEBUG + std::cout << "PlayState Clean Successful" << std::endl; + # endif +} + +void PlayState::Pause() +{ + SDL_EnableKeyRepeat ( 0, 0 ); + + # ifdef DEBUG + std::cout << "PlayState Paused" << std::endl; + # endif +} + +void PlayState::Resume() +{ + SDL_EnableKeyRepeat ( REPAET_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); + + # ifdef DEBUG + std::cout << "PlayState Resumed" << std::endl; + # endif +} + +void PlayState::HandleEvents ( game* Game ) +{ + SDL_Event event; + + while ( SDL_PollEvent ( &event ) ) + { + if ( event.type == SDL_QUIT) + Game->Quit(); + + /* Game Over - Write name for score */ + if( nameEntering == true && nameEntered == false ) + { + //Get user input + name.handle_input(Game, &event); + + //If the enter key was pressed + if( ( event.type == SDL_KEYDOWN ) && ( event.key.keysym.sym == SDLK_RETURN ) ) + { + //Change the flag + nameEntered = true; + nameEntering = false; + + Save(name.GetStr(), lines); + + name.Clear(); + + //Free the old message surface + SDL_FreeSurface( message ); + + //Change the message + } + + name.show_centered(Game); + } + /* Game key logic... */ + else + { + switch ( event.type ) + { + /* key pressed.... */ + case SDL_KEYDOWN: + switch ( event.key.keysym.sym ) + { + /* ESCAPE - Pause game (run PauseState) */ + case SDLK_ESCAPE: + { + //Game->SetRunning(false); + Game->PushState ( PauseState::Instance() ); + } + break; + + /* move part to the right */ + case SDLK_RIGHT: + { + /* */ + part p = Part; + + # ifdef DEBUG + std::cout << "move to Right: "; + # endif + + Part.move ( 1, 0 ); + + if ( Map.isCollision ( Part, true ) ) + { + # ifdef DEBUG + std::cout << "Collision" << std::endl; + # endif + + Part = p; + } + } + break; + + case SDLK_LEFT: + { + part p = Part; + + # ifdef DEBUG + std::cout << "move to Left: "; + # endif + + Part.move ( -1, 0 ); + + if ( Map.isCollision ( Part, true ) ) + { + # ifdef DEBUG + std::cout << "Collision" << std::endl; + # endif + + Part = p; + } + } + break; + + case SDLK_DOWN: + # ifdef DEBUG + std::cout << "move to Down: "; + # endif + + if ( !Map.isCollision ( Part ) ) + { + Part.move ( 0, 1 ); + } + else + { + # ifdef DEBUG + std::cout << "Collision" << std::endl; + # endif + } + break; + + case SDLK_UP: + { + part p = Part; + + # ifdef DEBUG + std::cout << "Rotate: "; + # endif + + Part.rotate(); + + if ( Map.isCollision ( Part, true ) ) + { + # ifdef DEBUG + std::cout << "Map: Collission" << std::endl; + # endif + + Part = p; + } + } + break; + + case SDLK_SPACE: + # ifdef DEBUG + std::cout << "move to Bottom" << std::endl; + # endif + + while ( !Map.isCollision ( Part ) ) + { + Part.move ( 0, 1 ); + + tick = ( FPS / ( ( level > 30 ) ? 30 : level ) ) - 1; + } + break; + + case SDLK_RETURN: + { + # ifdef DEBUG + std::cout << "continue" << std::endl; + # endif + + //Game->m_bGameOver = false; + } + break; + } + break; + } + } + } +} + +void PlayState::Update ( game* Game ) +{ + /* kontrola či je plné hracie pole... */ + if ( Map.isFull() ) + { + /* Start enter name */ + nameEntering = true; + + if (nameEntered) + { + nameEntering = false; + nameEntered = false; + //text.setString("Score " + intToStr(Map.getScore()) + "\n" + "Press enter"); + Map.reset(); + + lines = 0; + level = 1; + } + } + + + if (!nameEntering) + { + if ( level == 0 ) + { + level = 1; + } + + if ( tick % ( FPS / ( ( level > 30 ) ? 30 : level ) ) == 0 && !Map.isCollision ( Part ) ) + { + # ifdef DEBUG + std::cout << "move to Down: "; + # endif + + Part.move ( 0, 1 ); + } + + /* + if ( tick % ( FPS / ( ( level > 30 ) ? 30 : level ) ) != 0 && Map.isCollision ( Part ) && tick != ( FPS / ( ( level > 30 ) ? 30 : level ) ) -1 ) + std::cout << "DEBUG" << std::endl; + */ + + if ( Map.isCollision ( Part ) && ( tick ) == ( FPS / ( ( level > 30 ) ? 30 : level ) ) -1 ) + { + int count; + + Map.addPart ( Part ); + + count = Map.destroyLines(); + + lines += count; + // level = (lines >= 5) ? (lines / 10) : 0; + level = lines / 10 + 1; + + # ifdef DEBUG + std::cout << "Lines: " << lines << std::endl; + std::cout << "Level: " << level << std::endl; + # endif + + Part = Next; + Next = part(); + } + + + if ( tick < FPS ) + { + tick++; + } + else + { + tick = 1; + } + } +} + + +void PlayState::Draw ( game* Game ) +{ + if (!nameEntering) + { + SDL_FillRect ( Game->GetScreen(), NULL, 0x000000 ); + + SDL_Rect rect = {WIDTH * SIZE, 0, 130, HEIGHT * SIZE}; + + SDL_FillRect ( Game->GetScreen(), &rect, 0x111111 ); + + Map.draw ( Game->GetScreen() ); + Part.draw ( Game->GetScreen() ); + Next.draw ( 165, 100, Game->GetScreen() ); + + PlayInfo(this, Game); + } + else + { + SDL_FillRect ( Game->GetScreen(), NULL, 0x000000 ); + + message = TTF_RenderText_Solid( Game->GetfontGame(), "Enter Name: ", textColor ); + apply_surface(10, 40, message, Game->GetScreen()); + + name.show_centered(Game); + } + + SDL_Flip ( Game->GetScreen() ); +} + + +void PlayState::Save ( string Name, int Lines ) +{ + ofstream file; + + file.open(".score", ios_base::app); + + if (file.is_open()) + { + file << Name << " " << Lines << endl; + + file.close(); + } + else + { + cerr << "Cannot open file '.score'" << endl; + } +} + + +void PlayInfo ( PlayState * Info, game * Game ) +{ + SDL_Color textColor; + SDL_Surface * message; + char temp[10]; + + textColor = make_color(255, 255, 255); + + + message = TTF_RenderText_Solid( Game->GetfontGame(), "Lines", textColor); + apply_surface(220, 150, message, Game->GetScreen()); + + std::sprintf ( temp, "%d", Info->lines); + message = TTF_RenderText_Solid( Game->GetfontGame(), temp, textColor); + apply_surface(220, 185, message, Game->GetScreen()); + + + message = TTF_RenderText_Solid( Game->GetfontGame(), "Level", textColor); + apply_surface(220, 230, message, Game->GetScreen()); + + std::sprintf ( temp, "%d", Info->level); + message = TTF_RenderText_Solid( Game->GetfontGame(), temp, textColor); + apply_surface(220, 265, message, Game->GetScreen()); + + + SDL_FreeSurface(message); +} diff --git a/src/playstate.hpp b/src/playstate.hpp new file mode 100644 index 0000000..f13616d --- /dev/null +++ b/src/playstate.hpp @@ -0,0 +1,68 @@ +# ifndef PLAY_STATE_HPP_INCLUDED +# define PLAY_STATE_HPP_INCLUDED + +# include +# include +# include +# include + +# include "game.hpp" +# include "gamestate.hpp" +# include "resource.hpp" +# include "part.hpp" +# include "map.hpp" +# include "stringinput.hpp" + + +class PlayState : public GameState +{ + public: + void Init(); + void Clean(); + + void Pause(); + void Resume(); + + void HandleEvents ( game * Game ); + void Update ( game * Game ); + void Draw ( game * Game ); + + // Implement Singleton Pattern + static PlayState * Instance() + { + return &m_PlayState; + } + + friend void PlayInfo ( PlayState * Info, game * Game ); + + protected: + PlayState() {} + + private: + void Save(string Name, int Lines); + + static PlayState m_PlayState; + + map Map; + part Part; + part Next; + + int score; + int level; + int lines; + + int tick; + + bool nameEntered; + bool nameEntering; + + SDL_Surface * message; + SDL_Color textColor; + + StringInput name; +}; + + +void PlayInfo ( PlayState * Info, game * Game ); + +# endif diff --git a/src/resource.cpp b/src/resource.cpp new file mode 100644 index 0000000..d66a55e --- /dev/null +++ b/src/resource.cpp @@ -0,0 +1,21 @@ +#include "resource.hpp" + + +int colors[7] = +{ + 0xFF0000, + 0x00FF00, + 0x0000FF, + 0xFF00FF, + 0x00FFFF, + 0xFFFF00, + 0xFF8000 +}; + +int points[4] = +{ + 40, + 100, + 300, + 1200 +}; diff --git a/src/resource.hpp b/src/resource.hpp new file mode 100644 index 0000000..41186a8 --- /dev/null +++ b/src/resource.hpp @@ -0,0 +1,203 @@ +# ifndef RESOURCE_HPP_INCLUDED +# define RESOURCE_HPP_INCLUDED + + +# define WIDTH 10 +# define HEIGHT 20 +# define SIZE 20 +# define FPS 60 + +# define REPAET_DELAY 170 + +extern int colors[7]; +extern int points[4]; + +enum ShapeIndexes { I = 0, O = 4, S = 8, Z = 12, T = 16, L = 20, J = 24 }; + +/* Šablóny hracích "kociak" */ +const bool Shapes[][4][4] = +{ + /* I */ + { + {1, 0, 0, 0}, + {1, 0, 0, 0}, + {1, 0, 0, 0}, + {1, 0, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 1, 1} + }, + { + {1, 0, 0, 0}, + {1, 0, 0, 0}, + {1, 0, 0, 0}, + {1, 0, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 1, 1} + }, + + /* O - kocka */ + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 0, 0}, + {1, 1, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 0, 0}, + {1, 1, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 0, 0}, + {1, 1, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 0, 0}, + {1, 1, 0, 0} + }, + + /* S */ + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 1, 1, 0}, + {1, 1, 0, 0} + }, + { + {0, 0, 0, 0}, + {1, 0, 0, 0}, + {1, 1, 0, 0}, + {0, 1, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 1, 1, 0}, + {1, 1, 0, 0} + }, + { + {0, 0, 0, 0}, + {1, 0, 0, 0}, + {1, 1, 0, 0}, + {0, 1, 0, 0} + }, + + /* Z */ + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 0, 0}, + {0, 1, 1, 0} + }, + { + {0, 0, 0, 0}, + {0, 1, 0, 0}, + {1, 1, 0, 0}, + {1, 0, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 0, 0}, + {0, 1, 1, 0} + }, + { + {0, 0, 0, 0}, + {0, 1, 0, 0}, + {1, 1, 0, 0}, + {1, 0, 0, 0} + }, + + /* T */ + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 1, 0, 0}, + {1, 1, 1, 0} + }, + { + {0, 0, 0, 0}, + {1, 0, 0, 0}, + {1, 1, 0, 0}, + {1, 0, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 1, 0}, + {0, 1, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 1, 0, 0}, + {1, 1, 0, 0}, + {0, 1, 0, 0} + }, + + /* L */ + { + {0, 0, 0, 0}, + {1, 0, 0, 0}, + {1, 0, 0, 0}, + {1, 1, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 1, 0}, + {1, 0, 0, 0} + }, + { + {0, 0, 0, 0}, + {1, 1, 0, 0}, + {0, 1, 0, 0}, + {0, 1, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {0, 0, 1, 0}, + {1, 1, 1, 0} + }, + + /* J */ + { + {0, 0, 0, 0}, + {0, 1, 0, 0}, + {0, 1, 0, 0}, + {1, 1, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 0, 0, 0}, + {1, 1, 1, 0} + }, + { + {0, 0, 0, 0}, + {1, 1, 0, 0}, + {1, 0, 0, 0}, + {1, 0, 0, 0} + }, + { + {0, 0, 0, 0}, + {0, 0, 0, 0}, + {1, 1, 1, 0}, + {0, 0, 1, 0} + }, +}; + +#endif diff --git a/src/scoreitem.cpp b/src/scoreitem.cpp new file mode 100644 index 0000000..cb719fc --- /dev/null +++ b/src/scoreitem.cpp @@ -0,0 +1,35 @@ +#include "scoreitem.hpp" + +ScoreItem::ScoreItem ( string Name, int Lines ) +{ + this->Name = Name; + this->Lines = Lines; + + message = NULL; + + textColor = make_color(255, 255, 255); +} + +ScoreItem::~ScoreItem() +{ + +} + +void ScoreItem::Draw ( game * Game, int y ) +{ + char temp[10]; + + message = TTF_RenderText_Solid( Game->GetfontMenu(), Name.c_str(), textColor); + apply_surface(105, y, message, Game->GetScreen()); + + std::sprintf ( temp, "%d", Lines); + message = TTF_RenderText_Solid( Game->GetfontMenu(), temp, textColor); + apply_surface(15, y, message, Game->GetScreen()); + + SDL_FreeSurface(message); +} + +int ScoreItem::GetLines() +{ + return Lines; +} diff --git a/src/scoreitem.hpp b/src/scoreitem.hpp new file mode 100644 index 0000000..62d136f --- /dev/null +++ b/src/scoreitem.hpp @@ -0,0 +1,32 @@ +#ifndef SCOREITEM_H +#define SCOREITEM_H + +# include +# include +# include + +# include "game.hpp" +# include "global.hpp" + +using namespace std; + + +class ScoreItem +{ + public: + ScoreItem ( string Name, int Lines ); + ~ScoreItem(); + + int GetLines(); + + void Draw( game * Game, int y ); + + private: + string Name; + int Lines; + + SDL_Surface * message; + SDL_Color textColor; +}; + +#endif // SCOREITEM_H diff --git a/src/scorestate.cpp b/src/scorestate.cpp new file mode 100644 index 0000000..1204343 --- /dev/null +++ b/src/scorestate.cpp @@ -0,0 +1,108 @@ +#include "scorestate.hpp" + + +bool operator< (ScoreItem First, ScoreItem Second ) +{ + return (First.GetLines() > Second.GetLines()); +} + + +ScoreState ScoreState::m_ScoreState; + +void ScoreState::Draw ( game * Game ) +{ + for (int i = 0; i < (Items.size() > 10 ? 10 : (int) Items.size()); i++) + { + Items[i].Draw(Game, i * 35); + } + + SDL_Flip(Game->GetScreen()); +} + +void ScoreState::Update ( game * Game ) +{ + SDL_FillRect(Game->GetScreen(), NULL, 0x000000); +} + +void ScoreState::HandleEvents ( game * Game ) +{ + SDL_Event event; + + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + Game->Quit(); + break; + + case SDL_KEYDOWN: + switch (event.key.keysym.sym) + { + case SDLK_ESCAPE: + Game->PopState(); + break; + } + break; + } + } +} + +void ScoreState::Resume() +{ + # ifdef DEBUG + std::cout << "ScoreState Resumed" << std::endl; + # endif +} + +void ScoreState::Pause() +{ + # ifdef DEBUG + std::cout << "ScoreState Paused" << std::endl; + # endif +} + +void ScoreState::Clean() +{ + Items.clear(); + + # ifdef DEBUG + std::cout << "ScoreState Clean Successful" << std::endl; + # endif +} + +void ScoreState::Init() +{ + Load(); + + sort(Items.begin(), Items.end()); + + # ifdef DEBUG + std::cout << "ScoreState Init Successful" << std::endl; + # endif +} + +void ScoreState::Load() +{ + ifstream file; + string Name; + int Lines; + + file.open(".score"); + + if (file.is_open()) + { + while (!file.eof()) + { + file >> Name; + file >> Lines; + + if (!file.eof()) + Items.push_back(ScoreItem(Name, Lines)); + } + + file.close(); + } + else + cerr << "Cannot open file '.score'" << endl; +} diff --git a/src/scorestate.hpp b/src/scorestate.hpp new file mode 100644 index 0000000..98bed17 --- /dev/null +++ b/src/scorestate.hpp @@ -0,0 +1,46 @@ +#ifndef SCORESTATE_H +#define SCORESTATE_H + +# include +# include +# include +# include + +# include "gamestate.hpp" +# include "scoreitem.hpp" + +using namespace std; + + +class ScoreState : public GameState +{ + public: + void Init(); + void Clean(); + + void Pause(); + void Resume(); + + void HandleEvents ( game * Game ); + void Update ( game * Game ); + void Draw ( game * Game ); + + // Implement Singleton Pattern + static ScoreState * Instance() + { + return &m_ScoreState; + } + + + protected: + ScoreState() {} + + private: + void Load(); + + static ScoreState m_ScoreState; + + vector Items; +}; + +#endif // SCORESTATE_H diff --git a/src/states.hpp b/src/states.hpp new file mode 100644 index 0000000..b2201ba --- /dev/null +++ b/src/states.hpp @@ -0,0 +1,4 @@ +# include "playstate.hpp" +# include "menustate.hpp" +# include "pausestate.hpp" +# include "scorestate.hpp" diff --git a/src/stringinput.cpp b/src/stringinput.cpp new file mode 100644 index 0000000..dd1db89 --- /dev/null +++ b/src/stringinput.cpp @@ -0,0 +1,99 @@ +#include "stringinput.hpp" + +StringInput::StringInput() +{ + str = ""; + text = NULL; + textColor = make_color ( 255, 255, 255 ); +} + +StringInput::~StringInput() +{ + SDL_FreeSurface ( text ); +} + + +void StringInput::handle_input ( game * Game, SDL_Event *event) +{ + //If a key was pressed + if ( event->type == SDL_KEYDOWN ) + { + //Keep a copy of the current version of the string + string temp = str; + + //If the string less than maximum size + if ( str.length() <= 11 ) + { + //If the key is a number + if ( ( event->key.keysym.unicode >= ( Uint16 ) '0' ) && ( event->key.keysym.unicode <= ( Uint16 ) '9' ) ) + { + //Append the character + str += ( char ) event->key.keysym.unicode; + } + else if ( ( event->key.keysym.unicode == ( Uint16 ) '-' ) ) + { + //Append the character + str += ( char ) event->key.keysym.unicode; + } + //If the key is a uppercase letter + else if ( ( event->key.keysym.unicode >= ( Uint16 ) 'A' ) && ( event->key.keysym.unicode <= ( Uint16 ) 'Z' ) ) + { + //Append the character + str += ( char ) event->key.keysym.unicode; + } + //If the key is a lowercase letter + else if ( ( event->key.keysym.unicode >= ( Uint16 ) 'a' ) && ( event->key.keysym.unicode <= ( Uint16 ) 'z' ) ) + { + //Append the character + str += ( char ) event->key.keysym.unicode; + } + } + + #ifdef DEBUG + cout << str << endl; + #endif + + //If backspace was pressed and the string isn't blank + if ( ( event->key.keysym.sym == SDLK_BACKSPACE ) && ( str.length() != 0 ) ) + { + //Remove a character from the end + str.erase ( str.length() - 1 ); + } + + //If the string was changed + if ( str != temp ) + { + //Free the old surface + SDL_FreeSurface ( text ); + + //Render a new text surface + text = TTF_RenderText_Solid ( Game->GetfontGame(), str.c_str(), textColor ); + } + } + +} + +void StringInput::show_centered ( game * Game ) +{ + //If the surface isn't blank + if ( text != NULL ) + { + //Show the name + apply_surface ( 50, 85, text, Game->GetScreen() ); + } +} + + +string StringInput::GetStr() +{ + return str; +} + + +void StringInput::Clear() +{ + str = ""; + + SDL_FreeSurface ( text ); + text = NULL; +} diff --git a/src/stringinput.hpp b/src/stringinput.hpp new file mode 100644 index 0000000..f02d0d9 --- /dev/null +++ b/src/stringinput.hpp @@ -0,0 +1,35 @@ +#ifndef STRINGINPUT_H +#define STRINGINPUT_H + +# include +# include +# include +# include + +# include "game.hpp" +# include "global.hpp" + +using namespace std; + + +class StringInput +{ + public: + StringInput(); + ~StringInput(); + + string GetStr(); + + void handle_input( game * Game, SDL_Event * event ); + void show_centered( game * Game ); + + void Clear(); + + private: + string str; + + SDL_Surface *text; + SDL_Color textColor; +}; + +#endif // STRINGINPUT_H From 0792d5582312cbf61b0a886cce702f01c5409cf5 Mon Sep 17 00:00:00 2001 From: SGOrava Date: Mon, 6 Apr 2015 16:23:50 +0200 Subject: [PATCH 3/7] =?UTF-8?q?Zmena=20strukt=C3=BAry=20priecinkov...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + CMakeLists.txt | 25 ++++--------------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 6d65327..7cc9bfb 100644 --- a/.gitignore +++ b/.gitignore @@ -43,5 +43,6 @@ install_manifest.txt # unsuported build windows* +build/src build/tetris .kdev4* diff --git a/CMakeLists.txt b/CMakeLists.txt index b45e7bd..b4b94df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,10 @@ cmake_minimum_required(VERSION 2.8) -project(tetris) +set(EXE_NAME tetris) -add_executable( - tetris - scoreitem.cpp - scorestate.cpp - stringinput.cpp - part.cpp - main.cpp - global.cpp - map.cpp - resource.cpp - game.cpp - pausestate.cpp - playstate.cpp - menustate.cpp - menuitem.cpp - menu.cpp -) +project(${EXE_NAME}) + +add_subdirectory(src) -target_link_libraries(tetris SDL SDL_ttf) -set(CMAKE_CXX_FLAGS "-Wextra -ftabstop=4 -march=native -std=gnu++11 -fshow-column -ftabstop=4 -frounding-math -pipe") -install(TARGETS tetris RUNTIME DESTINATION bin) From a873e63cff7e792ebbfcdcea7a5127a0836f8b15 Mon Sep 17 00:00:00 2001 From: SGOrava Date: Mon, 6 Apr 2015 16:25:37 +0200 Subject: [PATCH 4/7] =?UTF-8?q?=C3=9Aprva=20prie=C4=8Dinkov?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENCE | 23 --- game.cpp | 228 ----------------------- game.hpp | 73 -------- gamestate.hpp | 32 ---- global.cpp | 29 --- global.hpp | 19 -- main.cpp | 44 ----- map.cpp | 140 -------------- map.hpp | 29 --- menu.cpp | 68 ------- menu.hpp | 34 ---- menuitem.cpp | 39 ---- menuitem.hpp | 34 ---- menustate.cpp | 127 ------------- menustate.hpp | 52 ------ part.cpp | 132 ------------- part.hpp | 45 ----- pausestate.cpp | 110 ----------- pausestate.hpp | 48 ----- playstate.cpp | 373 ------------------------------------- playstate.hpp | 68 ------- resource.cpp | 21 --- resource.hpp | 203 -------------------- scoreitem.cpp | 35 ---- scoreitem.hpp | 32 ---- scorestate.cpp | 108 ----------- scorestate.hpp | 46 ----- README.md => src/README.md | 0 states.hpp | 4 - stringinput.cpp | 99 ---------- stringinput.hpp | 35 ---- 31 files changed, 2330 deletions(-) delete mode 100644 LICENCE delete mode 100644 game.cpp delete mode 100644 game.hpp delete mode 100644 gamestate.hpp delete mode 100644 global.cpp delete mode 100644 global.hpp delete mode 100644 main.cpp delete mode 100644 map.cpp delete mode 100644 map.hpp delete mode 100644 menu.cpp delete mode 100644 menu.hpp delete mode 100644 menuitem.cpp delete mode 100644 menuitem.hpp delete mode 100644 menustate.cpp delete mode 100644 menustate.hpp delete mode 100644 part.cpp delete mode 100644 part.hpp delete mode 100644 pausestate.cpp delete mode 100644 pausestate.hpp delete mode 100644 playstate.cpp delete mode 100644 playstate.hpp delete mode 100644 resource.cpp delete mode 100644 resource.hpp delete mode 100644 scoreitem.cpp delete mode 100644 scoreitem.hpp delete mode 100644 scorestate.cpp delete mode 100644 scorestate.hpp rename README.md => src/README.md (100%) delete mode 100644 states.hpp delete mode 100644 stringinput.cpp delete mode 100644 stringinput.hpp diff --git a/LICENCE b/LICENCE deleted file mode 100644 index 4e45844..0000000 --- a/LICENCE +++ /dev/null @@ -1,23 +0,0 @@ -Copyright (c) 2014, [SG]Orava -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/game.cpp b/game.cpp deleted file mode 100644 index 8fcf29d..0000000 --- a/game.cpp +++ /dev/null @@ -1,228 +0,0 @@ -#include "game.hpp" -#include "gamestate.hpp" - - -game::game() -{ } - -game::~game() -{ } - - - -bool game::Init() -{ - if ( SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO ) == -1 ) - { - cerr << "[ERROR] Cannot init SDL" << endl; - - m_bRunning = false; - - return false; - } - - SDL_EnableUNICODE ( SDL_ENABLE ); - - - SDL_WM_SetCaption ( "[SG]Tetris", NULL ); - - m_pScreen = SDL_SetVideoMode ( WIDTH * SIZE + 130, HEIGHT * SIZE, 32, SDL_HWSURFACE | SDL_DOUBLEBUF ); - - if ( m_pScreen == NULL ) - { - cerr << "[ERROR] Cannot setup screen" << endl; - - m_bRunning = false; - - return false; - } - - - if ( TTF_Init() ) - { - cerr << "[ERROR] Cannot init SDL_ttf" << endl; - - m_bRunning = false; - - return false; - } - - - m_bRunning = Load(); - m_bGameOver = false; - tick = 0; - - return m_bRunning; -} - -bool game::Load() -{ - fontMenu = TTF_OpenFont ( "data-latin.ttf", 38 ); - - if ( fontMenu == NULL ) - { - cerr << "[ERROR] Cannot load font 'data-latin.ttf'" << endl; - - return false; - } - - - fontGame = TTF_OpenFont ( "handelgotd.ttf", 30 ); - - if ( fontGame == NULL ) - { - cerr << "[ERROR] Cannot load font 'handelgotd.ttf'" << endl; - - return false; - } - - - return true; -} - -void game::ChangeState ( GameState * state ) -{ - // cleanup the current state - if ( !states.empty() ) - { - states.back()->Clean(); - states.pop_back(); - } - - // store and init the new state - states.push_back ( state ); - states.back()->Init(); -} - -void game::PushState ( GameState * state ) -{ - // pause current state - if ( !states.empty() ) - { - states.back()->Pause(); - } - - // store and init the new state - states.push_back ( state ); - states.back()->Init(); -} - -void game::PopState() -{ - // cleanup the current state - if ( !states.empty() ) - { - states.back()->Clean(); - states.pop_back(); - } - - // resume previous state - if ( !states.empty() ) - { - states.back()->Resume(); - } -} - -void game::DelStateF() -{ - // cleanup the first state - if ( !states.empty() ) - { - states.front()->Clean(); - states.erase(states.begin()); - } -} - -# ifdef DEBUG - int game::CountStates() - { - return states.size(); - } -# endif - -void game::HandleEvents() -{ - states.back()->HandleEvents ( this ); -} - -void game::Update() -{ - states.back()->Update ( this ); -} - -void game::Draw() -{ - states.back()->Draw ( this ); -} - - -SDL_Surface * game::GetScreen() -{ - return m_pScreen; -} - -bool game::Running() -{ - return m_bRunning; -} - -void game::Clean() -{ - # ifdef DEBUG - cout << "Cleanning..." << endl; - # endif - - TTF_CloseFont ( fontMenu ); - - TTF_Quit(); - SDL_Quit(); -} - -void game::Quit() -{ - m_bRunning = false; - - # ifdef DEBUG - cout << "Shutting down..." << endl; - # endif -} - -void game::ReduceFPS() -{ - if ( 1000 / FPS > ( SDL_GetTicks() - start ) ) - { - SDL_Delay ( 1000 / FPS - ( SDL_GetTicks() - start ) ); - } -} - -void game::UpdateFPS() -{ - if ( tick <= FPS ) - { - tick += 1; - } - else - { - tick = 1; - } -} - -Uint32 game::GetStart() -{ - return start; -} - -void game::SetStart ( Uint32 start ) -{ - this->start = start; -} - -TTF_Font * game::GetfontGame() -{ - return fontGame; -} - -TTF_Font * game::GetfontMenu() -{ - return fontMenu; -} diff --git a/game.hpp b/game.hpp deleted file mode 100644 index 105b1ca..0000000 --- a/game.hpp +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef GAME_HPP_INCLUDED -#define GAME_HPP_INCLUDED - -#include -#include -#include -#include - -#include "map.hpp" -#include "part.hpp" - - -using namespace std; - - -class GameState; - -class game -{ - public: - game(); - ~game(); - - bool Init(); - bool Load(); - - void ChangeState ( GameState * state ); - void PushState ( GameState * state ); - void PopState(); - void DelStateF(); - - # ifdef DEBUG - int CountStates(); - # endif - - - void HandleEvents(); - void Update(); - void Draw(); - - SDL_Surface * GetScreen(); - Uint32 GetStart(); - - TTF_Font * GetfontMenu(); - TTF_Font * GetfontGame(); - - void SetStart ( Uint32 start ); - void SetRunning ( bool m_bRunning ); - - void Clean(); - - bool Running(); - void Quit(); - - void ReduceFPS(); - void UpdateFPS(); - - private: - SDL_Surface * m_pScreen; - vector states; - - bool m_bRunning; - bool m_bGameOver; - - TTF_Font * fontMenu; - TTF_Font * fontGame; - - Uint32 start; - int tick; -}; - - -#endif diff --git a/gamestate.hpp b/gamestate.hpp deleted file mode 100644 index ef2e653..0000000 --- a/gamestate.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef GAME_STATE_HPP_INCLUDED -#define GAME_STATE_HPP_INCLUDED - -#include "game.hpp" - - -class GameState -{ - public: - virtual void Init() = 0; - virtual void Clean() = 0; - - virtual void Pause() = 0; - virtual void Resume() = 0; - - virtual void HandleEvents ( game * Game ) = 0; - virtual void Update ( game * Game ) = 0; - virtual void Draw ( game * Game ) = 0; - - void ChangeState ( game * Game, GameState * state ) - { - Game->ChangeState ( state ); - } - - protected: - GameState() { } - - bool FirstRun; -}; - - -#endif diff --git a/global.cpp b/global.cpp deleted file mode 100644 index be01a1c..0000000 --- a/global.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "global.hpp" - - -void drawQuad ( SDL_Surface * screen, short int x, short int y, int color ) -{ - SDL_Rect rect = {x, y, SIZE, SIZE}; - - SDL_FillRect ( screen, &rect, color ); -} - -void apply_surface ( int x, int y, SDL_Surface * source, SDL_Surface * destination, SDL_Rect * clip ) -{ - //Holds offsets - SDL_Rect offset; - - //Get offsets - offset.x = x; - offset.y = y; - - //Blit - SDL_BlitSurface ( source, clip, destination, &offset ); -} - -SDL_Color make_color ( Uint8 r, Uint8 g, Uint8 b ) -{ - SDL_Color color = {r, g, b}; - - return color; -} diff --git a/global.hpp b/global.hpp deleted file mode 100644 index f94e847..0000000 --- a/global.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef GLOBAL_HPP_INCLUDED -#define GLOBAL_HPP_INCLUDED - -#include -#include -#include -#include - -#include "resource.hpp" - - - - -void drawQuad ( SDL_Surface* screen, short int x, short int y, int color ); -void apply_surface ( int x, int y, SDL_Surface * source, SDL_Surface * destination, SDL_Rect * clip = NULL ); -SDL_Color make_color ( Uint8 r, Uint8 g, Uint8 b ); - - -#endif diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 6d9bcb3..0000000 --- a/main.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include -#include -#include -#include - -#include "resource.hpp" -#include "global.hpp" -#include "game.hpp" - -#include "states.hpp" - - -using namespace std; - - -int main ( int argc, char ** argv ) -{ - srand ( time ( NULL ) ); - - game Game; - - if ( !Game.Init() ) - { - return 0; - } - - - Game.ChangeState ( MenuState::Instance() ); - - while ( Game.Running() ) - { - Game.SetStart ( SDL_GetTicks() ); - - Game.HandleEvents(); - Game.Update(); - Game.Draw(); - - Game.ReduceFPS(); - } - - Game.Clean(); - - return 0; -} diff --git a/map.cpp b/map.cpp deleted file mode 100644 index fb6693a..0000000 --- a/map.cpp +++ /dev/null @@ -1,140 +0,0 @@ -#include "map.hpp" - - -map::map() -{ - reset(); -} - -void map::reset() -{ - for (int y = 0; y < HEIGHT; y++) - { - for (int x = 0; x < WIDTH; x++) - { - data[y][x] = 0; - } - } -} - -bool map::isCollision(part Part, bool strict) -{ - for (int y = 0; y < 4; y++) - { - for (int x = 0; x < 4; x++) - { - if (strict) - { - if ( (Part.getPosY() + y >= 0) && - ( ( data[Part.getPosY() + y][Part.getPosX() + x] && Part.getElement(x, y) ) || - ( Part.getElement(x, y) && Part.getPosX() + x >= WIDTH)) ) - { - return true; - } - } - else - { - if ( (Part.getPosY() + y >= 0) && - ( ( data[Part.getPosY() + y + 1][Part.getPosX() + x] && Part.getElement(x, y) ) || - ( Part.getElement(x, y) && Part.getPosY() + y >= HEIGHT - 1)) ) - { - return true; - } - } - } - } - - return false; -} - -void map::addPart(part Part) -{ - for (int y = 0; y < 4; y++) - { - for (int x = 0; x < 4; x++) - { - if (Part.getElement(x, y)) - data[Part.getPosY() + y][Part.getPosX() + x] = Part.getColor() + 1; - } - } -} - -void map::applyGravity(int h) -{ - int tmp = 0; - - for (int y = h; y > -1; y--) - { - for (int x = 0; x < WIDTH; x++) - { - if (y < (HEIGHT - 1) && data[y + 1][x] == 0 && data[y][x]) - { - tmp = data[y + 1][x]; - data[y + 1][x] = data[y][x]; - data[y][x] = 0; - } - } - } -} - -int map::destroyLines() -{ - int pocet = 0; - - for (int y = 0; y < HEIGHT; y++) - { - bool good = true; - - for (int x = 0; x < WIDTH; x++) - { - if (!data[y][x]) - { - good = false; - - break; - } - } - - if (good) - { - for (int x = 0; x < WIDTH; x++) - { - data[y][x] = 0; - } - - applyGravity(y); - pocet++; - - y = 0; - } - } - - return pocet; -} - -bool map::isFull() -{ - for (int x = 0; x < WIDTH; x++) - { - if (data[0][x]) - { - return true; - } - } - - return false; -} - -void map::draw(SDL_Surface *screen) -{ - for(int i = 0; i < HEIGHT; i++) - { - for(int m = 0; m < WIDTH; m++) - { - if(data[i][m]) - { - drawQuad(screen, m * SIZE, i * SIZE, colors[data[i][m] - 1]); - } - } - } -} diff --git a/map.hpp b/map.hpp deleted file mode 100644 index b9b2b34..0000000 --- a/map.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MAP_HPP_INCLUDED -#define MAP_HPP_INCLUDED - -#include -#include - -#include "resource.hpp" -#include "part.hpp" -#include "global.hpp" - - -class map -{ - private: - int data[HEIGHT][WIDTH]; - - public: - map(); - - void reset(); - bool isCollision ( part Part, bool strict = false ); - void addPart ( part Part ); - void applyGravity ( int h ); - int destroyLines(); - bool isFull(); - void draw ( SDL_Surface * screen ); -}; - -#endif diff --git a/menu.cpp b/menu.cpp deleted file mode 100644 index 1e59fef..0000000 --- a/menu.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "menu.hpp" - - -Menu::Menu() -{ - select = 0; - - # ifdef DEBUG - cout << "First item selected" << endl; - # endif -} - -Menu::~Menu() -{ - -} - -void Menu::addItem(const char* nazov, void (* action)(game*)) -{ - MenuItem item = MenuItem(nazov, action); - - polozky.push_back(item); - - # ifdef DEBUG - cout << "Item was added" << endl; - # endif -} - -void Menu::Execute(game* Game) -{ - polozky[select].Execute(Game); -} - -void Menu::Draw(game* Game) -{ - int i = 0; - - for (vector::iterator it = polozky.begin(); it != polozky.end(); it++) - { - it->draw(Game, 100, (i * 50 + 50), (i == select)); - - i++; - } -} - -void Menu::Down(game* Game) -{ - if (polozky.size() > (select + 1)) - { - select++; - - # ifdef DEBUG - cout << "Next item" << endl; - # endif - } -} - -void Menu::Up(game* Game) -{ - if (select > 0) - { - # ifdef DEBUG - cout << "Previous item" << endl; - # endif - - select--; - } -} diff --git a/menu.hpp b/menu.hpp deleted file mode 100644 index 182445d..0000000 --- a/menu.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef MENU_HPP_INCLUDED -#define MENU_HPP_INCLUDED - - -#include -#include - -#include "game.hpp" -#include "menuitem.hpp" - - -using namespace std; - - -class Menu -{ - public: - Menu(); - ~Menu(); - - void addItem ( const char * nazov, void ( * action ) ( game * ) ); - void Execute ( game * Game ); - void Draw ( game * Game ); - - void Down ( game * Game ); - void Up ( game * Game ); - - private: - vector polozky; - int select; -}; - - -#endif diff --git a/menuitem.cpp b/menuitem.cpp deleted file mode 100644 index 4c0a82e..0000000 --- a/menuitem.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "menuitem.hpp" - - -MenuItem::MenuItem(const char* nazov, void (* action)(game*)) -{ - this->nazov = nazov; - this->action = action; -} - -void MenuItem::Execute(game* Game) -{ - # ifdef DEBUG - cout << "Executing..." << endl; - # endif - - action(Game); -} - -void MenuItem::draw(game* Game, int x, int y, bool active) -{ - SDL_Color textColor; - - if (active) - { - textColor = make_color(123, 123, 255); - } - else - { - textColor = make_color(255, 255, 255); - } - - message = TTF_RenderText_Solid( Game->GetfontMenu(), nazov, textColor); - - apply_surface(x, y, message, Game->GetScreen()); - - - SDL_FreeSurface(message); -} - diff --git a/menuitem.hpp b/menuitem.hpp deleted file mode 100644 index a703514..0000000 --- a/menuitem.hpp +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef MENUITEM_HPP_INCLUDED -#define MENUITEM_HPP_INCLUDED - - -#include -#include -#include - -#include "global.hpp" -#include "game.hpp" - - -using namespace std; - - -class MenuItem -{ - public: - MenuItem ( const char * nazov, void ( * action ) ( game * ) ); - - void Execute ( game * Game ); - void draw ( game * Game, int x, int y, bool active = false ); - - private: - void ( * action ) ( game * ); - - const char * nazov; - SDL_Surface * message; - - SDL_Color text_color; -}; - - -#endif diff --git a/menustate.cpp b/menustate.cpp deleted file mode 100644 index 6000851..0000000 --- a/menustate.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include "states.hpp" - - -MenuState MenuState::m_MenuState; - -void MenuState::Init() -{ - menu = new Menu(); - - menu->addItem("Play", play); - menu->addItem("High Score", score); - - # ifdef DEBUG - menu->addItem("Debug Info", Debug_Info); - # endif - - menu->addItem("Exit", quit); - - # ifdef DEBUG - std::cout << "MenuState Init Successful" << std::endl; - # endif -} - -void MenuState::Clean() -{ - delete menu; - - # ifdef DEBUG - std::cout << "MenuState Clean Successful" << std::endl; - # endif -} - -void MenuState::Pause() -{ - # ifdef DEBUG - std::cout << "MenuState Paused" << std::endl; - # endif -} - -void MenuState::Resume() -{ - # ifdef DEBUG - std::cout << "MenuState Resumed" << std::endl; - # endif -} - -void MenuState::HandleEvents(game* Game) -{ - SDL_Event event; - - while (SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_QUIT: - Game->Quit(); - break; - - case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - { - Game->Quit(); - } - break; - - case SDLK_DOWN: - menu->Down(Game); - break; - - case SDLK_UP: - menu->Up(Game); - break; - - case SDLK_SPACE: - menu->Execute(Game); - break; - - case SDLK_RETURN: - menu->Execute(Game); - break; - } - break; - } - } -} - -void MenuState::Update(game* Game) -{ - SDL_FillRect(Game->GetScreen(), NULL, 0x000000); -} - -// We have to change the way we get the screen in this function -void MenuState::Draw(game* Game) -{ - menu->Draw(Game); - - SDL_Flip(Game->GetScreen()); -} - - -void MenuState::play(game* Game) -{ - Game->ChangeState(PlayState::Instance()); -} - -void MenuState::score(game* Game) -{ - Game->PushState(ScoreState::Instance()); -} - -void MenuState::quit(game* Game) -{ - Game->Quit(); -} - -# ifdef DEBUG - void MenuState::Debug_Info(game* Game) - { - std::cout << "\n\n=== DEBUG INFO ===\n" << std::endl; - - std::cout << "Number of States: " << Game->CountStates() << std::endl; - - std::cout << "\n=== Debug Info ===\n\n" << endl; - } -# endif diff --git a/menustate.hpp b/menustate.hpp deleted file mode 100644 index a8d32df..0000000 --- a/menustate.hpp +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef MENU_STATE_HPP_INCLUDED -#define MENU_STATE_HPP_INCLUDED - - -#include -#include - -#include "game.hpp" -#include "gamestate.hpp" -#include "menuitem.hpp" -#include "menu.hpp" - - -class MenuState : public GameState -{ - public: - void Init(); - void Clean(); - - void Pause(); - void Resume(); - - void HandleEvents ( game * Game ); - void Update ( game * Game ); - void Draw ( game * Game ); - - // Implement Singleton Pattern - static MenuState * Instance() - { - return &m_MenuState; - } - - - static void play ( game * Game ); - static void score ( game * Game ); - static void quit ( game * Game ); - - # ifdef DEBUG - static void Debug_Info ( game * Game ); - # endif - - protected: - MenuState() {} - - private: - static MenuState m_MenuState; - - Menu * menu; -}; - - -#endif diff --git a/part.cpp b/part.cpp deleted file mode 100644 index de5adf3..0000000 --- a/part.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "part.hpp" - - -part::part() -{ - posX = WIDTH / 2 - 1; - posY = -4; - - generate(); -} - -void part::fillData() -{ - for (int i = 0; i < 4; i++) - { - for (int j = 0; j < 4; j++) - { - data[i][j] = Shapes[shapeIndex][i][j]; - } - } -} - -void part::generate() -{ - int g; - - g = (rand() % 7) * 4; - - shapeIndex = (ShapeIndexes)g; - color = g / 4; - - fillData(); -} - -void part::move(int x, int y) -{ - if (isValid(x, y)) - { - posX += x; - posY += y; - } -} - -void part::rotate() -{ - int coIndex; - - coIndex = shapeIndex; - - shapeIndex = ((shapeIndex + 1) % 4 == 0 ? shapeIndex - 3 : shapeIndex + 1); - - fillData(); - - if (!isValid()) - { - shapeIndex = coIndex; - - fillData(); - } -} - -bool part::isValid(int xOffset, int yOffset) -{ - for (int y = 0; y < 4; y++) - { - for (int x = 0; x < 4; x++) - { - if ( (data[y][x] && (posX + x + xOffset >= WIDTH || posX + xOffset < 0)) || (data[y][x] && (posY + y + yOffset > HEIGHT)) ) - { - # ifdef DEBUG - cout << "InValid" << endl; - # endif - - return false; - } - } - } - - # ifdef DEBUG - cout << "Valid" << endl; - # endif - - return true; -} - -void part::draw(SDL_Surface *screen) -{ - for (int i = 0; i < 4 ;i++) - { - for (int m = 0; m < 4; m++) - { - if (data[i][m]) - { - drawQuad(screen, (m + posX) * SIZE, (i + posY) * SIZE, colors[color]); - } - } - } -} - -void part::draw ( int startX, int startY, SDL_Surface * screen ) -{ - for (int i = 0; i < 4 ;i++) - { - for (int m = 0; m < 4; m++) - { - if (data[i][m]) - { - drawQuad(screen, (m + posX) * SIZE + startX, (i + posY) * SIZE + startY, colors[color]); - } - } - } -} - -int part::getPosX() -{ - return posX; -} - -int part::getPosY() -{ - return posY; -} - -int part::getElement(int x, int y) -{ - return data[y][x]; -} - -int part::getColor() -{ - return color; -} diff --git a/part.hpp b/part.hpp deleted file mode 100644 index f22dd20..0000000 --- a/part.hpp +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef PART_HPP_INCLUDED -#define PART_HPP_INCLUDED - -#include -#include - -#include "resource.hpp" -#include "global.hpp" - - -using namespace std; - - -class part -{ - private: - int shapeIndex; - int posX; - int posY; - - void fillData(); - - - protected: - int data[4][4]; - int color; - - - public: - part(); - - void generate(); - void move ( int x, int y ); - void rotate(); - bool isValid ( int xOffset = 0, int yOffset = 0 ); - void draw ( SDL_Surface * screen ); - void draw ( int startX, int startY, SDL_Surface * screen ); - - int getPosX(); - int getPosY(); - int getElement ( int x, int y ); - int getColor(); -}; - -#endif diff --git a/pausestate.cpp b/pausestate.cpp deleted file mode 100644 index 989a1c0..0000000 --- a/pausestate.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include "states.hpp" - - -PauseState PauseState::m_PauseState; - -void PauseState::Init() -{ - menu = new Menu(); - - menu->addItem("Resume", resume); - menu->addItem("To menu", go_to_menu); - menu->addItem("Exit", quit); - - # ifdef DEBUG - std::cout << "PauseState Init Successful" << std::endl; - # endif -} - -void PauseState::Clean() -{ - delete menu; - - # ifdef DEBUG - std::cout << "PauseState Clean Successful" << std::endl; - # endif -} - -void PauseState::Pause() -{ - # ifdef DEBUG - std::cout << "PauseState Paused" << std::endl; - # endif -} - -void PauseState::Resume() -{ - # ifdef DEBUG - std::cout << "PauseState Resumed" << std::endl; - # endif -} - -void PauseState::HandleEvents(game* Game) -{ - SDL_Event event; - - while (SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_QUIT: - Game->Quit(); - break; - - case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - Game->PopState(); - break; - - case SDLK_DOWN: - menu->Down(Game); - break; - - case SDLK_UP: - menu->Up(Game); - break; - - case SDLK_SPACE: - menu->Execute(Game); - break; - - case SDLK_RETURN: - menu->Execute(Game); - break; - } - break; - } - } -} - -void PauseState::Update(game* Game) -{ - SDL_FillRect(Game->GetScreen(), NULL, 0x000000); -} - -// We have to change the way we get the screen in this function -void PauseState::Draw(game* Game) -{ - menu->Draw(Game); - - SDL_Flip(Game->GetScreen()); -} - - -void PauseState::resume(game* Game) -{ - Game->PopState(); -} - -void PauseState::go_to_menu(game* Game) -{ - Game->DelStateF(); - Game->ChangeState(MenuState::Instance()); -} - -void PauseState::quit(game* Game) -{ - Game->Quit(); -} diff --git a/pausestate.hpp b/pausestate.hpp deleted file mode 100644 index d4baa03..0000000 --- a/pausestate.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef PAUSE_STATE_HPP_INCLUDED -#define PAUSE_STATE_HPP_INCLUDED - - -#include -#include - -#include "game.hpp" -#include "gamestate.hpp" -#include "menuitem.hpp" -#include "menu.hpp" - - -class PauseState : public GameState -{ - public: - void Init(); - void Clean(); - - void Pause(); - void Resume(); - - void HandleEvents ( game * Game ); - void Update ( game * Game ); - void Draw ( game * Game ); - - // Implement Singleton Pattern - static PauseState * Instance() - { - return &m_PauseState; - } - - - static void resume ( game * Game ); - static void go_to_menu ( game * Game ); - static void quit ( game * Game ); - - protected: - PauseState() {} - - private: - static PauseState m_PauseState; - - Menu * menu; -}; - - -#endif diff --git a/playstate.cpp b/playstate.cpp deleted file mode 100644 index 8617532..0000000 --- a/playstate.cpp +++ /dev/null @@ -1,373 +0,0 @@ -# include "game.hpp" -# include "states.hpp" - - -PlayState PlayState::m_PlayState; - - -void PlayState::Init() -{ - Map = map(); - Part = part(); - Next = part(); - - level = 0; - lines = 0; - score = 0; - - tick = 1; - - nameEntered = false; - nameEntering = false; - message = NULL; - - textColor = make_color(255, 255, 255); - - SDL_EnableKeyRepeat ( REPAET_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); - - # ifdef DEBUG - std::cout << "PlayState Init Successful" << std::endl; - # endif -} - -void PlayState::Clean() -{ - SDL_EnableKeyRepeat ( 0, 0 ); - - # ifdef DEBUG - std::cout << "PlayState Clean Successful" << std::endl; - # endif -} - -void PlayState::Pause() -{ - SDL_EnableKeyRepeat ( 0, 0 ); - - # ifdef DEBUG - std::cout << "PlayState Paused" << std::endl; - # endif -} - -void PlayState::Resume() -{ - SDL_EnableKeyRepeat ( REPAET_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); - - # ifdef DEBUG - std::cout << "PlayState Resumed" << std::endl; - # endif -} - -void PlayState::HandleEvents ( game* Game ) -{ - SDL_Event event; - - while ( SDL_PollEvent ( &event ) ) - { - if ( event.type == SDL_QUIT) - Game->Quit(); - - /* Game Over - Write name for score */ - if( nameEntering == true && nameEntered == false ) - { - //Get user input - name.handle_input(Game, &event); - - //If the enter key was pressed - if( ( event.type == SDL_KEYDOWN ) && ( event.key.keysym.sym == SDLK_RETURN ) ) - { - //Change the flag - nameEntered = true; - nameEntering = false; - - Save(name.GetStr(), lines); - - name.Clear(); - - //Free the old message surface - SDL_FreeSurface( message ); - - //Change the message - } - - name.show_centered(Game); - } - /* Game key logic... */ - else - { - switch ( event.type ) - { - /* key pressed.... */ - case SDL_KEYDOWN: - switch ( event.key.keysym.sym ) - { - /* ESCAPE - Pause game (run PauseState) */ - case SDLK_ESCAPE: - { - //Game->SetRunning(false); - Game->PushState ( PauseState::Instance() ); - } - break; - - /* move part to the right */ - case SDLK_RIGHT: - { - /* */ - part p = Part; - - # ifdef DEBUG - std::cout << "move to Right: "; - # endif - - Part.move ( 1, 0 ); - - if ( Map.isCollision ( Part, true ) ) - { - # ifdef DEBUG - std::cout << "Collision" << std::endl; - # endif - - Part = p; - } - } - break; - - case SDLK_LEFT: - { - part p = Part; - - # ifdef DEBUG - std::cout << "move to Left: "; - # endif - - Part.move ( -1, 0 ); - - if ( Map.isCollision ( Part, true ) ) - { - # ifdef DEBUG - std::cout << "Collision" << std::endl; - # endif - - Part = p; - } - } - break; - - case SDLK_DOWN: - # ifdef DEBUG - std::cout << "move to Down: "; - # endif - - if ( !Map.isCollision ( Part ) ) - { - Part.move ( 0, 1 ); - } - else - { - # ifdef DEBUG - std::cout << "Collision" << std::endl; - # endif - } - break; - - case SDLK_UP: - { - part p = Part; - - # ifdef DEBUG - std::cout << "Rotate: "; - # endif - - Part.rotate(); - - if ( Map.isCollision ( Part, true ) ) - { - # ifdef DEBUG - std::cout << "Map: Collission" << std::endl; - # endif - - Part = p; - } - } - break; - - case SDLK_SPACE: - # ifdef DEBUG - std::cout << "move to Bottom" << std::endl; - # endif - - while ( !Map.isCollision ( Part ) ) - { - Part.move ( 0, 1 ); - - tick = ( FPS / ( ( level > 30 ) ? 30 : level ) ) - 1; - } - break; - - case SDLK_RETURN: - { - # ifdef DEBUG - std::cout << "continue" << std::endl; - # endif - - //Game->m_bGameOver = false; - } - break; - } - break; - } - } - } -} - -void PlayState::Update ( game* Game ) -{ - /* kontrola či je plné hracie pole... */ - if ( Map.isFull() ) - { - /* Start enter name */ - nameEntering = true; - - if (nameEntered) - { - nameEntering = false; - nameEntered = false; - //text.setString("Score " + intToStr(Map.getScore()) + "\n" + "Press enter"); - Map.reset(); - - lines = 0; - level = 1; - } - } - - - if (!nameEntering) - { - if ( level == 0 ) - { - level = 1; - } - - if ( tick % ( FPS / ( ( level > 30 ) ? 30 : level ) ) == 0 && !Map.isCollision ( Part ) ) - { - # ifdef DEBUG - std::cout << "move to Down: "; - # endif - - Part.move ( 0, 1 ); - } - - /* - if ( tick % ( FPS / ( ( level > 30 ) ? 30 : level ) ) != 0 && Map.isCollision ( Part ) && tick != ( FPS / ( ( level > 30 ) ? 30 : level ) ) -1 ) - std::cout << "DEBUG" << std::endl; - */ - - if ( Map.isCollision ( Part ) && ( tick ) == ( FPS / ( ( level > 30 ) ? 30 : level ) ) -1 ) - { - int count; - - Map.addPart ( Part ); - - count = Map.destroyLines(); - - lines += count; - // level = (lines >= 5) ? (lines / 10) : 0; - level = lines / 10 + 1; - - # ifdef DEBUG - std::cout << "Lines: " << lines << std::endl; - std::cout << "Level: " << level << std::endl; - # endif - - Part = Next; - Next = part(); - } - - - if ( tick < FPS ) - { - tick++; - } - else - { - tick = 1; - } - } -} - - -void PlayState::Draw ( game* Game ) -{ - if (!nameEntering) - { - SDL_FillRect ( Game->GetScreen(), NULL, 0x000000 ); - - SDL_Rect rect = {WIDTH * SIZE, 0, 130, HEIGHT * SIZE}; - - SDL_FillRect ( Game->GetScreen(), &rect, 0x111111 ); - - Map.draw ( Game->GetScreen() ); - Part.draw ( Game->GetScreen() ); - Next.draw ( 165, 100, Game->GetScreen() ); - - PlayInfo(this, Game); - } - else - { - SDL_FillRect ( Game->GetScreen(), NULL, 0x000000 ); - - message = TTF_RenderText_Solid( Game->GetfontGame(), "Enter Name: ", textColor ); - apply_surface(10, 40, message, Game->GetScreen()); - - name.show_centered(Game); - } - - SDL_Flip ( Game->GetScreen() ); -} - - -void PlayState::Save ( string Name, int Lines ) -{ - ofstream file; - - file.open(".score", ios_base::app); - - if (file.is_open()) - { - file << Name << " " << Lines << endl; - - file.close(); - } - else - { - cerr << "Cannot open file '.score'" << endl; - } -} - - -void PlayInfo ( PlayState * Info, game * Game ) -{ - SDL_Color textColor; - SDL_Surface * message; - char temp[10]; - - textColor = make_color(255, 255, 255); - - - message = TTF_RenderText_Solid( Game->GetfontGame(), "Lines", textColor); - apply_surface(220, 150, message, Game->GetScreen()); - - std::sprintf ( temp, "%d", Info->lines); - message = TTF_RenderText_Solid( Game->GetfontGame(), temp, textColor); - apply_surface(220, 185, message, Game->GetScreen()); - - - message = TTF_RenderText_Solid( Game->GetfontGame(), "Level", textColor); - apply_surface(220, 230, message, Game->GetScreen()); - - std::sprintf ( temp, "%d", Info->level); - message = TTF_RenderText_Solid( Game->GetfontGame(), temp, textColor); - apply_surface(220, 265, message, Game->GetScreen()); - - - SDL_FreeSurface(message); -} diff --git a/playstate.hpp b/playstate.hpp deleted file mode 100644 index f13616d..0000000 --- a/playstate.hpp +++ /dev/null @@ -1,68 +0,0 @@ -# ifndef PLAY_STATE_HPP_INCLUDED -# define PLAY_STATE_HPP_INCLUDED - -# include -# include -# include -# include - -# include "game.hpp" -# include "gamestate.hpp" -# include "resource.hpp" -# include "part.hpp" -# include "map.hpp" -# include "stringinput.hpp" - - -class PlayState : public GameState -{ - public: - void Init(); - void Clean(); - - void Pause(); - void Resume(); - - void HandleEvents ( game * Game ); - void Update ( game * Game ); - void Draw ( game * Game ); - - // Implement Singleton Pattern - static PlayState * Instance() - { - return &m_PlayState; - } - - friend void PlayInfo ( PlayState * Info, game * Game ); - - protected: - PlayState() {} - - private: - void Save(string Name, int Lines); - - static PlayState m_PlayState; - - map Map; - part Part; - part Next; - - int score; - int level; - int lines; - - int tick; - - bool nameEntered; - bool nameEntering; - - SDL_Surface * message; - SDL_Color textColor; - - StringInput name; -}; - - -void PlayInfo ( PlayState * Info, game * Game ); - -# endif diff --git a/resource.cpp b/resource.cpp deleted file mode 100644 index d66a55e..0000000 --- a/resource.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "resource.hpp" - - -int colors[7] = -{ - 0xFF0000, - 0x00FF00, - 0x0000FF, - 0xFF00FF, - 0x00FFFF, - 0xFFFF00, - 0xFF8000 -}; - -int points[4] = -{ - 40, - 100, - 300, - 1200 -}; diff --git a/resource.hpp b/resource.hpp deleted file mode 100644 index 41186a8..0000000 --- a/resource.hpp +++ /dev/null @@ -1,203 +0,0 @@ -# ifndef RESOURCE_HPP_INCLUDED -# define RESOURCE_HPP_INCLUDED - - -# define WIDTH 10 -# define HEIGHT 20 -# define SIZE 20 -# define FPS 60 - -# define REPAET_DELAY 170 - -extern int colors[7]; -extern int points[4]; - -enum ShapeIndexes { I = 0, O = 4, S = 8, Z = 12, T = 16, L = 20, J = 24 }; - -/* Šablóny hracích "kociak" */ -const bool Shapes[][4][4] = -{ - /* I */ - { - {1, 0, 0, 0}, - {1, 0, 0, 0}, - {1, 0, 0, 0}, - {1, 0, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 1, 1, 1} - }, - { - {1, 0, 0, 0}, - {1, 0, 0, 0}, - {1, 0, 0, 0}, - {1, 0, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 1, 1, 1} - }, - - /* O - kocka */ - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 1, 0, 0}, - {1, 1, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 1, 0, 0}, - {1, 1, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 1, 0, 0}, - {1, 1, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 1, 0, 0}, - {1, 1, 0, 0} - }, - - /* S */ - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 1, 1, 0}, - {1, 1, 0, 0} - }, - { - {0, 0, 0, 0}, - {1, 0, 0, 0}, - {1, 1, 0, 0}, - {0, 1, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 1, 1, 0}, - {1, 1, 0, 0} - }, - { - {0, 0, 0, 0}, - {1, 0, 0, 0}, - {1, 1, 0, 0}, - {0, 1, 0, 0} - }, - - /* Z */ - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 1, 0, 0}, - {0, 1, 1, 0} - }, - { - {0, 0, 0, 0}, - {0, 1, 0, 0}, - {1, 1, 0, 0}, - {1, 0, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 1, 0, 0}, - {0, 1, 1, 0} - }, - { - {0, 0, 0, 0}, - {0, 1, 0, 0}, - {1, 1, 0, 0}, - {1, 0, 0, 0} - }, - - /* T */ - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 1, 0, 0}, - {1, 1, 1, 0} - }, - { - {0, 0, 0, 0}, - {1, 0, 0, 0}, - {1, 1, 0, 0}, - {1, 0, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 1, 1, 0}, - {0, 1, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 1, 0, 0}, - {1, 1, 0, 0}, - {0, 1, 0, 0} - }, - - /* L */ - { - {0, 0, 0, 0}, - {1, 0, 0, 0}, - {1, 0, 0, 0}, - {1, 1, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 1, 1, 0}, - {1, 0, 0, 0} - }, - { - {0, 0, 0, 0}, - {1, 1, 0, 0}, - {0, 1, 0, 0}, - {0, 1, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {0, 0, 1, 0}, - {1, 1, 1, 0} - }, - - /* J */ - { - {0, 0, 0, 0}, - {0, 1, 0, 0}, - {0, 1, 0, 0}, - {1, 1, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 0, 0, 0}, - {1, 1, 1, 0} - }, - { - {0, 0, 0, 0}, - {1, 1, 0, 0}, - {1, 0, 0, 0}, - {1, 0, 0, 0} - }, - { - {0, 0, 0, 0}, - {0, 0, 0, 0}, - {1, 1, 1, 0}, - {0, 0, 1, 0} - }, -}; - -#endif diff --git a/scoreitem.cpp b/scoreitem.cpp deleted file mode 100644 index cb719fc..0000000 --- a/scoreitem.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "scoreitem.hpp" - -ScoreItem::ScoreItem ( string Name, int Lines ) -{ - this->Name = Name; - this->Lines = Lines; - - message = NULL; - - textColor = make_color(255, 255, 255); -} - -ScoreItem::~ScoreItem() -{ - -} - -void ScoreItem::Draw ( game * Game, int y ) -{ - char temp[10]; - - message = TTF_RenderText_Solid( Game->GetfontMenu(), Name.c_str(), textColor); - apply_surface(105, y, message, Game->GetScreen()); - - std::sprintf ( temp, "%d", Lines); - message = TTF_RenderText_Solid( Game->GetfontMenu(), temp, textColor); - apply_surface(15, y, message, Game->GetScreen()); - - SDL_FreeSurface(message); -} - -int ScoreItem::GetLines() -{ - return Lines; -} diff --git a/scoreitem.hpp b/scoreitem.hpp deleted file mode 100644 index 62d136f..0000000 --- a/scoreitem.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef SCOREITEM_H -#define SCOREITEM_H - -# include -# include -# include - -# include "game.hpp" -# include "global.hpp" - -using namespace std; - - -class ScoreItem -{ - public: - ScoreItem ( string Name, int Lines ); - ~ScoreItem(); - - int GetLines(); - - void Draw( game * Game, int y ); - - private: - string Name; - int Lines; - - SDL_Surface * message; - SDL_Color textColor; -}; - -#endif // SCOREITEM_H diff --git a/scorestate.cpp b/scorestate.cpp deleted file mode 100644 index 1204343..0000000 --- a/scorestate.cpp +++ /dev/null @@ -1,108 +0,0 @@ -#include "scorestate.hpp" - - -bool operator< (ScoreItem First, ScoreItem Second ) -{ - return (First.GetLines() > Second.GetLines()); -} - - -ScoreState ScoreState::m_ScoreState; - -void ScoreState::Draw ( game * Game ) -{ - for (int i = 0; i < (Items.size() > 10 ? 10 : (int) Items.size()); i++) - { - Items[i].Draw(Game, i * 35); - } - - SDL_Flip(Game->GetScreen()); -} - -void ScoreState::Update ( game * Game ) -{ - SDL_FillRect(Game->GetScreen(), NULL, 0x000000); -} - -void ScoreState::HandleEvents ( game * Game ) -{ - SDL_Event event; - - while (SDL_PollEvent(&event)) - { - switch (event.type) - { - case SDL_QUIT: - Game->Quit(); - break; - - case SDL_KEYDOWN: - switch (event.key.keysym.sym) - { - case SDLK_ESCAPE: - Game->PopState(); - break; - } - break; - } - } -} - -void ScoreState::Resume() -{ - # ifdef DEBUG - std::cout << "ScoreState Resumed" << std::endl; - # endif -} - -void ScoreState::Pause() -{ - # ifdef DEBUG - std::cout << "ScoreState Paused" << std::endl; - # endif -} - -void ScoreState::Clean() -{ - Items.clear(); - - # ifdef DEBUG - std::cout << "ScoreState Clean Successful" << std::endl; - # endif -} - -void ScoreState::Init() -{ - Load(); - - sort(Items.begin(), Items.end()); - - # ifdef DEBUG - std::cout << "ScoreState Init Successful" << std::endl; - # endif -} - -void ScoreState::Load() -{ - ifstream file; - string Name; - int Lines; - - file.open(".score"); - - if (file.is_open()) - { - while (!file.eof()) - { - file >> Name; - file >> Lines; - - if (!file.eof()) - Items.push_back(ScoreItem(Name, Lines)); - } - - file.close(); - } - else - cerr << "Cannot open file '.score'" << endl; -} diff --git a/scorestate.hpp b/scorestate.hpp deleted file mode 100644 index 98bed17..0000000 --- a/scorestate.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef SCORESTATE_H -#define SCORESTATE_H - -# include -# include -# include -# include - -# include "gamestate.hpp" -# include "scoreitem.hpp" - -using namespace std; - - -class ScoreState : public GameState -{ - public: - void Init(); - void Clean(); - - void Pause(); - void Resume(); - - void HandleEvents ( game * Game ); - void Update ( game * Game ); - void Draw ( game * Game ); - - // Implement Singleton Pattern - static ScoreState * Instance() - { - return &m_ScoreState; - } - - - protected: - ScoreState() {} - - private: - void Load(); - - static ScoreState m_ScoreState; - - vector Items; -}; - -#endif // SCORESTATE_H diff --git a/README.md b/src/README.md similarity index 100% rename from README.md rename to src/README.md diff --git a/states.hpp b/states.hpp deleted file mode 100644 index b2201ba..0000000 --- a/states.hpp +++ /dev/null @@ -1,4 +0,0 @@ -# include "playstate.hpp" -# include "menustate.hpp" -# include "pausestate.hpp" -# include "scorestate.hpp" diff --git a/stringinput.cpp b/stringinput.cpp deleted file mode 100644 index dd1db89..0000000 --- a/stringinput.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "stringinput.hpp" - -StringInput::StringInput() -{ - str = ""; - text = NULL; - textColor = make_color ( 255, 255, 255 ); -} - -StringInput::~StringInput() -{ - SDL_FreeSurface ( text ); -} - - -void StringInput::handle_input ( game * Game, SDL_Event *event) -{ - //If a key was pressed - if ( event->type == SDL_KEYDOWN ) - { - //Keep a copy of the current version of the string - string temp = str; - - //If the string less than maximum size - if ( str.length() <= 11 ) - { - //If the key is a number - if ( ( event->key.keysym.unicode >= ( Uint16 ) '0' ) && ( event->key.keysym.unicode <= ( Uint16 ) '9' ) ) - { - //Append the character - str += ( char ) event->key.keysym.unicode; - } - else if ( ( event->key.keysym.unicode == ( Uint16 ) '-' ) ) - { - //Append the character - str += ( char ) event->key.keysym.unicode; - } - //If the key is a uppercase letter - else if ( ( event->key.keysym.unicode >= ( Uint16 ) 'A' ) && ( event->key.keysym.unicode <= ( Uint16 ) 'Z' ) ) - { - //Append the character - str += ( char ) event->key.keysym.unicode; - } - //If the key is a lowercase letter - else if ( ( event->key.keysym.unicode >= ( Uint16 ) 'a' ) && ( event->key.keysym.unicode <= ( Uint16 ) 'z' ) ) - { - //Append the character - str += ( char ) event->key.keysym.unicode; - } - } - - #ifdef DEBUG - cout << str << endl; - #endif - - //If backspace was pressed and the string isn't blank - if ( ( event->key.keysym.sym == SDLK_BACKSPACE ) && ( str.length() != 0 ) ) - { - //Remove a character from the end - str.erase ( str.length() - 1 ); - } - - //If the string was changed - if ( str != temp ) - { - //Free the old surface - SDL_FreeSurface ( text ); - - //Render a new text surface - text = TTF_RenderText_Solid ( Game->GetfontGame(), str.c_str(), textColor ); - } - } - -} - -void StringInput::show_centered ( game * Game ) -{ - //If the surface isn't blank - if ( text != NULL ) - { - //Show the name - apply_surface ( 50, 85, text, Game->GetScreen() ); - } -} - - -string StringInput::GetStr() -{ - return str; -} - - -void StringInput::Clear() -{ - str = ""; - - SDL_FreeSurface ( text ); - text = NULL; -} diff --git a/stringinput.hpp b/stringinput.hpp deleted file mode 100644 index f02d0d9..0000000 --- a/stringinput.hpp +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef STRINGINPUT_H -#define STRINGINPUT_H - -# include -# include -# include -# include - -# include "game.hpp" -# include "global.hpp" - -using namespace std; - - -class StringInput -{ - public: - StringInput(); - ~StringInput(); - - string GetStr(); - - void handle_input( game * Game, SDL_Event * event ); - void show_centered( game * Game ); - - void Clear(); - - private: - string str; - - SDL_Surface *text; - SDL_Color textColor; -}; - -#endif // STRINGINPUT_H From 3d1eb7b9b493a8703769cfe4ebd59a76b1c7a1d1 Mon Sep 17 00:00:00 2001 From: SGOrava Date: Mon, 6 Apr 2015 16:26:47 +0200 Subject: [PATCH 5/7] =?UTF-8?q?=C3=9Aprava=20prie=C4=8Dinkov?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/README.md => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/README.md => README.md (100%) diff --git a/src/README.md b/README.md similarity index 100% rename from src/README.md rename to README.md From 71f647043ad72377b53d0ddd809d598b43555b1d Mon Sep 17 00:00:00 2001 From: SGOrava Date: Mon, 6 Apr 2015 21:25:23 +0200 Subject: [PATCH 6/7] Replaced SDL 1.2 with SDL 2.0 --- CMakeLists.txt | 9 ++- README.md | 6 ++ cmake/FindSDL2.cmake | 171 +++++++++++++++++++++++++++++++++++++++ cmake/FindSDL2_ttf.cmake | 163 +++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 33 ++++---- src/game.cpp | 36 ++++++--- src/game.hpp | 9 ++- src/global.hpp | 4 +- src/main.cpp | 3 +- src/menuitem.hpp | 4 +- src/menustate.cpp | 3 +- src/menustate.hpp | 2 +- src/part.hpp | 2 +- src/pausestate.cpp | 3 +- src/pausestate.hpp | 2 +- src/playstate.cpp | 13 +-- src/playstate.hpp | 2 +- src/scoreitem.hpp | 4 +- src/scorestate.cpp | 3 +- src/states.hpp | 8 +- src/stringinput.cpp | 89 +++++++++++--------- src/stringinput.hpp | 4 +- 22 files changed, 475 insertions(+), 98 deletions(-) create mode 100644 cmake/FindSDL2.cmake create mode 100644 cmake/FindSDL2_ttf.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b4b94df..5861149 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,16 @@ cmake_minimum_required(VERSION 2.8) - set(EXE_NAME tetris) project(${EXE_NAME}) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + + +find_package(SDL2 REQUIRED) +find_package(SDL2_ttf REQUIRED) +include_directories(${SDL2_INCLUDE_DIR} ${SDL2TTF_INCLUDE_DIRS}) +set(TETRIS_LIBRARIES ${SDL2_LIBRARY} ${SDL2TTF_LIBRARY} ) + add_subdirectory(src) diff --git a/README.md b/README.md index e69de29..4c1428a 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,6 @@ +# Tetris +Basic tetris write in C++ and SDL + +## Changelog +* 4/6/2015 + * Replaced SDL with SDL2 \ No newline at end of file diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake new file mode 100644 index 0000000..071287b --- /dev/null +++ b/cmake/FindSDL2.cmake @@ -0,0 +1,171 @@ +# Locate SDL2 library +# This module defines +# SDL2_LIBRARY, the name of the library to link against +# SDL2_FOUND, if false, do not try to link to SDL2 +# SDL2_INCLUDE_DIR, where to find SDL.h +# +# This module responds to the the flag: +# SDL2_BUILDING_LIBRARY +# If this is defined, then no SDL2main will be linked in because +# only applications need main(). +# Otherwise, it is assumed you are building an application and this +# module will attempt to locate and set the the proper link flags +# as part of the returned SDL2_LIBRARY variable. +# +# Don't forget to include SDLmain.h and SDLmain.m your project for the +# OS X framework based version. (Other versions link to -lSDL2main which +# this module will try to find on your behalf.) Also for OS X, this +# module will automatically add the -framework Cocoa on your behalf. +# +# +# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration +# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library +# (SDL2.dll, libsdl2.so, SDL2.framework, etc). +# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. +# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL2_LIBRARY +# variable, but when these values are unset, SDL2_LIBRARY does not get created. +# +# +# $SDL2DIR is an environment variable that would +# correspond to the ./configure --prefix=$SDL2DIR +# used in building SDL2. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL guidelines. +# Added a search for SDL2main which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL2/SDL.h to just SDL.h +# This needed to change because "proper" SDL convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL2/ (see FreeBSD). + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(SDL2_ARCH_64 TRUE) + set(SDL2_PROCESSOR_ARCH "x64") +else() + set(SDL2_ARCH_64 FALSE) + set(SDL2_PROCESSOR_ARCH "x86") +endif(CMAKE_SIZEOF_VOID_P EQUAL 8) + +SET(SDL2_SEARCH_PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +FIND_PATH(SDL2_INCLUDE_DIR SDL.h + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES include/SDL2 include SDL2 + PATHS ${SDL2_SEARCH_PATHS} +) + +FIND_LIBRARY(SDL2_LIBRARY_TEMP + NAMES SDL2 + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib lib/${SDL2_PROCESSOR_ARCH} + PATHS ${SDL2_SEARCH_PATHS} +) + +IF(NOT SDL2_BUILDING_LIBRARY) + IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") + # Non-OS X framework versions expect you to also dynamically link to + # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms + # seem to provide SDL2main for compatibility even though they don't + # necessarily need it. + FIND_LIBRARY(SDL2MAIN_LIBRARY + NAMES SDL2main + HINTS + $ENV{SDL2DIR} + PATH_SUFFIXES lib64 lib lib/${SDL2_PROCESSOR_ARCH} + PATHS ${SDL2_SEARCH_PATHS} + ) + ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") +ENDIF(NOT SDL2_BUILDING_LIBRARY) + +# SDL2 may require threads on your system. +# The Apple build may not need an explicit flag because one of the +# frameworks may already provide it. +# But for non-OSX systems, I will use the CMake Threads package. +IF(NOT APPLE) + FIND_PACKAGE(Threads) +ENDIF(NOT APPLE) + +# MinGW needs an additional library, mwindows +# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows +# (Actually on second look, I think it only needs one of the m* libraries.) +IF(MINGW) + SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") +ENDIF(MINGW) + +IF(SDL2_LIBRARY_TEMP) + # For SDL2main + IF(NOT SDL2_BUILDING_LIBRARY) + IF(SDL2MAIN_LIBRARY) + SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(SDL2MAIN_LIBRARY) + ENDIF(NOT SDL2_BUILDING_LIBRARY) + + # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. + # CMake doesn't display the -framework Cocoa string in the UI even + # though it actually is there if I modify a pre-used variable. + # I think it has something to do with the CACHE STRING. + # So I use a temporary variable until the end so I can set the + # "real" variable in one-shot. + IF(APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa") + ENDIF(APPLE) + + # For threads, as mentioned Apple doesn't need this. + # In fact, there seems to be a problem if I used the Threads package + # and try using this line, so I'm just skipping it entirely for OS X. + IF(NOT APPLE) + SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) + ENDIF(NOT APPLE) + + # For MinGW library + IF(MINGW) + SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) + ENDIF(MINGW) + + # Set the final string here so the GUI reflects the final state. + SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") +ENDIF(SDL2_LIBRARY_TEMP) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) \ No newline at end of file diff --git a/cmake/FindSDL2_ttf.cmake b/cmake/FindSDL2_ttf.cmake new file mode 100644 index 0000000..e715f36 --- /dev/null +++ b/cmake/FindSDL2_ttf.cmake @@ -0,0 +1,163 @@ +# Locate SDL2 library +# This module defines +# SDL2_LIBRARY, the name of the library to link against +# SDL2_FOUND, if false, do not try to link to SDL2 +# SDL2_INCLUDE_DIR, where to find SDL.h +# +# This module responds to the the flag: +# SDL2_BUILDING_LIBRARY +# If this is defined, then no SDL2main will be linked in because +# only applications need main(). +# Otherwise, it is assumed you are building an application and this +# module will attempt to locate and set the the proper link flags +# as part of the returned SDL2_LIBRARY variable. +# +# Don't forget to include SDLmain.h and SDLmain.m your project for the +# OS X framework based version. (Other versions link to -lSDL2main which +# this module will try to find on your behalf.) Also for OS X, this +# module will automatically add the -framework Cocoa on your behalf. +# +# +# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration +# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library +# (SDL2.dll, libsdl2.so, SDL2.framework, etc). +# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. +# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value +# as appropriate. These values are used to generate the final SDL2_LIBRARY +# variable, but when these values are unset, SDL2_LIBRARY does not get created. +# +# +# $SDL2DIR is an environment variable that would +# correspond to the ./configure --prefix=$SDL2DIR +# used in building SDL2. +# l.e.galup 9-20-02 +# +# Modified by Eric Wing. +# Added code to assist with automated building by using environmental variables +# and providing a more controlled/consistent search behavior. +# Added new modifications to recognize OS X frameworks and +# additional Unix paths (FreeBSD, etc). +# Also corrected the header search path to follow "proper" SDL guidelines. +# Added a search for SDL2main which is needed by some platforms. +# Added a search for threads which is needed by some platforms. +# Added needed compile switches for MinGW. +# +# On OSX, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SDL2_LIBRARY to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. +# +# Note that the header path has changed from SDL2/SDL.h to just SDL.h +# This needed to change because "proper" SDL convention +# is #include "SDL.h", not . This is done for portability +# reasons because not all systems place things in SDL2/ (see FreeBSD). + +#============================================================================= +# Copyright 2003-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +SET(SDL2TTF_SEARCH_PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw # Fink + /opt/local # DarwinPorts + /opt/csw # Blastwave + /opt +) + +FIND_PATH(SDL2TTF_INCLUDE_DIR SDL_ttf.h + HINTS + $ENV{SDL2TTFDIR} + PATH_SUFFIXES include/SDL2 include + PATHS ${SDL2TTF_SEARCH_PATHS} +) + +FIND_LIBRARY(SDL2TTF_LIBRARY_TEMP + NAMES SDL2_ttf + HINTS + $ENV{SDL2TTFDIR} + PATH_SUFFIXES lib64 lib + PATHS ${SDL2TTF_SEARCH_PATHS} +) + +IF(NOT SDL2TTF_BUILDING_LIBRARY) + IF(NOT ${SDL2TTF_INCLUDE_DIR} MATCHES ".framework") + # Non-OS X framework versions expect you to also dynamically link to + # SDL2TTFmain. This is mainly for Windows and OS X. Other (Unix) platforms + # seem to provide SDL2TTFmain for compatibility even though they don't + # necessarily need it. + FIND_LIBRARY(SDL2TTFMAIN_LIBRARY + NAMES SDL2_ttf + HINTS + $ENV{SDL2TTFDIR} + PATH_SUFFIXES lib64 lib + PATHS ${SDL2TTF_SEARCH_PATHS} + ) + ENDIF(NOT ${SDL2TTF_INCLUDE_DIR} MATCHES ".framework") +ENDIF(NOT SDL2TTF_BUILDING_LIBRARY) + +# SDL2TTF may require threads on your system. +# The Apple build may not need an explicit flag because one of the +# frameworks may already provide it. +# But for non-OSX systems, I will use the CMake Threads package. +IF(NOT APPLE) + FIND_PACKAGE(Threads) +ENDIF(NOT APPLE) + +# MinGW needs an additional library, mwindows +# It's total link flags should look like -lmingw32 -lSDL2TTFmain -lSDL2TTF -lmwindows +# (Actually on second look, I think it only needs one of the m* libraries.) +IF(MINGW) + SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW") +ENDIF(MINGW) + +IF(SDL2TTF_LIBRARY_TEMP) + # For SDL2TTFmain + IF(NOT SDL2TTF_BUILDING_LIBRARY) + IF(SDL2TTFMAIN_LIBRARY) + SET(SDL2TTF_LIBRARY_TEMP ${SDL2TTFMAIN_LIBRARY} ${SDL2TTF_LIBRARY_TEMP}) + ENDIF(SDL2TTFMAIN_LIBRARY) + ENDIF(NOT SDL2TTF_BUILDING_LIBRARY) + + # For OS X, SDL2TTF uses Cocoa as a backend so it must link to Cocoa. + # CMake doesn't display the -framework Cocoa string in the UI even + # though it actually is there if I modify a pre-used variable. + # I think it has something to do with the CACHE STRING. + # So I use a temporary variable until the end so I can set the + # "real" variable in one-shot. + IF(APPLE) + SET(SDL2TTF_LIBRARY_TEMP ${SDL2TTF_LIBRARY_TEMP} "-framework Cocoa") + ENDIF(APPLE) + + # For threads, as mentioned Apple doesn't need this. + # In fact, there seems to be a problem if I used the Threads package + # and try using this line, so I'm just skipping it entirely for OS X. + IF(NOT APPLE) + SET(SDL2TTF_LIBRARY_TEMP ${SDL2TTF_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) + ENDIF(NOT APPLE) + + # For MinGW library + IF(MINGW) + SET(SDL2TTF_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2TTF_LIBRARY_TEMP}) + ENDIF(MINGW) + + # Set the final string here so the GUI reflects the final state. + SET(SDL2TTF_LIBRARY ${SDL2TTF_LIBRARY_TEMP} CACHE STRING "Where the SDL2TTF Library can be found") + # Set the temp variable to INTERNAL so it is not seen in the CMake GUI + SET(SDL2TTF_LIBRARY_TEMP "${SDL2TTF_LIBRARY_TEMP}" CACHE INTERNAL "") +ENDIF(SDL2TTF_LIBRARY_TEMP) + +INCLUDE(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf REQUIRED_VARS SDL2TTF_LIBRARY SDL2TTF_INCLUDE_DIR) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2fa0007..1d9d231 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,23 +1,24 @@ cmake_minimum_required(VERSION 2.8) -add_executable(${EXE_NAME} - scoreitem.cpp - scorestate.cpp - stringinput.cpp - part.cpp - main.cpp - global.cpp - map.cpp - resource.cpp - game.cpp - pausestate.cpp - playstate.cpp - menustate.cpp - menuitem.cpp - menu.cpp +add_executable( + ${EXE_NAME} + scoreitem.cpp + scorestate.cpp + stringinput.cpp + part.cpp + main.cpp + global.cpp + map.cpp + resource.cpp + game.cpp + pausestate.cpp + playstate.cpp + menustate.cpp + menuitem.cpp + menu.cpp ) -target_link_libraries(${EXE_NAME} SDL SDL_ttf) +target_link_libraries(${EXE_NAME} ${TETRIS_LIBRARIES}) set(CMAKE_CXX_FLAGS "-Wextra -ftabstop=4 -march=native -std=gnu++11 -fshow-column -ftabstop=4 -frounding-math -pipe") diff --git a/src/game.cpp b/src/game.cpp index 8fcf29d..652934e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -21,21 +21,22 @@ bool game::Init() return false; } - SDL_EnableUNICODE ( SDL_ENABLE ); + gWindow = SDL_CreateWindow( "[SG]Tetris", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, WIDTH * SIZE + 130, HEIGHT * SIZE, SDL_WINDOW_SHOWN ); - SDL_WM_SetCaption ( "[SG]Tetris", NULL ); - - m_pScreen = SDL_SetVideoMode ( WIDTH * SIZE + 130, HEIGHT * SIZE, 32, SDL_HWSURFACE | SDL_DOUBLEBUF ); - - if ( m_pScreen == NULL ) + if ( gWindow == NULL ) { + printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() ); cerr << "[ERROR] Cannot setup screen" << endl; m_bRunning = false; return false; } + else + { + gScreenSurface = SDL_GetWindowSurface( gWindow ); + } if ( TTF_Init() ) @@ -48,9 +49,9 @@ bool game::Init() } - m_bRunning = Load(); + m_bRunning = Load(); m_bGameOver = false; - tick = 0; + tick = 0; return m_bRunning; } @@ -155,10 +156,14 @@ void game::Draw() states.back()->Draw ( this ); } +SDL_Window * game::GetWindow() +{ + return gWindow; +} SDL_Surface * game::GetScreen() { - return m_pScreen; + return gScreenSurface; } bool game::Running() @@ -172,9 +177,11 @@ void game::Clean() cout << "Cleanning..." << endl; # endif - TTF_CloseFont ( fontMenu ); - - TTF_Quit(); + SDL_DestroyWindow( gWindow ); + gWindow = NULL; + TTF_CloseFont ( fontMenu ); + + TTF_Quit(); SDL_Quit(); } @@ -226,3 +233,8 @@ TTF_Font * game::GetfontMenu() { return fontMenu; } + +void game::SetRunning ( bool Running ) +{ + m_bRunning = Running; +} diff --git a/src/game.hpp b/src/game.hpp index 105b1ca..f580919 100644 --- a/src/game.hpp +++ b/src/game.hpp @@ -3,11 +3,12 @@ #include #include -#include -#include +#include +#include #include "map.hpp" #include "part.hpp" +#include "resource.hpp" using namespace std; @@ -40,6 +41,7 @@ class game SDL_Surface * GetScreen(); Uint32 GetStart(); + SDL_Window * GetWindow(); TTF_Font * GetfontMenu(); TTF_Font * GetfontGame(); @@ -56,7 +58,8 @@ class game void UpdateFPS(); private: - SDL_Surface * m_pScreen; + SDL_Window * gWindow; + SDL_Surface * gScreenSurface; vector states; bool m_bRunning; diff --git a/src/global.hpp b/src/global.hpp index f94e847..919a2fd 100644 --- a/src/global.hpp +++ b/src/global.hpp @@ -1,8 +1,8 @@ #ifndef GLOBAL_HPP_INCLUDED #define GLOBAL_HPP_INCLUDED -#include -#include +#include +#include #include #include diff --git a/src/main.cpp b/src/main.cpp index 6d9bcb3..42f9b40 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include "resource.hpp" #include "global.hpp" @@ -24,7 +24,6 @@ int main ( int argc, char ** argv ) return 0; } - Game.ChangeState ( MenuState::Instance() ); while ( Game.Running() ) diff --git a/src/menuitem.hpp b/src/menuitem.hpp index a703514..1a8d99f 100644 --- a/src/menuitem.hpp +++ b/src/menuitem.hpp @@ -3,8 +3,8 @@ #include -#include -#include +#include +#include #include "global.hpp" #include "game.hpp" diff --git a/src/menustate.cpp b/src/menustate.cpp index 6000851..11c3c68 100644 --- a/src/menustate.cpp +++ b/src/menustate.cpp @@ -96,7 +96,8 @@ void MenuState::Draw(game* Game) { menu->Draw(Game); - SDL_Flip(Game->GetScreen()); + SDL_UpdateWindowSurface( Game->GetWindow() ); + //SDL_Flip(Game->GetScreen()); } diff --git a/src/menustate.hpp b/src/menustate.hpp index a8d32df..b495d9a 100644 --- a/src/menustate.hpp +++ b/src/menustate.hpp @@ -3,7 +3,7 @@ #include -#include +#include #include "game.hpp" #include "gamestate.hpp" diff --git a/src/part.hpp b/src/part.hpp index f22dd20..c97e3e0 100644 --- a/src/part.hpp +++ b/src/part.hpp @@ -2,7 +2,7 @@ #define PART_HPP_INCLUDED #include -#include +#include #include "resource.hpp" #include "global.hpp" diff --git a/src/pausestate.cpp b/src/pausestate.cpp index 989a1c0..0c981cc 100644 --- a/src/pausestate.cpp +++ b/src/pausestate.cpp @@ -89,7 +89,8 @@ void PauseState::Draw(game* Game) { menu->Draw(Game); - SDL_Flip(Game->GetScreen()); + //SDL_Flip(Game->GetScreen()); + SDL_UpdateWindowSurface( Game->GetWindow() ); } diff --git a/src/pausestate.hpp b/src/pausestate.hpp index d4baa03..0fe0b81 100644 --- a/src/pausestate.hpp +++ b/src/pausestate.hpp @@ -3,7 +3,7 @@ #include -#include +#include #include "game.hpp" #include "gamestate.hpp" diff --git a/src/playstate.cpp b/src/playstate.cpp index 8617532..61cadf8 100644 --- a/src/playstate.cpp +++ b/src/playstate.cpp @@ -23,7 +23,7 @@ void PlayState::Init() textColor = make_color(255, 255, 255); - SDL_EnableKeyRepeat ( REPAET_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); +// SDL_EnableKeyRepeat ( REPAET_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); # ifdef DEBUG std::cout << "PlayState Init Successful" << std::endl; @@ -32,7 +32,7 @@ void PlayState::Init() void PlayState::Clean() { - SDL_EnableKeyRepeat ( 0, 0 ); +// SDL_EnableKeyRepeat ( 0, 0 ); # ifdef DEBUG std::cout << "PlayState Clean Successful" << std::endl; @@ -41,7 +41,7 @@ void PlayState::Clean() void PlayState::Pause() { - SDL_EnableKeyRepeat ( 0, 0 ); +// SDL_EnableKeyRepeat ( 0, 0 ); # ifdef DEBUG std::cout << "PlayState Paused" << std::endl; @@ -50,7 +50,7 @@ void PlayState::Pause() void PlayState::Resume() { - SDL_EnableKeyRepeat ( REPAET_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); +// SDL_EnableKeyRepeat ( REPAET_DELAY, SDL_DEFAULT_REPEAT_INTERVAL ); # ifdef DEBUG std::cout << "PlayState Resumed" << std::endl; @@ -226,9 +226,11 @@ void PlayState::Update ( game* Game ) { /* Start enter name */ nameEntering = true; + SDL_StartTextInput(); if (nameEntered) { + SDL_StopTextInput(); nameEntering = false; nameEntered = false; //text.setString("Score " + intToStr(Map.getScore()) + "\n" + "Press enter"); @@ -321,7 +323,8 @@ void PlayState::Draw ( game* Game ) name.show_centered(Game); } - SDL_Flip ( Game->GetScreen() ); + SDL_UpdateWindowSurface( Game->GetWindow() ); + //SDL_Flip ( Game->GetScreen() ); } diff --git a/src/playstate.hpp b/src/playstate.hpp index f13616d..2e11540 100644 --- a/src/playstate.hpp +++ b/src/playstate.hpp @@ -1,7 +1,7 @@ # ifndef PLAY_STATE_HPP_INCLUDED # define PLAY_STATE_HPP_INCLUDED -# include +# include # include # include # include diff --git a/src/scoreitem.hpp b/src/scoreitem.hpp index 62d136f..ea68631 100644 --- a/src/scoreitem.hpp +++ b/src/scoreitem.hpp @@ -2,8 +2,8 @@ #define SCOREITEM_H # include -# include -# include +# include +# include # include "game.hpp" # include "global.hpp" diff --git a/src/scorestate.cpp b/src/scorestate.cpp index 1204343..f306cfb 100644 --- a/src/scorestate.cpp +++ b/src/scorestate.cpp @@ -16,7 +16,8 @@ void ScoreState::Draw ( game * Game ) Items[i].Draw(Game, i * 35); } - SDL_Flip(Game->GetScreen()); + //SDL_Flip(Game->GetScreen()); + SDL_UpdateWindowSurface( Game->GetWindow() ); } void ScoreState::Update ( game * Game ) diff --git a/src/states.hpp b/src/states.hpp index b2201ba..b9a0435 100644 --- a/src/states.hpp +++ b/src/states.hpp @@ -1,4 +1,4 @@ -# include "playstate.hpp" -# include "menustate.hpp" -# include "pausestate.hpp" -# include "scorestate.hpp" +#include "playstate.hpp" +#include "menustate.hpp" +#include "pausestate.hpp" +#include "scorestate.hpp" diff --git a/src/stringinput.cpp b/src/stringinput.cpp index dd1db89..fab8b8d 100644 --- a/src/stringinput.cpp +++ b/src/stringinput.cpp @@ -15,62 +15,71 @@ StringInput::~StringInput() void StringInput::handle_input ( game * Game, SDL_Event *event) { + string temp; + //If a key was pressed if ( event->type == SDL_KEYDOWN ) { //Keep a copy of the current version of the string - string temp = str; + temp = str; //If the string less than maximum size if ( str.length() <= 11 ) { - //If the key is a number - if ( ( event->key.keysym.unicode >= ( Uint16 ) '0' ) && ( event->key.keysym.unicode <= ( Uint16 ) '9' ) ) + //Special key input + if( event->type == SDL_KEYDOWN ) { - //Append the character - str += ( char ) event->key.keysym.unicode; - } - else if ( ( event->key.keysym.unicode == ( Uint16 ) '-' ) ) - { - //Append the character - str += ( char ) event->key.keysym.unicode; - } - //If the key is a uppercase letter - else if ( ( event->key.keysym.unicode >= ( Uint16 ) 'A' ) && ( event->key.keysym.unicode <= ( Uint16 ) 'Z' ) ) - { - //Append the character - str += ( char ) event->key.keysym.unicode; - } - //If the key is a lowercase letter - else if ( ( event->key.keysym.unicode >= ( Uint16 ) 'a' ) && ( event->key.keysym.unicode <= ( Uint16 ) 'z' ) ) - { - //Append the character - str += ( char ) event->key.keysym.unicode; + //Handle backspace + if( event->key.keysym.sym == SDLK_BACKSPACE && str.length() > 0 ) + { + //lop off character + str.pop_back(); + } + //Handle copy + else if( event->key.keysym.sym == SDLK_c && SDL_GetModState() & KMOD_CTRL ) + { + SDL_SetClipboardText( str.c_str() ); + } + //Handle paste + else if( event->key.keysym.sym == SDLK_v && SDL_GetModState() & KMOD_CTRL ) + { + str = SDL_GetClipboardText(); + } } + } + } + //Special text input event + else if( event->type == SDL_TEXTINPUT ) + { + //Keep a copy of the current version of the string + temp = str; - #ifdef DEBUG - cout << str << endl; - #endif - - //If backspace was pressed and the string isn't blank - if ( ( event->key.keysym.sym == SDLK_BACKSPACE ) && ( str.length() != 0 ) ) + //If the string less than maximum size + if ( str.length() <= 11 ) { - //Remove a character from the end - str.erase ( str.length() - 1 ); - } - - //If the string was changed - if ( str != temp ) - { - //Free the old surface - SDL_FreeSurface ( text ); - - //Render a new text surface - text = TTF_RenderText_Solid ( Game->GetfontGame(), str.c_str(), textColor ); + //Not copy or pasting + if( !( ( event->text.text[ 0 ] == 'c' || event->text.text[ 0 ] == 'C' ) && ( event->text.text[ 0 ] == 'v' || event->text.text[ 0 ] == 'V' ) && SDL_GetModState() & KMOD_CTRL ) ) + { + //Append character + str += event->text.text; + } } } + #ifdef DEBUG + cout << str << endl; + #endif + + //If the string was changed + if ( str != temp ) + { + //Free the old surface + SDL_FreeSurface ( text ); + + //Render a new text surface + text = TTF_RenderText_Solid ( Game->GetfontGame(), str.c_str(), textColor ); + } } void StringInput::show_centered ( game * Game ) diff --git a/src/stringinput.hpp b/src/stringinput.hpp index f02d0d9..e8e6fbc 100644 --- a/src/stringinput.hpp +++ b/src/stringinput.hpp @@ -3,8 +3,8 @@ # include # include -# include -# include +# include +# include # include "game.hpp" # include "global.hpp" From d07ecdc228d2f1756572cd656777d7fa7804b013 Mon Sep 17 00:00:00 2001 From: SGOrava Date: Mon, 6 Apr 2015 21:26:10 +0200 Subject: [PATCH 7/7] Remove .kdev4 directory --- .kdev4/Tetris.kdev4 | 56 ------------------------------------------- .kdev4/_custom.kdev4 | 20 ---------------- .kdev4/tetris.kdev4 | 57 -------------------------------------------- 3 files changed, 133 deletions(-) delete mode 100644 .kdev4/Tetris.kdev4 delete mode 100644 .kdev4/_custom.kdev4 delete mode 100644 .kdev4/tetris.kdev4 diff --git a/.kdev4/Tetris.kdev4 b/.kdev4/Tetris.kdev4 deleted file mode 100644 index 2ffea92..0000000 --- a/.kdev4/Tetris.kdev4 +++ /dev/null @@ -1,56 +0,0 @@ -[Buildset] -BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x0c\x00T\x00e\x00t\x00r\x00i\x00s) - -[CMake] -Build Directory Count=1 -CMakeDir=/usr/share/cmake-3.0/Modules -Current Build Directory Index=0 -ProjectRootRelative=./ - -[CMake][CMake Build Directory 0] -Build Directory Path=file:///home/juraj/projects/Tetris/build -Build Type=Debug -CMake Binary=file:///usr/bin/cmake -Environment Profile= -Extra Arguments= -Install Directory=file:///usr/local - -[Defines And Includes][Compiler] -Name=GCC -Path=gcc -Type=GCC - -[Launch] -Launch Configurations=Launch Configuration 0 - -[Launch][Launch Configuration 0] -Configured Launch Modes=execute -Configured Launchers=nativeAppLauncher -Name=Tetris -Type=Native Application - -[Launch][Launch Configuration 0][Data] -Arguments= -Debugger Shell= -Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00) -Dependency Action=Nothing -Display Demangle Names=true -Display Static Members=true -EnvironmentGroup=default -Executable= -External Terminal=xterm -hold -e %exe -GDB Path= -Project Target=Tetris,tetris -Remote GDB Config Script= -Remote GDB Run Script= -Remote GDB Shell Script= -Start With=ApplicationOutput -Use External Terminal=true -Working Directory= -isExecutable=false - -[Project] -VersionControlSupport=kdevgit - -[SourceFileTemplates] -LastUsedTemplate=/home/juraj/.kde/share/apps/kdevfiletemplates/template_descriptions/cpp_basic.desktop diff --git a/.kdev4/_custom.kdev4 b/.kdev4/_custom.kdev4 deleted file mode 100644 index e128f9a..0000000 --- a/.kdev4/_custom.kdev4 +++ /dev/null @@ -1,20 +0,0 @@ -[Containments][1] -ActionPluginsSource=Global -activity=tetris -activityId= -desktop=-1 -formfactor=0 -geometry=0,0,1098,581 -immutability=1 -lastDesktop=-1 -lastScreen=0 -location=0 -orientation=2 -plugin=newspaper -screen=0 -zvalue=0 - -[Project] -Manager=KDevCMakeManager -Name=tetris -VersionControl= diff --git a/.kdev4/tetris.kdev4 b/.kdev4/tetris.kdev4 deleted file mode 100644 index 4632700..0000000 --- a/.kdev4/tetris.kdev4 +++ /dev/null @@ -1,57 +0,0 @@ -[Buildset] -BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00) - -[CMake] -Build Directory Count=2 -CMakeDir=/usr/share/cmake-2.8/Modules -Current Build Directory Index=0 -ProjectRootRelative=./ - -[CMake][CMake Build Directory 0] -Build Directory Path=file:///home/juraj/projects/tetris/build -Build Type= -CMake Binary=file:///usr/bin/cmake -Environment Profile=default -Extra Arguments= -Install Directory=file:///usr/local - -[CMake][CMake Build Directory 1] -Build Directory Path=file:///home/juraj/projects/tetris/releare -Build Type=Release -CMake Binary=file:///usr/bin/cmake -Environment Profile=Release -Extra Arguments= -Install Directory=file:///usr/local - -[Launch] -Launch Configurations=Launch Configuration 0 - -[Launch][Launch Configuration 0] -Configured Launch Modes=execute -Configured Launchers=nativeAppLauncher -Name=Tetris -Type=Native Application - -[Launch][Launch Configuration 0][Data] -Arguments= -Debugger Shell= -Dependencies=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x00) -Dependency Action=Nothing -Display Demangle Names=true -Display Static Members=true -EnvironmentGroup=default -Executable= -External Terminal=xterm -hold -e %exe -GDB Path= -Project Target=tetris,tetris -Remote GDB Config Script= -Remote GDB Run Script= -Remote GDB Shell Script= -Start With=GdbConsole -Use External Terminal=true -Working Directory= -isExecutable=false - -[MakeBuilder] -Number Of Jobs=3 -Su Command=2