changeset 1:e88a8f6d354b draft default tip

Done
author Radomir Dopieralski <sheep-devel@sheep.art.pl>
date Mon, 29 Apr 2019 00:13:52 +0200
parents 24875859393b
children
files __init__.py __main__.py cat.png gain.py sprites.png
diffstat 5 files changed, 49 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/__init__.py	Mon Apr 29 00:13:52 2019 +0200
@@ -0,0 +1,1 @@
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/__main__.py	Mon Apr 29 00:13:52 2019 +0200
@@ -0,0 +1,7 @@
+try:
+    import pygame
+except ImportError:
+    raise SystemExit("You need to install PyGame.")
+
+from gain import Game
+Game().run()
Binary file cat.png has changed
--- a/gain.py	Sun Apr 28 22:55:40 2019 +0200
+++ b/gain.py	Mon Apr 29 00:13:52 2019 +0200
@@ -4,10 +4,24 @@
 
 import pygame
 import math
+import StringIO
+import pkgutil
+
+
+def load_data(filename):
+    return pkgutil.get_data('gain', filename)
+
+
+def load_file(filename):
+    return StringIO.StringIO(load_data(filename))
+
+
+def load_image(filename):
+    return pygame.image.load(load_file(filename), filename)
 
 
 def load_sprites(filename, width=64):
-    image = pygame.image.load(filename).convert_alpha()
+    image = load_image(filename).convert_alpha()
     w, h = image.get_size()
     count = w // width
     return [image.subsurface((x * width, 0, width, h)) for x in xrange(count)]
@@ -86,6 +100,13 @@
             self.sy - self.sz
         )
 
+
+class Meow(Coin):
+    def __init__(self, x, y):
+        super(Meow, self).__init__(x, y)
+        self.image = sprite_images[7]
+
+
 class Mob(Thing):
     def __init__(self, frame, x, y):
         super(Mob, self).__init__(frame, x, y)
@@ -105,10 +126,20 @@
             self.sy - self.sz
         )
 
+
+class Cat(Mob):
+    def __init__(self, x, y):
+        super(Cat, self).__init__(6, x, y)
+
+    def act(self, game):
+        game.sprites.add(Meow(self.sx, self.sy + 1))
+
+
 class ExitRoom(Exception):
     def __init__(self, room):
         self.room = room
 
+
 def get_keys(game):
     keys = pygame.key.get_pressed()
     ret = keys
@@ -191,8 +222,8 @@
 
 class Room(object):
     def __init__(self, background_file, floor_file):
-        self.floor = pygame.image.load(floor_file)
-        self.background = pygame.image.load(background_file).convert()
+        self.floor = load_image(floor_file)
+        self.background = load_image(background_file).convert()
         self.exits = []
 
     def enter(self, game):
@@ -231,6 +262,13 @@
             Exit(350, 440, HallRoom, 350, 330),
         ]
 
+    def enter(self, game):
+        super(YardRoom, self).enter(game)
+        cat = Cat(700, 500)
+        cat_shadow = Shadow(cat)
+        game.sprites.add(cat)
+        game.shadows.add(cat_shadow)
+
 
 class Game(object):
     def __init__(self):
Binary file sprites.png has changed