aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-09-11 17:40:56 -0400
committerClyne Sullivan <tullivan99@gmail.com>2015-09-11 17:40:56 -0400
commit9e81d6b967d87a163ecb6123eb34b9817fa13454 (patch)
treecbfe646d808739353877d817b7becfe9ed0fc812 /src
parente2c16377c87b2ba70bea8fc1fb428eae525b5cf9 (diff)
good merge
Diffstat (limited to 'src')
-rw-r--r--src/World.cpp24
-rw-r--r--src/main.cpp42
2 files changed, 39 insertions, 27 deletions
diff --git a/src/World.cpp b/src/World.cpp
index 9b9a2c3..c2dc62d 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -9,7 +9,7 @@ World::World(void){
World::World(const float width,World *l,World *r){
unsigned int i;
double f;
- lineCount=width/HLINE+1;
+ lineCount=width/HLINE+11;
if((line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)))==NULL){
std::cout<<"Failed to allocate memory!"<<std::endl;
abort();
@@ -32,10 +32,10 @@ World::World(const float width,World *l,World *r){
toRight->toLeft=this;
}
}
- line[0].start=(rand()%100)/100.0f-0.8f; // lazy
+ line[0].start=(grand()%100)/100.0f-0.8f; // lazy
if(line[0].start>-0.5f)line[0].start=-0.7f;
for(i=10;i<lineCount;i+=10){
- line[i].start=((double)(rand()%40+200))/1000.0f-1;
+ line[i].start=((double)(grand()%40+200))/1000.0f-1;
}
for(i=0;i<lineCount;i++){
if(!(i%10)||!i){
@@ -49,7 +49,7 @@ World::World(const float width,World *l,World *r){
void World::draw(void){
unsigned int i;
glBegin(GL_QUADS);
- for(i=0;i<lineCount;i++){
+ for(i=0;i<lineCount-10;i++){
glColor3ub(0,255,0);
glVertex2f((HLINE*i)-1 ,line[i].start);
glVertex2f((HLINE*i)-1+HLINE,line[i].start);
@@ -65,22 +65,24 @@ void World::draw(void){
}
void World::detect(vec2 *v,const float width){
unsigned int i;
- for(i=0;i<lineCount;i++){
+ for(i=0;i<lineCount-10;i++){
if(v->y<line[i].start){
if(v->x>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){
- v->x=(HLINE*i)-1+HLINE;
+ v->y=line[i].start;
+ return;
+ //v->x=(HLINE*i)-1+HLINE;
}else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){
- v->x=(HLINE*i)-1-width;
- }else{
- v->y=line[i].start+HLINE/4;
+ v->y=line[i].start;
+ return;
+ //v->x=(HLINE*i)-1-width;
}
}else if(v->y>line[i].start+HLINE/4){
- //v->y-=HLINE/8;
+ v->y-=HLINE/8;
}
}
}
float World::getWidth(void){
- return (lineCount-1)*HLINE;
+ return (lineCount-11)*HLINE;
}
void World::saveToFile(FILE *f,World *parent){
fwrite(&lineCount,sizeof(unsigned int) ,1 ,f);
diff --git a/src/main.cpp b/src/main.cpp
index 8da775c..3575419 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,6 +21,16 @@ Player player;
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){
@@ -65,7 +75,6 @@ int main(int argc,char **argv){
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);
@@ -86,19 +95,21 @@ int main(int argc,char **argv){
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;
@@ -106,11 +117,6 @@ int main(int argc,char **argv){
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){
@@ -130,6 +136,10 @@ int main(int argc,char **argv){
}
}
+ 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();
}
@@ -162,7 +172,7 @@ void 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);
/**************************
@@ -176,7 +186,7 @@ void render(){
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;
@@ -185,4 +195,4 @@ unsigned int logic(unsigned int interval,void *param){
tickCount++;
return interval;
-}
+}