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
12 from erdslangetjie.data import filepath, load
13 from erdslangetjie.level import Level
14 from erdslangetjie.player import ThePlayer, Nemesis
17 class GameWindow(FloatLayout):
19 def __init__(self, level):
20 super(GameWindow, self).__init__(size=(960, 960))
21 if os.path.exists(filepath(level)):
22 level_data = load(level)
24 elif os.path.exists(filepath('levels/' + level)):
25 level_data = load('levels/' + level)
26 self.level = 'levels/' + level
28 print 'Unable to find %s - treating this as a new level' % level
30 self.level_obj = Level()
31 self.level_obj.load(level_data)
34 self.player = ThePlayer()
35 self.level_obj.load_tiles()
36 if not self.level_obj.enter_pos:
37 raise RuntimeError('No entry point')
39 self.player.pos = self.level_obj.enter_pos
43 tiles = self.level_obj.get_tiles()
46 for tile_line in tiles:
48 for tile in tile_line:
49 node = Widget(size=(tile_size, tile_size), pos=(bx, by))
52 Rectangle(pos=node.pos, size=node.size,
58 player_pos = (self.player.pos[0] * tile_size,
59 self.player.pos[1] * tile_size)
60 player_tile = Widget(size=(tile_size, tile_size),
62 with player_tile.canvas:
64 Rectangle(pos=player_pos, size=player_tile.size,
65 texture=self.player.sprite.texture)
66 self.add_widget(player_tile)
72 self.level = 'level1.txt'
73 super(GameApp, self).__init__()
76 game = GameWindow(self.level)
82 """ Erdslangetjie, a maze game of eluding nemesis