Hi guys you probably know me by now as the 2D pain
I just started a simple pong project, i made some sprites for wall barriers and stuck them in, now the problem is i had to rotate them to make my game board look the way i wanted it (hexagon shape) when i put in collision testing the map looks fine but there is invisible walls that cause the ball to bounce even though i'm using sprite collision, anyways heres my code has anyone else had these issues?
#include "DarkGDK.h"
const int Background = 1;
const int Bat = 2;
const int Ball = 3;
const int Wall = 10;
const int Wall1 = 11;
const int Wall2 = 12;
const int Wall3 = 13;
const int Post = 14;
const int Goal1 = 15;
const int Goal2 = 16;
const int Goal3 = 17;
const int Goal4 = 18;
const int Goal5 = 19;
const int Goal6 = 20;
//debug bool
bool debugEnabled = true;
void SetUpScreen();
void debug(int &batX, int &batY);
void LoadImages();
void MoveBat(int &batX, int &batY);
void BallMove(int &ballX, int &ballY, float ballSpeedX, float ballSpeedY);
void LoadObjects(int &ballX, int &ballY, int &batX, int &batY);
// the main entry point for the application is this function
void DarkGDK ( void )
{
int batX = 500;
int batY = 720;
int ballX = 500;
int ballY = 204;
float ballSpeedX = 5;
float ballSpeedY = 5;
SetUpScreen();
LoadImages();
LoadObjects(ballX,ballY,batX,batY);
// our main loop
while ( LoopGDK ( ) )
{
MoveBat(batX, batY);
BallMove(ballX, ballY, ballSpeedX, ballSpeedY);
dbPasteImage(Background,0,0);
if(dbSpriteHit(Bat,Ball))
{
ballSpeedY = ballSpeedY*-1;
}
if (ballY <= 0 || ballY >= 768 - dbSpriteWidth(Ball))
{
ballSpeedY = ballSpeedY*-1;
}//end if
if (ballX <= 0 || ballX >= 1024 - dbSpriteWidth(Ball))
{
ballSpeedX = ballSpeedX*-1;
}//end if
if((dbSpriteHit(Ball,Goal1))||(dbSpriteHit(Ball,Goal2))||(dbSpriteHit(Ball,Wall3)))
{
ballSpeedY = ballSpeedY*-1;
}
if((dbSpriteHit(Ball,Goal3))||(dbSpriteHit(Ball,Goal5))||(dbSpriteHit(Ball,Wall2)))
{
ballSpeedX = ballSpeedX*-1;
}
if((dbSpriteHit(Ball,Goal4))||(dbSpriteHit(Ball,Goal6))||(dbSpriteHit(Ball,Wall1)))
{
ballSpeedX = ballSpeedX*-1;
}
debug(batX, batY);
// update the screen
//dbSync ( );
}
// return back to windows
//return;
}
void SetUpScreen()
{
// Set up Game Screen
dbSyncOn ();
dbSyncRate (60);
dbSetWindowTitle("***Hexa Pong!***");
dbSetDisplayMode(1024,768,0);
dbMaximizeWindow();
}//end function set up screen
void LoadImages()
{
// Set Transparency
dbSetImageColorKey ( 0, 0, 0 );
//Load the menu images
dbLoadImage("Sprites\\BackGround.png",Background);
dbLoadImage("Sprites\\bat.png", Bat);
dbLoadImage("Sprites\\ball.png", Ball);
dbLoadImage("Sprites\\Barrier.png", Wall);
dbLoadImage("Sprites\\Goal.png",Post);
}//end function load images
void MoveBat(int &batX, int &batY)
{
if(dbLeftKey() == 1)
{
batX = batX-3;
//batY = batY-2;
dbSprite(Bat,batX,batY,Bat);
}
if(dbRightKey() == 1)
{
batX = batX+3;
//batY = batY+2;
dbSprite(Bat,batX,batY,Bat);
}
dbSync();
}//end function movebat
void BallMove(int &ballX, int &ballY, float ballSpeedX, float ballSpeedY)
{
ballX=dbSpriteX(Ball) + ballSpeedX;
ballY=dbSpriteY(Ball) + ballSpeedY;
//displays the ball in the updated x and y coord positions
dbSprite(Ball,ballX,ballY,Ball);
}//end function Ball
void debug(int &batX,int &batY)
{
if (debugEnabled == true)
{
// Debug Display
dbInk(dbRGB(255,0,0),1);
dbText(770,0,dbStr(dbScreenFPS()));
dbText(770,15,dbStr(dbScanCode()));
dbText(770,30,dbStr(batX));
dbText(770,45,dbStr(batY));
dbText(770,60,dbStr(dbMouseX()));
dbText(770,75,dbStr(dbMouseY()));
}//end if
}//end function debug
void LoadObjects(int &ballX, int &ballY, int &batX, int &batY)
{
dbSprite(Bat,batX,batY,Bat);
dbSprite(Ball, ballX, ballY, Ball);
dbSetSpriteAlpha ( Wall1, 0 );
dbSprite(Wall1,922,360,Wall);
dbSpriteAngle ( Wall1 );
dbRotateSprite(Wall1,30);
dbSprite(Wall2,322,742,Wall);
dbRotateSprite(Wall2,150);
dbSprite(Wall3,288,32,Wall);
dbRotateSprite(Wall3,270);
dbSprite(Goal1,278,18,Post);
dbSizeSprite(Goal1,30,30);
dbSprite(Goal2,718,18,Post);
dbSizeSprite(Goal2,30,30);
dbSprite(Goal3,90,350,Post);
dbSizeSprite(Goal3,30,30);
dbSprite(Goal4,910,350,Post);
dbSizeSprite(Goal4,30,30);
dbSprite(Goal5,304,730,Post);
dbSizeSprite(Goal5,30,30);
dbSprite(Goal6,692,730,Post);
dbSizeSprite(Goal6,30,30);
}//end function display objects
www.pricklyproductions.co.uk