From fd229306734ac8f9243a278b31d8643b1ada9529 Mon Sep 17 00:00:00 2001 From: Allanis Date: Fri, 1 Feb 2013 22:47:04 +0000 Subject: [PATCH] [Fix] Stars make a bit more sense now! :D --- src/space.c | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/space.c b/src/space.c index 7351a66..437ce81 100644 --- a/src/space.c +++ b/src/space.c @@ -54,8 +54,8 @@ static gl_texture* starBG_create(const int density) { w = (int)((float)gl_screen.w * 1.5); if((w & (w-1)) != 0) { w = 1; - while(h < (int)((float)gl_screen.h*1.5)) - h <<= 1; + while(w < (int)((float)gl_screen.w*1.5)) + w <<= 1; } h = (int)((float)gl_screen.h * 1.5); if((h & (h-1)) != 0) { @@ -94,12 +94,13 @@ void space_init(void) { void space_render(FP dt) { int i; - Vec2 tmp = { .x = starPos[0].x }; + Vec2 tmp; + FP f; for(i = 0; i < STAR_LAYERS; i++) { // Movement. - starPos[i].x -= player->solid->vel.x / (FP)(2*i+4)*dt; - starPos[i].y -= player->solid->vel.y / (FP)(2*i+4)*dt; + starPos[i].x -= player->solid->vel.x / (FP)(2*i+10)*dt; + starPos[i].y -= player->solid->vel.y / (FP)(2*i+104)*dt; // Displaces x if reaches edge. if(starPos[i].x > 0) @@ -119,23 +120,28 @@ void space_render(FP dt) { tmp.x = starPos[i].x; tmp.y = starPos[i].y; - // TODO: This needs optimizing. - tmp.x -= starBG[i]->w; - gl_blitStatic(starBG[i], &tmp); - tmp.y += starBG[i]->h; - gl_blitStatic(starBG[i], &tmp); - tmp.x += starBG[i]->w; - gl_blitStatic(starBG[i], &tmp); - tmp.x += starBG[i]->w; - gl_blitStatic(starBG[i], &tmp); - tmp.y -= starBG[i]->h; - gl_blitStatic(starBG[i], &tmp); - tmp.y -= starBG[i]->h; - gl_blitStatic(starBG[i], &tmp); - tmp.x -= starBG[i]->w; - gl_blitStatic(starBG[i], &tmp); - tmp.x -= starBG[i]->w; - gl_blitStatic(starBG[i], &tmp); + // More blits if part of the screen is blank. + if(starPos[i].x < starBG[i]->w/4.) + tmp.x += starBG[i]->w; + else if(starPos[i].x < starBG[i]->w*3./4.) + tmp.y -= starBG[i]->w; + + if(starPos[i].y < starBG[i]->h/4.) + tmp.y += starBG[i]->h; + else if(starPos[i].y < starBG[i]->h*3./4.) + tmp.y -= starBG[i]->h; + + if(tmp.x != starPos[i].x && tmp.y != starPos[i].y) { + gl_blitStatic(starBG[i], &tmp); + f = tmp.x; + tmp.x = starPos[i].x; + gl_blitStatic(starBG[i], &tmp); + tmp.x = f; + tmp.y = starPos[i].y; + gl_blitStatic(starBG[i], &tmp); + } + else if(tmp.x != starPos[i].x || tmp.y != starPos[i].y) + gl_blitStatic(starBG[i], &tmp); } }