The code from Clbembry, is alright too.. but i will give another example that also move down/up, which also checks for screen boundaries.
// Move sprite Left/Right and Up/Down
// Author: Yerrel
// Web-site: www.binary-coder.com
#include "DarkGDK.h"
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 0 );
// Declare the Start positions for X and Y, position it @ the center of the screen
int pos_x = dbScreenWidth() / 2;
int pos_y = dbScreenHeight() / 2;
int speed = 4;
// Creat a Cube to use as a sprite
dbInk(dbRgb(255, 255, 0),0); // Use yellow color for the cube
dbBox(0, 0, 16, 16); // Draw a cube with size: 16 x 16 pixels
dbGetImage(1, 0, 0, 16, 16); // Grab the box as Image
dbCLS(); // Clear the screen
// our main loop
while ( LoopGDK ( ) )
{
// Move right/left and check screen boundaries
if( dbRightKey() && pos_x < dbScreenWidth()-16)
{
pos_x = pos_x + speed;
}
if( dbLeftKey() && pos_x > 0)
{
pos_x = pos_x - speed;
}
// Move Up/Down and check screen boundaries
if( dbUpKey() && pos_y > 0)
{
pos_y = pos_y - speed;
}
if( dbDownKey() && pos_y < dbScreenHeight()-16)
{
pos_y = pos_y + speed;
}
dbSprite( 1, pos_x, pos_y, 1 );
// update the screen
dbSync ( );
}
// return back to windows
return;
}
MSI K8T NEO-2 F2.0, 8XAGP, 2x512Mb Dual Channel... Dark GDK..... http://www.binary-coder.com