Visual Basic.Net Games Tutorial

Visual Basic.Net Games Tutorial thumbnail
VB is well suited for writing children's games.

Visual Basic (VB) is one of the primary languages used to develop applications in Microsoft's .NET code library. Though most programmers choose to write games in C++ rather than VB, VB programmers can nevertheless take advantage of Microsoft's XNA Game Studio to create sophisticated games, or even create them in Visual Studio. Games created in VB within the XNA environment can run on a Windows desktop computer or on a Windows Phone 7 device. VB programmers may wish to explicitly manage memory when writing games, a task that is only rarely necessary in other VB applications.

Things You'll Need

  • Visual Studio
Show More

Instructions

    • 1

      Open XNA Game Studio 4.0 or Visual Studio and begin a new VB Windows game project.

    • 2

      Add a graphic, called a sprite, for your computer to draw on the screen. Pick a classic hero character, such as an alien or a cartoon person and upload it in .jpg or .bmp format. Add the file to Visual Studio's Content file by right-clicking on it and selecting "Add" and then "Existing Item" from the menus that appear. Repeat this process to add two or three enemies that you will program to kill the character.

    • 3

      Add a timer to the game, and create a method called "Tick()" and set it to fire every 30 milliseconds. If you're using XNA, you might prefer to use the "GameTime" class.

    • 4

      Create a method called "GameProcess" that responds to keystrokes and subscribe it to the "tick" event so that it executes every 30 milliseconds. Detect each keystroke and analyze the event parameter to detect the precise keystroke entered by the user. Within the method, use a switch statement that will move the sprite up if the user presses the up key, down if he presses the down key and so on for the other directional keys. With each keystroke, record and alter the position of the sprite.

    • 5

      Add enemy movements to the "tick" event within the "GameProcess" function. Move the enemy pictures randomly using an instance of the "Random" class. Each time an enemy moves, record its position and see if its position mirrors the position of the hero character. If the enemy and hero character are in identical positions, run a "KillCharacter()" method that positions the characters at their starting points.

    • 6

      Give the hero three lives. Each time the "KillCharacter()" method executes, subtract a life. End the game when the integer representing the hero's lives reaches zero.

Related Searches:

References

  • Photo Credit Creatas/Creatas/Getty Images

Comments

Related Ads

Featured