Skip to content

Commit

Permalink
Updates for testing TMX map rotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcraven committed Apr 23, 2020
1 parent 635f491 commit 780db04
Show file tree
Hide file tree
Showing 6 changed files with 194 additions and 7 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions tests/tmx_maps/rotation.tmx
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.3.4" orientation="orthogonal" renderorder="left-up" width="11" height="10" tilewidth="128" tileheight="128" infinite="0" nextlayerid="2" nextobjectid="1">
<tileset firstgid="1" source="tileset.tsx"/>
<layer id="1" name="Blocking Sprites" width="11" height="10">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
6,2147483654,0,2684354566,3758096390,0,3221225478,1073741830,0,1610612742,536870918
</data>
</layer>
</map>
2 changes: 1 addition & 1 deletion tests/tmx_maps/tileset.tsx
Expand Up @@ -17,7 +17,7 @@
<image width="128" height="128" source="../../arcade/resources/images/tiles/brickGrey.png"/>
</tile>
<tile id="5">
<image width="128" height="128" source="../../arcade/resources/images/tiles/brickTextureWhite.png"/>
<image width="128" height="128" source="../../arcade/resources/images/test_textures/test_texture.png"/>
</tile>
<tile id="6">
<image width="128" height="128" source="../../arcade/resources/images/tiles/bridgeA.png"/>
Expand Down
103 changes: 103 additions & 0 deletions tests/tmx_tests/show_tiled_map.py
@@ -0,0 +1,103 @@
"""
Load a Tiled map file
Artwork from: http://kenney.nl
Tiled available from: http://www.mapeditor.org/
If Python and Arcade are installed, this example can be run from the command line with:
python -m arcade.examples.sprite_tiled_map
"""

import arcade
import os
import time

TILE_SCALING = 0.5
PLAYER_SCALING = 1

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Sprite Tiled Map Example"
SPRITE_PIXEL_SIZE = 128
GRID_PIXEL_SIZE = (SPRITE_PIXEL_SIZE * TILE_SCALING)

# How many pixels to keep as a minimum margin between the character
# and the edge of the screen.
VIEWPORT_MARGIN_TOP = 60
VIEWPORT_MARGIN_BOTTOM = 60
VIEWPORT_RIGHT_MARGIN = 270
VIEWPORT_LEFT_MARGIN = 270

# Physics
MOVEMENT_SPEED = 5
JUMP_SPEED = 23
GRAVITY = 1.1


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

def __init__(self):
"""
Initializer
"""
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

# Set the working directory (where we expect to find files) to the same
# directory this .py file is in. You can leave this out of your own
# code, but it is needed to easily run the examples using "python -m"
# as mentioned at the top of this program.
file_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(file_path)

# Sprite lists
self.tile_list = None

# Set up the player
self.score = 0
self.player_sprite = None

self.view_left = 0
self.view_bottom = 0
self.end_of_map = 0
self.game_over = False
self.last_time = None
self.frame_count = 0
self.fps_message = None

def setup(self):
""" Set up the game and initialize the variables. """

map_name = "../tmx_maps/rotation.tmx"

# Read in the tiled map
my_map = arcade.tilemap.read_tmx(map_name)
self.end_of_map = my_map.map_size.width * GRID_PIXEL_SIZE

# --- Platforms ---
self.wall_list = arcade.tilemap.process_layer(my_map, 'Blocking Sprites', TILE_SCALING)

# --- Other stuff
# Set the background color
if my_map.background_color:
arcade.set_background_color(my_map.background_color)

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

# This command has to happen before we start drawing
arcade.start_render()

# Draw all the sprites.
self.wall_list.draw()

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


if __name__ == "__main__":
main()
8 changes: 2 additions & 6 deletions tests/tmx_tests/test_file_formats.py
Expand Up @@ -113,11 +113,6 @@ def test_base_64_gzip():

# --- Platforms ---
wall_list = arcade.tilemap.process_layer(my_map, 'Blocking Sprites', TILE_SCALING)
#
# for wall in wall_list:
# print()
# print(wall.position)
# print(wall.texture.name)

assert wall_list[0].position == (64, 1216)
assert "dirtCenter" in wall_list[0].texture.name
Expand All @@ -126,4 +121,5 @@ def test_base_64_gzip():
assert "grassCenter" in wall_list[1].texture.name

assert wall_list[2].position == (64, 64)
assert "boxCrate" in wall_list[2].texture.name
assert "boxCrate" in wall_list[2].texture.name

70 changes: 70 additions & 0 deletions tests/tmx_tests/test_rotation_flip.py
@@ -0,0 +1,70 @@
import arcade

def test_rotation_mirror():
# Read in the tiled map
my_map = arcade.tilemap.read_tmx("../tmx_maps/rotation.tmx")

assert my_map.tile_size == (128, 128)
assert my_map.orientation == "orthogonal"
assert my_map.render_order == "left-up"
assert my_map.infinite == 0
assert my_map.map_size == (11, 10)

# --- Platforms ---
wall_list = arcade.tilemap.process_layer(my_map, 'Blocking Sprites')

for wall in wall_list:
print()
print(wall.position)
print(wall.texture.name)
pos = 0, 0
print(wall.texture.image.getpixel(pos))
pos = 127, 0
print(wall.texture.image.getpixel(pos))
pos = 127, 127
print(wall.texture.image.getpixel(pos))


wall = wall_list[0]
assert wall.position == (64, 64)
pos = 0, 0
assert wall.texture.image.getpixel(pos) == (255, 0, 0, 255)
pos = 127, 0
assert wall.texture.image.getpixel(pos) == (0, 255, 0, 255)
pos = 127, 127
assert wall.texture.image.getpixel(pos) == (255, 0, 255, 255)

wall = wall_list[1]
assert wall.position == (192, 64)
pos = 0, 0
assert wall.texture.image.getpixel(pos) == (0, 255, 0, 255)
pos = 127, 0
assert wall.texture.image.getpixel(pos) == (255, 0, 0, 255)
pos = 127, 127
assert wall.texture.image.getpixel(pos) == (0, 0, 255, 255)

wall = wall_list[2]
assert wall.position == (448, 64)
pos = 0, 0
assert wall.texture.image.getpixel(pos) == (0, 0, 255, 255)
pos = 127, 0
assert wall.texture.image.getpixel(pos) == (255, 0, 0, 255)
pos = 127, 127
assert wall.texture.image.getpixel(pos) == (0, 255, 0, 255)


wall = wall_list[3]
assert wall.position == (576, 64)
pos = 0, 0
assert wall.texture.image.getpixel(pos) == (255, 0, 255, 255)
pos = 127, 0
assert wall.texture.image.getpixel(pos) == (0, 255, 0, 255)
pos = 127, 127
assert wall.texture.image.getpixel(pos) == (255, 0, 0, 255)

#
# assert wall_list[1].position == (1216, 1216)
# assert "grassCenter" in wall_list[1].texture.name
#
# assert wall_list[2].position == (64, 64)
# assert "boxCrate" in wall_list[2].texture.name

0 comments on commit 780db04

Please sign in to comment.