Skip to content

Commit

Permalink
final edition
Browse files Browse the repository at this point in the history
  • Loading branch information
elena3441 committed Feb 6, 2018
1 parent 7e932c2 commit 54195a8
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 32 deletions.
Binary file added Sounds/intro.WAV
Binary file not shown.
File renamed without changes.
3 changes: 2 additions & 1 deletion SourceCode/AI.h
Original file line number Diff line number Diff line change
Expand Up @@ -449,14 +449,15 @@ class MovingPathAnimatorAI : public MovingPathAnimator {
int col = game->GetSnake()->GetCurrCol() + ColList.front(); // ypologizw col
game->GetSnake()->UpdateRowCol(row, col);
// cout << "SNAKE BALL: row->" << game->GetSnake()->GetCurrRow() << " col->" << game->GetSnake()->GetCurrCol() << endl;
TheSoundManager::Instance()->playSound("Snake", 0);
}
else {
int row = game->GetBall(sprite)->GetCurrRow() + 1;
int col = game->GetBall(sprite)->GetCurrCol() + ColList.front();
game->GetBall(sprite)->UpdateRowCol(row, col);
// cout << "BALL " << sprite->GetId() <<": row->" << game->GetBall(sprite)->GetCurrRow() << " col->" << game->GetBall(sprite)->GetCurrCol() << endl;
}
//TheSoundManager::Instance()->playSound("Ball", 0);
TheSoundManager::Instance()->playSound("Ball", 0);
ColList.pop_front();
}
if (currPathFrame == anim->GetEndPathFrame()) {
Expand Down
2 changes: 1 addition & 1 deletion SourceCode/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class MovingPathAnimator : public Animator {
for (auto i = spriteList.GetList().begin(); i != spriteList.GetList().end(); ++i) {
if ( !((*i)->GetId().compare(0, 4, "cube"))) {
CubeSprite *cube = dynamic_cast<CubeSprite*> (*i);
assert(cube);
// assert(cube);
int qbertRow = game->GetQbertRow();
int qbertCol = game->GetQbertCol();
if (cube->getRow() == qbertRow && cube->getCol() == qbertCol) {
Expand Down
40 changes: 24 additions & 16 deletions SourceCode/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "AI.h"
#include "Disk.h"
#include <windows.h>

#include "SoundManager.h"



Expand All @@ -24,12 +24,15 @@ void Game::LoseLife() {


bool Game::init(const char * title, int xpos, int ypos, int width, int height, int flags,int flag) {
/*TheSoundManager::Instance()->load("Sounds/Hop.wav", "Qberthop", SOUND_SFX);
TheSoundManager::Instance()->load("Sounds/Hop.wav", "Qberthop", SOUND_SFX);
TheSoundManager::Instance()->load("Sounds/QbertFall.wav", "QbertFalls", SOUND_SFX);
TheSoundManager::Instance()->load("Sounds/ByeBye.wav", "bye", SOUND_SFX);
TheSoundManager::Instance()->load("Sounds/disk.wav", "disk", SOUND_SFX);
TheSoundManager::Instance()->load("Sounds/BallHop.wav", "Ball", SOUND_SFX);
TheSoundManager::Instance()->load("Sounds/snakeHop", "Snake", SOUND_SFX);*/
TheSoundManager::Instance()->load("Sounds/snakeHop.wav", "Snake", SOUND_SFX);
TheSoundManager::Instance()->load("Sounds/Sware1.wav", "Sware1", SOUND_SFX);
TheSoundManager::Instance()->load("Sounds/win.wav", "win", SOUND_SFX);
TheSoundManager::Instance()->load("Sounds/intro.wav", "intro", SOUND_SFX);
if (flag == 0) {
game_state = START;
if (SDL_Init(SDL_INIT_VIDEO) == 0) {
Expand All @@ -55,7 +58,7 @@ bool Game::init(const char * title, int xpos, int ypos, int width, int height, i
std::cout << "SDL Error: Failed to initialize: " << SDL_GetError() << std::endl;
return false;
}
SDL_Surface * pTempSurface = SDL_LoadBMP("Sprites/startWords.bmp");
SDL_Surface * pTempSurface = SDL_LoadBMP("Sprites/start.bmp");
m_pTexture = SDL_CreateTextureFromSurface(m_pRenderer, pTempSurface);
SDL_FreeSurface(pTempSurface);
SDL_QueryTexture(m_pTexture, NULL, NULL, &m_sourceRectangle.w, &m_sourceRectangle.h);
Expand Down Expand Up @@ -97,6 +100,7 @@ bool Game::init(const char * title, int xpos, int ypos, int width, int height, i
m_destinationRectangle3.h = 35;
m_destinationRectangle3.x = 250;
m_destinationRectangle3.y =100;
TheSoundManager::Instance()->playSound("intro", 0);
}
else {
game_state = PLAY;
Expand Down Expand Up @@ -165,6 +169,7 @@ void Game::Collision() {

if (DoBoxesIntersect(qbert->GetSprite(), (*i))) {
cout << "Colission with ball" << endl;
TheSoundManager::Instance()->playSound("Sware1", 0);
LoseLife();
}

Expand All @@ -177,6 +182,7 @@ void Game::Collision() {
ai->GetSnake()->GetCurrCol() == qbert->GetCurrCol() &&
ai->GetSnake()->GetCurrRow() == qbert->GetCurrRow()) {
cout << "Colission with Snake" << endl;
TheSoundManager::Instance()->playSound("Sware1", 0);
LoseLife();
}

Expand Down Expand Up @@ -219,8 +225,8 @@ void Game::handleEvents() {
//OR
//Here we lose
if (qbert->GetCurrRow() == 5 && diskRight->GetIsActive()) {
//TheSoundManager::Instance()->playsound("bye", 0);
//TheSoundManager::Instance()->playsound("disk", 0);
TheSoundManager::Instance()->playSound("bye", 0);
TheSoundManager::Instance()->playSound("disk", 0);
diskRight->MoveUpRight();
qbert->MoveUpDiskRight();
qbert->Restore();
Expand Down Expand Up @@ -252,12 +258,12 @@ void Game::handleEvents() {
qbert->SetZOrder(5);
spriteList.GetList().sort(compare);
qbertAnimator->Start(game->GetGameTime());
//TheSoundManager::Instance()->playsound("QbertFalls", 0);
TheSoundManager::Instance()->playSound("QbertFalls", 0);
LoseLife();
}
else {
qbert->moveUpRight();
//TheSoundManager::Instance()->playsound("Qberthop", 0);
TheSoundManager::Instance()->playSound("Qberthop", 0);
terrain->SetActive(qbert->GetCurrCol(), qbert->GetCurrRow());
cout << "Current active : " << terrain->currActive() << endl;
cout << "Qbert Position changed to : ";
Expand Down Expand Up @@ -292,11 +298,12 @@ void Game::handleEvents() {
spriteList.GetList().sort(compare);
}
qbertAnimator->Start(game->GetGameTime());
TheSoundManager::Instance()->playSound("QbertFalls", 0);
LoseLife();
}
else {
qbert->moveDownLeft();
//TheSoundManager::Instance()->playsound("Qberthop", 0);
TheSoundManager::Instance()->playSound("Qberthop", 0);
terrain->SetActive(qbert->GetCurrCol(), qbert->GetCurrRow());
cout << "Current active : " << terrain->currActive() << endl;
cout << "Qbert Position changed to : ";
Expand Down Expand Up @@ -333,14 +340,14 @@ void Game::handleEvents() {
spriteList.GetList().sort(compare);
}
qbertAnimator->Start(game->GetGameTime());

TheSoundManager::Instance()->playSound("QbertFalls", 0);
LoseLife();


}
else {
qbert->moveDownRight();
//TheSoundManager::Instance()->playsound("Qberthop", 0);
TheSoundManager::Instance()->playSound("Qberthop", 0);
terrain->SetActive(qbert->GetCurrCol(), qbert->GetCurrRow());
cout << "Current active : " << terrain->currActive() << endl;
cout << "qbert Position changed to : ";
Expand All @@ -351,8 +358,8 @@ void Game::handleEvents() {
else if (event.key.keysym.sym == SDLK_LEFT) {
if (qbert->GetCurrCol() == 1) {
if (qbert->GetCurrRow() == 5 && diskLeft->GetIsActive()) {
//TheSoundManager::Instance()->playsound("bye", 0);
//TheSoundManager::Instance()->playsound("disk", 0);
TheSoundManager::Instance()->playSound("bye", 0);
TheSoundManager::Instance()->playSound("disk", 0);
diskLeft->MoveUpLeft();
qbert->MoveUpDiskLeft();
qbert->Restore();
Expand Down Expand Up @@ -383,11 +390,12 @@ void Game::handleEvents() {
qbert->SetZOrder(5);
spriteList.GetList().sort(compare);
qbertAnimator->Start(game->GetGameTime());
TheSoundManager::Instance()->playSound("QbertFalls", 0);
LoseLife();
}
else {
qbert->moveUpLeft();
//TheSoundManager::Instance()->playsound("Qberthop", 0);
TheSoundManager::Instance()->playSound("Qberthop", 0);
terrain->SetActive(qbert->GetCurrCol(), qbert->GetCurrRow());
cout << "Current active : " << terrain->currActive() << endl;
cout << "Position changed to : ";
Expand All @@ -409,7 +417,7 @@ void Game::handleEvents() {

if (terrain->currActive() == 28 && win == false) {
win = true;

TheSoundManager::Instance()->playSound("win", 0);
terrain->Epilipsia1();
}
}
Expand All @@ -420,7 +428,7 @@ void Game::clean() {
std::cout << "cleaning game\n";
SDL_DestroyWindow(m_pWindow);
SDL_DestroyRenderer(m_pRenderer);
//TheSoundManager::Instance()->clearSoundMap();
TheSoundManager::Instance()->clearSoundMap();
SDL_Quit();
}

Expand Down
4 changes: 2 additions & 2 deletions SourceCode/SoundManager.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*#include "SoundManager.h"
#include "SoundManager.h"

SoundManager* SoundManager::s_pInstance;

Expand Down Expand Up @@ -75,4 +75,4 @@ void SoundManager::clearSoundMap() {
}
}
m_sfxs.clear();
}*/
}
4 changes: 2 additions & 2 deletions SourceCode/SoundManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef SOUNDMANAGER_H_DEFINED
#define SOUNDMANAGER_H_DEFINED
/*

#include <iostream>
#include <map>
#include <string>
Expand Down Expand Up @@ -37,5 +37,5 @@ class SoundManager {
};

typedef SoundManager TheSoundManager;
*/

#endif /* defined(SOUNDMANAGER_H_DEFINED) */
15 changes: 15 additions & 0 deletions SourceCode/Terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ class IsometricPyramid final {
if (!sprites[i]->isActive()) {
sprites[i]->SetActive();
//sprites[i]->SetFrame(2);
/*PathEntry *p2 = new PathEntry(0, 0, 4,100);
PathEntry *p3 = new PathEntry(0, 0, 2,1500);
path.push_back(*p2);
path.push_back(*p3);
MovingPathAnimation* qbertAnimation = new MovingPathAnimation(path, "Terrain" + i);
MovingPathAnimator* qbertAnimator = new MovingPathAnimator(sprites[i], qbertAnimation);
qbertAnimator->SetCont(true);
qbertAnimator->Start(game->GetGameTime());
path.clear();*/

activeCubes++;
}

Expand Down
39 changes: 29 additions & 10 deletions SourceCode/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,21 @@ void f() {
}
}
game->render();
game->update();
}

}

int main(int argc, char* args[]) {
game = new Game();
while (true) {
f();
game->init("Q*bert", 200, 40, 800, 700, 0, 1);
IsometricPyramid *terrain = new IsometricPyramid(400, 80, 7, 26, 74);
Qbert *qbert = new Qbert(377, 56);
Disk *diskLeft = new Disk("DiskLeft", 70, 350);
Disk *diskRight = new Disk("DiskRight", 680, 350);
bool flag = false;
//int count = 0;
diskLeft->Spin();
diskRight->Spin();
game->SetGameTime(); // arxhkopoiw to game->currTime (den einai swsto ekei kai prepei na fygei apla to xrhsimopoiw gia na dwkomasw to Qbert::Animation())
Expand All @@ -72,19 +74,36 @@ int main(int argc, char* args[]) {
if (game->lose) {
(game->GameLife)--;
game->Lose();
if (!(game->GameLife)) break;
if (!(game->GameLife)) {
AnimationFilm* film = AnimationFilmHolder::Get().GetFilm("GameOver");
if (film == nullptr) {
SDL_Rect rect;
vector<SDL_Rect> boxes;
rect.x = 0;
rect.y = 0;
rect.h = 400;
rect.w = 800;
boxes.push_back(rect);

string id = "GameOver";
AnimationFilmHolder::Get().Load(id, "Sprites/gameOver.bmp", boxes);
}
film = AnimationFilmHolder::Get().GetFilm("GameOver");
Sprite * gameOver = new Sprite("GameOver", film, 200, 200, 400, 100, 100);
spriteList.Insert(gameOver);
cout << "GAME OVERR" << endl;
}
game->Restart();
}
if (game->win)
count++;
if (count == 800) {
game->Lose();

if (game->win) count++;
if (game->GameLife <= 0 && !(game->win)) count++;

if (count == 3000)
break;
}
}
}
game->clean();
return 0;
game->clean();
return 0;
}


Binary file added Sprites/animate.bmp
Binary file not shown.
Binary file added Sprites/gameOver.bmp
Binary file not shown.
Binary file added Sprites/krustallia.bmp
Binary file not shown.
Binary file added Sprites/rider.bmp
Binary file not shown.
Binary file added Sprites/start.bmp
Binary file not shown.
Binary file added Sprites/startNames.bmp
Binary file not shown.
Binary file added Sprites/startProject.bmp
Binary file not shown.
Binary file added Sprites/startScreen.bmp
Binary file not shown.
Binary file added Sprites/startWords.bmp
Binary file not shown.

0 comments on commit 54195a8

Please sign in to comment.