Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "StudentWorld.h"
- #include "GameConstants.h"
- #include <string>
- using namespace std;
- #include "Actor.h"
- #include <iostream>
- GameWorld* createStudentWorld(string assetPath)
- {
- return new StudentWorld(assetPath);
- }
- // Students: Add code to this file, StudentWorld.h, Actor.h, and Actor.cpp
- StudentWorld::StudentWorld(string assetPath)
- : GameWorld(assetPath)
- {
- m_board = new Board;
- m_peach = nullptr;
- m_yoshi = nullptr;
- }
- // set<Player*>& is a reference to the set of pointers that point to a player object
- void StudentWorld::get_players_on_square(std::set<Player*>& players_on_square, int x, int y)
- {
- // Utilizing set because there could be multiple players colliding with a square at once
- // Want to process both players on the square
- if (m_peach->getX() == x && m_peach->getY() == y)
- players_on_square.insert(m_peach);
- if (m_yoshi->getX() == x && m_yoshi->getY() == y)
- players_on_square.insert(m_yoshi);
- }
- Actor* StudentWorld::get_random_square(int x, int y)
- {
- std::vector<Actor*> possible_squares;
- for (int i = 0; i < m_actors.size(); i++)
- {
- if (m_actors[i]->is_square() && m_actors[i]->getX() != x && m_actors[i]->getY() != y)
- possible_squares.push_back(m_actors[i]);
- }
- int random_choice = randInt(0, possible_squares.size() - 1);
- return possible_squares[random_choice];
- }
- int StudentWorld::init()
- {
- string board_file = assetPath() + "board0" + to_string(getBoardNumber()) + ".txt";
- Board::LoadResult res = m_board->loadBoard(board_file);
- // Iterate rows first then columns
- for (int x = 0; x < BOARD_WIDTH; x++)
- {
- for (int y = 0; y < BOARD_HEIGHT; y++)
- {
- Board::GridEntry grid_entry = m_board->getContentsOf(x, y);
- const int sprite_x = x * SPRITE_WIDTH;
- const int sprite_y = y * SPRITE_HEIGHT;
- // Drill in using const when possible and private
- //
- // Define coin value, don't use the number 3
- switch (grid_entry)
- {
- case Board::player:
- m_peach = new Player(PEACH, sprite_x, sprite_y, this);
- m_yoshi = new Player(YOSHI, sprite_x, sprite_y, this);
- m_actors.push_back(m_peach);
- m_actors.push_back(m_yoshi);
- m_actors.push_back(new Coin_Square(3, sprite_x, sprite_y, this));
- break;
- case Board::blue_coin_square:
- m_actors.push_back(new Coin_Square(3, sprite_x, sprite_y, this));
- break;
- case Board::boo:
- m_actors.push_back(new Boo(sprite_x, sprite_y, this));
- m_actors.push_back(new Coin_Square(3, sprite_x, sprite_y, this));
- break;
- case Board::bowser:
- m_actors.push_back(new Bowser(sprite_x, sprite_y, this));
- m_actors.push_back(new Coin_Square(3, sprite_x, sprite_y, this));
- break;
- default:
- break;
- }
- }
- }
- startCountdownTimer(99); // this placeholder causes timeout after 5 seconds
- return GWSTATUS_CONTINUE_GAME;
- }
- int StudentWorld::move()
- {
- // This code is here merely to allow the game to build, run, and terminate after you hit ESC.
- // Notice that the return value GWSTATUS_NOT_IMPLEMENTED will cause our framework to end the game.
- setGameStatText("Game will end in a few seconds");
- if (timeRemaining() <= 0)
- {
- return GWSTATUS_NOT_IMPLEMENTED;
- }
- for (size_t i = 0; i < m_actors.size(); i++)
- {
- m_actors[i]->do_something();
- }
- return GWSTATUS_CONTINUE_GAME;
- }
- void StudentWorld::cleanUp()
- {
- for (size_t i = 0; i < m_actors.size(); i++)
- {
- delete m_actors[i];
- m_actors[i] = nullptr;
- }
- delete m_board;
- m_board = nullptr;
- }
- StudentWorld::~StudentWorld()
- {
- cleanUp();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement