// Creates a new GameView to summarise the current state of the game GameView newGameView(char *pastPlays, PlayerMessage messages[]) { //printf("called newGameView\n"); GameView gameView = malloc(sizeof(struct gameView)); // INITIALIZE ALL THE THINGS IN THE GAMEVIEW STRUCT gameView->RoundNum = 0; gameView->CurrentPlayer = 0; gameView->GameScore = GAME_START_SCORE; gameView->europe = newMap(); gameView->Lord_Godalming = initPlayer(PLAYER_LORD_GODALMING); gameView->Dr_Seward = initPlayer(PLAYER_DR_SEWARD); gameView->Van_Helsing = initPlayer(PLAYER_VAN_HELSING); gameView->Mina_Harker = initPlayer(PLAYER_MINA_HARKER); gameView->Dracula = initPlayer(PLAYER_DRACULA); int i; int scoreChange=0; //// HANDLING PAST PLAYS STRING //// We will probably do this a different way in the final thing, (maybe) //// but for now it has to be like this because we can't add functions in //// this ADT (( :( )) for (i=0; pastPlays[i] != '\0' ; i+=7) { if (pastPlays[i] == ' ') i++; if (pastPlays[i] == 'G') { //if Godalmings turn 0 scoreChange = doPlayerTurn(gameView->Lord_Godalming, pastPlays+i); } else if (pastPlays[i] == 'S') { //Seward 1 scoreChange = doPlayerTurn(gameView->Dr_Seward, pastPlays+i); } else if (pastPlays[i] == 'H') { //Van helsing 2 scoreChange = doPlayerTurn(gameView->Van_Helsing, pastPlays+i); } else if (pastPlays[i] == 'M') { //Mine 3 scoreChange = doPlayerTurn(gameView->Mina_Harker, pastPlays+i); } else if (pastPlays[i] == 'D') { //DRACUULLLAAA 4 scoreChange = doPlayerTurn(gameView->Dracula, pastPlays+i); } if (scoreChange <= 0) { gameView->GameScore += scoreChange; } else if (scoreChange == 10) deductHealth(gameView->Dracula, 10); else if (scoreChange == 4) { deductHealth(gameView->Dracula, 10); gameView->GameScore -= 6; } gameView->CurrentPlayer++; if (gameView->CurrentPlayer==5) { gameView->CurrentPlayer = 0; gameView->RoundNum++; } } return gameView; }
void GameShell::action() { loadMap(); bob.draw(screen); zombie.draw(screen); updateLifebar(screen); refresh(); bool playing = true; // is the player alive? while(true) { int start = SDL_GetTicks(); actions.handleEvents(); if(playing == false) { if(actions.exitGame() == true) { break; } } else { if(actions.exitGame() == true) { break; } else if(actions.direction.x != 0 || actions.direction.y != 0) { if(col->detect(bob.coord, actions.direction, tiles) == false) { repaintTile(bob.coord); bob.move(actions.direction, screen); repaintTile(zombie.coord); if(bob.coord.x == exit.x && bob.coord.y == exit.y) { gameWon(); playing = false; } else { if(near_exit(bob) == true || near_player(bob) == true) // The zombie will start the chase { int zombie_old_x = zombie.coord.x; int zombie_old_y = zombie.coord.y; Tile* t = findPath(tiles[0][(zombie.coord.x + zombie.coord.y * (SCREEN_WIDTH / TILE_WIDTH))/32], tiles[0][(bob.coord.x + bob.coord.y * (SCREEN_WIDTH / TILE_WIDTH))/32]); if (t == NULL) std::cout << "t e NULL :(\n"; else { // update zombie coordinates zombie.coord.x = t->coord.x; zombie.coord.y = t->coord.y; std::cout<< "PREV COORDS: X = " <<zombie_old_x<<" | Y = "<<zombie_old_y<<"\n"; std::cout<< "NEW COORDS: X = " <<zombie.coord.x<<" | Y = "<<zombie.coord.y<<"\n"; // set the frame according to the direction if(zombie.coord.x - zombie_old_x == TILE_WIDTH) { zombie.last_frame = 1; std::cout<<"RIGHT\n"; } else if(zombie.coord.x - zombie_old_x == -TILE_WIDTH) { zombie.last_frame = 3; std::cout<<"LEFT\n"; } else if(zombie.coord.y - zombie_old_y == -TILE_HEIGHT) { zombie.last_frame = 0; std::cout<<"UP\n"; } else if(zombie.coord.y - zombie_old_y == TILE_HEIGHT) { zombie.last_frame = 2; std::cout<<"DOWN\n"; } } } else // The zombie will patrol { SDL_Rect temp = zombie.move(screen); repaintTile(zombie.coord); if (col->detect(zombie.coord, temp, tiles) == false) { zombie.coord.x += temp.x * TILE_WIDTH; zombie.coord.y += temp.y * TILE_HEIGHT; } } zombie.draw(screen); bob.draw(screen); // zombie attacks the player if(bob.coord.x == zombie.coord.x && bob.coord.y == zombie.coord.y) { deductHealth(zombie.damage); // repair the 3 tiles which are under the lifebar SDL_Rect repair; repair.x = (SCREEN_WIDTH - BAR_WIDTH) / 2 - 14; repair.y = 0; for(int i = 0; i < 4; i++) { repaintTile(repair); repair.x += TILE_WIDTH; } // update the player's lifebar updateLifebar(screen); } } } refresh(); } else { if(actions.use_item == true) { if (bob.inventory.cursor != NULL) { bob.inventory.cursor->val->use(bob); bob.inventory.Delete(); if (bob.inventory.cursor != NULL) bob.inventory.draw(bkgtiles, tileset, screen, bob.inventory.cursor->val->type); else bob.inventory.draw(bkgtiles, tileset, screen, 9); } updateLifebar(screen); } if(actions.left_inv_arrow == true && bob.inventory.cursor != NULL) { bob.inventory.moveLeft(bkgtiles, tileset, screen); bob.inventory.draw(bkgtiles, tileset, screen, bob.inventory.cursor->val->type); } if(actions.right_inv_arrow == true && bob.inventory.cursor != NULL) { bob.inventory.moveRight(bkgtiles, tileset, screen); bob.inventory.draw(bkgtiles, tileset, screen, bob.inventory.cursor->val->type); } refresh(); int layer_numb = layerNumber - 1; int tile_numb = bob.coord.y / 32 * 20 + (bob.coord.x / 32); if((tiles[layer_numb][tile_numb])->hasItem() == true) { bob.pick(tiles[layer_numb][tile_numb]); int type = (tiles[layer_numb][tile_numb])->type; (tiles[layer_numb][tile_numb])->type = TRANSPARENCY; repaintTile((tiles[layer_numb][tile_numb])->coord); bob.draw(screen); SDL_Rect dest; dest.x = 14 * TILE_WIDTH; dest.y = 0; repaintTile(dest); bob.inventory.draw(bkgtiles, tileset, screen, type); refresh(); } } actions.reset(); } if(bob.health <= 0 && playing == true) { SDL_Rect bloodpos; bloodpos.x = bloodpos.y = 0; bloodpos.w = bloodpos.h = TILE_HEIGHT; repaintTile(zombie.coord); zombie.draw(screen); SDL_BlitSurface(tileset, &bkgtiles[5], screen, &zombie.coord); gameOver(); playing = false; refresh(); } if(1000/FPS > SDL_GetTicks() - start) { SDL_Delay(1000/FPS - (SDL_GetTicks() - start)); } } }