Started setting things up to test the hexmap coordinate logic separately from the game.

This commit is contained in:
Amy Wooding 2016-07-16 19:16:41 -04:00
parent acf52537a2
commit 032f6db266
3 changed files with 50 additions and 18 deletions

View File

@ -57,7 +57,7 @@
" size_hint: 1, .66\n", " size_hint: 1, .66\n",
" DebugLabel:\n", " DebugLabel:\n",
" text: 'mini-map'\n", " text: 'mini-map'\n",
" size_hint: 1, .33\n" " size_hint: 1, .33"
] ]
}, },
{ {
@ -82,7 +82,7 @@
" return StrategyGame()\n", " return StrategyGame()\n",
"\n", "\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" StrategyGameApp().run()\n" " StrategyGameApp().run()"
] ]
}, },
{ {
@ -102,7 +102,7 @@
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"#!python main.py\n" "#!python main.py"
] ]
}, },
{ {
@ -140,7 +140,7 @@
" size_hint: 1, .66\n", " size_hint: 1, .66\n",
" DebugLabel:\n", " DebugLabel:\n",
" text: 'mini-map'\n", " text: 'mini-map'\n",
" size_hint: 1, .33\n" " size_hint: 1, .33"
] ]
}, },
{ {
@ -199,7 +199,7 @@
" size_hint: 1, .66\n", " size_hint: 1, .66\n",
" DebugLabel:\n", " DebugLabel:\n",
" text: 'mini-map'\n", " text: 'mini-map'\n",
" size_hint: 1, .33\n" " size_hint: 1, .33"
] ]
}, },
{ {
@ -237,7 +237,7 @@
" return StrategyGame()\n", " return StrategyGame()\n",
"\n", "\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" StrategyGameApp().run()\n" " StrategyGameApp().run()"
] ]
}, },
{ {
@ -290,7 +290,7 @@
" size_hint: 1, .66\n", " size_hint: 1, .66\n",
" DebugLabel:\n", " DebugLabel:\n",
" text: 'mini-map'\n", " text: 'mini-map'\n",
" size_hint: 1, .33\n" " size_hint: 1, .33"
] ]
}, },
{ {
@ -328,7 +328,7 @@
" return StrategyGame()\n", " return StrategyGame()\n",
"\n", "\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" StrategyGameApp().run()\n" " StrategyGameApp().run()"
] ]
}, },
{ {
@ -431,7 +431,7 @@
" return StrategyGame()\n", " return StrategyGame()\n",
"\n", "\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" StrategyGameApp().run()\n" " StrategyGameApp().run()"
] ]
}, },
{ {
@ -503,7 +503,7 @@
" return HelloWorld()\n", " return HelloWorld()\n",
"\n", "\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" HelloWorldApp().run()\n" " HelloWorldApp().run()"
] ]
}, },
{ {
@ -538,7 +538,7 @@
" size_hint: 1, .66\n", " size_hint: 1, .66\n",
" DebugLabel:\n", " DebugLabel:\n",
" text: 'mini-map'\n", " text: 'mini-map'\n",
" size_hint: 1, .33\n" " size_hint: 1, .33"
] ]
}, },
{ {
@ -619,7 +619,7 @@
" rgba: (1,1,1,1)\n", " rgba: (1,1,1,1)\n",
" Line:\n", " Line:\n",
" points: (self.right, self.y, self.right, self.top)\n", " points: (self.right, self.y, self.right, self.top)\n",
" width: 2\n" " width: 2"
] ]
}, },
{ {
@ -700,7 +700,7 @@
" return StrategyGame()\n", " return StrategyGame()\n",
"\n", "\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" StrategyGameApp().run()\n" " StrategyGameApp().run()"
] ]
}, },
{ {
@ -785,7 +785,7 @@
"\n", "\n",
"<HexMapCell>:\n", "<HexMapCell>:\n",
" size_hint: 1, None\n", " size_hint: 1, None\n",
" height: self.width / math.sqrt(3)\n" " height: self.width / math.sqrt(3)"
] ]
}, },
{ {
@ -895,7 +895,7 @@
" return StrategyGame()\n", " return StrategyGame()\n",
"\n", "\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" StrategyGameApp().run()\n" " StrategyGameApp().run()"
] ]
}, },
{ {
@ -1100,7 +1100,7 @@
" return StrategyGame()\n", " return StrategyGame()\n",
"\n", "\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" StrategyGameApp().run()\n" " StrategyGameApp().run()"
] ]
}, },
{ {
@ -1120,6 +1120,40 @@
"Cleaned some stuff up and added colours to the hexagons. " "Cleaned some stuff up and added colours to the hexagons. "
] ]
}, },
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Test out the hexmap conversion code"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"ename": "TypeError",
"evalue": "must be type, not classobj",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-45811acccccf>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mfrom\u001b[0m \u001b[0mfoo\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mHexMapCell\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mhex_cell\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mHexMapCell\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m9\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m4\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/Users/amywooding/python-code/gamecamp/foo.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, row, col, **kwargs)\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0;32mclass\u001b[0m \u001b[0mHexMapCell\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mObject\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrow\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcol\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 9\u001b[0;31m \u001b[0;31m#super(HexMapCell, self).__init__(**kwargs)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 10\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcoords\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mMapCoords\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrow\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcol\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 11\u001b[0m \u001b[0;31m## set the cube coordinates of the hexagon\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: must be type, not classobj"
]
}
],
"source": [
"from foo import HexMapCell\n",
"hex_cell = HexMapCell(9, 4)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,

View File

@ -13,7 +13,6 @@ class HexMapCell(Label):
## as [x, y, z] ## as [x, y, z]
self.cube_coords = self.even_r_to_cube(self.coords.row / 3, self.coords.col / 2) self.cube_coords = self.even_r_to_cube(self.coords.row / 3, self.coords.col / 2)
def even_r_to_cube(self, row, col): def even_r_to_cube(self, row, col):
'''compute cube coordinates from even-r hex coordinates''' '''compute cube coordinates from even-r hex coordinates'''
x = int(col - ceil(float(row)/2)) x = int(col - ceil(float(row)/2))

View File

@ -7,7 +7,6 @@ import kivy.utils
from hexmap import HexMapCell from hexmap import HexMapCell
class StrategyGame(FloatLayout): class StrategyGame(FloatLayout):
main_map = properties.ObjectProperty(None) main_map = properties.ObjectProperty(None)
map_rows = properties.NumericProperty(0) map_rows = properties.NumericProperty(0)