Changeset 366:249ba3bd6904


Ignore:
Timestamp:
04/09/11 12:46:23 (12 years ago)
Author:
Simon Cross <hodgestar@…>
Branch:
default
Phase:
public
Rebase:
30366632633735393137313833376636303966646238656662656331383935653461623633663563
Message:

Very, very frightening.

Location:
skaapsteker/sprites
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/sprites/base.py

    r362 r366  
    237237    DAMAGE = 10
    238238
    239     def setup(self, hits):
     239    PROJECTILE_SIZE = (0, 0) # pixels
     240    VELOCITY = (10, 10) # pixels/s
     241
     242    def setup(self, direction, hits, **opts):
     243        super(Projectile, self).setup(**opts)
     244        self.facing = direction
     245
    240246        if isinstance(hits, tuple):
    241247            self.hits = hits + (Geography,)
    242248        else:
    243249            self.hits = (hits, Geography)
     250
     251        if self.facing == "left":
     252            shift = (-self.PROJECTILE_SIZE[0] / 2, self.PROJECTILE_SIZE[1])
     253            dv = (-self.VELOCITY[0], self.VELOCITY[1])
     254        else:
     255            shift = (self.PROJECTILE_SIZE[0] / 2, self.PROJECTILE_SIZE[1])
     256            dv = (self.VELOCITY[0], self.VELOCITY[1])
     257
     258        self.rect.move_ip(shift)
     259        self.collide_rect.move_ip(shift)
     260        self.deltav(dv)
    244261
    245262    def explode(self):
  • skaapsteker/sprites/player.py

    r362 r366  
    55
    66from ..sprites.base import find_sprite, Monster, TILE_SIZE, PC_LAYER, MONSTER_LAYER, PROJECTILE_LAYER
    7 from ..sprites.projectiles import Fireball
     7from ..sprites.projectiles import Fireball, Lightning
    88from ..physics import Sprite
    99from ..constants import Layers, FoxHud
     
    270270        self._last_time = time.time() # Reset the animation clock
    271271
     272    def _launch_projectile(self, cls):
     273        if self.facing == 'left':
     274            pos = pygame.Rect(self.rect.midleft, (0, 0))
     275        else:
     276            pos = pygame.Rect(self.rect.midright, (0, 0))
     277        projectile = cls(pos, direction=self.facing, hits=Monster)
     278        AddSpriteEvent.post(projectile)
     279
    272280    def _fireball_attack(self):
    273281        print 'ninja fireball attack attack attack'
    274282        self.attacking = 2
    275283        self._last_time = time.time() # Reset the animation clock
    276         if self.facing == 'left':
    277             pos = pygame.Rect(self.rect.midleft, (0, 0))
    278         else:
    279             pos = pygame.Rect(self.rect.midright, (0, 0))
    280         fireball = Fireball(pos, direction=self.facing, hits=Monster)
    281         AddSpriteEvent.post(fireball)
     284        self._launch_projectile(Fireball)
    282285
    283286    def _lightning_attack(self):
     
    285288        self.attacking = 2
    286289        self._last_time = time.time() # Reset the animation clock
     290        self._launch_projectile(Lightning)
    287291
    288292    def action_fire1(self):
  • skaapsteker/sprites/projectiles.py

    r364 r366  
    2020    }
    2121
    22     FIREBALL_WIDTH = 55 # pixels
     22    PROJECTILE_SIZE = (55, 8) # pixels
    2323    VELOCITY = (300, -1000) # pps
    2424
    25     def setup(self, direction, **opts):
    26         super(Fireball, self).setup(**opts)
    27         self.facing = direction
    28         if self.facing == "left":
    29             shift = (-self.FIREBALL_WIDTH / 2, 4)
    30             dv = (-self.VELOCITY[0], self.VELOCITY[1])
    31         else:
    32             shift = (self.FIREBALL_WIDTH / 2, 4)
    33             dv = (self.VELOCITY[0], self.VELOCITY[1])
    34         self.rect.move_ip(shift)
    35         self.collide_rect.move_ip(shift)
    36         self.deltav(dv)
     25
     26class Lightning(Projectile):
     27
     28    gravitates = False
     29
     30    image_dir = 'sprites/attacks/fireball'
     31    animation_regexes = [
     32        ('frightening', r"^fireball-\d+-sm.png$"),
     33    ]
     34
     35    facings = {
     36        "frightening" : (
     37            ('left', None),
     38            ('right', lambda x: transform.flip(x, True, False))),
     39    }
     40
     41    PROJECTILE_SIZE = (55, 8) # pixels
     42    VELOCITY = (400, 0) # pps
Note: See TracChangeset for help on using the changeset viewer.