Changeset 373:a2efe5470b79


Ignore:
Timestamp:
04/09/11 13:00:53 (12 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Message:

start of patrolling monsters

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • data/levels/town.json

    r300 r373  
    3030    ],
    3131    "enemies": [                                                                             
    32         {"type": "RedOni", "pos": [3, 8], "direction": "left" },   
    33         {"type": "RedOni", "pos": [10, 11], "direction": "right" },
    34         {"type": "RedOni", "pos": [23, 9], "direction": "left" },
    35         {"type": "RedOni", "pos": [64, 6], "direction": "left" },                                 
    36         {"type": "RedOni", "pos": [63, 14], "direction": "left" }
     32        {"type": "PatrollingOni", "pos": [3, 8], "direction": "left" },   
     33        {"type": "PatrollingOni", "pos": [10, 11], "direction": "right" },
     34        {"type": "PatrollingOni", "pos": [23, 9], "direction": "left" },
     35        {"type": "PatrollingOni", "pos": [64, 6], "direction": "left" },                                 
     36        {"type": "PatrollingOni", "pos": [63, 14], "direction": "left" }
    3737    ],
    3838    "doorways": {
  • skaapsteker/sprites/base.py

    r370 r373  
    159159        self.setup(**opts)
    160160
    161 
    162161    def collided_player(self, player):
    163162        print "%s collided with player" % self
     
    204203            self.kill()
    205204
     205class PatrollingMonster(Monster):
     206    """Monster that collides with horizontal geography"""
     207
     208    debug_color = (120, 240, 120)
     209
     210    patrol_speed = (200, 0)
     211
     212    def update(self):
     213        Monster.update(self)
     214        if self._animation == 'running':
     215            if self.facing == 'left':
     216                self.velocity = (-self.patrol_speed[0], 0)
     217            elif self.facing == 'right':
     218                self.velocity = self.patrol_speed
     219
     220    def collided(self, other):
     221        Monster.collided(self, other)
     222        # Check if the object we've collided with is the same height our higher than us
     223        if other.block and other.collide_rect.bottom <= self.collide_rect.bottom:
     224            # Change direction
     225            if self.facing == 'left':
     226                self.facing = 'right'
     227            else:
     228                self.facing = 'left'
     229
    206230
    207231class NPC(AnimatedGameSprite):
  • skaapsteker/sprites/enemies.py

    r336 r373  
    1 from base import Monster
     1from base import Monster, PatrollingMonster
    22from pygame import transform
    33
     
    3232class FireballOni(RedOni):
    3333    pass # TODO
     34
     35
     36class PatrollingOni(RedOni, PatrollingMonster):
     37    pass
Note: See TracChangeset for help on using the changeset viewer.