LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Making something in a Pict Array move automatically

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

0 Kudos
Message 1 of 2
(2,562 Views)

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.

  • Use the Error Line to explicitly "serialize" those parts of your code that are serial in nature.
  • Try to keep wires straight and horizontal.
  • Keep Block Diagrams small (fit onto a single screen).
  • Make use of sub-VIs (a lot) to "keep diagrams small" (a 32 x 32 pixel sub-VI, particularly with a self-documenting Icon, can replace a 400 x 400 pixel chunk of code).
  • An example of a sub-VI begging to be written is "Choose N", which takes in N and returns a Random Integer in the range 0 .. N-1.  Use NI Best Practice when creating sub-VIs -- use the default 4-2-2-4 Connector Pane, use two lower corners for Error In and Error Out, create an Icon, even if only a White Box with the words "Choose N" inside.
  • -- create a "Choose" sub-VI that takes an I32, "N" as an input and returns a "Random Integer" in the range 0 .. N-1.  "Best Practice" for sub-VIs is to use the 4-2-2-4 (default) Connector pattern, make the lower left Error In, the lower right Error Out.  

     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).

Enum Use.png

 

     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

0 Kudos
Message 2 of 2
(2,548 Views)