1 //============================================================================= 2 // 3 // Adventure Game Studio (AGS) 4 // 5 // Copyright (C) 1999-2011 Chris Jones and 2011-20xx others 6 // The full list of copyright holders can be found in the Copyright.txt 7 // file, which is part of this source code distribution. 8 // 9 // The AGS source code is provided under the Artistic License 2.0. 10 // A copy of this license can be found in the file License.txt and at 11 // http://www.opensource.org/licenses/artistic-license-2.0.php 12 // 13 //============================================================================= 14 15 #include "ac/viewport.h" 16 #include "ac/draw.h" 17 #include "ac/roomstruct.h" 18 #include "ac/characterinfo.h" 19 #include "ac/gamestate.h" 20 #include "ac/gamesetup.h" 21 22 extern int offsetx, offsety; 23 extern GameState play; 24 extern roomstruct thisroom; 25 extern GameSetup usetup; 26 extern CharacterInfo*playerchar; 27 check_viewport_coords()28void check_viewport_coords() 29 { 30 if (offsetx<0) offsetx=0; 31 if (offsety<0) offsety=0; 32 33 int roomWidth = multiply_up_coordinate(thisroom.width); 34 int roomHeight = multiply_up_coordinate(thisroom.height); 35 if (offsetx + play.viewport.GetWidth() > roomWidth) 36 offsetx = roomWidth - play.viewport.GetWidth(); 37 if (offsety + play.viewport.GetHeight() > roomHeight) 38 offsety = roomHeight - play.viewport.GetHeight(); 39 } 40 41 update_viewport()42void update_viewport() 43 { 44 if ((thisroom.width > BASEWIDTH) || (thisroom.height > BASEHEIGHT)) { 45 if (play.offsets_locked == 0) { 46 offsetx = multiply_up_coordinate(playerchar->x) - play.viewport.GetWidth()/2; 47 offsety = multiply_up_coordinate(playerchar->y) - play.viewport.GetHeight()/2; 48 } 49 check_viewport_coords(); 50 } 51 else { 52 offsetx=0; 53 offsety=0; 54 } 55 } 56