Jump to content

  • Log In with Google      Sign In   
  • Create Account

Josh Petrie

Member Since 11 Jun 2003
Offline Last Active Private

#5198794 Should the player be just another entity in the etities list?

Posted by Josh Petrie on 17 December 2014 - 10:56 AM



A significant portion of the player's interactions with the game world can be modeled exactly the same as other entities' interactions, so it makes sense to have the player be just another entity. However, the player will also usually require additionally bookkeeping data that doesn't apply to other entities, so it makes sense to have a dedicated structure for that.


I usually model this by having a "player controller" or some similar object which has a reference to the game entity representing the player. This allows the best of both worlds, and if done cleanly can also allow you to temporarily take control of other entities in the world for diagnostic purposes.


Of course, for games where the player has no avatar in the world itself (Tetris and other puzzle games, for example), this doesn't really apply.

#5198635 declare custom types of ints?

Posted by Josh Petrie on 16 December 2014 - 04:31 PM

Ok, I just tested something about the old enum. You can't cast one EnumA into EnumB. Didn't remember that as I haven't used that enum type for a while. However you can pass both EnumA andEnumB into a function expecting an int. That shouldn't be too much of a problem though, if one is consitent in the use of enums.



"EnumA a = static_cast<EnumA>(someValueOfTypeEnumB);" is quite legal in C++. Did you mean something else when you said "cast?"

#5198462 0 experience in programming and game development

Posted by Josh Petrie on 15 December 2014 - 10:38 PM

i love playing games and thats why im choosing to start in this trade



Making games is nothing like playing them.

#5198360 Do i have to make basic games again after break in gamedev?

Posted by Josh Petrie on 15 December 2014 - 11:44 AM

So I am wondering if I need to recreate these simple games or I can start with more advanced concepts like AI, side scrolling, more physics etc



What do you think? Do you think you still retain enough of the information you learned originally to feel comfortable working on those more advanced concepts? If so, then go ahead. If you find yourself struggling you can always stop, re-evaluate, and potentially try something simpler.

#5198356 Minimalist Programming Environment

Posted by Josh Petrie on 15 December 2014 - 11:27 AM

vim is best learned incrementally. That is, you really shouldn't try going out and replacing your entire development workflow with one centered around vim in one go. Install it, and start using it for occasional editing of regular text files, or quick one-off edits where you don't need a lot of the context an IDE will provide. Add plugins and tweaks to your vimrc slowly, and try to avoid the temptation to poke around other people's vimrc and copy all the "cool sounding" stuff they've added. This will only, I find, impede your understanding of vim because you'll be changing a lot of things without understanding them.


By way of example, I've been using vim pretty seriously for years... since about 2007 or so I guess? My vimrc is still not very complex.


I get the appeal of a homogenized work environment across all platforms, but honestly even with vim it's hard to achieve. If you use C++ at all, for example, getting sane code completion via YouCompleteMe or similar involves a fair bit of work on Windows (even on OS X it's a bit of a pain, to the point where I don't really bother with it). I'd say you'd be better off using the "typical" tools of the platform and trying to adapt them towards a common workflow rather than dumping everything out and trying to do it all with vim. vim is just a text editor, although a powerful and extensible enough one that you can hack up a pretty decent approximation of an IDE. It will never be a true IDE through. You may want to look at emacs.

#5197907 C++ Number guessing

Posted by Josh Petrie on 12 December 2014 - 08:04 PM

A good first attempt. Here's a quick collection of things I noticed glancing through your code (and/or some suggestions for improvement).


  • #include "stdafx.h" is a Visual Studio-ism. VS's standard project templates will generate projects pre-configured to use precompiled headers. If you don't know what they are, you should opt to not allow the wizard to generate them (easiest way to is to uncheck them during creation, or check the "empty project" box instead) or disable them post-creation. Your program doesn't actually need the stdafx.h file included here anyway. It's also a good strategy in C++ to minimize the number of includes in any particular file (similarly, you don't use <string> anywhere).
  • using namespace std; can be dangerous, especially in header files (this isn't, but it's still worth noting). This is because it pollutes the global namespace and there's no way to undo it.
  • You aren't calling srand() before calling rand(), and you should.
  • You don't need to use std::endl all the time. You can just output "\n" tokens; use std::endl only when you need the output to be flushed, not just when you need a newline (generally for simple console output like this, you don't need std::endl at all).
  • You bounce between menu() and gameplay() by having those functions call each other. This will eventually (if the user plays long enough) build up a stack of function calls so deep you'll get a stack overflow and crash. Think about a way you could perhaps factor out the code controlling which mode of the game you're in to a higher-level layer so you don't have to bounce between the two functions like that.
  • What happens if the user enters, for example, the letter 'a' when you prompt for input in the menu() function? How do you think you can fix the resulting bug?
  • Your main gameplay loop is guarded by a check to see if the guessed number is the correct one. Immediately after that loop ends you make the check again. Consider how you might refactor the body of the loop (and it's guard) to avoid that; it may make for a slightly more elegant loop body.
  • How could you eliminate the global variables? While in a program of this size, it's not that big of a deal, globals tend to create maintainability problems as the complexity and size of a program increases. Thus, it's useful practice to try to eliminate even in small codebases, so you get used to the techniques and strategies involved in doing so.
  • Your comments are mechanical descriptions of what the code does, which anybody reading the code can tell already. Generally one should comment about the why of some code, not the what. Particularly it's important to comment why things that might look unusual look that way -- what the design process behind them, what were the unusual requirements, et cetera? (There's nothing in your code that necessarily needs such comments, I'm just providing advice for this point.)
  • Your random number is going to be between 0 and RAND_MAX, which is at least 32767. You may want to consider reducing the range of that number, and it's also nice to perhaps tell the player what that range actually is. Otherwise the game is basically unwinnable. 

#5197872 Where to go from here?

Posted by Josh Petrie on 12 December 2014 - 04:13 PM

I know little c++ i´ve been learning all syntax difference from other languages that i´m comfortable with and i´ve understood the basics and how c++ works(i hope) but, never made nothing with it  only console based little scripts such as hello world, testing loops, and functions, cout and cin etc...
I´m thinking this could be my starting point to make a game outside flash, but i don´t understand how graphics work here on c++, i ´ve read some articles about libs but i´m completly new to this and i´m confused.



You aren't ready for graphics with C++. Little "scripts" (we generally call them programs in C++) printing text and running some loops don't provide a sufficient background in the conceptual that you'll need before embarking on getting a window open, handling events, rendering into it, et cetera (all of which requires external libraries and knowledge of more than the trivialities of C++).
If you want to continue to pursue C++ as a language for building games, the next step you should take is another incremental one: make a game with only the knowledge of C++ you have.
The typical thing I recommend is to create a "guess-the-number" game. This can be done with only text-based input and output, and there are a lot of interesting things you can explore with it to stretch your C++ (specifically) and software development (generally) muscles. For example, a basic version of the game uses a fixed, hard-coded number. A more complex one generates the number randomly. Ever more complex is to limit the number of guesses, or to give the user hints about how close they are to the proper guess. 
Beyond guess-the-number might be hangman, a slightly more complex game that involves the tracking of much more state across multiple frames of the game. If you can build those, I would suggest doing so and then posting the implementation on this forum (in a new thread, please) for review and critique. Once you feel comfortable with that, you can move on to 2D graphics by using a library like SMFL to get a basic window open and rendering.

#5197700 Seperating Logic and Data

Posted by Josh Petrie on 11 December 2014 - 06:45 PM

It is fairly common, but the precise method by which it is done varies. There are a lot of ways you can do this.


They all boil down to putting the data in question in files that *aren't* compiled source code, though. You don't *need* to use a scripting language, you can put all your configurable constants in a simple text file, where each line is a constant name and value:


Then you load this text file at startup, read the values, stuff them into appropriate variables and reference those variables everywhere else.


If you want to fancy, you can implement change notifications by using the file system observer APIs of your operating system to tell you when the file changes, and then reloaded the file and re-assigning the values whenever that happens.


You can start with something as simple and basic as the above and expand on it as necessary.

#5197651 Text Based RPG help

Posted by Josh Petrie on 11 December 2014 - 01:48 PM

Please don't expect people to download your entire project to debug it for you. It's rude.


When you are asking for help, it also helps to post the exact, complete error message you're getting as well (and especially with C++, make sure it's the first error, as often later errors are caused by the first error because parsing C++ is hard). In this case, the number (LNK2109) is sufficient for me to tell what the error generally is (via the documentation). But not the specifics.


What this linker error means is that you've declared the existence of some symbol (typically a function), but never defined it. Thus, when the linker goes to assemble all the separate object files complied from your C++ code, it cannot find the definition of function you're calling (or in general, the symbol you are referring to).


What is the specific unresolved external symbol the error is referring to? And where in your code have you defined it?

#5197629 Atomic components in ECS

Posted by Josh Petrie on 11 December 2014 - 12:03 PM

But how would you address having multiple components of the same type representing different things?



Ideally, don't. Generally, I find that such a need suggests that one is modelling components at too granular a resolution, resulting in a system where you have basically replaced member variables with components, introducing rather significant complexity and overhead for no particularly good reason.


If you must, however, there are two points to consider:


  • Having multiple instances of components with the same type doesn't always mean you have to be able to individually query for each one. Typically, a well-performing component-based entity-system will use an outboard approach where so-called "systems" are the authoritative containers for all component instances and process/update them all in bulk (rather than the more naive, cache-inefficient 'for each entity, for each component therein, update' approach). In this system it doesn't necessarily matter if an entity has two components of the same type since they are all still processed.
  • If you really, really have to have multiple instances and refer to them directly (for example, you have to call GetComponent(...) to read a bunch of data from it inside some script somewhere) you have no real choice but to support discriminators of some form. A name is the typical way to do this (but ideally you'll hash this name or somethign to avoid constant string-based searches for components, which can have a noticeable impact on your performance).


The thing is, if you're at the point where you need to have named discriminators for components, what do you have? What, precisely, is the different between having two Point components (one called Position, the other called TargetPosition) and having a single structure (perhaps called TrackingComponent) with Position and TargetPosition members? When you get to this level of granularity you have usually started to replace member variables with components, which is not super efficient. It would almost certainly(*) be better to make the component a broader package of data and/or behavior (depending on what your components model). 


(*) I will concede that there are scenarios where this can be acceptable, but they are reliant on specifics that you have not provided in your discussion thus far.

#5197616 Atomic components in ECS

Posted by Josh Petrie on 11 December 2014 - 11:15 AM

I would go with the second option. The first option is fine although if you find yourself repeating yourself often, in terms of the declaration of the members or the functions operating on them, that's a classic scenario for when you may want to move to a more encapsulated representation (the Point structure).


The third option seems downright ridiculous and reeks of the over-granularized, over-zealous "make everything a component zomg!" attitude that often comes with trendy overthought designs like the "component-based entity system."

#5197610 Need Guidance and Advice

Posted by Josh Petrie on 11 December 2014 - 10:51 AM

do you know any online schools that provide certification



Be careful. If you went back to school you'd want a degree. This is different than "certification," which is often used in to refer to brief courses that give you, for example "Microsoft Blah Blah Blah Certification." These are almost completely useless in the industry.



Also on a complete sidenote, is C# a good place to start learning code? 




 I've always had a vision that I would love to work as a person who has the overall idea for a game, writes out the script and then works with the programmers to get it realized 



The job you are describing basically does not exist, unless you are running your own company and can do whatever you want.

#5197476 Nothing is drawn with gcc compiled application

Posted by Josh Petrie on 10 December 2014 - 05:48 PM

Any number of things could be causing this. You're going to have to do a little more digging and come back with some specifics.

#5197424 Need Guidance and Advice

Posted by Josh Petrie on 10 December 2014 - 12:34 PM

Can someone with no programming knowledge pick this up



Someone with no programming knowledge can certainly to program.


However, someone with no programming knowledge is totally unqualified for a position as a programmer in the industry. It will be a long time before you acquire the relevant knowledge and ability to be considered even minimally qualified for an entry-level programming position. Consider this: such positions are often filled by recent college graduates who by then have probably had at least four years of practice programming things.



You might be better served looking for a different path into the industry. For example, as a designer you won't necessarily be expected to have programming skills. You'll still be lacking in experience which will put you at a competitive disadvantage, but design positions are often filled with people from varying background (because they bring a useful variety of skills). 


If you want to learn to program, pick a language like C# or Python and start learning it. There's a lot of good information and guides about both out there; C# may be the better choice (even though I typically recommend Python) as you could, once you get a basic handle on the language and the concepts of programming, start using Unity to build some games (Unity uses, among other options, C# to drive game-specific behavior).

#5197316 I understand the language... I just have trouble implementing it into a game...

Posted by Josh Petrie on 09 December 2014 - 09:38 PM

I think it's essential that you find open source game projects for you to study. 

They might not even illustrate the best coding practices, but they will show you a way.



I don't think this is good advice at all.


Reading and comprehending source code is a skill on it's own, and requires a reasonable understanding of the structure of a program and conventions of the language. In this case the OP is unable to grasp enough of that structure or those conventions to articulate his own ideas in a tangible form via a programming language; looking at what others have done (without context for why) is not going to make that any easier. 


Plus, since the context for decisions is not provided with most source code, it's very easy to pick up extremely bad habits this way.


Not to mention that any of the 'open source game projects' the OP is likely to find via his or her local search engine of choice are almost certainly going to be well beyond the threshold of complexity he or she should be staying in.