Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <SFML/Graphics.hpp>
- #include <SFML/Audio.hpp>
- #include <SFML/System.hpp>
- #include <SFML/Window.hpp>
- #include <fstream>
- #include <vector>
- #include <limits>
- #include <string>
- #include <stdio.h>
- #include <windows.h>
- #include "connector.hpp"
- using namespace std;
- using namespace sf;
- //Declarations
- //Global variables
- const int scl = 16; //the images will be placed vector2f(image[][].x * scl, image[][].y * scl)
- Sprite Bomberman;
- Sprite Bomb;
- //Classes
- //Structures
- struct maps{
- int width;
- int height;
- Texture Entities;
- Texture Wall;
- Texture Barrier;
- // Texture Other;
- vector<vector<Sprite> > all;
- vector<vector<bool> > canGo;
- };
- //Functions
- std::string getexepath()
- {
- char result[ MAX_PATH ];
- GetModuleFileName( NULL, result, MAX_PATH );
- return string(result, 1);
- }
- ifstream& GotoLine(std::ifstream& file, unsigned int num){
- file.seekg(std::ios::beg);
- for(unsigned int i=0; i < num - 1; ++i){
- file.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
- }
- return file;
- }
- maps getMapData(string fileName){
- const string DRIVE_LETTER = getexepath();
- maps rtrn;
- ////////////////////////////////
- ///Line 1 = comment
- ///Line 2 = comment
- ///Line 3 = int width
- ///Line 4 = comment
- ///Line 5 = int height
- ///Line 6 = Dirt and wall images
- ///Line 7 = Entities images
- ///Line 8 = Dirt array
- ///Line 9 = Entities array
- ///Line 10 = Walls array
- ///////////////////////////////
- string path = (DRIVE_LETTER + ":/C++ Projects/Bomberman/DATA/mapData/" + fileName);
- //////////////////////////////
- ifstream mapFl(path.c_str());
- if (!mapFl){
- cout << "ERR_FILE.NOTFOUND" << endl;
- cout << path << endl;
- }
- string readline = " ";
- GotoLine(mapFl, 3);
- mapFl >> readline;
- const int width_ = atoi(readline.c_str());
- //const int width_ = int(readline.c_str() - '0');
- rtrn.width = width_;
- GotoLine(mapFl, 5);
- mapFl >> readline;
- const int height_ = atoi(readline.c_str());
- rtrn.height = height_;
- GotoLine(mapFl, 6);
- mapFl >> readline;
- string idlePath = readline;
- GotoLine(mapFl, 7);
- mapFl >> readline;
- string ePath = readline;
- GotoLine(mapFl, 8);
- mapFl >> readline;
- string dirtAr = readline;
- GotoLine(mapFl, 9);
- mapFl >> readline;
- string entityAr = readline;
- GotoLine(mapFl, 10);
- mapFl >> readline;
- string wallAr = readline;
- ////////////////////////////////
- mapFl.close();
- path = (DRIVE_LETTER + ":/C++ Projects/Bomberman/" + idlePath);
- if(!rtrn.Barrier.loadFromFile(path)){
- cout << "ERROR_CANNOT_OPEN_FILE:" << idlePath;
- }
- path = (DRIVE_LETTER + ":/C++ Projects/Bomberman/" + ePath);
- if(!rtrn.Entities.loadFromFile(path)){
- cout << "ERROR_CANNOT_OPEN_FILE:" << ePath;
- }
- path = (DRIVE_LETTER + ":/C++ Projects/Bomberman/" + dirtAr);
- mapFl.open(path.c_str());
- vector<vector<char> > result(width_, vector<char>(height_));
- char arrayResult = 0;
- for(int j = 0; j != height_; j++){
- for(int i = 0; i != width_; i++){
- if(!mapFl.good()){
- cout << "ERROR WITH FILE" << endl;
- break;
- }
- arrayResult = mapFl.get();
- (result[i])[j] = arrayResult;
- // cout << (result[i])[j];
- }
- }
- for (unsigned int i = 0; i < rtrn.canGo.size(); ++i) {
- for (unsigned int j = 0; j < rtrn.canGo[i].size(); ++j) {
- bool temp = false;
- if(result[i][j] == 1){
- temp = true;
- }
- rtrn.canGo[i][j] = temp;
- }
- }
- for (unsigned int i = 0; i < rtrn.all.size(); ++i) {
- for (unsigned int j = 0; j < rtrn.all[i].size(); ++j) {
- rtrn.all[i][j].setTexture(rtrn.Barrier);
- rtrn.all[i][j].setPosition(Vector2f(i * scl, j * scl));
- rtrn.all[i][j].setTextureRect(getRect(false, true, false, 1, 0));
- }
- }
- return rtrn;
- }
- //More Global variables
- //Main
- int main()
- {
- maps LM_MAIN = getMapData("Lvl1.map");
- RenderWindow window(sf::VideoMode(LM_MAIN.width * scl, (LM_MAIN.height * scl) + 20), "Bomberman!");
- while (window.isOpen())
- {
- sf::Event event;
- while (window.pollEvent(event))
- {
- if (event.type == sf::Event::Closed)
- window.close();
- }
- window.clear();
- for (auto&& v : LM_MAIN.all) {
- for (auto&& sprite : v) {
- window.draw(sprite);
- }
- }
- window.display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement