Changeset 362:02bf05964619


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

FIREBALLS!

Location:
skaapsteker/sprites
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/sprites/base.py

    r355 r362  
    2020MONSTER_LAYER = 1
    2121NPC_LAYER = 2
    22 
     22PROJECTILE_LAYER = 3
    2323
    2424
     
    142142
    143143    collision_layer = MONSTER_LAYER
    144     collides_with = set([PC_LAYER])
     144    collides_with = set([PC_LAYER, PROJECTILE_LAYER])
    145145
    146146    debug_color = (240, 120, 120)
     
    208208
    209209    collision_layer = NPC_LAYER
     210    collides_with = set([])
    210211
    211212    debug_color = (240, 240, 240)
     
    228229
    229230class Projectile(AnimatedGameSprite):
     231
     232    collision_layer = PROJECTILE_LAYER
     233    collides_with = set()
     234
    230235    gravitates = False
     236
     237    DAMAGE = 10
     238
     239    def setup(self, hits):
     240        if isinstance(hits, tuple):
     241            self.hits = hits + (Geography,)
     242        else:
     243            self.hits = (hits, Geography)
     244
     245    def explode(self):
     246        self.kill()
     247
     248    def collided(self, other):
     249        if not isinstance(other, self.hits):
     250            return
     251        if hasattr(other, 'damage'):
     252            other.damage(self.DAMAGE)
     253        self.explode()
    231254
    232255
     
    264287    mobile = False
    265288    gravitates = False
    266     collides_with = set([PC_LAYER, MONSTER_LAYER, NPC_LAYER])
     289    collides_with = set([PC_LAYER, MONSTER_LAYER, NPC_LAYER, PROJECTILE_LAYER])
    267290    is_ground = True
    268291    actionable = False
  • skaapsteker/sprites/player.py

    r359 r362  
    44import time
    55
    6 from ..sprites.base import find_sprite, TILE_SIZE, PC_LAYER, MONSTER_LAYER
     6from ..sprites.base import find_sprite, Monster, TILE_SIZE, PC_LAYER, MONSTER_LAYER, PROJECTILE_LAYER
    77from ..sprites.projectiles import Fireball
    88from ..physics import Sprite
     
    1515
    1616    collision_layer = PC_LAYER
    17     collides_with = set([MONSTER_LAYER])
     17    collides_with = set([MONSTER_LAYER, PROJECTILE_LAYER])
    1818    wants_updates = True
    1919
     
    278278        else:
    279279            pos = pygame.Rect(self.rect.midright, (0, 0))
    280         fireball = Fireball(pos, direction=self.facing)
     280        fireball = Fireball(pos, direction=self.facing, hits=Monster)
    281281        AddSpriteEvent.post(fireball)
    282282
  • skaapsteker/sprites/projectiles.py

    r355 r362  
    2121
    2222    FIREBALL_WIDTH = 60 # pixels
     23    VELOCITY = (300, -1000) # pps
    2324
    24     def setup(self, direction):
     25    def setup(self, direction, **opts):
     26        super(Fireball, self).setup(**opts)
    2527        self.facing = direction
    2628        if self.facing == "left":
    2729            shift = (-self.FIREBALL_WIDTH / 2, 0)
     30            dv = (-self.VELOCITY[0], self.VELOCITY[1])
    2831        else:
    2932            shift = (self.FIREBALL_WIDTH / 2, 0)
     33            dv = (self.VELOCITY[0], self.VELOCITY[1])
    3034        self.rect.move_ip(shift)
    3135        self.collide_rect.move_ip(shift)
    32 
    33     def collided_player(self, player):
    34         print "%s went boom with player" % self
    35 
    36 
     36        self.deltav(dv)
Note: See TracChangeset for help on using the changeset viewer.