Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

196 Neutral

About inanhour&

  • Rank
  1. inanhour&

    Game Structure Advice

    Thanks for the replies.     With the four functions in a game_state: Enter(), Leave(), Update(), Render(). Would you handle input in the update() function which would delegate it out to the objects in that state? Like the player or a button/ menu / piece of interface?   Also, where would you create the game objects? As public members of the game class?   As for scenes, would they only contain data about the game world like the player position, items the player has, world size etc. If there was a pre-made level made of a grid of tiles, would that all be loaded in in the same file?
  2. inanhour&

    Game Structure Advice

    Hello! This isn't a specific question, I just need some general advice on how to structure the code of a game.   Basically, I have been trying to write small games for a while and I eventually give up/start again because the code gets too tangled to keep working on it.   Right now I have written a sort of 'base game' that doesn't have anything game-like in it right now, mainly just the structure I would use to write a game. To me it seems like it could work, but am worried it is going to trip me up later on because I have no idea if what I am doing, if it is right or wrong, or if it resembles how actual games are structured.   So I am just looking for a pointer in the right direction before I do a game, so I know what I am doing is generally the right idea and I don't waste time making a massive mess.   Base game   There is quite a lot of code there but, like I said, I just need general guidance on the structure rather than the specific details, which are probably shit as well but oh well.   Thanks a lot!
  3. Oh my god I am an idiot.
  4. Thanks for your quick response. When I put #include "object.h" in component.cpp i get a linker error: Undefined symbols for architecture x86_64: "object::getSomething()", referenced from: component::accessThis(object&) in component.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
  5. Hello. Thanks in advance for reading. In this pattern http://gameprogrammingpatterns.com/component.html   with the example:   Bjørn contains an instance of inputComponent and calls its method like input_.update(this*); this method then accesses members of bjørn, like bjorn.velocity -= WALK_ACCELERATION;   I didn’t understand how this could work, each object accessing each others members/methods  without causing a dependancy loop. So I made a little test program, but I can’t get it to work. I get the error 'member access into incomplete type 'object''.Am I missing something? Or not understanding the pattern?   My basic test:   object.h: #include "component.h"   class object{ private:     component _component; public:     const char* getSomething();     void doSomething(); }; object.cpp: #include "object.h" void object::doSomething(){ _component.accessThis(*this); } const char* getSomething(){ return "something"; } component.h: #include <iostream> class object; class component{ public: void accessThis(object& obj); }; component.cpp: #include "component.h" void component::accessThis(object& obj){ std::cout<< "got" << obj.getSomething() << ".\n"; }
  6. This is quite a specific question, but I couldn't find a forum on ncurses so I thought I might as well ask it here. I am writing a program using ncurses that needs a function to highlight a line of characters on the screen. I started writing this function that took the x & y coordinates of a character on the screen and the length of characters after that to highlight. Whilst doing this I noticed that if I highlighted the last character in a row (maxX-1 in my example) it highlighted that character (as expected), and if I highlighted just the character before that (maxX-2) it also works. But if I do both, it highlights the whole row/line. Also, if there are characters in those spaces other than the 'space' character it works too, but for my program I need to be able to highlight empty spaces as well.   To highlight I am using inch() to get the character and addch() to print it because I am using some alternate characters that chgat() replaces with normal characters.   If anyone has any ideas why it could be doing this, that would be a great help, since this makes no sense to me and there must be something i'm missing.   #include <ncurses.h>   int main(){     initscr();     start_color();     use_default_colors();     curs_set(0);     noecho();          int maxX=0, maxY=0;     getmaxyx(stdscr, maxY, maxX);          init_pair(5, 15, 10);          attron(COLOR_PAIR(5)|A_BLINK);     mvaddch(5, maxX-1, inch());     //works as expected          mvaddch(6, maxX-1, inch());     mvaddch(6, maxX-2, inch());     //highlights whole line for some reason? whyyy?          mvaddch(7, maxX-1, inch());     mvaddch(7, maxX-2, 'c');        //works as expected     attroff(COLOR_PAIR(5)|A_BLINK);          refresh();     getch();     endwin();          return 0; }
  7. inanhour&

    code review - basic state system

    Thanks for the replies!     Ok, I have made a few changes to the program. It is now closer to yours, in that there is no global/static 'currentState' pointer (I understand thread safety a bit better now) and instead of a 'getInput()' function there is a 'process()' function which returns a state pointer which works just as you described.   Although, how would you not change state after a process()? Since, returning NULL is used for quit. I returned 'this', so it sets the current state to the same as it was before. I don't know if there is a way of returning something else, so it knows not to bother changing the state.   I also decided to change state transitions so they don’t have to be driven by input. For my simple program I wasn’t thinking I would need this, but I might as well just in case I want to later on. I still used the map of keys-to-states idea, but instead of keys, it uses state indexes (I used an enum). So, like you described, states know about the other states in an abstract way, but you need to 'setTransition(stateIndex index,  state* const state)' so that 'process()' can return a pointer to that state, using the map and index.   here is the updated version, if you want to see what i mean.   So yeah, thanks for the help! I think it works much better now (:
  8. I am writing a simple board game where the players place pieces on a board. (theres more to it than that, but you get the idea)   I needed a system where, on one screen the player can view the board and select tiles, and on the other they can select from a menu the type of tile they want to place.   For this I needed two 'states', each one handling input and output differently. So I created these as classes, both inheriting from the 'state' class. The thing I have had difficulty with is switching between these classes, since they cant see each other, and how the current state pointer switches from one state to the next will depend on the original state. What I have done is given the state class a 'states' static vector, which stores pointers to all the states that have been created, and a non-static 'keys' vector which stores the input needed to access that state from the this state (so the two vectors sort of line-up).    Anyway this seemed kind of messy and there is probably a reason why you shouldn't do this and i'm probably doing everything wrong anyway. So I'm posting this on here to ask for some feedback before I make it even worse.   thanks!   Here is the program. (its not actually a board game here. I've reduced it to just the basic state system)
  9. So, I have been learning the basics of C++ by writing a simple Battleships program (with the aid of tutorials from thenewboston.org and this Youtube channel). Well, I say simple, but to be honest it's taken me quite a bit longer than I was expecting. I guess speed is something that comes with practice, but the program seems to work anyway.   The program has basic AI, so that when the computer player hits a human player's ship once, it will try to find the rest of that ship. The ships are also randomly positioned.   Here  it is.   I am posting this on here because I am thinking of doing something more complex (a roguelike, using ncurses). Since I'm only teaching myself, as far as I know I might be doing things inefficiently, or even doing everything completely wrong. So I want to make sure I've got the basics down first.   One thing i was unsure about was in the computer player class. There are 4 functions sharing a bunch of variables, and I defined them as members of that class. I thought that passing pointers to them all from function to function wouldn't be as clear and would look messy, but this means that they take up memory even when they're not being used.   If anyone could scan through it and tell me anything I'm doing wrong, that would be really helpful. 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!