Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Platformer Tutorial Re-Write #1940

Merged
merged 29 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f000875
Chapter 1 update
Cleptomania Apr 24, 2023
a45111e
Merge branch 'development' into platformer_tutorial_revamp
Cleptomania Apr 24, 2023
784e9a0
Initial Chapter 2 Rewrite
Cleptomania Apr 24, 2023
1b2af17
Remove SpriteList from Chapter 2
Cleptomania Apr 24, 2023
ee45963
Initial Chapter 3 re-work
Cleptomania Apr 24, 2023
6c35157
Initial Chapter 4 re-write
Cleptomania Apr 25, 2023
fa59d1c
Initial Chapter 5 re-write
Cleptomania Apr 25, 2023
127984f
Consolidate window size
Cleptomania Apr 25, 2023
6c54950
Add run commands
Cleptomania Apr 25, 2023
f9df834
Initial Step 6 re-write
Cleptomania Apr 25, 2023
33bc136
Initial Chapter 7 re-write
Cleptomania Apr 25, 2023
9d50e60
Add missing can_jump check
Cleptomania Apr 25, 2023
f3ad3d4
Initial Chapter 8 re-write
Cleptomania Apr 25, 2023
018a5c5
Initial Chapter 9 re-write
Cleptomania Apr 25, 2023
53d37e4
Initial Chapter 10 Re-Write
Cleptomania Apr 25, 2023
2165323
Fix typo in chapters 3
Cleptomania Apr 25, 2023
f8665ba
Initial Chapter 11 Re-Write
Cleptomania Apr 25, 2023
b12abf8
Fix incorrect module names
Cleptomania Apr 25, 2023
56967d9
Initial Chapter 12 Re-Write
Cleptomania Apr 25, 2023
91d54d3
Makes comment more consistent, and fix typo. (#1728)
annelisagrout Apr 25, 2023
f88ca9e
Initial Chapter 13 Re-Write
Cleptomania Apr 25, 2023
9dc7df4
Merge branch 'development' into platformer_tutorial_revamp
Cleptomania Aug 28, 2023
546e8e6
Minor corrections
Cleptomania Aug 28, 2023
2d646b4
Initial chapter 14
Cleptomania Aug 28, 2023
e877d07
Initial code for chapters 15-20
Cleptomania Dec 15, 2023
472f4e2
Remove old defunct chapters
Cleptomania Dec 15, 2023
732c8b9
Merge branch 'development' into platformer_tutorial_revamp
Cleptomania Dec 15, 2023
bdc816a
Exclude platformer tutorial from ruff
Cleptomania Dec 15, 2023
f909c73
Update sound doc references to platformer tutorial
Cleptomania Dec 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions arcade/examples/platform_tutorial/01_open_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import arcade

# Constants
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = 650
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Platformer"


Expand All @@ -18,7 +18,7 @@ class MyGame(arcade.Window):

def __init__(self):

# Call the parent class and set up the window
# Call the parent class to set up the window
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

self.background_color = arcade.csscolor.CORNFLOWER_BLUE
Expand All @@ -30,8 +30,13 @@ def setup(self):
def on_draw(self):
"""Render the screen."""

# The clear method should always be called at the start of on_draw.
# It clears the whole screen to whatever the background color is
# set to. This ensures that you have a clean slate for drawing each
# frame of the game.
self.clear()
# Code to draw the screen goes here

# Code to draw other things will go here


def main():
Expand Down
52 changes: 9 additions & 43 deletions arcade/examples/platform_tutorial/02_draw_sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
import arcade

# Constants
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = 650
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Platformer"

# Constants used to scale our sprites from their original size
CHARACTER_SCALING = 1
TILE_SCALING = 0.5


class MyGame(arcade.Window):
"""
Expand All @@ -25,48 +21,19 @@ def __init__(self):
# Call the parent class and set up the window
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

# These are 'lists' that keep track of our sprites. Each sprite should
# go into a list.
self.wall_list = None
self.player_list = None
# Variable to hold our texture for our player
self.player_texture = arcade.load_texture(":resources:images/animated_characters/female_adventurer/femaleAdventurer_idle.png")

# Separate variable that holds the player sprite
self.player_sprite = None
self.player_sprite = arcade.Sprite(self.player_texture)
self.player_sprite.center_x = 64
self.player_sprite.center_y = 128

self.background_color = arcade.csscolor.CORNFLOWER_BLUE

def setup(self):
"""Set up the game here. Call this function to restart the game."""
# Create the Sprite lists
self.player_list = arcade.SpriteList()
self.wall_list = arcade.SpriteList(use_spatial_hash=True)

# Set up the player, specifically placing it at these coordinates.
image_source = ":resources:images/animated_characters/female_adventurer/femaleAdventurer_idle.png"
self.player_sprite = arcade.Sprite(image_source, CHARACTER_SCALING)
self.player_sprite.center_x = 64
self.player_sprite.center_y = 128
self.player_list.append(self.player_sprite)

# Create the ground
# This shows using a loop to place multiple sprites horizontally
for x in range(0, 1250, 64):
wall = arcade.Sprite(":resources:images/tiles/grassMid.png", TILE_SCALING)
wall.center_x = x
wall.center_y = 32
self.wall_list.append(wall)

# Put some crates on the ground
# This shows using a coordinate list to place sprites
coordinate_list = [[512, 96], [256, 96], [768, 96]]

for coordinate in coordinate_list:
# Add a crate on the ground
wall = arcade.Sprite(
":resources:images/tiles/boxCrate_double.png", TILE_SCALING
)
wall.position = coordinate
self.wall_list.append(wall)
pass

def on_draw(self):
"""Render the screen."""
Expand All @@ -75,8 +42,7 @@ def on_draw(self):
self.clear()

# Draw our sprites
self.wall_list.draw()
self.player_list.draw()
self.player_sprite.draw()


def main():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
"""
Platformer Game

python -m arcade.examples.platform_tutorial.03_scene_object
python -m arcade.examples.platform_tutorial.03_more_sprites
"""
import arcade

# Constants
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = 650
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Platformer"

# Constants used to scale our sprites from their original size
CHARACTER_SCALING = 1
TILE_SCALING = 0.5


Expand All @@ -25,38 +24,33 @@ def __init__(self):
# Call the parent class and set up the window
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

# Our Scene Object
self.scene = None
# Variable to hold our texture for our player
self.player_texture = arcade.load_texture(":resources:images/animated_characters/female_adventurer/femaleAdventurer_idle.png")

# Separate variable that holds the player sprite
self.player_sprite = None

self.background_color = arcade.csscolor.CORNFLOWER_BLUE

def setup(self):
"""Set up the game here. Call this function to restart the game."""

# Initialize Scene
self.scene = arcade.Scene()

# Create the Sprite lists
self.scene.add_sprite_list("Player")
self.scene.add_sprite_list("Walls", use_spatial_hash=True)

# Set up the player, specifically placing it at these coordinates.
image_source = ":resources:images/animated_characters/female_adventurer/femaleAdventurer_idle.png"
self.player_sprite = arcade.Sprite(image_source, CHARACTER_SCALING)
self.player_sprite = arcade.Sprite(self.player_texture)
self.player_sprite.center_x = 64
self.player_sprite.center_y = 128
self.scene.add_sprite("Player", self.player_sprite)

# SpriteList for our player
self.player_list = arcade.SpriteList()
self.player_list.append(self.player_sprite)

# SpriteList for our boxes and ground
# Putting our ground and box Sprites in the same SpriteList
# will make it easier to perform collision detection against
# them later on. Setting the spatial hash to True will make
# collision detection much faster if the objects in this
# SpriteList do not move.
self.wall_list = arcade.SpriteList(use_spatial_hash=True)

# Create the ground
# This shows using a loop to place multiple sprites horizontally
for x in range(0, 1250, 64):
wall = arcade.Sprite(":resources:images/tiles/grassMid.png", TILE_SCALING)
wall = arcade.Sprite(":resources:images/tiles/grassMid.png", scale=0.5)
wall.center_x = x
wall.center_y = 32
self.scene.add_sprite("Walls", wall)
self.wall_list.append(wall)

# Put some crates on the ground
# This shows using a coordinate list to place sprites
Expand All @@ -65,19 +59,26 @@ def setup(self):
for coordinate in coordinate_list:
# Add a crate on the ground
wall = arcade.Sprite(
":resources:images/tiles/boxCrate_double.png", TILE_SCALING
":resources:images/tiles/boxCrate_double.png", scale=0.5
)
wall.position = coordinate
self.scene.add_sprite("Walls", wall)
self.wall_list.append(wall)

self.background_color = arcade.csscolor.CORNFLOWER_BLUE

def setup(self):
"""Set up the game here. Call this function to restart the game."""
pass

def on_draw(self):
"""Render the screen."""

# Clear the screen to the background color
self.clear()

# Draw our Scene
self.scene.draw()
# Draw our sprites
self.player_list.draw()
self.wall_list.draw()


def main():
Expand Down
78 changes: 41 additions & 37 deletions arcade/examples/platform_tutorial/04_user_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import arcade

# Constants
SCREEN_WIDTH = 1000
SCREEN_HEIGHT = 650
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Platformer"

# Constants used to scale our sprites from their original size
CHARACTER_SCALING = 1
TILE_SCALING = 0.5

# Movement speed of player, in pixels per frame
Expand All @@ -28,37 +27,33 @@ def __init__(self):
# Call the parent class and set up the window
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

# Our Scene Object
self.scene = None
# Variable to hold our texture for our player
self.player_texture = arcade.load_texture(":resources:images/animated_characters/female_adventurer/femaleAdventurer_idle.png")

# Separate variable that holds the player sprite
self.player_sprite = None

# Our physics engine
self.physics_engine = None

self.background_color = arcade.csscolor.CORNFLOWER_BLUE

def setup(self):
"""Set up the game here. Call this function to restart the game."""

# Initialize Scene
self.scene = arcade.Scene()

# Set up the player, specifically placing it at these coordinates.
image_source = ":resources:images/animated_characters/female_adventurer/femaleAdventurer_idle.png"
self.player_sprite = arcade.Sprite(image_source, CHARACTER_SCALING)
self.player_sprite = arcade.Sprite(self.player_texture)
self.player_sprite.center_x = 64
self.player_sprite.center_y = 128
self.scene.add_sprite("Player", self.player_sprite)

# SpriteList for our player
self.player_list = arcade.SpriteList()
self.player_list.append(self.player_sprite)

# SpriteList for our boxes and ground
# Putting our ground and box Sprites in the same SpriteList
# will make it easier to perform collision detection against
# them later on. Setting the spatial hash to True will make
# collision detection much faster if the objects in this
# SpriteList do not move.
self.wall_list = arcade.SpriteList(use_spatial_hash=True)

# Create the ground
# This shows using a loop to place multiple sprites horizontally
for x in range(0, 1250, 64):
wall = arcade.Sprite(":resources:images/tiles/grassMid.png", TILE_SCALING)
wall = arcade.Sprite(":resources:images/tiles/grassMid.png", scale=TILE_SCALING)
wall.center_x = x
wall.center_y = 32
self.scene.add_sprite("Walls", wall)
self.wall_list.append(wall)

# Put some crates on the ground
# This shows using a coordinate list to place sprites
Expand All @@ -67,24 +62,39 @@ def setup(self):
for coordinate in coordinate_list:
# Add a crate on the ground
wall = arcade.Sprite(
":resources:images/tiles/boxCrate_double.png", TILE_SCALING
":resources:images/tiles/boxCrate_double.png", scale=TILE_SCALING
)
wall.position = coordinate
self.scene.add_sprite("Walls", wall)
self.wall_list.append(wall)

# Create the 'physics engine'
# Create a Simple Physics Engine, this will handle moving our
# player as well as collisions between the player sprite and
# whatever SpriteList we specify for the walls.
self.physics_engine = arcade.PhysicsEngineSimple(
self.player_sprite, self.scene.get_sprite_list("Walls")
self.player_sprite, self.wall_list
)

self.background_color = arcade.csscolor.CORNFLOWER_BLUE

def setup(self):
"""Set up the game here. Call this function to restart the game."""
pass

def on_draw(self):
"""Render the screen."""

# Clear the screen to the background color
self.clear()

# Draw our Scene
self.scene.draw()
# Draw our sprites
self.player_list.draw()
self.wall_list.draw()

def on_update(self, delta_time):
"""Movement and Game Logic"""

# Move the player using our physics engine
self.physics_engine.update()

def on_key_press(self, key, modifiers):
"""Called whenever a key is pressed."""
Expand All @@ -99,7 +109,7 @@ def on_key_press(self, key, modifiers):
self.player_sprite.change_x = PLAYER_MOVEMENT_SPEED

def on_key_release(self, key, modifiers):
"""Called when the user releases a key."""
"""Called whenever a key is released."""

if key == arcade.key.UP or key == arcade.key.W:
self.player_sprite.change_y = 0
Expand All @@ -110,12 +120,6 @@ def on_key_release(self, key, modifiers):
elif key == arcade.key.RIGHT or key == arcade.key.D:
self.player_sprite.change_x = 0

def on_update(self, delta_time):
"""Movement and game logic"""

# Move the player with the physics engine
self.physics_engine.update()


def main():
"""Main function"""
Expand Down
Loading