Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7cba294
Initial object-oriented tilemap rework
Cleptomania May 5, 2021
bb2c51e
Update example 08_load_map for tilemap rework
Cleptomania May 5, 2021
0ad4423
Make layer options optional
Cleptomania May 5, 2021
a330cd6
Map level default scaling value
Cleptomania May 5, 2021
d25716e
Update example 09_endgame
Cleptomania May 5, 2021
fa56328
Initial Scene manager
Cleptomania May 5, 2021
a6ee53f
Update example 08_load_map for scene manager
Cleptomania May 5, 2021
14f08d2
Update example 09_endgame for Scene manager
Cleptomania May 5, 2021
b2daf4b
Update physics engines to accept lists of SpriteList
Cleptomania May 5, 2021
35041bf
Fix typo in tilemap
Cleptomania May 5, 2021
2a4883c
Update physics_engines to accept lists of SpriteList
Cleptomania May 6, 2021
6600476
Add map_directory to animated Sprites
Cleptomania May 6, 2021
b85bad3
Update platformer_tutorial examples
Cleptomania May 6, 2021
3df1046
Remove timeit from example
Cleptomania May 6, 2021
98d266f
Add update utility functions to scene
Cleptomania May 6, 2021
e0de4a5
Use scene update utilities
Cleptomania May 6, 2021
09270af
Update example 12_animate_character for scene graph
Cleptomania May 6, 2021
7296850
Update example 13_add_enemies for scene graph update
Cleptomania May 6, 2021
a8c8cca
Use spatial hash for moving platforms in platform_tutorial
Cleptomania May 6, 2021
2871820
Add 14_moving_enemies to platformer tutorial
Cleptomania May 7, 2021
3288605
Update variable naming in 13_add_enemies
Cleptomania May 7, 2021
06b0532
Merge branch 'development' into scene-graph
Cleptomania May 29, 2021
d41b05e
Finish development merge to scene-graph
Cleptomania May 29, 2021
94972df
Add missed function to sprite_list package
Cleptomania May 29, 2021
c4cde06
Move tilemap module into package
Cleptomania May 29, 2021
82e0b73
Fix PhysicsEngineSimple
Cleptomania May 29, 2021
70f2383
Slight rework of some Scene functions
Cleptomania May 29, 2021
431f235
Update all platform_tutorial examples for scene-graph changes
Cleptomania May 29, 2021
1dd1351
Initial platform tutorial re-write
Cleptomania Jun 1, 2021
a7a4477
Merge branch 'development' into scene-graph
Cleptomania Jun 2, 2021
f1a5414
Add spatial hash support to scene
Cleptomania Jun 2, 2021
c2828cf
Structural Update for platformer_tutorial
Cleptomania Jun 2, 2021
c2d1c3e
Fix formatting for examples
Cleptomania Jun 5, 2021
94108e7
Initial Scene Object step for platformer_tutorial
Cleptomania Jun 5, 2021
972d8e5
Add docstrings to Scene module
Cleptomania Jun 6, 2021
bd1d588
Add docstrings to user facing tilemap functions
Cleptomania Jun 6, 2021
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
10 changes: 6 additions & 4 deletions arcade/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,13 @@ def configure_logging(level: int = None):
from .sprite_list import SpriteList
from .sprite_list import check_for_collision
from .sprite_list import check_for_collision_with_list
from .sprite_list import check_for_collision_with_lists
from .sprite_list import get_closest_sprite
from .sprite_list import get_sprites_at_exact_point
from .sprite_list import get_sprites_at_point

from .scene import Scene

from .physics_engines import PhysicsEnginePlatformer
from .physics_engines import PhysicsEngineSimple

Expand All @@ -255,10 +258,7 @@ def configure_logging(level: int = None):
from .text import create_text_image
from .text import create_text_sprite

from .tilemap import get_tilemap_layer
from .tilemap import process_layer
from .tilemap import read_map
from .tilemap import read_tmx
from .tilemap import load_tilemap

from .pymunk_physics_engine import PymunkPhysicsEngine
from .pymunk_physics_engine import PymunkPhysicsObject
Expand Down Expand Up @@ -341,6 +341,7 @@ def configure_logging(level: int = None):
'calculate_hit_box_points_simple',
'check_for_collision',
'check_for_collision_with_list',
'check_for_collision_with_lists',
'clamp',
'cleanup_texture_cache',
'close_window',
Expand Down Expand Up @@ -412,6 +413,7 @@ def configure_logging(level: int = None):
'get_screens',
'get_sprites_at_exact_point',
'get_sprites_at_point',
'get_text_image',
'create_text_image',
'get_tilemap_layer',
'get_viewport',
Expand Down
15 changes: 10 additions & 5 deletions arcade/arcade_types.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
"""
Module specifying data custom types used for type hinting.
"""
from typing import Tuple
from typing import List
from typing import Union
from typing import Sequence
from collections import namedtuple
from typing import List, NamedTuple, Optional, Sequence, Tuple, Union

from pytiled_parser import Properties

RGB = Union[Tuple[int, int, int], List[int]]
RGBA = Union[Tuple[int, int, int, int], List[int]]
Color = Union[RGB, RGBA]
Point = Union[Tuple[float, float], List[float]]
NamedPoint = namedtuple('NamedPoint', ['x', 'y'])
NamedPoint = namedtuple("NamedPoint", ["x", "y"])

Vector = Point
PointList = Sequence[Point]
Rect = Union[Tuple[float, float, float, float], List[float]] # x, y, width, height
RectList = Union[Tuple[Rect, ...], List[Rect]]


class TiledObject(NamedTuple):
shape: Union[Point, PointList, Rect]
properties: Optional[Properties] = None
name: Optional[str] = None
type: Optional[str] = None
6 changes: 3 additions & 3 deletions arcade/examples/platform_tutorial/01_open_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ def __init__(self):
arcade.set_background_color(arcade.csscolor.CORNFLOWER_BLUE)

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

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

arcade.start_render()
# Code to draw the screen goes here


def main():
""" Main method """
"""Main method"""
window = MyGame()
window.setup()
arcade.run()
Expand Down
14 changes: 7 additions & 7 deletions arcade/examples/platform_tutorial/02_draw_sprites.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self):
arcade.set_background_color(arcade.csscolor.CORNFLOWER_BLUE)

def setup(self):
""" Set up the game here. Call this function to restart the game. """
"""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)
Expand All @@ -59,18 +59,18 @@ def setup(self):

# Put some crates on the ground
# This shows using a coordinate list to place sprites
coordinate_list = [[512, 96],
[256, 96],
[768, 96]]
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 = arcade.Sprite(
":resources:images/tiles/boxCrate_double.png", TILE_SCALING
)
wall.position = coordinate
self.wall_list.append(wall)

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

# Clear the screen to the background color
arcade.start_render()
Expand All @@ -82,7 +82,7 @@ def on_draw(self):


def main():
""" Main method """
"""Main method"""
window = MyGame()
window.setup()
arcade.run()
Expand Down
90 changes: 90 additions & 0 deletions arcade/examples/platform_tutorial/03_scene_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""
Platformer Game
"""
import arcade

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

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


class MyGame(arcade.Window):
"""
Main application class.
"""

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

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

arcade.set_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.center_x = 64
self.player_sprite.center_y = 128
self.scene.add_sprite("Player", 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.scene.add_sprite("Walls", 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.scene.add_sprite("Walls", wall)

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

# Clear the screen to the background color
arcade.start_render()

# Draw our Scene
self.scene.draw()


def main():
"""Main method"""
window = MyGame()
window.setup()
arcade.run()


if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ 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.coin_list = None
self.wall_list = None
self.player_list = None
# Our Scene Object
self.scene = None

# Separate variable that holds the player sprite
self.player_sprite = None
Expand All @@ -42,55 +39,54 @@ def __init__(self):
arcade.set_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)
self.coin_list = arcade.SpriteList(use_spatial_hash=True)
"""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.center_x = 64
self.player_sprite.center_y = 128
self.player_list.append(self.player_sprite)
self.scene.add_sprite("Player", 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)
self.scene.add_sprite("Walls", wall)

# Put some crates on the ground
# This shows using a coordinate list to place sprites
coordinate_list = [[512, 96],
[256, 96],
[768, 96]]
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 = arcade.Sprite(
":resources:images/tiles/boxCrate_double.png", TILE_SCALING
)
wall.position = coordinate
self.wall_list.append(wall)
self.scene.add_sprite("Walls", wall)

# Create the 'physics engine'
self.physics_engine = arcade.PhysicsEngineSimple(self.player_sprite, self.wall_list)
self.physics_engine = arcade.PhysicsEngineSimple(
self.player_sprite, self.scene.get_sprite_list("Walls")
)

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

# Clear the screen to the background color
arcade.start_render()

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

def on_key_press(self, key, modifiers):
"""Called whenever a key is pressed. """
"""Called whenever a key is pressed."""

if key == arcade.key.UP or key == arcade.key.W:
self.player_sprite.change_y = PLAYER_MOVEMENT_SPEED
Expand All @@ -102,7 +98,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 when the user releases a key."""

if key == arcade.key.UP or key == arcade.key.W:
self.player_sprite.change_y = 0
Expand All @@ -114,14 +110,14 @@ def on_key_release(self, key, modifiers):
self.player_sprite.change_x = 0

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

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


def main():
""" Main method """
"""Main method"""
window = MyGame()
window.setup()
arcade.run()
Expand Down
Loading