forked from pythonarcade/arcade
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates for testing TMX map rotation.
- Loading branch information
Showing
6 changed files
with
194 additions
and
7 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |