compiles fine and runs, just doesn't show the text.
#include "SDL.h"
#include <cstdlib>
#include <ctime>
#include "SDL_ttf.h"
struct spriteSheet{
SDL_Surface *image;
int rows;
int col;
int pixls;
int border;
int state;
int speed;
int spinspeed;};
SDL_Rect newSDLRect(int x, int y, int w, int h){
SDL_Rect rect;
rect.x = x;
rect.y = y;
rect.w = w;
rect.h = h;
return(rect); }
void drawSprite(spriteSheet ball, SDL_Surface*& screen, int num, int xpos, int ypos){
int nx, ny;
int count = 0;
for(int fy=0; fy<ball.col; fy++){
for(int fx=0; fx<ball.rows; fx++){
if(count==num-1){
nx = fx;
ny = fy;
}
count++;
}
}
SDL_Rect srect = newSDLRect(xpos,ypos, ball.pixls,ball.pixls);
SDL_Rect crect = newSDLRect(
((nx*ball.pixls)+(nx+1*(ball.border))),
((ny*ball.pixls)+(ny+1*(ball.border))),
ball.pixls, ball.pixls);
SDL_BlitSurface(ball.image, &crect, screen, &srect);
}
int main(int argc, char *argv[])
{
SDL_Event event;
bool bRun = 1;
SDL_Surface *screen, *hands, *robot, *score_;
TTF_Font *font;
font = TTF_OpenFont("Robofont.ttf", 36);
SDL_Color textColor = { 255, 255, 255 };
score_ = TTF_RenderText_Solid( font, "THIS IS A TEST", textColor );
// Some font stuff, score_ is the surface, font is the fonttype, textColor is the font color. it's init'd and closes at the end
SDL_Rect rightHand, leftHand, robotbody, scorepos;
rightHand.x = 530 ;
rightHand.y = 420 ;
leftHand.x = 10 ;
leftHand.y = 420 ;
robotbody.x = 95;
robotbody.y = 0;
scorepos.x = 200;
scorepos.y = 20;
signed char rightHandPos = 3, leftHandPos = 1, ball1starth = 0;
atexit(SDL_Quit);
int ball1x = 0, ball1y = -100, inc = 7, score = 0, combo = 0;
int spinloop = 1;
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) return(1);
if( TTF_Init() < 0 ) return(1);
SDL_WM_SetCaption("Robo-Juggler", NULL);
screen = SDL_SetVideoMode( 640 , 480 , 32 , SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_ANYFORMAT);
robot = SDL_LoadBMP("robot.bmp");
hands = SDL_LoadBMP("hand.bmp");
spriteSheet ball1;
ball1.image = SDL_LoadBMP("ball1.bmp");
SDL_SetColorKey(ball1.image, SDL_SRCCOLORKEY, SDL_MapRGB(ball1.image->format, 255, 0, 255));
ball1.rows = 7;
ball1.col = 2;
ball1.pixls = 100;
ball1.border = 1;
ball1.state = 0;
ball1.speed = 40;
ball1.spinspeed = 2;
Uint32 colorkey=SDL_MapRGB(hands->format, 255, 0, 255);
SDL_SetColorKey(hands, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey);
int spin = 1;
//ENDTEST
srand(time(0));
int random = ((rand()%3)+1);
int counter = 0;
// convert Score from into to char
while(bRun) {
SDL_FillRect(screen , NULL , 0x000000);
SDL_BlitSurface( robot , NULL , screen , &robotbody );
SDL_BlitSurface( hands , NULL , screen , &rightHand );
SDL_BlitSurface( hands , NULL , screen , &leftHand );
SDL_BlitSurface( score_ , NULL , screen , &scorepos );
if (ball1y > 480)
{ ball1.state = 0; }
switch (ball1.state){
case 0:
ball1starth = ((rand()%6)+1);
break;
case 1:
switch(ball1starth){
case 1:
ball1x = 10; break;
case 3:
ball1x = 90; break;
case 5:
ball1x = 170; break;
case 2:
ball1x = 370; break;
case 4:
ball1x = 450; break;
case 6:
ball1x = 530; break;
};
ball1y += inc++;
if(inc == 24)
inc = 19;
drawSprite(ball1, screen, spin, ball1x, ball1y);
if (ball1starth==1&&ball1y>350&&ball1y<370&&leftHandPos==1)
{ball1.state = 2;
counter = 0;}
if (ball1starth==3&&ball1y>350&&ball1y<370&&leftHandPos==2)
{ball1.state = 3;
counter = 0;}
if (ball1starth==5&&ball1y>350&&ball1y<370&&leftHandPos==3)
{ball1.state = 4;
counter = 0;}
if (ball1starth==2&&ball1y>350&&ball1y<370&&rightHandPos==1)
{ball1.state = 5;
counter = ball1.speed;}
if (ball1starth==4&&ball1y>350&&ball1y<370&&rightHandPos==2)
{ball1.state = 6;
counter = ball1.speed;}
if (ball1starth==6&&ball1y>350&&ball1y<370&&rightHandPos==3)
{ball1.state = 7;
counter = ball1.speed;}
break;
case 2:
//from LL to:
switch (random)
{
case 1:
//RR
ball1x = ((520/ball1.speed)*counter)+10;
ball1y = (0.005177*((ball1x-10)*(ball1x-10)))+(-2.6923*(ball1x-10))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter++;
if (ball1y>350&&ball1y<370&&rightHandPos==3&&ball1x>250)
{ball1.state = 7;
counter = ball1.speed;
random = ((rand()%3)+1); }
break;
//MR
case 2:
ball1x = ((440/ball1.speed)*counter)+10;
ball1y = (0.00619*((ball1x-10)*(ball1x-10)))+(-2.727*(ball1x-10))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter++;
if (ball1y>350&&ball1y<370&&rightHandPos==2&&ball1x>250)
{ball1.state = 6;
counter = ball1.speed;
random = ((rand()%3)+1); }
break;
//LR
case 3:
ball1x = ((360/ball1.speed)*counter)+10;
ball1y = (0.00771605*((ball1x-10)*(ball1x-10)))+(-2.77778*(ball1x-10))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter++;
if (ball1y>350&&ball1y<370&&rightHandPos==1&&ball1x>250)
{ball1.state = 5;
counter = ball1.speed;
random = ((rand()%3)+1);}
break;
}
break;
case 3:
//ML TO
switch (random)
{
case 1:
//RR
ball1x = ((440/ball1.speed)*counter)+90;
ball1y = (0.00619*((ball1x-90)*(ball1x-90)))+(-2.727*(ball1x-90))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter++;
if (ball1y>350&&ball1y<370&&rightHandPos==3&&ball1x>250)
{ball1.state = 7;
counter = ball1.speed;
random = ((rand()%3)+1);}
break;
case 2:
//MR
ball1x = ((360/ball1.speed)*counter)+90;
ball1y = (0.00771605*((ball1x-90)*(ball1x-90)))+(-2.77778*(ball1x-90))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter++;
if (ball1y>350&&ball1y<370&&rightHandPos==2&&ball1x>250)
{ball1.state = 6;
counter = ball1.speed;
random = ((rand()%3)+1);}
break;
//LR
case 3:
ball1x = ((280/ball1.speed)*counter)+90;
ball1y = (0.0102041*((ball1x-90)*(ball1x-90)))+(-2.85714*(ball1x-90))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter++;
if (ball1y>350&&ball1y<370&&rightHandPos==1&&ball1x>250)
{ball1.state = 5;
counter = ball1.speed;
random = ((rand()%3)+1);}
break;
}
break;
case 4:
//From RL to:
switch (random){
//RR
case 1:
ball1x = ((360/ball1.speed)*counter)+170;
ball1y = (0.00771605*((ball1x-170)*(ball1x-170)))+(-2.77778*(ball1x-170))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter++;
if (ball1y>350&&ball1y<370&&rightHandPos==3&&ball1x>250)
{ball1.state = 7;
counter = ball1.speed;
random = ((rand()%3)+1);}
break;
//MR
case 2:
ball1x = ((280/ball1.speed)*counter)+170;
ball1y = (0.0102041*((ball1x-170)*(ball1x-170)))+(-2.85714*(ball1x-170))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter++;
if (ball1y>350&&ball1y<370&&rightHandPos==2&&ball1x>250)
{ball1.state = 6;
counter = ball1.speed;
random = ((rand()%3)+1);}
break;
//LR
case 3:
ball1x = ((200/ball1.speed)*counter)+170;
ball1y = (0.015*((ball1x-170)*(ball1x-170)))+(-3*(ball1x-170))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter++;
if (ball1y>350&&ball1y<370&&rightHandPos==1&&ball1x>250)
{ball1.state = 5;
counter = ball1.speed;
random = ((rand()%3)+1);}
break;
}break;
case 5:
//FROM LR to:
switch (random){
//LL
case 1:
ball1x = ((360/ball1.speed)*counter)+10;
ball1y = (0.00771605*((ball1x-10)*(ball1x-10)))+(-2.77778*(ball1x-10))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter--;
if (ball1y>350&&ball1y<370&&leftHandPos==1&&ball1x<250)
{ball1.state = 2;
counter = 0;
random = ((rand()%3)+1);}
break;
//ML
case 2:
ball1x = ((280/ball1.speed)*counter)+90;
ball1y = (0.0102041*((ball1x-90)*(ball1x-90)))+(-2.85714*(ball1x-90))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter--;
if (ball1y>350&&ball1y<370&&leftHandPos==2&&ball1x<250)
{ball1.state = 3;
counter = 0;
random = ((rand()%3)+1);}
break;
//RL
case 3:
ball1x = ((200/ball1.speed)*counter)+170;
ball1y = (0.015*((ball1x-170)*(ball1x-170)))+(-3*(ball1x-170))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter--;
if (ball1y>350&&ball1y<370&&leftHandPos==3&&ball1x<250)
{ball1.state = 4;
counter = 0;
random = ((rand()%3)+1);}
break;}
break;
case 6:
//From MR to:
switch (random){
//LL
case 1:
ball1x = ((440/ball1.speed)*counter)+10;
ball1y = (0.00619*((ball1x-10)*(ball1x-10)))+(-2.727*(ball1x-10))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter--;
if (ball1y>350&&ball1y<370&&leftHandPos==1&&ball1x<250)
{ball1.state = 2;
counter = 0;
random = ((rand()%3)+1);}
break;
//ML
case 2:
ball1x = ((360/ball1.speed)*counter)+90;
ball1y = (0.00771605*((ball1x-90)*(ball1x-90)))+(-2.77778*(ball1x-90))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter--;
if (ball1y>350&&ball1y<370&&leftHandPos==2&&ball1x<250)
{ball1.state = 3;
counter = 0;
random = ((rand()%3)+1);}
break;
//RL
case 3:
ball1x = ((280/ball1.speed)*counter)+170;
ball1y = (0.0102041*((ball1x-170)*(ball1x-170)))+(-2.85714*(ball1x-170))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter--;
if (ball1y>350&&ball1y<370&&leftHandPos==3&&ball1x<250)
{ball1.state = 4;
counter = 0;
random = ((rand()%3)+1);}
break;}
break;
case 7:
//From RR to:
switch (random){
//LL
case 1:
ball1x = ((520/ball1.speed)*counter)+10;
ball1y = (0.005177*((ball1x-10)*(ball1x-10)))+(-2.6923*(ball1x-10))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter--;
if (ball1y>350&&ball1y<370&&leftHandPos==1&&ball1x<250)
{ball1.state = 2;
counter = 0;
random = ((rand()%3)+1);}
break;
//ML
case 2:
ball1x = ((440/ball1.speed)*counter)+90;
ball1y = (0.00619*((ball1x-90)*(ball1x-90)))+(-2.727*(ball1x-90))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter--;
if (ball1y>350&&ball1y<370&&leftHandPos==2&&ball1x<250)
{ball1.state = 3;
counter = 0;
random = ((rand()%3)+1);}
break;
//RL
case 3:
ball1x = ((360/ball1.speed)*counter)+170;
ball1y = (0.00771605*((ball1x-170)*(ball1x-170)))+(-2.77778*(ball1x-170))+353;
drawSprite(ball1, screen, spin, ball1x, ball1y);
counter--;
if (ball1y>350&&ball1y<370&&leftHandPos==3&&ball1x<250)
{ball1.state = 4;
counter = 0;
random = ((rand()%3)+1);}
break;}
break;
}
//CONTROL FOR BALL SPIN SPEED
if (spin==14)
{spin=1;}
if (ball1.spinspeed == 1)
spin++;
if (ball1.spinspeed == 2)
{
switch (spinloop)
{
case 1:
spinloop++;
break;
case 2:
spin++;
spinloop = 1;
}
}
SDL_Flip(screen);
SDL_Delay( 20 );
while( SDL_PollEvent( &event ) ){
switch( event.type ){
case SDL_KEYDOWN:
switch( event.key.keysym.sym ){
case SDLK_LEFT:
if (rightHandPos == 1){
rightHand.x -= 0; }
if (rightHandPos == 2 || rightHandPos == 3){
rightHand.x -= 80;
rightHandPos -= 1; }
break;
case SDLK_RIGHT:
if (rightHandPos == 3){
rightHand.x += 0; }
if (rightHandPos == 2 || rightHandPos == 1){
rightHand.x += 80;
rightHandPos += 1; }
break;
case SDLK_a:
if (leftHandPos == 1){
leftHand.x -= 0; }
if (leftHandPos == 2 || leftHandPos == 3){
leftHand.x -= 80;
leftHandPos -= 1; }
break;
case SDLK_d:
if (leftHandPos == 3){
leftHand.x += 0; }
if (leftHandPos == 2 || leftHandPos == 1){
leftHand.x += 80;
leftHandPos += 1; }
break;
case SDLK_SPACE:
if (ball1.state == 0)
{
ball1.state = 1;
ball1y = -100;
inc = 7;
}
break;
case SDLK_ESCAPE:
bRun = 0 ;
break;
default:
break;
}
break;
case SDL_QUIT:
bRun = 0;
break;
default:
break;
}
}
};
TTF_CloseFont(font);
TTF_Quit();
return 0;
}
I think I'm going to rewrite the trajectory part as a function, should clean up the code quite a bit.