From c404e3611e06be55382a73031ee82b13795dd80a Mon Sep 17 00:00:00 2001 From: onpon4 Date: Thu, 26 Feb 2015 23:23:08 -0500 Subject: [PATCH] Fixed edges of the screen slowing you down. And unlike a fix I previously did, this one is perfect. Rather than fiddling with ssx and ssy, I just added some new variables, smx and smy. --- src/aliens.cpp | 4 ++-- src/bullets.cpp | 6 +++--- src/cargo.cpp | 4 ++-- src/collectable.cpp | 4 ++-- src/debris.cpp | 4 ++-- src/explosions.cpp | 4 ++-- src/game.cpp | 2 ++ src/globals.cpp | 2 ++ src/graphics.cpp | 6 ++++-- src/intermission.cpp | 3 ++- src/player.cpp | 25 +++++++++++++++++++++++-- src/script.cpp | 4 +++- src/structs.h | 2 ++ src/title.cpp | 2 ++ 14 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/aliens.cpp b/src/aliens.cpp index f1083b1..b0c5123 100644 --- a/src/aliens.cpp +++ b/src/aliens.cpp @@ -1219,9 +1219,9 @@ void doAliens() } if ((currentGame.area != 18) || (theEnemy->shield < 0)) - theEnemy->x += engine.ssx; + theEnemy->x += engine.ssx + engine.smx; - theEnemy->y += engine.ssy; + theEnemy->y += engine.ssy + engine.smy; } theEnemy++; diff --git a/src/bullets.cpp b/src/bullets.cpp index fb43b63..4c37eb7 100644 --- a/src/bullets.cpp +++ b/src/bullets.cpp @@ -43,7 +43,7 @@ void addBullet(object *theWeapon, object *attacker, int y, int dy) { bullet->dx = theWeapon->speed; if ((currentGame.area == 18) || (currentGame.area == 24)) - bullet->dx += fabsf(engine.ssx); + bullet->dx += fabsf(engine.ssx + engine.smx); } else { @@ -556,8 +556,8 @@ void doBullets() bullet->target = NULL; } - bullet->x += engine.ssx; - bullet->y += engine.ssy; + bullet->x += engine.ssx + engine.smx; + bullet->y += engine.ssy + engine.smy; for (int i = 0 ; i < MAX_ALIENS ; i++) { diff --git a/src/cargo.cpp b/src/cargo.cpp index 89f1ae7..d9a788d 100644 --- a/src/cargo.cpp +++ b/src/cargo.cpp @@ -96,8 +96,8 @@ void doCargo() blit(cargo[i].image[0], (int)cargo[i].x, (int)cargo[i].y); - cargo[i].x += engine.ssx; - cargo[i].y += engine.ssy; + cargo[i].x += engine.ssx + engine.smx; + cargo[i].y += engine.ssy + engine.smy; limitFloat(&cargo[i].x, cargo[i].owner->x - 50, cargo[i].owner->x + 50); limitFloat(&cargo[i].y, cargo[i].owner->y - 50, cargo[i].owner->y + 50); diff --git a/src/collectable.cpp b/src/collectable.cpp index ce1f210..f24f3bb 100644 --- a/src/collectable.cpp +++ b/src/collectable.cpp @@ -242,8 +242,8 @@ void doCollectables() if ((collectable->x + collectable->image->w > 0) && (collectable->x < 800) && (collectable->y + collectable->image->h > 0) && (collectable->y < 600)) blit(collectable->image, (int)collectable->x, (int)collectable->y); - collectable->x += engine.ssx; - collectable->y += engine.ssy; + collectable->x += engine.ssx + engine.smx; + collectable->y += engine.ssy + engine.smx; collectable->x += collectable->dx; collectable->y += collectable->dy; diff --git a/src/debris.cpp b/src/debris.cpp index 2535676..0ef8188 100644 --- a/src/debris.cpp +++ b/src/debris.cpp @@ -67,8 +67,8 @@ void doDebris() { debris->thinktime--; - debris->x += engine.ssx; - debris->y += engine.ssy; + debris->x += engine.ssx + engine.smx; + debris->y += engine.ssy + engine.smy; debris->x += debris->dx; debris->y += debris->dy; diff --git a/src/explosions.cpp b/src/explosions.cpp index 6b89d4e..9a795d0 100644 --- a/src/explosions.cpp +++ b/src/explosions.cpp @@ -78,8 +78,8 @@ void doExplosions() if (explosion->active) { - explosion->x += engine.ssx; - explosion->y += engine.ssy; + explosion->x += engine.ssx + engine.smx; + explosion->y += engine.ssy + engine.smy; if (isOnScreen((int)explosion->x, (int)explosion->y, explosion->image[0]->w, explosion->image[0]->h)) blit(explosion->image[0], (int)explosion->x, (int)explosion->y); diff --git a/src/game.cpp b/src/game.cpp index 46f49a7..bc19980 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -109,6 +109,8 @@ int mainGameLoop() engine.ssx = 0; engine.ssy = 0; + engine.smx = 0; + engine.smy = 0; engine.done = 0; diff --git a/src/globals.cpp b/src/globals.cpp index e00d8d9..32f3dbd 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -29,6 +29,8 @@ void defineGlobals() engine.ssx = 0; engine.ssy = 0; + engine.smx = 0; + engine.smy = 0; engine.bulletHead = new object; engine.bulletHead->next = NULL; diff --git a/src/graphics.cpp b/src/graphics.cpp index c3223f4..5c594cd 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -711,8 +711,10 @@ void doStarfield() else if (star[i].speed == 1) color = darkGrey; - wrapFloat(&(star[i].x += (engine.ssx * star[i].speed)), 0, screen->w - 1); - wrapFloat(&(star[i].y += (engine.ssy * star[i].speed)), 0, screen->h - 1); + wrapFloat(&(star[i].x += ((engine.ssx + engine.smx) * star[i].speed)), 0, + screen->w - 1); + wrapFloat(&(star[i].y += ((engine.ssy + engine.smy) * star[i].speed)), 0, + screen->h - 1); putpixel(screen, (int)star[i].x, (int)star[i].y, color); r.x = (int)star[i].x; diff --git a/src/intermission.cpp b/src/intermission.cpp index 8f7e7ac..c141da7 100644 --- a/src/intermission.cpp +++ b/src/intermission.cpp @@ -514,7 +514,8 @@ int galaxyMap() engine.done = 0; engine.keyState[KEY_FIRE] = 0; - engine.ssx = engine.ssy = 0; + engine.ssx = 0; + engine.ssy = 0; SDL_Rect r; SDL_Rect destRect; diff --git a/src/player.cpp b/src/player.cpp index ddd5e85..e56b98a 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -76,6 +76,9 @@ void doPlayer() engine.ssx *= 0.99; engine.ssy *= 0.99; + engine.smx = 0; + engine.smy = 0; + int shapeToUse; if (player.shield > -100) @@ -190,8 +193,26 @@ void doPlayer() if (engine.done == 0) { - limitFloat(&player.x, viewBorder, screen->w - viewBorder); - limitFloat(&player.y, viewBorder, screen->h - viewBorder); + if (player.x < viewBorder) + { + engine.smx += viewBorder - player.x; + player.x = viewBorder; + } + else if (player.x > screen->w - viewBorder) + { + engine.smx += (screen->w - viewBorder) - player.x; + player.x = screen->w - viewBorder; + } + if (player.y < viewBorder) + { + engine.smy += viewBorder - player.y; + player.y = viewBorder; + } + else if (player.y > screen->h - viewBorder) + { + engine.smy += (screen->h - viewBorder) - player.y; + player.y = screen->h - viewBorder; + } } if (player.shield > engine.lowShield) diff --git a/src/script.cpp b/src/script.cpp index 8aea6f1..247f377 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -189,6 +189,8 @@ void doCutscene(int scene) engine.ssx = -0.5; engine.ssy = 0; + engine.smx = 0; + engine.smy = 0; flushBuffer(); freeGraphics(); @@ -253,7 +255,7 @@ void doCutscene(int scene) } enemy[i].x += enemy[i].dx; enemy[i].y += enemy[i].dy; - enemy[i].x += engine.ssx; + enemy[i].x += engine.ssx + engine.smx; blit(enemy[i].image[0], (int)enemy[i].x, (int)enemy[i].y); if (enemy[i].x > (screen->w + 50)) { diff --git a/src/structs.h b/src/structs.h index 0d5f090..86c54ce 100644 --- a/src/structs.h +++ b/src/structs.h @@ -230,6 +230,8 @@ struct globalEngineVariables { float ssx; float ssy; + float smx; + float smy; Mix_Music *music; diff --git a/src/title.cpp b/src/title.cpp index 141813d..c1bdc37 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -217,6 +217,8 @@ int doTitle() // Set the star motion engine.ssx = -0.5; engine.ssy = 0; + engine.smx = 0; + engine.smy = 0; int then = SDL_GetTicks(); int now;