Page 1 of 1

Creating a simple game that responds off of user input Using the new Dark GDK Rate Topic: ***** 1 Votes

#1 aj32  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 30
  • View blog
  • Posts: 577
  • Joined: 30-August 07

Posted 02 February 2008 - 11:24 PM

This is a simple tutorial on how to build a simple animation using the new "Dark GDK" for Visual C++ 2008 express

Required Programs:
1. Visual Studio C++ 2008 Express
2. The "Dark GDK" add-on for VC++ 08

=============================================

After downloading and installing the dark GDK, open VC++ 08 and click "File->New->Project" (or "ctrl+shift+N").
Under project types, click "Wizards".
Select "Dark GDK - 2D Game", name the project something like 'Dark GDK - 2D Game1", select the folder in which you want your project to be stored in, and click "OK".
Now, under solution explorer, click "main.cpp".
There will already be a neat little bit of code there and if you run it (ctrl+F5) a neat animation will be displayed!

Now for the editing:

1. Let's edit the code that places the object at a random location, find this code
	for ( int i = 2; i < 30; i++ )
	{
		// create an animated sprite and give it the ID number from the
		// variable i, next is the filename, now we come to how many frames
		// across and down, in our case this is 4, finally we come to the image
		// ID that the sprite will use, again we use i
		dbCreateAnimatedSprite ( i, "sprite.bmp", 4, 4, i );

		// position our sprite at a random location
		dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i );
	}

and change it to:
int i = 2;
	
		dbCreateAnimatedSprite ( i, "sprite.bmp", 4, 4, i );

		// position our sprite
		dbSprite ( i, 100 , 100, i );



The code will now display 1 object and it will fall to the bottom of the screen.

2. Now, we will make the object work off of user input.

-Find this code:
	// now we come to our main loop, we call LoopGDK so some internal
	// work can be carried out by the GDK
	while ( LoopGDK ( ) )
	{
		// run a loop through all our sprites
		for ( int i = 2; i < 30; i++ )
		{
			// move the sprite down and play its animation
			// moving from frame 1 to 16 with a delay of 60 ms
			dbMoveSprite ( i, -2 );
			dbPlaySprite ( i, 1, 16, 60 );

			// check the position of the sprite, if it has gone off scren
			// then reposition it back to the top
			if ( dbSpriteY ( i ) > 500 )
				dbSprite ( i, dbRnd ( 640 ), -dbRnd ( 1500 ), i );
		}

		// here we check if the escape key has been pressed, when it has
		// we will break out of the loop
		if ( dbEscapeKey ( ) )
			break;

		// here we make a call to update the contents of the screen
		dbSync ( );
	}



and replace it with this code to make it work off of user input:
		//NOW: let's make our sprite move on user input!//
		int SDS = 1;
	while ( LoopGDK () )
	{
		  if(dbControlKey()) //Toggle constant animation on\off//
		  {
			  if(SDS == 1)
			  {
				  SDS = 2;//animation is off
			  }
			  else
			  {
				  SDS = 1;//animation is on
			  }
		  }

		  if(SDS == 1)//check to see if animation is toggled
		  {
			  dbPlaySprite ( i, 1, 16, 60 );
		  }

		  if(dbDownKey())//do something on user input
		  {
			dbMoveSprite ( i, -2 );
			dbPlaySprite ( i, 1, 16, 60 );
		  }
		  if(dbUpKey())//do something different on different user input
		  {
			dbMoveSprite ( i, 2 );
			dbPlaySprite ( i, 1, 16, 60 );
		  }
	
		// here we check if the escape key has been pressed, when it has
		// we will break out of the loop
		if ( dbEscapeKey ( ) )
			break;

		// here we make a call to update the contents of the screen
		dbSync ( );
		  }






3. Test the application:

press [Ctrl]+[F5] to run the program.

Now, the program should display something like this:

Attached File  bitmap.bmp (991.74K)
Number of downloads: 4361

=============================================

Congrats! You can now control what the object does!
Pressing the up and down arrows will move it on the screen and pressing [Ctrl] will toggle the animation!

Other controls can be added, such as useing dbLeftKey & dbRightKey.


=============================================

I hope this tutorial is helpful, it's the first one I have done. There are probably some errors in it, let me know if there are.

---------------------------------------------------------------------------------

-aj32 :)

This post has been edited by aj32: 09 February 2008 - 10:42 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Creating a simple game that responds off of user input

#2 brandon99337  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 167
  • Joined: 14-February 08

Posted 21 February 2008 - 05:29 PM

Awesome, No Errors And I Finally UnderStand It... Thanks!
Was This Post Helpful? 0
  • +
  • -

#3 Racso_the_great  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-August 08

Posted 17 August 2008 - 12:45 PM

How do you make the sprite go right? :blink:
Was This Post Helpful? 0
  • +
  • -

#4 zGoDLinGz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-November 08

Posted 21 November 2008 - 09:43 PM

I have Visual C++ 2008 Express Edition
(does it work with express edition? if not could u plz tell me wat does?)
Please help me i have downloaded everything but when i am installing the GDK download it says
"Error attempting to read from the source install database:
C:\WINDOWS\Installer\65efb8.msi."

thats what it says and pease reply me as soon as possible i really want to get started on making games
it looks really fun

please please help me if ANY help at all i will appreciate it very very much
!!!!

This post has been edited by zGoDLinGz: 21 November 2008 - 09:45 PM

Was This Post Helpful? 0
  • +
  • -

#5 1Timmy  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 35
  • Joined: 25-February 10

Posted 26 February 2010 - 03:20 PM

Dark GDK does work with Visual C++ expreess.
Ihave put it on two different computers,on one it works,
onthe other it has the same problem.
Was This Post Helpful? 0
  • +
  • -

#6 ModusOne  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 10-June 13

Posted 05 August 2013 - 08:47 AM

i have two points to make because I'm pretty new to game this.

1.
What does -
dbPlaySprite ( i, 1, 16, 60 ) mean?

2.
When you write the code for left and right controls is there some sort of XY direction arrangement like;
 if(dbLeftKey())
	  {
                                         
            dbMoveSprite ( i , 1, -2);  // (i, X, Y );
            dbPlaySprite ( i, 1, 16, 60);
          }




Thanks, and great tutorial.
Was This Post Helpful? 0
  • +
  • -

#7 Evil Overlord  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 11-February 14

Posted 15 February 2014 - 08:09 AM

Can this game be coded on "Codeblocks" compiler... and if so, how do you proceed?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1