Check box, Radio button, and Group box in Visual F#'s Windows Form Application

One of the most commonly used form controls in real-life application is the check box. A check box is a control that allows user to select various options from a group of options. To create a check box in Visual F#, use the following syntax:

let checkboxobjvariable=new CheckBox()

For instance:
let chk=new CheckBox()
Some of the essential properties of check box are Text and Checked. The Text property enables user to add a text beside a check box while the Checked property checks or unchecks a check box and can handle the boolean value true or false. Visual F#’s check box shares the same properties with the check boxes in other visual programming languages such as Visual C++, Visual J# and Visual Basic, so if you want to learn its other properties, check the check box properties of other visual programming languages.

Radio button of the other hand, is the complete opposite of check box for the fact that it only allow a single selection among a list of options. To change the text beside the radio button, use the Text property. It also has a Checked property which enables user to tick or untick the radio button.

To create a radio button, use the following syntax:
let radiobuttonobjvariable=new RadioButton()
For example:
let rdo=new RadioButton()
To group check boxes and radio buttons, a control called group box is used. Though there are several properties of radio buttons, the most frequently used is the Text property and is used to change the group box header text. To create a group box, use the following syntax:
Let groupboxobjvariable=new GroupBox()
For instance:
Let grp=new GroupBox()
Let’s now use the check box, radio button, and group box in a single application. Just follow these steps:

1. Click Start>All Programs>Microsoft Visual Studio 2008>Microsoft Visual Studio 2008.

2. Click File>New>Project>Select Visual F# in the project types>Select F# application in the Visual Studio installed templates category.

3. Click the Project menu>Add reference>Click the .Net tab>Locate then double-click System.Windows.Forms.
Do step 3 again and this time, select System.Drawing

4. Enter the following code after the line “// Learn more about F# at http://fsharp.net “:
// Learn more about F# at http://fsharp.net
//use the Visual F# library
open System
//use System.Drawing
open System.Drawing
//specifies the location of the Form classes
open System.Windows.Forms
//creates a form named cnbform and assign a “Use Radio Button” caption to it
let cnbform=new Form(Text="Use Radio Button",StartPosition=FormStartPosition.CenterScreen,AutoScaleMode=AutoScaleMode.Font)
//creates a group box and sets its header text to “RadioButtons”
//Use the Top and Left properties to align it in the form
let gbox1=new GroupBox(Text="RadioButtons", Location=new System.Drawing.Point(10,5),Height=80)
//creates a radio button and change its text to “First radio button”
//Use the top and left property to align it in the group box
let radio1=new RadioButton(Text="First radio button", Location=new System.Drawing.Point(20,20),AutoSize=true)
//creates radio button and set its text to “Second radio button”
//Use the autosize property to automatically expand the width of text handler
let radio2=new RadioButton(Text="Second radio button", Location=new System.Drawing.Point(20,40),AutoSize=true)
//creates a group box and set its text to “CheckBoxes”
//position the group box in the form by using the Top and Left properties
let gbox2=new GroupBox(Text="CheckBoxes",Height=80, Location=new System.Drawing.Point(10,100))
//creates a check box and change its text to “First checkbox”
//Use the top and left property to align it in the group box
let check1=new CheckBox(Text="First checkbox", Location=new System.Drawing.Point(20,20),AutoSize=true)
//creates another check box and change its text to “Second checkbox”
//Use the top and left property to align it in the group box

let check2=new CheckBox(Text="Second checkbox", Location=new System.Drawing.Point(20,40),AutoSize=true)
//creates a button and set its text to “Exit”
let exitbutton=new Button(Location=new System.Drawing.Point(200,200),Text="Exit")

//displays the first group box into the form
cnbform.Controls.Add(gbox1)
//adds the radio buttons into the groupbox
gbox1.Controls.Add(radio1)
gbox1.Controls.Add(radio2)

//adds the second group box into the form
cnbform.Controls.Add(gbox2)
//displays the checkboxes into the second groupbox
gbox2.Controls.Add(check1)
gbox2.Controls.Add(check2)

//inserts the exit button into the form
cnbform.Controls.Add(exitbutton)
//attach a click event to the first radio button then assign a function to it
radio1.Click.Add(fun r1msg->
//check the first checkbox
check1.Checked<-true
               //unchecks the first checkbox
                check2.Checked<-false)

//attach a click event to the first radio button then assign a function to it

radio2.Click.Add(fun r2msg->
//check the second checkbox
check2.Checked<-true
              //unchecks the first checkbox
              check1.Checked<-false)
//quits the form when the exit button is clicked                 
exitbutton.Click.Add(fun bact->cnbform.Close())    
//shows the form       
cnbform.Show()
//runs the application
Application.Run(cnbform)
5. Lets view of our again once again and this time, comments omitted:

// Learn more about F# at http://fsharp.net
open System
open System.Drawing
open System.Windows.Forms
let cnbform=new Form(Text="Use Radio Button",StartPosition=FormStartPosition.CenterScreen,AutoScaleMode=AutoScaleMode.Font)

let gbox1=new GroupBox(Text="RadioButtons", Location=new System.Drawing.Point(10,5),Height=80)
let radio1=new RadioButton(Text="First radio button", Location=new System.Drawing.Point(20,20),AutoSize=true)
let radio2=new RadioButton(Text="Second radio button", Location=new System.Drawing.Point(20,40),AutoSize=true)

let gbox2=new GroupBox(Text="CheckBoxes",Height=80, Location=new System.Drawing.Point(10,100))
let check1=new CheckBox(Text="First checkbox", Location=new System.Drawing.Point(20,20),AutoSize=true)
let check2=new CheckBox(Text="Second checkbox", Location=new System.Drawing.Point(20,40),AutoSize=true)

let exitbutton=new Button(Location=new System.Drawing.Point(200,200),Text="Exit")


cnbform.Controls.Add(gbox1)
gbox1.Controls.Add(radio1)
gbox1.Controls.Add(radio2)

cnbform.Controls.Add(gbox2)
gbox2.Controls.Add(check1)
gbox2.Controls.Add(check2)

cnbform.Controls.Add(exitbutton)

radio1.Click.Add(fun r1msg->
check1.Checked<-true
                    check2.Checked<-false)
radio2.Click.Add(fun r2msg->
check2.Checked<-true
                    check1.Checked<-false)
                    
exitbutton.Click.Add(fun bact->cnbform.Close())           
cnbform.Show()
Application.Run(cnbform)

6. Click the run icon to execute your application. You should now see an output similar to the following screen shot:

Add Two Numbers (Visual F# Windows Forms Application)

I’d been desperately combing the net for a while now looking for some tutorials relating to simple computations in Visual F# Windows Forms Application unfortunately I got no fluke finding some so I decided to make one. Today we will be making a simple application that adds two numbers and I hope that this will give you a head start in building advanced application using F# Windows Forms.
To create an application that adds two numbers, follow these simple steps:

1. Click Start>All Programs>Microsoft Visual Studio 2008>Microsoft Visual Studio 2008.

2. Click File>New>Project>Select Visual F# in the project types>Select F# application in the Visual Studio installed templates category.

3. Click the Project menu>Add reference>Click the .Net tab>Locate then double-click System.Windows.Forms.
Do step number 3 again and this time,select System.Drawing

4. Enter the following code after the line “// Learn more about F# at http://fsharp.net “:

// Learn more about F# at http://fsharp.net
//uses the F# standard library
open System
//specifies the location of the Drawing classes
open System.Drawing
//specifies the namespace memory location of the form class
open System.Windows.Forms
//creates a new form
let addform=new Form(Text="Add Numbers", Size=new System.Drawing.Size(300, 200),StartPosition=FormStartPosition.CenterScreen,AutoScaleMode=AutoScaleMode.Font)
//creates a label
let n1label=new Label(Text="First number:",Top=20,Left=5,AutoSize=true)
let firsttextbox=new TextBox(Location=new System.Drawing.Point(80, 20))
//creates another label and change its text to “Second number:”
let n2label=new Label(Text="Second number:", Location=new System.Drawing.Point(0,50),AutoSize=true)
let secondtextbox=new TextBox(Location=new System.Drawing.Point(100,50))
//creates another label and change its text to sum
let n3label=new Label(Text="Sum:", Location=new System.Drawing.Point(0, 90),AutoSize=true)
//creates a label that will display the result of the computation
let anslabel=new Label(Location=new System.Drawing.Point(80, 90))
//make our buttons
let addbutton=new Button(Text="Add", Location=new System.Drawing.Point(100, 130))
let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(200, 130))
//add the controls into the form
addform.Controls.Add(n1label)
addform.Controls.Add(firsttextbox)
addform.Controls.Add(n2label)
addform.Controls.Add(secondtextbox)
addform.Controls.Add(n3label)
addform.Controls.Add(anslabel)
addform.Controls.Add(addbutton)
addform.Controls.Add(exitbutton)

//when the add button is clicked
addbutton.Click.Add(fun addfunction ->
//convert the textbox values to unsigned int
let firstnum=Convert.ToUInt32(firsttextbox.Text)
let secondnum=Convert.ToUInt32(secondtextbox.Text)
let sumval=firstnum + secondnum
//display the sum in the anslabel
anslabel.Text<-Convert.ToString(sumval))
 //when the exit button is clicked, close the form            
exitbutton.Click.Add(fun exit -> addform.Close())  
addform.Show()
Application.Run(addform)

6. Press Ctrl+F5 or click the run icon to execute your application. You should now see something similar to the screenshot below:



7. That's all. Enjoy programming!

Fixing the “Fatal Error: Call to undefined imagecreate() function” in PHP

The "call to undefined imagecreate() function" normally appears if you try to execute graphic related scripts such as CAPTCHA scripts. To fix this problem, follow these simple steps:

1. Download a copy of PHP zip package from http://php.net/downloads.php.

2. For the sake of example, we will be using PHP 5.2.14 Windows Binary Zip Package.

3. Once you have downloaded the file, Right-Click it>Extract files>In the Winrar Destination path, enter “C:\PHP\” no quotes. If you have previously installed PHP distros just overwrite it.(I’ve assumed here that you have Winrar installed on your computer.)

4. Go to where your PHP file was extracted, in this case in the C:\ directory.

5. Locate php.ini-dist and rename it to php.ini.(Overwite the previous php.ini).



6. Right-click php.ini>Select Open. The following should then appear:



7. Click Edit>Select Find then enter extension_dir in the Find what textbox.



8. Change the line extension_dir=”./” to extension_dir=”C:\PHP\ext”.



9. Click Edit>Find>Enter “gd”(no quotes) in the Find what textbox then click Find Next.



10. Delete the semi-colon(;) before the line ;extension=php_gd2.dll.




11. Click File the Save. You should now be able to execute your captcha scripts without errors. Here is the screenshot of my captcha that I was able to execute effortlessly using these fixes:



12. If you continue to encounter error messages, try restarting your computer.

13. That's all. Ciao!

Changing the text color of an F# Console Application

By default, console texts are displayed in white. To change the text color, use the Console object together with its ForegroundColor Property.

Syntax:
Console.ForegroundColor<-Color value
Color values are stored in the ConsoleColor object and has the following values:

1. Black
2. DarkBlue
3. DarkGreen
4. DarkCyan
5. DarkRed
6. DarkMagenta
7. DarkYellow

8. Gray
9. DarkGray
10. Cyan
11. Red
12. Yellow
13. White
 

To assign the ConsoleColor object as a value of the Console ForegroundColor property, use the following syntax:
Console.ForegroundColor<-ConsoleColor.Colorname
For the sake of example, let us make a console application that will display the text “I am cyan” in cyan text color by following these steps: 1. Click Start>All Programs>Microsoft Visual Studio 2008>Microsoft Visual Studio 2008. 2. Click File>New>Project>Select Visual F# in the project types>Select F# application in the Visual Studio installed templates category. 3. The following should then come into view: 4. Enter the following code after the line “// Learn more about F# at http://fsharp.net “:
//Use the F# Library
open System
//assigns Cyan color to our console text color
Console.ForegroundColor<-ConsoleColor.Cyan
//Create a function named myfunction()
let myfunction()=
//adds an action to our function
//in this case, displays an "I am Cyan" text
printfn "I am Cyan"
//executes our function        
myfunction()
5. Press Ctrl+F5 to execute the console application. You should now see the following output:
6. To add a background color, you can use the BackgroundColor property of the Console object which follows the same syntax as ForegroundColor property. That’s all. Thanks!

Creating a menu system in Dark GDK

There are several ways on how to create a menu system in Dark GDK but since I hate to complicate simple things, today we will be learning the simplest. The idea is to assign a sprite as a customized mouse pointer and hide that sprite when your game is loaded using dbHideSprite so that only the mouse pointer is visible and not your customized sprite pointer. The next problem would be to test which menu item or button was clicked, to be able to do that, simply use dbSpriteHit or dbSpriteCollission to check whether your hidden sprite acting as your mouse pointer collided with your button sprite. It’s that simple. If you are confused, follow these steps:

1. Before the actual programming, draw the buttons and customized mouse pointer that will be needed in your game using your favorite image creation software such as Paint, GIMP, or PhotoShop. It does not matter how your customized mouse pointer looks like because it will not show up on your form, just make sure that you buttons and your customized pointer are of the same height and width.



2. Start Microsoft Visual C++. Click File>New>Project>Select Wizards>Dark GDK-Game>Type “Using Menu” in the name textbox no quotes.

3. Minimize the MSVC++ window then go to My Documents>Visual Studio 2008>Projects>Using Menu>Using Menu> Then paste the images that you have created in step 1.



4. Maximize Visual C++>View>Solution Explorer>Double-Click Main.cpp. The following should then come into view:
// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"

// the main entry point for the application is this function
void DarkGDK ( void )
{
 // turn on sync rate and set maximum rate to 60 fps
 dbSyncOn   ( );
 dbSyncRate ( 60 );

 // our main loop
 while ( LoopGDK ( ) )
 {
  // update the screen
  dbSync ( );
 }

 // return back to windows
 return;
}

5. Locate the line void DarkGDK ( void ) then type the following after the line dbSyncRate ( 60 );
//loads our images
dbLoadImage("hibutton.jpg",1);
dbLoadImage("exitbutton.jpg",2);
dbLoadImage("customizedpointer.jpg",3);
//displays our images
dbSprite(1,400,420,1);
dbSprite(2,500,420,2);

6.If you try to run this,only the "Say Hi" and "Exit" buttons are visible.That's because we haven't display our sprite pointer yet.To view it, locate the line while ( LoopGDK ( ) ) and type the following aster the open curly bracket:

//assigns the currentX and CurrentY position
//of our mouse an X and Y coordinate of
//our customized pointer
//we need to place it inside the
//while loop so that it is always
//updated depending on the current mouse coordinate
dbSprite(3,dbMouseX(),dbMouseY(),3);
//hides the sprite that acts as our pointer
dbHideSprite(3);

7. The next thing that we need to do is to enable our button to react to mouse click. To be able to do that locate the line dbHideSprite(3); and type the ff. below it:

//if our hidden sprite collided with the “Say Hi” button 
//and the mouse button is clicked then
if (dbSpriteCollision(3,1)==1 && dbMouseClick()==1)
{
//do something…you can add your game sequence action codes here
//but in this case we will be displaying a “Hi!” text
dbSetTextFont("Garamond");
dbSetTextSize(70);
dbText(0,0,"Hi!");      
}
//if our hidden sprite collided with the “Exit” button 
//and the mouse button is clicked then
if (dbSpriteCollision(3,2)==1 && dbMouseClick()==1)
{
//quit the form
return; 
}

8. Let us have a quick look of our codes once again:

// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"

// the main entry point for the application is this function
void DarkGDK ( void )
{
 // turn on sync rate and set maximum rate to 60 fps
 dbSyncOn   ( );
 dbSyncRate ( 60 );
 //loads our images
 dbLoadImage("hibutton.jpg",1);
 dbLoadImage("exitbutton.jpg",2);
 dbLoadImage("customizedpointer.jpg",3);
 //displays our images
 dbSprite(1,400,420,1);
 dbSprite(2,500,420,2);



 // our main loop
 while ( LoopGDK ( ) )
 {
 
  dbSprite(3,dbMouseX(),dbMouseY(),3);
  dbHideSprite(3);
  if (dbSpriteCollision(3,1)==1 && dbMouseClick()==1)
  {
   dbSetTextFont("Garamond");
   dbSetTextSize(70);
   dbText(0,0,"Hi!"); 
  }
  if (dbSpriteCollision(3,2)==1 && dbMouseClick()==1)
  {
  return; 
  }


  // update the screen
  dbSync ( );
 }

 // return back to windows
 return;
}

9. Press F5 to test your game. Try clicking the “Say Hi” and "Exit" button.



10. And that would be all. One of the first menu system tutorial in Dark GDK. My buttons looks disgusting because I just rushed it, I didn’t have time to make one in Blender. Hope you learn something from it, till next time.

A simple 2D pong game in darkGDK

In case you are wondering, Pong is a video game that simulates ping pong. It is a game where you maneuver a bat or paddle by pressing a control or joystick and the goal of the game is to return the ball to the opposing side just like the real ping pong. If you totally don't have any idea how pong works, I suggest googling it first before moving onto the next section. Being accustomed with the game and how it works greatly aids in trasforming it into codes.

Apart from familiarizing the game, we also need to learn few darkGDK game operations and the underlying commands behind them. These operations and commands are enumerated below:

1. Displaying an Image

Before you can display an image in darkGDK, you'll need to load it first into the computer memory. To be able to do that, use the dbLoadImage command which has the following syntax:
dbLoadImage("Imagefilename",imageloadid);
Where;
1. Imagefilename is an existent image file saved inside your game project folder. darkGDK supports .bmp, .jpg, and .png image file types.

2. imageloadid is a unique image numeric id that can be used later on to refer to a loaded image.

Example:
dbLoadImage("Galaxian.jpg",1);
Once an image is loaded in the computer memory, you can then display it by using dbPasteImage or dbSprite. dbSprite has the following syntax:
dbSprite(spriteid, x-coordinate, y-coordinate, imageloadid);
Where;
1. spriteid is a numerical id that can be use to manipulate the displayed image. spriteid can be identical to the imageloadid.

2. x-coordinate and y-coordinate are the x and y coordinate of the upper-left corner of your sprite or image. If you are unfamiliar of x and y coordinate, think of the screen as the fourth quadrant of the Cartesian coordinate system. The upper left corner is the origin which has the coordinate of x=0,y=0. The value of x coordinate increases as you move right. The value of the y coordinate increases as you move down.

3. imageloadid is the numeric id of a loaded image that you wanted to display.

Example:
dbSprite(1,0,01);
2. Moving Sprites

Sprites and images can be moved or animated by using dbMoveSprite or by simply incrementing or decrementing the x and y coordinate of an image. If you are familiar with java, c++, or visual basic, you probably know what I am talking about.

3. Detecting Collisions

darkGDK comes with powerful command that can be used to detect sprite or object collision. To detect collision, simply use dbSpriteCollission or dbSpriteHit. dbSpriteHit has the following syntax:
dbSpriteHit(Spriteid1, Spriteid2);
Where;
1. Spriteid1 and Spriteid2 are the numeric spriteids of the images that you wanted to test for collision.

Now that you have learned few basic commands and operations in darkGDK,I guess we can proceed into making our pong game. The following steps demonstrates how:

1. Click Start>All Programs>Microsoft Visual C++ Express Edition.

2. Click on File>New>Project. In the Project Types tree control, select on Wizards.

3. Select Dark GDK-Game from the available Game project options.

4. Type “Pong” no quotes in the Project Name textbox then Click Ok.

5. Click on View>Solution Explorer. Locate Main.cpp in the Solution Explorer Window then double-click it.

6. The following should then appear:

// Dark GDK - The Game Creators - www.thegamecreators.com   
// the wizard has created a very simple project that uses Dark GDK   
// it contains the basic code for a GDK application     
// whenever using Dark GDK you must ensure you include the header file   
#include "DarkGDK.h"    
// the main entry point for the application is this function   
void DarkGDK ( void )   
{   
// turn on sync rate and set maximum rate to 60 fps   
dbSyncOn   ( );   
dbSyncRate ( 60 );     
// our main loop   
while ( LoopGDK ( ) )   
{   
// update the screen   
dbSync ( );   
}     
// return back to windows   
return;   
}   

7. Locate the line #include "DarkGDK.h" and declare the following variables below it:
//handles the ball velocity, the larger the value 
//the faster the ball will move
int ballxvelocity=5,ballyvelocity=5;
//handles the updated x and y coordinate of the ball
int ballxcoord,ballycoord;
//handles the updated x and y coordinate 
//of player1's paddle
int bat1xcoord,bat1ycoord;
//handles the updated x and y coordinate 
//of player2's paddle
int bat2xcoord,bat2ycoord;

8. Locate the line dbSyncOn and dbSynRate(60) then type the following below it:
//sets the window title to pong
dbSetWindowTitle("Pong");
//sets the window size to 600x400 that is
//x coordinates runs from 0-600
//y coordinates runs from 0-400
dbSetWindowSize(600,400);
//loads an image located in your game project folder
//and gives it an id of 1
dbLoadImage("ball.png",1);
//loads an image located in your game project folder
//and gives it an id of 2
dbLoadImage("bat1.jpg",2);
//loads an image located in your game project folder
//and gives it an id of 3
dbLoadImage("bat2.jpg",3);

//displays the ball at the center of the screen
dbSprite(1,300,200,1);
//player1 paddle at the left side of the screen
dbSprite(2,50,150,2); 
//player2 paddle at the right side of the screen 
dbSprite(3,500,150,3);


9. Locate the line while ( LoopGDK ( ) ) and type the following after the open curly bracket:
//move the ball
//adds the value of ballxvelocity 
//and the current x coordinate of the ball
//and assign it as a new ball x coord value
ballxcoord=dbSpriteX(1) + ballxvelocity;
//do the same with y
ballycoord=dbSpriteY(1) + ballyvelocity;
//displays the ball in the updated x and y coord positions
dbSprite(1,ballxcoord,ballycoord,1);
//if the ball collides with the 
//top or bottom of the screen then
if (ballycoord <= 0 || ballycoord >= 400) 
{
//Multiply ballyvelocity by negative 1
//The result will  later on be added to the
//current y coordinate of the ball
//causing the ball to change position
//depending on the value of ballyvelocity and
//the current coord of the ball
ballyvelocity=ballyvelocity*-1;
}
//if the ball collides with the left side 
//or right side of the screen then
if (ballxcoord <= 0 || ballxcoord >= 600)
{
//Multiply ballxvelocity by negative 1
//The result will later on be added to the
//current x coordinate of the ball
//causing the ball to change position
//depending on the value of ballxvelocity and
//the current x coord of the ball
ballxvelocity=ballxvelocity*-1;
}

//check bat collision
//if the ball collides with player 1's paddle
if (dbSpriteHit(1,2)==1)
{
//if at this point you still don't 
//understand what this do
//I suggest recalling the rules in multiplying
//and adding negative numbers
ballxvelocity=ballxvelocity*-1;
}
//if the ball collides with player 2's paddle
if (dbSpriteHit(1,3)==1)
{
//reverse the direction of the ball
ballxvelocity=ballxvelocity*-1;
}

//move the player 1 bat
//if the enter key is pressed
if (dbReturnKey()==1)
{
//decrement the paddle y coord value
//causing the paddle to move up
bat1ycoord=dbSpriteY(2)-5;
//display the paddle in the
//updated position
dbSprite(2,bat1xcoord,bat1ycoord,2);
}
//if the down arrow is pressed
if (dbShiftKey()==1)
{  
//increment the paddle y coord value
//causing the paddle to move down
bat1ycoord=dbSpriteY(2)+5;
//display the paddle in its
//updated position



//move player 2 bat
//if the up arrow is pressed
if (dbUpKey()==1)
{
//decrement the paddle y coord value
//causing the paddle to move up
bat2ycoord=dbSpriteY(3)-5;
dbSprite(3,bat2xcoord,bat2ycoord,3);
}
//if the shift key is pressed
if (dbDownKey()==1)
{
//increment the paddle y coord value
//causing the paddle to move down
bat2ycoord=dbSpriteY(3)+5;
dbSprite(3,bat2xcoord,bat2ycoord,3);
}
10. Locate the line dbSync ( ); and type the following after the open curly bracket:
//Deletes the loaded image
//and sprites when the game is closed
//this will free up the used memory
for ( int i = 1; i < 30; i++ )
dbDeleteSprite ( i );
dbDeleteImage ( 1 );
11. Let's have a glance of our codes again and this time comments omitted:
// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
int ballxvelocity=5,ballyvelocity=5;
int ballxcoord,ballycoord;
int bat1xcoord,bat1ycoord;
int bat2xcoord,bat2ycoord;
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn   ( );
dbSyncRate ( 60 );
dbSetWindowTitle("Pong");
dbSetWindowSize(600,400);
dbLoadImage("ball.png",1);
dbLoadImage("bat1.jpg",2);
dbLoadImage("bat2.jpg",3);

 
dbSprite(1,300,200,1);   
dbSprite(2,50,150,2);  
dbSprite(3,500,150,3);  



// our main loop
while ( LoopGDK ( ) )
{
//move the ball
ballxcoord=dbSpriteX(1) + ballxvelocity;
ballycoord=dbSpriteY(1) + ballyvelocity;
dbSprite(1,ballxcoord,ballycoord,1);
if (ballycoord <= 0 || ballycoord >= 400) 
{
ballyvelocity=ballyvelocity*-1;
}
if (ballxcoord <= 0 || ballxcoord >= 600)
{
ballxvelocity=ballxvelocity*-1;
}

//check bat collission
if (dbSpriteHit(1,2)==1)
{

ballxvelocity=ballxvelocity*-1;
}
if (dbSpriteHit(1,3)==1)
{

ballxvelocity=ballxvelocity*-1;
}

//moves player 1 bat
if (dbReturnKey()==1)
{
bat1ycoord=dbSpriteY(2)-5;
dbSprite(2,bat1xcoord,bat1ycoord,2);
}
if (dbShiftKey()==1)
{
bat1ycoord=dbSpriteY(2)+5;
dbSprite(2,bat1xcoord,bat1ycoord,2);
}


//moves player 2 bat
if (dbUpKey()==1)
{
bat2ycoord=dbSpriteY(3)-5;
dbSprite(3,bat2xcoord,bat2ycoord,3);
}
if (dbDownKey()==1)
{
bat2ycoord=dbSpriteY(3)+5;
dbSprite(3,bat2xcoord,bat2ycoord,3);
}


// update the screen
dbSync ( );
}
for ( int i = 1; i < 30; i++ )
{
dbDeleteSprite ( i );
dbDeleteImage ( 1 );
}
// return back to windows
return;
}

12. Press F5 to test the game. You can press the Enter key and shift key to move player1's bat and the up and down arrow to move player2's bat.

13. And that's it. A very simple pong game using few lines of codes. At the point of writing I guess this was the very first pong game tutorial written using darkGDK. I will add attract mode animation, menus, scores, and AI enemy to this when I have time but for now, though it's incomplete, you can use it as starting point. Hope you'll learn something from it and enjoy the game.