The game space is rarely limited to the size the window. The player can often push the boundaries of the screen beyond to explore a larger environment.
With the sprites fully loaded and animated, I'm just missing some background art. I pieced together the background below using a tileset from "Pokemon Mystery Dungeon". I believe the game uses randomly generated maps, but for now I'll use the static one below:
I'll create a "Background" class to import background art, coordinates, and the "draw_bg" function. Since the "blit" function uses xy-coordinates as inputs, I can input variables to adjust where the background art is drawn within the window.
While the game window is limited to the screen size, the coordinates within the Python environment are infinite. Even if an image is too large to display in the game window, it's still loaded and accessible. When the xy-coordinates are updated, the image scrolls within the game window and gives the illusion of movement. For example, a Platformer game could have a long, horizontal background for each entire level. Thus, when the player character is moving on the edge of the screen, the player is no longer moving forward; instead they're moving everything else back!
Purple box represents the visible game window
The Code
I'll update the "Move_Object" function for the boundary conditions. When the player object approaches the edge of the window, they stop moving and also update a "scroll_x" or "scroll_y" variable. Another function called "Screen_Scroll" takes all objects (enemies, background) and applies the "scroll" variables to move them consistently. To test the scrolling, I decreased the window size greatly. I've also made some various restructuring to make it more readable.
See code below:
Next Steps
The biggest issue I have now is that the boundaries are not functional at all; it's still a completely open field. To address this, I'll need to bring out some complicated pathfinding.
Comments
Post a Comment