; ; ;--------------------------------------------------------------------------; ; ; Step 9 ; ; ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,; ; ;,,,, ; Same as Step 8, but with controllable view point. ; ; Again, let's recap. ; ; S---=---=---=---+ ; | | ; ( ) ; | | ; ( P ) ; | | ; ( ) ; | | ; +---=---=---=---+ ; ; Everything on screen is relative to the player world position. ; Where the Player screen pos is half the screen. ; ; Player screen pos = Screen size / 2 ; ; Add background. ; ; S---=---=---=---+ ; | | ; ( ) ; | | ; ( P ) ; | | ; ( B- -)-----------+ ; | |· ·|o o o o o o| ; +---=---=---=---+ o o o o o | ; |o o o o o o o o| ; | o o o o o o o | ; |o o o o o o o o| ; | o o o o o o o | ; |o o o o o o o o| ; +---------------+ ; ; The old background screen position equation: ; ; Back screen pos = Back world pos - Player world pos ; + Player screen pos ;---- ; ;,,,, ; We want to add a relative viewpoint to all world positions on screen. ; ; Screen coord = World coord + Relative view point ; ; Formerly we were using the View_Pos variables. ; I'm affraid we're gonna have to rename this to View_WorldPos. ; ; So when we want to move the screen over the world, ; e.g. the reversed thingy again, ; all we have to do is subtracting this ; from all world-to-screen equations. ; Yes, it's that simple! :) ; ; First, background. ; ; Back screen pos = Back world pos - Player world pos ; + Player screen pos - View world pos ; ; Second, player. ; ; Player screen pos = Screen size / 2 - View world pos ;---- ; -- Sizes -- ; Introducing the screen size variables. Screen_SizeX = GraphicsWidth () Screen_SizeY = GraphicsHeight () ; Half the screen or 'screen middle'. Screen_MidX = Screen_SizeX / 2 Screen_MidY = Screen_SizeY / 2 Back_SizeX = Screen_SizeX Back_SizeY = Screen_SizeY Player_SizeX = 20 Player_SizeY = 20 ; -- Positions -- Back_WorldPosX = 0 Back_WorldPosY = 0 Player_WorldPosX = 0 Player_WorldPosY = 0 View_WorldPosX = 0 View_WorldPosY = 0 ; -- Loop -- SetBuffer BackBuffer () Repeat ; -- Input -- ; Regular arrow keys to move the player. If KeyDown ( 200 ) Then Player_WorldPosY = Player_WorldPosY - 2 If KeyDown ( 208 ) Then Player_WorldPosY = Player_WorldPosY + 2 If KeyDown ( 203 ) Then Player_WorldPosX = Player_WorldPosX - 2 If KeyDown ( 205 ) Then Player_WorldPosX = Player_WorldPosX + 2 ; Keypad arrow keys to move the view point. If KeyDown ( 72 ) Then View_WorldPosY = View_WorldPosY - 2 If KeyDown ( 80 ) Then View_WorldPosY = View_WorldPosY + 2 If KeyDown ( 75 ) Then View_WorldPosX = View_WorldPosX - 2 If KeyDown ( 77 ) Then View_WorldPosX = View_WorldPosX + 2 ; -- Logic -- ; Equation for background position on screen: ; ; Back screen pos = Back world pos - Player world pos ; + Player screen pos - View world pos ; ; Because we now have a variable player screen position, ; and the 'player screen position' in the above equation ; is actually the player offset on screen, ; we'll substitute this with 'middle of screen' directly. ; This way we can alter the player screen position ; without having to worry about screwing ; the background position on screen. Back_ScreenPosX = Back_WorldPosX - Player_WorldPosX + Screen_MidX - View_WorldPosX Back_ScreenPosY = Back_WorldPosY - Player_WorldPosY + Screen_MidY - View_WorldPosY ; Okay, same thing for equation for player screen position. ; ; Player screen pos = Screen size / 2 - View world pos Player_ScreenPosX = Screen_MidX - View_WorldPosX Player_ScreenPosY = Screen_MidY - View_WorldPosY ; -- Render -- Rect Back_ScreenPosX , Back_ScreenPosY , Back_SizeX , Back_SizeY , False Rect Player_ScreenPosX,Player_ScreenPosY,Player_SizeX,Player_SizeY,False Flip Cls Until KeyHit ( 1 ) End