Skip to content

Commit

Permalink
Improved camera handling
Browse files Browse the repository at this point in the history
  • Loading branch information
theZiz committed May 14, 2017
1 parent 3ac3b0f commit 5b134f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
3 changes: 1 addition & 2 deletions ToDo
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* Fix bug
* Improve camera

27 changes: 17 additions & 10 deletions hase.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SDL_Surface* level_original;
Uint16* level_pixel;
SDL_Surface* arrow;
int posX,posY,rotation;
int mapviewX,mapviewY;
Sint32 zoom;
Sint32 zoom_d;
Sint32 zoomAdjust;
Expand Down Expand Up @@ -1088,25 +1089,31 @@ int calc(Uint32 steps)
zoom_d = 1;
if (spGetInput()->axis[0] < 0)
{
posX -= spDiv(spCos(-rotation),zoom*3/4)*steps;
posY -= spDiv(spSin(-rotation),zoom*3/4)*steps;
mapviewX -= spMul(spGetSizeFactor(),spDiv(spCos(-rotation),zoom*3))*steps;
mapviewY -= spMul(spGetSizeFactor(),spDiv(spSin(-rotation),zoom*3))*steps;
}
if (spGetInput()->axis[0] > 0)
{
posX -= spDiv(spCos(-rotation+SP_PI),zoom*3/4)*steps;
posY -= spDiv(spSin(-rotation+SP_PI),zoom*3/4)*steps;
mapviewX -= spMul(spGetSizeFactor(),spDiv(spCos(-rotation+SP_PI),zoom*3))*steps;
mapviewY -= spMul(spGetSizeFactor(),spDiv(spSin(-rotation+SP_PI),zoom*3))*steps;
}
if (spGetInput()->axis[1] < 0)
{
posX -= spDiv(spCos(-rotation+SP_PI/2),zoom*3/4)*steps;
posY -= spDiv(spSin(-rotation+SP_PI/2),zoom*3/4)*steps;
mapviewX -= spMul(spGetSizeFactor(),spDiv(spCos(-rotation+SP_PI/2),zoom*3))*steps;
mapviewY -= spMul(spGetSizeFactor(),spDiv(spSin(-rotation+SP_PI/2),zoom*3))*steps;
}
if (spGetInput()->axis[1] > 0)
{
posX -= spDiv(spCos(-rotation+3*SP_PI/2),zoom*3/4)*steps;
posY -= spDiv(spSin(-rotation+3*SP_PI/2),zoom*3/4)*steps;
mapviewX -= spMul(spGetSizeFactor(),spDiv(spCos(-rotation+3*SP_PI/2),zoom*3))*steps;
mapviewY -= spMul(spGetSizeFactor(),spDiv(spSin(-rotation+3*SP_PI/2),zoom*3))*steps;
}
}
else
if (mapviewX || mapviewY)
{
mapviewX = 0;
mapviewY = 0;
}
int i,j;
update_player_sprite(steps);
int result = 0;
Expand Down Expand Up @@ -1273,8 +1280,8 @@ int calc(Uint32 steps)
superZoom = 65536/(spFixedToInt(spMax(abs(dxl-dxr),abs(dyl-dyr)))+1)*(spGetSizeFactor()*224 >> SP_ACCURACY);
superZoom = spSqrt(superZoom);
}
posX = ((Sint64)posX*(Sint64)255+(Sint64)destX) >> 8;
posY = ((Sint64)posY*(Sint64)255+(Sint64)destY) >> 8;
posX = ((Sint64)posX*(Sint64)255+(Sint64)destX+(Sint64)mapviewX) >> 8;
posY = ((Sint64)posY*(Sint64)255+(Sint64)destY+(Sint64)mapviewY) >> 8;
}
//Zoom
if (zoom_d == -1)
Expand Down
2 changes: 2 additions & 0 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,8 @@ void init_player(pPlayer player_list,int pc,int hc,game_options_union options)
active_player = 0;
posX = player[active_player]->firstHare->x;
posY = player[active_player]->firstHare->y;
mapviewX = 0;
mapviewY = 0;
rotation = -player[active_player]->firstHare->rotation;
ai_shoot_tries = 0;
last_ai_try = 0;
Expand Down

0 comments on commit 5b134f6

Please sign in to comment.