Skip to content

Commit fc01e9b

Browse files
add hex support and example
1 parent 1c55978 commit fc01e9b

File tree

6 files changed

+584
-13
lines changed

6 files changed

+584
-13
lines changed

arcade/examples/hex_map.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
"""
2+
Hex Map Example
3+
4+
If Python and Arcade are installed, this example can be run from the command line with:
5+
python -m arcade.examples.hex_map
6+
"""
7+
import arcade
8+
from arcade import TileMap
9+
10+
WINDOW_WIDTH = 1280
11+
WINDOW_HEIGHT = 720
12+
WINDOW_TITLE = "Hex Map"
13+
14+
15+
class GameView(arcade.View):
16+
"""
17+
Main application class.
18+
"""
19+
20+
def __init__(self):
21+
super().__init__()
22+
23+
# Variable to hold our Tiled Map
24+
self.tile_map: TileMap
25+
26+
# Replacing all of our SpriteLists with a Scene variable
27+
self.scene: arcade.Scene
28+
29+
# A variable to store our camera object
30+
self.camera: arcade.camera.Camera2D
31+
32+
# A variable to store our gui camera object
33+
self.gui_camera: arcade.camera.Camera2D
34+
35+
36+
# If you have sprite lists, you should create them here,
37+
# and set them to None
38+
39+
def reset(self):
40+
"""Reset the game to the initial state."""
41+
# Do changes needed to restart the game here if you want to support that
42+
pass
43+
44+
def on_draw(self):
45+
"""
46+
Render the screen.
47+
"""
48+
49+
# This command should happen before we start drawing. It will clear
50+
# the screen to the background color, and erase what we drew last frame.
51+
self.clear()
52+
53+
# Call draw() on all your sprite lists below
54+
55+
def on_update(self, delta_time):
56+
"""
57+
All the logic to move, and the game logic goes here.
58+
Normally, you'll call update() on the sprite lists that
59+
need it.
60+
"""
61+
pass
62+
63+
def on_key_press(self, key, key_modifiers):
64+
"""
65+
Called whenever a key on the keyboard is pressed.
66+
67+
For a full list of keys, see:
68+
https://api.arcade.academy/en/latest/arcade.key.html
69+
"""
70+
pass
71+
72+
def on_key_release(self, key, key_modifiers):
73+
"""
74+
Called whenever the user lets off a previously pressed key.
75+
"""
76+
pass
77+
78+
def on_mouse_motion(self, x, y, delta_x, delta_y):
79+
"""
80+
Called whenever the mouse moves.
81+
"""
82+
pass
83+
84+
def on_mouse_press(self, x, y, button, key_modifiers):
85+
"""
86+
Called when the user presses a mouse button.
87+
"""
88+
pass
89+
90+
def on_mouse_release(self, x, y, button, key_modifiers):
91+
"""
92+
Called when a user releases a mouse button.
93+
"""
94+
pass
95+
96+
97+
def main():
98+
""" Main function """
99+
# Create a window class. This is what actually shows up on screen
100+
window = arcade.Window(WINDOW_WIDTH, WINDOW_HEIGHT, WINDOW_TITLE)
101+
102+
# Create and setup the GameView
103+
game = GameView()
104+
105+
# Show GameView on screen
106+
window.show_view(game)
107+
108+
# Start the arcade game loop
109+
arcade.run()
110+
111+
112+
113+
if __name__ == "__main__":
114+
main()
114 KB
Loading
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{ "compressionlevel":-1,
2+
"height":20,
3+
"hexsidelength":70,
4+
"infinite":false,
5+
"layers":[
6+
{
7+
"data":[38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
8+
38, 38, 38, 38, 38, 38, 38, 38, 37, 38, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,
9+
38, 38, 38, 38, 38, 38, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38,
10+
38, 38, 38, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38,
11+
38, 38, 38, 37, 37, 37, 37, 37, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 37, 37, 37, 38, 38, 38,
12+
38, 38, 38, 37, 37, 37, 37, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 39, 39, 39, 40, 40, 40, 37, 37, 37, 38, 38, 38,
13+
38, 38, 38, 37, 37, 37, 37, 40, 40, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 40, 40, 40, 37, 37, 37, 38, 38,
14+
38, 38, 38, 37, 37, 37, 40, 40, 39, 39, 39, 39, 39, 39, 39, 39, 39, 36, 36, 36, 36, 39, 40, 40, 37, 37, 37, 38, 38, 38,
15+
38, 38, 38, 37, 37, 37, 40, 40, 39, 39, 39, 39, 39, 39, 39, 39, 39, 36, 36, 36, 36, 39, 39, 40, 40, 37, 37, 37, 38, 38,
16+
38, 38, 38, 37, 37, 37, 40, 40, 39, 39, 39, 39, 39, 39, 39, 39, 36, 36, 36, 36, 36, 39, 39, 40, 37, 37, 37, 38, 38, 38,
17+
38, 38, 38, 37, 37, 37, 40, 40, 40, 39, 39, 39, 39, 39, 39, 39, 39, 36, 36, 36, 36, 39, 39, 40, 40, 37, 37, 37, 38, 38,
18+
38, 38, 38, 37, 37, 37, 40, 40, 40, 39, 39, 39, 39, 39, 39, 39, 39, 36, 36, 36, 39, 39, 40, 40, 40, 37, 37, 37, 38, 38,
19+
38, 38, 38, 37, 37, 37, 40, 40, 40, 40, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 40, 40, 40, 37, 37, 37, 38, 38,
20+
38, 38, 37, 37, 37, 37, 37, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 39, 39, 39, 40, 40, 40, 40, 37, 37, 37, 37, 38, 38,
21+
38, 38, 38, 37, 37, 37, 37, 37, 37, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 37, 37, 37, 37, 38, 38,
22+
38, 38, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 40, 40, 40, 40, 40, 40, 40, 37, 37, 37, 37, 37, 38, 38, 38,
23+
38, 38, 38, 38, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38,
24+
38, 38, 38, 38, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38,
25+
38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38,
26+
38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38, 38],
27+
"height":20,
28+
"id":1,
29+
"name":"TILE",
30+
"opacity":1,
31+
"type":"tilelayer",
32+
"visible":true,
33+
"width":30,
34+
"x":0,
35+
"y":0
36+
},
37+
{
38+
"data":[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,
39+
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,
40+
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,
41+
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,
42+
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,
43+
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,
44+
0, 0, 0, 0, 0, 0, 0, 0, 0, 45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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56+
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,
57+
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],
58+
"height":20,
59+
"id":2,
60+
"name":"POI",
61+
"opacity":1,
62+
"type":"tilelayer",
63+
"visible":true,
64+
"width":30,
65+
"x":0,
66+
"y":0
67+
}],
68+
"nextlayerid":3,
69+
"nextobjectid":1,
70+
"orientation":"hexagonal",
71+
"renderorder":"right-down",
72+
"staggeraxis":"y",
73+
"staggerindex":"odd",
74+
"tiledversion":"1.11.2",
75+
"tileheight":140,
76+
"tilesets":[
77+
{
78+
"firstgid":1,
79+
"source":"..\/..\/..\/..\/..\/sim\/assets\/maps\/tilesheet.tsj"
80+
},
81+
{
82+
"firstgid":36,
83+
"source":"hex_tilesheet.tsj"
84+
}],
85+
"tilewidth":120,
86+
"type":"map",
87+
"version":"1.10",
88+
"width":30
89+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
{ "columns":5,
2+
"image":"..\/images\/spritesheets\/hex_tilesheet.png",
3+
"imageheight":994,
4+
"imagewidth":610,
5+
"margin":1,
6+
"name":"tilesheet",
7+
"spacing":2,
8+
"tilecount":35,
9+
"tiledversion":"1.11.2",
10+
"tileheight":140,
11+
"tiles":[
12+
{
13+
"id":0,
14+
"type":"cement"
15+
},
16+
{
17+
"id":1,
18+
"type":"desert"
19+
},
20+
{
21+
"id":2,
22+
"type":"wasteland"
23+
},
24+
{
25+
"id":3,
26+
"type":"grass"
27+
},
28+
{
29+
"id":4,
30+
"type":"dirt"
31+
},
32+
{
33+
"id":5,
34+
"type":"yellow_warehouse"
35+
},
36+
{
37+
"id":6,
38+
"type":"mine"
39+
},
40+
{
41+
"id":8,
42+
"type":"barracks"
43+
},
44+
{
45+
"id":9,
46+
"type":"mountain"
47+
},
48+
{
49+
"id":10,
50+
"type":"gas station"
51+
},
52+
{
53+
"id":11,
54+
"type":"farm"
55+
},
56+
{
57+
"id":13,
58+
"type":"house_1"
59+
},
60+
{
61+
"id":15,
62+
"type":"corner store"
63+
},
64+
{
65+
"id":18,
66+
"type":"house_2"
67+
},
68+
{
69+
"id":20,
70+
"type":"camp"
71+
},
72+
{
73+
"id":23,
74+
"type":"house_3"
75+
},
76+
{
77+
"id":28,
78+
"type":"house_4"
79+
},
80+
{
81+
"id":32,
82+
"type":"construction"
83+
},
84+
{
85+
"id":33,
86+
"type":"forest"
87+
}],
88+
"tilewidth":120,
89+
"type":"tileset",
90+
"version":"1.10"
91+
}

0 commit comments

Comments
 (0)