changeset 3:1a1b7ceecb0f default tip

Bounds checking
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Thu, 16 Feb 2012 23:46:32 +0100
parents a3ecaba66636
children
files ziew.py
diffstat 1 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/ziew.py	Thu Feb 16 23:19:13 2012 +0100
+++ b/ziew.py	Thu Feb 16 23:46:32 2012 +0100
@@ -11,13 +11,13 @@
     '       ########     ',
     '                    ',
     '                    ',
-    '    ###      ###### ',
+    '    ###      #@@### ',
     '                    ',
     '                    ',
-    '       ########     ',
+    '       #####@@#     ',
     '                    ',
     '####                ',
-    '                    ',
+    '            @@@@    ',
     '                    ',
     '####################',
 ]
@@ -54,7 +54,7 @@
             self.frame = (self.frame + 1) % len(self.frames)
         else:
             self.frame = 0
-        if self.dy:
+        if self.dy or self.in_air:
             frame = 2
             self.in_air = True
         else:
@@ -68,7 +68,7 @@
             self.dy = 0
             self.rect.bottom = 480
             self.in_air = False
-        if self.dy>0 and LEVEL[(self.rect.bottom-4)/32][self.rect.centerx/32] == '#':
+        if self.dy>0 and LEVEL[max(min(len(LEVEL)-1, (self.rect.bottom-4)/32), 0)][max(0, min(self.rect.centerx/32, len(LEVEL[0])-1))] != ' ':
             self.dy = 0
             self.rect.bottom = int((self.rect.bottom-4)/32)*32 + 4
             self.in_air = False
@@ -91,6 +91,8 @@
         for x, cell in enumerate(line):
             if cell == '#':
                 background.blit(tiles[24], (32 * x, 32 * y))
+            elif cell == '@':
+                background.blit(tiles[25], (32 * x, 32 * y))
     return background