I used both and could not get either to work. I am not sure what other code i should post. Its in a loop it should work fine. Here is my entire code. its not to long at the moment.
#include "DarkGDK.h"
#include <stdio.h>
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbDisableEscapeKey ( );
dbRandomize ( dbTimer ( ) );
// Setup the backdrop for are game
dbLoadImage ( "backdrop.bmp", 1 );
dbSprite ( 1, 0, 0, 1 );
// Make yellow transparent on sprites
dbSetImageColorKey ( 255, 255, 0 );
// Create the game sprites, such as the paddle and the ball.
dbCreateAnimatedSprite(2,"paddle.bmp",1,4,2);
dbCreateAnimatedSprite(3,"ball.bmp",1,1,3);
// Declare are Shiz
int Score, AiScore, playerx, playery, compx, compy, ballx, bally;
byte ballmove, PlayerSpeed, CompSpeed, BallSpeed;
PlayerSpeed = 5; CompSpeed = 5; BallSpeed = 2;
ballmove = 0; Score = 0; AiScore = 0; playerx = 280; playery = 450; compx = 280; compy = 15; ballx = 300; bally = 230;
// Set initial bar movement direction
ballmove = dbRnd(3);
while ( LoopGDK ( ) )
{
dbOffsetSprite ( 2,playerx + 50, playery ) ;
// Draw Sprites first so text will show up
dbDrawSpritesFirst();
// Put a period on paddle position and ball position useful for debugging
dbText ( playerx, playery, ".");
dbText ( compx, compy, ".");
dbText ( ballx, bally, ".");
// Set up Text
dbSetTextFont("Trajan Pro");
dbSetTextToBold();
dbSetTextSize (22);
// Draw Score
dbInk(dbRgb(255,0,0),0);
dbText (5,5,"Player1:");
dbText (90,6,dbStr(Score));
dbInk(dbRgb(0,255,0),0);
dbText (5,20,"Computer:");
dbText (115,20,dbStr(AiScore));
// Make Text Red
dbInk(dbRgb(255,0,0),0);
// show fps
dbText( 555 , 5, "FPS: " );
dbText ( 600, 5, dbStr(dbScreenFPS()));
// Show Curser Position
dbText( 555 , 20, "M X: " );
dbText( 555 , 35, "M Y: " );
dbText ( 600, 20, dbStr(dbMouseX()));
dbText ( 600, 35, dbStr(dbMouseY()));
// Show the Players Paddle Position
dbText( 555 , 50, "PP: " );
dbText ( 600, 50, dbStr(playerx));
// Show the ball Position
dbText( 555 , 65, "Ball: " );
dbText ( 600, 65, dbStr(ballx));
// When user presses Left on the Keyboard and make sure the paddle position doesnt go off the screen.
if (dbLeftKey() == 1 && playerx > 0)
{
dbSprite ( 2, playerx = playerx - PlayerSpeed, playery, 2 );
}
// When user presses Right on the Keyboard and make sure the paddle position doesnt go off the screen.
if (dbRightKey() == 1 && playerx < 550)
{
dbSprite ( 2, playerx = playerx + PlayerSpeed, playery, 2 );
}
// Computer Movement Crappy Ai code
if (ballx > compx)
{
dbSprite ( 2, compx = compx + CompSpeed, compy, 2 );
}
if (ballx < compx)
{
dbSprite ( 2, compx = compx - CompSpeed, compy, 2 );
}
// If the ball Collides with a paddle
if (dbSpriteCollision(3,2) == 1 || dbSpriteCollision(2,3) == 1)
{
// Detect which paddle it hit
if (bally > 400) // Hit Players Paddle so only move the ball up
{
// Move ball in a random direction but only up.
ballmove = dbRnd(1);
}
// Detect which paddle it hit
if (bally < 70) // Hit Computers Paddle so only move the ball up
{
// Move ball in a random direction but only Down.
ballmove = dbRnd(3);
// If its going to randomize a number to make it move up then reset it.
if (ballmove == 0) {ballmove = 2;}
if (ballmove == 0) {ballmove = 3;}
}
}
// If the ball Collides with a wall || means or
if (ballx < 0 || ballx > 600)
{
// Check what direction the ball is moving in. So the direction isnt back the way it came
if (ballmove == 1 || ballmove == 0) // Ball is moving up
{
// Hit the left wall. So only bounce Right and Up
if (ballx < 0)
{
ballmove = 0;
}
// Hit the Right wall. So only bounce Left and Up
if (ballx > 640)
{
ballmove = 1;
}
}
// Check what direction the ball is moving in. So the direction isnt back the way it came
if (ballmove == 2 || ballmove == 3) // Ball is moving down
{
// Hit the left wall. So only bounce Right and Down
if (ballx < 0)
{
ballmove = 2;
}
// Hit the Right wall. So only bounce Left and Down
if (ballx > 640)
{
ballmove = 3;
}
}
}
// If the ball goes into the computers goal
if (bally < 0)
{
// Set ball back to start position
ballx = 300; bally = 230;
// Move ball in a random direction
ballmove = dbRnd(3);
// Adjust Score ++ adds one to score Score++; also works
++Score;
}
// If the ball goes into the Players goal
if (bally > 480)
{
// Set ball back to start position
ballx = 300; bally = 230;
// Move ball in a random direction
ballmove = dbRnd(3);
// Adjust Score ++ adds one to score AiScore++; also works
++AiScore;
}
// Select Sprite from Sheet and set to position we just declared above.
// Set Sprite to your paddle
dbSetSpriteFrame(2,1);
dbPasteSprite ( 2, playerx, playery );
// Set Sprite to enemies paddle
dbSetSpriteFrame(2,3);
dbPasteSprite ( 2, compx, compy );
if (ballmove == 0)
{
dbSprite ( 3, ballx = ballx + BallSpeed, bally = bally - BallSpeed, 3 );
}
if (ballmove == 1)
{
dbSprite ( 3, ballx = ballx - BallSpeed, bally = bally - BallSpeed, 3 );
}
if (ballmove == 2)
{
dbSprite ( 3, ballx = ballx + BallSpeed, bally = bally + BallSpeed, 3 );
}
if (ballmove == 3)
{
dbSprite ( 3, ballx = ballx - BallSpeed, bally = bally + BallSpeed, 3 );
}
if ( dbEscapeKey ( ) ) { break; }
dbSync ( );
}
return;
}
www.touchofdeathproductions.com