From 780db04699ceadbb45391adc128ffb625dc653fb Mon Sep 17 00:00:00 2001 From: Paul Vincent Craven Date: Thu, 23 Apr 2020 11:29:06 -0500 Subject: [PATCH] Updates for testing TMX map rotation. --- .../images/test_textures/test_texture.png | Bin 0 -> 625 bytes tests/tmx_maps/rotation.tmx | 18 +++ tests/tmx_maps/tileset.tsx | 2 +- tests/tmx_tests/show_tiled_map.py | 103 ++++++++++++++++++ tests/tmx_tests/test_file_formats.py | 8 +- tests/tmx_tests/test_rotation_flip.py | 70 ++++++++++++ 6 files changed, 194 insertions(+), 7 deletions(-) create mode 100644 arcade/resources/images/test_textures/test_texture.png create mode 100644 tests/tmx_maps/rotation.tmx create mode 100644 tests/tmx_tests/show_tiled_map.py create mode 100644 tests/tmx_tests/test_rotation_flip.py diff --git a/arcade/resources/images/test_textures/test_texture.png b/arcade/resources/images/test_textures/test_texture.png new file mode 100644 index 0000000000000000000000000000000000000000..8cf3f90157a7d12c1254e8c5aa7a2d193546d914 GIT binary patch literal 625 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7uRSjKx9jP7LeL$-HD>VAA$IBsU)noF zvN5DH6p%wq=TA7if2QEKj(=qrK72nIKH=Ku-JXFv8NRKH;ubu(uGZqs=Hu2+`53k1 z>)XqnO!w}#j3u^;NDSLzTvf2V)*XblLkeMJP%SI*|0p2WSGNvfOKN*p?afvZx7C^ z|0iXeDaQnM2eCxZI=jwmUp!5j8;lutY>Ph5x5Ku9Zwt$Z;@J=U<-_OS=4X80#?c0!0K?@$)V3zm@Y7)*B3bm9K1ZEnI;T|dqcV4SBj4}ov;M{FF+Bu@ g9 + + + + +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 + + + diff --git a/tests/tmx_maps/tileset.tsx b/tests/tmx_maps/tileset.tsx index 6578e343a..13ea05cbe 100644 --- a/tests/tmx_maps/tileset.tsx +++ b/tests/tmx_maps/tileset.tsx @@ -17,7 +17,7 @@ - + diff --git a/tests/tmx_tests/show_tiled_map.py b/tests/tmx_tests/show_tiled_map.py new file mode 100644 index 000000000..9950e0c03 --- /dev/null +++ b/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() diff --git a/tests/tmx_tests/test_file_formats.py b/tests/tmx_tests/test_file_formats.py index 2bb0ff983..9b8bfdf82 100644 --- a/tests/tmx_tests/test_file_formats.py +++ b/tests/tmx_tests/test_file_formats.py @@ -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 @@ -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 \ No newline at end of file + assert "boxCrate" in wall_list[2].texture.name + diff --git a/tests/tmx_tests/test_rotation_flip.py b/tests/tmx_tests/test_rotation_flip.py new file mode 100644 index 000000000..e8b9af785 --- /dev/null +++ b/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 \ No newline at end of file