01-05-2016 07:22 AM
Hi,
I'm pretty new to labview and im working on a project, making a game that is fairly similar to Pac-Man.
I've got most of the game working, but I'm not entirely sure on how to make the 'enemies' and the 'treasure' move on their own, independant of what I, the player, does - either randomly or the enemies specifically targetting the player and the treasure moving away from the player.
Also, I pull the map files out of an excel file, and I have several created. How do I make it so that a random one is chosen and used as the base to make the map?
Thank You
01-05-2016 07:55 AM
I'm not sure I understand your question. You clearly know about Random Numbers (I see you using them in your code).
Here are suggestions.
You ask how to choose a random map from your Excel file. If you have N Maps, use Choose(N) (meaning wire N to the Choose Function, see above, and use the result to "choose" which map to use). Similarly to move in a random direction, either Choose (4) (if moving up, down, left, right) or Choose (8) (if you allow diagonal moves). You'll need to decide what direction corresponds to 0 .. 3, though if you want to be more self-documenting, you could create an Enum called Direction (saved as a TypeDef) whose values are "Up", "Down", "Right", and "Left". You can convert the output of Choose(4) to an Enum using a Type Cast, as shown here -- note how it now gives you "self-documenting" Case Labels (Up, Down, Right, and Left).
I notice multiple nested loops in your program. The purpose of each loop is not at all obvious. Encapsulating a loop into a sub-VI with a self-documenting Icon would simplify the Top Level and maybe bring some clarity to this code.
If you see yourself "doing the same thing multiple times" (like in the Event Structure), it suggests trying to write code to "do it once" with input parameters deciding which path to take. Note how having a "Direction" Enum could simplify things here.
You should not need to use a Pict Map 2 Local Variable -- simply put Pict Map 2 inside the While Loop before going into the Event Case.
Clean this code up a bit and I bet it will make more sense to you.
Bob Schor