World::World(const float width,World *l,World *r){\r
unsigned int i;\r
double f;\r
- lineCount=width/HLINE+1;\r
+ lineCount=width/HLINE+11;\r
if((line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)))==NULL){\r
std::cout<<"Failed to allocate memory!"<<std::endl;\r
abort();\r
toRight->toLeft=this;\r
}\r
}\r
- line[0].start=(rand()%100)/100.0f-0.8f; // lazy\r
+ line[0].start=(grand()%100)/100.0f-0.8f; // lazy\r
if(line[0].start>-0.5f)line[0].start=-0.7f;\r
for(i=10;i<lineCount;i+=10){ \r
- line[i].start=((double)(rand()%40+200))/1000.0f-1;\r
+ line[i].start=((double)(grand()%40+200))/1000.0f-1;\r
}\r
for(i=0;i<lineCount;i++){\r
if(!(i%10)||!i){\r
void World::draw(void){\r
unsigned int i;\r
glBegin(GL_QUADS);\r
- for(i=0;i<lineCount;i++){\r
+ for(i=0;i<lineCount-10;i++){\r
glColor3ub(0,255,0);\r
glVertex2f((HLINE*i)-1 ,line[i].start);\r
glVertex2f((HLINE*i)-1+HLINE,line[i].start);\r
}\r
void World::detect(vec2 *v,const float width){\r
unsigned int i;\r
- for(i=0;i<lineCount;i++){\r
+ for(i=0;i<lineCount-10;i++){\r
if(v->y<line[i].start){\r
if(v->x>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){\r
- v->x=(HLINE*i)-1+HLINE;\r
+ v->y=line[i].start;\r
+ return;\r
+ //v->x=(HLINE*i)-1+HLINE;\r
}else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){\r
- v->x=(HLINE*i)-1-width;\r
- }else{\r
- v->y=line[i].start+HLINE/4;\r
+ v->y=line[i].start;\r
+ return;\r
+ //v->x=(HLINE*i)-1-width;\r
}\r
}else if(v->y>line[i].start+HLINE/4){\r
- //v->y-=HLINE/8;\r
+ v->y-=HLINE/8;\r
}\r
}\r
}\r
float World::getWidth(void){\r
- return (lineCount-1)*HLINE;\r
+ return (lineCount-11)*HLINE;\r
}\r
void World::saveToFile(FILE *f,World *parent){\r
fwrite(&lineCount,sizeof(unsigned int) ,1 ,f);\r
UIClass ui;
World *currentWorld;
+//static int randNext=1;
+
+void irand(unsigned int seed){
+ srand(seed);
+}
+
+int grand(void){
+ return rand();
+}
+
unsigned int logic(unsigned int interval,void *param);
float interpolate(float goal, float current, float dt){
std::cout << "SDL was not able to initialize! Error: " << SDL_GetError() << std::endl;
return -1;
}
- srand(time(NULL));
SDL_AddTimer(MSEC_PER_TICK,logic,NULL);
glClearColor(.3,.5,.8,0);
glEnable(GL_BLEND);
currentWorld=w;
// Save the world if necessary
- /*static FILE *f=fopen("world.dat","r");
- if(f==NULL){
+ /*FILE *f=fopen("world.dat","r");
+ unsigned int fSave;
+ if(!f){
f=fopen("world.dat","w");
- if(f!=NULL){
- currentWorld->saveToFile(f,currentWorld);
+ if(f){
+ fSave=time(NULL);
+ fwrite(&fSave,sizeof(unsigned int),1,f);
fclose(f);
- }else{
- std::cout<<"Error! Couldn\'t save the world!"<<std::endl;
}
}else{
- currentWorld->loadFromFile(f,currentWorld);
+ fread(&fSave,sizeof(unsigned int),1,f);
fclose(f);
}*/
+ irand(time(NULL));
+>>>>>>> Stashed changes
float gw;
prevTime = currentTime;
currentTime = tickCount;
deltaTime = currentTime - prevTime;
- //DO ALL RENDERING HERE
- player.vel.x = interpolate(player.velg.x, player.vel.x, deltaTime) * .005;
- if(player.vel.x > .05) player.vel.x = .05;
- if(player.vel.x < -.05) player.vel.x = -.05;
- player.loci.x += player.vel.x;
gw=currentWorld->getWidth();
if(player.loci.x+player.width>-1+gw){
}
}
+ player.vel.x = interpolate(player.velg.x, player.vel.x, deltaTime) * .005;
+ if(player.vel.x > .05) player.vel.x = .05;
+ if(player.vel.x < -.05) player.vel.x = -.05;
+ player.loci.x += player.vel.x;
render();
}
**************************/
currentWorld->draw();
- glColor3ub(0,0,0);
+ glColor3ub(120,30,30);
glRectf(player.loci.x, player.loci.y, player.loci.x + player.width, player.loci.y + player.height);
/**************************
unsigned int logic(unsigned int interval,void *param){
ui.handleEvents(); // Handle events
- player.vel.x = 0;
+ player.vel.x=0;
currentWorld->detect(&player.loci,player.width);
//std::cout << player.vel.x << std::endl;
tickCount++;
return interval;
-}
+}