Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Programming language: Pseudocode

In my program there will be (among others) two variables, called varX and varY. They will have only positive values, but they may be of varying length. They will represent the players position. When the player says that he wants to go 1 left, the program should check first if varX = (varX + 1),varY is an obstacle.

So I had thought that there would be a file containing all the impassable coordinates. Is there any way of having a file that can be read or written to very fast, containing the values for varX and varY that are obstacles? Something like a file full of paired numbers representing coordinates, in which the program would search, and if a pair in the file would be similar to varX + 1 varY (for 1 left move), then the program would not allow the player to move there.

What bothers me is that entities in the game that would move would be unpassable, too, so their new position coordinates should be added to the file, whilst their previous position, currently freed up, should be erased from the file...

Well, I hope you understand me, for I am as bad at explanations as it gets.

share|improve this question

closed as not a real question by Byte56, Nathan Reed, Sean Middleditch, bummzack, Josh Petrie Mar 29 '13 at 14:36

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

I'm voting to close as not a real question, only because you're pretty far off track. I think you should start with some basic tutorials on programming, then move on to basic game tutorials. You shouldn't be doing those checks in a file, this is what RAM is for. Create a data structure to hold your world information in memory and check against that. – Byte56 Mar 28 '13 at 2:50
Try to use descriptive names for your variables. You may come back to your code later and give yourself a headache! – Brian Butterfield Mar 28 '13 at 9:13
My worst problem is being misunderstood because of incorrect use of English, which by the way is not my mother tangue, so I cannot express my self clearly enough – Epimetheus98 Mar 31 '13 at 11:11
up vote 0 down vote accepted

You could:

  • Include a file (header or language files of sorts .c or .cpp or whatever else) EDITED (Scratch that header part unless only for the impassable areas)

  • In that file, have a 2 dimensional array (like so: [varX][varY] ) and use that for the impassable area. (You should be able to work from there, but ask if you can't)

  • Have another 2 dimensional array and use that for the x,y of enemies or characters, and have that be changed from some kind of function or procedure. Then "if x,y of char is at x,y of obstacle, don't allow to go forth". Keep doing this for multiple enemies or characters.

My take on your problem, in a nutshell.

share|improve this answer

First of all: Do not use files in a game in such a way you are currently trying to. Short explanation why not: Let's say your player moves one field in one frame and three of your other entities move one field in the same frame. Then you would need to open and read the file four times. Additionally you would also write in this file as the three entities move to another field. So new fields are impassable while others turn passable. It does not matter which file type you would use, the problem would be the same: Reading from a HDD is always much slower than reading from RAM.

What you actually could be looking for are tilemaps. They are just simple 2D arrays, in the simplest way telling you which positions are passable and which are not. You could store them in a file and read the file when your game starts. Then while the game is running, you can hold the information from this file in a tilemap (so just a 2D array) and update it easily every time an entity moves to a new field. Because then you only need to change the old position of the entity in the map to passable and the new to impassable. This is way faster and more flexible than reading a file every time something moves.

share|improve this answer

I don't know if you are talking about 2D or 3D. I have made a labyrinth console based game. If you can get the chest, than there is route to it.

Simply put, in 2D you don't want to use diagonal collisions (for my example).

If you are talking about the file you want to include, use a header file.

I read something, about freeing the position and that logically is during run-time. You have to use a pointer!

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.