mirror of
https://github.com/n0remac/2020GameJamPractice.git
synced 2025-12-08 02:05:13 -06:00
@@ -6,6 +6,10 @@ This repository serves as team practice for the [Python Discord](https://pythond
|
||||
|
||||
The project is a sample project, built off a [basic starter tutorial](https://arcade.academy/examples/platform_tutorial/index.html) for the [Arcade](https://pypi.org/project/arcade/) game framework.
|
||||
|
||||
##Workflow
|
||||
|
||||
[Issues](https://github.com/n0remac/2020GameJamPractice/issues) that need to be added can be found with the enhancement label. Before you start on an issue you should assign it to yourself. To track issue progress the [Projects](https://github.com/n0remac/2020GameJamPractice/projects/1) page can be used. Use Hopper for when you claim a card, Development when create a new branch, Code review when you make a pull request, Merging if need be, and finally Done when complete.
|
||||
|
||||
## Useful Links
|
||||
|
||||
1. [Using Pipenv with PyCharm](https://www.jetbrains.com/help/pycharm/pipenv.html)
|
||||
|
||||
@@ -18,6 +18,14 @@ PLAYER_MOVEMENT_SPEED = 5
|
||||
GRAVITY = 1
|
||||
PLAYER_JUMP_SPEED = 20
|
||||
|
||||
# How many pixels to keep as a minimum margin between the character
|
||||
# and the edge of the screen.
|
||||
LEFT_VIEWPORT_MARGIN = 250
|
||||
RIGHT_VIEWPORT_MARGIN = 250
|
||||
BOTTOM_VIEWPORT_MARGIN = 50
|
||||
TOP_VIEWPORT_MARGIN = 100
|
||||
|
||||
|
||||
|
||||
class MyGame(arcade.Window):
|
||||
"""
|
||||
@@ -41,6 +49,10 @@ class MyGame(arcade.Window):
|
||||
# Our physics engine
|
||||
self.physics_engine = None
|
||||
|
||||
# Used to keep track of our scrolling
|
||||
self.view_bottom = 0
|
||||
self.view_left = 0
|
||||
|
||||
arcade.set_background_color(arcade.csscolor.CORNFLOWER_BLUE)
|
||||
|
||||
def setup(self):
|
||||
@@ -118,6 +130,48 @@ class MyGame(arcade.Window):
|
||||
# Move the player with the physics engine
|
||||
self.physics_engine.update()
|
||||
|
||||
# --- Manage Scrolling ---
|
||||
|
||||
# Track if we need to change the viewport
|
||||
|
||||
changed = False
|
||||
|
||||
# Scroll left
|
||||
left_boundary = self.view_left + LEFT_VIEWPORT_MARGIN
|
||||
if self.player_sprite.left < left_boundary:
|
||||
self.view_left -= left_boundary - self.player_sprite.left
|
||||
changed = True
|
||||
|
||||
# Scroll right
|
||||
right_boundary = self.view_left + SCREEN_WIDTH - RIGHT_VIEWPORT_MARGIN
|
||||
if self.player_sprite.right > right_boundary:
|
||||
self.view_left += self.player_sprite.right - right_boundary
|
||||
changed = True
|
||||
|
||||
# Scroll up
|
||||
top_boundary = self.view_bottom + SCREEN_HEIGHT - TOP_VIEWPORT_MARGIN
|
||||
if self.player_sprite.top > top_boundary:
|
||||
self.view_bottom += self.player_sprite.top - top_boundary
|
||||
changed = True
|
||||
|
||||
# Scroll down
|
||||
bottom_boundary = self.view_bottom + BOTTOM_VIEWPORT_MARGIN
|
||||
if self.player_sprite.bottom < bottom_boundary:
|
||||
self.view_bottom -= bottom_boundary - self.player_sprite.bottom
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
# Only scroll to integers. Otherwise we end up with pixels that
|
||||
# don't line up on the screen
|
||||
self.view_bottom = int(self.view_bottom)
|
||||
self.view_left = int(self.view_left)
|
||||
|
||||
# Do the scrolling
|
||||
arcade.set_viewport(self.view_left,
|
||||
SCREEN_WIDTH + self.view_left,
|
||||
self.view_bottom,
|
||||
SCREEN_HEIGHT + self.view_bottom)
|
||||
|
||||
|
||||
def main():
|
||||
""" Main method """
|
||||
|
||||
Reference in New Issue
Block a user