cv::Mat draw_board(const baxter_tictactoe::MsgBoard::ConstPtr& msg) const { ROS_DEBUG("@display_board"); cv::Mat img(height,width,CV_8UC3,white); // 3x3 tic tac toe board unsigned short int col, row; this->draw_lines(img); for (size_t i = 0; i < msg->cells.size(); ++i) { ROS_DEBUG_STREAM("Processing Cell " << i); if(msg->cells[i].state>0) { col=i%n_cols; row=i/n_rows; cv::Point center_cell(cols_cell_img/2 + cols_cell_img*col, rows_cell_img/2 + rows_cell_img*row); cv::Point bottom_left_corner; cv::Point top_right_corner(cols_cell_img*5/6 + cols_cell_img*col, rows_cell_img*5/6 + rows_cell_img*row); ROS_DEBUG_STREAM("Center point in cell " << i << " (" << center_cell.x << "," << center_cell.y << ")"); draw_tile(img,i,msg->cells[i].state); } } return img; }
int main(int, char const**) { // Create the main window sf::RenderWindow window(sf::VideoMode(TILE_WIDTH*28, TILE_WIDTH*31), "PAC MAN"); window.setFramerateLimit(FRAME_RATE); // Set the Icon sf::Image icon; if (!icon.loadFromFile(resourcePath() + "icon.png")) { return EXIT_FAILURE; } window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr()); // Try to open the given texture sf::Texture tileset_texture; if (!tileset_texture.loadFromFile(resourcePath() + "data/full_texture_x3.png")) { return EXIT_FAILURE; } // More importantly, let's generate our tileset from that texture. AssetManager assetManager(TILE_WIDTH); std::map<sf::String, sf::Sprite> spriteSet = assetManager.generateSpriteSet(&tileset_texture); std::map<sf::String, PacTile*> tileSet; PacTile outer_top_left_corner(spriteSet["outer_top_left_corner"], "WALL"); tileSet["outer_top_left_corner"] = &outer_top_left_corner; PacTile weird_north_left_corner(spriteSet["weird_north_left_corner"], "WALL"); tileSet["weird_north_left_corner"] = &weird_north_left_corner; PacTile weird_west_upper_corner(spriteSet["weird_west_upper_corner"], "WALL"); tileSet["weird_west_upper_corner"] = &weird_west_upper_corner; PacTile weird_east_upper_corner(spriteSet["weird_east_upper_corner"], "WALL"); tileSet["weird_east_upper_corner"] = &weird_east_upper_corner; PacTile weird_west_lower_corner(spriteSet["weird_west_lower_corner"], "WALL"); tileSet["weird_west_lower_corner"] = &weird_west_lower_corner; PacTile weird_east_lower_corner(spriteSet["weird_east_lower_corner"], "WALL"); tileSet["weird_east_lower_corner"] = &weird_east_lower_corner; PacTile box_top_left_corner(spriteSet["box_top_left_corner"], "WALL"); tileSet["box_top_left_corner"] = &box_top_left_corner; PacTile top_right_corner(spriteSet["top_right_corner"], "WALL"); tileSet["top_right_corner"] = &top_right_corner; PacTile weird_north_right_corner(spriteSet["weird_north_right_corner"], "WALL"); tileSet["weird_north_right_corner"] = &weird_north_right_corner; PacTile box_top_right_corner(spriteSet["box_top_right_corner"], "WALL"); tileSet["box_top_right_corner"] = &box_top_right_corner; PacTile bottom_right_corner(spriteSet["bottom_right_corner"], "WALL"); tileSet["bottom_right_corner"] = &bottom_right_corner; PacTile box_bottom_right_corner(spriteSet["box_bottom_right_corner"], "WALL"); tileSet["box_bottom_right_corner"] = &box_bottom_right_corner; PacTile bottom_left_corner(spriteSet["bottom_left_corner"], "WALL"); tileSet["bottom_left_corner"] = &bottom_left_corner; PacTile box_bottom_left_corner(spriteSet["box_bottom_left_corner"], "WALL"); tileSet["box_bottom_left_corner"] = &box_bottom_left_corner; PacTile top_edge(spriteSet["top_edge"], "WALL"); tileSet["top_edge"] = &top_edge; PacTile box_top_edge(spriteSet["box_top_edge"], "WALL"); tileSet["box_top_edge"] = &box_top_edge; PacTile left_edge(spriteSet["left_edge"], "WALL"); tileSet["left_edge"] = &left_edge; PacTile inner_left_edge(spriteSet["inner_left_edge"], "WALL"); tileSet["inner_left_edge"] = &inner_left_edge; PacTile right_edge(spriteSet["right_edge"], "WALL"); tileSet["right_edge"] = &right_edge; PacTile inner_right_edge(spriteSet["inner_right_edge"], "WALL"); tileSet["inner_right_edge"] = &inner_right_edge; PacTile bottom_edge(spriteSet["bottom_edge"], "WALL"); tileSet["bottom_edge"] = &bottom_edge; PacTile box_bottom_edge(spriteSet["box_bottom_edge"], "WALL"); tileSet["box_bottom_edge"] = &box_bottom_edge; // House tiles! PacTile house_top_right_corner(spriteSet["house_top_right_corner"], "WALL"); tileSet["house_top_right_corner"] = &house_top_right_corner; PacTile house_bottom_right_corner(spriteSet["house_bottom_right_corner"], "WALL"); tileSet["house_bottom_right_corner"] = &house_bottom_right_corner; PacTile house_top_left_corner(spriteSet["house_top_left_corner"], "WALL"); tileSet["house_top_left_corner"] = &house_top_left_corner; PacTile house_bottom_left_corner(spriteSet["house_bottom_left_corner"], "WALL"); tileSet["house_bottom_left_corner"] = &house_bottom_left_corner; PacTile door(spriteSet["door"], "WALL"); tileSet["door"] = &door; PacTile floor(spriteSet["floor"], "FLOOR"); tileSet["floor"] = &floor; // Load up the map! Map map(sf::Vector2<double>(0, 0), sf::Vector2<int>(28, 31), TILE_WIDTH); map.configureMap(tileSet); // Create a graphical text to display /*sf::Font font; if (!font.loadFromFile(resourcePath() + "sansation.ttf")) { return EXIT_FAILURE; } // Load a music to play sf::Music music; if (!music.openFromFile(resourcePath() + "nice_music.ogg")) { return EXIT_FAILURE; }*/ // Declare the ghosts! Pinky pinky(sf::Vector2<double>(0, 0), "HOME"); Blinky blinky(sf::Vector2<double>(0, 0), "HOME"); Inky inky(sf::Vector2<double>(0, 0), "HOME"); Sue sue(sf::Vector2<double>(0, 0), "HOME"); // Game variables // Assemble the PacMan! PacMan pacman(1, 1, 1, 60, map); std::vector<sf::Sprite> pacUpSprites; std::vector<sf::Sprite> pacDownSprites; std::vector<sf::Sprite> pacLeftSprites; std::vector<sf::Sprite> pacRightSprites; pacUpSprites.push_back(spriteSet["pacUp0"]); pacUpSprites.push_back(spriteSet["pacUp1"]); pacUpSprites.push_back(spriteSet["pacUp2"]); pacUpSprites.push_back(spriteSet["pacUp1"]); pacDownSprites.push_back(spriteSet["pacDown0"]); pacDownSprites.push_back(spriteSet["pacDown1"]); pacDownSprites.push_back(spriteSet["pacDown2"]); pacDownSprites.push_back(spriteSet["pacDown1"]); pacLeftSprites.push_back(spriteSet["pacLeft0"]); pacLeftSprites.push_back(spriteSet["pacLeft1"]); pacLeftSprites.push_back(spriteSet["pacLeft2"]); pacLeftSprites.push_back(spriteSet["pacLeft1"]); pacRightSprites.push_back(spriteSet["pacRight0"]); pacRightSprites.push_back(spriteSet["pacRight1"]); pacRightSprites.push_back(spriteSet["pacRight2"]); pacRightSprites.push_back(spriteSet["pacRight1"]); pacman.setUpSprites(pacUpSprites, 4); pacman.setDownSprites(pacDownSprites, 4); pacman.setLeftSprites(pacLeftSprites, 4); pacman.setRightSprites(pacRightSprites, 4); pacman.setVelocity(sf::Vector2<double>(0.0, 1.0)); pacman.initialize("RIGHT"); // Play the music // music.play(); // Start the game loop while (window.isOpen()) { // Process events sf::Event event; while (window.pollEvent(event)) { // Close window: exit if (event.type == sf::Event::Closed) { window.close(); } // Escape pressed: exit if (event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape) { window.close(); } } pacman.update(map); // DRAWING THE SCREEN window.clear(); // Draw the map drawMap(&window, map); // Then, draw any pellets / fruits, those type things // Then, draw the ghosts // Then, draw pacman window.draw(pacman.getSprite()); // Update the window window.display(); } return EXIT_SUCCESS; }