Jump to content
  • Advertisement

bean.

Member
  • Content Count

    15
  • Joined

  • Last visited

Community Reputation

102 Neutral

About bean.

  • Rank
    Member
  1. Thank you everyone for the help. This has been an awesome learning experience for me. The Rule of Three was my problem, specifically, I was passing my Map object by reference to my Player object to check for collisions. This. After a whole lot of hair pulling, I think this was it. I knew that I wasn't making any copies of my map object, but I didn't know that passing it by reference would be an issue. I'm not sure why I didn't think to mention that sooner. So, I'm going to do some more research tomorrow. I understand how to write Destructors and Assignment operators, I just have to learn more about copy constructors. Here was the problem code: if (update) { player.Update(_map); } void Player::Update(Map &mp) { // These variables will record the distance that the player is going to move. float moveX = 0.0f; float moveY = 0.0f; // Movement based on keypresses. if(Game::GetInput().IsKeyDown(sf::Key::Left)) { moveX--; } else if(Game::GetInput().IsKeyDown(sf::Key::Right)) { moveX++; } else if(Game::GetInput().IsKeyDown(sf::Key::Down)) { moveY++; } else if(Game::GetInput().IsKeyDown(sf::Key::Up)) { moveY--; } // If the new destination is not a wall, move the player. if(mp.IsPassable((_cellPosX + moveX), (_cellPosY + moveY))) { GetSprite().Move(moveX * Game::CELL_SIZE, moveY * Game::CELL_SIZE); _cellPosX += moveX; _cellPosY += moveY; //return; } } bool Map::IsPassable(int x, int y) { // Iterates through the vector. std::vector<Wall*>::iterator iter; for (iter = _mazeMap.begin(); iter != _mazeMap.end(); ++iter) { // If the x and y coordinates of the tile are equal to a wall's x and y coords // then the tile is not passable. if ((*iter)->GetCellX() == x && (*iter)->GetCellY() == y) { return false; } //std::cout << std::endl << "X: " << (*iter).GetCellX() << std::endl << "Y: " << (*iter).GetCellY() << std::endl; } return true; }
  2. I learned a good deal about debugging today, a lot more than I knew before. However, all I was able to gather was that something was releasing my pointers before the destructor of Map was being called. So, I just took out the destructor, and used Instruments to run it and check it for Memory Leaks. It didn't detect any, so, I'm not sure what's happening. I tried using NSZombie to help, but it didn't get me too far. Using breakpoints, I noticed, that right before delete *iter is called, the value of *iter is non existant, as it does not have the X and Y values that a *Wall should have. Is there any way that pointers could get released before calling delete on them? I'm not using smart pointers. Unless my pointers are magically smarter than I thought.
  3. Thanks for all the help so far! Yeah, I'm just trying to tackle this right now, cause if I can get this to work, then my game (final project for my 1st programming course) will be done. Here's the constructors and destructors of Wall and VisibleGameObject, and an extra function or two that might be necessary to see what's going on. // Loads the wall from an image. Sets its position. Wall::Wall(int x, int y) : _cellPosX(x), _cellPosY(y) { Load("images/Wall.png"); SetPosition(_cellPosX * Game::CELL_SIZE, _cellPosY * Game::CELL_SIZE); assert(IsLoaded()); } Wall::~Wall() { } // When an object is created, it is not yet loaded. VisibleGameObject::VisibleGameObject() { _isLoaded=false; } VisibleGameObject::~VisibleGameObject() { } // Loads an image and sets it as the sprite. void VisibleGameObject::Load(std::string filename) { // Handles the image not loading. if(_image.LoadFromFile(filename) == false) { _filename = ""; _isLoaded = false; } // Sets the image for the sprite. else { _filename = filename; _sprite.SetImage(_image); _isLoaded = true; } } Edit: Sorry about that. I'm not sure what happened. Code fixed.
  4. I use xcode (developing on a macbook). I don't have much experience with my debugger, so I'm going to go do some research and figure out how to properly use it. Here are the 2 class definitions. class Wall : public VisibleGameObject { public: // Functions explained in implementation. Wall(int x, int y); ~Wall(); int GetCellX(); int GetCellY(); void Draw(sf::RenderWindow& rw); private: // X and Y position member variables. int _cellPosX; int _cellPosY; }; class VisibleGameObject { public: VisibleGameObject(); virtual ~VisibleGameObject(); // Loads an image for the object. virtual void Load(std::string filename); // Draws the object to the screen. virtual void Draw(sf::RenderWindow& window); // Updates the object's position. virtual void Update(float elapsedTime); // Sets the position of the sprite. virtual void SetPosition(float x, float y); // Returns a Vector for the position of the sprite. virtual sf::Vector2f GetPosition() const; // Boolean value for the image/sprite being loaded virtual bool IsLoaded() const; protected: // Provides access to the sprite sf::Sprite& GetSprite(); private: // Member variables sf::Sprite _sprite; sf::Image _image; std::string _filename; bool _isLoaded; };
  5. The crash did not go away when I replaced the code. Here's my debugger output if that sheds light on anything? I'm just lost. I can't figure out what I'm doing wrong. GNU gdb 6.3.50-20050815 (Apple version gdb-1708) (Thu Nov 3 21:59:02 UTC 2011) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000 warning: Unable to read symbols for @executable_path/../Frameworks/sfml-audio.framework/Versions/A/sfml-audio (file not found). warning: Unable to read symbols from "sfml-audio" (not yet mapped into memory). warning: Unable to read symbols for @executable_path/../Frameworks/sfml-graphics.framework/Versions/A/sfml-graphics (file not found). warning: Unable to read symbols from "sfml-graphics" (not yet mapped into memory). warning: Unable to read symbols for @executable_path/../Frameworks/sfml-network.framework/Versions/A/sfml-network (file not found). warning: Unable to read symbols from "sfml-network" (not yet mapped into memory). warning: Unable to read symbols for @executable_path/../Frameworks/sfml-system.framework/Versions/A/sfml-system (file not found). warning: Unable to read symbols from "sfml-system" (not yet mapped into memory). warning: Unable to read symbols for @executable_path/../Frameworks/sfml-window.framework/Versions/A/sfml-window (file not found). warning: Unable to read symbols from "sfml-window" (not yet mapped into memory). warning: Unable to read symbols for @executable_path/../Frameworks/SFML.framework/Versions/A/SFML (file not found). warning: Unable to read symbols from "SFML" (not yet mapped into memory). [Switching to process 49627 thread 0x0] 0x0x1000000000000000sharedlibrary apply-load-rules all Warning: the current language does not match this frame. Current language: auto; currently c++ (gdb) Update: Does this help at all? It's a picture of my debug area, and I think it's showing what's going on underneath the iterator. I'm not sure I particularly understand it though. Update 2: Could my issue have anything to do with the fact that class Wall extends VisibleGameObject? I have a blank virtual destructor in VisibleGameObject and a blank destructor in Wall.
  6. This is the output I get when that printf statement executes: 0x0xc00000001012f520 And that's all I get. I'm not extremely experienced at programming, just enough to know what I'm doing, I'd say. However, I'm not sure how to go about checking my implementations of new and delete. I haven't overloaded them, if that's what you're asking? How should I go about checking what implementations of new and delete I'm using? Thanks for the help. Edit: I commented out the (delete *iter) line with the printf statement still inserted. It gave me a ton of memory addresses. So, for some reason the program is crashing as soon as it tries to delete the first pointer.
  7. It's empty. Is that where my problem lies? I didn't give it much thought since it just has a few member variables and a draw function.
  8. It gives me the bad access error on the delete *iter line. I'm still not sure what's wrong. It's still happening, and I can't really understand it. Here's my code that Loads the Map/Vector in case that would help at all. // Loads the map from a text file. void Map::Load() { // Opens the file. std::ifstream loadedFile; loadedFile.open("images/level.txt"); // Variable that will hold each line for parsing. std::string line; // Counts how many rows have been completed. int rowcounter = 0; // Makes sure the file has opened. if(loadedFile.is_open()) { // Remains true until the file has ended. // Loops through each line. while(std::getline(loadedFile, line)) { // Once the line has been put into the string variable, // this will go through each character an check for walls. for (int i = 0; i < LEVELWIDTH; i++) { // If a wall (a '1' character in the text file) is found // then this will put it into the vector. if (line == '1') { _mazeMap.push_back(new Wall(i, rowcounter)); } } // After the line has been parsed, this iterates the counter. rowcounter++; } } } Edit: Yes, commenting out the (delete *iter) line causes the bug to disappear. As far as I'm aware, I don't make any copies of _mazeMap or Map objects. I have a single static Map object in my Game Global, and that's it.
  9. Hey everybody. I've run into a snag, and I can't quite figure it out. I'm making a maze game with c++ and SFML. My problem is with my Map class. My map class parses a text file (which is a text version of the map grid), and reads all 1s as Walls and all 0s as blank spaces. The 0s are ignored, and for each 1 that it encounters, it takes the coordinates of the '1' and creates a pointer to a Wall object with those coordinates, and adds it to my _mazeMap vector. vector _mazeMap; _mazeMap.push_back(new Wall(x, y)); is the gist of it. My problem is cleaning up the memory. In my Map class' destructor I figure I need to delete all the pointers that were created in the vector, correct? So this is the code I wrote to try and do it: Map::~Map() { std::vector::iterator iter = _mazeMap.begin(); for (iter = _mazeMap.begin(); iter != _mazeMap.end(); ++iter) { delete *iter; } } However, every time I run the game, when I shut it down, and the Destructor gets run, I get this error: Thread 1: Program received signal: "EXC_BAD_ACCESS" I have no idea what I'm doing wrong. Any help? Thanks so much.
  10. bean.

    ATM Project for School

    Alright. That makes sense. Is it okay to make a new class for every menu I have? For example, have a class FirstMenu, SecondMenu, ThirdMenu, all the way up to like 10 menus, that all extend the abstract class? I didn't want to go overboard with classes, so I avoided that, but I thought of doing something similar. My main method is quite bloated as of right now as a result.
  11. Hey everybody. I'm in my intro to programming class in College (Computer Science Major). We're learning C++ at the moment. So, our first big project of the semester is to make an ATM (Automated Teller Machine) Simulation Program, using the console for input and output. We haven't gotten to Classes or anything like that yet, but I wanted to try and implement them anyway (I've got a bit of past experience in Java, not a lot, but enough to know the basics of OOP). My teacher said it was fine to use anything in C++ if we knew about content that we haven't learned about yet. Point. I wrote the program today, and I was hoping that if I posted my thought process (as concise as possible), and how I implemented everything, I could get a few critiques and suggestions on my coding style. Why waste a learning opportunity, right? I approached the program similar to how I've learned to think about a game. I made a big, state driven loop. I used enums to control the states, and just used a boolean value (exit) to control the loop. First, the user selects the language after they insert their card (card is 'inserted' automatically, there is a cout statement that tells the user they inserted it.) So, we have to have the rest of the program's output in 2 languages. I chose English and Spanish. I implemented this by setting any output that is given to the console as variables. I set constants, for example, const string ENGLISH_PIN_MENU_TEXT = "Please enter your pin Number."; const string SPANISH_PIN_MENU_TEXT = "BLAH BLAH BLAH EL BLAH"; string pinMenuText; while (!exit) switch (currentState) { case SELECT_LANGUAGE: if (input == 1) //english pinMenuText = ENGLISH_PIN_MENU_TEXT; else if (input == 2) //spanish pinMenuText = SPANISH_PIN_MENU_TEXT; break; case PIN_MENU: int input; cout << pinMenuText; cin >> input; etc... Is this a good way to implement language localization? I was trying to avoid writing to the hard drive cause I'm not extremely comfortable with file parsing and all that yet. So yeah. The language implementation is one of the big things I would appreciate criticism on. The other big question I have is about my menu implementation. I created a class ATMMenu that I used to make formatting the output text for each state in the program a little bit easier. class ATMMenu { public: void SetText(std::string txtdisplayed); void AddOption(int option, std::string optiontext); void SetMaxTries(int maxtries); int GetMaxTries(); int GetInput(); void Display(); private: std::string _MenuText; static const int MAX_OPTIONS = 5; std::string _Options[MAX_OPTIONS]; int _MaxTries = 50; std::string _Error; }; Did I implement all of this alright? The general idea is that I use SetText to set the Menu's Text, AddOption to add options for the user to select, and then Display() outputs both of them together in a formatted cout state. GetInput then uses cin statements so that in my main() method I can put GetInput into a switch statement and then handle the user's input from there. Max Tries are there so that in the main() method I can use a for loop to let the user go through a menu more than once if incorrect input is entered (if the input is correct, the for loop breaks, if not, it loops again and gets more user input). How is this looking? Those are my big 3 questions about everything I coded. The Language Implementation, The State Driven Design, and the ATMMenu class. What could I have done differently? How could I have added more classes and simplified the design? Is my coding style alright? How could I have taken advantage of pointers? Here is one more excerpt from my actual program that shows the usage of the ATMMenu class and also the for loop I was talking about. // Select account to display or withdraw from case SELECT_ACCOUNT: { ATMMenu selAcct; selAcct.SetText(accountSelect); // Adds the options, checking and savings are both //string variables that are set in the SELECT_LANGUAGE state of //the loop selAcct.AddOption(1, checking); selAcct.AddOption(2, savings); // allows the user multiple chances to enter correct //input for (int i = 0; i < selAcct.GetMaxTries(); i++) { selAcct.Display(); switch (selAcct.GetInput()) { case 1: //activeAccount is an enum activeAccount = CHECKING; curBal = CheckingBalance; curState = BALANCE_OR_WITHDRAW; break; case 2: activeAccount = SAVINGS; curBal = SavingsBalance; curState = BALANCE_OR_WITHDRAW; break; // 0 is used to exit the program. case 0: exit = true; break; default: // handles all other entered numbers cout << endl << invalidNumberError << endl; break; } // If the correct input is received, break out of the for loop. if (curState == BALANCE_OR_WITHDRAW || exit == true) { break; } } break; } Thanks for any help I'm given.
  12. bean.

    2D game engine but what API?

    As someone who was in your situation a couple weeks ago, I would second the suggestion of SFML (just get right to it, don't bother with SDL). SDL and SFML are essentially very similar, while SFML is object oriented and is C++ based while SDL is C based (from what I understand). Both have the option of using OpenGL when you'd like to take that jump, however SFML uses hardware rendering, whereas SDL uses software rendering, for the built in graphics functions of the libraries. This vastly increases the rendering speed, making games written without OpenGL much faster in SFML than in SDL. There really isn't much sense in learning SDL and then SFML when they are pretty much the same thing. At least imo. Some useful resources: http://www.sfml-dev.org/tutorials/1.6/ http://www.gamefromscratch.com/page/Game-From-Scratch-CPP-Edition-The-Introduction.aspx Those 2 resources should be enough to get yous tarted on a 2D engine. You can also make use of the LazyFoo Tutorials for SDL once you know how to work SFML, for other things that have to do with game logic.
  13. bean.

    Video tutorials about game making

    Didn't get a chance to watch more than a couple minutes of the videos yet, but I'm looking forward to watching them when I get some time later today! Subscribed.
  14. bean.

    Biting off more than I can chew?

    Thank you. I appreciate your advice. My goal is like what you said, to create an engine by creating a game and then having the reusable parts for later. That's what I mean by creating an engine I suppose. I don't want to create an engine for creating an engine's sake. I want to create a game and create the engine for that game in the process. And I want to do that on my own so that I can do everything for learning's sake, as well. My fear is by using someone else's game engine, I'll be limited in what I'm doing, and I won't understand what's going on, even though I would get my first games out faster. Worth it, or would you say I'm better off just switching to an engine and learning the API?
  15. Hey there guys. I've been following this forum for a few days now, and so I thought I'd pose one of the questions that has been on my mind. Am I biting off more than I can chew? A little bit of background info. I'm 18, and a first semester Computer Science student, with a Minor in Mathematics. Programming is what I've wanted to do with my life since I was 11. So I started teaching myself Java at 13, which went through an on again off again cycle all through high school, mostly due to time and extra curricular activities. I have a pretty decent understanding of programming as a result. Anyway. Game development has always been a more interesting subject to me, and as is true for a lot of others, is the reason I began programming. So, I understand the concepts of a whole lot of things, and I'm going through Lazy Foo's Tutorials to learn some stuff with SDL, and then I'd like to build on that base with the OpenGL SuperBible. My question is, am I hindering myself by going straight to SDL and OpenGL? I mean, I know there are plenty of engines out there. And so many different ways to make games. My problem is, I want to understand everything. I don't want to use somebody else's engine because I want to know how an engine works and make my own. I don't want to use something just because it makes things "easy", and I would much rather just start off muscling through openGL and engine creation so that I can build on a solid foundation and not have to bother transitioning later. Is this an okay mindset to have? Am I actually making things harder on myself? And, am I going about things in the right way (lazyfoo's tutorials, opengl superbible)? I appreciate your feedback! Thanks!
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!