changeset 206:e2acf4663065

Move fox properties to the world
author Neil Muller <drnlmuller@gmail.com>
date Wed, 06 Apr 2011 23:19:08 +0200
parents 466147799786
children d2e4fb016627
files data/game.json skaapsteker/levelscene.py skaapsteker/sprites/base.py skaapsteker/sprites/player.py
diffstat 4 files changed, 18 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/data/game.json	Wed Apr 06 23:03:34 2011 +0200
+++ b/data/game.json	Wed Apr 06 23:19:08 2011 +0200
@@ -1,6 +1,8 @@
 {
     "fox": {
-        "item": null
+        "item": null,
+        "tails" : [],
+        "health" : 80
     },
     "missions": {
         "monk_tea": {}
@@ -21,4 +23,4 @@
         "level4" : "level4",
         "level5" : "level5"
     }
-}
\ No newline at end of file
+}
--- a/skaapsteker/levelscene.py	Wed Apr 06 23:03:34 2011 +0200
+++ b/skaapsteker/levelscene.py	Wed Apr 06 23:19:08 2011 +0200
@@ -16,7 +16,7 @@
     def __init__(self, game_state, leveldef):
         super(LevelScene, self).__init__(game_state)
 
-        self._player = sprites.player.Player()
+        self._player = sprites.player.Player(game_state.world)
         self._level = level.Level(leveldef, self._player)
 
         self._level_surface = self._level.get_surface()
--- a/skaapsteker/sprites/base.py	Wed Apr 06 23:03:34 2011 +0200
+++ b/skaapsteker/sprites/base.py	Wed Apr 06 23:19:08 2011 +0200
@@ -44,7 +44,7 @@
         GameSprite.__init__(self, pos, **opts)
         self.floor_rect = Rect(self.collide_rect.topleft, (self.collide_rect.width, 2))
         self._layer = Layers.PLAYER
-        self.health = 1
+        self.health = 10
         self.setup(**opts)
 
 
--- a/skaapsteker/sprites/player.py	Wed Apr 06 23:03:34 2011 +0200
+++ b/skaapsteker/sprites/player.py	Wed Apr 06 23:19:08 2011 +0200
@@ -1,7 +1,6 @@
 """Class for dealing with the player"""
 
 import pygame.transform
-import os
 import time
 
 from skaapsteker.sprites.base import TILE_SIZE, PC_LAYER, MONSTER_LAYER
@@ -16,7 +15,7 @@
     collides_with = set([MONSTER_LAYER])
     wants_updates = True
 
-    def __init__(self):
+    def __init__(self, the_world):
         Sprite.__init__(self)
         self.image = None
         self.rect = None
@@ -30,17 +29,17 @@
         self.flying = False
         self._load_images()
         # We muck with these in load for convience, so ensure they're right
-        self.tails = 0
+        self.the_world = the_world
+        self.health = the_world.fox.health
         self.set_facing('left')
         self.set_image()
         self.set_pos((0, 0))
         self._collisions_seen = 0
         self._last_collide = []
         self._layer = Layers.PLAYER
-        self.health = 4
 
     def set_image(self):
-        key = self._make_key()
+        key = self._make_key(len(self.the_world.fox.tails))
         images = self._image_dict[key]
         if self._animation_frame >= len(images):
             self._animation_frame = 0.0
@@ -174,7 +173,8 @@
         self.deltav((0.0, 100.0))
 
     def action_fire1(self):
-        if self.tails < 2:
+        # FIXME: Use the correct tail properties for this
+        if len(self.the_world.fox.tails) < 2:
             # Only have a bite attack
             print 'attacking'
             self.attacking = 2
@@ -192,32 +192,28 @@
             return 'jumpin'
         return 'standing'
 
-    def _make_key(self, action=None):
+    def _make_key(self, tails, action=None):
         if action is None:
             action = self._get_action()
-        tails = self.tails
-        if self.tails >= 4:
+        if tails >= 4:
             tails = 4
-        elif self.tails >= 2:
+        elif tails >= 2:
             tails = 2
         return '%s %s %d' % (action, self.facing, tails)
 
     def _load_images(self):
         for action in ['standing', 'running', 'jumping', 'attacking']:
             for tails in [0, 1, 2, 4]:
-                self.tails = tails
-                directory = os.path.join('sprites',
-                        'kitsune_%s' % action,
-                        'kitsune_%s_%dtail' % (action, tails))
+                directory = 'sprites/kitsune_%s/kitsune_%s_%dtail' % (action, action, tails)
                 for facing in ['left', 'right']:
                     self.facing = facing
-                    key = self._make_key(action)
+                    key = self._make_key(tails, action)
                     self._image_dict[key] = []
                     for image_file in get_files(directory):
                         if image_file.startswith('.'):
                             # Skip extra junk for now
                             continue
-                        image = load_image(os.path.join(directory, image_file))
+                        image = load_image('%s/%s' % (directory, image_file))
                         if facing == 'right':
                             image = pygame.transform.flip(image, True, False)
                         self._image_dict[key].append(image)