Add 1st screenshot
[erdslangetjie.git] / erdslangetjie / __main__.py
1 import sys
2 import os
3 import kivy
4
5 kivy.require('1.6.0')
6
7 from kivy.app import App
8 from kivy.uix.widget import Widget
9 from kivy.uix.floatlayout import FloatLayout
10 from kivy.graphics import Color, Rectangle
11
12 from erdslangetjie.data import filepath, load
13 from erdslangetjie.level import Level
14
15
16 class GameWindow(FloatLayout):
17
18     def __init__(self, level):
19         super(GameWindow, self).__init__(size=(960, 960))
20         if os.path.exists(filepath(level)):
21             level_data = load(level)
22             self.level = level
23         elif os.path.exists(filepath('levels/' + level)):
24             level_data = load('levels/' + level)
25             self.level = 'levels/' + level
26         else:
27             print 'Unable to find %s - treating this as a new level' % level
28             sys.exit(1)
29         self.level_obj = Level()
30         self.level_obj.load(level_data)
31         level_data.close()
32
33     def build(self):
34         self.clear_widgets()
35         tiles = self.level_obj.get_tiles()
36         tile_size = 24
37         bx, by = 0, 0
38         for tile_line in tiles:
39             bx = 0
40             for tile in tile_line:
41                 node = Widget(size=(tile_size, tile_size), pos=(bx, by))
42                 with node.canvas:
43                     Color(1, 1, 1)
44                     Rectangle(pos=node.pos, size=node.size,
45                             texture=tile.texture)
46                 self.add_widget(node)
47                 bx += tile_size
48             by += tile_size
49
50
51 class GameApp(App):
52
53     def __init__(self):
54         self.level = 'level1.txt'
55         super(GameApp, self).__init__()
56
57     def build(self):
58         game = GameWindow(self.level)
59         game.build()
60         return game
61
62
63 def main():
64     """ Erdslangetjie, a maze game of eluding nemesis
65     """
66     GameApp().run()