Example Code

LabVIEW Simple PONG 2 player game

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview

This example is a simple implementation of the classic game Pong. The user interface consists of an array of LEDs and a keyboard to control the position of the paddle.

 

Description

 

This example is a simple implementation of the classic game Pong. The game works on main principle that the ball has four attributes, x position, y position, x velocity and y velocity. You can move the ball with this pseudocode:

Ball x position = Ball x position + ball x velocity

Ball y position = Ball y position + ball y velocity

When the ball reaches a boundary or paddle, you can bounce the ball by changing its direction.

Ball x velocity = - Ball x velocity

Ball y velocity = - Ball y velocity

 

Requirements

  • LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Open Pong Game.lvproj
  2. Run MAIN game.vi
  3. Click run.
  4. Use the keyboard to move the paddles. Press A and D to move the player 1 paddle and LEFT and RIGHT to move player 2 paddle.

 

Additional Information or References

Front Panel

140fp.PNG

 

VI Snippet

140.png

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.