#include "SDL/SDL.h"
#include <iostream>
using namespace std;
int key[256]={0};
#define k_1 26
#define k_2 27
#define k_3 28
#define k_4 29
#define k_5 30
#define k_6 31
#define k_7 32
#define k_8 33
#define k_9 34
#define k_0 35
#define k_ESCAPE 40
#define k_RETURN 43
void sgUPDATE_KEYBOARD_STATE(){const Uint8* currentKeyStates;
currentKeyStates = SDL_GetKeyState( NULL );
if( currentKeyStates[SDLK_1] ){key[k_1]=1;}else{key[k_1]=0;}
if( currentKeyStates[SDLK_2] ){key[k_2]=1;}else{key[k_2]=0;}
if( currentKeyStates[SDLK_3] ){key[k_3]=1;}else{key[k_3]=0;}
if( currentKeyStates[SDLK_4] ){key[k_4]=1;}else{key[k_4]=0;}
if( currentKeyStates[SDLK_5] ){key[k_5]=1;}else{key[k_5]=0;}
if( currentKeyStates[SDLK_6] ){key[k_6]=1;}else{key[k_6]=0;}
if( currentKeyStates[SDLK_7] ){key[k_7]=1;}else{key[k_7]=0;}
if( currentKeyStates[SDLK_8] ){key[k_8]=1;}else{key[k_8]=0;}
if( currentKeyStates[SDLK_9] ){key[k_9]=1;}else{key[k_9]=0;}
if( currentKeyStates[SDLK_0] ){key[k_0]=1;}else{key[k_0]=0;}
if( currentKeyStates[SDLK_ESCAPE] ){key[k_ESCAPE]=1;}else{key[k_ESCAPE]=0;}
if( currentKeyStates[SDLK_RETURN] ){key[k_RETURN]=1;}else{key[k_RETURN]=0;}
}
SDL_Event sgEvent;
int sgPROCESS_EVENT(){int status=0;
while(SDL_PollEvent(&sgEvent)){
if(sgEvent.type == SDL_QUIT){status=2;}}
sgUPDATE_KEYBOARD_STATE();return status;}
#define sgDefineStandardMaxFPS 50.0f
Uint32 sgOldTime=0,sgCurrentTime=0;
float sgTimeUnit=0.1f,sgFrameRate=1000.0f/sgDefineStandardMaxFPS;
void sgGET_TIME(Uint32& utime){utime=SDL_GetTicks();}
void sgDELAY_TIME(Uint32 utime){SDL_Delay(utime);}
void sgUPDATE_TIME(){float x=0.0f;Uint32 td=0;sgGET_TIME(sgCurrentTime);
if(sgOldTime>sgCurrentTime){sgCurrentTime=sgOldTime;}x=sgCurrentTime-sgOldTime;
if(x<sgFrameRate){x=sgFrameRate-x;td=x;sgDELAY_TIME(td);sgCurrentTime+=td;}
sgTimeUnit=(float)(sgCurrentTime-sgOldTime)/1000.0f;
if(sgTimeUnit<0.0f){sgTimeUnit*=-1.0f;}sgOldTime=sgCurrentTime;}
int sgQuit=0;
SDL_Surface *sgWindow;
#define sgFrameStart 0
#define sgFrameEnd 1
void sgFRAME_ROUTINE(int id){int sgInfo;
if(id==sgFrameStart){
sgInfo=sgPROCESS_EVENT();if(sgInfo==2){sgQuit=1;}}
if(id==sgFrameEnd){
sgUPDATE_TIME();
SDL_Flip(sgWindow);
}
}
int main(int argc,char **argv){
int k_0h=0,k_1h=0,k_2h=0,k_3h=0,k_4h=0,k_5h=0,k_6h=0,k_7h=0,k_8h=0,k_9h=0;
float x=1.0f,floatvar=0.0f;
SDL_Init(SDL_INIT_EVERYTHING);
sgWindow=SDL_SetVideoMode(250,250,16,SDL_SWSURFACE);
while(sgQuit==0){//**************************************** GAME LOOP
sgFRAME_ROUTINE(sgFrameStart);
if(key[k_ESCAPE]==1){sgQuit=1;cout<<endl<<"exit ESC "<<floatvar<<endl;}
if(key[k_0]==0){k_0h=0;}
if(key[k_1]==0){k_1h=0;}
if(key[k_2]==0){k_2h=0;}
if(key[k_3]==0){k_3h=0;}
if(key[k_4]==0){k_4h=0;}
if(key[k_5]==0){k_5h=0;}
if(key[k_6]==0){k_6h=0;}
if(key[k_7]==0){k_7h=0;}
if(key[k_8]==0){k_8h=0;}
if(key[k_9]==0){k_9h=0;}
if(key[k_0]==1&&k_0h==0&&x>0.000001f){k_0h=1;floatvar+=0.0f*x;x*=0.1f;cout<<0;if(x==0.1f){cout<<".";}}
if(key[k_1]==1&&k_1h==0&&x>0.000001f){k_1h=1;floatvar+=1.0f*x;x*=0.1f;cout<<1;if(x==0.1f){cout<<".";}}
if(key[k_2]==1&&k_2h==0&&x>0.000001f){k_2h=1;floatvar+=2.0f*x;x*=0.1f;cout<<2;if(x==0.1f){cout<<".";}}
if(key[k_3]==1&&k_3h==0&&x>0.000001f){k_3h=1;floatvar+=3.0f*x;x*=0.1f;cout<<3;if(x==0.1f){cout<<".";}}
if(key[k_4]==1&&k_4h==0&&x>0.000001f){k_4h=1;floatvar+=4.0f*x;x*=0.1f;cout<<4;if(x==0.1f){cout<<".";}}
if(key[k_5]==1&&k_5h==0&&x>0.000001f){k_5h=1;floatvar+=5.0f*x;x*=0.1f;cout<<5;if(x==0.1f){cout<<".";}}
if(key[k_6]==1&&k_6h==0&&x>0.000001f){k_6h=1;floatvar+=6.0f*x;x*=0.1f;cout<<6;if(x==0.1f){cout<<".";}}
if(key[k_7]==1&&k_7h==0&&x>0.000001f){k_7h=1;floatvar+=7.0f*x;x*=0.1f;cout<<7;if(x==0.1f){cout<<".";}}
if(key[k_8]==1&&k_8h==0&&x>0.000001f){k_8h=1;floatvar+=8.0f*x;x*=0.1f;cout<<8;if(x==0.1f){cout<<".";}}
if(key[k_9]==1&&k_9h==0&&x>0.000001f){k_9h=1;floatvar+=9.0f*x;x*=0.1f;cout<<9;if(x==0.1f){cout<<".";}}
if(x<0.00001f){sgQuit=1;cout<<endl<<"exit END "<<floatvar<<endl;}
sgFRAME_ROUTINE(sgFrameEnd);}//**************************** END OF GAME LOOP
SDL_Quit();
return 0;}